修改物资设备清单导入和批次需求计划新增
This commit is contained in:
@ -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) {
|
||||||
|
|||||||
@ -208,48 +208,63 @@ 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()) {
|
||||||
String sheetName = sheetData.getSheetName();
|
String sheetName = sheetData.getSheetName();
|
||||||
List<List<String>> rowDataList = sheetData.getData();
|
List<List<String>> rowDataList = sheetData.getData();
|
||||||
// 构建当前Sheet的树形结构(复用ExcelReader的buildTree方法)
|
// 构建当前Sheet的树形结构(复用ExcelReader的buildTree方法)
|
||||||
ExcelReader.TreeNode rootNode = ExcelReader.buildTree(rowDataList);
|
ExcelReader.TreeNode rootNode = ExcelReader.buildTree(rowDataList);
|
||||||
// 存储节点映射:TreeNode → ExcelMaterial(用于子节点关联父节点)
|
// 存储节点映射:TreeNode → ExcelMaterial(用于子节点关联父节点)
|
||||||
Map<ExcelReader.TreeNode, BusBillofquantities> nodeMap = new HashMap<>();
|
Map<ExcelReader.TreeNode, BusBillofquantities> nodeMap = new HashMap<>();
|
||||||
// 递归遍历树形结构,生成sid和pid
|
// 递归遍历树形结构,生成sid和pid
|
||||||
traverseTree(rootNode, nodeMap, allMaterials, sheetName, banBen);
|
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) {
|
for (BusBillofquantities allMaterial : allMaterials) {
|
||||||
allMaterial.setProjectId(bo.getProjectId());
|
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();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
// sheet为空表示不走下面的代码
|
// sheet为空表示不走下面的代码
|
||||||
if (StringUtils.isBlank(bo.getSheet())) {
|
// if (StringUtils.isBlank(bo.getSheet())) {
|
||||||
return flatList;
|
// return flatList;
|
||||||
}
|
// }
|
||||||
// 2. 构建父子映射:key=父节点pid,value=该父节点的所有子节点
|
// 2. 构建父子映射:key=父节点pid,value=该父节点的所有子节点
|
||||||
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()));
|
||||||
|
|||||||
Reference in New Issue
Block a user