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

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

package com.clx.performance.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public enum OrderEnum {
;
//订单状态: 0待报价 1客户确认中 2报价已确认 3平台已承接 4已取消 5暂停 6拒绝承运 7 挂单中 8运输中 9订单已完成 10 已失效
@Getter
@AllArgsConstructor
public enum Status {
WAIT_QUOTATION(0, "待报价"),
CUSTOMER_CONFIRMING(1, "客户确认中"),
QUOTATION_CONFIRMED(2, "报价已确认"),
PLATFORM_UNDERTAKING(3, "平台已承接"),
CANCELED(4, "已取消"),
SUSPEND(5, "暂停"),
REFUSAL_TO_CARRY(6, "拒绝承运"),
ON_ORDER(7, "挂单中"),
IN_TRANSIT(8, "运输中"),
SUCCESS(9, "订单已完成"),
EXPIRED(10, "已失效"),
POST_ORDER(11, "已挂单"),
COMPLETED(12,"已完结")
;
private final Integer code;
private final String name;
public static Status getByCode(int code) {
for(Status type: Status.values()){
if(type.code == code){
return type;
}
}
return null;
}
}
//申请状态 1.申请 2.驳回 3.同意 4.过期'
@Getter
@AllArgsConstructor
public enum CancelApplyStatus {
APPLY(1, "申请"),
REJECT(2, "驳回"),
AGREE(3, "同意"),
EXPIRED(4, "过期");
private final int code;
private final String name;
public static Status getByCode(int code) {
for(Status type: Status.values()){
if(type.code == code){
return type;
}
}
return null;
}
}
//报价状态 2.确认报价 3.驳回报价 4.报价过期'
@Getter
@AllArgsConstructor
public enum QuotationStatus{
CONFIRM(2, "确认报价"),
REJECT(3, "驳回报价"),
EXPIRE(4, "报价过期");
private final int code;
private final String name;
public static QuotationStatus getByCode(Integer code) {
for(QuotationStatus type: QuotationStatus.values()){
if(type.code == code){
return type;
}
}
return null;
}
}
@Getter
@AllArgsConstructor
public enum OverWeight{
NO(0, "否"),
YES(1, "是");
private final Integer code;
private final String name;
public static OverWeight getByCode(Integer code) {
for(OverWeight type: OverWeight.values()){
if(Objects.equals(type.code,code)){
return type;
}
}
return null;
}
}
@Getter
@AllArgsConstructor
public enum ReportFlag{
NO(0, "否"),
YES(1, "是");
private final int code;
private final String name;
public static String getNameByCode(int code) {
for(ReportFlag type: ReportFlag.values()){
if(type.code == code){
return type.getName();
}
}
return null;
}
}
//预付运费标识 1:部分预付 2:全额预付
@Getter
@AllArgsConstructor
public enum PrepayFreightFlag{
PART(1, "部分预付"),
ALL(2, "全额预付");
private final Integer code;
private final String name;
public static String getByCode(Integer code) {
for(PrepayFreightFlag type: PrepayFreightFlag.values()){
if(Objects.equals(type.code,code)){
return type.getName();
}
}
return null;
}
}
public static final List<Integer> BORROW_TIP_STATUS_lIST = Arrays.asList(
Status.PLATFORM_UNDERTAKING.getCode(),
Status.ON_ORDER.getCode(),
Status.POST_ORDER.getCode(),
Status.IN_TRANSIT.getCode()
);
//外部系统可以修改数据的状态
public static final List<Integer> SYNC_ORDER_UPDATE_lIST = Arrays.asList(
Status.CUSTOMER_CONFIRMING.getCode(),
Status.QUOTATION_CONFIRMED.getCode(),
Status.PLATFORM_UNDERTAKING.getCode(),
Status.ON_ORDER.getCode(),
Status.POST_ORDER.getCode(),
Status.IN_TRANSIT.getCode()
);
}
......@@ -24,7 +24,7 @@ public enum VehicleWarnUserEnum {
@Getter
@AllArgsConstructor
public enum NoticeStatus {
NO(0, "禁用"),
NO(0, "关闭"),
YES(1, "开启"),
;
......
......@@ -99,7 +99,7 @@ public class RabbitLineWarnConfig {
}
@Bean
public Binding lineWarnLineReportQueueBinding() {
return BindingBuilder.bind(lineWarnNoticeQueue()).to(lineWarnDefaultExchange())
return BindingBuilder.bind(lineWarnLineReportQueue()).to(lineWarnDefaultExchange())
.with(RabbitKeyLineWarnConstants.LINE_WARN_LINE_REPORT_ROUTING_KEY);
}
......
......@@ -36,4 +36,10 @@ public class RedisConstants {
public static final String MESSAGE_RESET_PASSWORD_TOKEN = "message:resetpassword:token:";
/**
* 线路天气预警
*/
public static final String LINE_WARN_WEATHER = "clx-performance:lineWarn:weather:";
}
package com.clx.performance.controller.temp;
import com.clx.order.vo.feign.FeignAddressVO;
import com.clx.performance.extranal.user.AddressService;
import com.clx.performance.service.linewarn.LineWarnMqHandlerService;
import com.clx.performance.service.linewarn.LineWarnMqService;
import com.clx.performance.utils.gd.GdUtils;
import com.msl.common.base.Optional;
import com.msl.common.result.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
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;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: aiqingguo
* @Description: 临时接口
......@@ -22,6 +32,12 @@ public class TempLineWarnController {
@Autowired
private LineWarnMqService lineWarnMqService;
@Autowired
private AddressService addressService;
@Autowired
private GdUtils gdUtils;
@Autowired
private LineWarnMqHandlerService lineWarnMqHandlerService;
@ApiOperation(value = "test", notes = "<br>By:艾庆国")
@PostMapping("/test")
......@@ -45,5 +61,51 @@ public class TempLineWarnController {
lineWarnMqService.orderGoodsAdd(orderGoodsNo);
return Result.ok();
}
@ApiOperation(value = "天气", notes = "<br>By:艾庆国")
@PostMapping("/weather")
public Result<Map<String, String>> weather(Integer sendAddressId, Integer receiveAddressId) {
Map<String, String> result = new HashMap<>();
Optional<FeignAddressVO> addressOptional = addressService
.getSendAndReceiveAddress(sendAddressId, receiveAddressId);
if (addressOptional.isEmpty()) {return Result.ok(result);}
FeignAddressVO feignAddressVO = addressOptional.get();
if (feignAddressVO.getSendAddress()!=null){
String cityCode = gdUtils.getCity(feignAddressVO.getSendAddress().getLongitude(),
feignAddressVO.getSendAddress().getLatitude());
String weather = gdUtils.getWeather(cityCode);
result.put("send", weather);
}
if (feignAddressVO.getReceiveAddress()!=null){
String cityCode = gdUtils.getCity(feignAddressVO.getReceiveAddress().getLongitude(),
feignAddressVO.getReceiveAddress().getLatitude());
String weather = gdUtils.getWeather(cityCode);
result.put("receive", weather);
}
return Result.ok(result);
}
@ApiOperation(value = "发送预警短信", notes = "<br>By:艾庆国")
@PostMapping("/sendSms")
public Result sendSms(String mobile, String warnName, String orderGoodsNo) {
lineWarnMqHandlerService.sendSms(Arrays.asList(mobile), warnName, orderGoodsNo);
return Result.ok();
}
@ApiOperation(value = "发送预警外呼", notes = "<br>By:艾庆国")
@PostMapping("/sendClink")
public Result sendClink(String mobile, String warnName, String orderGoodsNo) {
lineWarnMqHandlerService.sendClink(Arrays.asList(mobile), warnName, orderGoodsNo);
return Result.ok();
}
}
......@@ -183,7 +183,7 @@ public interface OrderChildDao extends BaseDao<OrderChildMapper, OrderChild, Int
List<OrderChild> listByOrderGoodsNoAndStatus(String orderGoodsNo, List<Integer> statusList);
BigDecimal sumTakeWeightByOrderGoodsNo(String orderGoodsNo);
BigDecimal sumTakeWeightByOrderGoodsNo(String orderGoodsNo, BigDecimal defaultWeight);
BigDecimal sumLoadWeightByOrderGoodsNo(String orderGoodsNo);
BigDecimal sumUnloadWeightByOrderGoodsNo(String orderGoodsNo);
......
......@@ -578,8 +578,8 @@ public class OrderChildDaoImpl extends BaseDaoImpl<OrderChildMapper, OrderChild,
}
@Override
public BigDecimal sumTakeWeightByOrderGoodsNo(String orderGoodsNo) {
return baseMapper.sumTakeWeightByOrderGoodsNo(orderGoodsNo);
public BigDecimal sumTakeWeightByOrderGoodsNo(String orderGoodsNo, BigDecimal defaultWeight) {
return baseMapper.sumTakeWeightByOrderGoodsNo(orderGoodsNo, defaultWeight);
}
@Override
......
......@@ -27,6 +27,7 @@ public class LineWarnConfigDaoImpl extends BaseDaoImpl<LineWarnConfigMapper, Lin
.set(LineWarnConfig::getInterval, item.getInterval())
.set(LineWarnConfig::getTimeRatio, item.getTimeRatio())
.set(LineWarnConfig::getTaskCompleteRatio, item.getTaskCompleteRatio())
.set(LineWarnConfig::getCongestionTime, item.getCongestionTime())
);
}
......
......@@ -38,7 +38,7 @@ public class LineWarnInfoDaoImpl extends BaseDaoImpl<LineWarnInfoMapper, LineWar
public boolean updateSuspendTime(LineWarnInfo item) {
return update(lUdWrapper()
.eq(LineWarnInfo::getWarnConfigId, item.getWarnConfigId())
.eq(LineWarnInfo::getId, item.getId())
.ne(LineWarnInfo::getStatus, LineWarnInfoEnum.Status.RESOLVE.getCode())
.set(LineWarnInfo::getSuspendTime, item.getSuspendTime())
);
......
......@@ -122,38 +122,47 @@ public interface OrderChildMapper extends BaseMapper<OrderChild> {
@SelectProvider(type = OrderChildSqlProvider.class, method = "statisticsTruckMonth")
MonthInComeAndOrderedVO statisticsTruckMonth(@Param("startTime")LocalDateTime startTime, @Param("endTime")LocalDateTime endTime, @Param("truckNo")String truckNo);
@Select("select sum(weight) from order_child where order_goods_no=#{orderGoodsNo} and status in(10,20,30,40,50,60,70,80,90,100)")
BigDecimal sumTakeWeightByOrderGoodsNo(String orderGoodsNo);
@Select("select sum(if (status>=50, load_net, #{defaultWeight})) from order_child " +
" where order_goods_no=#{orderGoodsNo} and status in(10,20,30,40,50,60,70,80,90,100)")
BigDecimal sumTakeWeightByOrderGoodsNo(String orderGoodsNo, BigDecimal defaultWeight);
@Select("select sum(weight) from order_child where order_goods_no=#{orderGoodsNo} and status in(50,60,70,80,90,100)")
@Select("select sum(load_net) from order_child " +
" where order_goods_no=#{orderGoodsNo} and status in(50,60,70,80,90,100)")
BigDecimal sumLoadWeightByOrderGoodsNo(String orderGoodsNo);
@Select("select sum(weight) from order_child where order_goods_no=#{orderGoodsNo} and status in(80,90,100)")
@Select("select sum(if (unload_net>load_net, load_net, unload_net)) from order_child " +
" where order_goods_no=#{orderGoodsNo} and status in(80,90,100)")
BigDecimal sumUnloadWeightByOrderGoodsNo(String orderGoodsNo);
@Select("<script>select order_goods_no, count(*) num from order_child where status in(10,20,30,40,50,60,70,80,90,100) " +
" and order_goods_no in <foreach collection='list' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
@Select("<script>select order_goods_no, count(*) num from order_child " +
" where status in(10,20,30,40,50,60,70,80,90,100) " +
" and order_goods_no " +
" in <foreach collection='list' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
" group by order_goods_no " +
"</script>")
List<LineWarnOrderChildStatisticsDTO>sumTakeNumByOrderGoodsNoList(List<String> orderGoodsNoList);
@Select("<script>select order_goods_no, count(*) num from order_child where status in(40,50,60,70,80,90,100) " +
" and order_goods_no in <foreach collection='list' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
" and order_goods_no " +
" in <foreach collection='list' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
" group by order_goods_no " +
"</script>")
List<LineWarnOrderChildStatisticsDTO>sumArriveSendNumByOrderGoodsNoList(List<String> orderGoodsNoList);
@Select("<script>select order_goods_no, count(*) num from order_child where status in(50,60,70,80,90,100) " +
" and order_goods_no in <foreach collection='list' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
" and order_goods_no " +
" in <foreach collection='list' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
" group by order_goods_no " +
"</script>")
List<LineWarnOrderChildStatisticsDTO>sumLoadNumByOrderGoodsNoList(List<String> orderGoodsNoList);
@Select("<script>select order_goods_no, count(*) num from order_child where status in(70,80,90,100) " +
" and order_goods_no in <foreach collection='list' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
" and order_goods_no " +
" in <foreach collection='list' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
" group by order_goods_no " +
"</script>")
List<LineWarnOrderChildStatisticsDTO>sumArriveRecieveNumByOrderGoodsNoList(List<String> orderGoodsNoList);
@Select("<script>select order_goods_no, count(*) num from order_child where status in(80,90,100) " +
" and order_goods_no in <foreach collection='list' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
" and order_goods_no " +
" in <foreach collection='list' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
" group by order_goods_no " +
"</script>")
List<LineWarnOrderChildStatisticsDTO>sumUnloadNumByOrderGoodsNoList(List<String> orderGoodsNoList);
......
......@@ -68,4 +68,18 @@ public class LineWarnCommonServiceImpl implements LineWarnCommonService {
lineWarnMqService.lineWarnNotice(lineWarnInfo.getId());
}
/**
* 暂停检测
*/
@Override
public boolean suspendCheck(LineWarnInfo lineWarnInfo){
if (lineWarnInfo == null) {return false;}
if (lineWarnInfo.getSuspendTime() != null && lineWarnInfo.getSuspendTime().isAfter(LocalDateTime.now())){
return true;
}
return false;
}
}
......@@ -2,9 +2,11 @@ package com.clx.performance.service.impl.linewarn;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.clx.performance.dao.linewarn.LineWarnConfigDao;
import com.clx.performance.dao.linewarn.LineWarnInfoDao;
import com.clx.performance.enums.ResultEnum;
import com.clx.performance.enums.linewarn.LineWarnConfigEnum;
import com.clx.performance.model.linewarn.LineWarnConfig;
import com.clx.performance.model.vehiclewarn.VehicleWarnInfo;
import com.clx.performance.param.pc.linewarn.*;
import com.clx.performance.service.linewarn.LineWarnConfigService;
import com.clx.performance.struct.linewarn.LineWarnConfigStruct;
......@@ -32,6 +34,9 @@ public class LineWarnConfigServiceImpl implements LineWarnConfigService {
@Autowired
private LineWarnConfigStruct lineWarnConfigStruct;
@Autowired
private LineWarnInfoDao lineWarnInfoDao;
@Transactional(rollbackFor = Exception.class)
@Override
public void saveConfig(LineWarnConfigAddParam param) {
......@@ -77,6 +82,11 @@ public class LineWarnConfigServiceImpl implements LineWarnConfigService {
lineWarnConfig.setTaskCompleteRatio(param.getTaskCompleteRatio());
lineWarnConfig.setCongestionTime(param.getCongestionTime());
lineWarnConfigDao.updateConfig(lineWarnConfig);
// 同步历史数据
VehicleWarnInfo vehicleWarnInfo = new VehicleWarnInfo();
lineWarnInfoDao.updateByConfig(lineWarnConfig.getId()
, lineWarnConfig.getWarnName(), lineWarnConfig.getWarnLevel());
}
@Transactional(rollbackFor = Exception.class)
@Override
......
......@@ -57,6 +57,10 @@ public class LineWarnCongestionWarnServiceImpl implements LineWarnCongestionWarn
return;
}
// 暂停检测
boolean suspend = lineWarnCommonService.suspendCheck(lineWarnInfo);
if (suspend) {return;}
// 检测是否拥堵
Boolean flag = internalReportService.checkLineJam(orderGoods.getSendSystemAddressId(),
orderGoods.getReceiveSystemAddressId(),
......
......@@ -3,6 +3,7 @@ package com.clx.performance.service.impl.linewarn;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clx.performance.dao.OrderChildDao;
import com.clx.performance.dao.OrderGoodsDao;
import com.clx.performance.dao.linewarn.LineWarnInfoDao;
import com.clx.performance.dao.linewarn.LineWarnLogDao;
import com.clx.performance.dao.linewarn.LineWarnRangeDao;
......@@ -11,6 +12,7 @@ import com.clx.performance.enums.ResultEnum;
import com.clx.performance.enums.linewarn.LineWarnInfoEnum;
import com.clx.performance.enums.linewarn.LineWarnLogEnum;
import com.clx.performance.enums.linewarn.LineWarnRangEnum;
import com.clx.performance.model.OrderGoods;
import com.clx.performance.model.linewarn.LineWarnInfo;
import com.clx.performance.model.linewarn.LineWarnLog;
import com.clx.performance.model.linewarn.LineWarnRange;
......@@ -49,6 +51,8 @@ public class LineWarnInfoServiceImpl implements LineWarnInfoService {
@Autowired
private OrderChildDao orderChildDao;
@Autowired
private OrderGoodsDao orderGoodsDao;
@Transactional(rollbackFor = Exception.class)
@Override
......@@ -120,12 +124,15 @@ public class LineWarnInfoServiceImpl implements LineWarnInfoService {
// 更新车数统计数据
List<String> orderGoodsNoList = page.getRecords().stream().map(item -> item.getOrderGoodsNo()).collect(Collectors.toList());
if (!orderGoodsNoList.isEmpty()) {
List<OrderGoods> pengList = orderGoodsDao.selectListByOrderGoodsList(orderGoodsNoList);
List<LineWarnOrderChildStatisticsDTO> takeList = orderChildDao.sumTakeNumByOrderGoodsNoList(orderGoodsNoList);
List<LineWarnOrderChildStatisticsDTO> sendList = orderChildDao.sumArriveSendNumByOrderGoodsNoList(orderGoodsNoList);
List<LineWarnOrderChildStatisticsDTO> loadList = orderChildDao.sumLoadNumByOrderGoodsNoList(orderGoodsNoList);
List<LineWarnOrderChildStatisticsDTO> receiveList = orderChildDao.sumArriveRecieveNumByOrderGoodsNoList(orderGoodsNoList);
List<LineWarnOrderChildStatisticsDTO> unloadList = orderChildDao.sumUnloadNumByOrderGoodsNoList(orderGoodsNoList);
Map<String, OrderGoods> pengMap = pengList.stream().collect(Collectors.toMap(item -> item.getOrderGoodsNo(), item -> item));
Map<String, LineWarnOrderChildStatisticsDTO> takeMap = takeList.stream().collect(Collectors.toMap(item -> item.getOrderGoodsNo(), item -> item));
Map<String, LineWarnOrderChildStatisticsDTO> sendMap = sendList.stream().collect(Collectors.toMap(item -> item.getOrderGoodsNo(), item -> item));
Map<String, LineWarnOrderChildStatisticsDTO> loadMap = loadList.stream().collect(Collectors.toMap(item -> item.getOrderGoodsNo(), item -> item));
......@@ -133,6 +140,7 @@ public class LineWarnInfoServiceImpl implements LineWarnInfoService {
Map<String, LineWarnOrderChildStatisticsDTO> unloadMap = unloadList.stream().collect(Collectors.toMap(item -> item.getOrderGoodsNo(), item -> item));
for (LineWarnInfoVO item : page.getRecords()) {
item.setPengNum(pengMap.get(item.getOrderGoodsNo()) == null? 0:pengMap.get(item.getOrderGoodsNo()).getNeedTruckNum());
item.setTakeNum(takeMap.get(item.getOrderGoodsNo()) == null? 0:takeMap.get(item.getOrderGoodsNo()).getNum());
item.setArriveSendNum(sendMap.get(item.getOrderGoodsNo()) == null? 0:sendMap.get(item.getOrderGoodsNo()).getNum());
item.setLoadNum(loadMap.get(item.getOrderGoodsNo()) == null? 0:loadMap.get(item.getOrderGoodsNo()).getNum());
......
......@@ -55,6 +55,10 @@ public class LineWarnLineWarnServiceImpl implements LineWarnLineWarnService {
return;
}
// 暂停检测
boolean suspend = lineWarnCommonService.suspendCheck(lineWarnInfo);
if (suspend) {return;}
// 检测线路是否异常
Boolean flag = internalReportService.checkLineAbnormal(orderGoods.getSendSystemAddressId(),
orderGoods.getReceiveSystemAddressId(),
......
......@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Arrays;
......@@ -47,6 +48,8 @@ public class LineWarnLoadWarnServiceImpl implements LineWarnLoadWarnService {
int needTime = unloadTimeAvg+arriveReceiveExpectTime;
// 接单最长时间
long difTime = totalTime - needTime;
if (difTime < 0){difTime = 0;}
// 任务量
BigDecimal taskWeight = lineWarnCommonInfo.getTaskWeight();
......@@ -54,8 +57,9 @@ public class LineWarnLoadWarnServiceImpl implements LineWarnLoadWarnService {
BigDecimal taskCompleteRatio = BigDecimal.ZERO;
BigDecimal weight = orderChildDao.sumLoadWeightByOrderGoodsNo(orderGoods.getOrderGoodsNo());
if (weight != null){
taskCompleteRatio = weight.divide(taskWeight, 4, BigDecimal.ROUND_UP).movePointRight(2);
taskCompleteRatio = weight.divide(taskWeight, 4, RoundingMode.UP).movePointRight(2);
}
log.info("装车预警,任务量:{}, 完成量:{}, 任务完成率:{}, 总时间:{}, 需要时间:{}, 相差时间:{}", taskWeight, weight, taskCompleteRatio, totalTime, needTime, difTime);
List<LineWarnConfig> lineWarnConfigList = lineWarnConfigDao
.listByWarnType(LineWarnConfigEnum.WarnType.LOAD.getCode());
......@@ -76,12 +80,16 @@ public class LineWarnLoadWarnServiceImpl implements LineWarnLoadWarnService {
return;
}
int time = lineWarnConfig.getTimeRatio().multiply(new BigDecimal(difTime)).intValue();
// 暂停检测
boolean suspend = lineWarnCommonService.suspendCheck(lineWarnInfo);
if (suspend) {return;}
int time = lineWarnConfig.getTimeRatio().multiply(new BigDecimal(difTime)).movePointLeft(2).intValue();
// 未达到时间占比
if (pendingOrderTime.plusMinutes(time).isAfter(LocalDateTime.now())){return;}
// 达到任务占比
if (lineWarnConfig.getTaskCompleteRatio().compareTo(taskCompleteRatio) >= 0) {return;}
if (lineWarnConfig.getTaskCompleteRatio().compareTo(taskCompleteRatio) < 0) {return;}
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig);
......
......@@ -47,6 +47,7 @@ public class LineWarnMqHandlerServiceImpl implements LineWarnMqHandlerService {
// 缺省装卸车时间
private static final int DEFAULT_LOAD_UNLOAD_TIME = 60;
private static final int DEFAULT_LOAD_UNLOAD_DAY = 7;
private static final int SECOND_PER_MIN = 60;
@Autowired
private ClxMessageConfig clxMessageConfig;
......@@ -94,14 +95,14 @@ public class LineWarnMqHandlerServiceImpl implements LineWarnMqHandlerService {
.getOrderInfo(orderGoods.getOrderNo()).orElseThrow(ResultEnum.DATA_NOT_FIND);
// 计算货源地到
int arriveSendExpectTime = gdUtils.getNeedTime(new BigDecimal[]{orderGoods.getSendLongitude(),
int arriveReceiveExpectTime = gdUtils.getNeedTime(new BigDecimal[]{orderGoods.getSendLongitude(),
orderGoods.getSendLatitude()}, orderGoods.getReceiveLongitude(), orderGoods.getReceiveLatitude());
LineWarnOrderGoods lineWarnOrderGoods = new LineWarnOrderGoods();
lineWarnOrderGoods.setOrderGoodsNo(orderGoods.getOrderGoodsNo());
lineWarnOrderGoods.setTransportEndTime(LocalDateTimeUtils.parseTime(orderInfo.getTransportEndTime()));
lineWarnOrderGoods.setPendingOrderTime(orderGoods.getPendingOrderTime());
lineWarnOrderGoods.setArriveReceiveExpectTime(arriveSendExpectTime==0? null : arriveSendExpectTime);
lineWarnOrderGoods.setArriveReceiveExpectTime(arriveReceiveExpectTime==0? null : arriveReceiveExpectTime);
lineWarnOrderGoodsDao.saveEntity(lineWarnOrderGoods);
}
......@@ -126,12 +127,18 @@ public class LineWarnMqHandlerServiceImpl implements LineWarnMqHandlerService {
.loadTimeAvg(orderGoods.getSendAddressId(), orderGoods.getReceiveAddressId(),
orderGoods.getSendSystemAddressId(), orderGoods.getReceiveSystemAddressId(),
LocalDateTimeUtils.formatTime(LocalDateTime.now().minusDays(DEFAULT_LOAD_UNLOAD_DAY)));
if (loadTimeAvg == null) {loadTimeAvg = DEFAULT_LOAD_UNLOAD_TIME;}
else {loadTimeAvg = loadTimeAvg/SECOND_PER_MIN;}
Integer unloadTimeAvg = orderChildDao
.unloadTimeAvg(orderGoods.getSendAddressId(), orderGoods.getReceiveAddressId(),
orderGoods.getSendSystemAddressId(), orderGoods.getReceiveSystemAddressId(),
LocalDateTimeUtils.formatTime(LocalDateTime.now().minusDays(DEFAULT_LOAD_UNLOAD_DAY)));
lineWarnCommonInfo.setLoadTimeAvg(loadTimeAvg!=null? loadTimeAvg:DEFAULT_LOAD_UNLOAD_TIME);
lineWarnCommonInfo.setUnloadTimeAvg(unloadTimeAvg!=null? unloadTimeAvg:DEFAULT_LOAD_UNLOAD_TIME);
if (unloadTimeAvg == null) {unloadTimeAvg = DEFAULT_LOAD_UNLOAD_TIME;}
else {unloadTimeAvg = unloadTimeAvg/SECOND_PER_MIN;}
lineWarnCommonInfo.setLoadTimeAvg(loadTimeAvg);
lineWarnCommonInfo.setUnloadTimeAvg(unloadTimeAvg);
log.info("线路预警, lineWarnCommonInfo:{}", lineWarnCommonInfo);
......@@ -254,6 +261,7 @@ public class LineWarnMqHandlerServiceImpl implements LineWarnMqHandlerService {
ClinkMessageReq req = new ClinkMessageReq();
StringBuilder sb = new StringBuilder();
sb.append("触发");
sb.append(warnName);
sb.append("预警;货单");
......
......@@ -30,7 +30,7 @@ public class LineWarnOrderChildWarnServiceImpl implements LineWarnOrderChildWarn
@Override
public void orderChildWarn(OrderGoods orderGoods) {
List<LineWarnConfig> lineWarnConfigList = lineWarnConfigDao
.listByWarnType(LineWarnConfigEnum.WarnType.UNLOAD.getCode());
.listByWarnType(LineWarnConfigEnum.WarnType.CHILD_ABNORMAL.getCode());
if (lineWarnConfigList.isEmpty()) {return;}
for (LineWarnConfig item : lineWarnConfigList) {
......@@ -46,6 +46,10 @@ public class LineWarnOrderChildWarnServiceImpl implements LineWarnOrderChildWarn
return;
}
// 暂停检测
boolean suspend = lineWarnCommonService.suspendCheck(lineWarnInfo);
if (suspend) {return;}
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig);
}
......
package com.clx.performance.service.impl.linewarn;
import com.clx.order.vo.feign.FeignOrderInfoVO;
import com.clx.performance.dao.OrderChildDao;
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.dto.linewarn.LineWarnOrderChildStatisticsDTO;
import com.clx.performance.enums.OrderEnum;
import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.enums.linewarn.LineWarnConfigEnum;
import com.clx.performance.enums.linewarn.LineWarnInfoEnum;
import com.clx.performance.extranal.user.OrderService;
import com.clx.performance.model.OrderGoods;
import com.clx.performance.model.linewarn.LineWarnConfig;
import com.clx.performance.model.linewarn.LineWarnInfo;
......@@ -17,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Arrays;
......@@ -28,6 +33,8 @@ import java.util.Objects;
public class LineWarnTakeWarnServiceImpl implements LineWarnTakeWarnService {
// 默认时间
private static final int DEFAULT_TIME = 60;
private static final BigDecimal OVER_WEIGHT = new BigDecimal(50);
private static final BigDecimal STANDARD_WEIGHT = new BigDecimal(35);
@Autowired
private LineWarnConfigDao lineWarnConfigDao;
@Autowired
......@@ -36,6 +43,8 @@ public class LineWarnTakeWarnServiceImpl implements LineWarnTakeWarnService {
private LineWarnCommonService lineWarnCommonService;
@Autowired
private OrderChildDao orderChildDao;
@Autowired
private OrderService orderService;
@Override
public void takeWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo) {
......@@ -49,16 +58,25 @@ public class LineWarnTakeWarnServiceImpl implements LineWarnTakeWarnService {
int needTime = DEFAULT_TIME+loadTimeAvg+unloadTimeAvg+arriveReceiveExpectTime;
// 接单最长时间
long difTime = totalTime - needTime;
if (difTime < 0){difTime = 0;}
// 任务量
BigDecimal taskWeight = lineWarnCommonInfo.getTaskWeight();
// 任务完成率
BigDecimal taskCompleteRatio = BigDecimal.ZERO;
BigDecimal weight = orderChildDao.sumTakeWeightByOrderGoodsNo(orderGoods.getOrderGoodsNo());
if (weight != null){
taskCompleteRatio = weight.divide(taskWeight, 4, BigDecimal.ROUND_UP).movePointRight(2);
}
FeignOrderInfoVO orderInfo = orderService.getOrderInfo(orderGoods.getOrderNo()).orElseThrow(PerformanceResultEnum.ORDER_INVALID);
BigDecimal weight = orderChildDao.sumTakeWeightByOrderGoodsNo(orderGoods.getOrderGoodsNo(),
Objects.equals(orderInfo.getOverWeight(), OrderEnum.OverWeight.YES.getCode())
? OVER_WEIGHT
: STANDARD_WEIGHT
);
if (weight == null) {weight = BigDecimal.ZERO;}
taskCompleteRatio = weight.divide(taskWeight, 4, RoundingMode.UP).movePointRight(2);
log.info("接单预警,任务量:{}, 完成量:{}, 任务完成率:{}, 总时间:{}, 需要时间:{}, 相差时间:{}", taskWeight, weight, taskCompleteRatio, totalTime, needTime, difTime);
List<LineWarnConfig> lineWarnConfigList = lineWarnConfigDao
.listByWarnType(LineWarnConfigEnum.WarnType.TAKE.getCode());
if (lineWarnConfigList.isEmpty()) {return;}
......@@ -78,12 +96,16 @@ public class LineWarnTakeWarnServiceImpl implements LineWarnTakeWarnService {
return;
}
int time = lineWarnConfig.getTimeRatio().multiply(new BigDecimal(difTime)).intValue();
// 暂停检测
boolean suspend = lineWarnCommonService.suspendCheck(lineWarnInfo);
if (suspend) {return;}
int time = lineWarnConfig.getTimeRatio().multiply(new BigDecimal(difTime)).movePointLeft(2).intValue();
// 未达到时间占比
if (pendingOrderTime.plusMinutes(time).isAfter(LocalDateTime.now())){return;}
// 达到任务占比
if (lineWarnConfig.getTaskCompleteRatio().compareTo(taskCompleteRatio) >= 0) {return;}
if (lineWarnConfig.getTaskCompleteRatio().compareTo(taskCompleteRatio) < 0) {return;}
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig);
......
......@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
......@@ -42,15 +43,18 @@ public class LineWarnUnloadServiceImpl implements LineWarnUnloadWarnService {
int needTime = 0;
// 接单最长时间
long difTime = totalTime - needTime;
if (difTime < 0){difTime = 0;}
// 任务量
BigDecimal taskWeight = lineWarnCommonInfo.getTaskWeight();
// 任务完成率
BigDecimal taskCompleteRatio = BigDecimal.ZERO;
BigDecimal weight = orderChildDao.sumTakeWeightByOrderGoodsNo(orderGoods.getOrderGoodsNo());
BigDecimal weight = orderChildDao.sumUnloadWeightByOrderGoodsNo(orderGoods.getOrderGoodsNo());
if (weight != null){
taskCompleteRatio = weight.divide(taskWeight, 4, BigDecimal.ROUND_UP).movePointRight(2);
taskCompleteRatio = weight.divide(taskWeight, 4, RoundingMode.UP).movePointRight(2);
}
log.info("卸车预警,任务量:{}, 完成量:{}, 任务完成率:{}, 总时间:{}, 需要时间:{}, 相差时间:{}", taskWeight, weight, taskCompleteRatio, totalTime, needTime, difTime);
List<LineWarnConfig> lineWarnConfigList = lineWarnConfigDao
.listByWarnType(LineWarnConfigEnum.WarnType.UNLOAD.getCode());
......@@ -71,12 +75,16 @@ public class LineWarnUnloadServiceImpl implements LineWarnUnloadWarnService {
return;
}
int time = lineWarnConfig.getTimeRatio().multiply(new BigDecimal(difTime)).intValue();
// 暂停检测
boolean suspend = lineWarnCommonService.suspendCheck(lineWarnInfo);
if (suspend) {return;}
int time = lineWarnConfig.getTimeRatio().multiply(new BigDecimal(difTime)).movePointLeft(2).intValue();
// 未达到时间占比
if (pendingOrderTime.plusMinutes(time).isAfter(LocalDateTime.now())){return;}
// 达到任务占比
if (lineWarnConfig.getTaskCompleteRatio().compareTo(taskCompleteRatio) >= 0) {return;}
if (lineWarnConfig.getTaskCompleteRatio().compareTo(taskCompleteRatio) < 0) {return;}
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig);
......
package com.clx.performance.service.impl.linewarn;
import com.clx.order.vo.feign.FeignAddressVO;
import com.clx.performance.constant.RedisConstants;
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;
......@@ -18,19 +18,20 @@ 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.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Slf4j
@Service
public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnService {
@Autowired
private LineWarnConfigDao lineWarnConfigDao;
@Autowired
private InternalReportService internalReportService;
@Autowired
private LineWarnCommonService lineWarnCommonService;
@Autowired
......@@ -39,10 +40,15 @@ public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnServic
private GdUtils gdUtils;
@Autowired
private AddressService addressService;
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Override
public void weatherWarn(OrderGoods orderGoods, LineWarnCommonInfoDTO lineWarnCommonInfo) {
Boolean flag = redisTemplate.opsForValue().setIfAbsent(RedisConstants.LINE_WARN_WEATHER + orderGoods.getOrderGoodsNo(), orderGoods.getOrderGoodsNo(), 1, TimeUnit.HOURS);
if (!flag) {return;}
List<LineWarnConfig> lineWarnConfigList = lineWarnConfigDao
.listByWarnType(LineWarnConfigEnum.WarnType.WEATHER.getCode());
if (lineWarnConfigList.isEmpty()) {return;}
......@@ -61,28 +67,47 @@ public class LineWarnWeatherWarnServiceImpl implements LineWarnWeatherWarnServic
return;
}
// 暂停检测
boolean suspend = lineWarnCommonService.suspendCheck(lineWarnInfo);
if (suspend) {return;}
String weatherAll = "";
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 (feignAddressVO.getSendAddress()!=null){
String cityCode = gdUtils.getCity(feignAddressVO.getSendAddress().getLongitude(),
feignAddressVO.getSendAddress().getLatitude());
String weather = gdUtils.getWeather(cityCode);
if (weatherCheck(weather)){
weatherAll = weather;
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig, weather);
}
}
if (feignAddressVO.getReceiveAddress()!=null
&& StringUtils.isNotBlank(feignAddressVO.getReceiveAddress().getCityCode())){
String weather = gdUtils.getWeather(feignAddressVO.getReceiveAddress().getCityCode());
if (feignAddressVO.getReceiveAddress()!=null){
String cityCode = gdUtils.getCity(feignAddressVO.getReceiveAddress().getLongitude(),
feignAddressVO.getReceiveAddress().getLatitude());
String weather = gdUtils.getWeather(cityCode);
if (weatherCheck(weather)){
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig, weather);
if (StringUtils.isBlank(weatherAll)){weatherAll = weather;}
else {
//不相同,逗号分隔
if (!weatherAll.equals(weather)){
weatherAll = weatherAll + "," + weather;
}
}
}
}
if (StringUtils.isNotBlank(weatherAll)){
// 更新
lineWarnCommonService.lineWarnInfoUpdate(orderGoods, lineWarnInfo, lineWarnConfig, weatherAll);
}
}
/**
......
......@@ -9,4 +9,6 @@ public interface LineWarnCommonService {
void lineWarnInfoUpdate(OrderGoods orderGoods, LineWarnInfo lineWarnInfo, LineWarnConfig lineWarnConfig);
void lineWarnInfoUpdate(OrderGoods orderGoods, LineWarnInfo lineWarnInfo, LineWarnConfig lineWarnConfig, String weather);
boolean suspendCheck(LineWarnInfo lineWarnInfo);
}
......@@ -23,11 +23,11 @@ public class VehicleWarnRangeSqlProvider {
if (Objects.nonNull(param.getWarnRang())) {WHERE("warn_rang = #{param.warnRang}");}
if (StringUtils.isNotBlank(param.getSuspendObject())) {
WHERE("((warn_rage=1 and child_no =#{param.suspendObject}) " +
"or (warn_rage=2 and order_goods_no =#{param.suspendObject}))");}
WHERE("((warn_rang=1 and child_no =#{param.suspendObject}) " +
"or (warn_rang=2 and order_goods_no =#{param.suspendObject}))");}
if (StringUtils.isNotBlank(param.getBeginTime())) {WHERE("create_time >= #{param.beginTime}");}
if (StringUtils.isNotBlank(param.getEndTime())) {WHERE("create_time <= #{param.endTime}");}
if (StringUtils.isNotBlank(param.getBeginTime())) {WHERE("warn_end_time >= #{param.beginTime}");}
if (StringUtils.isNotBlank(param.getEndTime())) {WHERE("warn_end_time <= #{param.endTime}");}
ORDER_BY("id desc");
}}.toString();
......
......@@ -12,6 +12,7 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
......@@ -35,6 +36,7 @@ public class GdService {
private static final String WEATHER_API = "https://restapi.amap.com/v3/weather/weatherInfo?parameters";//天气
private static final String CITY_API = "https://restapi.amap.com/v3/geocode/regeo?parameters";//城市
private String gaodeKey = "b2550e16bbc7bf9f6cd168e0f21709fc";
......@@ -405,4 +407,50 @@ public class GdService {
return weather;
}
public String getCity(BigDecimal longitude, BigDecimal latitude){
return getCity(gaodeKey, longitude, latitude);
}
public static String getCity(String key, BigDecimal longitude, BigDecimal latitude) {
String url = CITY_API+"?output=json&location=" +longitude.setScale(6, RoundingMode.HALF_UP)+","+latitude.setScale(2, RoundingMode.HALF_UP)+"&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);}
}
// 解析
String adcode = retJSONObject.getJSONObject("regeocode").getJSONObject("addressComponent").getString("adcode");
if (StringUtils.isBlank(adcode)) {throw new ServiceSystemException(ResultCodeEnum.FAIL, "调用高德城市编码接口异常, result:"+resultStr);}
return adcode;
}
}
......@@ -80,6 +80,12 @@ public class GdUtils {
public String getWeather(String city){
return gdService.getWeather(city);
}
/**
* 天气
*/
public String getCity(BigDecimal longitude, BigDecimal latitude){
return gdService.getCity(longitude,latitude);
}
/**
* 获取线路
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论