浏览代码

1、4.2撤回、接单、拒绝接单、出车、拒绝出车接口;

zk 1 年之前
父节点
当前提交
6e07a5a860

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

@@ -156,7 +156,7 @@ public class KwtWaybillOrderController {
      * @param params {}
      * @desc 派车-趟次/循环
      * @author zk
-     * @date 2023/5/30
+     * @date 2024/3/1
      **/
     @PostMapping("/sendCarV1")
     public HttpResult sendCarV1(@RequestBody @Valid SendCarDto2 params){
@@ -174,6 +174,17 @@ public class KwtWaybillOrderController {
         return waybillOrderService.cancelSendCarV1(ids);
     }
 
+    /**
+     * @param ids 车辆运单主键ID,多个已逗号隔开
+     * @desc 取消派车
+     * @author zk
+     * @date 2024/3/7
+     **/
+    @PostMapping("/cancelSendCarV1")
+    public HttpResult cancelSendCarV1(@RequestBody List<Long> ids){
+        return waybillOrderV1Service.cancelSendCarV1(ids);
+    }
+
     /**
      * @param params {}
      * @desc 确认接单
@@ -185,6 +196,17 @@ public class KwtWaybillOrderController {
         return waybillOrderService.confirmSendCar(params);
     }
 
+    /**
+     * @param params {}
+     * @desc 确认接单
+     * @author zk
+     * @date 2024/3/7
+     **/
+    @PostMapping("/confirmSendCarV1")
+    public HttpResult confirmSendCarV1(@RequestBody @Valid OperateWaybillDto params){
+        return waybillOrderV1Service.confirmSendCarV1(params);
+    }
+
     /**
      * @param params {}
      * @desc 拒绝接单
@@ -196,6 +218,17 @@ public class KwtWaybillOrderController {
         return waybillOrderService.refuseSendCar(params);
     }
 
+    /**
+     * @param params {}
+     * @desc 拒绝接单
+     * @author zk
+     * @date 2024/3/7
+     **/
+    @PostMapping("/refuseSendCarV1")
+    public HttpResult refuseSendCarV1(@RequestBody @Valid OperateWaybillDto params){
+        return waybillOrderV1Service.refuseSendCarV1(params);
+    }
+
     /**
      * @param params {}
      * @desc 确认出车
@@ -207,6 +240,17 @@ public class KwtWaybillOrderController {
         return waybillOrderService.confirmDeparture(params);
     }
 
+    /**
+     * @param params {}
+     * @desc 确认出车
+     * @author zk
+     * @date 2023/7/26
+     **/
+    @PostMapping("/confirmDepartureV1")
+    public HttpResult confirmDepartureV1(@RequestBody @Valid OperateWaybillDto params){
+        return waybillOrderV1Service.confirmDepartureV1(params);
+    }
+
     /**
      * @param params {}
      * @desc 拒绝出车
@@ -218,6 +262,17 @@ public class KwtWaybillOrderController {
         return waybillOrderService.refuseDeparture(params);
     }
 
+    /**
+     * @param params {}
+     * @desc 拒绝出车
+     * @author zk
+     * @date 2023/7/26
+     **/
+    @PostMapping("/refuseDepartureV1")
+    public HttpResult refuseDepartureV1(@RequestBody @Valid OperateWaybillDto params){
+        return waybillOrderV1Service.refuseDepartureV1(params);
+    }
+
     /**
      * @param params {}
      * @desc 到达装货地点

+ 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("lAddressId") Long lAddressId);
+    KwtLogisticsOrderAmount findByLAddressId(@Param("lAddressId") Long lAddressId);
 }

+ 2 - 10
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/dao/KwtWaybillOrderAddressMapper.java

@@ -14,16 +14,6 @@ import java.util.List;
 @Mapper
 public interface KwtWaybillOrderAddressMapper extends BaseMapper<KwtWaybillOrderAddress> {
 
-    /**
-     * 新增
-     * @param params 新增参数
-     * @desc 新增
-     * @author zk
-     * @date 2023/7/20
-     * @return 更新记录数
-     **/
-    int insert1(KwtWaybillOrderAddress params);
-
     /**
      * 查询车辆运单装卸货地址信息
      * @param wOrderId 车辆订单id
@@ -35,6 +25,8 @@ public interface KwtWaybillOrderAddressMapper extends BaseMapper<KwtWaybillOrder
      **/
     KwtWaybillOrderAddress findByAddress(@Param("wOrderId") Long wOrderId, @Param("addressType") Integer addressType);
 
+    List<KwtWaybillOrderAddress> findByAddresses(@Param("wOrderId") Long wOrderId, @Param("addressType") Integer addressType);
+
     /**
      * 查询车辆运单装卸货地址CODE
      * @param entId 企业信息

+ 7 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/dao/KwtWaybillOrderSubtaskMapper.java

@@ -3,6 +3,9 @@ package com.sckw.transport.dao;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sckw.transport.model.KwtWaybillOrderSubtask;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * @author zk
@@ -11,4 +14,8 @@ import org.apache.ibatis.annotations.Mapper;
  */
 @Mapper
 public interface KwtWaybillOrderSubtaskMapper extends BaseMapper<KwtWaybillOrderSubtask> {
+
+    List<KwtWaybillOrderSubtask> findByWOrderId(@Param("wOrderId") Long wOrderId);
+
+    KwtWaybillOrderSubtask findByOrderId(@Param("wOrderId") Long wOrderId, @Param("lOrderId") Long lOrderId);
 }

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

@@ -24,5 +24,7 @@ import java.util.Map;
 @Mapper
 public interface KwtWaybillOrderV1Mapper extends BaseMapper<KwtWaybillOrderV1> {
 
+    WaybillCountVo findCountByDriverOrTruck(@Param("driverId") Long driverId, @Param("truckId") Long truckId);
 
+    WaybillCountVo findAmountByDriverOrTruck(@Param("driverId") Long driverId, @Param("truckId") Long truckId);
 }

+ 1 - 2
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/dto/OperateSendCarDto.java

@@ -18,10 +18,9 @@ import java.util.Date;
 public class OperateSendCarDto {
 
     /**
-     * 派车类型(1:趟次:2:循环)
+     * 派车类型(1趟次、2循环)
      */
     @JsonProperty("type")
-    @NotNull(message = "派车类型不能为空")
     private Integer type;
 
     /**

+ 44 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/KwtWaybillOrderSubtaskService.java

@@ -1,6 +1,17 @@
 package com.sckw.transport.service;
 
+import com.sckw.core.model.constant.Global;
+import com.sckw.transport.dao.KwtLogisticsOrderMapper;
+import com.sckw.transport.dao.KwtWaybillOrderSubtaskMapper;
+import com.sckw.transport.model.KwtLogisticsOrder;
+import com.sckw.transport.model.KwtWaybillOrderSubtask;
+import com.sckw.transport.model.KwtWaybillOrderV1;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import java.math.BigDecimal;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
 
 /**
  * @author zk
@@ -9,4 +20,37 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class KwtWaybillOrderSubtaskService {
+
+    @Autowired
+    KwtWaybillOrderSubtaskMapper waybillOrderSubtaskDao;
+    @Autowired
+    KwtLogisticsOrderMapper logisticsOrderDao;
+
+    /**
+     * @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;
+    }
 }

+ 333 - 41
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/KwtWaybillOrderV1Service.java

@@ -60,9 +60,6 @@ import java.util.stream.Collectors;
 @Slf4j
 @Service
 public class KwtWaybillOrderV1Service {
-
-    @Autowired
-    KwtWaybillOrderMapper waybillOrderDao;
     @Autowired
     KwtWaybillOrderV1Mapper waybillOrderV1Dao;
     @Autowired
@@ -92,6 +89,8 @@ public class KwtWaybillOrderV1Service {
     @Autowired
     KwtLogisticsOrderGoodsService kwtLogisticsOrderGoodsService;
     @Autowired
+    KwtWaybillOrderSubtaskService waybillOrderSubtaskService;
+    @Autowired
     KwtCommonService commonService;
     @Resource
     private StreamBridge streamBridge;
@@ -156,16 +155,18 @@ public class KwtWaybillOrderV1Service {
         //物流订单装卸货地址委派量统计
         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;
             //运输委托信息
             List<SendCarEntrustDto> entrusts = sendCar.getEntrusts();
             /*数据组装*/
-            for (SendCarEntrustDto e : entrusts) {
-                lOrderIds.add(e.getLOrderId());
+            for (SendCarEntrustDto sendCarEntrust : entrusts) {
+                lOrderIds.add(sendCarEntrust.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));
+                BigDecimal entrustAmount = BigDecimal.valueOf(sendCarEntrust.getEntrustAmount() * count);
+                BigDecimal totalEntrustAmount = truckTotalEntrustAmount.get(sendCarEntrust.getAddressId()) != null
+                        ? truckTotalEntrustAmount.get(sendCarEntrust.getAddressId()) : NumberConstant.ZERO_TWO;
+                truckTotalEntrustAmount.put(sendCarEntrust.getAddressId(), totalEntrustAmount.add(entrustAmount));
             }
         }
         List<Long> lOrderIdsList = lOrderIds.stream().distinct().toList();
@@ -203,7 +204,7 @@ public class KwtWaybillOrderV1Service {
                 //当前下游司机委派量 + 历史下游司机委派量 + 分包量
                 BigDecimal actualAmount = truckEntrustAmount.add(entrustAmountTotal);
                 if (actualAmount.doubleValue() > orderAmount.getAmount().doubleValue()) {
-                    return HttpResult.error("订单" + logisticsOrder.getLOrderNo() + "累计派车量已大于剩余可运量!");
+                    return HttpResult.error("订单" + logisticsOrder.getLOrderNo() + "可运量小于累计派车量!");
                 }
             }
         }
@@ -272,7 +273,7 @@ public class KwtWaybillOrderV1Service {
                     }
 
                     //新增运单子单信息
-                    KwtWaybillOrderSubtask subtasks = sendCarSubtask(waybillOrder, lOrderId, entrustAmount, loadTime, unloadTime);
+                    KwtWaybillOrderSubtask subtasks = waybillOrderSubtaskService.sendCarSubtask(waybillOrder, lOrderId, entrustAmount, loadTime, unloadTime);
                     for (SendCarEntrustDto sendCarEntrust:sendCars) {
                         //新增地址信息
                         sendCarAddress(subtasks.getId(), sendCarEntrust, waybillOrder);
@@ -336,7 +337,7 @@ public class KwtWaybillOrderV1Service {
 
         //更新承运订单kwt_logistics_order委派量
         for (Long lAddressId:aEntrustAmount.keySet()) {
-            KwtLogisticsOrderAmount logisticsOrderAmount = logisticsOrderAmountDao.findByAddressId(lAddressId);
+            KwtLogisticsOrderAmount logisticsOrderAmount = logisticsOrderAmountDao.findByLAddressId(lAddressId);
             BigDecimal entrustAmount = logisticsOrderAmount.getEntrustAmount() == null ? new BigDecimal(Global.AMOUNT) : logisticsOrderAmount.getEntrustAmount();
             logisticsOrderAmount.setEntrustAmount(entrustAmount.add(aEntrustAmount.get(lAddressId)));
             logisticsOrderAmountDao.updateById(logisticsOrderAmount);
@@ -408,34 +409,6 @@ public class KwtWaybillOrderV1Service {
         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 运输委托信息
@@ -474,12 +447,331 @@ public class KwtWaybillOrderV1Service {
     public void setWaybillOrderTrack(Long wOrderId, Date operateTime, int status, String remark) {
         KwtWaybillOrderTrack orderTrack = new KwtWaybillOrderTrack();
         orderTrack.setWOrderId(wOrderId);
-        orderTrack.setOperateTime(operateTime);
+        orderTrack.setOperateTime(operateTime == null ? new Date() : operateTime);
         orderTrack.setStatus(status);
         orderTrack.setRemark(remark);
         waybillOrderTrackDao.insert(orderTrack);
     }
 
+    /**
+     * @param ids 车辆运单主键ID,多个已逗号隔开
+     * @desc 取消派车(趟次派车)
+     * @author zk
+     * @date 2024/3/7
+     **/
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResult cancelSendCarV1(List<Long> ids) {
+        /*1、校验*/
+        if (CollectionUtils.isEmpty(ids)) {
+            return HttpResult.error("请选择需要撤回的运单!");
+        }
+        for (Long wOrderId:ids) {
+            KwtWaybillOrderV1 waybillOrder = waybillOrderV1Dao.selectById(wOrderId);
+            if (waybillOrder == null) {
+                return HttpResult.error("运单" + wOrderId + "不存在,请确认!");
+            }
+            //趟次运单才能撤回
+            if (waybillOrder.getType() != Global.NUMERICAL_ONE) {
+                return HttpResult.error("运单" + waybillOrder.getWOrderNo() + "为循环运单不能撤回!");
+            }
+            //待接单的车辆运单才能撤回
+            if (!waybillOrder.getStatus().equals(CarWaybillEnum.PENDING_ORDER.getCode())) {
+                return HttpResult.error("运单" + waybillOrder.getWOrderNo() + "当前状态已不能撤回!");
+            }
+
+            /*2、更新运单状态*/
+            waybillOrder.setStatus(CarWaybillEnum.REVOKED.getCode());
+            waybillOrderV1Dao.updateById(waybillOrder);
+
+            /*3、新增运单状态记录*/
+            setWaybillOrderTrack(waybillOrder.getId(), waybillOrder.getUpdateTime(), waybillOrder.getStatus(), null);
+
+            /*4、回退物流订单委托量*/
+            /*4.1、装货址委派量entrustAmount回退*/
+            //运单装货地址
+            List<KwtWaybillOrderAddress> orderAddresses = waybillOrderAddressDao.findByAddresses(wOrderId, AddressDefaultTypeEnum.SHIPMENT.getCode());
+            for (KwtWaybillOrderAddress address:orderAddresses) {
+                //物流订单-装卸货地址运量信息
+                KwtLogisticsOrderAmount logisticsOrderAmount = logisticsOrderAmountDao.findByLAddressId(address.getLAddressId());
+                //承运订单地址已委派量=承运订单地址原委派量-当前车辆运单地址委派量
+                BigDecimal entrustAmount = logisticsOrderAmount.getEntrustAmount() == null ? NumberConstant.ZERO_TWO : logisticsOrderAmount.getEntrustAmount();
+                logisticsOrderAmount.setEntrustAmount(entrustAmount.subtract(address.getEntrustAmount()));
+                logisticsOrderAmountDao.updateById(logisticsOrderAmount);
+            }
+
+            /*4.2、物流订单委派量entrustAmount回退*/
+            //运单子订单
+            List<KwtWaybillOrderSubtask> orderSubtasks = waybillOrderSubtaskDao.findByWOrderId(wOrderId);
+            for (KwtWaybillOrderSubtask subtask:orderSubtasks) {
+                //物流订单
+                KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(subtask.getLOrderId());
+                //承运订单已委派量=承运订单原委派量-当前车辆运单委派量
+                BigDecimal entrustAmount = logisticsOrder.getEntrustAmount() == null ? NumberConstant.ZERO_TWO : logisticsOrder.getEntrustAmount();
+                logisticsOrder.setEntrustAmount(entrustAmount.subtract(BigDecimal.valueOf(subtask.getEntrustAmount())));
+                logisticsOrderDao.updateById(logisticsOrder);
+            }
+        }
+        return HttpResult.ok();
+    }
+
+    /**
+     * @param params {}
+     * @desc 确认接单
+     * @author zk
+     * @date 2024/3/7
+     **/
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResult confirmSendCarV1(OperateWaybillDto params) {
+        /*1、校验*/
+        Long wOrderId = params.getWOrderId();
+        //运单信息
+        KwtWaybillOrderV1 waybillOrder = waybillOrderV1Dao.selectById(wOrderId);
+        if (waybillOrder == null) {
+            return HttpResult.error("运单" + wOrderId + "不存在,请确认!");
+        }
+        //待接单的车辆运单才能撤回
+        if (!waybillOrder.getStatus().equals(CarWaybillEnum.PENDING_ORDER.getCode())) {
+            return HttpResult.error("运单" + waybillOrder.getWOrderNo() + "当前状态已不能接单!");
+        }
+
+        /*2、更新运单状态*/
+        waybillOrder.setStatus(CarWaybillEnum.PENDING_VEHICLE.getCode());
+        waybillOrderV1Dao.updateById(waybillOrder);
+
+        /*3、新增运单状态记录*/
+        setWaybillOrderTrack(waybillOrder.getId(), params.getOperateTime(), waybillOrder.getStatus(), params.getRemark());
+
+        /*4、更新司机/车辆数据*/
+        //更新司机信息
+        editDriver(waybillOrder.getDriverId());
+        //更新车辆信息
+        editTruck(waybillOrder.getTruckId());
+        //趟次运单不对物流订单委托量变更
+        if (waybillOrder.getType() == Global.NUMERICAL_ONE) {
+            return HttpResult.ok();
+        }
+
+        /*5、累加物流订单委托量(循环运单)*/
+        /*5.1、装货址委派量entrustAmount累加*/
+        //运单装货地址
+        List<KwtWaybillOrderAddress> orderAddresses = waybillOrderAddressDao.findByAddresses(wOrderId, AddressDefaultTypeEnum.SHIPMENT.getCode());
+        for (KwtWaybillOrderAddress address:orderAddresses) {
+            //物流订单-装卸货地址运量信息
+            KwtLogisticsOrderAmount logisticsOrderAmount = logisticsOrderAmountDao.findByLAddressId(address.getLAddressId());
+            //承运订单地址已委派量=承运订单地址原委派量+当前车辆运单地址委派量
+            BigDecimal entrustAmount = logisticsOrderAmount.getEntrustAmount() == null ? NumberConstant.ZERO_TWO : logisticsOrderAmount.getEntrustAmount();
+            logisticsOrderAmount.setEntrustAmount(entrustAmount.add(address.getEntrustAmount()));
+            logisticsOrderAmountDao.updateById(logisticsOrderAmount);
+        }
+
+        /*5.2、物流订单委派量entrustAmount累加*/
+        //运单子订单
+        List<KwtWaybillOrderSubtask> orderSubtasks = waybillOrderSubtaskDao.findByWOrderId(wOrderId);
+        for (KwtWaybillOrderSubtask subtask:orderSubtasks) {
+            //物流订单
+            KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(subtask.getLOrderId());
+            //承运订单已委派量=承运订单原委派量+当前车辆运单委派量
+            BigDecimal entrustAmount = logisticsOrder.getEntrustAmount() == null ? NumberConstant.ZERO_TWO : logisticsOrder.getEntrustAmount();
+            logisticsOrder.setEntrustAmount(entrustAmount.add(BigDecimal.valueOf(subtask.getEntrustAmount())));
+            logisticsOrderDao.updateById(logisticsOrder);
+        }
+        return HttpResult.ok();
+    }
+
+    /**
+     * @param params {}
+     * @desc 拒绝接单
+     * @author zk
+     * @date 2024/3/7
+     **/
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResult refuseSendCarV1(OperateWaybillDto params) {
+        /*1、校验*/
+        Long wOrderId = params.getWOrderId();
+        //运单信息
+        KwtWaybillOrderV1 waybillOrder = waybillOrderV1Dao.selectById(wOrderId);
+        if (waybillOrder == null) {
+            return HttpResult.error("运单" + wOrderId + "不存在,请确认!");
+        }
+        //待接单的车辆运单才能撤回
+        if (!waybillOrder.getStatus().equals(CarWaybillEnum.PENDING_ORDER.getCode())) {
+            return HttpResult.error("运单" + waybillOrder.getWOrderNo() + "当前状态已不能拒绝接单!");
+        }
+
+        /*2、更新运单状态*/
+        waybillOrder.setStatus(CarWaybillEnum.REJECT_ORDER.getCode());
+        waybillOrderV1Dao.updateById(waybillOrder);
+
+        /*3、新增运单状态记录*/
+        setWaybillOrderTrack(waybillOrder.getId(), params.getOperateTime(), waybillOrder.getStatus(), params.getRemark());
+
+        //循环运单不对物流订单委托量变更
+        if (waybillOrder.getType() == Global.NUMERICAL_TWO) {
+            return HttpResult.ok();
+        }
+
+        /*4、回退物流订单委托量(循环运单)*/
+        /*4.1、装货址委派量entrustAmount回退*/
+        //运单装货地址
+        List<KwtWaybillOrderAddress> orderAddresses = waybillOrderAddressDao.findByAddresses(wOrderId, AddressDefaultTypeEnum.SHIPMENT.getCode());
+        for (KwtWaybillOrderAddress address:orderAddresses) {
+            //物流订单-装卸货地址运量信息
+            KwtLogisticsOrderAmount logisticsOrderAmount = logisticsOrderAmountDao.findByLAddressId(address.getLAddressId());
+            //承运订单地址已委派量=承运订单地址原委派量-+当前车辆运单地址委派量
+            BigDecimal entrustAmount = logisticsOrderAmount.getEntrustAmount() == null ? NumberConstant.ZERO_TWO : logisticsOrderAmount.getEntrustAmount();
+            logisticsOrderAmount.setEntrustAmount(entrustAmount.subtract(address.getEntrustAmount()));
+            logisticsOrderAmountDao.updateById(logisticsOrderAmount);
+        }
+
+        /*4.2、物流订单委派量entrustAmount回退*/
+        //运单子订单
+        List<KwtWaybillOrderSubtask> orderSubtasks = waybillOrderSubtaskDao.findByWOrderId(wOrderId);
+        for (KwtWaybillOrderSubtask subtask:orderSubtasks) {
+            //物流订单
+            KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(subtask.getLOrderId());
+            //承运订单已委派量=承运订单原委派量-当前车辆运单委派量
+            BigDecimal entrustAmount = logisticsOrder.getEntrustAmount() == null ? NumberConstant.ZERO_TWO : logisticsOrder.getEntrustAmount();
+            logisticsOrder.setEntrustAmount(entrustAmount.subtract(BigDecimal.valueOf(subtask.getEntrustAmount())));
+            logisticsOrderDao.updateById(logisticsOrder);
+        }
+        return HttpResult.ok();
+    }
+
+    /**
+     * @param params {}
+     * @desc 确认出车
+     * @author zk
+     * @date 2024/3/7
+     **/
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResult confirmDepartureV1(OperateWaybillDto params) {
+        /*1、校验*/
+        Long wOrderId = params.getWOrderId();
+        //运单信息
+        KwtWaybillOrderV1 waybillOrder = waybillOrderV1Dao.selectById(wOrderId);
+        if (waybillOrder == null) {
+            return HttpResult.error("运单" + wOrderId + "不存在,请确认!");
+        }
+        //待出车的车辆运单才能撤回
+        if (!waybillOrder.getStatus().equals(CarWaybillEnum.PENDING_VEHICLE.getCode())) {
+            return HttpResult.error("运单" + waybillOrder.getWOrderNo() + "当前状态不能出车!");
+        }
+        //车辆任务中校验
+        WaybillCountVo countVo = waybillOrderV1Dao.findCountByDriverOrTruck(null, waybillOrder.getTruckId());
+        if (countVo.getTotalExecute() > 0) {
+            return HttpResult.error("车辆"+waybillOrder.getTruckNo()+"正在任务中,暂不能出车!");
+        }
+
+        /*2、更新运单状态*/
+        waybillOrder.setStatus(CarWaybillEnum.EXIT_COMPLETED.getCode());
+        waybillOrderV1Dao.updateById(waybillOrder);
+
+        /*3、新增运单状态记录*/
+        setWaybillOrderTrack(waybillOrder.getId(), params.getOperateTime(), waybillOrder.getStatus(), params.getRemark());
+
+        /*4、更新司机/车辆数据*/
+        //更新司机信息
+        editDriver(waybillOrder.getDriverId());
+        //更新车辆信息
+        editTruck(waybillOrder.getTruckId());
+        return HttpResult.ok();
+    }
+
+    /**
+     * @param params {}
+     * @desc 拒绝出车
+     * @author zk
+     * @date 2024/3/7
+     **/
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResult refuseDepartureV1(OperateWaybillDto params) {
+        /*1、校验*/
+        Long wOrderId = params.getWOrderId();
+        //运单信息
+        KwtWaybillOrderV1 waybillOrder = waybillOrderV1Dao.selectById(wOrderId);
+        if (waybillOrder == null) {
+            return HttpResult.error("运单" + wOrderId + "不存在,请确认!");
+        }
+        //待出车的车辆运单才能撤回
+        if (!waybillOrder.getStatus().equals(CarWaybillEnum.PENDING_VEHICLE.getCode())) {
+            return HttpResult.error("运单" + waybillOrder.getWOrderNo() + "当前状态不能拒绝出车!");
+        }
+
+        /*2、更新运单状态*/
+        waybillOrder.setStatus(CarWaybillEnum.REFUSE_TRAFFIC.getCode());
+        waybillOrderV1Dao.updateById(waybillOrder);
+
+        /*3、新增运单状态记录*/
+        setWaybillOrderTrack(waybillOrder.getId(), params.getOperateTime(), waybillOrder.getStatus(), params.getRemark());
+
+        /*4、回退物流订单委托量*/
+        /*4.1、装货址委派量entrustAmount回退*/
+        //运单装货地址
+        List<KwtWaybillOrderAddress> orderAddresses = waybillOrderAddressDao.findByAddresses(wOrderId, AddressDefaultTypeEnum.SHIPMENT.getCode());
+        for (KwtWaybillOrderAddress address:orderAddresses) {
+            //物流订单-装卸货地址运量信息
+            KwtLogisticsOrderAmount logisticsOrderAmount = logisticsOrderAmountDao.findByLAddressId(address.getLAddressId());
+            //承运订单地址已委派量=承运订单地址原委派量-当前车辆运单地址委派量
+            BigDecimal entrustAmount = logisticsOrderAmount.getEntrustAmount() == null ? NumberConstant.ZERO_TWO : logisticsOrderAmount.getEntrustAmount();
+            logisticsOrderAmount.setEntrustAmount(entrustAmount.subtract(address.getEntrustAmount()));
+            logisticsOrderAmountDao.updateById(logisticsOrderAmount);
+        }
+
+        /*4.2、物流订单委派量entrustAmount回退*/
+        //运单子订单
+        List<KwtWaybillOrderSubtask> orderSubtasks = waybillOrderSubtaskDao.findByWOrderId(wOrderId);
+        for (KwtWaybillOrderSubtask subtask:orderSubtasks) {
+            //物流订单
+            KwtLogisticsOrder logisticsOrder = logisticsOrderDao.selectById(subtask.getLOrderId());
+            //承运订单已委派量=承运订单原委派量-当前车辆运单委派量
+            BigDecimal entrustAmount = logisticsOrder.getEntrustAmount() == null ? NumberConstant.ZERO_TWO : logisticsOrder.getEntrustAmount();
+            logisticsOrder.setEntrustAmount(entrustAmount.subtract(BigDecimal.valueOf(subtask.getEntrustAmount())));
+            logisticsOrderDao.updateById(logisticsOrder);
+        }
+        return HttpResult.ok();
+    }
+
+
+
+
+    /**
+     * @param driverId 司机档案ID
+     * @desc 更新司机信息
+     * @author zk
+     * @date 2023/8/3
+     **/
+    public void editDriver(Long driverId) {
+        //数据统计
+        WaybillCountVo countVo = waybillOrderV1Dao.findCountByDriverOrTruck(driverId, null);
+        WaybillCountVo amountVo = waybillOrderV1Dao.findAmountByDriverOrTruck(driverId, null);
+        RDriverVo driver = new RDriverVo();
+        driver.setId(driverId);
+        driver.setTotalComplete(countVo.getTotalComplete());
+        driver.setTotalTake(countVo.getTotalTake());
+        driver.setTotalWeight(amountVo.getLoadAmount());
+        driver.setBusinessStatus(countVo.getTotalExecute() > 0 ? 1 : 0);
+        remoteFleetService.updateById(driver);
+    }
+
+    /**
+     * @param truckId 车辆档案ID
+     * @desc 更新车辆信息
+     * @author zk
+     * @date 2023/8/3
+     **/
+    public void editTruck(Long truckId) {
+        //数据统计
+        WaybillCountVo countVo = waybillOrderV1Dao.findCountByDriverOrTruck(null, truckId);
+        WaybillCountVo amountVo = waybillOrderV1Dao.findAmountByDriverOrTruck(null, truckId);
+        RTruckVo truck = new RTruckVo();
+        truck.setId(truckId);
+        truck.setTotalComplete(countVo.getTotalComplete());
+        truck.setTotalTake(countVo.getTotalTake());
+        truck.setTotalWeight(amountVo.getLoadAmount());
+        truck.setBusinessStatus(countVo.getTotalExecute() > 0 ? 1 : 0);
+        remoteFleetService.updateById(truck);
+    }
+
     /**
      * @param type  字典类型
      * @param value 字典值

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

@@ -19,7 +19,7 @@
         </if>
     </select>
 
-    <select id="findByAddressId" resultType="com.sckw.transport.model.KwtLogisticsOrderAmount" >
+    <select id="findByLAddressId" resultType="com.sckw.transport.model.KwtLogisticsOrderAmount" >
         select
         id, l_order_id lOrderId, l_address_id lAddressId, amount, subcontract_amount subcontractAmount,
         entrust_amount entrustAmount, load_amount loadAmount, unload_amount unloadAmount, ignore_amount ignoreAmount,

+ 12 - 164
sckw-modules/sckw-transport/src/main/resources/mapper/KwtWaybillOrderAddressMapper.xml

@@ -1,170 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.sckw.transport.dao.KwtWaybillOrderAddressMapper">
-    <resultMap id="BaseResultMap" type="com.sckw.transport.model.KwtWaybillOrderAddress">
-        <id column="id" jdbcType="BIGINT" property="id"/>
-        <result column="w_order_id" jdbcType="BIGINT" property="wOrderId"/>
-        <result column="address_type" jdbcType="VARCHAR" property="addressType"/>
-        <result column="name" jdbcType="VARCHAR" property="name"/>
-        <result column="type" jdbcType="BIGINT" property="type"/>
-        <result column="contacts" jdbcType="VARCHAR" property="contacts"/>
-        <result column="phone" jdbcType="VARCHAR" property="phone"/>
-        <result column="city_code" jdbcType="INTEGER" property="cityCode"/>
-        <result column="city_name" jdbcType="VARCHAR" property="cityName"/>
-        <result column="detail_address" jdbcType="VARCHAR" property="detailAddress"/>
-        <result column="lat" jdbcType="VARCHAR" property="lat"/>
-        <result column="lng" jdbcType="VARCHAR" property="lng"/>
-        <result column="fence" jdbcType="VARCHAR" property="fence"/>
-        <result column="entry_type" jdbcType="INTEGER" property="entryType"/>
-        <result column="remark" jdbcType="VARCHAR" property="remark"/>
-        <result column="status" jdbcType="INTEGER" property="status"/>
-        <result column="create_by" jdbcType="BIGINT" property="createBy"/>
-        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
-        <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
-        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
-        <result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
-    </resultMap>
-    <sql id="Base_Column_List">
-        id
-        , w_order_id, address_type, `name`, `type`, `contacts`,`phone`,`city_code`
-        , city_name, detail_address, lat, lng, fence, entry_type, remark, status
-        , create_by, create_time, update_by, update_time, del_flag
-
-    </sql>
-
-    <insert id="insert1" parameterType="com.sckw.transport.model.KwtWaybillOrderAddress">
-        insert into kwt_waybill_order_address
-        <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="id != null">
-                `id`,
-            </if>
-            <if test="wOrderId != null">
-                `w_order_id`,
-            </if>
-            <if test="addressType != null">
-                `address_type`,
-            </if>
-            <if test="name != null">
-                `name`,
-            </if>
-            <if test="type != null">
-                `type`,
-            </if>
-            <if test="contacts != null">
-                `contacts`,
-            </if>
-            <if test="phone != null">
-                `phone`,
-            </if>
-            <if test="cityCode != null">
-                `city_code`,
-            </if>
-            <if test="cityName != null">
-                `city_name`,
-            </if>
-            <if test="detailAddress != null">
-                `detail_address`,
-            </if>
-            <if test="lat != null">
-                `lat`,
-            </if>
-            <if test="lng != null">
-                `lng`,
-            </if>
-            <if test="fence != null">
-                `fence`,
-            </if>
-            <if test="entryType != null">
-                `entry_type`,
-            </if>
-            <if test="remark != null">
-                `remark`,
-            </if>
-            <if test="status != null">
-                `status`,
-            </if>
-            <if test="createBy != null">
-                `create_by`,
-            </if>
-            <if test="createTime != null">
-                `create_time`,
-            </if>
-            <if test="updateBy != null">
-                `update_by`,
-            </if>
-            <if test="updateTime != null">
-                `update_time`,
-            </if>
-            <if test="delFlag != null">
-                `del_flag`,
-            </if>
-        </trim>
-        <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="id != null">
-                #{id,jdbcType=BIGINT},
-            </if>
-            <if test="wOrderId != null">
-                #{wOrderId,jdbcType=BIGINT},
-            </if>
-            <if test="addressType != null">
-                #{addressType,jdbcType=INTEGER},
-            </if>
-            <if test="name != null">
-                #{name,jdbcType=VARCHAR},
-            </if>
-            <if test="type != null">
-                #{type,jdbcType=BIGINT},
-            </if>
-            <if test="contacts != null">
-                #{contacts,jdbcType=VARCHAR},
-            </if>
-            <if test="phone != null">
-                #{phone,jdbcType=VARCHAR},
-            </if>
-            <if test="cityCode != null">
-                #{cityCode,jdbcType=INTEGER},
-            </if>
-            <if test="cityName != null">
-                #{cityName,jdbcType=VARCHAR},
-            </if>
-            <if test="detailAddress != null">
-                #{detailAddress,jdbcType=VARCHAR},
-            </if>
-            <if test="lat != null">
-                #{lat,jdbcType=VARCHAR},
-            </if>
-            <if test="lng != null">
-                #{lng,jdbcType=VARCHAR},
-            </if>
-            <if test="fence != null">
-                #{fence,jdbcType=VARCHAR},
-            </if>
-            <if test="entryType != null">
-                #{entryType,jdbcType=INTEGER},
-            </if>
-            <if test="remark != null">
-                #{remark,jdbcType=VARCHAR},
-            </if>
-            <if test="status != null">
-                #{status,jdbcType=INTEGER},
-            </if>
-            <if test="createBy != null">
-                #{createBy,jdbcType=BIGINT},
-            </if>
-            <if test="createTime != null">
-                #{createTime,jdbcType=TIMESTAMP},
-            </if>
-            <if test="updateBy != null">
-                #{updateBy,jdbcType=BIGINT},
-            </if>
-            <if test="updateTime != null">
-                #{updateTime,jdbcType=TIMESTAMP},
-            </if>
-            <if test="delFlag != null">
-                #{delFlag,jdbcType=INTEGER},
-            </if>
-        </trim>
-    </insert>
 
     <select id="findByAddress" resultType="com.sckw.transport.model.KwtWaybillOrderAddress" >
         select
@@ -177,6 +13,18 @@
         and address_type = #{addressType, jdbcType=INTEGER}
     </select>
 
+    <select id="findByAddresses" resultType="com.sckw.transport.model.KwtWaybillOrderAddress" >
+        select
+        id, w_order_id wOrderId, w_subtask_id wSubtaskId, l_address_id lAddressId, address_type addressType,
+        `name`, `type`, contacts, phone, city_code cityCode, city_name cityName, detail_address detailAddress,
+        lat, lng, fence, entry_type entryType, plan_time planTime, entrust_amount entrustAmount, sort, remark,
+        `status`, create_by createBy, create_time createTime, update_by updateBy, update_time updateTime
+        from kwt_waybill_order_address
+        where del_flag = 0
+        and w_order_id = #{wOrderId, jdbcType=BIGINT}
+        and address_type = #{addressType, jdbcType=INTEGER}
+    </select>
+
     <select id="findAddressCodeList" resultType="java.lang.Integer" >
         SELECT
         DISTINCT kwoa.city_code

+ 19 - 3
sckw-modules/sckw-transport/src/main/resources/mapper/KwtWaybillOrderSubtaskMapper.xml

@@ -2,10 +2,26 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.sckw.transport.dao.KwtWaybillOrderSubtaskMapper">
 
-    <select id="findByAddress" resultType="com.sckw.transport.model.KwtWaybillOrderSubtask" >
-        select * from kwt_logistics_order_amount
+    <select id="findByWOrderId" resultType="com.sckw.transport.model.KwtWaybillOrderSubtask" >
+        select
+        id, ent_id entId, l_order_id lOrderId, w_order_id wOrderId, w_order_no wOrderNo, unit,
+        entrust_amount entrustAmount, unload_amount unloadAmount, unload_time unloadTime,
+        load_amount loadAmount, load_time loadTime, deficit_amount deficitAmount, deficit_price deficitPrice,
+        remark, status, create_by createBy, create_time createTime, update_by updateBy, update_time updateTime
+        from kwt_waybill_order_subtask
+        where del_flag = 0
+        and w_order_id = #{wOrderId, jdbcType=BIGINT}
+    </select>
+
+    <select id="findByOrderId" resultType="com.sckw.transport.model.KwtWaybillOrderSubtask" >
+        select
+        id, ent_id entId, l_order_id lOrderId, w_order_id wOrderId, w_order_no wOrderNo, unit,
+        entrust_amount entrustAmount, unload_amount unloadAmount, unload_time unloadTime,
+        load_amount loadAmount, load_time loadTime, deficit_amount deficitAmount, deficit_price deficitPrice,
+        remark, status, create_by createBy, create_time createTime, update_by updateBy, update_time updateTime
+        from kwt_waybill_order_subtask
         where del_flag = 0
-        and l_order_id = #{lOrderId, jdbcType=BIGINT}
         and w_order_id = #{wOrderId, jdbcType=BIGINT}
+        and l_order_id = #{lOrderId, jdbcType=BIGINT}
     </select>
 </mapper>

+ 35 - 0
sckw-modules/sckw-transport/src/main/resources/mapper/KwtWaybillOrderV1Mapper.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sckw.transport.dao.KwtWaybillOrderV1Mapper">
+
+    <select id="findCountByDriverOrTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
+        SELECT
+        count(case when wo.status = 8 then 1 end) totalComplete,
+        count(case when wo.status not in (1, 9, 10, 11) then 1 end) totalTake,
+        count(case when wo.status in (3, 4, 5, 6) then 1 end) totalExecute
+        from kwt_waybill_order wo
+        left join kwt_waybill_order_subtask wos on wos.w_order_id = wo.id
+        where wo.del_flag = 0
+        <if test="driverId != null and driverId != ''">
+            and wo.driver_id = #{driverId, jdbcType=BIGINT}
+        </if>
+        <if test="truckId != null and truckId != ''">
+            and wo.truck_id = #{truckId, jdbcType=BIGINT}
+        </if>
+    </select>
+
+    <select id="findAmountByDriverOrTruck" resultType="com.sckw.transport.model.vo.WaybillCountVo">
+        SELECT
+        IFNULL(SUM(wos.load_amount), 0.0) loadAmount
+        from kwt_waybill_order_subtask wos
+        left join kwt_waybill_order wo on wos.w_order_id = wo.id
+        where wo.del_flag = 0 and wos.del_flag = 0
+        <if test="driverId != null and driverId != ''">
+            and wo.driver_id = #{driverId, jdbcType=BIGINT}
+        </if>
+        <if test="truckId != null and truckId != ''">
+            and wo.truck_id = #{truckId, jdbcType=BIGINT}
+        </if>
+    </select>
+
+</mapper>