From faff11ad6f8752ee2fc42695d3a1cad3f652f1b7 Mon Sep 17 00:00:00 2001 From: dfdg <2710245601@qq.com> Date: Wed, 24 Sep 2025 14:36:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=A9=E8=B5=84=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=B8=85=E5=8D=95=E7=9B=B8=E5=85=B3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BusMrpBaseController.java | 18 ++++- .../service/IBusMrpBaseService.java | 2 +- .../service/impl/BusMrpBaseServiceImpl.java | 75 ++++++++++++++----- .../domain/bo/CoryObtainTheListReq.java | 2 + ...usBillofquantitiesVersionsServiceImpl.java | 38 ++++------ .../service/impl/DesUserServiceImpl.java | 4 + ...sBillofquantitiesLimitListServiceImpl.java | 6 +- 7 files changed, 95 insertions(+), 50 deletions(-) diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/controller/BusMrpBaseController.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/controller/BusMrpBaseController.java index d2f6db0c..0f5a3bf6 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/controller/BusMrpBaseController.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/controller/BusMrpBaseController.java @@ -141,8 +141,8 @@ public class BusMrpBaseController extends BaseController { * 获取剩余量 */ @GetMapping("/remaining") - public R> remaining(Long suppliespriceId,Long mrpBaseId) { - return R.ok(busMrpBaseService.remaining(suppliespriceId,mrpBaseId)); + public R> remaining(Long projectId, String suppliespriceName,String specification,Long mrpBaseId) { + return R.ok(busMrpBaseService.remaining(projectId,suppliespriceName,specification,mrpBaseId)); } @@ -209,7 +209,19 @@ public class BusMrpBaseController extends BaseController { // // 3. 递归组装树形结构,从顶级节点(pid=0)开始 // List treeList = buildTree("0", parentMap); // return R.ok(treeList); - return R.ok(busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper().eq(BusBillofquantities::getPid, req.getSid()))); + List busBillofquantities = busBillofquantitiesService.getBaseMapper() + .selectList(new LambdaQueryWrapper() + .eq(BusBillofquantities::getProjectId, req.getProjectId()) + .eq(BusBillofquantities::getName, req.getSid())); + List sids = new ArrayList<>(); + busBillofquantities.forEach(busBillofquantities1 -> { + sids.add(busBillofquantities1.getSid()); + }); + return R.ok(busBillofquantitiesService + .getBaseMapper() + .selectList(new LambdaQueryWrapper() + .eq(BusBillofquantities::getProjectId, req.getProjectId()) + .in(BusBillofquantities::getPid, sids))); } private List buildTree(String parentId, Map> parentMap) { diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/service/IBusMrpBaseService.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/service/IBusMrpBaseService.java index 0f09408e..6b25834c 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/service/IBusMrpBaseService.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/service/IBusMrpBaseService.java @@ -86,5 +86,5 @@ public interface IBusMrpBaseService extends IService{ /** * 获取物资已有数量 */ - Map remaining(Long suppliespriceId, Long mrpBaseId); + Map remaining(Long projectId, String suppliespriceName, String specification, Long mrpBaseId); } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/service/impl/BusMrpBaseServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/service/impl/BusMrpBaseServiceImpl.java index 78cc1f0e..71556819 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/service/impl/BusMrpBaseServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cailiaoshebei/service/impl/BusMrpBaseServiceImpl.java @@ -75,7 +75,7 @@ public class BusMrpBaseServiceImpl extends ServiceImpl voList = planservice.queryList(planBo); for (BusMaterialbatchdemandplanVo vo : voList) { - Map map = remaining(vo.getSuppliespriceId(), id); + Map map = remaining(vo.getProjectId(),vo.getName(), vo.getSpecification(), id); vo.setRemaining(Convert.toBigDecimal(map.get("remainingQuantity"))); } busMrpVo.setMrpBaseBo(busMrpBaseVo); @@ -190,25 +190,34 @@ public class BusMrpBaseServiceImpl extends ServiceImpl batchSumMap = dto.getPlanList().stream() + Map batchSumMap = dto.getPlanList().stream() .collect(Collectors.groupingBy( - BusMaterialbatchdemandplanBo::getSuppliespriceId, + // 关键修改:使用 name + specification 拼接作为分组键 + item -> { + String name = item.getName() != null ? item.getName() : ""; + String spec = item.getSpecification() != null ? item.getSpecification() : ""; + return name + "&&&" + spec; + }, Collectors.reducing( BigDecimal.ZERO, - BusMaterialbatchdemandplanBo::getDemandQuantity, + item -> { + BigDecimal quantity = item.getDemandQuantity(); + return quantity != null ? quantity : BigDecimal.ZERO; + }, BigDecimal::add ) )); // 检查每种物料是否超出数量限制 - for (Map.Entry entry : batchSumMap.entrySet()) { - Long suppliespriceId = entry.getKey(); + for (Map.Entry entry : batchSumMap.entrySet()) { + String biaoshi = entry.getKey(); BigDecimal batchSum = entry.getValue(); - + String[] split = biaoshi.split("&&&"); // 获取数据库中已有的数量 List existingList = planservice.list( Wrappers.lambdaQuery(BusMaterialbatchdemandplan.class) - .eq(BusMaterialbatchdemandplan::getSuppliespriceId, suppliespriceId) + .eq(BusMaterialbatchdemandplan::getName, split[0]) + .eq(BusMaterialbatchdemandplan::getSpecification,split[1]) .ne(BusMaterialbatchdemandplan::getMrpBaseId, convert.getId()) // 排除当前批次 ); @@ -217,13 +226,29 @@ public class BusMrpBaseServiceImpl extends ServiceImpl 0) { + List busBillofquantities = busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper() + .eq(BusBillofquantities::getProjectId, dto.getMrpBaseBo().getProjectId()) + .eq(BusBillofquantities::getName, split[0]) + .eq(BusBillofquantities::getSpecification, split[1])); + BigDecimal quantity = busBillofquantities.stream() + .map(BusBillofquantities::getQuantity) + .filter(Objects::nonNull) + .reduce(BigDecimal.ZERO, BigDecimal::add); + if (existingSum.add(batchSum).compareTo(quantity) > 0) { // 找到超出限制的物料名称用于提示 String itemName = dto.getPlanList().stream() - .filter(plan -> plan.getSuppliespriceId().equals(suppliespriceId)) + .filter(item -> { + String name = item.getName() != null ? item.getName() : ""; + String spec = item.getSpecification() != null ? item.getSpecification() : ""; + return (name + "&&&" + spec).equals(biaoshi); + + }) .findFirst() - .map(BusMaterialbatchdemandplanBo::getName) + .map(item -> { + String name = item.getName() != null ? item.getName() : ""; + String spec = item.getSpecification() != null ? item.getSpecification() : ""; + return "名称:“"+name + "”,规格:“" + spec+"”"; + }) .orElse("未知物料"); throw new ServiceException(itemName + "超出数量"); } @@ -272,13 +297,23 @@ public class BusMrpBaseServiceImpl extends ServiceImpl remaining(Long suppliespriceId, Long mrpBaseId) { + public Map remaining(Long projectId, String suppliespriceName, String specification, Long mrpBaseId) { Map map = new HashMap<>(); - BusBillofquantities byId = busBillofquantitiesService.getById(suppliespriceId); + List busBillofquantities = busBillofquantitiesService.getBaseMapper() + .selectList(new LambdaQueryWrapper() + .eq(BusBillofquantities::getProjectId, projectId) + .eq(BusBillofquantities::getName, suppliespriceName) + .eq(BusBillofquantities::getSpecification,specification)); + BigDecimal quantity = busBillofquantities.stream() + .map(BusBillofquantities::getQuantity) + .filter(Objects::nonNull) + .reduce(BigDecimal.ZERO, BigDecimal::add); +// BusBillofquantities byId = busBillofquantitiesService.getById(suppliespriceId); // 获取数据库中已有的数量 List existingList = planservice.list( Wrappers.lambdaQuery(BusMaterialbatchdemandplan.class) - .eq(BusMaterialbatchdemandplan::getSuppliespriceId, suppliespriceId) + .eq(BusMaterialbatchdemandplan::getName, suppliespriceName) + .eq(BusMaterialbatchdemandplan::getSpecification ,specification) .ne(mrpBaseId!=null,BusMaterialbatchdemandplan::getMrpBaseId, mrpBaseId)// 排除当前批次 ); BigDecimal reduce = BigDecimal.ZERO; @@ -287,11 +322,11 @@ public class BusMrpBaseServiceImpl extends ServiceImpl allMaterials = new ArrayList<>(); - for (ExcelReader.SheetData sheetData : excelData.getSheetDataList()) { + if (Objects.equals(bo.getWorkOrderType(), "3")){ + ExcelReader.SheetData sheetData = excelData.getSheetDataList().getFirst(); String sheetName = sheetData.getSheetName(); List> rowDataList = sheetData.getData(); // 构建当前Sheet的树形结构(复用ExcelReader的buildTree方法) @@ -220,30 +221,21 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl nodeMap = new HashMap<>(); // 递归遍历树形结构,生成sid和pid traverseTree(rootNode, nodeMap, allMaterials, sheetName, banBen); + }else { + for (ExcelReader.SheetData sheetData : excelData.getSheetDataList()) { + String sheetName = sheetData.getSheetName(); + List> rowDataList = sheetData.getData(); + // 构建当前Sheet的树形结构(复用ExcelReader的buildTree方法) + ExcelReader.TreeNode rootNode = ExcelReader.buildTree(rowDataList); + // 存储节点映射:TreeNode → ExcelMaterial(用于子节点关联父节点) + Map nodeMap = new HashMap<>(); + // 递归遍历树形结构,生成sid和pid + traverseTree(rootNode, nodeMap, allMaterials, sheetName, banBen); + } } // 3. 批量插入数据库 - if (Objects.equals(bo.getWorkOrderType(), "3")){ - List busBillofquantities = busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper().eq(BusBillofquantities::getProjectId, bo.getProjectId())); - Set names = busBillofquantities.stream() - .filter(Objects::nonNull) - .map(obj->{ - String name = Optional.ofNullable (obj.getName ()).orElse (""); - String specification = Optional.ofNullable (obj.getSpecification ()).orElse (""); - String remark = Optional.ofNullable (obj.getRemark ()).orElse (""); - return name+"+"+specification+"+"+remark; - }) - .collect(Collectors.toSet()); - for (BusBillofquantities allMaterial : allMaterials) { - String biaoqian = allMaterial.getName()+"+"+allMaterial.getSpecification()+"+"+allMaterial.getRemark(); - if (names.contains(biaoqian)) { - throw new ServiceException("名称:“"+allMaterial.getName()+"+”规格:”"+allMaterial.getSpecification()+"“+”备注:“"+allMaterial.getRemark()+"已存在,请修改后重新上传!"); - } - allMaterial.setProjectId(bo.getProjectId()); - } - }else { - for (BusBillofquantities allMaterial : allMaterials) { - allMaterial.setProjectId(bo.getProjectId()); - } + for (BusBillofquantities allMaterial : allMaterials) { + allMaterial.setProjectId(bo.getProjectId()); } boolean b = busBillofquantitiesService.saveBatch(allMaterials); if (!b) { diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesUserServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesUserServiceImpl.java index 56bdc6c5..19465612 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesUserServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesUserServiceImpl.java @@ -468,5 +468,9 @@ public class DesUserServiceImpl extends ServiceImpl impl DataValidationConstraint constraint = helper.createFormulaListConstraint(personRange); // 作用范围:第2行到100行,第四列 CellRangeAddressList addressList = new CellRangeAddressList(1, 100, rowCount, rowCount); + + DataValidation validation = helper.createValidation(constraint, addressList); + validation.setShowErrorBox(true); + mainSheet.addValidationData(validation); } } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/tender/service/impl/BusBillofquantitiesLimitListServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/tender/service/impl/BusBillofquantitiesLimitListServiceImpl.java index 8822d6fe..a6890288 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/tender/service/impl/BusBillofquantitiesLimitListServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/tender/service/impl/BusBillofquantitiesLimitListServiceImpl.java @@ -203,9 +203,9 @@ public class BusBillofquantitiesLimitListServiceImpl extends ServiceImpl { item.setPrice(item.getUnitPrice().multiply(item.getQuantity()).setScale(4, RoundingMode.HALF_UP)); }); - if (bo.getType().equals(LimitListTypeEnum.SPECIAL.getCode())) { - return listVoList; - } +// if (bo.getType().equals(LimitListTypeEnum.SPECIAL.getCode())) { +// return listVoList; +// } //构建父子映射 Map> parentMap = listVoList.stream()