From bbfaaf83f149707edd5c5b598d9d822141ced6fc Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: Wed, 20 Sep 2023 11:25:34 +0800
Subject: [PATCH] 设备健康列表
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java | 65 ++++++++++++
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java | 7 +
ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java | 135 +++++++++++++++-----------
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeDeptWell.java | 31 ++++++
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/HealthVo.java | 1
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelectWell.java | 10 -
6 files changed, 178 insertions(+), 71 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java b/ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java
index ff86ec3..1f3aab1 100644
--- a/ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java
+++ b/ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java
@@ -6,6 +6,7 @@
import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWellDeptVo;
import com.ruoyi.common.core.domain.HealthVo;
import com.ruoyi.alarmpoints.well.service.IArdAlarmpointsWellService;
+import com.ruoyi.common.core.domain.TreeDeptWell;
import com.ruoyi.common.core.domain.TreeSelectWell;
import com.ruoyi.common.core.domain.TreeSelectWellJson;
import com.ruoyi.common.core.domain.entity.SysConfig;
@@ -32,10 +33,7 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* @author Administrator
@@ -90,7 +88,6 @@
List<Map<String, Object>> listResult = (List<Map<String, Object>>) JSON.parse((String) mapResult.get("resdata"));
//循环得到权限下匹配数据
for (int i = 0; i < listResult.size(); i++) {
- JSONObject jsonObject = new JSONObject();
String equipNumber = (String) listResult.get(i).get("EquipNumber");
if(equipNumber!=null){
for (int j = 0; j < list.size(); j++) {
@@ -113,6 +110,7 @@
healthVo.setLatitude(list.get(j).getLatitude());
healthVo.setAltitude(list.get(j).getAltitude());
healthVo.setDeptId(list.get(j).getDeptId());
+ healthVo.setAncestors(list.get(j).getAncestors());
healthVos.add(healthVo);
if(listResult.get(i).get("EquipLevel").equals("0")){
count0++;
@@ -127,69 +125,88 @@
}
}
}
- //用逗号分隔字符后的size为最大的结构层数
- String[] ancestorsArray = longest.split(",");
- int max = ancestorsArray.length;
- //获取部门层级
- List<SysDept> sysDepts = sysDeptService.all();
- List<TreeSelectWell> tree = sysDeptService.wellTree(sysDepts);
- //循环数据挂在到部门层级下
- for (int i = 0; i < healthVos.size(); i++) {
- HealthVo healthVo = healthVos.get(i);
- Long deptId = healthVo.getDeptId();
- //循环树结构
- for (int j = 0; j < tree.size(); j++) {
- //如果第一层匹配赋值
- if(deptId.equals(tree.get(j).getId())){
- tree.get(j).getWell().add(healthVo);
- break;
+ //根据deptList查询出用户及以下的所有部门信息
+ List<SysDept> sysDepts = sysDeptService.allByUser(deptList);
+ //循环查询出该用户的所有上级ID
+ List<String> userParentId = new ArrayList<>();
+ for (int i = 0; i < sysDepts.size(); i++) {
+ Long userDeptId = sysDepts.get(i).getDeptId();
+ if(usersId.equals(userDeptId)){
+ String ancestors = sysDepts.get(i).getAncestors();
+ if(ancestors.contains(",")){
+ userParentId = Arrays.asList(ancestors.split(","));
}else {
- //不匹配且children大于0查询第二层
- if(tree.get(j).getChildren().size()>0){
- for (int k = 0; k < tree.get(j).getChildren().size(); k++) {
- //如果第二层匹配
- if(deptId.equals(tree.get(j).getChildren().get(k).getId())){
- tree.get(j).getChildren().get(k).getWell().add(healthVo);
- break;
- }else {
- //不匹配且children大于0查询第三层
- if(tree.get(j).getChildren().get(k).getChildren().size()>0){
- for (int l = 0; l < tree.get(j).getChildren().get(k).getChildren().size(); l++) {
- //如果第三层匹配
- if(deptId.equals(tree.get(j).getChildren().get(k).getChildren().get(l).getId())){
- tree.get(j).getChildren().get(k).getChildren().get(l).getWell().add(healthVo);
- break;
- }else {
- //不匹配且children大于0查询第四层
- if(tree.get(j).getChildren().get(k).getChildren().get(l).getChildren().size()>0){
- for (int m = 0; m < tree.get(j).getChildren().get(k).getChildren().get(l).getChildren().size(); m++) {
- //如果第四层匹配
- if(deptId.equals(tree.get(j).getChildren().get(k).getChildren().get(l).getChildren().get(m).getId())){
- tree.get(j).getChildren().get(k).getChildren().get(l).getChildren().get(m).getWell().add(healthVo);
- break;
- }else {
- //不匹配且children大于0查询第五层
- if(tree.get(j).getChildren().get(k).getChildren().get(l).getChildren().get(m).getChildren().size()>0){
- for (int n = 0; n < tree.get(j).getChildren().get(k).getChildren().get(l).getChildren().get(m).getChildren().size(); n++) {
- //如果第五层匹配
- if(deptId.equals(tree.get(j).getChildren().get(k).getChildren().get(l).getChildren().get(m).getChildren().get(n).getId())){
- tree.get(j).getChildren().get(k).getChildren().get(l).getChildren().get(m).getChildren().get(n).getWell().add(healthVo);
- break;
- }
- }
- }
- }
- }
- }
- }
+ userParentId.add(ancestors);
+ }
+ break;
+ }
+ }
+ //把部门层级和数据结合
+ List<TreeDeptWell> treeDeptWells = new ArrayList<>();
+ for (int i = 0; i < sysDepts.size(); i++) {
+ SysDept sysDept = sysDepts.get(i);
+ Long deptId = sysDept.getDeptId();
+ List<HealthVo> deptHealths = new ArrayList<>();
+ for (int j = 0; j < healthVos.size(); j++) {
+ HealthVo healthVo = healthVos.get(j);
+ Long healthDeptId = healthVo.getDeptId();
+ if(deptId.equals(healthDeptId)){
+ deptHealths.add(healthVo);
+ //父级结构赋值
+ String thisAncestors = healthVo.getAncestors();
+ List<String> ancestorsA = Arrays.asList(thisAncestors.split(","));
+ ancestorsA.removeAll(userParentId);
+// for (int k = 0; k < userParentId.size(); k++) {
+// String a = userParentId.get(k);
+// for (int l = 0; l < ancestorsA.size(); l++) {
+// String b = ancestorsA.get(l);
+// if(a.equals(b)){
+// ancestorsA.remove(b);
+// }
+// }
+// }
+ for (int k = 0; k < ancestorsA.size(); k++) {
+ Long ancestor = Long.parseLong(ancestorsA.get(k));
+ //循环最终List判断是否有该数据的父级,如果没有就填进去
+ boolean wellTrue = false;
+ if(ancestor==0){
+ wellTrue = true;
+ }else {
+ if(treeDeptWells.size()>0){
+ for (int l = 0; l < treeDeptWells.size(); l++) {
+ Long treeId = treeDeptWells.get(l).getDeptId();
+ if(ancestor.equals(treeId)){
+ wellTrue = true;
}
}
}
}
+ if(!wellTrue){
+ SysDept sysDept1 = sysDeptService.selectDeptById(ancestor);
+ TreeDeptWell treeDeptWell = new TreeDeptWell();
+ treeDeptWell.setDeptId(ancestor);
+ treeDeptWell.setAncestors(sysDept1.getAncestors());
+ treeDeptWell.setDeptName(sysDept1.getDeptName());
+ treeDeptWell.setOrderNum(sysDept1.getOrderNum());
+ treeDeptWell.setParentId(sysDept1.getParentId());
+ treeDeptWells.add(treeDeptWell);
+ }
}
}
}
+ if(deptHealths.size()>0){
+ //有设备展示
+ TreeDeptWell treeDeptWell = new TreeDeptWell();
+ treeDeptWell.setDeptId(deptId);
+ treeDeptWell.setAncestors(sysDept.getAncestors());
+ treeDeptWell.setDeptName(sysDept.getDeptName());
+ treeDeptWell.setOrderNum(sysDept.getOrderNum());
+ treeDeptWell.setParentId(sysDept.getParentId());
+ treeDeptWell.setWell(deptHealths);
+ treeDeptWells.add(treeDeptWell);
+ }
}
+ List<TreeSelectWell> tree = sysDeptService.wellTree(treeDeptWells);
TreeSelectWellJson treeSelectWellJson = new TreeSelectWellJson();
treeSelectWellJson.setWellList(tree);
treeSelectWellJson.setCount0(count0);
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/HealthVo.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/HealthVo.java
index d3dc190..3fa76a3 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/HealthVo.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/HealthVo.java
@@ -18,5 +18,6 @@
private BigDecimal longitude;
private BigDecimal latitude;
private BigDecimal altitude;
+ private String ancestors;
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeDeptWell.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeDeptWell.java
new file mode 100644
index 0000000..5eb85b0
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeDeptWell.java
@@ -0,0 +1,31 @@
+package com.ruoyi.common.core.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.ruoyi.common.core.domain.entity.SysDept;
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+public class TreeDeptWell {
+ private Long deptId;
+ /** 父部门ID */
+ private Long parentId;
+
+ /** 祖级列表 */
+ private String ancestors;
+
+ /** 部门名称 */
+ private String deptName;
+
+ /** 显示顺序 */
+ private Integer orderNum;
+
+ private List<HealthVo> well = new ArrayList<>();
+
+ @TableField(exist = false)
+ private List<TreeDeptWell> children = new ArrayList<TreeDeptWell>();
+
+}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelectWell.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelectWell.java
index df3a0bc..f8abd28 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelectWell.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelectWell.java
@@ -43,18 +43,12 @@
}
- public TreeSelectWell(SysDept dept)
+ public TreeSelectWell(TreeDeptWell dept)
{
this.id = dept.getDeptId();
this.label = dept.getDeptName();
+ this.well = dept.getWell();
this.children = dept.getChildren().stream().map(TreeSelectWell::new).collect(Collectors.toList());
- }
-
- public TreeSelectWell(SysMenu menu)
- {
- this.id = menu.getMenuId();
- this.label = menu.getMenuName();
- this.children = menu.getChildren().stream().map(TreeSelectWell::new).collect(Collectors.toList());
}
public Long getId()
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
index 40598fa..0b3d308 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
@@ -4,6 +4,7 @@
import java.util.Map;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.common.core.domain.TreeDeptWell;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.core.domain.TreeSelectWell;
import com.ruoyi.common.core.domain.entity.SysDept;
@@ -135,11 +136,13 @@
List<SysDept> all();
+ List<SysDept> allByUser(List<Long> deptList);
+
/**
* 预留结构的树形
* @param depts
* @return
*/
- List<TreeSelectWell> wellTree(List<SysDept> depts);
-
+ List<TreeSelectWell> wellTree(List<TreeDeptWell> depts);
+ List<TreeDeptWell> buildDeptWellTree(List<TreeDeptWell> depts);
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
index a7e0212..e0a4d85 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -4,6 +4,7 @@
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.common.core.domain.TreeDeptWell;
import com.ruoyi.common.core.domain.TreeSelectWell;
import org.springframework.stereotype.Service;
import com.ruoyi.common.annotation.DataScope;
@@ -358,10 +359,70 @@
}
@Override
- public List<TreeSelectWell> wellTree(List<SysDept> depts) {
- List<SysDept> deptTrees = buildDeptTree(depts);
+ public List<SysDept> allByUser(List<Long> deptList) {
+ QueryWrapper<SysDept> queryWrapper = new QueryWrapper();
+ queryWrapper.in("dept_id",deptList);
+ return deptMapper.selectList(queryWrapper);
+ }
+
+ @Override
+ public List<TreeSelectWell> wellTree(List<TreeDeptWell> depts) {
+ List<TreeDeptWell> deptTrees = buildDeptWellTree(depts);
return deptTrees.stream().map(TreeSelectWell::new).collect(Collectors.toList());
}
+ @Override
+ public List<TreeDeptWell> buildDeptWellTree(List<TreeDeptWell> depts)
+ {
+ List<TreeDeptWell> returnList = new ArrayList<TreeDeptWell>();
+ List<Long> tempList = depts.stream().map(TreeDeptWell::getDeptId).collect(Collectors.toList());
+ for (TreeDeptWell dept : depts)
+ {
+ // 如果是顶级节点, 遍历该父节点的所有子节点
+ if (!tempList.contains(dept.getParentId()))
+ {
+ recursionFnWell(depts, dept);
+ returnList.add(dept);
+ }
+ }
+ if (returnList.isEmpty())
+ {
+ returnList = depts;
+ }
+ return returnList;
+ }
+ private void recursionFnWell(List<TreeDeptWell> list, TreeDeptWell t)
+ {
+ // 得到子节点列表
+ List<TreeDeptWell> childList = getChildListWell(list, t);
+ t.setChildren(childList);
+ for (TreeDeptWell tChild : childList)
+ {
+ if (hasChildWell(list, tChild))
+ {
+ recursionFnWell(list, tChild);
+ }
+ }
+ }
+
+ private List<TreeDeptWell> getChildListWell(List<TreeDeptWell> list, TreeDeptWell t)
+ {
+ List<TreeDeptWell> tlist = new ArrayList<TreeDeptWell>();
+ Iterator<TreeDeptWell> it = list.iterator();
+ while (it.hasNext())
+ {
+ TreeDeptWell n = (TreeDeptWell) it.next();
+ if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue())
+ {
+ tlist.add(n);
+ }
+ }
+ return tlist;
+ }
+
+ private boolean hasChildWell(List<TreeDeptWell> list, TreeDeptWell t)
+ {
+ return getChildListWell(list, t).size() > 0;
+ }
}
--
Gitblit v1.9.3