Procházet zdrojové kódy

1、4.2派车功能;

zk před 1 rokem
rodič
revize
3152033e66

+ 4 - 1
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/KwtWaybillOrderController.java

@@ -14,6 +14,7 @@ import com.sckw.core.web.response.HttpResult;
 import com.sckw.transport.model.dto.*;
 import com.sckw.transport.model.vo.WaybillOrderDriverVo;
 import com.sckw.transport.service.KwtWaybillOrderService;
+import com.sckw.transport.service.KwtWaybillOrderV1Service;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.validation.Valid;
 import jakarta.validation.constraints.NotBlank;
@@ -35,6 +36,8 @@ public class KwtWaybillOrderController {
 
     @Autowired
     KwtWaybillOrderService waybillOrderService;
+    @Autowired
+    KwtWaybillOrderV1Service waybillOrderV1Service;
 
     /**
      * @desc 统计司机任务数(待接单/出车/执行/完结)
@@ -157,7 +160,7 @@ public class KwtWaybillOrderController {
      **/
     @PostMapping("/sendCarV1")
     public HttpResult sendCarV1(@RequestBody @Valid SendCarDto2 params){
-        return waybillOrderService.sendCarV1(params);
+        return waybillOrderV1Service.sendCarV1(params);
     }
 
     /**

+ 1 - 1
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/dao/KwtLogisticsOrderAmountMapper.java

@@ -18,5 +18,5 @@ public interface KwtLogisticsOrderAmountMapper extends BaseMapper<KwtLogisticsOr
 
     List<KwtLogisticsOrderAmount> findByAddress(KwtLogisticsOrderAddress params);
 
-    KwtLogisticsOrderAmount findByAddressId(@Param("") Long lAddressId);
+    KwtLogisticsOrderAmount findByAddressId(@Param("lAddressId") Long lAddressId);
 }

+ 28 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/dao/KwtWaybillOrderV1Mapper.java

@@ -0,0 +1,28 @@
+package com.sckw.transport.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sckw.mongo.model.TableTops;
+import com.sckw.transport.model.KwtWaybillOrder;
+import com.sckw.transport.model.KwtWaybillOrderV1;
+import com.sckw.transport.model.dto.OrderCarDTO;
+import com.sckw.transport.model.dto.WayBillDetailDTO;
+import com.sckw.transport.model.dto.WaybillAmountDTO;
+import com.sckw.transport.model.vo.WaybillCountVo;
+import com.sckw.transport.model.vo.WaybillOrderDriverVo;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author zk
+ * @desc 车辆运单
+ * @date 2023/10/16
+ */
+@Mapper
+public interface KwtWaybillOrderV1Mapper extends BaseMapper<KwtWaybillOrderV1> {
+
+
+}

+ 1 - 1
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/KwtLogisticsOrderAmount.java

@@ -24,7 +24,7 @@ public class KwtLogisticsOrderAmount extends BaseModel {
     /**
      * 地址ID
      */
-    private Long addressId;
+    private Long lAddressId;
 
     /**
      * 货物数量

+ 10 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/KwtWaybillOrderAddress.java

@@ -26,6 +26,16 @@ public class KwtWaybillOrderAddress implements Serializable {
      */
     private Long wOrderId;
 
+    /**
+     * 运单关联子单ID
+     */
+    private Long wSubtaskId;
+
+    /**
+     * 物流订单地址ID
+     */
+    private Long lAddressId;
+
     /**
      * 地址类型(1装货地址、2卸货地址)
      */

+ 3 - 2
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/KwtWaybillOrderV1.java

@@ -6,11 +6,11 @@ import lombok.Data;
 
 /**
  * @author zk
- * @desc TODO
+ * @desc 物流订单
  * @date 2024/3/1 0001
  */
 @Data
-@TableName("kwt_waybill_orderV1")
+@TableName("kwt_waybill_order")
 public class KwtWaybillOrderV1 extends BaseModel {
 
     /**
@@ -57,4 +57,5 @@ public class KwtWaybillOrderV1 extends BaseModel {
      * 司机身份证号码
      */
     private String driverIdcard;
+
 }

+ 4 - 4
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/KwtLogisticsOrderConsignmentService.java

@@ -462,7 +462,7 @@ public class KwtLogisticsOrderConsignmentService {
                     KwtLogisticsOrderAmount orderAmount = new KwtLogisticsOrderAmount();
                     BigDecimal defaultBigDecimal = new BigDecimal("0.00");
                     orderAmount.setLOrderId(orderId);
-                    orderAmount.setAddressId(addressId);
+                    orderAmount.setLAddressId(addressId);
                     orderAmount.setAmount(addressInfoDto.getAmount());
                     orderAmount.setSubcontractAmount(defaultBigDecimal);
                     orderAmount.setEntrustAmount(defaultBigDecimal);
@@ -505,7 +505,7 @@ public class KwtLogisticsOrderConsignmentService {
                     KwtLogisticsOrderAmount orderAmount = new KwtLogisticsOrderAmount();
                     BigDecimal defaultBigDecimal = new BigDecimal("0.00");
                     orderAmount.setLOrderId(orderId);
-                    orderAmount.setAddressId(addressId);
+                    orderAmount.setLAddressId(addressId);
                     orderAmount.setAmount(addressInfoDto.getAmount());
                     orderAmount.setSubcontractAmount(defaultBigDecimal);
                     orderAmount.setEntrustAmount(defaultBigDecimal);
@@ -1118,7 +1118,7 @@ public class KwtLogisticsOrderConsignmentService {
                 KwtLogisticsOrderAmount orderAmount = new KwtLogisticsOrderAmount();
                 BigDecimal defaultBigDecimal = new BigDecimal("0.00");
                 orderAmount.setLOrderId(lOrderId);
-                orderAmount.setAddressId(addressId);
+                orderAmount.setLAddressId(addressId);
                 orderAmount.setAmount(address.getAmount());
                 orderAmount.setSubcontractAmount(defaultBigDecimal);
                 orderAmount.setEntrustAmount(defaultBigDecimal);
@@ -1166,7 +1166,7 @@ public class KwtLogisticsOrderConsignmentService {
                 KwtLogisticsOrderAmount orderAmount = new KwtLogisticsOrderAmount();
                 BigDecimal defaultBigDecimal = new BigDecimal("0.00");
                 orderAmount.setLOrderId(lOrderId);
-                orderAmount.setAddressId(addressId);
+                orderAmount.setLAddressId(addressId);
                 orderAmount.setAmount(address.getAmount());
                 orderAmount.setSubcontractAmount(defaultBigDecimal);
                 orderAmount.setEntrustAmount(defaultBigDecimal);

+ 165 - 3
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/KwtWaybillOrderService.java

@@ -65,6 +65,8 @@ public class KwtWaybillOrderService {
     @Autowired
     KwtWaybillOrderMapper waybillOrderDao;
     @Autowired
+    KwtWaybillOrderV1Mapper waybillOrderV1Dao;
+    @Autowired
     KwtLogisticsOrderMapper logisticsOrderDao;
     @Autowired
     KwtLogisticsOrderTrackMapper logisticsOrderTrackDao;
@@ -77,6 +79,8 @@ public class KwtWaybillOrderService {
     @Autowired
     KwtWaybillOrderTicketMapper waybillOrderTicketDao;
     @Autowired
+    KwtWaybillOrderSubtaskMapper waybillOrderSubtaskDao;
+    @Autowired
     KwtLogisticsOrderUnitMapper logisticsOrderUnitDao;
     @Autowired
     KwtLogisticsOrderGoodsMapper logisticsOrderGoodsDao;
@@ -458,12 +462,79 @@ public class KwtWaybillOrderService {
      **/
     @Transactional(rollbackFor = Exception.class)
     public HttpResult sendCarV1(SendCarDto2 params) {
-        /**校验**/
+        /**1、校验**/
         HttpResult result = checkWaybillOrderV1(params);
         if (result.getCode() != HttpStatus.SUCCESS_CODE) {
             return result;
         }
 
+        /**2、新增运单相关信息**/
+        //车辆司机信息
+        List<SendCarInfoDto> sends = params.getSends();
+        //物流订单ID
+        List<Long> lOrderIds = new ArrayList<>();
+        //物流订单装卸货地址委派量统计
+        Map<Long, BigDecimal> truckTotalEntrustAmount = new HashMap<>(NumberConstant.SIXTEEN);
+        for (SendCarInfoDto sendCar:sends) {
+            //趟次(循环单默认趟次为1)
+            int count = params.getType() == Global.NUMERICAL_ONE ? sendCar.getCount() : Global.NUMERICAL_ONE;
+            for (int i=0; i<count; i++) {
+                //新增运单信息
+                KwtWaybillOrderV1 waybillOrder = sendCarDriver(sendCar, params.getType());
+                //运输委托信息
+                List<SendCarEntrustDto> entrusts = sendCar.getEntrusts();
+                //物流订单委派量统计
+                Map<Long, BigDecimal> entrustAmount = new HashMap<>(NumberConstant.SIXTEEN);
+                //物流订单委派装货时间
+                Map<Long, List<Date>> loadTime = new HashMap<>(NumberConstant.SIXTEEN);
+                //物流订单委派卸货时间
+                Map<Long, List<Date>> unloadTime = new HashMap<>(NumberConstant.SIXTEEN);
+                /**数据组装**/
+                for (SendCarEntrustDto sendCarEntrust:entrusts) {
+                    //物流运单ID
+                    Long lOrderId = sendCarEntrust.getLOrderId();
+                    //委派量
+                    BigDecimal amount = new BigDecimal(sendCarEntrust.getEntrustAmount());
+                    //计划装卸货时间
+                    Date planTime = sendCarEntrust.getPlanTime();
+                    //装货+卸货
+                    if (sendCarEntrust.getAddressType() == AddressDefaultTypeEnum.SHIPMENT.getCode()) {
+                        if (entrustAmount.get(lOrderId) == null) {
+                            entrustAmount.put(lOrderId, amount);
+                            loadTime.put(lOrderId, new ArrayList<>(){{add(planTime);}});
+                        } else {
+                            List<Date> time = loadTime.get(lOrderId);
+                            time.add(planTime);
+                            entrustAmount.put(lOrderId, entrustAmount.get(lOrderId).add(amount));
+                            loadTime.put(lOrderId, time);
+                        }
+                    } else {
+                        if (entrustAmount.get(lOrderId) == null) {
+                            unloadTime.put(lOrderId, new ArrayList<>(){{add(planTime);}});
+                        } else {
+                            List<Date> time = unloadTime.get(lOrderId);
+                            time.add(planTime);
+                            unloadTime.put(lOrderId, time);
+                        }
+                    }
+                    //新增地址信息
+                    sendCarAddress(sendCarEntrust, waybillOrder);
+                }
+                //新增运单子单信息
+                List<KwtWaybillOrderSubtask> subtasks = sendCarSubtask(waybillOrder, entrustAmount, loadTime, unloadTime);
+                /**车辆运单状态记录**/
+                this.setWaybillOrderTrack(waybillOrder.getId(), waybillOrder.getUpdateTime(), waybillOrder.getStatus(), null);
+            }
+        }
+
+        /**3、更新承运订单委派信息**/
+
+        //更新承运订单kwt_logistics_order委派量
+
+        //更新承运订单运量kwt_logistics_order_amount委派量
+
+
+        /**4、更新承运订单状态(包括上级承运订单)**/
 
 
 
@@ -527,7 +598,7 @@ public class KwtWaybillOrderService {
      * @param logisticsOrder 物流订单
      * @desc 派车校验
      * @author zk
-     * @date 2023/7/19
+     * @date 2024/3/4
      **/
     public HttpResult checkWaybillOrderV1(SendCarDto2 params) {
         /**控制校验**/
@@ -592,7 +663,7 @@ public class KwtWaybillOrderService {
             queryAmount.setAddressType(AddressDefaultTypeEnum.SHIPMENT.getCode());
             List<KwtLogisticsOrderAmount> logisticsOrderAmounts = logisticsOrderAmountDao.findByAddress(queryAmount);
             for (KwtLogisticsOrderAmount orderAmount:logisticsOrderAmounts) {
-                BigDecimal truckEntrustAmount = truckTotalEntrustAmount.get(orderAmount.getAddressId());
+                BigDecimal truckEntrustAmount = truckTotalEntrustAmount.get(orderAmount.getLAddressId());
                 //当前下游司机委派量 + 历史下游司机委派量 + 分包量
                 BigDecimal actualAmount = truckEntrustAmount.add(entrustAmountTotal);
                 if (actualAmount.doubleValue() > orderAmount.getAmount().doubleValue()) {
@@ -604,6 +675,97 @@ public class KwtWaybillOrderService {
         return HttpResult.ok(truckTotalEntrustAmount);
     }
 
+    /**
+     * @param sendCar 车辆司机信息
+     * @param type 派车类型(1 趟次、2 循环)
+     * @desc 运单信息
+     * @author zk
+     * @date 2024/3/4
+     **/
+    public KwtWaybillOrderV1 sendCarDriver(SendCarInfoDto sendCar, int type) {
+        //车辆运单编号存储
+        //String wOrderNo = getRedisGenerateWaybillOrderNo(RedisOrderGenerateEnum.WAYBILL_ORDER, OrderRuleEnum.WAYBILL_ORDER, logisticsOrder.getLOrderNo());
+        //车辆信息
+        RTruckVo truck = remoteFleetService.findTruck(sendCar.getTruckId());
+        //司机信息
+        RDriverVo driver = remoteFleetService.findDriver(sendCar.getDriverId());
+        //运单信息
+        KwtWaybillOrderV1 waybillOrder = new KwtWaybillOrderV1();
+        waybillOrder.setEntId(LoginUserHolder.getEntId());
+        waybillOrder.setWOrderNo("W"+System.currentTimeMillis());
+        waybillOrder.setType(type);
+        waybillOrder.setTruckId(sendCar.getTruckId());
+        waybillOrder.setTruckNo(truck != null ? truck.getTruckNo() : null);
+        waybillOrder.setDriverId(sendCar.getDriverId());
+        waybillOrder.setDriverName(driver != null ? driver.getName() : null);
+        waybillOrder.setDriverPhone(driver != null ? driver.getPhone() : null);
+        waybillOrder.setDriverIdcard(driver != null ? driver.getIdcard() : null);
+        waybillOrder.setStatus(CarWaybillEnum.PENDING_ORDER.getCode());
+        waybillOrderV1Dao.insert(waybillOrder);
+        return waybillOrder;
+    }
+
+    /**
+     * @param waybillOrder 运单信息
+     * @param entrustAmount 运输委托信息
+     * @param loadTime 装货时间
+     * @param unloadTime 卸货时间
+     * @desc 车辆运单-子运单信息
+     * @author zk
+     * @date 2024/3/4
+     **/
+    public List<KwtWaybillOrderSubtask> sendCarSubtask(KwtWaybillOrderV1 waybillOrder, Map<Long, BigDecimal> entrustAmount,
+                                                 Map<Long, List<Date>> loadTime, Map<Long, List<Date>> unloadTime) {
+        List<KwtWaybillOrderSubtask> subtasks = new ArrayList<>();
+        for (Long key : entrustAmount.keySet()) {
+            List<Date> loadTime1 = loadTime.get(key);
+            List<Date> unloadTime1 = unloadTime.get(key);
+            Collections.sort(loadTime1, Comparator.naturalOrder());
+            Collections.sort(unloadTime1, Comparator.reverseOrder());
+            KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(key);
+            KwtWaybillOrderSubtask orderSubtask = new KwtWaybillOrderSubtask();
+            orderSubtask.setEntId(waybillOrder.getEntId());
+            orderSubtask.setLOrderId(logisticsOrder.getId());
+            orderSubtask.setWOrderId(waybillOrder.getId());
+            orderSubtask.setWOrderNo(waybillOrder.getWOrderNo());
+            orderSubtask.setUnit(logisticsOrder != null ? logisticsOrder.getUnit() : null);
+            orderSubtask.setEntrustAmount(entrustAmount.get(key).doubleValue());
+            orderSubtask.setLoadTime(loadTime1.get(Global.NUMERICAL_ZERO));
+            orderSubtask.setUnloadTime(unloadTime1.get(Global.NUMERICAL_ZERO));
+            orderSubtask.setStatus(waybillOrder.getStatus());
+            waybillOrderSubtaskDao.insert(orderSubtask);
+            subtasks.add(orderSubtask);
+        }
+        return subtasks;
+    }
+
+    /**
+     * @param sendCarEntrust 运输委托信息
+     * @param waybillOrder 运单信息
+     * @desc 运单地址信息
+     * @author zk
+     * @date 2024/3/4
+     **/
+    public KwtWaybillOrderAddress sendCarAddress(SendCarEntrustDto sendCarEntrust, KwtWaybillOrderV1 waybillOrder) {
+        KwtLogisticsOrderAddress logisticsOrderAddress = logisticsOrderAddressDao.selectById(sendCarEntrust.getAddressId());
+        KwtWaybillOrderAddress orderAddress = new KwtWaybillOrderAddress();
+        BeanUtils.copyProperties(logisticsOrderAddress, orderAddress);
+        orderAddress.setId(null);
+        orderAddress.setWOrderId(waybillOrder.getId());
+        orderAddress.setPlanTime(sendCarEntrust.getPlanTime());
+        orderAddress.setEntrustAmount(new BigDecimal(sendCarEntrust.getEntrustAmount()));
+        orderAddress.setSort(sendCarEntrust.getSort());
+        orderAddress.setCreateBy(null);
+        orderAddress.setCreateTime(null);
+        orderAddress.setUpdateBy(null);
+        orderAddress.setUpdateTime(null);
+        waybillOrderAddressDao.insert(orderAddress);
+        return orderAddress;
+    }
+
+
+
+
     /**
      * @param params         派车请求参数
      * @param logisticsOrder 物流订单

+ 516 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/KwtWaybillOrderV1Service.java

@@ -0,0 +1,516 @@
+package com.sckw.transport.service;
+
+import com.alibaba.fastjson2.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.github.pagehelper.PageHelper;
+import com.sckw.core.common.enums.enums.DictTypeEnum;
+import com.sckw.core.exception.BusinessException;
+import com.sckw.core.model.constant.Global;
+import com.sckw.core.model.constant.NumberConstant;
+import com.sckw.core.model.enums.*;
+import com.sckw.core.model.page.PageResult;
+import com.sckw.core.utils.*;
+import com.sckw.core.web.constant.HttpStatus;
+import com.sckw.core.web.context.LoginUserHolder;
+import com.sckw.core.web.response.HttpResult;
+import com.sckw.excel.utils.DateUtil;
+import com.sckw.fleet.api.RemoteFleetService;
+import com.sckw.fleet.api.model.vo.RDriverVo;
+import com.sckw.fleet.api.model.vo.RTruckVo;
+import com.sckw.mongo.enums.BusinessTypeEnum;
+import com.sckw.mongo.model.SckwLogisticsOrder;
+import com.sckw.mongo.model.SckwWaybillOrder;
+import com.sckw.order.api.dubbo.TradeOrderInfoService;
+import com.sckw.redis.constant.RedisConstant;
+import com.sckw.redis.utils.RedissonUtils;
+import com.sckw.stream.enums.MessageEnum;
+import com.sckw.stream.model.SckwBusSum;
+import com.sckw.stream.model.SckwMessage;
+import com.sckw.stream.model.UserInfo;
+import com.sckw.system.api.RemoteSystemService;
+import com.sckw.system.api.model.dto.res.EntCacheResDto;
+import com.sckw.system.api.model.dto.res.SysDictResDto;
+import com.sckw.transport.dao.*;
+import com.sckw.transport.model.*;
+import com.sckw.transport.model.dto.*;
+import com.sckw.transport.model.vo.*;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.validation.Valid;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.stream.function.StreamBridge;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author zk
+ * @desc 车辆运单
+ * @date 2023/7/19 0019
+ */
+@Slf4j
+@Service
+public class KwtWaybillOrderV1Service {
+
+    @Autowired
+    KwtWaybillOrderMapper waybillOrderDao;
+    @Autowired
+    KwtWaybillOrderV1Mapper waybillOrderV1Dao;
+    @Autowired
+    KwtLogisticsOrderMapper logisticsOrderDao;
+    @Autowired
+    KwtLogisticsOrderTrackMapper logisticsOrderTrackDao;
+    @Autowired
+    KwtLogisticsOrderAddressMapper logisticsOrderAddressDao;
+    @Autowired
+    KwtWaybillOrderAddressMapper waybillOrderAddressDao;
+    @Autowired
+    KwtWaybillOrderTrackMapper waybillOrderTrackDao;
+    @Autowired
+    KwtWaybillOrderTicketMapper waybillOrderTicketDao;
+    @Autowired
+    KwtWaybillOrderSubtaskMapper waybillOrderSubtaskDao;
+    @Autowired
+    KwtLogisticsOrderUnitMapper logisticsOrderUnitDao;
+    @Autowired
+    KwtLogisticsOrderGoodsMapper logisticsOrderGoodsDao;
+    @Autowired
+    KwtLogisticsOrderCirculateMapper logisticsOrderCirculateDao;
+    @Autowired
+    KwtLogisticsOrderAmountMapper logisticsOrderAmountDao;
+    @Autowired
+    KwtWaybillOrderTicketService waybillOrderTicketService;
+    @Autowired
+    KwtLogisticsOrderGoodsService kwtLogisticsOrderGoodsService;
+    @Autowired
+    KwtCommonService commonService;
+    @Resource
+    private StreamBridge streamBridge;
+    @DubboReference(version = "1.0.0", group = "design", check = false)
+    private RemoteSystemService remoteSystemService;
+    @DubboReference(version = "1.0.0", group = "design", check = false)
+    private RemoteFleetService remoteFleetService;
+    @DubboReference(version = "1.0.0", group = "design", check = false)
+    private TradeOrderInfoService tradeOrderInfoService;
+    @Value("${message.waybill.refuseSendCar.app}")
+    private String refuseSendCarAppUrl;
+    @Value("${message.waybill.refuseSendCar.pc}")
+    private String refuseSendCarPcUrl;
+
+    /**
+     * @param params 派车参数
+     * @desc 派车-多装多卸
+     * @author zk
+     * @date 2023/7/19
+     **/
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResult sendCarV1(SendCarDto2 params) {
+        /*1、校验*/
+        HttpResult result = checkWaybillOrderV1(params);
+        if (result.getCode() != HttpStatus.SUCCESS_CODE) {
+            return result;
+        }
+
+        /*2、新增运单相关信息*/
+        List<SendCarEntrustDto> sendCarEntrustAll = ranksSave(params);
+
+        /*3、更新承运订单委派信息*/
+        List<Long> lOrderIds = editLogisticsOrder(sendCarEntrustAll, params.getType());
+
+        /*4、更新承运订单状态(包括上级承运订单)*/
+        editLogisticsOrderStatus(lOrderIds);
+        return HttpResult.ok();
+    }
+
+    /**
+     * @param params         派车请求参数
+     * @desc 派车校验
+     * @author zk
+     * @date 2024/3/4
+     **/
+    public HttpResult checkWaybillOrderV1(SendCarDto2 params) {
+        /*控制校验*/
+        if (CollectionUtils.isEmpty(params.getSends())) {
+            return HttpResult.error("请选择委派信息!");
+        } else {
+            for (SendCarInfoDto sendCar:params.getSends()) {
+                if (CollectionUtils.isEmpty(sendCar.getEntrusts())) {
+                    return HttpResult.error("请选择委派信息!");
+                }
+            }
+        }
+
+        //车辆司机信息
+        List<SendCarInfoDto> sends = params.getSends();
+        //物流订单ID
+        List<Long> lOrderIds = new ArrayList<>();
+        //物流订单装卸货地址委派量统计
+        Map<Long, BigDecimal> truckTotalEntrustAmount = new HashMap<>(NumberConstant.SIXTEEN);
+        for (SendCarInfoDto sendCar:sends) {
+            //运输委托信息
+            List<SendCarEntrustDto> entrusts = sendCar.getEntrusts();
+            /*数据组装*/
+            for (SendCarEntrustDto e : entrusts) {
+                lOrderIds.add(e.getLOrderId());
+                //承运订单该车辆计划运输总量:核定载量 * 趟次
+                BigDecimal entrustAmount = BigDecimal.valueOf(e.getEntrustAmount() * sendCar.getCount());
+                BigDecimal totalEntrustAmount = truckTotalEntrustAmount.get(e.getAddressId()) != null
+                        ? truckTotalEntrustAmount.get(e.getAddressId()) : NumberConstant.ZERO_TWO;
+                truckTotalEntrustAmount.put(e.getAddressId(), totalEntrustAmount.add(entrustAmount));
+            }
+        }
+        List<Long> lOrderIdsList = lOrderIds.stream().distinct().toList();
+
+        /*校验物流运单是否可以派车*/
+        for (Long lOrderId:lOrderIdsList) {
+            KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(lOrderId);
+            if (logisticsOrder == null) {
+                return HttpResult.error("订单"+lOrderId+"已不存在!");
+            }
+
+            //状态校验
+            if (!logisticsOrder.getStatus().equals(LogisticsOrderEnum.WAIT_DELIVERY.getCode())
+                    && !logisticsOrder.getStatus().equals(LogisticsOrderEnum.IN_TRANSIT.getCode())) {
+                return HttpResult.error("订单" + logisticsOrder.getLOrderNo() + LogisticsOrderEnum.getName(logisticsOrder.getStatus()) + "不能派车!");
+            }
+
+            //剩余可运量校验
+            BigDecimal entrustAmount = logisticsOrder.getEntrustAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getEntrustAmount();
+            BigDecimal subcontractAmount = logisticsOrder.getSubcontractAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getSubcontractAmount();
+            //历史下游司机委派量 + 分包量
+            BigDecimal entrustAmountTotal = entrustAmount.add(subcontractAmount);
+            if (entrustAmountTotal.compareTo(logisticsOrder.getAmount()) > 0) {
+                return HttpResult.error("订单" + logisticsOrder.getLOrderNo() + "剩余可运量已不能派车!");
+            }
+
+            /*校验是车辆委托量否超过物流订单剩余量-趟次*/
+            //物流订单地址委托量信息-装货信息
+            KwtLogisticsOrderAddress queryAmount = new KwtLogisticsOrderAddress();
+            queryAmount.setLOrderId(lOrderId);
+            queryAmount.setAddressType(AddressDefaultTypeEnum.SHIPMENT.getCode());
+            List<KwtLogisticsOrderAmount> logisticsOrderAmounts = logisticsOrderAmountDao.findByAddress(queryAmount);
+            for (KwtLogisticsOrderAmount orderAmount:logisticsOrderAmounts) {
+                BigDecimal truckEntrustAmount = truckTotalEntrustAmount.get(orderAmount.getLAddressId());
+                //当前下游司机委派量 + 历史下游司机委派量 + 分包量
+                BigDecimal actualAmount = truckEntrustAmount.add(entrustAmountTotal);
+                if (actualAmount.doubleValue() > orderAmount.getAmount().doubleValue()) {
+                    return HttpResult.error("订单" + logisticsOrder.getLOrderNo() + "累计派车量已大于剩余可运量!");
+                }
+            }
+        }
+        return HttpResult.ok(truckTotalEntrustAmount);
+    }
+
+    /**
+     * @param params         派车请求参数
+     * @desc 新增运单相关信息
+     * @author zk
+     * @date 2024/3/5
+     **/
+    public List<SendCarEntrustDto> ranksSave(SendCarDto2 params) {
+        //车辆司机信息
+        List<SendCarInfoDto> sends = params.getSends();
+        //物流订单对应地址信息(所有)
+        List<SendCarEntrustDto> sendCarEntrustAll = new ArrayList<>();
+        for (SendCarInfoDto sendCar:sends) {
+            //趟次(循环单默认趟次为1)
+            int count = params.getType() == Global.NUMERICAL_ONE ? sendCar.getCount() : Global.NUMERICAL_ONE;
+            for (int i=0; i<count; i++) {
+                //新增运单信息
+                KwtWaybillOrderV1 waybillOrder = sendCarDriver(sendCar, params.getType());
+                //运输委托信息
+                List<SendCarEntrustDto> entrusts = sendCar.getEntrusts();
+                //物流订单对应地址信息
+                Map<Long, List<SendCarEntrustDto>> sendCarEntrusts = new HashMap<>(NumberConstant.SIXTEEN);
+                //数据组装-物流订单归类(合并派车)
+                for (SendCarEntrustDto sendCarEntrust:entrusts) {
+                    //物流订单ID
+                    Long lOrderId = sendCarEntrust.getLOrderId();
+                    //委派信息
+                    List<SendCarEntrustDto> entrustDtos = new ArrayList<>(){{add(sendCarEntrust);}};
+                    if (sendCarEntrusts.get(lOrderId) == null) {
+                        sendCarEntrusts.put(lOrderId, entrustDtos);
+                    } else {
+                        entrustDtos.addAll(sendCarEntrusts.get(lOrderId));
+                        sendCarEntrusts.put(lOrderId, entrustDtos);
+                    }
+                    sendCarEntrustAll.add(sendCarEntrust);
+                }
+
+                //数据存储
+                for (Long lOrderId:sendCarEntrusts.keySet()) {
+                    //物流订单关联委派地址信息
+                    List<SendCarEntrustDto> sendCars = sendCarEntrusts.get(lOrderId);
+                    //物流订单委派量统计
+                    BigDecimal entrustAmount = NumberConstant.ZERO_TWO;
+                    //物流订单委派装货时间
+                    List<Date> loadTime = new ArrayList<>();
+                    //物流订单委派卸货时间
+                    List<Date> unloadTime = new ArrayList<>();
+                    //数据组装-数据统计
+                    for (SendCarEntrustDto sendCarEntrust:sendCars) {
+                        //委派量
+                        BigDecimal amount = BigDecimal.valueOf(sendCarEntrust.getEntrustAmount());
+                        //计划装卸货时间
+                        Date planTime = sendCarEntrust.getPlanTime();
+                        //装货+卸货
+                        if (sendCarEntrust.getAddressType() == AddressDefaultTypeEnum.SHIPMENT.getCode()) {
+                            entrustAmount = entrustAmount.add(amount);
+                            loadTime.add(planTime);
+                        } else {
+                            unloadTime.add(planTime);
+                        }
+                    }
+
+                    //新增运单子单信息
+                    KwtWaybillOrderSubtask subtasks = sendCarSubtask(waybillOrder, lOrderId, entrustAmount, loadTime, unloadTime);
+                    for (SendCarEntrustDto sendCarEntrust:sendCars) {
+                        //新增地址信息
+                        sendCarAddress(subtasks.getId(), sendCarEntrust, waybillOrder);
+                    }
+                }
+
+                /*车辆运单状态记录*/
+                this.setWaybillOrderTrack(waybillOrder.getId(), waybillOrder.getUpdateTime(), waybillOrder.getStatus(), null);
+            }
+        }
+        return sendCarEntrustAll;
+    }
+
+    /**
+     * @param sendCarEntrusts         委派参数
+     * @desc 更新承运订单委派信息
+     * @author zk
+     * @date 2024/3/5
+     **/
+    public List<Long> editLogisticsOrder(List<SendCarEntrustDto> sendCarEntrusts, int type) {
+        //物流订单ID
+        List<Long> lOrderIds = new ArrayList<>();
+        //物流订单对应委派量(所有)
+        Map<Long, BigDecimal> lEntrustAmount = new HashMap<>(NumberConstant.SIXTEEN);
+        //物流订单地址对应委派量(所有)
+        Map<Long, BigDecimal> aEntrustAmount = new HashMap<>(NumberConstant.SIXTEEN);
+        //数据组装-数据统计
+        for (SendCarEntrustDto sendCarEntrust:sendCarEntrusts) {
+            //委派量
+            BigDecimal amount = BigDecimal.valueOf(sendCarEntrust.getEntrustAmount());
+            //装货+卸货
+            if (sendCarEntrust.getAddressType() == AddressDefaultTypeEnum.SHIPMENT.getCode()) {
+                if (lEntrustAmount.get(sendCarEntrust.getLOrderId()) == null) {
+                    lEntrustAmount.put(sendCarEntrust.getLOrderId(), amount);
+                } else {
+                    BigDecimal entrustAmount = lEntrustAmount.get(sendCarEntrust.getLOrderId()).add(amount);
+                    lEntrustAmount.put(sendCarEntrust.getLOrderId(), entrustAmount);
+                }
+                if (aEntrustAmount.get(sendCarEntrust.getAddressId()) == null) {
+                    aEntrustAmount.put(sendCarEntrust.getAddressId(), amount);
+                } else {
+                    BigDecimal entrustAmount = aEntrustAmount.get(sendCarEntrust.getAddressId()).add(amount);
+                    aEntrustAmount.put(sendCarEntrust.getAddressId(), entrustAmount);
+                }
+            }
+            lOrderIds.add(sendCarEntrust.getLOrderId());
+        }
+
+        //循环单不更新物流订单委派量
+        if (type == Global.NUMERICAL_TWO) {
+            return lOrderIds.stream().distinct().toList();
+        }
+
+        //更新承运订单运量kwt_logistics_order_amount委派量
+        for (Long lOrderId:lEntrustAmount.keySet()) {
+            KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(lOrderId);
+            BigDecimal entrustAmount = logisticsOrder.getEntrustAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrder.getEntrustAmount();
+            logisticsOrder.setEntrustAmount(entrustAmount.add(lEntrustAmount.get(lOrderId)));
+            logisticsOrderDao.updateById(logisticsOrder);
+        }
+
+        //更新承运订单kwt_logistics_order委派量
+        for (Long lAddressId:aEntrustAmount.keySet()) {
+            KwtLogisticsOrderAmount logisticsOrderAmount = logisticsOrderAmountDao.findByAddressId(lAddressId);
+            BigDecimal entrustAmount = logisticsOrderAmount.getEntrustAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrderAmount.getEntrustAmount();
+            logisticsOrderAmount.setEntrustAmount(entrustAmount.add(aEntrustAmount.get(lAddressId)));
+            logisticsOrderAmountDao.updateById(logisticsOrderAmount);
+        }
+        return lOrderIds.stream().distinct().toList();
+    }
+
+    /**
+     * @param lOrderIds         物流订单集
+     * @desc 更新承运订单状态信息(包括分包上级物流订单)
+     * @author zk
+     * @date 2024/3/5
+     **/
+    public void editLogisticsOrderStatus(List<Long> lOrderIds) {
+        for (Long lOrderId:lOrderIds) {
+            //物流订单信息
+            KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(lOrderId);
+            //当前承运订单所属分包层级
+            String pids = logisticsOrder.getPids();
+            if (StringUtils.isNotBlank(pids)) {
+                String[] idArray = pids.split(Global.COMMA);
+                for (String id : idArray) {
+                    KwtLogisticsOrder order = logisticsOrderDao.selectById(id);
+                    //承运订单-待派车
+                    if (order.getStatus().equals(LogisticsOrderEnum.WAIT_DELIVERY.getCode())) {
+                        //更新当前承运订单状态(待派车->运输中)
+                        order.setStatus(LogisticsOrderEnum.IN_TRANSIT.getCode());
+                        logisticsOrderDao.updateById(order);
+
+                        //承运订单状态记录
+                        KwtLogisticsOrderTrack orderTrack = new KwtLogisticsOrderTrack();
+                        orderTrack.setLOrderId(order.getId());
+                        orderTrack.setStatus(order.getStatus());
+                        orderTrack.setRemark(LogisticsOrderEnum.getName(order.getStatus()));
+                        logisticsOrderTrackDao.insert(orderTrack);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * @param sendCar 车辆司机信息
+     * @param type 派车类型(1 趟次、2 循环)
+     * @desc 运单信息
+     * @author zk
+     * @date 2024/3/4
+     **/
+    public KwtWaybillOrderV1 sendCarDriver(SendCarInfoDto sendCar, int type) {
+        //车辆运单编号存储
+        //String wOrderNo = getRedisGenerateWaybillOrderNo(RedisOrderGenerateEnum.WAYBILL_ORDER, OrderRuleEnum.WAYBILL_ORDER, logisticsOrder.getLOrderNo());
+        //车辆信息
+        RTruckVo truck = remoteFleetService.findTruck(sendCar.getTruckId());
+        //司机信息
+        RDriverVo driver = remoteFleetService.findDriver(sendCar.getDriverId());
+        //运单信息
+        KwtWaybillOrderV1 waybillOrder = new KwtWaybillOrderV1();
+        waybillOrder.setEntId(LoginUserHolder.getEntId());
+        waybillOrder.setWOrderNo("W"+System.currentTimeMillis());
+        waybillOrder.setType(type);
+        waybillOrder.setTruckId(sendCar.getTruckId());
+        waybillOrder.setTruckNo(truck != null ? truck.getTruckNo() : null);
+        waybillOrder.setDriverId(sendCar.getDriverId());
+        waybillOrder.setDriverName(driver != null ? driver.getName() : null);
+        waybillOrder.setDriverPhone(driver != null ? driver.getPhone() : null);
+        waybillOrder.setDriverIdcard(driver != null ? driver.getIdcard() : null);
+        waybillOrder.setStatus(CarWaybillEnum.PENDING_ORDER.getCode());
+        waybillOrderV1Dao.insert(waybillOrder);
+        return waybillOrder;
+    }
+
+    /**
+     * @param waybillOrder 运单信息
+     * @param lOrderId 物流运单ID
+     * @param entrustAmount 运输委托信息
+     * @param loadTime 装货时间
+     * @param unloadTime 卸货时间
+     * @desc 车辆运单-子运单信息
+     * @author zk
+     * @date 2024/3/4
+     **/
+    public KwtWaybillOrderSubtask sendCarSubtask(KwtWaybillOrderV1 waybillOrder, Long lOrderId, BigDecimal entrustAmount, List<Date> loadTime, List<Date> unloadTime) {
+        loadTime.sort(Comparator.naturalOrder());
+        unloadTime.sort(Comparator.reverseOrder());
+        KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(lOrderId);
+        KwtWaybillOrderSubtask orderSubtask = new KwtWaybillOrderSubtask();
+        orderSubtask.setEntId(waybillOrder.getEntId());
+        orderSubtask.setLOrderId(lOrderId);
+        orderSubtask.setWOrderId(waybillOrder.getId());
+        orderSubtask.setWOrderNo(waybillOrder.getWOrderNo());
+        orderSubtask.setUnit(logisticsOrder != null ? logisticsOrder.getUnit() : null);
+        orderSubtask.setEntrustAmount(entrustAmount.doubleValue());
+        orderSubtask.setLoadTime(loadTime.get(Global.NUMERICAL_ZERO));
+        orderSubtask.setUnloadTime(unloadTime.get(Global.NUMERICAL_ZERO));
+        orderSubtask.setStatus(waybillOrder.getStatus());
+        waybillOrderSubtaskDao.insert(orderSubtask);
+        return orderSubtask;
+    }
+
+    /**
+     * @param wSubtaskId 运单-子订单ID
+     * @param sendCarEntrust 运输委托信息
+     * @param waybillOrder 运单信息
+     * @desc 运单地址信息
+     * @author zk
+     * @date 2024/3/4
+     **/
+    public KwtWaybillOrderAddress sendCarAddress(Long wSubtaskId, SendCarEntrustDto sendCarEntrust, KwtWaybillOrderV1 waybillOrder) {
+        KwtLogisticsOrderAddress logisticsOrderAddress = logisticsOrderAddressDao.selectById(sendCarEntrust.getAddressId());
+        KwtWaybillOrderAddress orderAddress = new KwtWaybillOrderAddress();
+        BeanUtils.copyProperties(logisticsOrderAddress, orderAddress);
+        orderAddress.setId(null);
+        orderAddress.setWOrderId(waybillOrder.getId());
+        orderAddress.setWSubtaskId(wSubtaskId);
+        orderAddress.setLAddressId(sendCarEntrust.getAddressId());
+        orderAddress.setPlanTime(sendCarEntrust.getPlanTime());
+        orderAddress.setEntrustAmount(BigDecimal.valueOf(sendCarEntrust.getEntrustAmount()));
+        orderAddress.setSort(sendCarEntrust.getSort());
+        orderAddress.setCreateBy(null);
+        orderAddress.setCreateTime(null);
+        orderAddress.setUpdateBy(null);
+        orderAddress.setUpdateTime(null);
+        waybillOrderAddressDao.insert(orderAddress);
+        return orderAddress;
+    }
+
+    /**
+     * @param wOrderId 车辆订单ID
+     * @param status   车辆运单状态
+     * @param remark   备注
+     * @desc 新增运单状态记录
+     * @author zk
+     * @date 2023/7/20
+     **/
+    public void setWaybillOrderTrack(Long wOrderId, Date operateTime, int status, String remark) {
+        KwtWaybillOrderTrack orderTrack = new KwtWaybillOrderTrack();
+        orderTrack.setWOrderId(wOrderId);
+        orderTrack.setOperateTime(operateTime);
+        orderTrack.setStatus(status);
+        orderTrack.setRemark(remark);
+        waybillOrderTrackDao.insert(orderTrack);
+    }
+
+    /**
+     * @param type  字典类型
+     * @param value 字典值
+     * @desc 获取数据字典值
+     * @author zk
+     * @date 2023/8/30
+     **/
+    public String getDictValue(String type, String value) {
+        if (StringUtils.isBlank(type) || StringUtils.isBlank(value)) {
+            return null;
+        }
+        List<String> dictKey = new ArrayList<>() {{
+            add(type + Global.POUND + value);
+        }};
+        Map<String, SysDictResDto> dicts = remoteSystemService.queryDictMapByTypeValues(String.join(Global.COMMA, dictKey));
+        SysDictResDto dict = dicts == null ? null : dicts.get(DictTypeEnum.APPROVED_DRIVING.getType() + Global.POUND + value);
+        return dict != null ? dict.getLabel() : null;
+    }
+
+    /**
+     * @param dictKey 字典值
+     * @desc 获取数据字典
+     * @author zk
+     * @date 2023/9/11
+     **/
+    public Map<String, SysDictResDto> dict(List<String> dictKey) {
+        if (CollectionUtils.isEmpty(dictKey)) {
+            return Collections.emptyMap();
+        }
+        dictKey = dictKey.stream().distinct().collect(Collectors.toList());
+        return remoteSystemService.queryDictMapByTypeValues(String.join(Global.COMMA, dictKey));
+    }
+
+}

+ 1 - 1
sckw-modules/sckw-transport/src/main/resources/mapper/KwtLogisticsOrderAmountMapper.xml

@@ -9,7 +9,7 @@
         kloa1.entrust_amount entrustAmount, kloa1.load_amount loadAmount, kloa1.unload_amount unloadAmount, kloa1.ignore_amount ignoreAmount,
         kloa1.load_time loadTime, kloa1.unload_time unloadTime, kloa1.total_load_amount totalLoadAmount, kloa1.total_unload_amount totalUnloadAmount
         from kwt_logistics_order_amount kloa1
-        left join kwt_logistics_order_address kloa2 on kloa2.id = kloa1.address_id
+        left join kwt_logistics_order_address kloa2 on kloa2.id = kloa1.l_address_id
         where kloa1.del_flag = 0 and kloa2.del_flag = 0
         <if test="lOrderId != null and lOrderId !=''">
             and kloa1.l_order_id = #{lOrderId, jdbcType=BIGINT}