Parcourir la source

订单合同新增接口

chenxiaofei il y a 2 mois
Parent
commit
fb46dab440

+ 10 - 0
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/controller/KwcLogisticsContractController.java

@@ -1,7 +1,9 @@
 package com.sckw.contract.controller;
 
+import com.sckw.contract.model.vo.req.ContractDetailReq;
 import com.sckw.contract.model.vo.req.LogisticListReq;
 import com.sckw.contract.model.vo.req.QueryLogisticListReq;
+import com.sckw.contract.model.vo.res.QueryLogisticDetailResp;
 import com.sckw.contract.model.vo.res.QueryLogisticListResp;
 import com.sckw.contract.service.operateService.KwcContractLogisticsService;
 import com.sckw.core.web.response.BaseResult;
@@ -42,4 +44,12 @@ public class KwcLogisticsContractController {
     public BaseResult<Boolean> addOrUpdateLogisticsContract(@RequestBody LogisticListReq req) {
         return BaseResult.success(kwcContractLogisticsService.addOrUpdateLogisticsContract(req));
     }
+
+    /**
+     * 查询物流合同明细
+     */
+    @PostMapping("/queryLogisticsContractDetail")
+    public BaseResult<QueryLogisticDetailResp> queryLogisticsContractDetail(@RequestBody ContractDetailReq req) {
+       return BaseResult.success(kwcContractLogisticsService.queryLogisticsContractDetail(req)) ;
+    }
 }

+ 5 - 0
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/model/entity/KwcContractLogistics.java

@@ -132,5 +132,10 @@ public class KwcContractLogistics implements Serializable {
      * 业务id
      */
     private String businessId;
+    /**
+     * 通用价格
+     */
+    @TableField("common_price")
+    private BigDecimal commonPrice;
 
 }

+ 4 - 0
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/model/vo/req/ContractDetailReq.java

@@ -24,4 +24,8 @@ public class ContractDetailReq implements Serializable {
     @Schema(description = "合同编号")
     @NotBlank(message = "合同编号不能为空")
     private String contractCode;
+    /**
+     * 物流合同id
+     */
+    private Long contractId;
 }

+ 207 - 0
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/model/vo/res/QueryLogisticDetailResp.java

@@ -0,0 +1,207 @@
+package com.sckw.contract.model.vo.res;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.Digits;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Size;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author :chenXiaoFei
+ * @version :1.0
+ * @description : 物流合同明细返回参数
+ * @create :2025-11-06 18:30:00
+ */
+@Data
+public class QueryLogisticDetailResp implements Serializable {
+    @Serial
+    private static final long serialVersionUID = -1122401200820144338L;
+    /**
+     * 合同id 修改时必传
+     */
+    @Schema(description = "合同id")
+    private Long id;
+
+    /**
+     * 父合同ID 补充合同
+     */
+    @Schema(description = "父合同ID")
+    @NotNull(message = "父合同ID不能为空")
+    private Long pid;
+
+    /**
+     * 基础信息
+     */
+    @Schema(description = "基础信息")
+    @NotNull(message = "基础信息不能为空")
+    private TradeBaseInfo baseInfo;
+
+    /**
+     * 合同文件
+     */
+    @Schema(description = "合同文件")
+    @NotBlank(message = "合同文件不能为空")
+    private String contractFile;
+
+    /**
+     * 标的信息
+     */
+    @Schema(description = "标的信息")
+    @NotNull(message = "标的信息不能为空")
+    private List<TradeGoodsInfo> goodsInfo;
+
+    /**
+     * 备注
+     */
+    @Schema(description = "备注")
+    private String remark;
+    @Data
+    public static class TradeBaseInfo implements Serializable{
+
+        @Serial
+        private static final long serialVersionUID = -5828478625710244673L;
+
+        /**
+         * 采购单位id
+         */
+        @Schema(description = "采购单位id")
+        @NotNull(message = "采购单位不能为空")
+        private Long purchaseEntId;
+
+        /**
+         * 采购单位联系电话
+         */
+        @Schema(description = "采购单位联系电话")
+        @NotBlank(message = "采购单位联系电话不能为空")
+        private String purchasePhone;
+
+        /**
+         * 供应单位id
+         */
+        @NotNull(message = "供应单位不能为空")
+        @Schema(description = "供应单位id")
+        private Long provideEntId;
+
+        /**
+         * 供应单位联系电话
+         */
+        @Schema(description = "供应单位联系电话")
+        @NotBlank(message = "供应单位联系电话不能为空")
+        private String providePhone;
+
+        /**
+         * 合同编号
+         */
+        @Schema(description = "合同编号")
+        @NotBlank(message = "合同编号不能为空")
+        @Size(max = 20, message = "合同编号超长")
+        private String contractCode;
+
+        /**
+         * 合同名称
+         */
+        @Schema(description = "合同名称")
+        @NotBlank(message = "合同名称不能为空")
+        @Size(max = 50, message = "合同名称超长")
+        private String contractName;
+
+        /**
+         * 终止时间
+         */
+        @DateTimeFormat(pattern = "yyyy-MM-dd")
+        @JsonFormat(pattern="yyyy-MM-dd", timezone = "GMT+8")
+        @Schema(description = "终止时间")
+        private Date endTime;
+
+        /**
+         * 签约方式(1线上签约、2线下签约)
+         */
+        @NotNull(message = "签约方式不能为空")
+        @Schema(description = "签约方式")
+        private Integer signingWay;
+        /**
+         * 签约方式描述
+         */
+        @Schema(description = "签约方式描述")
+        private String signingWayDesc;
+
+        /**
+         * 生效时间
+         */
+        @NotNull(message = "生效时间不能为空")
+        @DateTimeFormat(pattern = "yyyy-MM-dd")
+        @JsonFormat(pattern="yyyy-MM-dd", timezone = "GMT+8")
+        @Schema(description = "生效时间")
+        private Date startTime;
+        /**
+         * 通用价格
+         */
+        @Schema(description = "通用价格")
+        private BigDecimal commonPrice;
+
+
+
+    }
+    @Data
+    public static class TradeGoodsInfo implements Serializable{
+        @Serial
+        private static final long serialVersionUID = -7003603561892852639L;
+
+        /**
+         * 商品id
+         */
+        @NotNull(message = "商品不能为空")
+        @Schema(description = "商品id")
+        private Long goodsId;
+        /**
+         * 商品名称
+         */
+        @Schema(description = "商品名称")
+        private String goodsName;
+
+        /**
+         * 采购数量
+         */
+        @Schema(description = "采购数量")
+        @Digits(integer = 10, fraction = 2, message = "采购数量超长")
+        private BigDecimal amount;
+        /**
+         * 数量单位
+         */
+        private String amountUnit;
+
+        /**
+         * 单价
+         */
+        @Schema(description = "单价")
+        @Digits(integer = 10, fraction = 2, message = "单价超长")
+        private BigDecimal price;
+
+        /**
+         * 单位
+         */
+        @Schema(description = "价格单位")
+        private String unit;
+        /**
+         * 生效时间
+         */
+        @Schema(description = "生效开始时间")
+        @NotBlank(message = "生效时间不能为空")
+        private Date effectiveStartTime;
+        /**
+         * 生效时间
+         */
+        @Schema(description = "生效结束时间")
+        @NotBlank(message = "生效时间不能为空")
+        private Date effectiveEntTime;
+    }
+}

+ 2 - 2
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/repository/KwcContractLogisticsGoodsRepository.java

@@ -25,10 +25,10 @@ public class KwcContractLogisticsGoodsRepository extends ServiceImpl<KwcContract
                 .eq(KwcContractLogisticsGoods::getContractId,contractId));
     }
 
-    public List<KwcContractLogisticsGoods> queryByContractIds(Set<Long> entIds) {
+    public List<KwcContractLogisticsGoods> queryByContractIds(Set<Long> contractIds) {
         return list(Wrappers.<KwcContractLogisticsGoods>lambdaQuery()
                 .eq(KwcContractLogisticsGoods::getDelFlag,0)
-                .in(CollectionUtils.isNotEmpty(entIds),KwcContractLogisticsGoods::getContractId,entIds));
+                .in(CollectionUtils.isNotEmpty(contractIds),KwcContractLogisticsGoods::getContractId,contractIds));
     }
 
     @Transactional(rollbackFor = Exception.class)

+ 109 - 5
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/service/operateService/KwcContractLogisticsService.java

@@ -59,6 +59,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.function.Function;
 import java.util.stream.Collectors;
@@ -1078,7 +1079,7 @@ public class KwcContractLogisticsService {
                 .map(KwcContractLogistics::getId)
                 .collect(Collectors.toSet());
         //查询物流商品信息
-        List<KwcContractLogisticsGoods> kwcContractLogisticsGoods =kwcContractLogisticsGoodsRepository.queryByContractIds(entIds);
+        List<KwcContractLogisticsGoods> kwcContractLogisticsGoods =kwcContractLogisticsGoodsRepository.queryByContractIds(contractIds);
         Map<Long, List<KwcContractLogisticsGoods>> contractIdAndGoodsMap = Maps.newHashMap();
         if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(kwcContractLogisticsGoods)){
             //按照合同id进行分组
@@ -1195,6 +1196,8 @@ public class KwcContractLogisticsService {
         saveContractLogistics.setCreateTime(date);
         saveContractLogistics.setUpdateBy(LoginUserHolder.getUserId());
         saveContractLogistics.setUpdateTime(date);
+        saveContractLogistics.setCommonPrice(baseInfo.getCommonPrice());
+        saveContractLogistics.setSigningUrl(changeFile(req.getContractFile()));
         kwcContractLogisticsRepository.saveOrUpdateLogistics(saveContractLogistics);
 
         //保存交易商品信息
@@ -1216,19 +1219,32 @@ public class KwcContractLogisticsService {
 
         return Boolean.TRUE;
     }
-
+    private String changeFile(String contractFile) {
+        if (StringUtils.isNotBlank(contractFile)) {
+            JSONArray jsonArray = JSONArray.parseArray(contractFile);
+            for (int n = 0; n < jsonArray.size(); n++) {
+                JSONObject jsonObject = jsonArray.getJSONObject(n);
+                String url = jsonObject.getString("url");
+                jsonObject.put("url", FileUtils.replaceAll(url));
+            }
+            return JSON.toJSONString(jsonArray);
+        }
+        return null;
+    }
     private void saveLogisticsGoods(LogisticListReq req, long contactId) {
         //删除商品
         kwcContractLogisticsGoodsRepository.deleteByContractId(contactId);
+        LogisticListReq.TradeBaseInfo baseInfo = req.getBaseInfo();
         List<LogisticListReq.TradeGoodsInfo> goodsInfos = req.getGoodsInfo();
         List<KwcContractLogisticsGoods> goods = goodsInfos.stream()
-                .map(x -> getKwcContractLogisticsGoods(x, contactId))
+                .map(x -> getKwcContractLogisticsGoods(x, contactId,baseInfo))
                 .collect(Collectors.toList());
         kwcContractLogisticsGoodsRepository.saveLogisticsGoods(goods);
     }
 
     @NotNull
-    private static KwcContractLogisticsGoods getKwcContractLogisticsGoods(LogisticListReq.TradeGoodsInfo x, long contactId) {
+    private static KwcContractLogisticsGoods getKwcContractLogisticsGoods(LogisticListReq.TradeGoodsInfo x,
+                                                                          long contactId,LogisticListReq.TradeBaseInfo baseInfo) {
         KwcContractLogisticsGoods logisticsGoods = new KwcContractLogisticsGoods();
         Date date1 = new Date();
         logisticsGoods.setId(x.getGoodsId());
@@ -1238,7 +1254,12 @@ public class KwcContractLogisticsService {
         logisticsGoods.setSkuId(0L);
         logisticsGoods.setAmount(x.getAmount());
         logisticsGoods.setUnit(x.getUnit());
-        logisticsGoods.setPrice(x.getPrice());
+        if (Objects.isNull(x.getPrice())) {
+            logisticsGoods.setPrice(Objects.nonNull(baseInfo.getCommonPrice())? baseInfo.getCommonPrice().setScale(2,
+                    RoundingMode.HALF_UP) : null);
+        }else {
+            logisticsGoods.setPrice(x.getPrice());
+        }
         logisticsGoods.setPriceUnit(x.getAmountUnit());
         logisticsGoods.setCreateBy(LoginUserHolder.getUserId());
         logisticsGoods.setCreateTime(date1);
@@ -1287,4 +1308,87 @@ public class KwcContractLogisticsService {
         kwcContractTradeUnit.setDelFlag(Global.NO);
         units.add(kwcContractTradeUnit);
     }
+
+    public QueryLogisticDetailResp queryLogisticsContractDetail(ContractDetailReq req) {
+        log.info("查询物流合同明细参数:{}", JSON.toJSONString( req));
+        if (Objects.isNull(req.getContractId())){
+            throw new BusinessException("物流合同id不能为空");
+        }
+        KwcContractLogistics logistics = kwcContractLogisticsRepository.queryById(req.getContractId());
+        if (Objects.isNull(logistics)){
+            throw new BusinessException("物流合同不存在");
+        }
+
+        //合同id
+        Long contractId = logistics.getId();
+
+        //查询物流商品信息
+        List<KwcContractLogisticsGoods> kwcContractLogisticsGoods =kwcContractLogisticsGoodsRepository.queryByContractId(contractId);
+
+
+        List<KwcContractLogisticsUnit> kwcContractLogisticsUnits =
+                kwcContractLogisticsUnitRepository.queryByContractId(contractId);
+        Map<String, KwcContractLogisticsUnit> contractUniTypeAndUnitMap = Maps.newHashMap();
+        if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(kwcContractLogisticsUnits)){
+            //合同id和单位类型组合成key映射物流企业信息
+            contractUniTypeAndUnitMap = kwcContractLogisticsUnits.stream()
+                    .peek(k -> k.setContractIdUnitTypeKey(k.getContractId() + "-" + k.getUnitType()))
+                    .collect(Collectors.toMap(KwcContractLogisticsUnit::getContractIdUnitTypeKey, Function.identity(),
+                            (x, y) -> x));
+        }
+
+        return getQueryLogisticDetailResp(logistics, contractUniTypeAndUnitMap, kwcContractLogisticsGoods);
+
+    }
+
+    @NotNull
+    private static QueryLogisticDetailResp getQueryLogisticDetailResp(KwcContractLogistics logistics, Map<String, KwcContractLogisticsUnit> contractUniTypeAndUnitMap, List<KwcContractLogisticsGoods> kwcContractLogisticsGoods) {
+        QueryLogisticDetailResp queryLogisticListResp = new QueryLogisticDetailResp();
+        queryLogisticListResp.setId(logistics.getId());
+        queryLogisticListResp.setPid(logistics.getContractPid());
+        QueryLogisticDetailResp.TradeBaseInfo tradeBaseInfo = new QueryLogisticDetailResp.TradeBaseInfo();
+        KwcContractLogisticsUnit logisticsUnit = contractUniTypeAndUnitMap.get(logistics.getId() + "-" + CooperateTypeEnum.PURCHASER.getCode());
+        if (Objects.nonNull(logisticsUnit)){
+            tradeBaseInfo.setPurchaseEntId(logisticsUnit.getEntId());
+            tradeBaseInfo.setPurchasePhone(logisticsUnit.getPhone());
+        }
+        KwcContractLogisticsUnit providerLogisticsUnit =
+                contractUniTypeAndUnitMap.get(logistics.getId() + "-" + CooperateTypeEnum.PURCHASER.getCode());
+        if (Objects.nonNull(providerLogisticsUnit)){
+            tradeBaseInfo.setProvideEntId(providerLogisticsUnit.getEntId());
+            tradeBaseInfo.setProvidePhone(providerLogisticsUnit.getPhone());
+        }
+
+        tradeBaseInfo.setContractCode(logistics.getContractNo());
+        tradeBaseInfo.setContractName(logistics.getName());
+        tradeBaseInfo.setEndTime(logistics.getEndTime());
+        tradeBaseInfo.setSigningWay(logistics.getSigningWay());
+        tradeBaseInfo.setSigningWayDesc(DictEnum.getLabel(DictTypeEnum.SIGNING_TYPE.getType(),
+                String.valueOf(logistics.getSigningWay())));
+        tradeBaseInfo.setStartTime(logistics.getStartTime());
+        tradeBaseInfo.setCommonPrice(logistics.getCommonPrice());
+
+        queryLogisticListResp.setBaseInfo(tradeBaseInfo);
+        queryLogisticListResp.setContractFile(logistics.getSigningUrl());
+        List<QueryLogisticDetailResp.TradeGoodsInfo> tradeGoodsInfos = Lists.newArrayList();
+        if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(kwcContractLogisticsGoods)){
+            tradeGoodsInfos = kwcContractLogisticsGoods.stream()
+                    .map(KwcContractLogisticsService::getTradeGoodsInfo)
+                    .collect(Collectors.toList());
+        }
+
+        queryLogisticListResp.setGoodsInfo(tradeGoodsInfos);
+        queryLogisticListResp.setRemark(logistics.getRemark());
+        return queryLogisticListResp;
+    }
+
+    private static QueryLogisticDetailResp.TradeGoodsInfo getTradeGoodsInfo(KwcContractLogisticsGoods x) {
+        QueryLogisticDetailResp.TradeGoodsInfo tradeGoodsInfo = new QueryLogisticDetailResp.TradeGoodsInfo();
+        tradeGoodsInfo.setGoodsId(x.getGoodsId());
+        tradeGoodsInfo.setGoodsName(x.getGoodsName());
+        tradeGoodsInfo.setAmount(x.getAmount());
+        tradeGoodsInfo.setAmountUnit(x.getUnit());
+        tradeGoodsInfo.setPrice(x.getPrice());
+        return tradeGoodsInfo;
+    }
 }

+ 1 - 0
sql/2025/11/30/2025_11_30_cxf_alert.sql

@@ -23,3 +23,4 @@ ALTER TABLE kwc_contract_trade_order ADD unload_address  varchar(255) NOT NULL d
 
 ALTER TABLE kwc_contract_logistics_goods ADD price decimal(10, 2)  NOT NULL default '0'  comment '运输单价';
 
+ALTER TABLE kwc_contract_logistics_goods ADD common_price decimal(10, 2)  NOT NULL default '0'  comment '通用价格';