From c5dee14a0f46cb530e2e12c504f33f396d4d58fe Mon Sep 17 00:00:00 2001 From: aike <17730485278@139.com> Date: Thu, 15 May 2025 14:29:01 +0800 Subject: [PATCH] =?UTF-8?q?demand:=20=E6=BC=8F=E7=BB=84=E6=89=B9=E6=AC=A1?= =?UTF-8?q?=E3=80=81=E4=BE=9B=E5=BA=94=E5=95=86=E7=BA=BF=E8=B7=AF=E8=A7=84?= =?UTF-8?q?=E5=88=92=E7=9B=B8=E5=85=B3=E9=9C=80=E6=B1=82=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E3=80=82=E4=BE=9B=E5=BA=94=E5=95=86=E7=BA=BF?= =?UTF-8?q?=E8=B7=AF=E8=A7=84=E5=88=92=E6=96=B0=E5=A2=9E=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20committer:=20heyu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/emis/EmisTransPlanRuleController.java | 14 +- .../erp/emis/domain/EmisTmsSiteBatchMiss.java | 4 +- .../xdadan/erp/emis/domain/EmisTransLine.java | 2 + .../erp/emis/domain/EmisTransPlanRule.java | 29 +- .../domain/enumtype/EmisBizErrorType.java | 1 + .../emis/mapper/EmisTransPlanRuleMapper.java | 62 ++- .../erp/emis/service/EmisBaseService.java | 140 +++++ .../service/IEmisTransPlanRuleService.java | 20 +- .../impl/EmisTmsSiteBatchMissServiceImpl.java | 276 ++-------- .../impl/EmisTransPlanRuleServiceImpl.java | 503 ++++++------------ .../mapper/EmisTmsSiteBatchMapper.xml | 2 +- .../mapper/EmisTmsSiteBatchMissMapper.xml | 8 +- .../resources/mapper/EmisTransLineMapper.xml | 11 +- .../mapper/EmisTransPlanRuleMapper.xml | 141 +++-- .../resources/mapper/EmisWaybillMapper.xml | 2 +- 15 files changed, 519 insertions(+), 696 deletions(-) diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTransPlanRuleController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTransPlanRuleController.java index d8ce6a50f..a92dab6ab 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTransPlanRuleController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisTransPlanRuleController.java @@ -2,6 +2,7 @@ package com.xdadan.erp.web.emis; import java.util.List; +import com.alibaba.excel.support.ExcelTypeEnum; import com.xdadan.erp.common.annotation.filter.jackson.JacksonFilter; import com.xdadan.erp.common.core.domain.AjaxResult; import com.xdadan.erp.common.core.page.TableDataInfo; @@ -71,6 +72,15 @@ public class EmisTransPlanRuleController extends EmisBaseController { return toAjax(emisTransPlanRuleService.insertEmisTransPlanRule(emisTransPlanRule)); } + /** + * Excel草稿方式新增 + */ + @PreAuthorize("@ss.hasPermi('emis:emisTransPlanRule:draftSubmitRule')") + @PostMapping(value = "/draftSubmitRule") + public AjaxResult draftSubmitRule(@RequestBody EmisTransPlanRule emisTransPlanRule) throws EmisBizError { + return toAjax(emisTransPlanRuleService.draftSubmitRule(emisTransPlanRule)); + } + /** * 修改供应商线路规划 */ @@ -94,7 +104,7 @@ public class EmisTransPlanRuleController extends EmisBaseController { */ @PreAuthorize("@ss.hasPermi('emis:emisTransPlanRule:tree')") @GetMapping("/tree") - public TableDataInfo tree(String lineCode) { - return getDataTable(emisTransPlanRuleService.selectEmisTransPlanRuleTree(lineCode)); + public TableDataInfo tree(EmisTransPlanRule emisTransPlanRule) { + return getDataTable(emisTransPlanRuleService.selectEmisTransPlanRuleTree(emisTransPlanRule)); } } \ No newline at end of file diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTmsSiteBatchMiss.java b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTmsSiteBatchMiss.java index a4efe3913..240f0779b 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTmsSiteBatchMiss.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTmsSiteBatchMiss.java @@ -27,8 +27,10 @@ public class EmisTmsSiteBatchMiss extends BaseEntity { private Long transPlanRuleId; /* 运单号 */ private String billCode; - /* 线路负责人 */ + /* 节点负责人 */ private String manager; + /* 线路负责人 */ + private String transManager; /* 寄件网点编码 */ private String sendSiteCode; /* 寄件网点名称 */ diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTransLine.java b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTransLine.java index b583f50af..6a6969d36 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTransLine.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTransLine.java @@ -76,4 +76,6 @@ public class EmisTransLine extends BaseEntity private String countryName; private String logoTypeName; + /* 线路负责人 */ + private String transManager; } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTransPlanRule.java b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTransPlanRule.java index 2aa871704..0e00e96ba 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTransPlanRule.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/EmisTransPlanRule.java @@ -1,9 +1,16 @@ package com.xdadan.erp.emis.domain; +import java.util.Date; import java.util.List; +import com.alibaba.excel.annotation.ExcelIgnore; +import com.fasterxml.jackson.annotation.JsonFormat; import com.xdadan.erp.common.core.domain.BaseEntity; import lombok.Data; +import com.xdadan.erp.common.annotation.Excel; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.converters.date.DateStringConverter; +import com.alibaba.excel.converters.longconverter.LongNumberConverter; /** * 供应商线路规划表对象 emis_trans_plan_rule @@ -30,16 +37,17 @@ public class EmisTransPlanRule extends BaseEntity { /** 线路名称 (仅用于查询结果) */ private String lineName; - /** 运输方式 */ - private String transType; - /** 产品类型 */ private String productType; - /** 产品类型名称 */ + /** + * 产品类型名称 + */ private String productTypeName; - /** 起始网点编码 */ + /** + * 起始网点编码 + */ private String startSiteCode; /** 下一网点编码 */ @@ -51,7 +59,7 @@ public class EmisTransPlanRule extends BaseEntity { /** 下一网点名称 */ private String nextSiteName; - /** 线路负责人 */ + /** 节点负责人 */ private String manager; /** 供应商编码 */ @@ -60,8 +68,13 @@ public class EmisTransPlanRule extends BaseEntity { /** 供应商名称 */ private String supplierName; - /** 状态 1-启用 0-不启用 */ - private String status; + /** 生效时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date startDate; + + /** 失效时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date endDate; /** 子节点 */ private List children; diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/enumtype/EmisBizErrorType.java b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/enumtype/EmisBizErrorType.java index 7a8095892..5658e2d8f 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/enumtype/EmisBizErrorType.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/enumtype/EmisBizErrorType.java @@ -25,6 +25,7 @@ public enum EmisBizErrorType { SUCCESS("0000", "成功"), FAIL("9999", "失败"), + PARAM_ERROR("E005", "参数错误"), PARAM_ERROR1("E001", "参数不完整"), CALC_FEE_ERROR("E002", "运费计算错误"), CALC_WEIGHT_ERROR("E003", "重量计算错误"), diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTransPlanRuleMapper.java b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTransPlanRuleMapper.java index f83f3b566..b46290fa8 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTransPlanRuleMapper.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisTransPlanRuleMapper.java @@ -21,7 +21,7 @@ public interface EmisTransPlanRuleMapper { public EmisTransPlanRule selectEmisTransPlanRuleById(Long id); /** - * 查询供应商线路规划列表,过滤根节点 + * 查询供应商线路规划列表 * * @param emisTransPlanRule 供应商线路规划 * @return 供应商线路规划集合 @@ -29,28 +29,12 @@ public interface EmisTransPlanRuleMapper { public List selectEmisTransPlanRuleList(EmisTransPlanRule emisTransPlanRule); /** - * 查询供应商线路规划列表,查询包括根节点 + * 查询供应商线路规划列表 * * @param emisTransPlanRule 供应商线路规划 * @return 供应商线路规划集合 */ - public List getEmisTransPlanRuleList(EmisTransPlanRule emisTransPlanRule); - - /** - * 查询子节点列表 - * - * @param id 父节点ID - * @return 子节点列表 - */ - public List selectChildrenEmisTransPlanRuleById(Long id); - - /** - * 查询是否存在子节点 - * - * @param id 节点ID - * @return 结果 - */ - public int hasChildByEmisTransPlanRuleId(Long id); + public List checkDuplicate(EmisTransPlanRule emisTransPlanRule); /** * 新增供应商线路规划 @@ -68,14 +52,6 @@ public interface EmisTransPlanRuleMapper { */ public int updateEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule); - /** - * 删除供应商线路规划 - * - * @param id 供应商线路规划主键 - * @return 结果 - */ - public int deleteEmisTransPlanRuleById(Long id); - /** * 批量删除供应商线路规划 * @@ -123,4 +99,36 @@ public interface EmisTransPlanRuleMapper { * @return 运输计划规则列表 */ List selectTransPlanRuleByLineCode(@Param("lineCode") String lineCode); + + /** + * 根据产品类型名称查询产品类型信息 + * + * @param productTypeNames 产品类型名称列表 + * @return 产品类型信息列表 + */ + public List> selectProductTypeInfoByNames(List productTypeNames); + + /** + * 根据网点名称查询网点信息 + * + * @param siteNames 网点名称列表 + * @return 网点信息列表 + */ + public List> selectSiteInfoByNames(List siteNames); + + /** + * 根据供应商名称查询供应商信息 + * + * @param supplierNames 供应商名称列表 + * @return 供应商信息列表 + */ + public List> selectSupplierInfoByNames(List supplierNames); + + /** + * 根据线路名称查询线路信息 + * + * @param lineNames 线路名称列表 + * @return 线路信息列表 + */ + public List> selectLineInfoByNames(List lineNames); } \ No newline at end of file diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java index f81605d46..de8eef86e 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java @@ -37,6 +37,7 @@ package com.xdadan.erp.emis.service; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.WordUtils; + import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -3855,6 +3856,145 @@ public class EmisBaseService { return weekDays; } + public List buildTree(List allRules) { + // 按lineCode分组 + Map> groupByLine = allRules.stream() + .collect(Collectors.groupingBy(EmisTransPlanRule::getLineCode)); + + List result = new ArrayList<>(); + + // 处理每个lineCode分组 + for (Map.Entry> lineEntry : groupByLine.entrySet()) { + List lineRules = lineEntry.getValue(); + if (lineRules.isEmpty()) { + continue; + } + + // 按productType分组 + Map> groupByProductType = lineRules.stream() + .collect(Collectors.groupingBy(EmisTransPlanRule::getProductType)); + + // 处理每个productType分组 + for (Map.Entry> productEntry : groupByProductType.entrySet()) { + List productRules = productEntry.getValue(); + + // 构建站点关系树 + Map> nodeMap = new HashMap<>(); + for (EmisTransPlanRule rule : productRules) { + String key = rule.getNextSiteCode() != null ? rule.getNextSiteCode() : rule.getStartSiteCode(); + if (key != null) { + nodeMap.computeIfAbsent(key, k -> new ArrayList<>()).add(rule); + } + } + + // 按startSiteCode分组,找出所有可能的父节点 + Map> parentGroups = productRules.stream() + .filter(rule -> rule.getStartSiteCode() != null) + .collect(Collectors.groupingBy(EmisTransPlanRule::getStartSiteCode)); + + // 设置父子关系 + for (Map.Entry> parentGroup : parentGroups.entrySet()) { + String startSiteCode = parentGroup.getKey(); + List children = parentGroup.getValue(); + + // 获取所有可能的父节点 + List parents = nodeMap.get(startSiteCode); + if (parents != null) { + for (EmisTransPlanRule parent : parents) { + if (parent.getChildren() == null) { + parent.setChildren(new ArrayList<>()); + } + + // 添加所有子节点到父节点的children列表中 + for (EmisTransPlanRule child : children) { + if (!parent.getChildren().contains(child)) { + parent.getChildren().add(child); + } + } + } + } + } + + // 找出顶级节点(没有父节点的节点) + List topLevelNodes = productRules.stream() + .filter(rule -> { + // 检查该节点是否作为其他节点的子节点 + boolean isChild = productRules.stream() + .anyMatch(potential -> potential.getChildren() != null + && potential.getChildren().contains(rule)); + return !isChild; + }) + .collect(Collectors.toList()); + + // 将顶级节点直接添加到结果中(进行深度复制) + for (EmisTransPlanRule node : topLevelNodes) { + result.add(deepCopyNode(node)); + } + } + } + + // 递归设置父ID和祖先节点ID + for (EmisTransPlanRule root : result) { + setParentAndAncestors(root, null, ""); + } + + return result; + } + + /** + * 递归设置父ID和祖先节点ID + * + * @param node 当前节点 + * @param parentId 父节点ID + * @param ancestors 祖先节点ID字符串 + */ + private void setParentAndAncestors(EmisTransPlanRule node, Long parentId, String ancestors) { + if (node == null) { + return; + } + + // 设置父ID + node.setParentId(parentId); + + // 设置祖先节点ID + node.setAncestors(ancestors); + + // 处理子节点,子节点的祖先包含当前节点和当前节点的所有祖先 + if (node.getChildren() != null && !node.getChildren().isEmpty()) { + String childAncestors = ancestors.isEmpty() ? node.getId().toString() : ancestors + "," + node.getId(); + + for (EmisTransPlanRule child : node.getChildren()) { + setParentAndAncestors(child, node.getId(), childAncestors); + } + } + } + + /** + * 深度复制节点及其子节点 + * + * @param source 源节点 + * @return 复制后的新节点 + */ + private EmisTransPlanRule deepCopyNode(EmisTransPlanRule source) { + if (source == null) { + return null; + } + + EmisTransPlanRule copy = new EmisTransPlanRule(); + BeanUtils.copyProperties(source, copy); + + // 递归复制子节点 + if (source.getChildren() != null) { + List copiedChildren = new ArrayList<>(); + for (EmisTransPlanRule child : source.getChildren()) { + copiedChildren.add(deepCopyNode(child)); + } + copy.setChildren(copiedChildren); + } + + return copy; + } + public static void main(String[] args) { // Date startDate = new Date(); // Date endDate = DateUtils.addDays(startDate, 10); diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisTransPlanRuleService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisTransPlanRuleService.java index 02474d0a1..374ba6c06 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisTransPlanRuleService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisTransPlanRuleService.java @@ -51,21 +51,13 @@ public interface IEmisTransPlanRuleService { */ public int deleteEmisTransPlanRuleByIds(Long[] ids) throws EmisBizError; - /** - * 删除供应商线路规划信息 - * - * @param id 供应商线路规划主键 - * @return 结果 - */ - public int deleteEmisTransPlanRuleById(Long id); - /** * 查询供应商线路规划树结构 * - * @param lineCode 线路编码 + * @param emisTransPlanRule 查询条件 * @return 供应商线路规划树结构 */ - public List selectEmisTransPlanRuleTree(String lineCode); + public List selectEmisTransPlanRuleTree(EmisTransPlanRule emisTransPlanRule); /** * 根据条件查询供应商信息 @@ -74,4 +66,12 @@ public interface IEmisTransPlanRuleService { * @return 供应商信息列表 */ List selectSupplierInfoByConditions(EmisTransPlanRule emisTransPlanRule); + + /** + * Excel草稿方式新增 + * + * @param emisTransPlanRule 供应商线路规划 + * @return 结果 + */ + int draftSubmitRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError; } \ No newline at end of file diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchMissServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchMissServiceImpl.java index 3aa4c7b88..971a547d0 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchMissServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTmsSiteBatchMissServiceImpl.java @@ -8,19 +8,15 @@ import java.util.concurrent.Executors; import cn.hutool.core.collection.CollectionUtil; import com.beust.jcommander.internal.Lists; -import com.xdadan.erp.common.utils.SecurityUtils; import com.xdadan.erp.emis.domain.*; import com.xdadan.erp.emis.mapper.*; +import com.xdadan.erp.emis.service.EmisBaseService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.xdadan.erp.emis.service.IEmisTmsSiteBatchMissService; -import static com.xdadan.erp.common.utils.SecurityUtils.getLoginUser; - /** * TMS漏组批次信息Service业务层处理 * @@ -28,7 +24,7 @@ import static com.xdadan.erp.common.utils.SecurityUtils.getLoginUser; */ @Service @Slf4j -public class EmisTmsSiteBatchMissServiceImpl implements IEmisTmsSiteBatchMissService { +public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements IEmisTmsSiteBatchMissService { @Autowired private EmisTmsSiteBatchMissMapper emisTmsSiteBatchMissMapper; @@ -143,10 +139,8 @@ public class EmisTmsSiteBatchMissServiceImpl implements IEmisTmsSiteBatchMissSer } // 按线路编码分组 - Map transPlanRulesByLineCode = new HashMap<>(); - treeRules.stream().filter(Objects::nonNull).forEach(i -> { - transPlanRulesByLineCode.put(i.getLineCode(), i); - }); + Map> transPlanRulesByLineCode = treeRules.stream() + .collect(Collectors.groupingBy(EmisTransPlanRule::getLineCode)); // 创建线程池 int processors = Runtime.getRuntime().availableProcessors(); @@ -278,7 +272,7 @@ public class EmisTmsSiteBatchMissServiceImpl implements IEmisTmsSiteBatchMissSer } private ProcessResult processWaybillBatch(List waybills, - Map transPlanRulesByLineCode) { + Map> transPlanRulesByLineCode) { int successCount = 0; int failCount = 0; List failedBillCodes = new ArrayList<>(); @@ -307,8 +301,8 @@ public class EmisTmsSiteBatchMissServiceImpl implements IEmisTmsSiteBatchMissSer for (EmisWaybill waybill : waybills) { try { // 获取运单对应的线路规划 - EmisTransPlanRule emisTransPlanRule = transPlanRulesByLineCode.get(waybill.getTransLineType()); - if (Objects.isNull(emisTransPlanRule)) { + List ruleListByTransLineType = transPlanRulesByLineCode.get(waybill.getTransLineType()); + if (CollectionUtil.isEmpty(ruleListByTransLineType)) { // 创建漏组记录 EmisTmsSiteBatchMiss miss = createMissRecord(waybill); miss.setMissReason("当前线路没有创建对应的线路规划"); @@ -317,13 +311,29 @@ public class EmisTmsSiteBatchMissServiceImpl implements IEmisTmsSiteBatchMissSer continue; } + List ruleListByProductType = ruleListByTransLineType.stream() + .filter(i -> StringUtils.isNotBlank(i.getProductType()) + && i.getProductType().contains(waybill.getProductType())) + .collect(Collectors.toList()); + + if (CollectionUtil.isEmpty(ruleListByProductType)) { + // 创建漏组记录 + EmisTmsSiteBatchMiss miss = createMissRecord(waybill); + miss.setMissReason("当前线路没有创建对应的产品类型"); + missRecords.add(miss); + successCount++; + continue; + } + // 获取运单对应的组批次信息 List waybillBatches = siteBatchesByBillCode.get(waybill.getBillCode()); if (CollectionUtil.isEmpty(waybillBatches)) { // 创建漏组记录 EmisTmsSiteBatchMiss miss = createMissRecord(waybill); miss.setMissReason("当前运单没有组批次"); - miss.setTransPlanRuleId(emisTransPlanRule.getId()); +// miss.setTransPlanRuleId(ruleListByTransLineType.stream() +// .sorted(Comparator.comparing(EmisTransPlanRule::getId)) +// .collect(Collectors.toList()).get(0).getId()); missRecords.add(miss); successCount++; continue; @@ -347,7 +357,7 @@ public class EmisTmsSiteBatchMissServiceImpl implements IEmisTmsSiteBatchMissSer waybillBatches = new ArrayList<>(mergedBatches.values()); // 检查运单是否匹配线路规划树 - boolean isAnyBranchMatched = checkBranchMatch(emisTransPlanRule, waybillBatches, waybill, + boolean isAnyBranchMatched = checkBranchMatch(ruleListByProductType, waybillBatches, waybill, missRecords); if (isAnyBranchMatched) { @@ -373,206 +383,12 @@ public class EmisTmsSiteBatchMissServiceImpl implements IEmisTmsSiteBatchMissSer public List selectEmisTransPlanRuleTree() { log.info("Start querying supplier route plan tree"); - List list = emisTransPlanRuleMapper.getEmisTransPlanRuleList(new EmisTransPlanRule()); - setName(list); + List list = emisTransPlanRuleMapper.selectEmisTransPlanRuleList(new EmisTransPlanRule()); List tree = buildTree(list); log.info("Queried supplier route plan tree, node count={}", tree != null ? tree.size() : 0); return tree; } - private void setName(List list) { - setSupplierNames(list); - setProductTypeNames(list); - setLineName(list); - } - - /** - * 设置供应商名称 - */ - private void setSupplierNames(List rules) { - if (rules == null || rules.isEmpty()) { - log.info("Setting supplier names: rules list is empty"); - return; - } - // 收集所有需要查询的供应商编码 - List supplierCodes = rules.stream() - .map(EmisTransPlanRule::getSupplierCode) - .filter(org.springframework.util.StringUtils::hasText) - .flatMap(code -> Arrays.stream(code.split(","))) - .distinct() - .collect(Collectors.toList()); - - log.info("Setting supplier names: code count={}, codes={}", supplierCodes.size(), supplierCodes); - - if (!supplierCodes.isEmpty()) { - // 批量查询供应商信息 - List> supplierInfos = emisTransPlanRuleMapper.selectSupplierInfoByCodes(supplierCodes); - log.info("Setting supplier names: found supplier info count={}", - supplierInfos != null ? supplierInfos.size() : 0); - - if (supplierInfos != null && !supplierInfos.isEmpty()) { - // 创建供应商编码到名称的映射 - Map supplierCodeToNameMap = supplierInfos.stream() - .collect(Collectors.toMap( - info -> info.get("code"), - info -> info.get("name"), - (existing, replacement) -> existing)); - - log.info("Setting supplier names: code to name mapping count={}", supplierCodeToNameMap.size()); - - // 设置供应商名称 - rules.forEach(rule -> { - if (org.springframework.util.StringUtils.hasText(rule.getSupplierCode())) { - String names = Arrays.stream(rule.getSupplierCode().split(",")) - .map(code -> supplierCodeToNameMap.getOrDefault(code, "")) - .filter(org.springframework.util.StringUtils::hasText) - .collect(Collectors.joining(",")); - rule.setSupplierName(names); - log.debug("Setting supplier name: id={}, supplierCode={}, supplierName={}", - rule.getId(), rule.getSupplierCode(), names); - } - }); - } - } - } - - /** - * 设置产品类型名称 - */ - private void setProductTypeNames(List rules) { - if (rules == null || rules.isEmpty()) { - log.info("Setting product type names: rules list is empty"); - return; - } - // 收集所有需要查询的产品类型编码 - List productTypes = rules.stream() - .map(EmisTransPlanRule::getProductType) - .filter(org.springframework.util.StringUtils::hasText) - .flatMap(type -> Arrays.stream(type.split(","))) - .distinct() - .collect(Collectors.toList()); - - log.info("Setting product type names: code count={}, codes={}", productTypes.size(), productTypes); - - if (!productTypes.isEmpty()) { - // 批量查询产品类型信息 - List> productTypeInfos = emisTransPlanRuleMapper - .selectProductTypeInfoByCodes(productTypes); - log.info("Setting product type names: found product type info count={}", - productTypeInfos != null ? productTypeInfos.size() : 0); - - if (productTypeInfos != null && !productTypeInfos.isEmpty()) { - // 创建产品类型编码到名称的映射 - Map productTypeToNameMap = productTypeInfos.stream() - .collect(Collectors.toMap( - info -> info.get("code"), - info -> info.get("name"), - (existing, replacement) -> existing)); - - log.info("Setting product type names: code to name mapping count={}", productTypeToNameMap.size()); - - // 设置产品类型名称 - rules.forEach(rule -> { - if (org.springframework.util.StringUtils.hasText(rule.getProductType())) { - String names = Arrays.stream(rule.getProductType().split(",")) - .map(code -> productTypeToNameMap.getOrDefault(code, "")) - .filter(org.springframework.util.StringUtils::hasText) - .collect(Collectors.joining(",")); - rule.setProductTypeName(names); - log.debug("Setting product type name: id={}, productType={}, productTypeName={}", - rule.getId(), rule.getProductType(), names); - } - }); - } - } - } - - /** - * 设置线路名称 - */ - private void setLineName(List rules) { - if (rules == null || rules.isEmpty()) { - log.info("Setting line names: rules list is empty"); - return; - } - - // 收集所有需要查询的线路编码 - List lineCodes = rules.stream() - .map(EmisTransPlanRule::getLineCode) - .filter(org.springframework.util.StringUtils::hasText) - .distinct() - .collect(Collectors.toList()); - - log.info("Setting line names: code count={}, codes={}", lineCodes.size(), lineCodes); - - if (!lineCodes.isEmpty()) { - // 批量查询线路信息 - List lines = emisTransLineMapper.selectEmisTransLineList( - new EmisTransLine() { - { - setLineCode(String.join(",", lineCodes)); - } - }); - - log.info("Setting line names: found line info count={}", lines != null ? lines.size() : 0); - - if (lines != null && !lines.isEmpty()) { - // 创建线路编码到线路名称的映射 - Map lineCodeToNameMap = lines.stream() - .collect(Collectors.toMap( - EmisTransLine::getLineCode, - EmisTransLine::getLineName, - (existing, replacement) -> existing)); - - log.info("Setting line names: code to name mapping count={}", lineCodeToNameMap.size()); - - // 设置线路名称 - rules.forEach(rule -> { - if (org.springframework.util.StringUtils.hasText(rule.getLineCode())) { - String name = lineCodeToNameMap.get(rule.getLineCode()); - rule.setLineName(name); - log.debug("Setting line name: id={}, lineCode={}, lineName={}", - rule.getId(), rule.getLineCode(), name); - } - }); - } - } - } - - /** - * 构建树形结构 - */ - private List buildTree(List allRules) { - log.debug("Start building tree structure, node count={}", allRules != null ? allRules.size() : 0); - if (allRules == null || allRules.isEmpty()) { - return new ArrayList<>(); - } - - // 使用 Map 存储 ID 到节点的映射,方便查找父节点 - Map map = allRules.stream() - .collect(Collectors.toMap(EmisTransPlanRule::getId, rule -> rule)); - - List tree = new ArrayList<>(); - for (EmisTransPlanRule rule : allRules) { - EmisTransPlanRule parent = map.get(rule.getParentId()); - // 如果 parent 不为 null 且在当前查询结果中,则添加到父节点的 children 列表 - if (parent != null) { - if (parent.getChildren() == null) { - parent.setChildren(new ArrayList<>()); - } - parent.getChildren().add(rule); - log.debug("Adding child node, parentId={}, childId={}", parent.getId(), rule.getId()); - } - // 否则,如果 parentId 为 0 或者父节点不在当前查询结果中,则认为是根节点 - else if (rule.getParentId() == null || rule.getParentId() == 0L || !map.containsKey(rule.getParentId())) { - tree.add(rule); - log.debug("Adding root node, ID={}", rule.getId()); - } - } - log.debug("Built tree structure, root node count={}", tree.size()); - return tree; - } - private EmisTmsSiteBatchMiss createMissRecord(EmisWaybill waybill) { EmisTmsSiteBatchMiss miss = new EmisTmsSiteBatchMiss(); miss.setBillCode(waybill.getBillCode()); @@ -590,32 +406,12 @@ public class EmisTmsSiteBatchMissServiceImpl implements IEmisTmsSiteBatchMissSer * @param missRecords * @return 是否匹配 */ - private boolean checkBranchMatch(EmisTransPlanRule emisTransPlanRule, List waybillBatches, + private boolean checkBranchMatch(List ruleList, List waybillBatches, EmisWaybill waybill, List missRecords) { // 检查当前节点是否匹配 boolean allNodeMatched = false; - List children1 = emisTransPlanRule.getChildren(); - if (children1.isEmpty()) { - // 创建漏组记录 - EmisTmsSiteBatchMiss miss = createMissRecord(waybill); - miss.setMissReason("当前线路没有创建对应的线路规划"); - missRecords.add(miss); - return false; - } - List children2 = children1.stream() - .filter(i -> StringUtils.isNotBlank(i.getProductType()) - && i.getProductType().contains(waybill.getProductType())) - .collect(Collectors.toList()); - if (children2.isEmpty() || children2.get(0) == null || children2.get(0).getChildren().isEmpty()) { - // 创建漏组记录 - EmisTmsSiteBatchMiss miss = createMissRecord(waybill); - miss.setMissReason("当前线路没有创建对应的线路规划"); - missRecords.add(miss); - return false; - } - List rules = children2.get(0).getChildren(); List filterRules = Lists.newArrayList(); - for (EmisTransPlanRule rule : rules) { + for (EmisTransPlanRule rule : ruleList) { List list = Lists.newArrayList(); if (checkRule(rule, waybillBatches, list)) { allNodeMatched = true; @@ -636,17 +432,17 @@ public class EmisTmsSiteBatchMissServiceImpl implements IEmisTmsSiteBatchMissSer return false; } EmisTransPlanRule filterRule = filterRules.get(0); - String[] ancestors = filterRule.getAncestors().split(","); Long ancestor; - if (ancestors.length > 3) { - ancestor = Long.valueOf(ancestors[3]); - } else { + if (StringUtils.isEmpty(filterRule.getAncestors())) { ancestor = filterRule.getId(); + } else { + String[] ancestors = filterRule.getAncestors().split(","); + ancestor = Long.valueOf(ancestors[0]); } - List ruleList = rules.stream().filter(i -> i.getId().equals(ancestor)) + List rules = ruleList.stream().filter(i -> i.getId().equals(ancestor)) .collect(Collectors.toList()); - EmisTransPlanRule rule = ruleList.get(0); + EmisTransPlanRule rule = rules.get(0); setMissRecords(missRecords, rule, filterRules, waybill); return false; } @@ -658,7 +454,9 @@ public class EmisTmsSiteBatchMissServiceImpl implements IEmisTmsSiteBatchMissSer for (EmisTmsSiteBatch batch : waybillBatches) { if (rule.getStartSiteCode().equals(batch.getStartSiteCode()) && rule.getNextSiteCode().equals(batch.getNextSiteCode()) && - rule.getSupplierCode().equals(batch.getSupplierCode())) { + rule.getSupplierCode().equals(batch.getSupplierCode()) + && batch.getEtd().before(rule.getEndDate()) + && !batch.getEtd().before(rule.getStartDate())) { currentMatch = true; list.add(rule); break; diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTransPlanRuleServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTransPlanRuleServiceImpl.java index b42f5b17c..58e3b302f 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTransPlanRuleServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisTransPlanRuleServiceImpl.java @@ -1,18 +1,16 @@ package com.xdadan.erp.emis.service.impl; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; -import java.util.Arrays; +import java.util.stream.Stream; import com.beust.jcommander.internal.Lists; import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType; import com.xdadan.erp.emis.domain.exception.EmisBizError; +import com.xdadan.erp.emis.service.EmisBaseService; import jodd.util.StringUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -34,14 +32,11 @@ import org.slf4j.LoggerFactory; */ @Service @Slf4j -public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService { +public class EmisTransPlanRuleServiceImpl extends EmisBaseService implements IEmisTransPlanRuleService { @Autowired private EmisTransPlanRuleMapper emisTransPlanRuleMapper; - @Autowired - private EmisTransLineMapper emisTransLineMapper; - /** * 查询供应商线路规划 * @@ -54,7 +49,6 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService { EmisTransPlanRule rule = emisTransPlanRuleMapper.selectEmisTransPlanRuleById(id); if (rule != null) { log.info("Found supplier route plan, ID={}", id); - setName(Collections.singletonList(rule)); } else { log.warn("Supplier route plan not found, ID={}", id); } @@ -62,7 +56,7 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService { } /** - * 查询供应商线路规划列表,过滤根节点 + * 查询供应商线路规划列表 * * @param emisTransPlanRule 供应商线路规划 * @return 供应商线路规划 @@ -72,182 +66,9 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService { log.info("Start querying supplier route plan list, query={}", emisTransPlanRule); List list = emisTransPlanRuleMapper.selectEmisTransPlanRuleList(emisTransPlanRule); log.info("Found supplier route plan list, count={}", list != null ? list.size() : 0); - setName(list); return list; } - /** - * 查询供应商线路规划列表,查询包括根节点 - * - * @param emisTransPlanRule 供应商线路规划 - * @return 供应商线路规划 - */ - public List getEmisTransPlanRuleList(EmisTransPlanRule emisTransPlanRule) { - log.info("Start getting supplier route plan list, query={}", emisTransPlanRule); - List list = emisTransPlanRuleMapper.getEmisTransPlanRuleList(emisTransPlanRule); - log.info("Got supplier route plan list, count={}", list != null ? list.size() : 0); - setName(list); - return list; - } - - private void setName(List list) { - setSupplierNames(list); - setProductTypeNames(list); - setLineName(list); - } - - /** - * 设置供应商名称 - */ - private void setSupplierNames(List rules) { - if (rules == null || rules.isEmpty()) { - log.info("Setting supplier names: rules list is empty"); - return; - } - // 收集所有需要查询的供应商编码 - List supplierCodes = rules.stream() - .map(EmisTransPlanRule::getSupplierCode) - .filter(StringUtils::hasText) - .flatMap(code -> Arrays.stream(code.split(","))) - .distinct() - .collect(Collectors.toList()); - - log.info("Setting supplier names: code count={}, codes={}", supplierCodes.size(), supplierCodes); - - if (!supplierCodes.isEmpty()) { - // 批量查询供应商信息 - List> supplierInfos = emisTransPlanRuleMapper.selectSupplierInfoByCodes(supplierCodes); - log.info("Setting supplier names: found supplier info count={}", - supplierInfos != null ? supplierInfos.size() : 0); - - if (supplierInfos != null && !supplierInfos.isEmpty()) { - // 创建供应商编码到名称的映射 - Map supplierCodeToNameMap = supplierInfos.stream() - .collect(Collectors.toMap( - info -> info.get("code"), - info -> info.get("name"), - (existing, replacement) -> existing)); - - log.info("Setting supplier names: code to name mapping count={}", supplierCodeToNameMap.size()); - - // 设置供应商名称 - rules.forEach(rule -> { - if (StringUtils.hasText(rule.getSupplierCode())) { - String names = Arrays.stream(rule.getSupplierCode().split(",")) - .map(code -> supplierCodeToNameMap.getOrDefault(code, "")) - .filter(StringUtils::hasText) - .collect(Collectors.joining(",")); - rule.setSupplierName(names); - log.debug("Setting supplier name: id={}, supplierCode={}, supplierName={}", - rule.getId(), rule.getSupplierCode(), names); - } - }); - } - } - } - - /** - * 设置产品类型名称 - */ - private void setProductTypeNames(List rules) { - if (rules == null || rules.isEmpty()) { - log.info("Setting product type names: rules list is empty"); - return; - } - // 收集所有需要查询的产品类型编码 - List productTypes = rules.stream() - .map(EmisTransPlanRule::getProductType) - .filter(StringUtils::hasText) - .flatMap(type -> Arrays.stream(type.split(","))) - .distinct() - .collect(Collectors.toList()); - - log.info("Setting product type names: code count={}, codes={}", productTypes.size(), productTypes); - - if (!productTypes.isEmpty()) { - // 批量查询产品类型信息 - List> productTypeInfos = emisTransPlanRuleMapper - .selectProductTypeInfoByCodes(productTypes); - log.info("Setting product type names: found product type info count={}", - productTypeInfos != null ? productTypeInfos.size() : 0); - - if (productTypeInfos != null && !productTypeInfos.isEmpty()) { - // 创建产品类型编码到名称的映射 - Map productTypeToNameMap = productTypeInfos.stream() - .collect(Collectors.toMap( - info -> info.get("code"), - info -> info.get("name"), - (existing, replacement) -> existing)); - - log.info("Setting product type names: code to name mapping count={}", productTypeToNameMap.size()); - - // 设置产品类型名称 - rules.forEach(rule -> { - if (StringUtils.hasText(rule.getProductType())) { - String names = Arrays.stream(rule.getProductType().split(",")) - .map(code -> productTypeToNameMap.getOrDefault(code, "")) - .filter(StringUtils::hasText) - .collect(Collectors.joining(",")); - rule.setProductTypeName(names); - log.debug("Setting product type name: id={}, productType={}, productTypeName={}", - rule.getId(), rule.getProductType(), names); - } - }); - } - } - } - - /** - * 设置线路名称 - */ - private void setLineName(List rules) { - if (rules == null || rules.isEmpty()) { - log.info("Setting line names: rules list is empty"); - return; - } - // 收集所有需要查询的线路编码 - List lineCodes = rules.stream() - .map(EmisTransPlanRule::getLineCode) - .filter(StringUtils::hasText) - .distinct() - .collect(Collectors.toList()); - - log.info("Setting line names: code count={}, codes={}", lineCodes.size(), lineCodes); - - if (!lineCodes.isEmpty()) { - // 批量查询线路信息 - List lines = emisTransLineMapper.selectEmisTransLineList( - new EmisTransLine() { - { - setLineCode(String.join(",", lineCodes)); - } - }); - - log.info("Setting line names: found line info count={}", lines != null ? lines.size() : 0); - - if (lines != null && !lines.isEmpty()) { - // 创建线路编码到线路名称的映射 - Map lineCodeToNameMap = lines.stream() - .collect(Collectors.toMap( - EmisTransLine::getLineCode, - EmisTransLine::getLineName, - (existing, replacement) -> existing)); - - log.info("Setting line names: code to name mapping count={}", lineCodeToNameMap.size()); - - // 设置线路名称 - rules.forEach(rule -> { - if (StringUtils.hasText(rule.getLineCode())) { - String name = lineCodeToNameMap.get(rule.getLineCode()); - rule.setLineName(name); - log.debug("Setting line name: id={}, lineCode={}, lineName={}", - rule.getId(), rule.getLineCode(), name); - } - }); - } - } - } - /** * 新增供应商线路规划 * @@ -255,40 +76,13 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService { * @return 结果 */ @Override - @Transactional public int insertEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError { - log.info("Start inserting supplier route plan, emisTransPlanRule={}", emisTransPlanRule); - // 处理父节点 - if (emisTransPlanRule.getParentId() != null) { - EmisTransPlanRule parent = emisTransPlanRuleMapper - .selectEmisTransPlanRuleById(emisTransPlanRule.getParentId()); - if (parent == null) { - throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "Parent node does not exist"); - } - // 设置祖先节点 - String ancestors = parent.getAncestors() == null ? "" : parent.getAncestors(); - emisTransPlanRule.setAncestors(ancestors + "," + parent.getId()); - log.debug("Setting ancestors, parentId={}, ancestors={}", parent.getId(), emisTransPlanRule.getAncestors()); - } else { - emisTransPlanRule.setParentId(0L); - emisTransPlanRule.setAncestors("0"); - log.debug("Setting root node, parentId=0, ancestors=0"); - } - - // 插入当前节点 - int rows = emisTransPlanRuleMapper.insertEmisTransPlanRule(emisTransPlanRule); - log.info("Inserted supplier route plan, affected rows={}, ID={}", rows, emisTransPlanRule.getId()); - - // 如果有子节点,递归处理 - if (emisTransPlanRule.getChildren() != null && !emisTransPlanRule.getChildren().isEmpty()) { - log.info("Start processing child nodes, count={}", emisTransPlanRule.getChildren().size()); - for (EmisTransPlanRule child : emisTransPlanRule.getChildren()) { - child.setParentId(emisTransPlanRule.getId()); - insertEmisTransPlanRule(child); - } - } - - return rows; + // 校验非空 + checkCode(emisTransPlanRule); + checkDate(emisTransPlanRule); + // 检查重复 + checkDuplicate(emisTransPlanRule); + return emisTransPlanRuleMapper.insertEmisTransPlanRule(emisTransPlanRule); } /** @@ -298,40 +92,8 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService { * @return 结果 */ @Override - @Transactional - public int updateEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError { - log.info("Start updating supplier route plan, ID={}, emisTransPlanRule={}", emisTransPlanRule.getId(), - emisTransPlanRule); - if (emisTransPlanRule.getParentId() == null) { - int rows = emisTransPlanRuleMapper.updateEmisTransPlanRule(emisTransPlanRule); - log.info("Updated supplier route plan, affected rows={}", rows); - return rows; - } - // 检查父节点是否存在 - EmisTransPlanRule parent = emisTransPlanRuleMapper - .selectEmisTransPlanRuleById(emisTransPlanRule.getParentId()); - if (parent == null) { - throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "Parent node does not exist"); - } - - // 检查是否形成循环引用 - if (parent.getAncestors() != null && parent.getAncestors().contains(emisTransPlanRule.getId().toString())) { - throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1, "Cannot move node under its child node"); - } - - // 更新祖先节点 - String ancestors = parent.getAncestors() == null ? "" : parent.getAncestors(); - emisTransPlanRule.setAncestors(ancestors + "," + parent.getId()); - log.debug("Updating ancestors, parentId={}, ancestors={}", parent.getId(), emisTransPlanRule.getAncestors()); - - // 更新当前节点 - int rows = emisTransPlanRuleMapper.updateEmisTransPlanRule(emisTransPlanRule); - log.info("Updated supplier route plan, affected rows={}", rows); - - // 更新子节点的祖先节点 - updateChildrenAncestors(emisTransPlanRule); - - return rows; + public int updateEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule) { + return emisTransPlanRuleMapper.updateEmisTransPlanRule(emisTransPlanRule); } /** @@ -341,116 +103,171 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService { * @return 结果 */ @Override - @Transactional - public int deleteEmisTransPlanRuleByIds(Long[] ids) throws EmisBizError { - log.info("Start batch deleting supplier route plans, IDs={}", Arrays.toString(ids)); - for (Long id : ids) { - // 检查是否有子节点 - if (emisTransPlanRuleMapper.hasChildByEmisTransPlanRuleId(id) > 0) { - throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1, "Cannot delete node with child nodes"); - } - deleteEmisTransPlanRuleById(id); - } - log.info("Batch deleted supplier route plans, count={}", ids.length); - return ids.length; - } - - /** - * 删除供应商线路规划信息 - * - * @param id 供应商线路规划主键 - * @return 结果 - */ - @Override - public int deleteEmisTransPlanRuleById(Long id) { - log.info("Start deleting supplier route plan, ID={}", id); - int rows = emisTransPlanRuleMapper.deleteEmisTransPlanRuleById(id); - log.info("Deleted supplier route plan, affected rows={}", rows); - return rows; + public int deleteEmisTransPlanRuleByIds(Long[] ids) { + return emisTransPlanRuleMapper.deleteEmisTransPlanRuleByIds(ids); } /** * 查询供应商线路规划树结构 * - * @param lineCode 线路编码 + * @param emisTransPlanRule 供应商线路规划 * @return 供应商线路规划树结构 */ @Override - public List selectEmisTransPlanRuleTree(String lineCode) { - log.info("Start querying supplier route plan tree, lineCode={}", lineCode); - EmisTransPlanRule query = new EmisTransPlanRule(); - query.setLineCode(lineCode); - List allRules = this.getEmisTransPlanRuleList(query); - List tree = buildTree(allRules); - log.info("Queried supplier route plan tree, node count={}", tree != null ? tree.size() : 0); - return tree; - } + public List selectEmisTransPlanRuleTree(EmisTransPlanRule emisTransPlanRule) { + // 查询所有规则 + List allRules = emisTransPlanRuleMapper.selectEmisTransPlanRuleList(emisTransPlanRule); - /** - * 构建树形结构 - */ - private List buildTree(List allRules) { - log.debug("Start building tree structure, node count={}", allRules != null ? allRules.size() : 0); if (allRules == null || allRules.isEmpty()) { return new ArrayList<>(); } - // 使用 Map 存储 ID 到节点的映射,方便查找父节点 - Map map = allRules.stream() - .collect(Collectors.toMap(EmisTransPlanRule::getId, rule -> rule)); - - List tree = new ArrayList<>(); - for (EmisTransPlanRule rule : allRules) { - EmisTransPlanRule parent = map.get(rule.getParentId()); - // 如果 parent 不为 null 且在当前查询结果中,则添加到父节点的 children 列表 - if (parent != null) { - if (parent.getChildren() == null) { - parent.setChildren(new ArrayList<>()); - } - parent.getChildren().add(rule); - log.debug("Adding child node, parentId={}, childId={}", parent.getId(), rule.getId()); - } - // 否则,如果 parentId 为 0 或者父节点不在当前查询结果中,则认为是根节点 - else if (rule.getParentId() == null || rule.getParentId() == 0L || !map.containsKey(rule.getParentId())) { - tree.add(rule); - log.debug("Adding root node, ID={}", rule.getId()); - } - } - log.debug("Built tree structure, root node count={}", tree.size()); - return tree; - } - - /** - * 递归更新子节点的祖先节点 - */ - @Transactional - public void updateChildrenAncestors(EmisTransPlanRule parent) { - log.info("Start updating children's ancestors, parentId={}", parent.getId()); - // 查询直接子节点 - EmisTransPlanRule childQuery = new EmisTransPlanRule(); - childQuery.setParentId(parent.getId()); - List children = emisTransPlanRuleMapper.getEmisTransPlanRuleList(childQuery); - log.info("Found child nodes, count={}", children != null ? children.size() : 0); - - if (children != null && !children.isEmpty()) { - String newAncestors = parent.getAncestors() + "," + parent.getId(); - for (EmisTransPlanRule child : children) { - child.setAncestors(newAncestors); - // 更新子节点,包括其祖先信息 - emisTransPlanRuleMapper.updateEmisTransPlanRule(child); - log.debug("Updating child node's ancestors, childId={}, ancestors={}", child.getId(), newAncestors); - // 递归更新子节点 - updateChildrenAncestors(child); - } - } + // 构建树形结构 + return buildTree(allRules); } @Override public List selectSupplierInfoByConditions(EmisTransPlanRule emisTransPlanRule) { log.info("Start querying supplier info by conditions, query={}", emisTransPlanRule); - emisTransPlanRule.setStatus("1"); - List result = this.getEmisTransPlanRuleList(emisTransPlanRule); + List result = emisTransPlanRuleMapper.selectEmisTransPlanRuleList(emisTransPlanRule); log.info("Queried supplier info, count={}", result != null ? result.size() : 0); return result; } + + /** + * Excel草稿方式新增 + * + * @param emisTransPlanRule 供应商线路规划 + * @return 结果 + */ + @Override + public int draftSubmitRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError { + // 校验参数 + checkName(emisTransPlanRule); + checkDate(emisTransPlanRule); + + nameToCode(emisTransPlanRule); + + // 检查重复 + checkDuplicate(emisTransPlanRule); + + return emisTransPlanRuleMapper.insertEmisTransPlanRule(emisTransPlanRule); + } + + private void nameToCode(EmisTransPlanRule emisTransPlanRule) throws EmisBizError { + // 线路 + List> lineInfo = emisTransPlanRuleMapper.selectLineInfoByNames(Collections.singletonList(emisTransPlanRule.getLineName())); + if (lineInfo == null || lineInfo.isEmpty()) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "未找到对应的线路:" + emisTransPlanRule.getLineName()); + } + emisTransPlanRule.setLineCode(lineInfo.get(0).get("code")); + + // 产品类型(支持多个,逗号分隔) + String[] productTypeNames = emisTransPlanRule.getProductTypeName().split(","); + List> productTypeInfo = emisTransPlanRuleMapper.selectProductTypeInfoByNames(Arrays.asList(productTypeNames)); + if (productTypeInfo == null || productTypeInfo.isEmpty()) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "未找到对应的产品类型:" + emisTransPlanRule.getProductTypeName()); + } + if (productTypeInfo.size() != productTypeNames.length) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "部分产品类型未找到:" + emisTransPlanRule.getProductTypeName()); + } + String productTypeCodes = productTypeInfo.stream() + .map(map -> map.get("code")) + .collect(Collectors.joining(",")); + emisTransPlanRule.setProductType(productTypeCodes); + + // 起始网点 + List> startSiteInfo = emisTransPlanRuleMapper.selectSiteInfoByNames(Collections.singletonList(emisTransPlanRule.getStartSiteName())); + if (startSiteInfo == null || startSiteInfo.isEmpty()) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "未找到对应的起始网点:" + emisTransPlanRule.getStartSiteName()); + } + emisTransPlanRule.setStartSiteCode(startSiteInfo.get(0).get("code")); + + // 下一网点 + List> nextSiteInfo = emisTransPlanRuleMapper.selectSiteInfoByNames(Collections.singletonList(emisTransPlanRule.getNextSiteName())); + if (nextSiteInfo == null || nextSiteInfo.isEmpty()) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "未找到对应的下一网点:" + emisTransPlanRule.getNextSiteName()); + } + emisTransPlanRule.setNextSiteCode(nextSiteInfo.get(0).get("code")); + + // 供应商(支持多个,逗号分隔) + String[] supplierNames = emisTransPlanRule.getSupplierName().split(","); + List> supplierInfo = emisTransPlanRuleMapper.selectSupplierInfoByNames(Arrays.asList(supplierNames)); + if (supplierInfo == null || supplierInfo.isEmpty()) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "未找到对应的供应商:" + emisTransPlanRule.getSupplierName()); + } + if (supplierInfo.size() != supplierNames.length) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "部分供应商未找到:" + emisTransPlanRule.getSupplierName()); + } + String supplierCodes = supplierInfo.stream() + .map(map -> map.get("code")) + .collect(Collectors.joining(",")); + emisTransPlanRule.setSupplierCode(supplierCodes); + } + + private void checkDuplicate(EmisTransPlanRule emisTransPlanRule) throws EmisBizError { + List existingRules = emisTransPlanRuleMapper.checkDuplicate(emisTransPlanRule); + if (existingRules != null && !existingRules.isEmpty()) { + throw new EmisBizError(EmisBizErrorType.EXISTS, "已存在相同的规则配置"); + } + } + + private static void checkName(EmisTransPlanRule emisTransPlanRule) throws EmisBizError { + if (StringUtil.isBlank(emisTransPlanRule.getManager())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "节点负责人不能为空"); + } + if (StringUtil.isBlank(emisTransPlanRule.getLineName())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "线路名称不能为空"); + } + if (StringUtil.isBlank(emisTransPlanRule.getProductTypeName())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "产品名称不能为空"); + } + + + if (StringUtil.isBlank(emisTransPlanRule.getStartSiteName())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "起始网点名称不能为空"); + } + if (StringUtil.isBlank(emisTransPlanRule.getNextSiteName())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "下一网点名称不能为空"); + } + if (StringUtil.isBlank(emisTransPlanRule.getSupplierName())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "供应商名称不能为空"); + } + } + + private static void checkCode(EmisTransPlanRule emisTransPlanRule) throws EmisBizError { + if (StringUtil.isBlank(emisTransPlanRule.getManager())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "节点负责人不能为空"); + } + if (StringUtil.isBlank(emisTransPlanRule.getLineCode())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "线路名称不能为空"); + } + if (StringUtil.isBlank(emisTransPlanRule.getProductType())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "产品名称不能为空"); + } + if (StringUtil.isBlank(emisTransPlanRule.getStartSiteCode())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "起始网点名称不能为空"); + } + if (StringUtil.isBlank(emisTransPlanRule.getNextSiteCode())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "下一网点名称不能为空"); + } + if (StringUtil.isBlank(emisTransPlanRule.getSupplierCode())) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "供应商名称不能为空"); + } + } + + private static void checkDate(EmisTransPlanRule emisTransPlanRule) throws EmisBizError { + Date startDate = emisTransPlanRule.getStartDate(); + Date endDate = emisTransPlanRule.getEndDate(); + if (startDate == null) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "生效时间不能为空"); + } + if (endDate == null) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "失效时间不能为空"); + } + if (startDate.after(endDate)) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "生效时间不能晚于失效时间"); + } + } + } \ No newline at end of file diff --git a/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchMapper.xml b/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchMapper.xml index be7b3383c..406f3de28 100644 --- a/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchMapper.xml @@ -483,7 +483,7 @@ - select distinct b.* from emis_tms_site_batch b inner join emis_tms_site_batch_dtl d on b.batch_no = d.batch_no diff --git a/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchMissMapper.xml b/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchMissMapper.xml index 8cf956432..95d1b54a8 100644 --- a/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchMissMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTmsSiteBatchMissMapper.xml @@ -8,6 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -47,7 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" w.send_site_code, s.site_name as send_site_name, w.send_country, c1.name as send_country_name, w.destination_code, n.dest_name as destination_name, w.receive_country, c2.name as receive_country_name, w.send_date, w.bl_sign, w.sign_date, w.trans_line_type, k.line_name as trans_line_type_name, w.product_type, j.prod_name as product_type_name, w.payment_type, w.parcel_qty, w.bill_weight, w.total_volume, w.volume_weight, - w.settlement_weight, w.freight, w.remark as waybill_remark, w.fee_remark, r.manager + w.settlement_weight, w.freight, w.remark as waybill_remark, w.fee_remark, r.manager, k.trans_manager from emis_tms_site_batch_miss m left join emis_waybill w on m.bill_code = w.bill_code and w.del_flag='0' left join emis_site s on w.send_site_code=s.site_code and s.del_flag=0 @@ -72,8 +73,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND r.manager like concat('%', #{manager}, '%') + + AND k.trans_manager like concat('%', #{transManager}, '%') + - and r.manager=#{params.privEmpName} + and (r.manager=#{params.privEmpName} or k.trans_manager=#{params.privEmpName}) diff --git a/emis-biz/src/main/resources/mapper/EmisTransLineMapper.xml b/emis-biz/src/main/resources/mapper/EmisTransLineMapper.xml index 68ad7bae3..38acc2e15 100644 --- a/emis-biz/src/main/resources/mapper/EmisTransLineMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTransLineMapper.xml @@ -23,6 +23,7 @@ + @@ -33,7 +34,7 @@ - select id, line_code, line_name, line_name_en, meter_rate, status, site_audit_man, site_audit_man_code, market_man, market_man_code, operate_man, operate_man_code, from_country, country, apply_scope, logo_type, trans_type, order_num, remark, tenant_id, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_trans_line + select id, line_code, line_name, line_name_en,trans_manager, meter_rate, status, site_audit_man, site_audit_man_code, market_man, market_man_code, operate_man, operate_man_code, from_country, country, apply_scope, logo_type, trans_type, order_num, remark, tenant_id, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_trans_line @@ -91,6 +93,7 @@ line_code, line_name, line_name_en, + trans_manager, meter_rate, status, site_audit_man, @@ -120,6 +123,7 @@ #{lineCode}, #{lineName}, #{lineNameEn}, + #{transManager}, #{meterRate}, #{status}, #{siteAuditMan}, @@ -152,6 +156,7 @@ line_code = #{lineCode}, line_name = #{lineName}, line_name_en = #{lineNameEn}, + trans_manager = #{transManager}, meter_rate = #{meterRate}, status = #{status}, site_audit_man = #{siteAuditMan}, diff --git a/emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml b/emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml index 207d3f0d4..c455a73af 100644 --- a/emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml @@ -6,11 +6,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - @@ -18,53 +15,59 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + + + + - select r.id, r.parent_id, r.ancestors, r.line_code, r.trans_type, r.product_type, r.start_site_code, - s1.site_name as start_site_name, r.next_site_code, s2.site_name as next_site_name, r.manager, r.supplier_code, - r.status, r.remark, r.del_flag, r.create_by, r.create_time, r.update_by, r.update_time, r.create_site, r.update_site + select r.id, r.line_code, r.product_type, r.start_site_code, + s1.site_name as start_site_name, r.next_site_code, s2.site_name as next_site_name, + r.manager, r.supplier_code, r.start_date, r.end_date, r.remark, + r.del_flag, r.create_by, r.create_time, r.update_by, r.update_time, r.create_site, r.update_site, + l.line_name, + (SELECT GROUP_CONCAT(s.name) + FROM emis_supplier s + WHERE FIND_IN_SET(s.code, r.supplier_code) + AND s.del_flag = '0') as supplier_name, + (SELECT GROUP_CONCAT(p.prod_name) + FROM emis_trans_product p + WHERE FIND_IN_SET(p.prod_code, r.product_type) + AND p.del_flag = '0') as product_type_name from emis_trans_plan_rule r - left join emis_site s1 on r.start_site_code = s1.site_code and s1.del_flag=0 - left join emis_site s2 on r.next_site_code = s2.site_code and s2.del_flag=0 + left join emis_site s1 on r.start_site_code = s1.site_code and s1.del_flag='0' + left join emis_site s2 on r.next_site_code = s2.site_code and s2.del_flag='0' + left join emis_trans_line l on r.line_code = l.line_code and l.del_flag='0' - - and r.parent_id = #{parentId} - and r.ancestors like concat(#{ancestors}, '%') - and r.line_code = #{lineCode} - and ( FIND_IN_SET(#{transType},r.trans_type) ) - and ( FIND_IN_SET(#{productType},r.product_type) ) - and r.start_site_code = #{startSiteCode} - and r.next_site_code = #{nextSiteCode} - and r.manager = #{manager} - and ( FIND_IN_SET(#{supplierCode},r.supplier_code) ) - and r.status = #{status} + and r.line_code = #{lineCode} + and r.product_type=#{productType} + and r.start_site_code = #{startSiteCode} + and r.next_site_code = #{nextSiteCode} + and r.supplier_code=#{supplierCode} and r.del_flag = '0' - order by id + order by id desc - - - - + + + + + + + + \ No newline at end of file diff --git a/emis-biz/src/main/resources/mapper/EmisWaybillMapper.xml b/emis-biz/src/main/resources/mapper/EmisWaybillMapper.xml index cfbb1c36b..75d423cee 100644 --- a/emis-biz/src/main/resources/mapper/EmisWaybillMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisWaybillMapper.xml @@ -3198,7 +3198,7 @@ left join emis_waybill_batch_status b on a.bill_code = b.bill_code where a.bl_sign = '1' and a.del_flag = '0' --- and a.bill_code="T7080300382673" +-- and a.bill_code="T7080300290222" and (b.site_batch_status is null or b.site_batch_status != '1') order by a.create_time desc limit #{offset}, #{pageSize}