Просмотр исходного кода

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

xucaiqin 2 лет назад
Родитель
Сommit
8f96452fa2
23 измененных файлов с 849 добавлено и 74 удалено
  1. 1 0
      sckw-modules-api/pom.xml
  2. 35 0
      sckw-modules-api/sckw-manage-api/pom.xml
  3. 24 0
      sckw-modules-api/sckw-manage-api/src/main/java/com/sckw/manage/api/RemoteManageService.java
  4. 74 0
      sckw-modules-api/sckw-manage-api/src/main/java/com/sckw/manage/api/model/dto/res/EntAddressResDto.java
  5. 0 2
      sckw-modules/sckw-contract/src/main/java/com/sckw/contract/dubbo/RemoteContractServiceImpl.java
  6. 6 2
      sckw-modules/sckw-manage/pom.xml
  7. 5 0
      sckw-modules/sckw-manage/src/main/java/com/sckw/manage/controller/KwmAddressController.java
  8. 53 0
      sckw-modules/sckw-manage/src/main/java/com/sckw/manage/dubbo/RemoteManageServiceImpl.java
  9. 8 0
      sckw-modules/sckw-manage/src/main/java/com/sckw/manage/service/KwmAddressService.java
  10. 5 0
      sckw-modules/sckw-order/src/main/java/com/sckw/order/model/dto/OrderCheckDTO.java
  11. 0 1
      sckw-modules/sckw-order/src/main/java/com/sckw/order/model/vo/req/GoodsInfo.java
  12. 12 5
      sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwoTradeOrderService.java
  13. 4 0
      sckw-modules/sckw-product/pom.xml
  14. 12 1
      sckw-modules/sckw-product/src/main/java/com/sckw/product/controller/KwpGoodsController.java
  15. 43 0
      sckw-modules/sckw-product/src/main/java/com/sckw/product/model/vo/req/MaxPurchaseNumParam.java
  16. 55 0
      sckw-modules/sckw-product/src/main/java/com/sckw/product/service/KwpGoodsService.java
  17. 6 3
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteSystemServiceImpl.java
  18. 1 1
      sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/AcceptCarriageOrderController.java
  19. 18 0
      sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/ConsignOrderController.java
  20. 8 0
      sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/KwtLogisticsOrder.java
  21. 26 20
      sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/dto/AddOrderDTO.java
  22. 87 38
      sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/AcceptCarriageOrderService.java
  23. 366 1
      sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/ConsignOrderService.java

+ 1 - 0
sckw-modules-api/pom.xml

@@ -28,6 +28,7 @@
         <module>sckw-fleet-api</module>
         <module>sckw-contract-api</module>
         <module>sckw-payment-api</module>
+        <module>sckw-manage-api</module>
     </modules>
 
     <properties>

+ 35 - 0
sckw-modules-api/sckw-manage-api/pom.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>sckw-modules-api</artifactId>
+        <groupId>com.sckw</groupId>
+        <version>1.0.0</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>sckw-manage-api</artifactId>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-openfeign-core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.sckw</groupId>
+            <artifactId>sckw-common-core</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

+ 24 - 0
sckw-modules-api/sckw-manage-api/src/main/java/com/sckw/manage/api/RemoteManageService.java

@@ -0,0 +1,24 @@
+package com.sckw.manage.api;
+
+import com.sckw.manage.api.model.dto.res.EntAddressResDto;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author czh
+ * @desc 基础信息+合作管理远程接口
+ * @date 2023/7/31
+ */
+public interface RemoteManageService {
+
+    /**
+     * @param idList 企业id集合
+     * @return Map<Long, List<EntAddressResDto>>
+     * @desc: 根据企业id查下面的地址
+     * @author: czh
+     * @date: 2023/7/31
+     */
+    Map<Long, List<EntAddressResDto>> queryEntAddressByEntIdList(List<Long> idList);
+
+}

+ 74 - 0
sckw-modules-api/sckw-manage-api/src/main/java/com/sckw/manage/api/model/dto/res/EntAddressResDto.java

@@ -0,0 +1,74 @@
+package com.sckw.manage.api.model.dto.res;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * @author czh
+ * @desc 企业地址
+ * @date 2023/7/31
+ */
+@Data
+public class EntAddressResDto implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = -7929121414731623227L;
+
+    /**
+     * 主键
+     */
+    private Long id;
+
+    /**
+     * 企业id
+     */
+    private Long entId;
+
+    /**
+     * 地址名称
+     */
+    private String name;
+
+    /**
+     * 地址类型
+     */
+    private Integer type;
+
+    /**
+     * 1 默认装货地址 2默认卸货地址 3都是
+     */
+    private Integer defaultType;
+
+    /**
+     * 所在地区
+     */
+    private Integer cityCode;
+
+    /**
+     * 所属区域名称
+     */
+    private String cityName;
+
+    /**
+     * 详细地址
+     */
+    private String detailAddress;
+
+    /**
+     * 纬度
+     */
+    private String lat;
+
+    /**
+     * 经度
+     */
+    private String lng;
+
+    /**
+     * 电子围栏
+     */
+    private String fence;
+
+}

+ 0 - 2
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/dubbo/RemoteContractServiceImpl.java

@@ -1,11 +1,9 @@
 package com.sckw.contract.dubbo;
-import com.google.common.collect.Lists;
 
 import com.sckw.contract.api.RemoteContractService;
 import com.sckw.contract.api.model.dto.res.ContractCommonInfoResDto;
 import com.sckw.contract.api.model.dto.res.EntInfo;
 import com.sckw.contract.dao.KwcContractLogisticsMapper;
-import com.sckw.contract.dao.KwcContractLogisticsUnitMapper;
 import com.sckw.contract.dao.KwcContractTradeMapper;
 import com.sckw.contract.model.entity.KwcContractLogistics;
 import com.sckw.contract.model.entity.KwcContractLogisticsUnit;

+ 6 - 2
sckw-modules/sckw-manage/pom.xml

@@ -62,7 +62,11 @@
             <groupId>com.sckw</groupId>
             <artifactId>sckw-common-excel</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>com.sckw</groupId>
+            <artifactId>sckw-manage-api</artifactId>
+            <version>1.0.0</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
-
 </project>

+ 5 - 0
sckw-modules/sckw-manage/src/main/java/com/sckw/manage/controller/KwmAddressController.java

@@ -125,4 +125,9 @@ public class KwmAddressController {
         return HttpResult.ok(kwmAddressService.detail(reqVo.getId()));
     }
 
+    @PostMapping("test")
+    public HttpResult test(@RequestBody IdsReqVo reqVo) throws SystemException {
+        return HttpResult.ok(kwmAddressService.test(reqVo.getId()));
+    }
+
 }

+ 53 - 0
sckw-modules/sckw-manage/src/main/java/com/sckw/manage/dubbo/RemoteManageServiceImpl.java

@@ -0,0 +1,53 @@
+package com.sckw.manage.dubbo;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.sckw.core.model.constant.Global;
+import com.sckw.core.utils.BeanUtils;
+import com.sckw.core.utils.CollectionUtils;
+import com.sckw.manage.api.RemoteManageService;
+import com.sckw.manage.api.model.dto.res.EntAddressResDto;
+import com.sckw.manage.dao.KwmAddressMapper;
+import com.sckw.manage.model.entity.KwmAddress;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author czh
+ * @desc 基础信息+合作管理远程接口实现
+ * @date 2023/7/31
+ */
+@DubboService(group = "design", version = "2.0.0")
+@Service
+public class RemoteManageServiceImpl implements RemoteManageService {
+
+    @Autowired
+    private KwmAddressMapper kwmAddressMapper;
+
+    /**
+     * @param idList 企业id集合
+     * @return Map<Long, List<EntAddressResDto>>
+     * @desc: 根据企业id查下面的地址
+     * @author: czh
+     * @date: 2023/7/31
+     */
+    @Override
+    public Map<Long, List<EntAddressResDto>> queryEntAddressByEntIdList(List<Long> idList) {
+        Map<Long, List<EntAddressResDto>> map = new HashMap<>();
+        LambdaQueryWrapper<KwmAddress> kwmAddressLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        kwmAddressLambdaQueryWrapper.in(KwmAddress::getEntId, idList).
+                                     eq(KwmAddress::getDelFlag, Global.NO);
+        List<KwmAddress> kwmAddressList = kwmAddressMapper.selectList(kwmAddressLambdaQueryWrapper);
+        if (CollectionUtils.isEmpty(kwmAddressList)) {
+            return map;
+        }
+
+        List<EntAddressResDto> entAddressResDtoList= BeanUtils.copyToList(kwmAddressList, EntAddressResDto.class);
+        return entAddressResDtoList.stream().collect(Collectors.groupingBy(EntAddressResDto::getEntId));
+    }
+}

+ 8 - 0
sckw-modules/sckw-manage/src/main/java/com/sckw/manage/service/KwmAddressService.java

@@ -20,7 +20,9 @@ import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.excel.utils.EasyExcelUtil;
+import com.sckw.manage.api.model.dto.res.EntAddressResDto;
 import com.sckw.manage.dao.KwmAddressMapper;
+import com.sckw.manage.dubbo.RemoteManageServiceImpl;
 import com.sckw.manage.model.entity.KwmAddress;
 import com.sckw.manage.model.vo.req.*;
 import com.sckw.manage.model.vo.res.AddressDetailResVo;
@@ -47,6 +49,8 @@ public class KwmAddressService {
     @Autowired
     private CommonBusinessService commonBusinessService;
 
+    @Autowired
+    private RemoteManageServiceImpl remoteManageService;
     /**
      * @param reqVo 分页入参
      * @return HttpResult
@@ -366,4 +370,8 @@ public class KwmAddressService {
         BeanUtils.copyProperties(kwmAddress, addressDetailResVo);
         return addressDetailResVo;
     }
+
+    public Map<Long, List<EntAddressResDto>> test(Long id) {
+        return remoteManageService.queryEntAddressByEntIdList(Collections.singletonList(id));
+    }
 }

+ 5 - 0
sckw-modules/sckw-order/src/main/java/com/sckw/order/model/dto/OrderCheckDTO.java

@@ -53,5 +53,10 @@ public class OrderCheckDTO {
      */
     private Long supplyTopEntId;
 
+    /**
+     * 订单来源 1采购下单2代客下单
+     */
+    private String orderSource;
+
 
 }

+ 0 - 1
sckw-modules/sckw-order/src/main/java/com/sckw/order/model/vo/req/GoodsInfo.java

@@ -64,7 +64,6 @@ public class GoodsInfo {
     /**
      * 价格段id
      */
-    @NotNull(message = "价格段id不能为空")
     private Long priceRangeId;
 
     /**

+ 12 - 5
sckw-modules/sckw-order/src/main/java/com/sckw/order/serivce/KwoTradeOrderService.java

@@ -227,9 +227,14 @@ public class KwoTradeOrderService {
      * @return: void
      */
     public void addPurchaseOrderSubmit(PurchaseOrderParam param) {
+        GoodsInfo goodsInfo = param.getGoodsInfo();
+        if (Objects.isNull(goodsInfo.getPriceRangeId())) {
+            throw new BusinessException("采购下单价格梯度信息不能为空!");
+        }
         OrderCheckDTO orderCheckDTO = BeanUtils.copyProperties(param, OrderCheckDTO.class);
         getTopEnt(orderCheckDTO, param.getUnitInfo());
-        orderCheckDTO.setGoodsId(param.getGoodsInfo().getGoodsId()).setUnitPrice(param.getGoodsInfo().getUnitPrice());
+        orderCheckDTO.setGoodsId(goodsInfo.getGoodsId()).setUnitPrice(goodsInfo.getUnitPrice())
+                .setOrderSource(DictEnum.TORDER_SOURCE_1.getValue());
         orderCheck(orderCheckDTO, false);
         KwoTradeOrder order = BeanUtils.copyProperties(param, KwoTradeOrder.class);
         order.setEntId(LoginUserHolder.getEntId()).setTOrderNo(OrderGenerateUtils.generateOrderNo(ORDER_NO_PREFIX))
@@ -292,8 +297,8 @@ public class KwoTradeOrderService {
             throw new BusinessException("商品库存不足,请联系供应方!");
         }
         BigDecimal advancePrice = goods.getAdvancePrice().multiply(new BigDecimal("10000"));
-        //受理订单不校验预付款限额
-        if (!isAcceptanceOrder && trading.startsWith("0") && price.compareTo(advancePrice) < 0) {
+        //直接采购下单才校验预付款限额
+        if (Objects.equals(param.getOrderSource(), DictEnum.TORDER_SOURCE_1.getValue()) && trading.startsWith("0") && price.compareTo(advancePrice) < 0) {
             throw new BusinessException("您的订单总额未达到预付限额,请确认");
         }
         if (trading.startsWith("0")) {
@@ -323,7 +328,8 @@ public class KwoTradeOrderService {
     public void addValetOrderSubmit(ValetOrderParam param) {
         OrderCheckDTO orderCheck = BeanUtils.copyProperties(param, OrderCheckDTO.class);
         getTopEnt(orderCheck, param.getUnitInfo());
-        orderCheck.setGoodsId(param.getGoodsInfo().getGoodsId()).setUnitPrice(param.getGoodsInfo().getUnitPrice());
+        orderCheck.setGoodsId(param.getGoodsInfo().getGoodsId()).setUnitPrice(param.getGoodsInfo().getUnitPrice())
+                .setOrderSource(DictEnum.TORDER_SOURCE_2.getValue());
         orderCheck(orderCheck, false);
         KwoTradeOrder order = BeanUtils.copyProperties(param, KwoTradeOrder.class);
         order.setEntId(LoginUserHolder.getEntId()).setTOrderNo(OrderGenerateUtils.generateOrderNo(ORDER_NO_PREFIX))
@@ -459,7 +465,8 @@ public class KwoTradeOrderService {
             }
             OrderCheckDTO orderCheck = BeanUtils.copyProperties(param, OrderCheckDTO.class);
             getTopEnt(orderCheck, param.getUnitInfo());
-            orderCheck.setGoodsId(param.getGoodsInfo().getGoodsId()).setUnitPrice(param.getGoodsInfo().getUnitPrice());
+            orderCheck.setGoodsId(param.getGoodsInfo().getGoodsId()).setUnitPrice(param.getGoodsInfo().getUnitPrice())
+                    .setOrderSource(source);
             orderCheck(orderCheck, false);
             //扣减库存
             HttpResult updateResult = goodsInfoService.updateGoodsAmount(param.getGoodsInfo().getGoodsId(), param.getAmount());

+ 4 - 0
sckw-modules/sckw-product/pom.xml

@@ -72,6 +72,10 @@
             <groupId>com.sckw</groupId>
             <artifactId>sckw-common-redis</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.sckw</groupId>
+            <artifactId>sckw-payment-api</artifactId>
+        </dependency>
 
     </dependencies>
 

+ 12 - 1
sckw-modules/sckw-product/src/main/java/com/sckw/product/controller/KwpGoodsController.java

@@ -182,9 +182,20 @@ public class KwpGoodsController {
      * @return: com.sckw.core.web.response.HttpResult
      */
     @PostMapping(value = "/dropList", produces = MediaType.APPLICATION_JSON_VALUE)
-    public HttpResult dropList(@RequestBody GoodsDropListReq params) {
+    public HttpResult dropList(@RequestBody @Validated GoodsDropListReq params) {
         return HttpResult.ok(kwpGoodsService.dropList(params));
     }
 
+    /**
+     * @desc: 获取商品预计最大可购数量
+     * @author: yzc
+     * @date: 2023-07-31 17:42
+     * @Param param:
+     * @return: com.sckw.core.web.response.HttpResult
+     */
+    @PostMapping(value = "/maxPurchaseNum", produces = MediaType.APPLICATION_JSON_VALUE)
+    public HttpResult maxPurchaseNum(@RequestBody @Validated MaxPurchaseNumParam param) {
+        return HttpResult.ok(kwpGoodsService.maxPurchaseNum(param));
+    }
 
 }

+ 43 - 0
sckw-modules/sckw-product/src/main/java/com/sckw/product/model/vo/req/MaxPurchaseNumParam.java

@@ -0,0 +1,43 @@
+package com.sckw.product.model.vo.req;
+
+import jakarta.validation.constraints.DecimalMin;
+import jakarta.validation.constraints.NotNull;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+import java.math.BigDecimal;
+
+/**
+ * @desc: 最
+ * @author: yzc
+ * @date: 2023-07-31 17:38
+ */
+@Getter
+@Setter
+@ToString
+public class MaxPurchaseNumParam {
+
+    /**
+     * 商品id
+     */
+    @NotNull(message = "商品id不能为空")
+    private Long goodsId;
+
+    /**
+     * 成交单价
+     */
+    @NotNull(message = "成交单价不能为空")
+    @DecimalMin(value = "0.00", message = "成交单价最小为零")
+    private BigDecimal utilPrice;
+
+    /**
+     * 采购企业id
+     */
+    private Long procureEntId;
+
+    /**
+     * 供应企业id
+     */
+    private Long supplyEntId;
+}

+ 55 - 0
sckw-modules/sckw-product/src/main/java/com/sckw/product/service/KwpGoodsService.java

@@ -18,6 +18,10 @@ import com.sckw.core.utils.NumberUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.excel.utils.DateUtil;
+import com.sckw.payment.api.dubbo.PayCenterDubboService;
+import com.sckw.payment.api.model.constant.ChannelEnum;
+import com.sckw.payment.api.model.dto.WalletDto;
+import com.sckw.payment.api.model.dto.common.R;
 import com.sckw.product.dao.KwpGoodsMapper;
 import com.sckw.product.enums.GoodsStatusEnum;
 import com.sckw.product.model.*;
@@ -34,6 +38,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -50,6 +55,9 @@ public class KwpGoodsService {
     @DubboReference(version = "2.0.0", group = "design", check = false)
     private RemoteSystemService remoteSystemService;
 
+    @DubboReference(version = "2.0.0", group = "design", check = false)
+    private PayCenterDubboService payCenterDubboService;
+
     private final KwpGoodsMapper kwpGoodsMapper;
     private final KwpGoodsAddressService kwpGoodsAddressService;
     private final KwpGoodsAttributeService kwpGoodsAttributeService;
@@ -814,4 +822,51 @@ public class KwpGoodsService {
     public void updateById(KwpGoods goods) {
         kwpGoodsMapper.updateById(goods);
     }
+
+    /**
+     * @desc: 获取商品预计最大可购数量
+     * @author: yzc
+     * @date: 2023-07-31 17:41
+     * @Param param:
+     * @return: java.math.BigDecimal
+     */
+    public BigDecimal maxPurchaseNum(MaxPurchaseNumParam param) {
+        LambdaQueryWrapper<KwpGoods> wrapper = new LambdaQueryWrapper<>();
+        LambdaQueryWrapper<KwpGoods> last = wrapper.eq(KwpGoods::getId, param.getGoodsId()).eq(KwpGoods::getDelFlag, Global.NO)
+                .eq(KwpGoods::getStatus, GoodsStatusEnum.PUT_ON_SHELVES.getCode()).last("LIMIT 1");
+        KwpGoods goods = kwpGoodsMapper.selectOne(last);
+        if (Objects.isNull(goods)) {
+            throw new BusinessException("商品不存在或已下架!");
+        }
+        BigDecimal amount = goods.getAmount();
+        if (!goods.getTrading().startsWith("0")) {
+            return amount;
+        }
+        if (Objects.isNull(param.getProcureEntId()) || Objects.isNull(param.getSupplyEntId())) {
+            throw new BusinessException("采购或供应单位信息不能为空!");
+        }
+        List<Long> entIds = Arrays.asList(param.getProcureEntId(), param.getSupplyEntId());
+        Map<Long, EntCacheResDto> entMap = remoteSystemService.queryEntTreeByIds(entIds);
+        EntCacheResDto procure = entMap.get(param.getProcureEntId());
+        if (Objects.isNull(procure) || Objects.isNull(procure.getId())) {
+            log.error("采购单位:{}找不到对应一级企业信息", param.getProcureEntId());
+            throw new BusinessException("采购单位一级企业信息不存在!");
+        }
+        EntCacheResDto supply = entMap.get(param.getSupplyEntId());
+        if (Objects.isNull(supply) || Objects.isNull(supply.getId())) {
+            log.error("供应单位:{}找不到对应一级企业信息", param.getSupplyEntId());
+            throw new BusinessException("供应单位一级企业信息不存在!");
+        }
+        R<List<WalletDto>> wallet = payCenterDubboService.wallet(procure.getId(), ChannelEnum.getByCode(goods.getTrading()), supply.getId());
+        if (Objects.isNull(wallet) || Objects.equals(wallet.getCode(), 0)) {
+            throw new BusinessException("校验预付钱包异常,请联系管理员!");
+        }
+        List<WalletDto> data = wallet.getData();
+        if (CollectionUtils.isEmpty(data)) {
+            throw new BusinessException("检测尚未创建对应预付款清单,请先创建!");
+        }
+        long money = data.get(0).getMoney();
+        BigDecimal divide = new BigDecimal(money).divide(param.getUtilPrice().multiply(new BigDecimal("100")), 2, RoundingMode.HALF_UP);
+        return amount.compareTo(divide) < 0 ? amount : divide;
+    }
 }

+ 6 - 3
sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteSystemServiceImpl.java

@@ -104,7 +104,7 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
             RedissonUtils.putString(key, JSON.toJSONString(sysDictResDtos), Global.COMMON_EXPIRE);
             return sysDictResDtos;
         }
-
+        RedissonUtils.putString(key, dictCache, Global.COMMON_EXPIRE);
         return JSONObject.parseArray(dictCache, SysDictResDto.class);
     }
 
@@ -130,6 +130,7 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
             RedissonUtils.putString(key, JSON.toJSONString(sysDictResDto), Global.COMMON_EXPIRE);
             return sysDictResDto;
         }
+        RedissonUtils.putString(key, dictCache, Global.COMMON_EXPIRE);
         return JSONObject.parseObject(dictCache, SysDictResDto.class);
     }
 
@@ -228,6 +229,7 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
             RedissonUtils.putString(key, JSON.toJSONString(sysDictGroupResDto), Global.COMMON_EXPIRE);
             return sysDictGroupResDto;
         }
+        RedissonUtils.putString(key, dictCache, Global.COMMON_EXPIRE);
         return JSONObject.parseObject(dictCache, SysDictGroupResDto.class);
     }
 
@@ -261,7 +263,7 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
             RedissonUtils.putString(key, JSON.toJSONString(entCacheResDto), Global.COMMON_EXPIRE);
             return entCacheResDto;
         }
-
+        RedissonUtils.putString(key, dictCache, Global.COMMON_EXPIRE);
         return JSONObject.parseObject(dictCache, EntCacheResDto.class);
     }
 
@@ -413,7 +415,7 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
             RedissonUtils.putString(key, JSON.toJSONString(userCacheResDto), Global.COMMON_EXPIRE);
             return userCacheResDto;
         }
-
+        RedissonUtils.putString(key, dictCache, Global.COMMON_EXPIRE);
         return JSONObject.parseObject(dictCache, UserCacheResDto.class);
     }
 
@@ -456,6 +458,7 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
             RedissonUtils.putString(key, JSON.toJSONString(sysAreaCacheResDto), Global.COMMON_EXPIRE);
             return sysAreaCacheResDto;
         }
+        RedissonUtils.putString(key, areaCache, Global.COMMON_EXPIRE);
         return JSONObject.parseObject(areaCache, SysAreaCacheResDto.class);
     }
 

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

@@ -272,7 +272,7 @@ public class AcceptCarriageOrderController {
      * @return
      */
     @RequestMapping(value = "/addOrder", method = RequestMethod.POST)
-    public HttpResult addOrder(@Validated @RequestBody AddOrderDTO addOrderDTO) {
+    public HttpResult addOrder(@Valid @RequestBody AddOrderDTO addOrderDTO) {
         try {
             return acceptCarriageOrderService.addOrder(addOrderDTO);
         } catch (Exception e) {

+ 18 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/ConsignOrderController.java

@@ -2,9 +2,11 @@ package com.sckw.transport.controller;
 
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.transport.model.dto.AddOrderDTO;
 import com.sckw.transport.model.dto.OrderDTO;
 import com.sckw.transport.model.dto.OrderFinishDTO;
 import com.sckw.transport.service.ConsignOrderService;
+import jakarta.validation.Valid;
 import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import lombok.RequiredArgsConstructor;
@@ -103,4 +105,20 @@ public class ConsignOrderController {
         }
     }
 
+    /**
+     * 托运订单-新建订单
+     *
+     * @param addOrderDTO 页面传递参数
+     * @return
+     */
+    @RequestMapping(value = "/addOrder", method = RequestMethod.POST)
+    public HttpResult addOrder(@Valid @RequestBody AddOrderDTO addOrderDTO) {
+        try {
+            return consignOrderService.addOrder(addOrderDTO);
+        } catch (Exception e) {
+            log.error("托运订单-新建订单 error:{}", e.getMessage(), e);
+            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
+        }
+    }
+
 }

+ 8 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/KwtLogisticsOrder.java

@@ -2,6 +2,10 @@ package com.sckw.transport.model;
 
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
+import jakarta.validation.constraints.DecimalMin;
+import jakarta.validation.constraints.Digits;
+import jakarta.validation.constraints.Max;
+import jakarta.validation.constraints.Min;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -73,11 +77,15 @@ public class KwtLogisticsOrder implements Serializable {
     /**
      * 运价方式(元/吨、元/车)
      */
+    @Min(value = 0,message = "运价方式类型不能大于等于{value}")
+    @Max(value = 4,message = "运价方式类型不能大于等于{value}")
     private Long priceType;
 
     /**
      * 已委托量
      */
+    @Digits(integer = 10,fraction = 2,message = "委托量格式不正确")
+    @DecimalMin(value = "0.00",message = "委托量不能小于{value}")
     private BigDecimal amount;
 
     /**

+ 26 - 20
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/model/dto/AddOrderDTO.java

@@ -1,9 +1,6 @@
 package com.sckw.transport.model.dto;
 
-import jakarta.validation.constraints.DecimalMin;
-import jakarta.validation.constraints.Digits;
-import jakarta.validation.constraints.NotBlank;
-import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.*;
 import lombok.Data;
 import org.hibernate.validator.constraints.Length;
 
@@ -95,7 +92,7 @@ public class AddOrderDTO {
     /**
      * 运价
      */
-    @NotBlank(message = "运价不能为空")
+    @NotNull(message = "运价不能为空")
     @Digits(integer = 10, fraction = 2, message = "装货量格式错误")
     @DecimalMin(value = "0.00", message = "运价最小为{value}")
     private BigDecimal price;
@@ -104,7 +101,9 @@ public class AddOrderDTO {
      * 运价方式
      */
     @NotNull(message = "运价方式不能为空")
-    private String priceType;
+    @Min(value = 0, message = "必须大于等于{value}")
+    @Max(value = 4, message = "必须小于等于{value}")
+    private Long priceType;
 
     /**
      * 税率
@@ -117,15 +116,15 @@ public class AddOrderDTO {
     /**
      * 税率单位
      */
-    @NotBlank(message = "税率单位不能为空")
-    private Long taxRateUnit;
+    @NotNull(message = "税率单位不能为空")
+    private String taxRateUnit;
 
     /**
      * 总量
      */
     @NotNull(message = "总量不能为空")
     @Digits(integer = 10, fraction = 2, message = "总量格式错误")
-    @DecimalMin(value = "0.00",message = "总量最小值为{value}")
+    @DecimalMin(value = "0.00", message = "总量最小值为{value}")
     private BigDecimal amount;
 
     /**
@@ -138,7 +137,7 @@ public class AddOrderDTO {
      * 合理损耗
      */
     @Digits(integer = 10, fraction = 2, message = "合理损耗格式错误")
-    @DecimalMin(value = "0.00",message = "合理损耗最小值为{value}")
+    @DecimalMin(value = "0.00", message = "合理损耗最小值为{value}")
     private BigDecimal loss;
 
     /**
@@ -150,8 +149,8 @@ public class AddOrderDTO {
      * 商品价值(扣亏货值)
      */
     @Digits(integer = 10, fraction = 2, message = "扣亏货值格式错误")
-    @DecimalMin(value = "0.00",message = "扣亏货值最小值为{value}")
-    private Long goodsPrice;
+    @DecimalMin(value = "0.00", message = "扣亏货值最小值为{value}")
+    private BigDecimal goodsPrice;
     /**
      * 商品价值(扣亏货值)单位
      */
@@ -173,8 +172,9 @@ public class AddOrderDTO {
     /**
      * 结算周期(周结、月结、季结)
      */
-    @NotNull(message = "结算周期不能为空")
-    private String settlementCycle;
+    @Min(value = 0, message = "必须大于等于{value}")
+    @Max(value = 4, message = "必须小于等于{value}")
+    private Long settlementCycle;
 
     /**
      * 合同id
@@ -197,8 +197,10 @@ public class AddOrderDTO {
     /**
      * 合同签约方式
      */
-    @NotBlank(message = "合同签约方式不能为空")
-    private String payment;
+    @NotNull(message = "合同签约方式不能为空")
+    @Min(value = 0,message = "合同签约方式必须大于等于{value}")
+    @Max(value = 4,message = "合同签约方式必须小于等于{value}")
+    private Long payment;
 
     /**
      * 备注
@@ -221,8 +223,10 @@ public class AddOrderDTO {
     /**
      * 装货城市编码
      */
-    @NotBlank(message = "装货城市编码不能为空")
-    private String loadCityCode;
+    @NotNull(message = "装货城市编码不能为空")
+    @Min(value = 0,message = "城市编码必须大于等于{value}")
+    @Max(value = 999,message = "城市编码必须小于等于{value}")
+    private Integer loadCityCode;
 
     /**
      * 装货城市名称
@@ -249,8 +253,10 @@ public class AddOrderDTO {
     /**
      * 卸货城市编码
      */
-    @NotBlank(message = "卸货城市编码不能为空")
-    private String unloadCityCode;
+    @NotNull(message = "卸货城市编码不能为空")
+    @Min(value = 0,message = "卸货城市编码必须大于等于{value}")
+    @Max(value = 999,message = "卸货城市编码必须小于等于{value}")
+    private Integer unloadCityCode;
 
     /**
      * 卸货城市名称

+ 87 - 38
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/AcceptCarriageOrderService.java

@@ -10,6 +10,7 @@ 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;
+import com.sckw.core.exception.BusinessException;
 import com.sckw.core.model.enums.CarWaybillEnum;
 import com.sckw.core.model.enums.LogisticsOrderEnum;
 import com.sckw.core.utils.*;
@@ -1093,6 +1094,11 @@ public class AcceptCarriageOrderService {
      */
     @Transactional(rollbackFor = Exception.class)
     public HttpResult addOrder(AddOrderDTO orderDTO) throws ParseException {
+        HttpResult httpResult = ValidUtil.serviceValid(orderDTO);
+        if (!String.valueOf(HttpStatus.SUCCESS_CODE).equals(String.valueOf(httpResult.getCode()))) {
+            return HttpResult.error(httpResult.getMsg());
+        }
+        checkAddOrderParam(orderDTO);
         /**保存新建数据*/
         Long lOrderId = new IdWorker(NumberConstant.ONE).nextId();
         /**生成订单编号*/
@@ -1123,15 +1129,69 @@ public class AcceptCarriageOrderService {
             log.info("承运订单创建订单异常");
             throw new RuntimeException("自建订单异常");
         }
+        //todo dubbo根据企业获取地址信息
+        /**获取商品信息*/
+        KwpGoods goods = goodsInfoService.getGoodsById(Long.parseLong(orderDTO.getGoodsId()));
+        if (goods == null) {
+            log.info("自建订单获取商品信息失败 商品id:{},商品名称:{}", orderDTO.getGoodsId(), orderDTO.getGoodsName());
+            throw new BusinessException("商品信息获取失败");
+        }
         saveLogisticsOrder(orderDTO, lOrderId, orderStatus, lOrderNo);
         saveLogisticsOrderAddress(orderDTO, lOrderId);
+        saveLogisticsOrderGoods(orderDTO, lOrderId, lOrderNo, goods);
         saveLogisticsOrderContract(orderDTO, lOrderId, status);
         saveLogisticsOrderTrack(lOrderId, orderStatus);
         saveLogisticsOrderUnit(orderDTO, lOrderId);
-        saveMongoDb(orderDTO, orderStatus, lOrderId, lOrderNo, infoResDto);
+        saveMongoDb(orderDTO, orderStatus, lOrderId, lOrderNo, infoResDto, goods);
         return HttpResult.ok();
     }
 
+    /**
+     * 承运订单-页面新增订单-商品信息
+     *
+     * @param orderDTO 页面参数
+     * @param lOrderId 订单id
+     * @param lOrderNo 订单编号
+     * @param kwpGoods 商品信息
+     */
+    private void saveLogisticsOrderGoods(AddOrderDTO orderDTO, Long lOrderId, String lOrderNo, KwpGoods kwpGoods) {
+        KwtLogisticsOrderGoods goods = new KwtLogisticsOrderGoods();
+        goods.setId(new IdWorker(NumberConstant.ONE).nextId());
+        goods.setLOrderId(lOrderId);
+        goods.setLOrderNo(lOrderNo);
+        goods.setGoodsId(Long.parseLong(orderDTO.getGoodsId()));
+        goods.setGoodsName(kwpGoods.getName());
+        goods.setStatus(kwpGoods.getStatus());
+        goods.setCreateBy(LoginUserHolder.getUserId());
+        goods.setCreateTime(new Date());
+        goods.setUpdateBy(LoginUserHolder.getUserId());
+        goods.setUpdateTime(new Date());
+        kwtLogisticsOrderGoodsMapper.insert(goods);
+    }
+
+    /**
+     * 校验请求参数
+     *
+     * @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.getTaxRate().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("税率填写格式错误!");
+            }
+        }
+    }
+
     /**
      * 承运订单-新建订单-保存mongodb
      *
@@ -1140,8 +1200,9 @@ public class AcceptCarriageOrderService {
      * @param lOrderId    主体订单id
      * @param lOrderNo    主体订单编号
      * @param infoResDto  合同信息
+     * @param goods       商品信息
      */
-    private void saveMongoDb(AddOrderDTO orderDTO, Integer orderStatus, Long lOrderId, String lOrderNo, ContractCommonInfoResDto infoResDto) {
+    private void saveMongoDb(AddOrderDTO orderDTO, Integer orderStatus, Long lOrderId, String lOrderNo, ContractCommonInfoResDto infoResDto, KwpGoods goods) {
         SckwLogisticsOrder order = new SckwLogisticsOrder();
         order.set_id(lOrderId);
         order.setLOrderId(lOrderId);
@@ -1149,14 +1210,14 @@ public class AcceptCarriageOrderService {
         order.setLOrderPid(null);
         order.setLOrderPids(String.valueOf(lOrderId));
         order.setType(NumberConstant.TWO);
-        order.setSettlementCycle(Long.parseLong(orderDTO.getSettlementCycle()));
+        order.setSettlementCycle(orderDTO.getSettlementCycle());
         order.setPrice(orderDTO.getPrice());
         order.setPriceType(order.getPriceType());
         order.setAmount(orderDTO.getAmount());
         order.setUnit(orderDTO.getAmountUnit());
         order.setLoss(orderDTO.getLoss());
         order.setLossUnit(orderDTO.getLossUnit());
-        order.setGoodsPrice(orderDTO.getGoodsPrice() == null ? null : new BigDecimal(orderDTO.getGoodsPrice()));
+        order.setGoodsPrice(orderDTO.getGoodsPrice() == null ? null : orderDTO.getGoodsPrice());
         order.setGoodsPriceUnit(orderDTO.getGoodsPriceUnit());
         BigDecimal decimal = new BigDecimal(NumberConstant.ZERO);
         order.setSubcontractAmount(decimal);
@@ -1166,14 +1227,13 @@ public class AcceptCarriageOrderService {
         order.setIgnoreAmount(decimal);
         order.setDeficitAmount(decimal);
         order.setDeficitPrice(decimal);
-        order.setPayment(StringUtils.isBlank(orderDTO.getPayment()) ? null : Long.parseLong(orderDTO.getPayment()));
+        order.setPayment(orderDTO.getPayment());
         order.setTaxRate(orderDTO.getTaxRate());
         order.setRemark(orderDTO.getRemark());
         order.setStatus(String.valueOf(orderStatus));
         order.setEntId(LoginUserHolder.getEntId());
         order.setFirmName(LoginUserHolder.getEntName());
         order.setGoodsId(Long.parseLong(orderDTO.getGoodsId()));
-        KwpGoods goods = goodsInfoService.getGoodsById(Long.parseLong(orderDTO.getGoodsId()));
         order.setGoodsCode(goods == null ? null : goods.getCode());
         order.setGoodsName(goods == null ? null : goods.getName());
         order.setGoodsType(goods == null ? null : goods.getGoodsType());
@@ -1297,9 +1357,9 @@ public class AcceptCarriageOrderService {
         loadAddress.setAddressType(NumberConstant.ONE);
 //        loadAddress.setName();
 //        loadAddress.setType();
-//        loadAddress.setContacts();
-//        loadAddress.setPhone();
-        loadAddress.setCityCode(Integer.valueOf(orderDTO.getLoadCityCode()));
+        loadAddress.setContacts(orderDTO.getContacts());
+        loadAddress.setPhone(orderDTO.getConsignContactPhone());
+        loadAddress.setCityCode(orderDTO.getLoadCityCode());
         loadAddress.setCityName(orderDTO.getLoadCityName());
         loadAddress.setDetailAddress(orderDTO.getLoadDetailAddress());
         loadAddress.setLat(orderDTO.getLoadLat());
@@ -1318,9 +1378,9 @@ public class AcceptCarriageOrderService {
         unloadAddress.setAddressType(NumberConstant.TWO);
 //        unloadAddress.setName();
 //        unloadAddress.setType();
-//        unloadAddress.setContacts();
-//        unloadAddress.setPhone();
-        unloadAddress.setCityCode(Integer.valueOf(orderDTO.getUnloadCityCode()));
+        unloadAddress.setContacts(orderDTO.getContacts());
+        unloadAddress.setPhone(orderDTO.getAcceptContactPhone());
+        unloadAddress.setCityCode(orderDTO.getUnloadCityCode());
         unloadAddress.setCityName(orderDTO.getUnloadCityName());
         unloadAddress.setDetailAddress(orderDTO.getUnloadDetailAddress());
         unloadAddress.setLat(orderDTO.getUnloadLat());
@@ -1343,28 +1403,16 @@ public class AcceptCarriageOrderService {
      * @param status   合同状态
      */
     private void saveLogisticsOrderContract(AddOrderDTO orderDTO, Long lOrderId, Integer status) {
-        //托运
-        KwtLogisticsOrderContract consignContract = new KwtLogisticsOrderContract();
-        consignContract.setId(new IdWorker(NumberConstant.ONE).nextId());
-        consignContract.setContractId(Long.parseLong(orderDTO.getContractId()));
-        consignContract.setLOrderId(lOrderId);
-        consignContract.setStatus(status);
-        consignContract.setCreateBy(LoginUserHolder.getUserId());
-        consignContract.setCreateTime(new Date());
-        consignContract.setUpdateBy(LoginUserHolder.getUserId());
-        consignContract.setUpdateTime(new Date());
-        //承运
-        KwtLogisticsOrderContract acceptContract = new KwtLogisticsOrderContract();
-        acceptContract.setId(new IdWorker(NumberConstant.TWO).nextId());
-        acceptContract.setContractId(Long.parseLong(orderDTO.getContractId()));
-        acceptContract.setLOrderId(lOrderId);
-        acceptContract.setStatus(status);
-        acceptContract.setCreateBy(LoginUserHolder.getUserId());
-        acceptContract.setCreateTime(new Date());
-        acceptContract.setUpdateBy(LoginUserHolder.getUserId());
-        acceptContract.setUpdateTime(new Date());
-        kwtLogisticsOrderContractMapper.insert(consignContract);
-        kwtLogisticsOrderContractMapper.insert(acceptContract);
+        KwtLogisticsOrderContract contract = new KwtLogisticsOrderContract();
+        contract.setId(new IdWorker(NumberConstant.ONE).nextId());
+        contract.setContractId(Long.parseLong(orderDTO.getContractId()));
+        contract.setLOrderId(lOrderId);
+        contract.setStatus(status);
+        contract.setCreateBy(LoginUserHolder.getUserId());
+        contract.setCreateTime(new Date());
+        contract.setUpdateBy(LoginUserHolder.getUserId());
+        contract.setUpdateTime(new Date());
+        kwtLogisticsOrderContractMapper.insert(contract);
     }
 
     /**
@@ -1382,15 +1430,16 @@ public class AcceptCarriageOrderService {
         order.setType(String.valueOf(NumberConstant.TWO));
         order.setLOrderNo(lOrderNo);
         order.setPids(lOrderId.toString());
-        order.setSettlementCycle(Long.parseLong(orderDTO.getSettlementCycle()));
+        order.setSettlementCycle(orderDTO.getSettlementCycle());
         order.setBillingMode(orderDTO.getBillingMode());
         order.setPrice(orderDTO.getPrice());
-        order.setPriceType(Long.parseLong(orderDTO.getPriceType()));
+        order.setPriceType(orderDTO.getPriceType());
+        order.setPayment(orderDTO.getPayment());
         order.setAmount(orderDTO.getAmount());
         order.setUnit(orderDTO.getAmountUnit());
-        order.setLoss(orderDTO.getLossUnit() == null ? null : new BigDecimal((orderDTO.getLossUnit())));
+        order.setLoss(orderDTO.getLoss() == null ? null : orderDTO.getLoss());
         order.setLossUnit(orderDTO.getLossUnit());
-        order.setGoodsPrice(orderDTO.getGoodsPrice() == null ? null : new BigDecimal((orderDTO.getGoodsPrice())));
+        order.setGoodsPrice(orderDTO.getGoodsPrice() == null ? null : orderDTO.getGoodsPrice());
         order.setGoodsPriceUnit(orderDTO.getGoodsPriceUnit());
         order.setStartTime(org.apache.commons.lang3.StringUtils.isBlank(orderDTO.getStartTime()) ?
                 null : DateUtil.strToDate(StringTimeUtil.fillStart(orderDTO.getStartTime()), StringConstant.DEFAULT_DATE_PATTERN));

+ 366 - 1
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/ConsignOrderService.java

@@ -2,12 +2,16 @@ package com.sckw.transport.service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+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.exception.BusinessException;
 import com.sckw.core.model.enums.CarWaybillEnum;
 import com.sckw.core.model.enums.LogisticsOrderEnum;
 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.context.LoginUserHolder;
 import com.sckw.core.web.response.HttpResult;
@@ -16,10 +20,13 @@ import com.sckw.fleet.api.RemoteFleetService;
 import com.sckw.fleet.api.model.vo.RTruckVo;
 import com.sckw.mongo.enums.BusinessTypeEnum;
 import com.sckw.mongo.model.SckwLogisticsOrder;
+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.transport.dao.*;
 import com.sckw.transport.model.*;
+import com.sckw.transport.model.dto.AddOrderDTO;
 import com.sckw.transport.model.dto.OrderDTO;
 import com.sckw.transport.model.dto.OrderFinishDTO;
 import com.sckw.transport.model.vo.CarDataVO;
@@ -35,6 +42,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 
 import java.math.BigDecimal;
+import java.text.ParseException;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -49,6 +57,11 @@ public class ConsignOrderService {
 
     @DubboReference(version = "2.0.0", group = "design", check = false)
     RemoteSystemService remoteSystemService;
+    @DubboReference(version = "2.0.0", group = "design", check = false)
+    RemoteContractService remoteContractService;
+
+    @DubboReference(version = "2.0.0", group = "design", check = false, timeout = 8000)
+    GoodsInfoService goodsInfoService;
 
     @DubboReference(version = "2.0.0", group = "design", check = false)
     RemoteFleetService remoteFleetService;
@@ -65,12 +78,18 @@ public class ConsignOrderService {
     @Autowired
     public KwtLogisticsOrderAddressMapper kwtLogisticsOrderAddressMapper;
 
+    @Autowired
+    public KwtLogisticsOrderContractMapper logisticsOrderContractMapper;
+
     @Autowired
     public KwtLogisticsOrderUnitMapper kwtLogisticsOrderUnitMapper;
 
     @Autowired
     public KwtLogisticsOrderTrackMapper kwtLogisticsOrderTrackMapper;
 
+    @Autowired
+    public KwtLogisticsOrderGoodsMapper logisticsOrderGoodsMapper;
+
     @Autowired
     public KwtWaybillOrderMapper kwtWaybillOrderMapper;
 
@@ -499,11 +518,357 @@ public class ConsignOrderService {
 
     /**
      * 托运订单-完结订单-数据查询展示
-     * @param orderId   物流订单id
+     *
+     * @param orderId 物流订单id
      * @return
      */
     public HttpResult consignOrderFinishDetail(String orderId) {
         OrderFinishVO orderFinishVO = kwtLogisticsOrderMapper.selectOrderFinishData(orderId);
         return HttpResult.ok(orderFinishVO);
     }
+
+    /**
+     * 托运订单-完结订单
+     *
+     * @param addOrderDTO
+     * @return
+     */
+    public HttpResult addOrder(AddOrderDTO addOrderDTO) throws ParseException {
+        /**保存新建数据*/
+        Long lOrderId = new IdWorker(NumberConstant.ONE).nextId();
+        /**生成订单编号*/
+        String lOrderNo = com.sckw.transport.utils.StringUtils.getLOrderNo();
+        /**根据合同计算当前单据状态*/
+        /**判断生成物流订单应生成哪一种单据状态*/
+        List<Long> contractList = new ArrayList<>();
+        contractList.add(Long.parseLong(addOrderDTO.getContractId()));
+        Map<Long, ContractCommonInfoResDto> longContractCommonInfoResDtoMap = remoteContractService.queryContractBaseInfo(contractList);
+        if (CollectionUtils.isEmpty(longContractCommonInfoResDtoMap)) {
+            throw new RuntimeException("托运订单新建订单-并未有对应合同,应先签约合同");
+        }
+        if (longContractCommonInfoResDtoMap.get(Long.parseLong(addOrderDTO.getContractId())) == null) {
+            throw new RuntimeException("托运订单新建订单-并未有对应合同,应先签约合同");
+        }
+        ContractCommonInfoResDto infoResDto = longContractCommonInfoResDtoMap.get(Long.parseLong(addOrderDTO.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("托运订单创建订单异常");
+            throw new RuntimeException("自建订单异常");
+        }
+        /**获取商品信息*/
+        KwpGoods goods = goodsInfoService.getGoodsById(Long.parseLong(addOrderDTO.getGoodsId()));
+        if (goods == null) {
+            log.info("自建订单获取商品信息失败 商品id:{},商品名称:{}", addOrderDTO.getGoodsId(), addOrderDTO.getGoodsName());
+            throw new BusinessException("商品信息获取失败");
+        }
+        saveConsignLogisticsOrder(addOrderDTO, lOrderId, orderStatus, lOrderNo);
+        saveConsignLogisticsOrderAddress(addOrderDTO, lOrderId);
+        saveConsignLogisticsOrderGoods(addOrderDTO, lOrderId, lOrderNo, goods);
+        saveConsignLogisticsOrderContract(addOrderDTO, lOrderId, status);
+        saveConsignLogisticsOrderTrack(lOrderId, orderStatus);
+        saveConsignLogisticsOrderUnit(addOrderDTO, lOrderId);
+        saveMongoDb(addOrderDTO, orderStatus, lOrderId, lOrderNo, infoResDto, goods);
+        return HttpResult.ok();
+    }
+
+    /**
+     * 托运订单-页面新增订单-商品信息
+     *
+     * @param addOrderDTO 页面参数
+     * @param lOrderId    订单id
+     * @param lOrderNo    订单编号
+     */
+    private void saveConsignLogisticsOrderGoods(AddOrderDTO addOrderDTO, Long lOrderId, String lOrderNo, KwpGoods kwpGoods) {
+        KwtLogisticsOrderGoods goods = new KwtLogisticsOrderGoods();
+        goods.setId(new IdWorker(NumberConstant.ONE).nextId());
+        goods.setLOrderId(lOrderId);
+        goods.setLOrderNo(lOrderNo);
+        goods.setGoodsId(Long.parseLong(addOrderDTO.getGoodsId()));
+        goods.setGoodsName(kwpGoods.getName());
+        goods.setStatus(kwpGoods.getStatus());
+        goods.setCreateBy(LoginUserHolder.getUserId());
+        goods.setCreateTime(new Date());
+        goods.setUpdateBy(LoginUserHolder.getUserId());
+        goods.setUpdateTime(new Date());
+        logisticsOrderGoodsMapper.insert(goods);
+    }
+
+    /**
+     * 托运订单-页面新增订单-订单主体
+     *
+     * @param addOrderDTO 页面请求参数
+     * @param lOrderId    主体id
+     * @param orderStatus 订单状态
+     * @param lOrderNo    主体订单编号
+     */
+    private void saveConsignLogisticsOrder(AddOrderDTO addOrderDTO, Long lOrderId, Integer orderStatus, String lOrderNo) throws ParseException {
+        KwtLogisticsOrder order = new KwtLogisticsOrder();
+        order.setId(lOrderId);
+        order.setEntId(LoginUserHolder.getEntId());
+        order.setType(String.valueOf(NumberConstant.TWO));
+        order.setLOrderNo(lOrderNo);
+        order.setPids(lOrderId.toString());
+        order.setSettlementCycle(addOrderDTO.getSettlementCycle());
+        order.setBillingMode(addOrderDTO.getBillingMode());
+        order.setPrice(addOrderDTO.getPrice());
+        order.setPayment(addOrderDTO.getPayment());
+        order.setPriceType(addOrderDTO.getPriceType());
+        order.setAmount(addOrderDTO.getAmount());
+        order.setUnit(addOrderDTO.getAmountUnit());
+        order.setLoss(addOrderDTO.getLoss() == null ? null : addOrderDTO.getLoss());
+        order.setLossUnit(addOrderDTO.getLossUnit());
+        order.setGoodsPrice(addOrderDTO.getGoodsPrice() == null ? null : addOrderDTO.getGoodsPrice());
+        order.setGoodsPriceUnit(addOrderDTO.getGoodsPriceUnit());
+        order.setStartTime(org.apache.commons.lang3.StringUtils.isBlank(addOrderDTO.getStartTime()) ?
+                null : DateUtil.strToDate(StringTimeUtil.fillStart(addOrderDTO.getStartTime()), StringConstant.DEFAULT_DATE_PATTERN));
+        order.setEndTime(org.apache.commons.lang3.StringUtils.isBlank(addOrderDTO.getEndTime()) ?
+                null : DateUtil.strToDate(StringTimeUtil.fillStart(addOrderDTO.getEndTime()), StringConstant.DEFAULT_DATE_PATTERN));
+        BigDecimal decimal = new BigDecimal(NumberConstant.ZERO);
+        order.setSubcontractAmount(decimal);
+        order.setEntrustAmount(decimal);
+        order.setUnloadAmount(decimal);
+        order.setLoadAmount(decimal);
+        order.setIgnoreAmount(decimal);
+        order.setDeficitAmount(decimal);
+        order.setDeficitPrice(decimal);
+        order.setTaxRate(addOrderDTO.getTaxRate());
+        order.setRemark(addOrderDTO.getRemark());
+        order.setStatus(orderStatus);
+        order.setCreateBy(LoginUserHolder.getUserId());
+        order.setCreateTime(new Date());
+        order.setUpdateBy(LoginUserHolder.getUserId());
+        order.setUpdateTime(new Date());
+        kwtLogisticsOrderMapper.insert(order);
+    }
+
+    /**
+     * 托运订单-新建订单-地址信息保存
+     *
+     * @param addOrderDTO 页面请求参数
+     * @param lOrderId    主体id
+     */
+    private void saveConsignLogisticsOrderAddress(AddOrderDTO addOrderDTO, Long lOrderId) {
+        KwtLogisticsOrderAddress loadAddress = new KwtLogisticsOrderAddress();
+        loadAddress.setId(new IdWorker(NumberConstant.ONE).nextId());
+        loadAddress.setLOrderId(lOrderId);
+        loadAddress.setAddressType(NumberConstant.ONE);
+//        loadAddress.setName();
+//        loadAddress.setType();
+//        loadAddress.setContacts();
+//        loadAddress.setPhone();
+        loadAddress.setCityCode(addOrderDTO.getLoadCityCode());
+        loadAddress.setCityName(addOrderDTO.getLoadCityName());
+        loadAddress.setDetailAddress(addOrderDTO.getLoadDetailAddress());
+        loadAddress.setLat(addOrderDTO.getLoadLat());
+        loadAddress.setLng(addOrderDTO.getLoadLng());
+        loadAddress.setEntryType(NumberConstant.FOUR);
+        loadAddress.setStatus(NumberConstant.ZERO);
+        loadAddress.setCreateBy(LoginUserHolder.getUserId());
+        Date date = new Date();
+        loadAddress.setCreateTime(date);
+        loadAddress.setUpdateBy(LoginUserHolder.getUserId());
+        loadAddress.setUpdateTime(date);
+
+        KwtLogisticsOrderAddress unloadAddress = new KwtLogisticsOrderAddress();
+        unloadAddress.setId(new IdWorker(NumberConstant.TWO).nextId());
+        unloadAddress.setLOrderId(lOrderId);
+        unloadAddress.setAddressType(NumberConstant.TWO);
+//        unloadAddress.setName();
+//        unloadAddress.setType();
+//        unloadAddress.setContacts();
+//        unloadAddress.setPhone();
+        unloadAddress.setCityCode(addOrderDTO.getUnloadCityCode());
+        unloadAddress.setCityName(addOrderDTO.getUnloadCityName());
+        unloadAddress.setDetailAddress(addOrderDTO.getUnloadDetailAddress());
+        unloadAddress.setLat(addOrderDTO.getUnloadLat());
+        unloadAddress.setLng(addOrderDTO.getUnloadLng());
+        unloadAddress.setEntryType(NumberConstant.FOUR);
+        unloadAddress.setStatus(NumberConstant.ZERO);
+        unloadAddress.setCreateBy(LoginUserHolder.getUserId());
+        unloadAddress.setCreateTime(date);
+        unloadAddress.setUpdateBy(LoginUserHolder.getUserId());
+        unloadAddress.setUpdateTime(date);
+        kwtLogisticsOrderAddressMapper.insert(loadAddress);
+        kwtLogisticsOrderAddressMapper.insert(unloadAddress);
+    }
+
+    /**
+     * 托运订单-新建订单-合体主体
+     *
+     * @param addOrderDTO 页面请求参数
+     * @param lOrderId    主体id
+     * @param status      合同状态
+     */
+    private void saveConsignLogisticsOrderContract(AddOrderDTO addOrderDTO, Long lOrderId, Integer status) {
+        //托运
+        KwtLogisticsOrderContract consignContract = new KwtLogisticsOrderContract();
+        consignContract.setId(new IdWorker(NumberConstant.ONE).nextId());
+        consignContract.setContractId(Long.parseLong(addOrderDTO.getContractId()));
+        consignContract.setLOrderId(lOrderId);
+        consignContract.setStatus(status);
+        consignContract.setCreateBy(LoginUserHolder.getUserId());
+        consignContract.setCreateTime(new Date());
+        consignContract.setUpdateBy(LoginUserHolder.getUserId());
+        consignContract.setUpdateTime(new Date());
+        logisticsOrderContractMapper.insert(consignContract);
+    }
+
+    /**
+     * 托运订单-页面新增订单-订单状态
+     *
+     * @param lOrderId    主体id
+     * @param orderStatus 主体单据状态
+     */
+    private void saveConsignLogisticsOrderTrack(Long lOrderId, Integer orderStatus) {
+        KwtLogisticsOrderTrack track = new KwtLogisticsOrderTrack();
+        track.setId(new IdWorker(NumberConstant.ONE).nextId());
+        track.setLOrderId(lOrderId);
+        track.setStatus(orderStatus);
+        track.setCreateBy(LoginUserHolder.getUserId());
+        track.setCreateTime(new Date());
+        track.setUpdateBy(LoginUserHolder.getUserId());
+        track.setUpdateTime(new Date());
+        kwtLogisticsOrderTrackMapper.insert(track);
+    }
+
+    /**
+     * 托运订单-页面新增订单-订单对应企业单位
+     *
+     * @param addOrderDTO 页面请求参数
+     * @param lOrderId    主体id
+     */
+    private void saveConsignLogisticsOrderUnit(AddOrderDTO addOrderDTO, Long lOrderId) {
+        //托运
+        KwtLogisticsOrderUnit consignUnit = new KwtLogisticsOrderUnit();
+        consignUnit.setId(new IdWorker(NumberConstant.ONE).nextId());
+        consignUnit.setLOrderId(lOrderId);
+        consignUnit.setUnitType(NumberConstant.ONE);
+        consignUnit.setEntId(Long.parseLong(addOrderDTO.getConsignCompanyId()));
+        consignUnit.setFirmName(addOrderDTO.getConsignCompany());
+        consignUnit.setContacts(addOrderDTO.getConsignContacts());
+        consignUnit.setPhone(addOrderDTO.getConsignContactPhone());
+        consignUnit.setRemark(addOrderDTO.getRemark());
+        consignUnit.setStatus(NumberConstant.ZERO);
+        consignUnit.setCreateBy(LoginUserHolder.getUserId());
+        consignUnit.setCreateTime(new Date());
+        consignUnit.setUpdateBy(LoginUserHolder.getUserId());
+        consignUnit.setUpdateTime(new Date());
+        //承运
+        KwtLogisticsOrderUnit unit = new KwtLogisticsOrderUnit();
+        unit.setId(new IdWorker(NumberConstant.TWO).nextId());
+        unit.setLOrderId(lOrderId);
+        unit.setUnitType(NumberConstant.TWO);
+        unit.setEntId(Long.parseLong(addOrderDTO.getAcceptCompanyId()));
+        unit.setFirmName(addOrderDTO.getAcceptCompany());
+        unit.setContacts(addOrderDTO.getAcceptContacts());
+        unit.setPhone(addOrderDTO.getAcceptContactPhone());
+        unit.setRemark(addOrderDTO.getRemark());
+        unit.setStatus(NumberConstant.ZERO);
+        unit.setCreateBy(LoginUserHolder.getUserId());
+        unit.setCreateTime(new Date());
+        unit.setUpdateBy(LoginUserHolder.getUserId());
+        unit.setUpdateTime(new Date());
+        kwtLogisticsOrderUnitMapper.insert(consignUnit);
+        kwtLogisticsOrderUnitMapper.insert(unit);
+    }
+
+    /**
+     * 托运订单-新建订单-保存mongodb
+     *
+     * @param addOrderDTO 页面请求参数
+     * @param orderStatus 主体单据状态
+     * @param lOrderId    主体订单id
+     * @param lOrderNo    主体订单编号
+     * @param infoResDto  合同信息
+     * @param goods       商品信息
+     */
+    private void saveMongoDb(AddOrderDTO addOrderDTO, Integer orderStatus, Long lOrderId, String lOrderNo, ContractCommonInfoResDto infoResDto, KwpGoods goods) {
+        SckwLogisticsOrder order = new SckwLogisticsOrder();
+        order.set_id(lOrderId);
+        order.setLOrderId(lOrderId);
+        order.setLOrderNo(lOrderNo);
+        order.setLOrderPid(null);
+        order.setLOrderPids(String.valueOf(lOrderId));
+        order.setType(NumberConstant.TWO);
+        order.setSettlementCycle(addOrderDTO.getSettlementCycle());
+        order.setPrice(addOrderDTO.getPrice());
+        order.setPriceType(order.getPriceType());
+        order.setAmount(addOrderDTO.getAmount());
+        order.setUnit(addOrderDTO.getAmountUnit());
+        order.setLoss(addOrderDTO.getLoss());
+        order.setLossUnit(addOrderDTO.getLossUnit());
+        order.setGoodsPrice(addOrderDTO.getGoodsPrice() == null ? null : addOrderDTO.getGoodsPrice());
+        order.setGoodsPriceUnit(addOrderDTO.getGoodsPriceUnit());
+        BigDecimal decimal = new BigDecimal(NumberConstant.ZERO);
+        order.setSubcontractAmount(decimal);
+        order.setEntrustAmount(decimal);
+        order.setUnloadAmount(decimal);
+        order.setLoadAmount(decimal);
+        order.setIgnoreAmount(decimal);
+        order.setDeficitAmount(decimal);
+        order.setDeficitPrice(decimal);
+        order.setPayment(addOrderDTO.getPayment());
+        order.setTaxRate(addOrderDTO.getTaxRate());
+        order.setRemark(addOrderDTO.getRemark());
+        order.setStatus(String.valueOf(orderStatus));
+        order.setEntId(LoginUserHolder.getEntId());
+        order.setFirmName(LoginUserHolder.getEntName());
+        order.setGoodsId(Long.parseLong(addOrderDTO.getGoodsId()));
+        order.setGoodsCode(goods == null ? null : goods.getCode());
+        order.setGoodsName(goods == null ? null : goods.getName());
+        order.setGoodsType(goods == null ? null : goods.getGoodsType());
+//        order.setGoodsIndustry(goods == null ? null : goods.get);
+        order.setGoodsSpec(goods == null ? null : goods.getSpec());
+        order.setContractId(addOrderDTO.getContractId());
+        order.setContractNo(infoResDto.getContractCode());
+        order.setContractName(infoResDto.getContactName());
+        order.setContractSigningWay(String.valueOf(infoResDto.getSigningWay()));
+        order.setCheckEntId(Long.parseLong(addOrderDTO.getConsignCompanyId()));
+        order.setCheckFirmName(addOrderDTO.getConsignCompany());
+        order.setCheckContacts(addOrderDTO.getConsignContacts());
+        order.setCheckPhone(addOrderDTO.getConsignContactPhone());
+        order.setCarrierEntId(Long.parseLong(addOrderDTO.getAcceptCompanyId()));
+        order.setCarrierFirmName(addOrderDTO.getAcceptCompany());
+        order.setCarrierContacts(addOrderDTO.getAcceptContacts());
+        order.setCarrierPhone(addOrderDTO.getAcceptContactPhone());
+//        order.setLoadType();
+//        order.setLoadContacts();
+//        order.setLoadPhone();
+//        order.setLoadCityCode();
+//        order.setLoadCityName();
+//        order.setLoadDetailAddress();
+//        order.setLoadLat();
+//        order.setLoadLng();
+//        order.setUnloadType();
+//        order.setUnloadContacts();
+//        order.setUnloadPhone();
+//        order.setUnloadCityCode();
+//        order.setUnloadCityName();
+//        order.setUnloadDetailAddress();
+//        order.setUnloadLat();
+//        order.setUnloadLng();
+        order.setCreateBy(LoginUserHolder.getUserId());
+        order.setCreateByName(LoginUserHolder.getUserName());
+        order.setCreateTime(new Date());
+        order.setUpdateBy(LoginUserHolder.getUserId());
+        order.setUpdateByName(LoginUserHolder.getUserName());
+        order.setUpdateTime(new Date());
+        order.setWOrderNo(lOrderNo);
+        order.setCarryingCapacity(addOrderDTO.getAmount().longValue());
+        order.setBillingMode(addOrderDTO.getBillingMode());
+        SckwBusSum busSum = new SckwBusSum();
+        busSum.setBusSumType(BusinessTypeEnum.LOGISTICS_ORDER_TYPE.getName());
+        busSum.setMethod(NumberConstant.ONE);
+        busSum.setObject(order);
+        streamBridge.send("sckw-busSum", com.alibaba.fastjson2.JSON.toJSONString(busSum));
+    }
 }