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

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")
public R<List<BusBillofquantities>> obtainTheList(CoryObtainTheListReq req) {
// public R<List<ObtainTheListRes>> obtainTheList(CoryObtainTheListReq req) {
BusBillofquantitiesVersions one = busBillofquantitiesVersionsService.getOne(Wrappers.<BusBillofquantitiesVersions>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<BusBillofquantities> list = busBillofquantitiesService.list(Wrappers.<BusBillofquantities>lambdaQuery()
.eq(BusBillofquantities::getVersions, one.getVersions())
);
// BusBillofquantitiesVersions one = busBillofquantitiesVersionsService.getOne(Wrappers.<BusBillofquantitiesVersions>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<BusBillofquantities> list = busBillofquantitiesService.list(Wrappers.<BusBillofquantities>lambdaQuery()
// .eq(BusBillofquantities::getVersions, one.getVersions())
// );
// return R.ok(list);
// List<ObtainTheListRes> obtainTheListRes = new ArrayList<>();
// list.forEach(billofquantities -> {
// ObtainTheListRes res = new ObtainTheListRes();
@ -208,8 +209,7 @@ public class BusMrpBaseController extends BaseController {
// // 3. 递归组装树形结构从顶级节点pid=0开始
// List<ObtainTheListRes> treeList = buildTree("0", parentMap);
// 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) {

View File

@ -208,48 +208,63 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl<BusBillo
//1、获取到解析数据
ExcelReader.ExcelData excelData = ExcelReader.readExcelFromMultipartFile(file);
//走正常的工程清单
if (!Objects.equals(bo.getWorkOrderType(), "3")) {
// 2. 解析所有工作表转换为带父子关系的ExcelMaterial列表 解析所有Sheet数据按规则生成sid和pid
List<BusBillofquantities> allMaterials = new ArrayList<>();
for (ExcelReader.SheetData sheetData : excelData.getSheetDataList()) {
String sheetName = sheetData.getSheetName();
List<List<String>> rowDataList = sheetData.getData();
// 构建当前Sheet的树形结构复用ExcelReader的buildTree方法
ExcelReader.TreeNode rootNode = ExcelReader.buildTree(rowDataList);
// 存储节点映射TreeNode → ExcelMaterial用于子节点关联父节点
Map<ExcelReader.TreeNode, BusBillofquantities> nodeMap = new HashMap<>();
// 递归遍历树形结构生成sid和pid
traverseTree(rootNode, nodeMap, allMaterials, sheetName, banBen);
// if (!Objects.equals(bo.getWorkOrderType(), "3")) {
// 2. 解析所有工作表转换为带父子关系的ExcelMaterial列表 解析所有Sheet数据按规则生成sid和pid
List<BusBillofquantities> allMaterials = new ArrayList<>();
for (ExcelReader.SheetData sheetData : excelData.getSheetDataList()) {
String sheetName = sheetData.getSheetName();
List<List<String>> rowDataList = sheetData.getData();
// 构建当前Sheet的树形结构复用ExcelReader的buildTree方法
ExcelReader.TreeNode rootNode = ExcelReader.buildTree(rowDataList);
// 存储节点映射TreeNode → ExcelMaterial用于子节点关联父节点
Map<ExcelReader.TreeNode, BusBillofquantities> nodeMap = new HashMap<>();
// 递归遍历树形结构生成sid和pid
traverseTree(rootNode, nodeMap, allMaterials, sheetName, banBen);
}
// 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());
}
// 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<MaterialsAndEquipmentExcelDto> dataList = ExcelDynamicReader.readExcel(
file, // 上传的文件
1, // 跳过1行表头
0, // 从第0列开始
5, // 到第5列结束
MaterialsAndEquipmentExcelDto.class // 目标实体类
);
List<BusBillofquantities> 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<MaterialsAndEquipmentExcelDto> dataList = ExcelDynamicReader.readExcel(
// file, // 上传的文件
// 1, // 跳过1行表头
// 0, // 从第0列开始
// 5, // 到第5列结束
// MaterialsAndEquipmentExcelDto.class // 目标实体类
// );
// List<BusBillofquantities> 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<BusBillo
return Collections.emptyList();
}
// sheet为空表示不走下面的代码
if (StringUtils.isBlank(bo.getSheet())) {
return flatList;
}
// if (StringUtils.isBlank(bo.getSheet())) {
// return flatList;
// }
// 2. 构建父子映射key=父节点pidvalue=该父节点的所有子节点
Map<String, List<ObtainTheListRes>> parentMap = flatList.stream()
.collect(Collectors.groupingBy(ObtainTheListRes::getPid));
@ -337,7 +352,8 @@ public class BusBillofquantitiesVersionsServiceImpl extends ServiceImpl<BusBillo
public List<BusBillofquantitiesVo> obtainAllClassification(ObtainAllVersionNumbersReq bo) {
LambdaQueryWrapper<BusBillofquantitiesVersions> 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<BusBillofquantitiesVersionsVo> result = baseMapper.selectVoList(lqw);
List<String> versionss = new ArrayList<>();
result.forEach(v -> versionss.add(v.getVersions()));