生辰助手
parent
ef47644c0b
commit
6a324ff5e1
|
@ -0,0 +1,22 @@
|
||||||
|
package com.muyu.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:chaiyapeng
|
||||||
|
* @Package:com.muyu.domain
|
||||||
|
* @Project:cloud-mart
|
||||||
|
* @name:BirthdayHelper
|
||||||
|
* @Date:2024/8/24 19:37
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Birthday {
|
||||||
|
private String year;
|
||||||
|
private String month;
|
||||||
|
private String day;
|
||||||
|
private String hour;
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import com.muyu.cloud.mart.service.MarketService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
|
import com.muyu.domain.Birthday;
|
||||||
import com.muyu.domain.Market;
|
import com.muyu.domain.Market;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
@ -72,5 +73,12 @@ public class MarketController extends BaseController {
|
||||||
public Result getWeather(){
|
public Result getWeather(){
|
||||||
return marketService.getWeather();
|
return marketService.getWeather();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 生辰助手
|
||||||
|
*/
|
||||||
|
@PostMapping("getBirthday")
|
||||||
|
public Result getBirthday(@RequestBody Birthday birthday){
|
||||||
|
return marketService.getBirthday(birthday);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.cloud.mart.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.domain.Birthday;
|
||||||
import com.muyu.domain.Market;
|
import com.muyu.domain.Market;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,4 +24,6 @@ public interface MarketService extends IService<Market> {
|
||||||
Result getHeadlines();
|
Result getHeadlines();
|
||||||
|
|
||||||
Result getWeather();
|
Result getWeather();
|
||||||
|
|
||||||
|
Result getBirthday(Birthday birthday);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,11 @@ package com.muyu.cloud.mart.service.impl;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
import com.muyu.cloud.mart.utils.Headlines;
|
import com.muyu.cloud.mart.utils.*;
|
||||||
import com.muyu.cloud.mart.utils.IPLocation;
|
|
||||||
import com.muyu.cloud.mart.utils.MobileLocation;
|
|
||||||
import com.muyu.cloud.mart.mapper.MarketMapper;
|
import com.muyu.cloud.mart.mapper.MarketMapper;
|
||||||
import com.muyu.cloud.mart.service.MarketService;
|
import com.muyu.cloud.mart.service.MarketService;
|
||||||
import com.muyu.cloud.mart.utils.Weather;
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.domain.Birthday;
|
||||||
import com.muyu.domain.Market;
|
import com.muyu.domain.Market;
|
||||||
import com.muyu.domain.PhonePlace;
|
import com.muyu.domain.PhonePlace;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
@ -92,10 +90,18 @@ public class MarketServiceImpl extends ServiceImpl<MarketMapper, Market> impleme
|
||||||
StringBuffer stringBuffer = Headlines.queryHeadlines();
|
StringBuffer stringBuffer = Headlines.queryHeadlines();
|
||||||
return Result.success(stringBuffer);
|
return Result.success(stringBuffer);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 气象预警
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result getWeather() {
|
public Result getWeather() {
|
||||||
StringBuffer stringBuffer = Weather.queryWeather();
|
StringBuffer stringBuffer = Weather.queryWeather();
|
||||||
return Result.success(stringBuffer);
|
return Result.success(stringBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result getBirthday(Birthday birthday) {
|
||||||
|
StringBuffer stringBuffer = BirthdayHelper.queryBirthday(birthday);
|
||||||
|
return Result.success(stringBuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.muyu.cloud.mart.utils;
|
||||||
|
|
||||||
|
import com.muyu.domain.Birthday;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:chaiyapeng
|
||||||
|
* @Package:com.muyu.cloud.mart.utils
|
||||||
|
* @Project:cloud-mart
|
||||||
|
* @name:BirthdayHelper
|
||||||
|
* @Date:2024/8/24 19:36
|
||||||
|
*/
|
||||||
|
public class BirthdayHelper {
|
||||||
|
|
||||||
|
public static StringBuffer queryBirthday(Birthday birthday){
|
||||||
|
String apiKey = "9bbfc46233d4931c39207b090ed4b27c";
|
||||||
|
String apiUrl = "http://apis.juhe.cn/birthEight/query";
|
||||||
|
HashMap<String, String> map = new HashMap<>();
|
||||||
|
|
||||||
|
map.put("key", apiKey);
|
||||||
|
map.put("year", birthday.getYear());
|
||||||
|
birthday.setYear(map.put("year", birthday.getYear()));
|
||||||
|
map.put("month", birthday.getMonth());
|
||||||
|
birthday.setMonth(map.put("month", birthday.getMonth()));
|
||||||
|
map.put("day", birthday.getDay());
|
||||||
|
birthday.setDay(map.put("day", birthday.getDay()));
|
||||||
|
map.put("hour", birthday.getHour());
|
||||||
|
birthday.setHour(map.put("hour", birthday.getHour()));
|
||||||
|
try {
|
||||||
|
URL url = new URL(String.format(apiUrl + "?" + params(map)));
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
StringBuffer response = new StringBuffer();
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
response.append(inputLine);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
System.out.println(response);
|
||||||
|
return response;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String params(Map<String, String> map) {
|
||||||
|
return map.entrySet().stream()
|
||||||
|
.map(entry -> {
|
||||||
|
try {
|
||||||
|
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return entry.getKey() + "=" + entry.getValue();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect(Collectors.joining("&"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ public class MobileLocation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据手机号码/手机号码前7位查询号码归属地
|
* 根据手机号码/手机号码前7位查询号码归属地
|
||||||
* @param mobile
|
* @param tel
|
||||||
*/
|
*/
|
||||||
public static PhonePlace queryMobileLocation(String tel)
|
public static PhonePlace queryMobileLocation(String tel)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue