Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/dev' into dev

yzc 2 gadi atpakaļ
vecāks
revīzija
11bb69151b

+ 2 - 2
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/AcceptCarriageOrderController.java

@@ -217,7 +217,7 @@ public class AcceptCarriageOrderController {
     }
 
     /**
-     * 承运订单-取消派车(撤回派车)
+     * 承运订单-取消派车(撤回派车)/单趟撤回
      *
      * @param ids 车辆运单id
      * @return
@@ -228,7 +228,7 @@ public class AcceptCarriageOrderController {
         try {
             return acceptCarriageOrderService.cancelDelivery(lists);
         } catch (Exception e) {
-            log.error("承运订单-取消派车 error:{}", e.getMessage(), e);
+            log.error("承运订单-单趟撤回 error:{}", e.getMessage(), e);
             return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
         }
     }

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

@@ -34,7 +34,7 @@ public interface KwtLogisticsOrderMapper extends BaseMapper<KwtLogisticsOrder> {
 
     int updateByPrimaryKey(KwtLogisticsOrder record);
 
-    void removeById(KwtLogisticsOrder logisticsOrder);
+//    void removeById(KwtLogisticsOrder logisticsOrder);
 
     /**
      * 查询物流订单数据

+ 38 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/dto/AddressDropListDTO.java

@@ -0,0 +1,38 @@
+package com.sckw.transport.model.dto;
+
+import com.sckw.system.api.model.dto.res.AreaTreeFrontResDto;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @desc: 物流订单地址下拉列表响应
+ * @author: yzc
+ * @date: 2023-08-02 14:49
+ */
+@Getter
+@Setter
+@ToString
+@Accessors(chain = true)
+public class AddressDropListDTO implements Serializable {
+
+
+    @Serial
+    private static final long serialVersionUID = -1892537474089018495L;
+
+    /**
+     * 装货地址树
+     */
+    private List<AreaTreeFrontResDto> loadAddressList;
+
+    /**
+     * 卸货地址树
+     */
+    private List<AreaTreeFrontResDto> unloadAddressList;
+
+}

+ 94 - 21
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/AcceptCarriageOrderService.java

@@ -572,32 +572,99 @@ public class AcceptCarriageOrderService {
         log.info("接单操作接收数据:{}", JSONObject.toJSONString(orderDTO));
         HttpResult result = new HttpResult();
         result.setCode(HttpStatus.SUCCESS_CODE);
+        HttpResult httpResult = ValidUtil.serviceValid(orderDTO);
+        if (!String.valueOf(httpResult.getCode()).equals(String.valueOf(HttpStatus.SUCCESS_CODE))) {
+            result.setMsg(httpResult.getMsg());
+            return result;
+        }
         KwtLogisticsOrder logisticsOrder = logisticsOrderMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrder>()
                 .eq(StringUtils.isNotBlank(orderDTO.getLOrderId()), KwtLogisticsOrder::getId, orderDTO.getLOrderId())
                 .eq(StringUtils.isNotBlank(orderDTO.getLOrderNo()), KwtLogisticsOrder::getLOrderNo, orderDTO.getLOrderNo())
                 .eq(KwtLogisticsOrder::getEntId, LoginUserHolder.getEntId()));
         if (logisticsOrder == null) {
             result.setMsg("单据不存在!");
+            return result;
+        }
+        if (!LogisticsOrderEnum.PENDING_ORDER.getStatus().equals(String.valueOf(logisticsOrder.getStatus()))) {
+            result.setMsg("该【" + orderDTO.getLOrderNo() + "】单号并不是待接单状态!");
+            return result;
+        }
+        KwtLogisticsOrderContract contract = kwtLogisticsOrderContractMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderContract>()
+                .eq(KwtLogisticsOrderContract::getLOrderId, orderDTO.getLOrderId()));
+        if (contract == null) {
+            result.setMsg("该订单并未存在合同信息!");
+            return result;
+        }
+        /**
+         * 根据合同是否已签约 变更物流订单状态 已签约->待派车  未签约->签约中
+         * */
+        /**判断生成物流订单应生成哪一种单据状态*/
+        List<Long> contractList = new ArrayList<>();
+        contractList.add(contract.getContractId());
+        Map<Long, ContractCommonInfoResDto> longContractCommonInfoResDtoMap = remoteContractService.queryContractBaseInfo(contractList);
+        if (CollectionUtils.isEmpty(longContractCommonInfoResDtoMap)) {
+            throw new BusinessException("并未有对应合同,应先签约合同");
+        }
+        if (longContractCommonInfoResDtoMap.get(contract.getContractId()) == null) {
+            throw new BusinessException("并未有对应合同,应先签约合同");
+        }
+        ContractCommonInfoResDto infoResDto = longContractCommonInfoResDtoMap.get(contract.getContractId());
+        /**状态判断
+         * 是否是已签约合同
+         * */
+        // 0 已签约 1待签约
+        Integer status = infoResDto.getStatus();
+        Integer orderStatus = LogisticsOrderEnum.PENDING_ORDER.getCode();
+        if (NumberConstant.ONE == status) {
+            orderStatus = LogisticsOrderEnum.PENDING_ORDER.getCode();
+        } else if (NumberConstant.ZERO == status) {
+            orderStatus = LogisticsOrderEnum.WAIT_DELIVERY.getCode();
+        } else {
+            log.info("接单 物流订单id:{}," +
+                            "物流订单编号:{},合同id:{},合同信息:{}",
+                    orderDTO.getLOrderId(), orderDTO.getLOrderNo(),
+                    contract.getContractId(), JSONObject.toJSONString(infoResDto));
+            throw new RuntimeException("物流订单-接单异常");
         }
         if (orderDTO.getType()) {
-            logisticsOrderTrackMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrderTrack>()
-                    .eq(StringUtils.isNotBlank(orderDTO.getLOrderId()), KwtLogisticsOrderTrack::getLOrderId, orderDTO.getLOrderId())
-                    .set(KwtLogisticsOrderTrack::getStatus, LogisticsOrderEnum.WAIT_DELIVERY.getCode())
-                    .set(KwtLogisticsOrderTrack::getUpdateBy, LoginUserHolder.getUserId())
-                    .set(KwtLogisticsOrderTrack::getUpdateTime, new Date()));
+            //修改单据状态
+            logisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
+                    .eq(StringUtils.isNotBlank(orderDTO.getLOrderId()), KwtLogisticsOrder::getId, orderDTO.getLOrderId())
+                    .eq(StringUtils.isNotBlank(orderDTO.getLOrderNo()), KwtLogisticsOrder::getLOrderNo, orderDTO.getLOrderNo())
+                    .set(KwtLogisticsOrder::getStatus, orderStatus)
+                    .set(KwtLogisticsOrder::getUpdateTime, new Date())
+                    .set(KwtLogisticsOrder::getUpdateBy, LoginUserHolder.getUserId()));
         } else {
-            logisticsOrderTrackMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrderTrack>()
-                    .eq(StringUtils.isNotBlank(orderDTO.getLOrderId()), KwtLogisticsOrderTrack::getLOrderId, orderDTO.getLOrderId())
-                    .set(KwtLogisticsOrderTrack::getStatus, LogisticsOrderEnum.SEND_BACK.getCode())
-                    .set(KwtLogisticsOrderTrack::getUpdateBy, LoginUserHolder.getUserId())
-                    .set(StringUtils.isNotBlank(orderDTO.getRemark()), KwtLogisticsOrderTrack::getRemark, orderDTO.getRemark())
-                    .set(KwtLogisticsOrderTrack::getUpdateTime, new Date()));
+            //删除订单
+            logisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
+                    .eq(StringUtils.isNotBlank(orderDTO.getLOrderId()), KwtLogisticsOrder::getId, orderDTO.getLOrderId())
+                    .eq(StringUtils.isNotBlank(orderDTO.getLOrderNo()), KwtLogisticsOrder::getLOrderNo, orderDTO.getLOrderNo())
+                    .set(KwtLogisticsOrder::getDelFlag, NumberConstant.ONE)
+                    .set(KwtLogisticsOrder::getUpdateTime, new Date())
+                    .set(KwtLogisticsOrder::getUpdateBy, LoginUserHolder.getUserId()));
         }
-        logisticsOrderMapper.update(null, new LambdaUpdateWrapper<KwtLogisticsOrder>()
-                .eq(StringUtils.isNotBlank(orderDTO.getLOrderId()), KwtLogisticsOrder::getId, orderDTO.getLOrderId())
-                .eq(StringUtils.isNotBlank(orderDTO.getLOrderNo()), KwtLogisticsOrder::getLOrderNo, orderDTO.getLOrderNo())
-                .set(KwtLogisticsOrder::getUpdateTime, new Date())
-                .set(KwtLogisticsOrder::getUpdateBy, LoginUserHolder.getUserId()));
+        //状态表新增状态数据
+        KwtLogisticsOrderTrack track = logisticsOrderTrackMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderTrack>()
+                .eq(KwtLogisticsOrderTrack::getLOrderId, orderDTO.getLOrderId()).eq(KwtLogisticsOrderTrack::getStatus, orderStatus));
+        if (track == null) {
+            KwtLogisticsOrderTrack orderTrack = new KwtLogisticsOrderTrack();
+            orderTrack.setId(new IdWorker(NumberConstant.ONE).nextId());
+            orderTrack.setLOrderId(Long.parseLong(orderDTO.getLOrderId()));
+            orderTrack.setRemark(orderDTO.getRemark());
+            orderTrack.setStatus(orderStatus);
+            orderTrack.setCreateBy(LoginUserHolder.getUserId());
+            orderTrack.setCreateTime(new Date());
+            orderTrack.setUpdateBy(LoginUserHolder.getUserId());
+            orderTrack.setUpdateTime(new Date());
+            logisticsOrderTrackMapper.insert(orderTrack);
+        }else {
+            track.setRemark(orderDTO.getRemark());
+            track.setUpdateTime(new Date());
+            track.setUpdateBy(LoginUserHolder.getUserId());
+            track.setStatus(orderStatus);
+            logisticsOrderTrackMapper.updateById(track);
+        }
+
         return result;
     }
 
@@ -806,6 +873,7 @@ public class AcceptCarriageOrderService {
      */
     @Transactional(rollbackFor = Exception.class)
     public HttpResult cancelDelivery(List<String> ids) {
+        List<JSONObject> list = new ArrayList<>();
         JSONObject result = new JSONObject(NumberConstant.THREE);
         for (String id : ids) {
             result.put("id", id);
@@ -814,10 +882,14 @@ public class AcceptCarriageOrderService {
             if (waybillOrder == null) {
                 result.put("status", HttpStatus.GLOBAL_EXCEPTION_CODE);
                 result.put("message", "单据不存在");
+                list.add(result);
+                continue;
             }
             if (!CarWaybillEnum.PENDING_ORDER.getCode().equals(waybillOrder.getStatus())) {
                 result.put("status", HttpStatus.GLOBAL_EXCEPTION_CODE);
                 result.put("message", "单据不是待接单状态,不可取消!");
+                list.add(result);
+                continue;
             }
             /**针对于趟次车,需要将可派单数量溯源回归于物流订单中*/
             KwtLogisticsOrder logisticsOrder = logisticsOrderMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrder>()
@@ -861,8 +933,9 @@ public class AcceptCarriageOrderService {
             streamBridge.send("sckw-busSum", com.alibaba.fastjson2.JSON.toJSONString(busSum));
             result.put("status", HttpStatus.SUCCESS_CODE);
             result.put("message", "取消成功");
+            list.add(result);
         }
-        return HttpResult.ok(result);
+        return HttpResult.ok(list);
     }
 
     /**
@@ -1208,13 +1281,13 @@ public class AcceptCarriageOrderService {
             }
         }
         if (!ObjectUtils.isEmpty(orderDTO.getLoss())) {
-            if (orderDTO.getTaxRate().compareTo(new BigDecimal(NumberConstant.ZERO)) < 0) {
-                throw new BusinessException("税率填写格式错误!");
+            if (orderDTO.getLoss().compareTo(new BigDecimal(NumberConstant.ZERO)) < 0) {
+                throw new BusinessException("合理损耗填写格式错误!");
             }
         }
         if (!ObjectUtils.isEmpty(orderDTO.getGoodsPrice())) {
-            if (orderDTO.getTaxRate().compareTo(new BigDecimal(NumberConstant.ZERO)) < 0) {
-                throw new BusinessException("税率填写格式错误!");
+            if (orderDTO.getGoodsPrice().compareTo(new BigDecimal(NumberConstant.ZERO)) < 0) {
+                throw new BusinessException("扣亏货值填写格式错误!");
             }
         }
     }

+ 133 - 56
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/ConsignOrderService.java

@@ -6,6 +6,7 @@ import com.sckw.contract.api.RemoteContractService;
 import com.sckw.contract.api.model.dto.res.ContractCommonInfoResDto;
 import com.sckw.core.common.enums.NumberConstant;
 import com.sckw.core.common.enums.StringConstant;
+import com.sckw.core.common.enums.enums.DictEnum;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.enums.CarWaybillEnum;
 import com.sckw.core.model.enums.LogisticsOrderEnum;
@@ -14,9 +15,11 @@ import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.StringTimeUtil;
 import com.sckw.core.utils.StringUtils;
+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.excel.utils.ValidUtil;
 import com.sckw.fleet.api.RemoteFleetService;
 import com.sckw.mongo.enums.BusinessTypeEnum;
 import com.sckw.mongo.model.SckwLogisticsOrder;
@@ -24,12 +27,10 @@ import com.sckw.product.api.dubbo.GoodsInfoService;
 import com.sckw.product.api.model.KwpGoods;
 import com.sckw.stream.model.SckwBusSum;
 import com.sckw.system.api.RemoteSystemService;
+import com.sckw.system.api.model.dto.res.AreaTreeFrontResDto;
 import com.sckw.transport.dao.*;
 import com.sckw.transport.model.*;
-import com.sckw.transport.model.dto.AddOrderDTO;
-import com.sckw.transport.model.dto.OrderCarDTO;
-import com.sckw.transport.model.dto.OrderDTO;
-import com.sckw.transport.model.dto.OrderFinishDTO;
+import com.sckw.transport.model.dto.*;
 import com.sckw.transport.model.vo.CarWaybillVO;
 import com.sckw.transport.model.vo.OrderFinishVO;
 import jakarta.annotation.Resource;
@@ -43,10 +44,8 @@ import org.springframework.util.ObjectUtils;
 
 import java.math.BigDecimal;
 import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author lfdc
@@ -176,27 +175,34 @@ public class ConsignOrderService {
         BigDecimal deductWeighNumber = new BigDecimal("0.00");
         if (CollectionUtils.isNotEmpty(kwtWaybillOrders)) {
             for (KwtWaybillOrder kwtWaybillOrder : kwtWaybillOrders) {
-                CarWaybillVO carWaybillVo = new CarWaybillVO();
-                carWaybillVo.setSendCarWeigh(kwtWaybillOrder.getEntrustAmount() == null ? null : String.valueOf(kwtWaybillOrder.getEntrustAmount()));
+                //派车量
+                BigDecimal sendCarWeigh = kwtWaybillOrder.getEntrustAmount() == null ? new BigDecimal("0.00") : kwtWaybillOrder.getEntrustAmount();
                 /**亏吨量/吨->装货量-卸货量
-                 * 合理损耗值=已委托量*合理损耗
-                 扣亏量/吨->亏吨量-合理损耗值*/
-                //合理损耗值=已委托量*合理损耗
-                BigDecimal multiply = kwtWaybillOrder.getEntrustAmount().multiply(loss.divide(BigDecimal.valueOf(1000L)));
-                carWaybillVo.setDefectiveWeigh(kwtWaybillOrder.getDeficitAmount() == null ? null : String.valueOf(kwtWaybillOrder.getDeficitAmount()));
-                carWaybillVo.setDeduct(kwtWaybillOrder.getDeficitAmount().compareTo(new BigDecimal(NumberConstant.ZERO)) == 0 ?
-                        new BigDecimal(NumberConstant.ZERO) : kwtWaybillOrder.getDeficitAmount().subtract(multiply));
-                sendCarWeighNumber = sendCarWeighNumber.add(kwtWaybillOrder.getLoadAmount());
-                if (carWaybillVo.getLoadAmount() != null) {
-                    loadAmountNumber = loadAmountNumber.add(new BigDecimal(carWaybillVo.getLoadAmount()));
-                }
-                if (carWaybillVo.getUnloadAmount() != null) {
-                    unloadAmountNumber = unloadAmountNumber.add(new BigDecimal(carWaybillVo.getUnloadAmount()));
+                 * 合理损耗值=装货量*合理损耗
+                 扣亏量/吨->亏吨量-合理损耗值
+                 罚款值 扣亏量/吨*扣亏货值
+                 运价:
+                 按照装货量 运价*装货量
+                 按照卸货量 卸货量*运输单价-罚款值
+                 按照趟次=运价
+                 */
+                //已委托量
+                BigDecimal entrustAmount = kwtWaybillOrder.getEntrustAmount() == null ? new BigDecimal("0.00") : kwtWaybillOrder.getEntrustAmount();
+                //合理损耗值
+                BigDecimal multiply = entrustAmount.multiply(loss.divide(BigDecimal.valueOf(1000L)));
+                //亏吨量
+                BigDecimal defectiveWeigh = kwtWaybillOrder.getDeficitAmount() == null ? new BigDecimal("0.00") : kwtWaybillOrder.getDeficitAmount();
+                //扣亏量/吨
+                BigDecimal deduct = defectiveWeigh.compareTo(new BigDecimal("0.00")) == 0 ? new BigDecimal("0.00") : defectiveWeigh.subtract(multiply);
+                sendCarWeighNumber = sendCarWeighNumber.add(sendCarWeigh);
+                if (kwtWaybillOrder.getLoadAmount() != null) {
+                    loadAmountNumber = loadAmountNumber.add(kwtWaybillOrder.getLoadAmount());
                 }
-                if (carWaybillVo.getDefectiveWeigh() != null) {
-                    defectiveWeighNumber = defectiveWeighNumber.add(new BigDecimal(carWaybillVo.getDefectiveWeigh()));
+                if (kwtWaybillOrder.getUnloadAmount() != null) {
+                    unloadAmountNumber = unloadAmountNumber.add(kwtWaybillOrder.getUnloadAmount());
                 }
-                deductWeighNumber = deductWeighNumber.add(carWaybillVo.getDeduct());
+                defectiveWeighNumber = defectiveWeighNumber.add(defectiveWeigh);
+                deductWeighNumber = deductWeighNumber.add(deduct);
             }
         }
         statistics.put("count", kwtWaybillOrders.size());
@@ -242,26 +248,29 @@ public class ConsignOrderService {
         BigDecimal deductWeighNumber = new BigDecimal(NumberConstant.ZERO);
         if (CollectionUtils.isNotEmpty(kwtWaybillOrders)) {
             for (KwtWaybillOrder kwtWaybillOrder : kwtWaybillOrders) {
-                CarWaybillVO carWaybillVo = new CarWaybillVO();
-                carWaybillVo.setSendCarWeigh(kwtWaybillOrder.getEntrustAmount() == null ? null : String.valueOf(kwtWaybillOrder.getEntrustAmount()));
+                //派车量
+                BigDecimal sendCarWeigh = kwtWaybillOrder.getEntrustAmount() == null ? new BigDecimal("0.00") : kwtWaybillOrder.getEntrustAmount();
                 /**亏吨量/吨->装货量-卸货量
-                 扣亏量/吨->亏吨量*合理损耗*/
-                BigDecimal multiply = kwtWaybillOrder.getEntrustAmount().multiply(loss.divide(BigDecimal.valueOf(1000L)));
-                carWaybillVo.setDefectiveWeigh(kwtWaybillOrder.getDeficitAmount() == null ? null : String.valueOf(kwtWaybillOrder.getDeficitAmount()));
-                carWaybillVo.setDeduct(kwtWaybillOrder.getDeficitAmount().compareTo(new BigDecimal(NumberConstant.ZERO)) == 0 ?
-                        new BigDecimal(NumberConstant.ZERO) : kwtWaybillOrder.getDeficitAmount().subtract(multiply));
-                sendCarWeighNumber = sendCarWeighNumber.add(kwtWaybillOrder.getLoadAmount());
-                sendCarWeighNumber = sendCarWeighNumber.add(kwtWaybillOrder.getLoadAmount());
-                if (carWaybillVo.getLoadAmount() != null) {
-                    loadAmountNumber = loadAmountNumber.add(new BigDecimal(carWaybillVo.getLoadAmount()));
+                 * 合理损耗值=装货量*合理损耗
+                 扣亏量/吨->亏吨量-合理损耗值
+                 */
+                //已委托量
+                BigDecimal entrustAmount = kwtWaybillOrder.getEntrustAmount() == null ? new BigDecimal("0.00") : kwtWaybillOrder.getEntrustAmount();
+                //合理损耗值
+                BigDecimal multiply = entrustAmount.multiply(loss.divide(BigDecimal.valueOf(1000L)));
+                //亏吨量
+                BigDecimal defectiveWeigh = kwtWaybillOrder.getDeficitAmount() == null ? new BigDecimal("0.00") : kwtWaybillOrder.getDeficitAmount();
+                //扣亏量/吨
+                BigDecimal deduct = defectiveWeigh.compareTo(new BigDecimal("0.00")) == 0 ? new BigDecimal("0.00") : defectiveWeigh.subtract(multiply);
+                sendCarWeighNumber = sendCarWeighNumber.add(sendCarWeigh);
+                if (kwtWaybillOrder.getLoadAmount() != null) {
+                    loadAmountNumber = loadAmountNumber.add(kwtWaybillOrder.getLoadAmount());
                 }
-                if (carWaybillVo.getUnloadAmount() != null) {
-                    unloadAmountNumber = unloadAmountNumber.add(new BigDecimal(carWaybillVo.getUnloadAmount()));
+                if (kwtWaybillOrder.getUnloadAmount() != null) {
+                    unloadAmountNumber = unloadAmountNumber.add(kwtWaybillOrder.getUnloadAmount());
                 }
-                if (carWaybillVo.getDefectiveWeigh() != null) {
-                    defectiveWeighNumber = defectiveWeighNumber.add(new BigDecimal(carWaybillVo.getDefectiveWeigh()));
-                }
-                deductWeighNumber = deductWeighNumber.add(carWaybillVo.getDeduct());
+                defectiveWeighNumber = defectiveWeighNumber.add(defectiveWeigh);
+                deductWeighNumber = deductWeighNumber.add(deduct);
             }
         }
         statistics.put("count", kwtWaybillOrders.size());
@@ -301,11 +310,20 @@ public class ConsignOrderService {
                 KwtWaybillOrderTicket unloadTicket = kwtWaybillOrderTicketMapper.selectOne(new LambdaQueryWrapper<KwtWaybillOrderTicket>()
                         .eq(StringUtils.isNotBlank(kwtWaybillOrder.getId()), KwtWaybillOrderTicket::getWOrderId, kwtWaybillOrder.getId())
                         .eq(KwtWaybillOrderTicket::getType, NumberConstant.TWO));
-                //扣亏量/吨->亏吨量-合理损耗
-                BigDecimal deduct = null;
-                if (kwtWaybillOrder.getDeficitAmount() != null && (kwtWaybillOrder.getDeficitAmount().compareTo(new BigDecimal(NumberConstant.ZERO)) == NumberConstant.ZERO)) {
-                    deduct = kwtWaybillOrder.getDeficitAmount().subtract(order.getLoss() == null ? new BigDecimal(NumberConstant.ZERO) : order.getLoss());
-                }
+                //合理损耗
+                BigDecimal loss = order.getLoss();
+                /**亏吨量/吨->装货量-卸货量
+                 * 合理损耗值=装货量*合理损耗
+                 扣亏量/吨->亏吨量-合理损耗值
+                 */
+                //已委托量
+                BigDecimal entrustAmount = kwtWaybillOrder.getEntrustAmount() == null ? new BigDecimal("0.00") : kwtWaybillOrder.getEntrustAmount();
+                //合理损耗值
+                BigDecimal multiply = entrustAmount.multiply(loss.divide(BigDecimal.valueOf(1000L)));
+                //亏吨量
+                BigDecimal defectiveWeigh = kwtWaybillOrder.getDeficitAmount() == null ? new BigDecimal("0.00") : kwtWaybillOrder.getDeficitAmount();
+                //扣亏量/吨
+                BigDecimal deduct = defectiveWeigh.compareTo(new BigDecimal("0.00")) == 0 ? new BigDecimal("0.00") : defectiveWeigh.subtract(multiply);
                 carWaybillVo.setWOrderId(String.valueOf(kwtWaybillOrder.getId()));
                 carWaybillVo.setWOrderNo(order.getLOrderNo());
                 carWaybillVo.setTruckNo(kwtWaybillOrder.getTruckNo());
@@ -316,6 +334,7 @@ public class ConsignOrderService {
 //                SckwWaybillOrder sckwWaybillOrder = mongoTemplate.findById(kwtWaybillOrder.getId(), SckwWaybillOrder.class);
                 /** 2023-07-24 原值为承运车队-去除后更换展示为承运公司*/
 //                carWaybillVo.setConsignMotorcade(sckwWaybillOrder == null ? null : sckwWaybillOrder.getCarrierFirmName());
+                //派车量
                 carWaybillVo.setSendCarWeigh(kwtWaybillOrder.getEntrustAmount() == null ? null : String.valueOf(kwtWaybillOrder.getEntrustAmount()));
                 carWaybillVo.setSendCarDate(DateUtil.getDateTime(kwtWaybillOrder.getCreateTime()));
                 if (loadTicket != null) {
@@ -374,11 +393,20 @@ public class ConsignOrderService {
                 KwtWaybillOrderTicket unloadTicket = kwtWaybillOrderTicketMapper.selectOne(new LambdaQueryWrapper<KwtWaybillOrderTicket>()
                         .eq(StringUtils.isNotBlank(kwtWaybillOrder.getId()), KwtWaybillOrderTicket::getWOrderId, kwtWaybillOrder.getId())
                         .eq(KwtWaybillOrderTicket::getType, NumberConstant.TWO));
-                //扣亏量/吨->亏吨量-合理损耗
-                BigDecimal deduct = null;
-                if (kwtWaybillOrder.getDeficitAmount() != null && (kwtWaybillOrder.getDeficitAmount().compareTo(new BigDecimal(NumberConstant.ZERO)) == NumberConstant.ZERO)) {
-                    deduct = kwtWaybillOrder.getDeficitAmount().subtract(order.getLoss() == null ? new BigDecimal(NumberConstant.ZERO) : order.getLoss());
-                }
+                //合理损耗
+                BigDecimal loss = order.getLoss();
+                /**亏吨量/吨->装货量-卸货量
+                 * 合理损耗值=装货量*合理损耗
+                 扣亏量/吨->亏吨量-合理损耗值
+                 */
+                //已委托量
+                BigDecimal entrustAmount = kwtWaybillOrder.getEntrustAmount() == null ? new BigDecimal("0.00") : kwtWaybillOrder.getEntrustAmount();
+                //合理损耗值
+                BigDecimal multiply = entrustAmount.multiply(loss.divide(BigDecimal.valueOf(1000L)));
+                //亏吨量
+                BigDecimal defectiveWeigh = kwtWaybillOrder.getDeficitAmount() == null ? new BigDecimal("0.00") : kwtWaybillOrder.getDeficitAmount();
+                //扣亏量/吨
+                BigDecimal deduct = defectiveWeigh.compareTo(new BigDecimal("0.00")) == 0 ? new BigDecimal("0.00") : defectiveWeigh.subtract(multiply);
                 carWaybillVo.setWOrderId(String.valueOf(kwtWaybillOrder.getId()));
                 carWaybillVo.setWOrderNo(order.getLOrderNo());
                 carWaybillVo.setTruckNo(kwtWaybillOrder.getTruckNo());
@@ -389,6 +417,7 @@ public class ConsignOrderService {
 //                SckwWaybillOrder sckwWaybillOrder = mongoTemplate.findById(kwtWaybillOrder.getId(), SckwWaybillOrder.class);
                 /** 2023-07-24 原值为承运车队-去除后更换展示为承运公司*/
 //                carWaybillVo.setConsignMotorcade(sckwWaybillOrder == null ? null : sckwWaybillOrder.getCarrierFirmName());
+                //派车量
                 carWaybillVo.setSendCarWeigh(kwtWaybillOrder.getEntrustAmount() == null ? null : String.valueOf(kwtWaybillOrder.getEntrustAmount()));
                 carWaybillVo.setSendCarDate(DateUtil.getDateTime(kwtWaybillOrder.getCreateTime()));
                 if (loadTicket != null) {
@@ -632,12 +661,17 @@ public class ConsignOrderService {
     }
 
     /**
-     * 托运订单-完结订单
+     * 托运订单-新建订单
      *
      * @param addOrderDTO
      * @return
      */
     public HttpResult addOrder(AddOrderDTO addOrderDTO) throws ParseException {
+        HttpResult httpResult = ValidUtil.serviceValid(addOrderDTO);
+        if (!String.valueOf(HttpStatus.SUCCESS_CODE).equals(String.valueOf(httpResult.getCode()))) {
+            return HttpResult.error(httpResult.getMsg());
+        }
+        checkAddOrderParam(addOrderDTO);
         /**保存新建数据*/
         Long lOrderId = new IdWorker(NumberConstant.ONE).nextId();
         /**生成订单编号*/
@@ -684,6 +718,29 @@ public class ConsignOrderService {
         return HttpResult.ok();
     }
 
+    /**
+     * 校验请求参数
+     *
+     * @param orderDTO
+     */
+    private void checkAddOrderParam(AddOrderDTO orderDTO) {
+        if (!ObjectUtils.isEmpty(orderDTO.getTaxRate())) {
+            if (orderDTO.getTaxRate().compareTo(new BigDecimal(NumberConstant.ZERO)) < 0) {
+                throw new BusinessException("税率填写格式错误!");
+            }
+        }
+        if (!ObjectUtils.isEmpty(orderDTO.getLoss())) {
+            if (orderDTO.getLoss().compareTo(new BigDecimal(NumberConstant.ZERO)) < 0) {
+                throw new BusinessException("合理损耗填写格式错误!");
+            }
+        }
+        if (!ObjectUtils.isEmpty(orderDTO.getGoodsPrice())) {
+            if (orderDTO.getGoodsPrice().compareTo(new BigDecimal(NumberConstant.ZERO)) < 0) {
+                throw new BusinessException("扣亏货值填写格式错误!");
+            }
+        }
+    }
+
     /**
      * 托运订单-页面新增订单-商品信息
      *
@@ -982,7 +1039,27 @@ public class ConsignOrderService {
      */
     public HttpResult getLogisticsOrderAddressList() {
         Long entId = LoginUserHolder.getEntId();
-        List<Integer> codeList = kwtLogisticsOrderMapper.getAddressList(entId);
-        return HttpResult.ok(codeList);
+        AddressDropListDTO res = new AddressDropListDTO();
+        List<KwtLogisticsOrderUnit> unitInfo = kwtLogisticsOrderUnitMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrderUnit>()
+                .eq(KwtLogisticsOrderUnit::getEntId, entId));
+        if (CollectionUtils.isEmpty(unitInfo)) {
+            return HttpResult.ok(res);
+        }
+        Set<Long> lOrderIds = unitInfo.stream().map(KwtLogisticsOrderUnit::getLOrderId).collect(Collectors.toSet());
+        //订单ids获取地址信息
+        List<KwtLogisticsOrderAddress> addressList = kwtLogisticsOrderAddressMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrderAddress>()
+                .in(KwtLogisticsOrderAddress::getLOrderId, lOrderIds));
+        if (CollectionUtils.isEmpty(addressList)) {
+            return HttpResult.ok(res);
+        }
+        //装卸货地址类型分组获取装卸货cityCodes
+        Map<Integer, List<Integer>> map = addressList.stream().collect(Collectors.
+                groupingBy(KwtLogisticsOrderAddress::getAddressType, Collectors.mapping(KwtLogisticsOrderAddress::getCityCode, Collectors.toList())));
+        //装货地址下拉列表树
+        List<AreaTreeFrontResDto> loadTree = remoteSystemService.queryAreaTreeFrontByCodeList(map.get(DictEnum.TORDER_ADDRESS_TYPE_1.getValue()));
+        //卸货地址下拉列表树
+        List<AreaTreeFrontResDto> unloadTree = remoteSystemService.queryAreaTreeFrontByCodeList(map.get(DictEnum.TORDER_ADDRESS_TYPE_2.getValue()));
+        res.setLoadAddressList(loadTree).setUnloadAddressList(unloadTree);
+        return HttpResult.ok(res);
     }
 }

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

@@ -6,7 +6,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.sckw.contract.api.RemoteContractService;
-import com.sckw.contract.api.model.dto.res.ContractCommonInfoResDto;
 import com.sckw.core.common.enums.NumberConstant;
 import com.sckw.core.common.enums.StringConstant;
 import com.sckw.core.common.enums.enums.DictTypeEnum;
@@ -50,7 +49,10 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
 
 import java.math.BigDecimal;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -172,34 +174,7 @@ public class LogisticsConsignmentService {
         }
         String lOrderNo = com.sckw.transport.utils.StringUtils.getLOrderNo();
         Long orderId = new IdWorker(NumberConstant.ONE).nextId();
-        /**判断生成物流订单应生成哪一种单据状态*/
-        List<Long> contractList = new ArrayList<>();
-        contractList.add(Long.parseLong(bo.getContractId()));
-        Map<Long, ContractCommonInfoResDto> longContractCommonInfoResDtoMap = remoteContractService.queryContractBaseInfo(contractList);
-        if (CollectionUtils.isEmpty(longContractCommonInfoResDtoMap)) {
-            throw new RuntimeException("并未有对应合同,应先签约合同");
-        }
-        if (longContractCommonInfoResDtoMap.get(Long.parseLong(bo.getContractId())) == null) {
-            throw new RuntimeException("并未有对应合同,应先签约合同");
-        }
-        ContractCommonInfoResDto infoResDto = longContractCommonInfoResDtoMap.get(Long.parseLong(bo.getContractId()));
-        /**状态判断
-         * 是否是已签约合同
-         * */
-        // 0 已签约 1待签约
-        Integer status = infoResDto.getStatus();
         Integer orderStatus = LogisticsOrderEnum.PENDING_ORDER.getCode();
-        if (NumberConstant.ONE == status) {
-            orderStatus = LogisticsOrderEnum.TO_BE_PLANNED.getCode();
-        } else if (NumberConstant.ZERO == status) {
-            orderStatus = LogisticsOrderEnum.PENDING_ORDER.getCode();
-        } else {
-            log.info("采购/销售生成物流托运 贸易订单id:{}," +
-                            "贸易订单编号:{},合同id:{},合同信息:{}",
-                    bo.getTOrderId(), bo.getTOrderNo(),
-                    bo.getContractId(), JSONObject.toJSONString(infoResDto));
-            throw new RuntimeException("生成物流托运合同异常");
-        }
         insertLogisticsGoods(bo, lOrderNo, orderId);
         insertLogisticsOrder(bo, lOrderNo, order, tradeOrder, orderId, orderStatus);
         insertLogisticsOrderContract(bo, orderId);