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

线路预警

上级 25ad987c
......@@ -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;
......
......@@ -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.clx.performance.service.linewarn.LineWarnMqService;
import com.msl.common.result.Result;
import io.swagger.annotations.ApiOperation;
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.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 {
@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);
return Result.ok();
}
}
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; //创建人
......
......@@ -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; //创建时间
......
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.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.LineWarnWeatherWarnService;
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 LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnService {
@Autowired
private LineWarnConfigDao lineWarnConfigDao;
@Autowired
private InternalReportService internalReportService;
@Autowired
private LineWarnCommonService lineWarnCommonService;
@Autowired
private LineWarnInfoDao lineWarnInfoDao;
@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;
}
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig);
}
}
......@@ -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);
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论