diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/component/IPCFaultTreeTask.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/component/IPCFaultTreeTask.java new file mode 100644 index 0000000..3d7abe8 --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/component/IPCFaultTreeTask.java @@ -0,0 +1,177 @@ +package com.inspur.industrial.component; + +import com.inspur.common.utils.spring.SpringUtils; +import com.inspur.equip.domain.IpcEquipInfo; +import com.inspur.equip.service.IIpcEquipInfoService; +import com.inspur.industrial.domain.IpcFaultTreeConfig; +import com.inspur.industrial.service.IIpcFaultTreeConfigService; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.Row; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Author zhangjunwen + * @create 2024/4/18 + */ +@Component("faultTask") +public class IPCFaultTreeTask{ + + public void taskRun() { + try { + faultExcelProcess(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private void faultExcelProcess() throws IOException { + TreeNode treeNode = new TreeNode(); + POIFSFileSystem fs = new POIFSFileSystem(Files.newInputStream(Paths.get("C:\\Users\\zhangjunwen\\Desktop\\故障树.xls"))); + HSSFWorkbook wb = new HSSFWorkbook(fs); + //2. 获取工作表 + //sheets.getSheet(); 根据选项卡名称,即工作表名称 + //根据索引获取工作表 +// XSSFSheet sheetAt = sheets.getSheetAt(0); + HSSFSheet sheetAt = wb.getSheetAt(1); + int columnNum = 0; + if(sheetAt.getRow(0) != null){ + columnNum = sheetAt.getRow(0).getLastCellNum() - sheetAt.getRow(0).getFirstCellNum(); + + } + + // 初始化一些计数器 + int id = 0; // 遍历赋值连续ID + int level = 0;// 记录层级 + int rowNumber = 0;// 记录行号 + treeNode.setId("-2"); + treeNode.setName("关系图"); + treeNode.setChild(new ArrayList()); + // 初始化一个缓存map , 用于缓存最新的父类 + HashMap map = new HashMap(); + map.put(-2, treeNode); + // 开始遍历 + if (columnNum > 0) { + for (Row row : sheetAt) { + level = 0; + rowNumber++; + // 跳过前两行 + if (rowNumber < 2) { + continue; + } + + String[] singleRow = new String[columnNum]; + for (int i = 0; i < columnNum; i++) { + // 查询到有信息的行 + Cell cell = row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); + if(cell.getCellType() == CellType.BLANK || i % 2 != 0){ + continue; + } + id++; + TreeNode treeNodeTmp = new TreeNode(); + treeNodeTmp.setId("" + id); + treeNodeTmp.setName(cell.getStringCellValue()); + treeNodeTmp.setChild(new ArrayList()); + treeNodeTmp.setType(sheetAt.getRow(row.getRowNum()).getCell(i + 1) == null ? "" : sheetAt.getRow(row.getRowNum()).getCell(i + 1).getStringCellValue()); + TreeNode pTreeNode = map.get(i - 2); + pTreeNode.getChild().add(treeNodeTmp); + + map.put(i, treeNodeTmp); + } + } + } +// System.err.println(treeNode); + insertNode(treeNode.getChild().get(0), 1L); + //5. 释放资源 + wb.close(); + } + + private void insertNode(TreeNode node, Long parentId){ + // 1. 插入当前节点到数据库 + IIpcFaultTreeConfigService ipcFaultTreeConfigService = SpringUtils.getBean(IIpcFaultTreeConfigService.class); + IIpcEquipInfoService ipcEquipInfoService = SpringUtils.getBean(IIpcEquipInfoService.class); + IpcFaultTreeConfig ipcFaultTreeConfig = new IpcFaultTreeConfig(); + ipcFaultTreeConfig.setNodeName(node.getName()); + ipcFaultTreeConfig.setParentId(parentId); + List equipInfos = ipcEquipInfoService.selectIpcEquipInfoList(null); + ipcFaultTreeConfig.setEquipId(equipInfos.stream().filter(data -> data.getEquipNum().equals("KKZGG-T-001")).collect(Collectors.toList()).get(0).getId()); + ipcFaultTreeConfig.setNodeDefaultColor("green"); + ipcFaultTreeConfig.setNodeAlarmColor("red"); + ipcFaultTreeConfig.setStatus("0"); + ipcFaultTreeConfig.setDelFlag("0"); + if(node.getType().equals("或") || node.getType().startsWith("条件或")) { + ipcFaultTreeConfig.setNodeShapeType("rectangle"); + ipcFaultTreeConfig.setIconCls("icon-huomen"); + }else if(node.getType().equals("与")) { + ipcFaultTreeConfig.setNodeShapeType("rectangle"); + ipcFaultTreeConfig.setIconCls("icon-yumen"); + } + ipcFaultTreeConfig.setCreateTime(new Date()); + ipcFaultTreeConfigService.insertIpcFaultTreeConfig(ipcFaultTreeConfig); + List faults = ipcFaultTreeConfigService.selectIpcFaultTreeConfigList(ipcFaultTreeConfig); + if(node.getChild() == null){ + return; + } + // 3. 递归处理子节点 + for (TreeNode child : node.getChild()) { + insertNode(child, faults.get(0).getNodeId()); + } + } +} + +class TreeNode { + private String name;// 名称 + private String id;// id + private String pid;//父ID + + private String type; + private List child; + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public List getChild() { + return child; + } + public void setChild(List child) { + this.child = child; + } + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getPid() { + return pid; + } + public void setPid(String pid) { + this.pid = pid; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/zfipc-ui/src/views/faultTree/faultTreeShow.vue b/zfipc-ui/src/views/faultTree/faultTreeShow.vue index 761e698..53924de 100644 --- a/zfipc-ui/src/views/faultTree/faultTreeShow.vue +++ b/zfipc-ui/src/views/faultTree/faultTreeShow.vue @@ -27,9 +27,11 @@ @@ -55,6 +57,7 @@ export default { equipList: [], equipId: "", treeData: [], + expKeys: [], }; }, created() { @@ -67,10 +70,14 @@ export default { }, getList() { this.loading = true; + this.expKeys = []; getFaultTreeShow(this.equipId).then((response) => { const nodes = this.handleTree(response.data, "nodeId", "parentId"); + console.log("nodes:", nodes); + this.expKeys.push(nodes[0].children[0].nodeId); this.updateParentStatusBasedOnLogic(nodes); this.treeData = nodes[0].children; + const datalist = response.data; this.loading = false; }); }, @@ -159,6 +166,9 @@ export default { } } node.label = node.nodeName; + if (node.isAlarm === "1") { + this.expKeys.push(node.nodeId); + } node.nodeBorderColor = node.isAlarm === "1" ? node.nodeAlarmColor : node.nodeDefaultColor; node.nodeFontColor = @@ -169,7 +179,7 @@ export default { }; -