Эх сурвалжийг харах

提交630第二阶段商品功能

chenxiaofei 1 долоо хоног өмнө
parent
commit
a994cbf913

+ 9 - 0
sckw-modules-api/sckw-contract-api/src/main/java/com/sckw/contract/api/RemoteContractService.java

@@ -89,6 +89,15 @@ public interface RemoteContractService {
 
     List<Long> queryNewSignGoods(Long entId, LocalDateTime time);
 
+    /**
+     * 查询当前企业作为采购方或销售方时,已签约且有效的贸易合同商品ID集合。
+     *
+     * @param entId 当前企业ID
+     * @param time  当前时间
+     * @return 商品ID集合
+     */
+    List<Long> queryNewSignGoodsByEnt(Long entId, LocalDateTime time);
+
     /**
      * 查询签约的商品
      *

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

@@ -424,6 +424,93 @@ public class RemoteContractServiceImpl implements RemoteContractService {
         return kwcContractTradeMapper.queryNewSignGoods(entId, time);
     }
 
+
+    /**
+     * 查询指定企业在给定时间点已签约且有效的贸易合同关联的商品ID列表。
+     * <p>
+     * 业务逻辑:
+     * 1. 参数校验:确保 entId 和 time 不为空。
+     * 2. 查找关联合同:查询该企业(作为供应商 SUPPLIER 或采购商 PURCHASER)参与的所有未删除的贸易合同单元,获取合同ID列表。
+     * 3. 筛选有效合同:在上述合同ID列表中,筛选出满足以下条件的合同:
+     *    - 未删除 (delFlag = 0)
+     *    - 状态为已签约 (status = SIGNED)
+     *    - 指定时间在合同有效期内 (startTime <= time < endTime 或 endTime 为空表示长期有效)
+     * 4. 提取商品ID:根据筛选出的有效合同ID,查询对应的合同商品记录,提取所有未删除的商品ID并去重。
+     *
+     * @param entId 企业ID
+     * @param time  查询时间点
+     * @return 商品ID列表,若无匹配数据则返回空列表
+     */
+    @Override
+    public List<Long> queryNewSignGoodsByEnt(Long entId, LocalDateTime time) {
+        // 1. 参数校验
+        if (Objects.isNull(entId) || Objects.isNull(time)) {
+            log.warn("查询企业已签约商品参数异常,entId:{},time:{}", entId, time);
+            return Collections.emptyList();
+        }
+
+        log.debug("开始查询企业[{}]在时间[{}]的已签约商品列表", entId, time);
+
+        // 将 LocalDateTime 转换为 Date 用于数据库查询
+        Date queryTime = Date.from(time.atZone(ZoneId.systemDefault()).toInstant());
+
+        // 2. 查找该企业参与的所有贸易合同ID
+        // 条件:未删除、企业ID匹配、单位类型为供应商或采购商
+        List<Long> contractIdsByEnt = kwcContractTradeUnitMapper.selectList(new LambdaQueryWrapper<KwcContractTradeUnit>()
+                        .eq(KwcContractTradeUnit::getDelFlag, Global.NO)
+                        .eq(KwcContractTradeUnit::getEntId, entId)
+                        .in(KwcContractTradeUnit::getUnitType, List.of(CooperateTypeEnum.SUPPLIER.getCode(), CooperateTypeEnum.PURCHASER.getCode())))
+                .stream()
+                .map(KwcContractTradeUnit::getContractId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .toList();
+
+        if (CollectionUtils.isEmpty(contractIdsByEnt)) {
+            log.debug("企业[{}]未找到任何关联的贸易合同单元", entId);
+            return Collections.emptyList();
+        }
+        log.debug("企业[{}]关联的合同ID数量: {}", entId, contractIdsByEnt.size());
+
+        // 3. 筛选在指定时间点有效的已签约合同
+        // 条件:
+        // - 未删除
+        // - 状态为已签约
+        // - 合同ID在之前筛选出的集合中
+        // - 合同开始时间 <= 查询时间
+        // - 合同结束时间 > 查询时间 或 结束时间为空(表示长期有效)
+        List<Long> validContractIds = kwcContractTradeMapper.selectList(new LambdaQueryWrapper<KwcContractTrade>()
+                        .eq(KwcContractTrade::getDelFlag, Global.NO)
+                        .eq(KwcContractTrade::getStatus, ContractStatusEnum.SIGNED.getCode())
+                        .in(KwcContractTrade::getId, contractIdsByEnt)
+                        .lt(KwcContractTrade::getStartTime, queryTime)
+                        .and(wrapper -> wrapper.gt(KwcContractTrade::getEndTime, queryTime).or().isNull(KwcContractTrade::getEndTime)))
+                .stream()
+                .map(KwcContractTrade::getId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .toList();
+
+        if (CollectionUtils.isEmpty(validContractIds)) {
+            log.debug("企业[{}]在时间[{}]没有有效的已签约合同", entId, time);
+            return Collections.emptyList();
+        }
+        log.info("企业[{}]在时间[{}]找到{}个有效的已签约合同", entId, time, validContractIds.size());
+
+        // 4. 根据有效合同ID查询关联的商品ID
+        List<Long> goodsIds = kwcContractTradeGoodsMapper.selectList(new LambdaQueryWrapper<KwcContractTradeGoods>()
+                        .eq(KwcContractTradeGoods::getDelFlag, Global.NO)
+                        .in(KwcContractTradeGoods::getContractId, validContractIds))
+                .stream()
+                .map(KwcContractTradeGoods::getGoodsId)
+                .filter(Objects::nonNull)
+                .distinct()
+                .toList();
+
+        log.debug("查询成功,企业[{}]在时间[{}]关联的商品ID数量: {}", entId, time, goodsIds.size());
+        return goodsIds;
+    }
+
     @Override
     public List<Long> querySignTradeContract(Long entId, LocalDateTime time) {
         return kwcContractTradeMapper.querySignTradeContract(entId, time);

+ 3 - 1
sckw-modules/sckw-product/src/main/java/com/sckw/product/service/KwpGoodsService.java

@@ -1091,7 +1091,7 @@ public class KwpGoodsService {
         Long entId = LoginUserHolder.getEntId();
         if (Objects.nonNull(entId)) {
             if (Objects.nonNull(params.getSign())) {//查询签约或未签约商品
-                List<Long> longs = remoteContractService.queryNewSignGoods(entId, LocalDateTime.now());
+                List<Long> longs = remoteContractService.queryNewSignGoodsByEnt(entId, LocalDateTime.now());
                 if (Objects.equals(params.getSign(), 1)) {
                     if (CollUtil.isNotEmpty(longs)) {
                         wrapper.in(KwpGoods::getId, longs);
@@ -1147,11 +1147,13 @@ public class KwpGoodsService {
             List<KwpGoodsPriceRange> priceRanges = priceRangeMap.get(e.getId());
             materials.setGoodsTypeLabel(CollectionUtils.isNotEmpty(productNameMap) ? productNameMap.get(e.getGoodsType()) : null).setUnitLabel(CollectionUtils.isNotEmpty(unitMap) ? unitMap.get(e.getUnit()) : null).setSpec(CollectionUtils.isNotEmpty(specMap) ? specMap.get(e.getSpec()) : null).setAddressName(Objects.isNull(address) ? null : address.getCityName()).setDetailAddress(Objects.isNull(address) ? null : address.getDetailAddress()).setPrice(CollectionUtils.isEmpty(priceRanges) ? null : priceRanges.get(0).getPrice()).setThumb(FileUtils.splice(e.getThumb())).setSupplyEnt(entMap.get(e.getSupplyEntId()));
             materials.setSignFlag(false);
+            materials.setShowOrderButtonFlag(false);
             if (Objects.nonNull(entId)) {
                 TradeContractGoodsDto tradeContractResDto = remoteContractService.queryTradeContractNewByEnt(entId, e.getId(), LocalDateTime.now());
                 if (Objects.nonNull(tradeContractResDto)) {
                     materials.setSignPrice(tradeContractResDto.getPrice());
                     materials.setSignFlag(true);
+                    materials.setShowOrderButtonFlag(true);
                 }
             }
             result.add(materials);