提交 8280a2a8 authored 作者: 艾庆国's avatar 艾庆国

线路预警

上级 059a78d0
package com.clx.performance.controller.temp; package com.clx.performance.controller.temp;
import com.clx.performance.service.linewarn.LineWarnMqService;
import com.msl.common.result.Result; import com.msl.common.result.Result;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
* @Author: aiqingguo * @Author: aiqingguo
* @Description: 临时接口 * @Description: 临时接口
...@@ -21,15 +18,10 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -21,15 +18,10 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping(value="/temp/lineWarn") @RequestMapping(value="/temp/lineWarn")
public class TempLineWarnController { public class TempLineWarnController {
@Autowired
private LineWarnMqService lineWarnMqService;
@ApiOperation(value = "线路上报", notes = "<br>By:艾庆国")
@PostMapping("/lineReport")
public Result lineReport(Integer sendSystemAddressId, Integer receiveSystemAddressId,
Integer reportType, Integer estimatedTravelTime) {
lineWarnMqService.lineReport(sendSystemAddressId, receiveSystemAddressId, reportType, estimatedTravelTime); @ApiOperation(value = "test", notes = "<br>By:艾庆国")
@PostMapping("/test")
public Result test() {
return Result.ok(); return Result.ok();
} }
......
...@@ -49,6 +49,7 @@ public class LineWarnInfoDaoImpl extends BaseDaoImpl<LineWarnInfoMapper, LineWar ...@@ -49,6 +49,7 @@ public class LineWarnInfoDaoImpl extends BaseDaoImpl<LineWarnInfoMapper, LineWar
public boolean updateWarnTime(LineWarnInfo item) { public boolean updateWarnTime(LineWarnInfo item) {
return update(lUdWrapper() return update(lUdWrapper()
.eq(LineWarnInfo::getId, item.getId()) .eq(LineWarnInfo::getId, item.getId())
.set(LineWarnInfo::getWeather, item.getWeather())
.set(LineWarnInfo::getWarnTime, item.getWarnTime()) .set(LineWarnInfo::getWarnTime, item.getWarnTime())
); );
} }
......
...@@ -36,6 +36,7 @@ public class LineWarnInfo implements HasKey<Integer> { ...@@ -36,6 +36,7 @@ public class LineWarnInfo implements HasKey<Integer> {
private Integer receiveAddressId; //收货地址id private Integer receiveAddressId; //收货地址id
private String receiveAddress; //收货地址 private String receiveAddress; //收货地址
private LocalDateTime suspendTime; //预警暂停时间 private LocalDateTime suspendTime; //预警暂停时间
private String weather; //天气
private LocalDateTime warnTime; //预警时间 private LocalDateTime warnTime; //预警时间
private Integer status; //处理状态:1待处理 2已处理 3暂停预警 private Integer status; //处理状态:1待处理 2已处理 3暂停预警
private String createBy; //创建人 private String createBy; //创建人
......
...@@ -26,6 +26,11 @@ public class LineWarnCommonServiceImpl implements LineWarnCommonService { ...@@ -26,6 +26,11 @@ public class LineWarnCommonServiceImpl implements LineWarnCommonService {
@Override @Override
public void lineWarnInfoUpdate(OrderGoods orderGoods, LineWarnInfo lineWarnInfo, LineWarnConfig lineWarnConfig){ public void lineWarnInfoUpdate(OrderGoods orderGoods, LineWarnInfo lineWarnInfo, LineWarnConfig lineWarnConfig){
lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig, null);
}
@Override
public void lineWarnInfoUpdate(OrderGoods orderGoods, LineWarnInfo lineWarnInfo, LineWarnConfig lineWarnConfig, String weather){
// 更新 // 更新
if (lineWarnInfo != null){ if (lineWarnInfo != null){
...@@ -33,6 +38,7 @@ public class LineWarnCommonServiceImpl implements LineWarnCommonService { ...@@ -33,6 +38,7 @@ public class LineWarnCommonServiceImpl implements LineWarnCommonService {
LocalDateTime nextTime = lineWarnInfo.getWarnTime().plusMinutes(lineWarnConfig.getInterval().multiply(new BigDecimal(MIN_FER_HOUR)).intValue()); LocalDateTime nextTime = lineWarnInfo.getWarnTime().plusMinutes(lineWarnConfig.getInterval().multiply(new BigDecimal(MIN_FER_HOUR)).intValue());
if (nextTime.isAfter(LocalDateTime.now())) {return;} if (nextTime.isAfter(LocalDateTime.now())) {return;}
lineWarnInfo.setWeather(weather);
lineWarnInfo.setWarnTime(LocalDateTime.now()); lineWarnInfo.setWarnTime(LocalDateTime.now());
lineWarnInfoDao.updateWarnTime(lineWarnInfo); lineWarnInfoDao.updateWarnTime(lineWarnInfo);
...@@ -54,6 +60,7 @@ public class LineWarnCommonServiceImpl implements LineWarnCommonService { ...@@ -54,6 +60,7 @@ public class LineWarnCommonServiceImpl implements LineWarnCommonService {
lineWarnInfo.setReceiveAddressId(orderGoods.getReceiveAddressId()); lineWarnInfo.setReceiveAddressId(orderGoods.getReceiveAddressId());
lineWarnInfo.setReceiveAddress(orderGoods.getReceiveAddressShorter()); lineWarnInfo.setReceiveAddress(orderGoods.getReceiveAddressShorter());
lineWarnInfo.setWeather(weather);
lineWarnInfo.setWarnTime(LocalDateTime.now()); lineWarnInfo.setWarnTime(LocalDateTime.now());
lineWarnInfoDao.saveEntity(lineWarnInfo); lineWarnInfoDao.saveEntity(lineWarnInfo);
......
package com.clx.performance.service.impl.linewarn; package com.clx.performance.service.impl.linewarn;
import com.clx.order.vo.feign.FeignAddressVO;
import com.clx.performance.dao.linewarn.LineWarnConfigDao; import com.clx.performance.dao.linewarn.LineWarnConfigDao;
import com.clx.performance.dao.linewarn.LineWarnInfoDao; import com.clx.performance.dao.linewarn.LineWarnInfoDao;
import com.clx.performance.dto.linewarn.LineWarnCommonInfoDTO; import com.clx.performance.dto.linewarn.LineWarnCommonInfoDTO;
import com.clx.performance.enums.linewarn.LineWarnConfigEnum; import com.clx.performance.enums.linewarn.LineWarnConfigEnum;
import com.clx.performance.enums.linewarn.LineWarnInfoEnum; import com.clx.performance.enums.linewarn.LineWarnInfoEnum;
import com.clx.performance.extranal.order.InternalReportService; import com.clx.performance.extranal.order.InternalReportService;
import com.clx.performance.extranal.user.AddressService;
import com.clx.performance.model.OrderGoods; import com.clx.performance.model.OrderGoods;
import com.clx.performance.model.linewarn.LineWarnConfig; import com.clx.performance.model.linewarn.LineWarnConfig;
import com.clx.performance.model.linewarn.LineWarnInfo; import com.clx.performance.model.linewarn.LineWarnInfo;
import com.clx.performance.service.linewarn.LineWarnCommonService; import com.clx.performance.service.linewarn.LineWarnCommonService;
import com.clx.performance.service.linewarn.LineWarnWeatherWarnService; import com.clx.performance.service.linewarn.LineWarnWeatherWarnService;
import com.clx.performance.utils.LocalDateTimeUtils; import com.clx.performance.utils.gd.GdUtils;
import com.msl.common.base.Optional;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -32,6 +35,10 @@ public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnServic ...@@ -32,6 +35,10 @@ public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnServic
private LineWarnCommonService lineWarnCommonService; private LineWarnCommonService lineWarnCommonService;
@Autowired @Autowired
private LineWarnInfoDao lineWarnInfoDao; private LineWarnInfoDao lineWarnInfoDao;
@Autowired
private GdUtils gdUtils;
@Autowired
private AddressService addressService;
@Override @Override
public void weatherWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo) { public void weatherWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo) {
...@@ -54,8 +61,49 @@ public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnServic ...@@ -54,8 +61,49 @@ public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnServic
return; return;
} }
// 更新 Optional<FeignAddressVO> addressOptional = addressService
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig); .getSendAndReceiveAddress(orderGoods.getSendAddressId(), orderGoods.getReceiveAddressId());
if (addressOptional.isEmpty()) {return;}
FeignAddressVO feignAddressVO = addressOptional.get();
if (feignAddressVO.getSendAddress()!=null
&& StringUtils.isNotBlank(feignAddressVO.getSendAddress().getCityCode())){
String weather = gdUtils.getWeather(feignAddressVO.getSendAddress().getCityCode());
if (weatherCheck(weather)){
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig, weather);
}
}
if (feignAddressVO.getReceiveAddress()!=null
&& StringUtils.isNotBlank(feignAddressVO.getReceiveAddress().getCityCode())){
String weather = gdUtils.getWeather(feignAddressVO.getReceiveAddress().getCityCode());
if (weatherCheck(weather)){
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig, weather);
}
}
}
/**
* 天气验证
*/
private boolean weatherCheck(String weather){
if (weather.contains("雨")
|| weather.contains("雪")
|| weather.contains("沙尘暴")
|| weather.contains("强沙尘暴")
|| weather.contains("大雾")
|| weather.contains("浓雾")
|| weather.contains("强浓雾")
|| weather.contains("特强浓雾")
|| weather.contains("雾")
|| weather.contains("中度霾")
|| weather.contains("重度霾")
|| weather.contains("严重霾")
){
return true;
}
return false;
} }
} }
...@@ -8,4 +8,5 @@ public interface LineWarnCommonService { ...@@ -8,4 +8,5 @@ public interface LineWarnCommonService {
void lineWarnInfoUpdate(OrderGoods orderGoods, LineWarnInfo lineWarnInfo, LineWarnConfig lineWarnConfig); void lineWarnInfoUpdate(OrderGoods orderGoods, LineWarnInfo lineWarnInfo, LineWarnConfig lineWarnConfig);
void lineWarnInfoUpdate(OrderGoods orderGoods, LineWarnInfo lineWarnInfo, LineWarnConfig lineWarnConfig, String weather);
} }
...@@ -33,6 +33,7 @@ public class GdService { ...@@ -33,6 +33,7 @@ public class GdService {
private static final String REGEO_API = "https://restapi.amap.com/v3/geocode/regeo";//逆地理编码 private static final String REGEO_API = "https://restapi.amap.com/v3/geocode/regeo";//逆地理编码
private static final String WEATHER_API = "https://restapi.amap.com/v3/weather/weatherInfo?parameters";//天气
private String gaodeKey = "b2550e16bbc7bf9f6cd168e0f21709fc"; private String gaodeKey = "b2550e16bbc7bf9f6cd168e0f21709fc";
...@@ -356,4 +357,52 @@ public class GdService { ...@@ -356,4 +357,52 @@ public class GdService {
return !Objects.isNull(value) && BigDecimal.ZERO.compareTo(value) != 0 ? value.setScale(2, 4) : BigDecimal.ZERO; return !Objects.isNull(value) && BigDecimal.ZERO.compareTo(value) != 0 ? value.setScale(2, 4) : BigDecimal.ZERO;
} }
public String getWeather(String city){
return getWeather(gaodeKey, city);
}
public static String getWeather(String key, String city) {
String url = WEATHER_API+"?output=json&city=" +city+"&extensions=base&key="+key;
String resultStr;
try {
resultStr = HttpUtils.httpGetRequest(url);
} catch (Exception e) {
throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德地理编码接口异常");
}
if (StringUtils.isBlank(resultStr)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 返回结果空");}
JSONObject retJSONObject = JSONObject.parseObject(resultStr);
if (Objects.isNull(retJSONObject)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 返回结果转换异常, result:"+resultStr);}
Integer status = retJSONObject.getInteger("status");
if (!Objects.equals(1, status)) {
if (Objects.equals(10001, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 无效key, result:"+resultStr);}
else if (Objects.equals(10002, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 没有权限使用相应的服务或者请求接口的路径拼写错误, result:"+resultStr);}
else if (Objects.equals(10003, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 访问已超出日访问量, result:"+resultStr);}
else if (Objects.equals(10004, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 单位时间内访问过于频繁, result:"+resultStr);}
else if (Objects.equals(10010, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, IP访问超限, result:"+resultStr);}
else if (Objects.equals(10044, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 账号维度日调用量超出限制, result:"+resultStr);}
else if (Objects.equals(40000, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 余额耗尽, result:"+resultStr);}
else if (Objects.equals(40002, status)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 购买服务到期, result:"+resultStr);}
else if (Objects.equals(20802, status)) { throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 路线计算失败, result:"+resultStr); }
else if (Objects.equals(20803, status)) { throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 起点终点距离过长, result:"+resultStr); }
else {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, 状态异常, result:"+resultStr);}
}
// 解析
JSONArray geocodes = retJSONObject.getJSONArray("lives");
if (Objects.isNull(geocodes)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德天气接口异常, result:"+resultStr);}
JSONObject item = geocodes.getJSONObject(0);
String weather = item.getString("weather");
return weather;
}
} }
...@@ -72,4 +72,10 @@ public class GdUtils { ...@@ -72,4 +72,10 @@ public class GdUtils {
return GpsUtil.distanceM(currentPosition[0], currentPosition[1], destinationLongitude, destinationLatitude); return GpsUtil.distanceM(currentPosition[0], currentPosition[1], destinationLongitude, destinationLatitude);
} }
/**
* 天气
*/
public String getWeather(String city){
return gdService.getWeather(city);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论