From e49d26ed810f3dc3167103e6ced0025b6c72907a Mon Sep 17 00:00:00 2001
From: zhangjian <zhangjianrock@163.com>
Date: Thu, 21 Sep 2023 11:51:41 +0800
Subject: [PATCH] 修改服务IP地址
---
ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java | 153 ++++++++++++++++++++++++--------------------------
1 files changed, 73 insertions(+), 80 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..9fd511f 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
@@ -63,6 +61,7 @@
@ApiOperation("根据权限获取设备列表")
@GetMapping("getEquipmentListByUser")
public Results getEquipmentListByUser(){
+ //查询用户ID
String usersId = SecurityUtils.getUserId();
//根据userId查询部门Id
SysUser sysUser = sysUserService.selectUserById(usersId);
@@ -79,41 +78,36 @@
return Results.succeed("没有设备信息");
}
Map<String, Object> mapResult = (Map<String, Object>) JSON.parse((String) result);
- JSONArray jsonArray = new JSONArray();
- //ancestors字段最长的数据
- String longest = "";
//等级
int count0 = 0,count1 = 0,count2 = 0;
//装数据
- List<HealthVo> healthVos = new ArrayList<>();
+ List<TreeDeptWell> treeDeptWells = new ArrayList<>();
if ((int) mapResult.get("code") == 200) {
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++) {
- String ancestors = list.get(j).getAncestors();
- if (ancestors.length() > longest.length()) {
- longest = ancestors;
- }
String wellId = list.get(j).getWellId();
if(wellId!=null){
if(wellId.equals(equipNumber)){
//返回设备数据
- HealthVo healthVo = new HealthVo();
- healthVo.setId((Integer) listResult.get(i).get("id"));
- healthVo.setEquipName((String) listResult.get(i).get("EquipName"));
- healthVo.setEquipNumber((String) listResult.get(i).get("EquipNumber"));
- healthVo.setEquipLevel((String) listResult.get(i).get("EquipLevel"));
- healthVo.setEquipKey((String) listResult.get(i).get("EquipKey"));
- healthVo.setMeasureDate((String) listResult.get(i).get("MeasureDate"));
- healthVo.setLongitude(list.get(j).getLongitude());
- healthVo.setLatitude(list.get(j).getLatitude());
- healthVo.setAltitude(list.get(j).getAltitude());
- healthVo.setDeptId(list.get(j).getDeptId());
- healthVos.add(healthVo);
+ TreeDeptWell treeDeptWell = new TreeDeptWell();
+ treeDeptWell.setId((Integer) listResult.get(i).get("id"));
+ treeDeptWell.setEquipName((String) listResult.get(i).get("EquipName"));
+ treeDeptWell.setEquipNumber((String) listResult.get(i).get("EquipNumber"));
+ treeDeptWell.setEquipLevel((String) listResult.get(i).get("EquipLevel"));
+ treeDeptWell.setEquipKey((String) listResult.get(i).get("EquipKey"));
+ treeDeptWell.setMeasureDate((String) listResult.get(i).get("MeasureDate"));
+ treeDeptWell.setLongitude(list.get(j).getLongitude());
+ treeDeptWell.setLatitude(list.get(j).getLatitude());
+ treeDeptWell.setAltitude(list.get(j).getAltitude());
+ treeDeptWell.setDeptId(list.get(j).getDeptId());
+ treeDeptWell.setAncestors(list.get(j).getAncestors());
+ treeDeptWell.setParentId(list.get(j).getParentId());
+ treeDeptWell.setDeptName(list.get(j).getDeptName());
+ treeDeptWells.add(treeDeptWell);
if(listResult.get(i).get("EquipLevel").equals("0")){
count0++;
}else if(listResult.get(i).get("EquipLevel").equals("1")){
@@ -127,69 +121,68 @@
}
}
}
- //用逗号分隔字符后的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++) {
+ //部门ID
+ SysDept sysDept = sysDepts.get(i);
+ Long deptId = sysDept.getDeptId();
+ for (int j = 0; j < treeDeptWells.size(); j++) {
+ //设备的部门ID
+ TreeDeptWell healthVo = treeDeptWells.get(j);
+ Long healthDeptId = healthVo.getDeptId();
+ if(deptId.equals(healthDeptId)){
+ //父级结构赋值
+ String thisAncestors = healthVo.getAncestors();
+ List<String> ancestorsA = Arrays.asList(thisAncestors.split(","));
+ ancestorsA.removeAll(userParentId);
+ for (int k = 0; k < ancestorsA.size(); k++) {
+ Long ancestor = Long.parseLong(ancestorsA.get(k));
+ //循环最终List判断是否有该数据的父级,如果没有就填进去
+ boolean wellTrue = false;
+ if(ancestor==0){
+ //父类集合为0则是最顶级上面没有
+ wellTrue = true;
+ }else {
+ for (int l = 0; l < treeDeptWells.size(); l++) {
+ //如果该父类集合在结构中已经存在并且不是设备数据就不用重复添加了
+ Long treeId = treeDeptWells.get(l).getDeptId();
+ Integer id = treeDeptWells.get(l).getId();
+ if(ancestor.equals(treeId) && id==null){
+ 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.setParentId(sysDept1.getParentId());
+ treeDeptWells.add(treeDeptWell);
}
}
}
}
}
+ List<TreeDeptWell> tree = sysDeptService.wellTree(treeDeptWells);
TreeSelectWellJson treeSelectWellJson = new TreeSelectWellJson();
treeSelectWellJson.setWellList(tree);
treeSelectWellJson.setCount0(count0);
--
Gitblit v1.9.3