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

Merge branch 'refs/heads/v16.3_line_warn_20240528' into dev

......@@ -15,8 +15,8 @@ public enum LineWarnConfigEnum {
TAKE(1, "接单预警"),
LOAD(2, "装车预警"),
UNLOAD(3, "卸车预警"),
JAM(4, "拥堵预警 "),
CONGESTION(4, "拥堵预警"),
WEATHER(5, "天气预警"),
CHILD_ABNORMAL(6, "运单异常"),
LINE_ABNORMAL(7, "线路异常"),
......
......@@ -31,5 +31,7 @@ public class LineWarnConfigAddParam {
private BigDecimal timeRatio;
@ApiModelProperty(value = "任务完成占比", example = "1.3")
private BigDecimal taskCompleteRatio;
@ApiModelProperty(value = "交通增加时间(分钟)", example = "1")
private Integer congestionTime;
}
......@@ -35,5 +35,6 @@ public class LineWarnConfigUpdateParam {
private BigDecimal timeRatio;
@ApiModelProperty(value = "任务完成占比", example = "1.3")
private BigDecimal taskCompleteRatio;
@ApiModelProperty(value = "交通增加时间(分钟)", example = "1")
private Integer congestionTime;
}
......@@ -49,6 +49,8 @@ public class LineWarnConfigVO {
private BigDecimal timeRatio;
@ApiModelProperty(value = "任务完成占比", example = "1.3")
private BigDecimal taskCompleteRatio;
@ApiModelProperty(value = "交通增加时间(分钟)", example = "1")
private Integer congestionTime;
@ApiModelProperty(value = "状态:1启用 2禁用", example = "1")
private Integer status;
......
......@@ -67,6 +67,19 @@ public class LineWarnInfoVO {
@ApiModelProperty(value = "预警暂停时间", example = "")
private String suspendTime;
@ApiModelProperty(value = "挂单数", example = "1")
private Integer pengNum;
@ApiModelProperty(value = "接单数", example = "1")
private Integer takeNum;
@ApiModelProperty(value = "到达货源地车数", example = "1")
private Integer arriveSendNum;
@ApiModelProperty(value = "装车车数", example = "1")
private Integer loadNum;
@ApiModelProperty(value = "到达目的地车数", example = "1")
private Integer arriveReceiveNum;
@ApiModelProperty(value = "卸车车数", example = "1")
private Integer unloadNum;
@ApiModelProperty(value = "处理状态:1待处理 2已处理 3暂停预警", example = "1")
private Integer status;
public Integer getStatus() {
......
......@@ -40,8 +40,15 @@ public class LineWarnConfigController {
|| Objects.equals(param.getWarnType(), LineWarnConfigEnum.WarnType.LOAD.getCode())
|| Objects.equals(param.getWarnType(), LineWarnConfigEnum.WarnType.UNLOAD.getCode())
){
if (Objects.isNull(param.getTimeRatio())){throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER, "时间占比不能为空");}
if (Objects.isNull(param.getTaskCompleteRatio())){throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER, "任务完成占比不能为空");}
if (Objects.isNull(param.getTimeRatio())){
throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER, "时间占比不能为空");}
if (Objects.isNull(param.getTaskCompleteRatio())){
throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER, "任务完成占比不能为空");}
}
if (Objects.equals(param.getWarnType(), LineWarnConfigEnum.WarnType.CONGESTION.getCode())
){
if (Objects.isNull(param.getCongestionTime())){
throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER, "交通增加时间不能为空");}
}
lineWarnConfigService.saveConfig(param);
......@@ -56,10 +63,16 @@ public class LineWarnConfigController {
|| Objects.equals(param.getWarnType(), LineWarnConfigEnum.WarnType.LOAD.getCode())
|| Objects.equals(param.getWarnType(), LineWarnConfigEnum.WarnType.UNLOAD.getCode())
){
if (Objects.isNull(param.getTimeRatio())){throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER, "时间占比不能为空");}
if (Objects.isNull(param.getTaskCompleteRatio())){throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER, "任务完成占比不能为空");}
if (Objects.isNull(param.getTimeRatio())){
throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER, "时间占比不能为空");}
if (Objects.isNull(param.getTaskCompleteRatio())){
throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER, "任务完成占比不能为空");}
}
if (Objects.equals(param.getWarnType(), LineWarnConfigEnum.WarnType.CONGESTION.getCode())
){
if (Objects.isNull(param.getCongestionTime())){
throw new ServiceSystemException(ResultCodeEnum.ILLEGAL_PARAMETER, "交通增加时间不能为空");}
}
lineWarnConfigService.updateConfig(param);
return Result.ok();
}
......
package com.clx.performance.controller.temp;
import com.msl.common.result.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author: aiqingguo
* @Description: 临时接口
* @Date: 2023-8-21 12:10:16
* @Version: 1.0
*/
@Slf4j
@RestController
@RequestMapping(value="/temp/lineWarn")
public class TempLineWarnController {
@ApiOperation(value = "test", notes = "<br>By:艾庆国")
@PostMapping("/test")
public Result test() {
return Result.ok();
}
}
......@@ -49,6 +49,7 @@ public class LineWarnInfoDaoImpl extends BaseDaoImpl<LineWarnInfoMapper, LineWar
public boolean updateWarnTime(LineWarnInfo item) {
return update(lUdWrapper()
.eq(LineWarnInfo::getId, item.getId())
.set(LineWarnInfo::getWeather, item.getWeather())
.set(LineWarnInfo::getWarnTime, item.getWarnTime())
);
}
......
package com.clx.performance.extranal.order;
public interface InternalReportService {
Boolean checkLineJam(Integer sendSystemAddressId,
Integer receiveSystemAddressId,
String beginTime,
Integer duration);
Boolean checkLineAbnormal(Integer sendSystemAddressId,
Integer receiveSystemAddressId,
String beginTime);
}
package com.clx.performance.extranal.order.impl;
import com.clx.order.feign.InternalReportFeign;
import com.clx.performance.extranal.order.InternalReportService;
import com.msl.common.base.Optional;
import com.msl.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class InternalReportServiceImpl implements InternalReportService {
@Autowired
private InternalReportFeign internalReportFeign;
@Override
public Boolean checkLineJam(Integer sendSystemAddressId,
Integer receiveSystemAddressId,
String beginTime,
Integer duration) {
return Optional.of(internalReportFeign.checkLineJam(sendSystemAddressId,
receiveSystemAddressId,beginTime,duration))
.filter(Result::succeed)
.map(Result::getData)
.orElse(false);
}
@Override
public Boolean checkLineAbnormal(Integer sendSystemAddressId,
Integer receiveSystemAddressId,
String beginTime) {
return Optional.of(internalReportFeign.checkLineAbnormal(sendSystemAddressId,
receiveSystemAddressId,beginTime))
.filter(Result::succeed)
.map(Result::getData)
.orElse(false);
}
}
......@@ -33,6 +33,7 @@ public class LineWarnConfig implements HasKey<Integer> {
private BigDecimal interval; //预警间隔(小时)
private BigDecimal timeRatio; //时间占比(%)
private BigDecimal taskCompleteRatio; //任务完成占比
private Integer congestionTime; //拥堵时间(分钟)
private Integer deleteStatus; //删除状态: 0-否;1-是
private Integer status; //状态:1启用 2禁用
private String createBy; //创建人
......
......@@ -36,6 +36,7 @@ public class LineWarnInfo implements HasKey<Integer> {
private Integer receiveAddressId; //收货地址id
private String receiveAddress; //收货地址
private LocalDateTime suspendTime; //预警暂停时间
private String weather; //天气
private LocalDateTime warnTime; //预警时间
private Integer status; //处理状态:1待处理 2已处理 3暂停预警
private String createBy; //创建人
......
......@@ -37,6 +37,7 @@ public class LineWarnOrderGoods implements HasKey<Integer> {
private Integer loadNum; //装车车数
private Integer arriveReceiveNum; //到达目的地车数
private Integer unloadNum; //卸车车数
private LocalDateTime lastLineReportTime; //上次线路上报时间
private Integer status; //状态
private Integer warnStatus; //预警使能:0禁用 1启用
private LocalDateTime createTime; //创建时间
......
......@@ -26,6 +26,11 @@ public class LineWarnCommonServiceImpl implements LineWarnCommonService {
@Override
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){
......@@ -33,6 +38,7 @@ public class LineWarnCommonServiceImpl implements LineWarnCommonService {
LocalDateTime nextTime = lineWarnInfo.getWarnTime().plusMinutes(lineWarnConfig.getInterval().multiply(new BigDecimal(MIN_FER_HOUR)).intValue());
if (nextTime.isAfter(LocalDateTime.now())) {return;}
lineWarnInfo.setWeather(weather);
lineWarnInfo.setWarnTime(LocalDateTime.now());
lineWarnInfoDao.updateWarnTime(lineWarnInfo);
......@@ -54,6 +60,7 @@ public class LineWarnCommonServiceImpl implements LineWarnCommonService {
lineWarnInfo.setReceiveAddressId(orderGoods.getReceiveAddressId());
lineWarnInfo.setReceiveAddress(orderGoods.getReceiveAddressShorter());
lineWarnInfo.setWeather(weather);
lineWarnInfo.setWarnTime(LocalDateTime.now());
lineWarnInfoDao.saveEntity(lineWarnInfo);
......
package com.clx.performance.service.impl.linewarn;
import com.clx.performance.dao.linewarn.LineWarnConfigDao;
import com.clx.performance.dao.linewarn.LineWarnInfoDao;
import com.clx.performance.dto.linewarn.LineWarnCommonInfoDTO;
import com.clx.performance.enums.linewarn.LineWarnConfigEnum;
import com.clx.performance.enums.linewarn.LineWarnInfoEnum;
import com.clx.performance.extranal.order.InternalReportService;
import com.clx.performance.model.OrderGoods;
import com.clx.performance.model.linewarn.LineWarnConfig;
import com.clx.performance.model.linewarn.LineWarnInfo;
import com.clx.performance.service.linewarn.LineWarnCommonService;
import com.clx.performance.service.linewarn.LineWarnCongestionWarnService;
import com.clx.performance.utils.LocalDateTimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
@Slf4j
@Service
public class LineWarnCongestionWarnServiceImpl implements LineWarnCongestionWarnService {
// 默认监控时间
private static final int DEFAULT_TIME = 5;
@Autowired
private LineWarnConfigDao lineWarnConfigDao;
@Autowired
private InternalReportService internalReportService;
@Autowired
private LineWarnCommonService lineWarnCommonService;
@Autowired
private LineWarnInfoDao lineWarnInfoDao;
@Override
public void congestionWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo) {
LocalDateTime beginTime = LocalDateTime.now().minusMinutes(DEFAULT_TIME);
List<LineWarnConfig> lineWarnConfigList = lineWarnConfigDao
.listByWarnType(LineWarnConfigEnum.WarnType.CONGESTION.getCode());
if (lineWarnConfigList.isEmpty()) {return;}
for (LineWarnConfig item : lineWarnConfigList) {
doCongestionWarn(orderGoods, item, beginTime);
}
}
private void doCongestionWarn(OrderGoods orderGoods, LineWarnConfig lineWarnConfig, LocalDateTime beginTime){
LineWarnInfo lineWarnInfo = lineWarnInfoDao
.findByOrderGoodsNoAndWarnConfigId(orderGoods.getOrderGoodsNo(), lineWarnConfig.getId()).orNull();
if (lineWarnInfo != null
&& Objects.equals(lineWarnInfo.getStatus(), LineWarnInfoEnum.Status.RESOLVE.getCode())){
return;
}
// 检测是否拥堵
Boolean flag = internalReportService.checkLineJam(orderGoods.getSendSystemAddressId(),
orderGoods.getReceiveSystemAddressId(),
LocalDateTimeUtils.formatTime(beginTime), lineWarnConfig.getCongestionTime());
if (!flag) {return;}
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig);
}
}
package com.clx.performance.service.impl.linewarn;
import com.clx.performance.dto.linewarn.LineWarnCommonInfoDTO;
import com.clx.performance.model.OrderGoods;
import com.clx.performance.service.linewarn.LineWarnJamWarnService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class LineWarnJamWarnServiceImpl implements LineWarnJamWarnService {
@Override
public void jamWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo) {
}
}
package com.clx.performance.service.impl.linewarn;
import com.clx.performance.dao.linewarn.LineWarnConfigDao;
import com.clx.performance.dao.linewarn.LineWarnInfoDao;
import com.clx.performance.dto.linewarn.LineWarnCommonInfoDTO;
import com.clx.performance.enums.linewarn.LineWarnConfigEnum;
import com.clx.performance.enums.linewarn.LineWarnInfoEnum;
import com.clx.performance.extranal.order.InternalReportService;
import com.clx.performance.model.OrderGoods;
import com.clx.performance.model.linewarn.LineWarnConfig;
import com.clx.performance.model.linewarn.LineWarnInfo;
import com.clx.performance.service.linewarn.LineWarnCommonService;
import com.clx.performance.service.linewarn.LineWarnLineWarnService;
import com.clx.performance.utils.LocalDateTimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
@Slf4j
@Service
public class LineWarnLineWarnServiceImpl implements LineWarnLineWarnService {
// 默认监控时间
private static final int DEFAULT_TIME = 5;
@Autowired
private LineWarnConfigDao lineWarnConfigDao;
@Autowired
private LineWarnInfoDao lineWarnInfoDao;
@Autowired
private InternalReportService internalReportService;
@Autowired
private LineWarnCommonService lineWarnCommonService;
@Override
public void lineWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo) {
public void lineAbnormalWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo) {
LocalDateTime beginTime = LocalDateTime.now().minusMinutes(DEFAULT_TIME);
List<LineWarnConfig> lineWarnConfigList = lineWarnConfigDao
.listByWarnType(LineWarnConfigEnum.WarnType.LINE_ABNORMAL.getCode());
if (lineWarnConfigList.isEmpty()) {return;}
for (LineWarnConfig item : lineWarnConfigList) {
doLineAbnormalWarn(orderGoods, item, beginTime);
}
}
private void doLineAbnormalWarn(OrderGoods orderGoods, LineWarnConfig lineWarnConfig, LocalDateTime beginTime){
LineWarnInfo lineWarnInfo = lineWarnInfoDao
.findByOrderGoodsNoAndWarnConfigId(orderGoods.getOrderGoodsNo(), lineWarnConfig.getId()).orNull();
if (lineWarnInfo != null
&& Objects.equals(lineWarnInfo.getStatus(), LineWarnInfoEnum.Status.RESOLVE.getCode())){
return;
}
// 检测线路是否异常
Boolean flag = internalReportService.checkLineAbnormal(orderGoods.getSendSystemAddressId(),
orderGoods.getReceiveSystemAddressId(),
LocalDateTimeUtils.formatTime(beginTime));
if (!flag) {return;}
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig);
}
}
......@@ -48,7 +48,7 @@ public class LineWarnMqHandlerServiceImpl implements LineWarnMqHandlerService {
@Autowired
private LineWarnLoadWarnService lineWarnLoadWarnService;
@Autowired
private LineWarnJamWarnService lineWarnJamWarnService;
private LineWarnCongestionWarnService lineWarnCongestionWarnService;
@Autowired
private LineWarnWeatherWarnService lineWarnWeatherWarnService;
@Autowired
......@@ -59,6 +59,7 @@ public class LineWarnMqHandlerServiceImpl implements LineWarnMqHandlerService {
private OrderChildDao orderChildDao;
@Override
public void orderGoodsAdd(LineWarnOrderGoodsAddMqParam mq) {
OrderGoods orderGoods = orderGoodsDao
......@@ -126,13 +127,6 @@ public class LineWarnMqHandlerServiceImpl implements LineWarnMqHandlerService {
log.info("卸车预警异常,msg:{}", e.getMessage());
}
// 拥堵预警
try{
lineWarnJamWarnService.jamWarn(orderGoods, lineWarnCommonInfo);
}catch (Exception e){
log.info("拥堵预警异常,msg:{}", e.getMessage());
}
// 天气预警
try{
lineWarnWeatherWarnService.weatherWarn(orderGoods, lineWarnCommonInfo);
......@@ -147,16 +141,25 @@ public class LineWarnMqHandlerServiceImpl implements LineWarnMqHandlerService {
log.info("运单异常异常,msg:{}", e.getMessage());
}
// 拥堵预警
try {
lineWarnCongestionWarnService.congestionWarn(orderGoods, lineWarnCommonInfo);
} catch (Exception e) {
log.info("拥堵预警异常,msg:{}", e.getMessage());
}
// 线路异常
try{
lineWarnLineWarnService.lineWarn(orderGoods, lineWarnCommonInfo);
}catch (Exception e){
log.info("运单异常异常,msg:{}", e.getMessage());
try {
lineWarnLineWarnService.lineAbnormalWarn(orderGoods, lineWarnCommonInfo);
} catch (Exception e) {
log.info("线路异常,msg:{}", e.getMessage());
}
}
@Override
public void notice(LineWarnNoticeMqParam mq) {
}
}
......@@ -57,16 +57,20 @@ public class LineWarnMqServiceImpl implements LineWarnMqService {
}
@Override
public void lineReport(Integer sendSystemAddressId, Integer receiveSystemAddressId, Integer reportType) {
public void lineReport(Integer sendSystemAddressId, Integer receiveSystemAddressId,
Integer reportType, Integer estimatedTravelTime) {
LineWarnLineReportMqParam mq = new LineWarnLineReportMqParam();
mq.setSendSystemAddressId(sendSystemAddressId);
mq.setReceiveSystemAddressId(receiveSystemAddressId);
mq.setReportType(reportType);
mq.setEstimatedTravelTime(estimatedTravelTime);
MqDelay delay = new MqDelay<>(RabbitKeyLineWarnConstants.DEFAULT_EXCHANGE, RabbitKeyLineWarnConstants.LINE_WARN_LINE_REPORT_ROUTING_KEY, new MqWrapper<>(mq));
MqDelay delay = new MqDelay<>(RabbitKeyLineWarnConstants.DEFAULT_EXCHANGE,
RabbitKeyLineWarnConstants.LINE_WARN_LINE_REPORT_ROUTING_KEY, new MqWrapper<>(mq));
Message message = MessageBuilder.withBody(JSON.toJSONString(new MqWrapper<>(delay)).getBytes()).build();
message.getMessageProperties().setExpiration("5000");
rabbitTemplate.send(RabbitKeyLineWarnConstants.DEFAULT_EXCHANGE, RabbitKeyLineWarnConstants.DEFAULT_DELAY_ROUTING_KEY, message);
rabbitTemplate.send(RabbitKeyLineWarnConstants.DEFAULT_EXCHANGE,
RabbitKeyLineWarnConstants.DEFAULT_DELAY_ROUTING_KEY, message);
}
}
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.LineWarnInfoDao;
import com.clx.performance.dto.linewarn.LineWarnCommonInfoDTO;
import com.clx.performance.enums.linewarn.LineWarnConfigEnum;
import com.clx.performance.enums.linewarn.LineWarnInfoEnum;
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.linewarn.LineWarnConfig;
import com.clx.performance.model.linewarn.LineWarnInfo;
import com.clx.performance.service.linewarn.LineWarnCommonService;
import com.clx.performance.service.linewarn.LineWarnWeatherWarnService;
import com.clx.performance.utils.gd.GdUtils;
import com.msl.common.base.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
@Slf4j
@Service
public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnService {
@Autowired
private LineWarnConfigDao lineWarnConfigDao;
@Autowired
private InternalReportService internalReportService;
@Autowired
private LineWarnCommonService lineWarnCommonService;
@Autowired
private LineWarnInfoDao lineWarnInfoDao;
@Autowired
private GdUtils gdUtils;
@Autowired
private AddressService addressService;
@Override
public void weatherWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo) {
List<LineWarnConfig> lineWarnConfigList = lineWarnConfigDao
.listByWarnType(LineWarnConfigEnum.WarnType.WEATHER.getCode());
if (lineWarnConfigList.isEmpty()) {return;}
for (LineWarnConfig item : lineWarnConfigList) {
doWeather(orderGoods, item);
}
}
private void doWeather(OrderGoods orderGoods, LineWarnConfig lineWarnConfig){
LineWarnInfo lineWarnInfo = lineWarnInfoDao
.findByOrderGoodsNoAndWarnConfigId(orderGoods.getOrderGoodsNo(), lineWarnConfig.getId()).orNull();
if (lineWarnInfo != null
&& Objects.equals(lineWarnInfo.getStatus(), LineWarnInfoEnum.Status.RESOLVE.getCode())){
return;
}
Optional<FeignAddressVO> addressOptional = addressService
.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 {
void lineWarnInfoUpdate(OrderGoods orderGoods, LineWarnInfo lineWarnInfo, LineWarnConfig lineWarnConfig);
void lineWarnInfoUpdate(OrderGoods orderGoods, LineWarnInfo lineWarnInfo, LineWarnConfig lineWarnConfig, String weather);
}
......@@ -3,8 +3,8 @@ package com.clx.performance.service.linewarn;
import com.clx.performance.dto.linewarn.LineWarnCommonInfoDTO;
import com.clx.performance.model.OrderGoods;
public interface LineWarnJamWarnService {
public interface LineWarnCongestionWarnService {
void jamWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo);
void congestionWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo);
}
......@@ -5,6 +5,6 @@ import com.clx.performance.model.OrderGoods;
public interface LineWarnLineWarnService {
void lineWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo);
void lineAbnormalWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo);
}
......@@ -11,4 +11,5 @@ public interface LineWarnMqHandlerService {
void lineWarn(LineWarnLineWarnMqParam mq);
void notice(LineWarnNoticeMqParam mq);
}
......@@ -8,5 +8,6 @@ public interface LineWarnMqService {
void lineWarnNotice(Integer infoId);
void lineReport(Integer sendSystemAddressId, Integer receiveSystemAddressId, Integer reportType);
void lineReport(Integer sendSystemAddressId, Integer receiveSystemAddressId,
Integer reportType, Integer estimatedTravelTime);
}
......@@ -33,6 +33,7 @@ public class GdService {
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";
......@@ -356,4 +357,52 @@ public class GdService {
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 {
return GpsUtil.distanceM(currentPosition[0], currentPosition[1], destinationLongitude, destinationLatitude);
}
/**
* 天气
*/
public String getWeather(String city){
return gdService.getWeather(city);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论