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 cc1acc16a..bcbd60b5a 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 @@ -116,6 +116,41 @@ public class EmisTransPlanRuleController extends EmisBaseController { return toAjax(emisTransPlanRuleService.updateEmisTransPlanRule(emisTransPlanRule)); } + /** + * 批量修改供应商线路规划 + */ + @PreAuthorize("@ss.hasPermi('emis:emisTransPlanRule:batchEdit')") + @PutMapping("/batchEdit") + public AjaxResult batchEdit(@RequestBody List emisTransPlanRuleList) { + JSONObject jObjOut = new JSONObject(); + String result = "success"; + String msg = "批量修改成功"; + try { + int successCount = emisTransPlanRuleService.batchUpdateEmisTransPlanRule(emisTransPlanRuleList); + jObjOut.put("successCount", successCount); + jObjOut.put("totalCount", emisTransPlanRuleList.size()); + msg = "批量修改成功,成功修改 " + successCount + " 条记录"; + } catch (EmisBizError ex) { + ex.printStackTrace(); + result = "fail"; + msg = ex.getErrorCode() + ":" + ex.getMessage(); + } catch (DuplicateKeyException e) { + e.printStackTrace(); + result = "fail"; + msg = "数据重复"; + } catch (Exception ex) { + result = "fail"; + ex.printStackTrace(); + msg = "系统异常:" + ex.getMessage(); + if (ex instanceof EmisBizError) { + msg = ((EmisBizError) ex).getErrorCode() + ":" + ex.getMessage(); + } + } + jObjOut.put("result", result); + jObjOut.put("msg", msg); + return AjaxResult.success("成功", jObjOut); + } + /** * 删除供应商线路规划 */ 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 d2436be51..55fd9e025 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 @@ -82,4 +82,12 @@ public interface IEmisTransPlanRuleService { * @return 循环引用提示信息列表 */ List checkTree(EmisTransPlanRule emisTransPlanRule); + + /** + * 批量修改供应商线路规划 + * + * @param emisTransPlanRuleList 供应商线路规划列表 + * @return 结果 + */ + int batchUpdateEmisTransPlanRule(List emisTransPlanRuleList) throws EmisBizError; } \ No newline at end of file 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 4bc8ed11e..287ea3e29 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 @@ -99,6 +99,22 @@ public class EmisTransPlanRuleServiceImpl extends EmisBaseService implements IEm */ @Override public int updateEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError { + // 校验非空 + checkCode(emisTransPlanRule); + checkDate(emisTransPlanRule); + + // 检查重复(排除自身) + checkDuplicateForUpdate(emisTransPlanRule); + + // 校验循环引用 + EmisTransPlanRule checkRule = new EmisTransPlanRule(); + checkRule.setProductType(emisTransPlanRule.getProductType()); + List allRules = emisTransPlanRuleMapper.selectEmisTransPlanRuleListWithoutName(checkRule); + // 移除当前要修改的规则,避免自己与自己比较 + allRules.removeIf(rule -> rule.getId().equals(emisTransPlanRule.getId())); + allRules.add(emisTransPlanRule); + buildTree(allRules, emisTransPlanRule); + return emisTransPlanRuleMapper.updateEmisTransPlanRule(emisTransPlanRule); } @@ -370,6 +386,119 @@ public class EmisTransPlanRuleServiceImpl extends EmisBaseService implements IEm return buildTreeForCheck(allRules); } + /** + * 批量修改供应商线路规划 + * + * @param emisTransPlanRuleList 供应商线路规划列表 + * @return 结果 + */ + @Override + @Transactional + public int batchUpdateEmisTransPlanRule(List emisTransPlanRuleList) throws EmisBizError { + if (emisTransPlanRuleList == null || emisTransPlanRuleList.isEmpty()) { + throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "批量修改数据不能为空"); + } + + int successCount = 0; + for (EmisTransPlanRule emisTransPlanRule : emisTransPlanRuleList) { + try { + // 校验非空 + checkCode(emisTransPlanRule); + checkDate(emisTransPlanRule); + + // 检查重复(排除自身) + checkDuplicateForUpdate(emisTransPlanRule); + + // 校验循环引用 + EmisTransPlanRule checkRule = new EmisTransPlanRule(); + checkRule.setProductType(emisTransPlanRule.getProductType()); + List allRules = emisTransPlanRuleMapper + .selectEmisTransPlanRuleListWithoutName(checkRule); + // 移除当前要修改的规则,避免自己与自己比较 + allRules.removeIf(rule -> rule.getId().equals(emisTransPlanRule.getId())); + allRules.add(emisTransPlanRule); + buildTree(allRules, emisTransPlanRule); + + // 执行更新 + int result = emisTransPlanRuleMapper.updateEmisTransPlanRule(emisTransPlanRule); + if (result > 0) { + successCount++; + } + } catch (Exception e) { + log.error("批量修改供应商线路规划失败,ID: {}, 错误: {}", emisTransPlanRule.getId(), e.getMessage()); + throw new EmisBizError(EmisBizErrorType.SYS_EXCEPTION, + "批量修改失败,ID: " + emisTransPlanRule.getId() + ", 错误: " + e.getMessage()); + } + } + + return successCount; + } + + /** + * 检查重复(用于更新操作,排除自身) + */ + private void checkDuplicateForUpdate(EmisTransPlanRule emisTransPlanRule) throws EmisBizError { + // 检查正向规则(起始网点到下一网点) + List existingRules = checkDuplicateDirectionForUpdate(emisTransPlanRule, + emisTransPlanRule.getStartSiteCode(), emisTransPlanRule.getNextSiteCode()); + if (existingRules != null && !existingRules.isEmpty()) { + throw new EmisBizError(EmisBizErrorType.EXISTS, "已存在相同的规则配置"); + } + + // 检查反向规则(下一网点到起始网点) + List existingRules1 = checkDuplicateDirectionForUpdate(emisTransPlanRule, + emisTransPlanRule.getNextSiteCode(), emisTransPlanRule.getStartSiteCode()); + if (existingRules1 != null && !existingRules1.isEmpty()) { + throw new EmisBizError(EmisBizErrorType.EXISTS, "已存在相同的规则配置"); + } + } + + /** + * 检查重复方向(用于更新操作,排除自身) + */ + private List checkDuplicateDirectionForUpdate(EmisTransPlanRule emisTransPlanRule, + String startSiteCode, String nextSiteCode) { + // 构建查询条件 + EmisTransPlanRule queryRule = new EmisTransPlanRule(); + queryRule.setLineCode(emisTransPlanRule.getLineCode()); + queryRule.setStartSiteCode(startSiteCode); + queryRule.setNextSiteCode(nextSiteCode); + queryRule.setStartDate(emisTransPlanRule.getStartDate()); + queryRule.setEndDate(emisTransPlanRule.getEndDate()); + + // 查询所有匹配的规则 + List allRules = emisTransPlanRuleMapper.checkDuplicate(queryRule); + + if (allRules == null || allRules.isEmpty()) { + return new ArrayList<>(); + } + + // 排除自身 + allRules.removeIf(rule -> rule.getId().equals(emisTransPlanRule.getId())); + + if (allRules.isEmpty()) { + return new ArrayList<>(); + } + + // 检查productType和supplierCode是否有交集 + String newProductType = emisTransPlanRule.getProductType(); + String newSupplierCode = emisTransPlanRule.getSupplierCode(); + + for (EmisTransPlanRule existingRule : allRules) { + // 检查产品类型是否有交集 + boolean productTypeOverlap = hasOverlap(newProductType, existingRule.getProductType()); + // 检查供应商编码是否有交集 + boolean supplierCodeOverlap = hasOverlap(newSupplierCode, existingRule.getSupplierCode()); + + // 如果产品类型和供应商编码都有交集,则认为重复 + if (productTypeOverlap && supplierCodeOverlap) { + return Arrays.asList(existingRule); + } + } + + return new ArrayList<>(); + } + /** * 仅校验循环引用并收集所有循环引用提示 * diff --git a/emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml b/emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml index a7dbe5388..c31565efc 100644 --- a/emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml @@ -335,6 +335,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and ( FIND_IN_SET(#{emisTransPlanRule.supplierCode},r.supplier_code) ) and r.start_date = #{emisTransPlanRule.startDate} and r.end_date = #{emisTransPlanRule.endDate} + and r.line_code!='014' order by id desc limit #{limit} offset #{offset}