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 24e1a8f5..d2f6db0c 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 @@ -182,19 +182,20 @@ public class BusMrpBaseController extends BaseController { @GetMapping("/coryEngineeringList") public R> obtainTheList(CoryObtainTheListReq req) { // public R> obtainTheList(CoryObtainTheListReq req) { - BusBillofquantitiesVersions one = busBillofquantitiesVersionsService.getOne(Wrappers.lambdaQuery() - .eq(BusBillofquantitiesVersions::getWorkOrderType, "3") //物资工程量清单 - .eq(BusBillofquantitiesVersions::getProjectId, req.getProjectId()) - .eq(BusBillofquantitiesVersions::getVersions, req.getVersions()) - .eq(BusBillofquantitiesVersions::getStatus, BusinessStatusEnum.FINISH.getStatus()) - .last("limit 1") - ); - if (one == null){ - throw new ServiceException("请先完成物资工程量清单"); - } - List list = busBillofquantitiesService.list(Wrappers.lambdaQuery() - .eq(BusBillofquantities::getVersions, one.getVersions()) - ); +// BusBillofquantitiesVersions one = busBillofquantitiesVersionsService.getOne(Wrappers.lambdaQuery() +// .eq(BusBillofquantitiesVersions::getWorkOrderType, "3") //物资工程量清单 +// .eq(BusBillofquantitiesVersions::getProjectId, req.getProjectId()) +// .eq(BusBillofquantitiesVersions::getVersions, req.getVersions()) +// .eq(BusBillofquantitiesVersions::getStatus, BusinessStatusEnum.FINISH.getStatus()) +// .last("limit 1") +// ); +// if (one == null){ +// throw new ServiceException("请先完成物资工程量清单"); +// } +// List list = busBillofquantitiesService.list(Wrappers.lambdaQuery() +// .eq(BusBillofquantities::getVersions, one.getVersions()) +// ); +// return R.ok(list); // List obtainTheListRes = new ArrayList<>(); // list.forEach(billofquantities -> { // ObtainTheListRes res = new ObtainTheListRes(); @@ -208,8 +209,7 @@ public class BusMrpBaseController extends BaseController { // // 3. 递归组装树形结构,从顶级节点(pid=0)开始 // List treeList = buildTree("0", parentMap); // return R.ok(treeList); - return R.ok(list); -// return R.ok(busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper().eq(BusBillofquantities::getPid, req.getSid()))); + return R.ok(busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper().eq(BusBillofquantities::getPid, req.getSid()))); } private List buildTree(String parentId, Map> parentMap) { diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/BusBillofquantitiesVersionsServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/BusBillofquantitiesVersionsServiceImpl.java index a946f022..d347dc85 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/BusBillofquantitiesVersionsServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/BusBillofquantitiesVersionsServiceImpl.java @@ -208,48 +208,63 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl allMaterials = new ArrayList<>(); - 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); +// if (!Objects.equals(bo.getWorkOrderType(), "3")) { + // 2. 解析所有工作表,转换为带父子关系的ExcelMaterial列表 解析所有Sheet数据,按规则生成sid和pid + List allMaterials = new ArrayList<>(); + 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(BusBillofquantities::getName) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + for (BusBillofquantities allMaterial : allMaterials) { + if (names.contains(allMaterial.getName())) { + throw new ServiceException("名称“"+allMaterial.getName()+"”已存在,请修改后重新上传!"); + } + allMaterial.setProjectId(bo.getProjectId()); } - // 3. 批量插入数据库 + }else { for (BusBillofquantities allMaterial : allMaterials) { allMaterial.setProjectId(bo.getProjectId()); } - boolean b = busBillofquantitiesService.saveBatch(allMaterials); - if (!b) { - throw new RuntimeException("导入失败"); - } - return true; - } else { - // 跳过1行(表头),读取0到6列(共7列),映射到ExcelData实体类 - List dataList = ExcelDynamicReader.readExcel( - file, // 上传的文件 - 1, // 跳过1行(表头) - 0, // 从第0列开始 - 5, // 到第5列结束 - MaterialsAndEquipmentExcelDto.class // 目标实体类 - ); - List busBillofquantities = BeanUtil.copyToList(dataList, BusBillofquantities.class); - for (BusBillofquantities busBillofquantity : busBillofquantities) { - busBillofquantity.setProjectId(bo.getProjectId()); - busBillofquantity.setVersions(banBen); - } - boolean b = busBillofquantitiesService.saveBatch(busBillofquantities); - if (!b) { - throw new RuntimeException("导入失败"); - } - return true; } + boolean b = busBillofquantitiesService.saveBatch(allMaterials); + if (!b) { + throw new RuntimeException("导入失败"); + } + return true; +// } else { +// // 跳过1行(表头),读取0到6列(共7列),映射到ExcelData实体类 +// List dataList = ExcelDynamicReader.readExcel( +// file, // 上传的文件 +// 1, // 跳过1行(表头) +// 0, // 从第0列开始 +// 5, // 到第5列结束 +// MaterialsAndEquipmentExcelDto.class // 目标实体类 +// ); +// List busBillofquantities = BeanUtil.copyToList(dataList, BusBillofquantities.class); +// for (BusBillofquantities busBillofquantity : busBillofquantities) { +// busBillofquantity.setProjectId(bo.getProjectId()); +// busBillofquantity.setVersions(banBen); +// } +// boolean b = busBillofquantitiesService.saveBatch(busBillofquantities); +// if (!b) { +// throw new RuntimeException("导入失败"); +// } +// return true; +// } } @@ -261,9 +276,9 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl> parentMap = flatList.stream() .collect(Collectors.groupingBy(ObtainTheListRes::getPid)); @@ -337,7 +352,8 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl obtainAllClassification(ObtainAllVersionNumbersReq bo) { LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); lqw.eq(bo.getProjectId() != null, BusBillofquantitiesVersions::getProjectId, bo.getProjectId()); - lqw.eq(StringUtils.isNotBlank(bo.getWorkOrderType()), BusBillofquantitiesVersions::getWorkOrderType, bo.getWorkOrderType()); + lqw.eq(BusBillofquantitiesVersions::getWorkOrderType, "3"); + lqw.eq(BusBillofquantitiesVersions::getStatus, BusinessStatusEnum.FINISH.getStatus()); List result = baseMapper.selectVoList(lqw); List versionss = new ArrayList<>(); result.forEach(v -> versionss.add(v.getVersions()));