修改物资设备清单导入和批次需求计划新增

This commit is contained in:
2025-09-23 14:23:23 +08:00
parent d0c1a1337e
commit 20dc9b3e85
2 changed files with 72 additions and 56 deletions

View File

@ -182,19 +182,20 @@ public class BusMrpBaseController extends BaseController {
@GetMapping("/coryEngineeringList") @GetMapping("/coryEngineeringList")
public R<List<BusBillofquantities>> obtainTheList(CoryObtainTheListReq req) { public R<List<BusBillofquantities>> obtainTheList(CoryObtainTheListReq req) {
// public R<List<ObtainTheListRes>> obtainTheList(CoryObtainTheListReq req) { // public R<List<ObtainTheListRes>> obtainTheList(CoryObtainTheListReq req) {
BusBillofquantitiesVersions one = busBillofquantitiesVersionsService.getOne(Wrappers.<BusBillofquantitiesVersions>lambdaQuery() // BusBillofquantitiesVersions one = busBillofquantitiesVersionsService.getOne(Wrappers.<BusBillofquantitiesVersions>lambdaQuery()
.eq(BusBillofquantitiesVersions::getWorkOrderType, "3") //物资工程量清单 // .eq(BusBillofquantitiesVersions::getWorkOrderType, "3") //物资工程量清单
.eq(BusBillofquantitiesVersions::getProjectId, req.getProjectId()) // .eq(BusBillofquantitiesVersions::getProjectId, req.getProjectId())
.eq(BusBillofquantitiesVersions::getVersions, req.getVersions()) // .eq(BusBillofquantitiesVersions::getVersions, req.getVersions())
.eq(BusBillofquantitiesVersions::getStatus, BusinessStatusEnum.FINISH.getStatus()) // .eq(BusBillofquantitiesVersions::getStatus, BusinessStatusEnum.FINISH.getStatus())
.last("limit 1") // .last("limit 1")
); // );
if (one == null){ // if (one == null){
throw new ServiceException("请先完成物资工程量清单"); // throw new ServiceException("请先完成物资工程量清单");
} // }
List<BusBillofquantities> list = busBillofquantitiesService.list(Wrappers.<BusBillofquantities>lambdaQuery() // List<BusBillofquantities> list = busBillofquantitiesService.list(Wrappers.<BusBillofquantities>lambdaQuery()
.eq(BusBillofquantities::getVersions, one.getVersions()) // .eq(BusBillofquantities::getVersions, one.getVersions())
); // );
// return R.ok(list);
// List<ObtainTheListRes> obtainTheListRes = new ArrayList<>(); // List<ObtainTheListRes> obtainTheListRes = new ArrayList<>();
// list.forEach(billofquantities -> { // list.forEach(billofquantities -> {
// ObtainTheListRes res = new ObtainTheListRes(); // ObtainTheListRes res = new ObtainTheListRes();
@ -208,8 +209,7 @@ public class BusMrpBaseController extends BaseController {
// // 3. 递归组装树形结构从顶级节点pid=0开始 // // 3. 递归组装树形结构从顶级节点pid=0开始
// List<ObtainTheListRes> treeList = buildTree("0", parentMap); // List<ObtainTheListRes> treeList = buildTree("0", parentMap);
// return R.ok(treeList); // return R.ok(treeList);
return R.ok(list); return R.ok(busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper<BusBillofquantities>().eq(BusBillofquantities::getPid, req.getSid())));
// return R.ok(busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper<BusBillofquantities>().eq(BusBillofquantities::getPid, req.getSid())));
} }
private List<ObtainTheListRes> buildTree(String parentId, Map<String, List<ObtainTheListRes>> parentMap) { private List<ObtainTheListRes> buildTree(String parentId, Map<String, List<ObtainTheListRes>> parentMap) {

View File

@ -208,7 +208,7 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl<BusBillo
//1、获取到解析数据 //1、获取到解析数据
ExcelReader.ExcelData excelData = ExcelReader.readExcelFromMultipartFile(file); ExcelReader.ExcelData excelData = ExcelReader.readExcelFromMultipartFile(file);
//走正常的工程清单 //走正常的工程清单
if (!Objects.equals(bo.getWorkOrderType(), "3")) { // if (!Objects.equals(bo.getWorkOrderType(), "3")) {
// 2. 解析所有工作表转换为带父子关系的ExcelMaterial列表 解析所有Sheet数据按规则生成sid和pid // 2. 解析所有工作表转换为带父子关系的ExcelMaterial列表 解析所有Sheet数据按规则生成sid和pid
List<BusBillofquantities> allMaterials = new ArrayList<>(); List<BusBillofquantities> allMaterials = new ArrayList<>();
for (ExcelReader.SheetData sheetData : excelData.getSheetDataList()) { for (ExcelReader.SheetData sheetData : excelData.getSheetDataList()) {
@ -222,34 +222,49 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl<BusBillo
traverseTree(rootNode, nodeMap, allMaterials, sheetName, banBen); traverseTree(rootNode, nodeMap, allMaterials, sheetName, banBen);
} }
// 3. 批量插入数据库 // 3. 批量插入数据库
if (Objects.equals(bo.getWorkOrderType(), "3")){
List<BusBillofquantities> busBillofquantities = busBillofquantitiesService.getBaseMapper().selectList(new LambdaQueryWrapper<BusBillofquantities>().eq(BusBillofquantities::getProjectId, bo.getProjectId()));
Set<String> 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());
}
}else {
for (BusBillofquantities allMaterial : allMaterials) { for (BusBillofquantities allMaterial : allMaterials) {
allMaterial.setProjectId(bo.getProjectId()); allMaterial.setProjectId(bo.getProjectId());
} }
}
boolean b = busBillofquantitiesService.saveBatch(allMaterials); boolean b = busBillofquantitiesService.saveBatch(allMaterials);
if (!b) { if (!b) {
throw new RuntimeException("导入失败"); throw new RuntimeException("导入失败");
} }
return true; return true;
} else { // } else {
// 跳过1行表头读取0到6列共7列映射到ExcelData实体类 // // 跳过1行表头读取0到6列共7列映射到ExcelData实体类
List<MaterialsAndEquipmentExcelDto> dataList = ExcelDynamicReader.readExcel( // List<MaterialsAndEquipmentExcelDto> dataList = ExcelDynamicReader.readExcel(
file, // 上传的文件 // file, // 上传的文件
1, // 跳过1行表头 // 1, // 跳过1行表头
0, // 从第0列开始 // 0, // 从第0列开始
5, // 到第5列结束 // 5, // 到第5列结束
MaterialsAndEquipmentExcelDto.class // 目标实体类 // MaterialsAndEquipmentExcelDto.class // 目标实体类
); // );
List<BusBillofquantities> busBillofquantities = BeanUtil.copyToList(dataList, BusBillofquantities.class); // List<BusBillofquantities> busBillofquantities = BeanUtil.copyToList(dataList, BusBillofquantities.class);
for (BusBillofquantities busBillofquantity : busBillofquantities) { // for (BusBillofquantities busBillofquantity : busBillofquantities) {
busBillofquantity.setProjectId(bo.getProjectId()); // busBillofquantity.setProjectId(bo.getProjectId());
busBillofquantity.setVersions(banBen); // busBillofquantity.setVersions(banBen);
} // }
boolean b = busBillofquantitiesService.saveBatch(busBillofquantities); // boolean b = busBillofquantitiesService.saveBatch(busBillofquantities);
if (!b) { // if (!b) {
throw new RuntimeException("导入失败"); // throw new RuntimeException("导入失败");
} // }
return true; // return true;
} // }
} }
@ -261,9 +276,9 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl<BusBillo
return Collections.emptyList(); return Collections.emptyList();
} }
// sheet为空表示不走下面的代码 // sheet为空表示不走下面的代码
if (StringUtils.isBlank(bo.getSheet())) { // if (StringUtils.isBlank(bo.getSheet())) {
return flatList; // return flatList;
} // }
// 2. 构建父子映射key=父节点pidvalue=该父节点的所有子节点 // 2. 构建父子映射key=父节点pidvalue=该父节点的所有子节点
Map<String, List<ObtainTheListRes>> parentMap = flatList.stream() Map<String, List<ObtainTheListRes>> parentMap = flatList.stream()
.collect(Collectors.groupingBy(ObtainTheListRes::getPid)); .collect(Collectors.groupingBy(ObtainTheListRes::getPid));
@ -337,7 +352,8 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl<BusBillo
public List<BusBillofquantitiesVo> obtainAllClassification(ObtainAllVersionNumbersReq bo) { public List<BusBillofquantitiesVo> obtainAllClassification(ObtainAllVersionNumbersReq bo) {
LambdaQueryWrapper<BusBillofquantitiesVersions> lqw = Wrappers.lambdaQuery(); LambdaQueryWrapper<BusBillofquantitiesVersions> lqw = Wrappers.lambdaQuery();
lqw.eq(bo.getProjectId() != null, BusBillofquantitiesVersions::getProjectId, bo.getProjectId()); 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<BusBillofquantitiesVersionsVo> result = baseMapper.selectVoList(lqw); List<BusBillofquantitiesVersionsVo> result = baseMapper.selectVoList(lqw);
List<String> versionss = new ArrayList<>(); List<String> versionss = new ArrayList<>();
result.forEach(v -> versionss.add(v.getVersions())); result.forEach(v -> versionss.add(v.getVersions()));