feat: 零部件firstNode历史数据处理接口
This commit is contained in:
+8
@@ -50,5 +50,13 @@ public class LawsPartNameController {
|
||||
return Result.OK(list);
|
||||
}
|
||||
|
||||
@AutoLog(value = "企业标准-零部件树历史数据处理")
|
||||
@ApiOperation(value = "企业标准-零部件树历史数据处理", notes = "企业标准-零部件树历史数据处理")
|
||||
@PostMapping("/hisDataFix")
|
||||
public Result<List<PartName>> hisDataFix() {
|
||||
partNameService.hisDataFix();
|
||||
return Result.OK();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -30,4 +30,9 @@ public interface PartNameService extends IService<PartName> {
|
||||
* @return 零部件树
|
||||
*/
|
||||
List<PartName> queryEcho(String selectNodeCodes);
|
||||
|
||||
/**
|
||||
* 零部件树历史数据处理
|
||||
*/
|
||||
void hisDataFix();
|
||||
}
|
||||
|
||||
+44
@@ -85,6 +85,50 @@ public class PartNameServiceImpl extends ServiceImpl<PartNameMapper, PartName>
|
||||
return partNameMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hisDataFix() {
|
||||
List<PartName> allDataList = list();
|
||||
// 遍历所有数据,填充firstNode字段
|
||||
// 找到树结构中每个节点的一级节点
|
||||
Map<String, PartName> nodeMap = allDataList.stream()
|
||||
.collect(Collectors.toMap(PartName::getCode, Function.identity()));
|
||||
|
||||
// 构建树形结构
|
||||
allDataList.forEach(node -> {
|
||||
PartName parentNode = nodeMap.get(node.getParentCode());
|
||||
if (parentNode != null) {
|
||||
if (parentNode.getChildPartNameList() == null) {
|
||||
parentNode.setChildPartNameList(new ArrayList<>());
|
||||
}
|
||||
parentNode.getChildPartNameList().add(node);
|
||||
}
|
||||
});
|
||||
|
||||
// 数据整理
|
||||
allDataList.forEach(node -> {
|
||||
if (!node.getParentCode().equals("Part") && node.getFirstNode() == null) {
|
||||
PartName firstNode = this.getFirstLevelNode(node, nodeMap);
|
||||
if (firstNode != null) {
|
||||
node.setFirstNode(firstNode.getCode());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 更新数据库
|
||||
updateBatchById(allDataList);
|
||||
}
|
||||
|
||||
private PartName getFirstLevelNode(PartName node, Map<String, PartName> nodeMap) {
|
||||
if (node.getParentCode().equals("Part")) {
|
||||
return node;
|
||||
}
|
||||
PartName parentNode = nodeMap.get(node.getParentCode());
|
||||
if (parentNode != null) {
|
||||
return getFirstLevelNode(parentNode, nodeMap);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user