|
|
@@ -4,8 +4,8 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.google.common.collect.Lists;
|
|
|
@@ -18,7 +18,6 @@ import com.sckw.core.exception.BusinessException;
|
|
|
import com.sckw.core.exception.BusinessPlatfromException;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
|
import com.sckw.core.model.constant.NumberConstant;
|
|
|
-import com.sckw.core.model.constant.UrlConstants;
|
|
|
import com.sckw.core.model.enums.*;
|
|
|
import com.sckw.core.model.page.PageHelperUtil;
|
|
|
import com.sckw.core.model.page.PageResult;
|
|
|
@@ -27,8 +26,8 @@ import com.sckw.core.utils.*;
|
|
|
import com.sckw.core.web.constant.CommonConstants;
|
|
|
import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
-import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.core.web.response.BaseResult;
|
|
|
+import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.core.web.response.result.PageDataResult;
|
|
|
import com.sckw.excel.utils.DateUtil;
|
|
|
import com.sckw.fleet.api.RemoteFleetService;
|
|
|
@@ -45,7 +44,6 @@ import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.RemoteUserService;
|
|
|
import com.sckw.system.api.model.dto.res.*;
|
|
|
import com.sckw.transport.api.feign.VehicleTraceClient;
|
|
|
-import com.sckw.transport.api.model.vo.VehicleTraceResponse;
|
|
|
import com.sckw.transport.common.config.UrlConfigProperties;
|
|
|
import com.sckw.transport.dao.*;
|
|
|
import com.sckw.transport.model.*;
|
|
|
@@ -80,6 +78,7 @@ import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -3655,11 +3654,384 @@ public class KwtWaybillOrderV1Service {
|
|
|
if (!b ){
|
|
|
throw new BusinessException("完善单证失败");
|
|
|
}
|
|
|
+
|
|
|
return Boolean.TRUE;
|
|
|
}
|
|
|
+ //计算司机分值
|
|
|
+ calculateAutoDispatchScore(billOrder, status);
|
|
|
+
|
|
|
return Boolean.FALSE;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 自动派单计算司机分值
|
|
|
+ * @param billOrder
|
|
|
+ */
|
|
|
+ protected void calculateAutoDispatchScore(KwtWaybillOrder billOrder, Integer status) {
|
|
|
+ if (true) {
|
|
|
+ //先不执行自动派单逻辑
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //查询运单装卸货地址
|
|
|
+ List<KwtWaybillOrderAddress> addressList = waybillOrderAddressRepository.queryByWOrderId(billOrder.getId());
|
|
|
+ if (CollectionUtils.isEmpty(addressList)) {
|
|
|
+ log.info("物流运单无装卸货地址信息,运单id:{}", billOrder.getId());
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.LOGISTICS_ORDER_NOT_ADDRESS, "物流订单无装卸货地址信息");
|
|
|
+ }
|
|
|
+ Map<Integer, KwtWaybillOrderAddress> addressMap = addressList.stream()
|
|
|
+ .filter(addr -> addr.getAddressType() != null)
|
|
|
+ .collect(Collectors.toMap(KwtWaybillOrderAddress::getAddressType, Function.identity(),
|
|
|
+ (x,y) ->x));
|
|
|
+
|
|
|
+ // 获取司机行为规则配置(司机违规取消运单分钟数)
|
|
|
+ DriverConductRulesVO driverRulesVO = remoteFleetService.findDriverConductRulesByEntId(billOrder.getEntId());
|
|
|
+ if (driverRulesVO == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "未找到司机行为规则数据!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //1. 运单单据错误被驳回
|
|
|
+ checkRefuseScore(billOrder, status, driverRulesVO);
|
|
|
+
|
|
|
+ //运单没通过,不执行以下逻辑
|
|
|
+ if (!Objects.equals(status, CarWaybillV1Enum.WAIT_UNLOADING.getCode())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //2. 校验司机运单完成是否超时
|
|
|
+ checkCompletionTimeout(billOrder, addressMap, driverRulesVO);
|
|
|
+
|
|
|
+ //3. 校验司机连续准时卸货(审核通过)
|
|
|
+ checkContinuousUnload(billOrder, addressMap);
|
|
|
+
|
|
|
+ //4. 校验司机连续准确填写卸货信息(审核通过)
|
|
|
+ checkContinuousPass(billOrder, addressMap);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运单被驳回,扣减司机分数
|
|
|
+ * @param waybillOrder
|
|
|
+ */
|
|
|
+ private void checkRefuseScore(KwtWaybillOrder waybillOrder, Integer status, DriverConductRulesVO driverRulesVO) {
|
|
|
+ //运单驳回
|
|
|
+ if (!Objects.equals(status, CarWaybillV1Enum.COMPLETION_UNLOADING.getCode())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //单据错误驳回分数
|
|
|
+ Integer documentErrorMissing = driverRulesVO.getDocumentErrorMissing();
|
|
|
+ if (documentErrorMissing <= 0) {
|
|
|
+ log.warn("司机扣分失败:企业{}的司机单据错误/缺失分数配置需大于0,运单ID:{}", waybillOrder.getEntId(), waybillOrder.getId());
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "司机扣分失败,单据错误/缺失分数配置需大于0!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //1、更新司机分数(减分)
|
|
|
+ documentErrorMissing = -Math.abs(documentErrorMissing);
|
|
|
+ remoteFleetService.updateDriverScore(waybillOrder.getEntId(), waybillOrder.getDriverId(), documentErrorMissing);
|
|
|
+
|
|
|
+ //2、更新企业分数(减分)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验司机运单完成是否超时
|
|
|
+ * @param waybillOrder
|
|
|
+ */
|
|
|
+ private void checkCompletionTimeout(KwtWaybillOrder waybillOrder, Map<Integer, KwtWaybillOrderAddress> addressMap,
|
|
|
+ DriverConductRulesVO driverRulesVO) {
|
|
|
+ //单趟严重超时分数
|
|
|
+ BigDecimal timeoutMultiple = driverRulesVO.getUnloadSeriousTimeoutMultiple();
|
|
|
+
|
|
|
+ //单趟严重超时分数
|
|
|
+ Integer timeoutScore = driverRulesVO.getUnloadSeriousTimeout();
|
|
|
+ if (timeoutScore <= 0) {
|
|
|
+ log.warn("司机扣分失败:企业{}的司机单趟严重超时分数配置需大于0,运单ID:{}", waybillOrder.getEntId(), waybillOrder.getId());
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "司机扣分失败,司机单趟严重超时分数配置需大于0!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验司机运单完成是否超时
|
|
|
+ Boolean isTimeOut = isTimeOut(waybillOrder, addressMap, timeoutMultiple);
|
|
|
+ if (isTimeOut) {
|
|
|
+ //1、更新司机分数(减分)
|
|
|
+ timeoutScore = -Math.abs(timeoutScore);
|
|
|
+ remoteFleetService.updateDriverScore(waybillOrder.getEntId(), waybillOrder.getDriverId(), timeoutScore);
|
|
|
+
|
|
|
+ //2、更新企业分数(减分)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验司机运单完成是否超时
|
|
|
+ * @param waybillOrder 运单
|
|
|
+ * @param addressMap 运单地址
|
|
|
+ */
|
|
|
+ protected Boolean isTimeOut(KwtWaybillOrder waybillOrder, Map<Integer, KwtWaybillOrderAddress> addressMap, BigDecimal timeoutMultiple) {
|
|
|
+ log.info("校验司机运单完成是否超时:运单ID:{}", waybillOrder.getId());
|
|
|
+ //运单总耗时
|
|
|
+ Long orderTotalTimes = calOrderTotalTimes(waybillOrder);
|
|
|
+ //平台配置的运单单趟总耗时
|
|
|
+ Integer singleTripTotalTimes = calSingleTripTotalTimes(waybillOrder, addressMap);
|
|
|
+ //计算超时阈值
|
|
|
+ BigDecimal threshold = timeoutMultiple.compareTo(BigDecimal.ZERO) == 0 ?
|
|
|
+ new BigDecimal(singleTripTotalTimes) : timeoutMultiple.multiply(new BigDecimal(singleTripTotalTimes));
|
|
|
+ BigDecimal actualTimes = new BigDecimal(orderTotalTimes);
|
|
|
+ if (actualTimes.compareTo(threshold) > 0) {
|
|
|
+ log.warn("【司机运单超时】运单ID:{},实际总耗时:{}分钟,平台单趟耗时:{}分钟", waybillOrder.getId(), orderTotalTimes, singleTripTotalTimes);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算司机接单到结束的总耗时
|
|
|
+ * @param waybillOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Long calOrderTotalTimes(KwtWaybillOrder waybillOrder) {
|
|
|
+ //司机接单时间
|
|
|
+ KwtWaybillOrderNode takingOrderNodes = kwtWaybillOrderNodeRepository.queryNodesByOrderId(waybillOrder.getId(), CarWaybillV1Enum.PENDING_VEHICLE.getCode());
|
|
|
+ if (takingOrderNodes == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_NODE_NOT_EXIST, "未找到关联的运单节点数据!");
|
|
|
+ }
|
|
|
+ Date takingOrderTime = takingOrderNodes.getCreateTime() != null ? takingOrderNodes.getCreateTime() : null;
|
|
|
+ //司机完成运单时间
|
|
|
+ KwtWaybillOrderNode overOrderNodes = kwtWaybillOrderNodeRepository.queryNodesByOrderId(waybillOrder.getId(), CarWaybillV1Enum.WAIT_UNLOADING.getCode());
|
|
|
+ if (overOrderNodes == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_NODE_NOT_EXIST, "未找到关联的运单节点数据!");
|
|
|
+ }
|
|
|
+ Date overOrderTime = overOrderNodes.getCreateTime() != null ? overOrderNodes.getCreateTime() : null;
|
|
|
+ //运单总耗时(分钟)
|
|
|
+ Long orderTotalTimes = calculateTimeDiffMinutes(takingOrderTime, overOrderTime);
|
|
|
+ log.info("司机完成运单总耗时:{}", orderTotalTimes);
|
|
|
+ return orderTotalTimes;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算平台配置的运单单趟总耗时
|
|
|
+ * @param waybillOrder
|
|
|
+ * @param addressMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Integer calSingleTripTotalTimes(KwtWaybillOrder waybillOrder, Map<Integer, KwtWaybillOrderAddress> addressMap) {
|
|
|
+ // 获取自动派单系数配置(单趟耗时 = 装货时间 + 卸货时间 + 运输时间 + 返回时间)
|
|
|
+ TruckDispatchCoefficientVO truckDispatchVO = remoteFleetService.findAutoTruckDispatchByEntId(waybillOrder.getEntId());
|
|
|
+ if (truckDispatchVO == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "未找到自动派车系数!");
|
|
|
+ }
|
|
|
+ //装货时长
|
|
|
+ Integer vehicleLoadingHours = truckDispatchVO.getVehicleLoadingHours();
|
|
|
+ //卸货货时长
|
|
|
+ Integer vehicleUnloadingHours = truckDispatchVO.getVehicleUnloadingHours();
|
|
|
+ //平均行驶速度
|
|
|
+ Integer vehicleAvgSpeed = truckDispatchVO.getVehicleAvgSpeed();
|
|
|
+ if (vehicleLoadingHours <= 0 || vehicleUnloadingHours <= 0 || vehicleAvgSpeed <= 0) {
|
|
|
+ log.warn("企业{}的司机装货时长/卸货时长/平均行驶速度配置数据异常(装货:{},卸货:{},速度:{}),运单ID:{}",
|
|
|
+ waybillOrder.getEntId(), vehicleLoadingHours, vehicleUnloadingHours, vehicleAvgSpeed, waybillOrder.getId());
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "司机配置的装货时长/卸货时长/平均行驶速度需要≥0!");
|
|
|
+ }
|
|
|
+ //查询运单装卸货地址
|
|
|
+ KwtWaybillOrderAddress shipmentAddress = addressMap.getOrDefault(AddressTypeEnum.SHIPMENT.getCode(), new KwtWaybillOrderAddress());
|
|
|
+ KwtWaybillOrderAddress takeAddress = addressMap.getOrDefault(AddressTypeEnum.TAKE.getCode(), new KwtWaybillOrderAddress());
|
|
|
+
|
|
|
+ //应卸货地与实际卸货地之间距离
|
|
|
+ double twoPlaceDistanceKm = DistanceUtils.calculateDistance(
|
|
|
+ Optional.ofNullable(takeAddress.getLng()).map(Double::valueOf).orElse(null),
|
|
|
+ Optional.ofNullable(takeAddress.getLat()).map(Double::valueOf).orElse(null),
|
|
|
+ Optional.ofNullable(shipmentAddress.getLng()).map(Double::valueOf).orElse(null),
|
|
|
+ Optional.ofNullable(shipmentAddress.getLat()).map(Double::valueOf).orElse(null));
|
|
|
+ //运输时间/返回时间(小时) = 两地距离除以平均行驶速度
|
|
|
+ if (twoPlaceDistanceKm == 0.0 || Double.isNaN(twoPlaceDistanceKm)) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "物流运单装货地址有误!");
|
|
|
+ }
|
|
|
+ BigDecimal bdDividend = BigDecimal.valueOf(twoPlaceDistanceKm);
|
|
|
+ BigDecimal bdDivisor = BigDecimal.valueOf(vehicleAvgSpeed);
|
|
|
+ //运输时间小时
|
|
|
+ BigDecimal transportTimeHours = bdDividend.divide(bdDivisor, 4, RoundingMode.HALF_UP);
|
|
|
+ //运输时间分钟取整
|
|
|
+ Integer transportTimeMinutes = transportTimeHours.multiply(BigDecimal.valueOf(60)).setScale(0, RoundingMode.HALF_UP).intValue();
|
|
|
+ //往返时间=运输时间
|
|
|
+ Integer returnTimeMinutes = transportTimeMinutes;
|
|
|
+ //单趟总耗时
|
|
|
+ Integer singleTripTotalTimes = vehicleLoadingHours + vehicleUnloadingHours + transportTimeMinutes + returnTimeMinutes;
|
|
|
+ log.info("平台配置的运单单趟总耗时:{}", singleTripTotalTimes);
|
|
|
+ return singleTripTotalTimes;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算两个时间的分钟差值
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Long calculateTimeDiffMinutes(Date startTime, Date endTime) {
|
|
|
+ // 校验
|
|
|
+ if (startTime == null || endTime == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR,
|
|
|
+ "计算时间差失败:,startTime=[" + startTime + "], endTime=[" + endTime + "]");
|
|
|
+ }
|
|
|
+ // 计算时间戳差值(毫秒)
|
|
|
+ long diffMillis = endTime.getTime() - startTime.getTime();
|
|
|
+ long diffMinutes = TimeUnit.MILLISECONDS.toMinutes(diffMillis);
|
|
|
+ // 时间顺序异常提醒(结束时间早于开始时间)
|
|
|
+ if (diffMinutes < 0) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR,
|
|
|
+ "时间顺序异常,结束时间早于开始时间,startTime=[" + startTime + "], endTime=[" + endTime + "], 差值:[" + diffMinutes + "]分钟");
|
|
|
+ }
|
|
|
+ return diffMinutes;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验司机连续准时卸货
|
|
|
+ * @param waybillOrder
|
|
|
+ */
|
|
|
+ private void checkContinuousUnload(KwtWaybillOrder waybillOrder, Map<Integer, KwtWaybillOrderAddress> addressMap) {
|
|
|
+ // 获取司机行为规则配置(连续准时卸货次数)
|
|
|
+ DriverConductRulesVO driverRulesVO = remoteFleetService.findDriverConductRulesByEntId(waybillOrder.getEntId());
|
|
|
+ if (driverRulesVO == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "未找到司机行为规则数据!");
|
|
|
+ }
|
|
|
+ //连续卸货次数
|
|
|
+ Integer continuousOnTimes = driverRulesVO.getContinuousOnTimeUnloadTimes();
|
|
|
+ //连续卸货加分分数
|
|
|
+ Integer continuousOnTimeUnload = driverRulesVO.getContinuousOnTimeUnload();
|
|
|
+ if (continuousOnTimes <= 0 || continuousOnTimeUnload <= 0) {
|
|
|
+ log.warn("该司机无需加分,获取连续准时卸货数据失败:企业{}的连续按时到场配置需大于0,运单ID:{}", waybillOrder.getEntId(), waybillOrder.getId());
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "连续准时卸货次数和分数需大于0!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询该司机连续审核通过节点数据
|
|
|
+ List<KwtWaybillOrderNode> waybillOrderNodeList = getWaybillOrderNodesByStatus(waybillOrder, continuousOnTimes, CarWaybillV1Enum.WAIT_UNLOADING);
|
|
|
+ if (waybillOrderNodeList == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //记录连续审核通过次数
|
|
|
+ int continuousCount = 0;
|
|
|
+ List<Long> qualifiedNodeIds = new ArrayList<>();
|
|
|
+ List<Long> nodeIds = new ArrayList<>();
|
|
|
+ for (KwtWaybillOrderNode orderNode : waybillOrderNodeList) {
|
|
|
+ KwtWaybillOrder wOrder = kwtWaybillOrderRepository.queryByBillOrderId(orderNode.getWOrderId());
|
|
|
+ Boolean timeOut = isTimeOut(wOrder, addressMap, BigDecimal.ZERO);
|
|
|
+ if (timeOut) {
|
|
|
+ log.info("司机{}存在超时情况,运单id:{}", orderNode.getDriverId(), orderNode.getWOrderId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ continuousCount++;
|
|
|
+ qualifiedNodeIds.add(orderNode.getId());
|
|
|
+ // 达到10次,返回最新的10条ID
|
|
|
+ if (continuousCount >= continuousOnTimes) {
|
|
|
+ // 截断前10条
|
|
|
+ nodeIds = qualifiedNodeIds.subList(0, continuousOnTimes);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 校验是否达到次数
|
|
|
+ if (continuousCount < continuousOnTimes) {
|
|
|
+ log.info("司机{}连续卸货完成次数{},未达到配置阈值{}", waybillOrder.getDriverId(), continuousCount, continuousOnTimes);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //1. 给连续的10次节点数据打标
|
|
|
+ updateNode(waybillOrder, nodeIds, continuousOnTimeUnload);
|
|
|
+
|
|
|
+ //2 .更新司机分数(加分)
|
|
|
+ remoteFleetService.updateDriverScore(waybillOrder.getEntId(), waybillOrder.getDriverId(), continuousOnTimeUnload);
|
|
|
+
|
|
|
+ //3. 更新企业分数(加分)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验司机连续准确填写卸货信息
|
|
|
+ * @param waybillOrder
|
|
|
+ */
|
|
|
+ private void checkContinuousPass(KwtWaybillOrder waybillOrder, Map<Integer, KwtWaybillOrderAddress> addressMap) {
|
|
|
+ // 获取司机行为规则配置(连续准确填写卸货信息次数)
|
|
|
+ DriverConductRulesVO driverRulesVO = remoteFleetService.findDriverConductRulesByEntId(waybillOrder.getEntId());
|
|
|
+ if (driverRulesVO == null) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "未找到司机行为规则数据!");
|
|
|
+ }
|
|
|
+ //连续卸货次数
|
|
|
+ Integer continuousAccurateUnloadTimes = driverRulesVO.getContinuousAccurateUnloadTimes();
|
|
|
+ //连续卸货加分分数
|
|
|
+ Integer continuousAccurateUnload = driverRulesVO.getContinuousAccurateUnload();
|
|
|
+ if (continuousAccurateUnloadTimes <= 0 || continuousAccurateUnload <= 0) {
|
|
|
+ log.warn("该司机无需加分,获取连续准确填写卸货信息数据失败:企业{}的连续按时到场配置异常,运单ID:{}", waybillOrder.getEntId(), waybillOrder.getId());
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.DATA_NOT_EXIST, "连续准确填写卸货信息次数和分数不能小于等于0!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询该司机连续审核通过节点数据
|
|
|
+ List<KwtWaybillOrderNode> waybillOrderNodeList = getWaybillOrderNodesByStatus(waybillOrder, continuousAccurateUnloadTimes, CarWaybillV1Enum.WAIT_UNLOADING);
|
|
|
+ if (waybillOrderNodeList == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //记录连续审核通过次数
|
|
|
+ int continuousCount = 0;
|
|
|
+ List<Long> qualifiedNodeIds = new ArrayList<>();
|
|
|
+ List<Long> nodeIds = new ArrayList<>();
|
|
|
+ for (KwtWaybillOrderNode orderNode : waybillOrderNodeList) {
|
|
|
+ continuousCount++;
|
|
|
+ qualifiedNodeIds.add(orderNode.getId());
|
|
|
+ // 达到10次,返回最新的10条ID
|
|
|
+ if (continuousCount >= continuousAccurateUnloadTimes) {
|
|
|
+ // 截断前10条
|
|
|
+ nodeIds = qualifiedNodeIds.subList(0, continuousAccurateUnloadTimes);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 校验是否达到次数
|
|
|
+ if (continuousCount < continuousAccurateUnloadTimes) {
|
|
|
+ log.info("司机{}连续准确填写卸货信息次数{},未达到配置阈值{}", waybillOrder.getDriverId(), continuousCount, continuousAccurateUnloadTimes);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //1. 给连续的10次节点数据打标
|
|
|
+ updateNode(waybillOrder, nodeIds, continuousAccurateUnloadTimes);
|
|
|
+
|
|
|
+ //2 .更新司机分数(加分)
|
|
|
+ remoteFleetService.updateDriverScore(waybillOrder.getEntId(), waybillOrder.getDriverId(), continuousAccurateUnload);
|
|
|
+
|
|
|
+ //3. 更新企业分数(加分)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询该司机连续卸货节点数据
|
|
|
+ * @param waybillOrder
|
|
|
+ * @param continuousOnTimes
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ protected List<KwtWaybillOrderNode> getWaybillOrderNodesByStatus(KwtWaybillOrder waybillOrder, Integer continuousOnTimes, CarWaybillV1Enum waybillV1Enum) {
|
|
|
+ //司机运单数据
|
|
|
+ List<KwtWaybillOrder> waybillOrders = kwtWaybillOrderRepository.queryByEntId(waybillOrder.getEntId(), waybillOrder.getDriverId());
|
|
|
+ if (CollectionUtils.isEmpty(waybillOrders)) {
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.WAYBILL_ORDER_NOT_FOUND, "物流运单不存在!");
|
|
|
+ }
|
|
|
+ List<Long> wOrderIds = waybillOrders.stream().map(KwtWaybillOrder::getId).collect(Collectors.toList());
|
|
|
+ //查询司机的节点数据
|
|
|
+ List<KwtWaybillOrderNode> waybillOrderNodeList = kwtWaybillOrderNodeRepository
|
|
|
+ .queryContinuousNodesByDriverId(wOrderIds, waybillOrder.getDriverId(), waybillV1Enum.getCode());
|
|
|
+ if (CollectionUtils.isEmpty(waybillOrderNodeList) || waybillOrderNodeList.size() < continuousOnTimes) {
|
|
|
+ log.info("司机{}按时接节点不足{}次,当前记录数:{}", waybillOrder.getDriverId(), continuousOnTimes, waybillOrderNodeList.size());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return waybillOrderNodeList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 给连续的10次的节点数据打标
|
|
|
+ */
|
|
|
+ protected void updateNode(KwtWaybillOrder waybillOrder, List<Long> nodeIds, Integer continuousOnTimeScore) {
|
|
|
+ KwtWaybillOrderNode updateEntity = new KwtWaybillOrderNode();
|
|
|
+ updateEntity.setContinuous(1);
|
|
|
+ LambdaQueryWrapper<KwtWaybillOrderNode> updateWrapper = new LambdaQueryWrapper<KwtWaybillOrderNode>()
|
|
|
+ .in(KwtWaybillOrderNode::getId, nodeIds);
|
|
|
+ kwtWaybillOrderNodeRepository.update(updateEntity, updateWrapper);
|
|
|
+ log.info("司机{}连续执行运单节点,加分:{},节点ID:{}", waybillOrder.getDriverId(), continuousOnTimeScore, JSON.toJSONString(nodeIds));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void noticeTraderOrder(KwtLogisticsOrder kwtLogisticsOrder, KwtLogisticsOrder kwtLogistics) {
|
|
|
|
|
|
if (!Objects.equals(kwtLogisticsOrder.getStatus(),LogisticsOrderV1Enum.HAVE_RECONCILED.getCode())){
|