Sfoglia il codice sorgente

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

donglang 1 giorno fa
parent
commit
91fbf406e0

+ 1 - 1
sckw-common/sckw-common-core/src/main/java/com/sckw/core/model/enums/ClientTypeEnum.java

@@ -50,7 +50,7 @@ public enum ClientTypeEnum {
     public static int expireTime(String clientType) {
         if (clientType.equals(pc.getValue())) {
             return Global.PC_TOKEN_EXPIRE;
-        } else if (clientType.equals(ios.getValue()) || clientType.equals(android.getValue())) {
+        } else if (clientType.equals(ios.getValue()) || clientType.equals(android.getValue()) || clientType.equals(app.getValue())) {
             return Global.APP_TOKEN_EXPIRE;
         } else {
             return Global.COMMON_EXPIRE;

+ 86 - 26
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/service/operateService/KwcContractTradeService.java

@@ -1654,19 +1654,7 @@ public class KwcContractTradeService {
             entIds.add(Long.valueOf(req.getSupplyEntId()));
             //type = CooperateTypeEnum.SUPPLIER.getCode();
         }
-        Set<Long> contractIds = null;
-        if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(entIds)) {
-            List<KwcContractTradeUnit> units = kwcContractTradeUnitRepository.queryByEntIds(entIds);
-            if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(units)) {
-                Set<Long> contractIdList = units.stream().filter(x -> Objects.equals(x.getEntId(), entId))
-                        .map(KwcContractTradeUnit::getContractId)
-                        .collect(Collectors.toSet());
-                contractIds = units.stream()
-                        .map(KwcContractTradeUnit::getContractId)
-                        .filter(contractIdList::contains)
-                        .collect(Collectors.toSet());
-            }
-        }
+        Set<Long> contractIds = buildTradeQueryContractIds(entId, req, entIds);
         if (org.apache.commons.collections4.CollectionUtils.isEmpty(contractIds)) {
             return Collections.emptyList();
         }
@@ -1808,6 +1796,90 @@ public class KwcContractTradeService {
                 .collect(Collectors.toList());
     }
 
+
+    /**
+     * 构建贸易合同查询的合同ID集合。
+     * <p>
+     * 根据当前登录企业ID、采购方企业ID、供应方企业ID等条件,从合同关联单位表中筛选出符合条件的合同ID。
+     * 主要用于分页查询和总数统计时的数据过滤。
+     * </p>
+     *
+     * @param entId  当前登录的企业ID
+     * @param req    查询请求参数,包含采购方ID、供应方ID等过滤条件
+     * @param entIds 参与查询的所有相关企业ID集合(包括当前企业、指定的采购/供应企业等)
+     * @return 符合条件的合同ID集合,若无匹配则返回空集合
+     */
+    private Set<Long> buildTradeQueryContractIds(Long entId, QueryTradeReq req, Set<Long> entIds) {
+        // 1. 基础参数校验:如果当前企业ID为空或关联企业ID集合为空,直接返回空集合
+        if (Objects.isNull(entId) || org.apache.commons.collections4.CollectionUtils.isEmpty(entIds)) {
+            log.debug("构建贸易合同查询ID失败:entId为空或entIds集合为空, entId: {}", entId);
+            return Collections.emptySet();
+        }
+
+        // 2. 查询这些企业关联的所有合同单位信息
+        List<KwcContractTradeUnit> units = kwcContractTradeUnitRepository.queryByEntIds(entIds);
+        if (org.apache.commons.collections4.CollectionUtils.isEmpty(units)) {
+            log.debug("构建贸易合同查询ID失败:未查询到任何合同单位信息, entIds: {}", entIds);
+            return Collections.emptySet();
+        }
+        log.debug("查询到合同单位数量: {}, entIds: {}", units.size(), entIds);
+
+        // 3. 初步筛选:获取当前登录企业(entId)参与的所有合同ID
+        Set<Long> contractIds = units.stream()
+                .filter(unit -> Objects.equals(unit.getEntId(), entId))
+                .map(KwcContractTradeUnit::getContractId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+
+        if (org.apache.commons.collections4.CollectionUtils.isEmpty(contractIds)) {
+            log.debug("构建贸易合同查询ID失败:当前企业[{}]未参与任何合同", entId);
+            return Collections.emptySet();
+        }
+        log.debug("当前企业[{}]参与的初始合同ID数量: {}", entId, contractIds.size());
+
+        // 4. 如果指定了采购方企业ID,则取交集:只保留该采购方作为“采购角色”参与的合同
+        if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getPurchaseEntId())) {
+            Long purchaseEntId = Long.valueOf(req.getPurchaseEntId());
+            log.debug("应用采购方过滤条件: purchaseEntId = {}", purchaseEntId);
+            
+            Set<Long> purchaseContractIds = units.stream()
+                    .filter(unit -> Objects.equals(unit.getEntId(), purchaseEntId))
+                    // 必须明确 unitType 为 PURCHASER (采购方)
+                    .filter(unit -> Objects.equals(unit.getUnitType(), CooperateTypeEnum.PURCHASER.getCode()))
+                    .map(KwcContractTradeUnit::getContractId)
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toSet());
+            
+            // 取交集:合同必须同时出现在当前企业的合同列表 和 指定采购方的合同列表中
+            int beforeSize = contractIds.size();
+            contractIds.retainAll(purchaseContractIds);
+            log.debug("采购方过滤后剩余合同数量: {} (原数量: {})", contractIds.size(), beforeSize);
+        }
+
+        // 5. 如果指定了供应方企业ID,则取交集:只保留该供应方作为“供应角色”参与的合同
+        if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getSupplyEntId())) {
+            Long supplyEntId = Long.valueOf(req.getSupplyEntId());
+            log.debug("应用供应方过滤条件: supplyEntId = {}", supplyEntId);
+
+            Set<Long> supplyContractIds = units.stream()
+                    .filter(unit -> Objects.equals(unit.getEntId(), supplyEntId))
+                    // 必须明确 unitType 为 SUPPLIER (供应方)
+                    .filter(unit -> Objects.equals(unit.getUnitType(), CooperateTypeEnum.SUPPLIER.getCode()))
+                    .map(KwcContractTradeUnit::getContractId)
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toSet());
+            
+            // 取交集
+            int beforeSize = contractIds.size();
+            contractIds.retainAll(supplyContractIds);
+            log.debug("供应方过滤后剩余合同数量: {} (原数量: {})", contractIds.size(), beforeSize);
+        }
+
+        log.info("最终构建的合同ID集合大小: {}, entId: {}, purchaseEntId: {}, supplyEntId: {}", 
+                contractIds.size(), entId, req.getPurchaseEntId(), req.getSupplyEntId());
+        return contractIds;
+    }
+
     private long countQueryTradeListByPage(QueryTradeReq req) {
         Long entId;
         if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getEntId())) {
@@ -1823,19 +1895,7 @@ public class KwcContractTradeService {
         if (org.apache.commons.lang3.StringUtils.isNotBlank(req.getSupplyEntId())) {
             entIds.add(Long.valueOf(req.getSupplyEntId()));
         }
-        Set<Long> contractIds = null;
-        if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(entIds)) {
-            List<KwcContractTradeUnit> units = kwcContractTradeUnitRepository.queryByEntIds(entIds);
-            if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(units)) {
-                Set<Long> contractIdList = units.stream().filter(x -> Objects.equals(x.getEntId(), entId))
-                        .map(KwcContractTradeUnit::getContractId)
-                        .collect(Collectors.toSet());
-                contractIds = units.stream()
-                        .map(KwcContractTradeUnit::getContractId)
-                        .filter(contractIdList::contains)
-                        .collect(Collectors.toSet());
-            }
-        }
+        Set<Long> contractIds = buildTradeQueryContractIds(entId, req, entIds);
         if (org.apache.commons.collections4.CollectionUtils.isEmpty(contractIds)) {
             return 0L;
         }