From 39a88b3fd870ad8a65f356561b42d465c4f2fc42 Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期二, 26 九月 2023 09:35:28 +0800
Subject: [PATCH] 设备健康列表

---
 ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java |  187 +++++++++++++++++++++++-----------------------
 1 files changed, 93 insertions(+), 94 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..6637e42 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);
+            //寰幆鏌ヨ鍑鸿鐢ㄦ埛鐨勬墍鏈変笂绾D
+            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++) {
+                    //璁惧鐨勯儴闂↖D
+                    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));
+                            //寰幆鏈�缁圠ist鍒ゆ柇鏄惁鏈夎鏁版嵁鐨勭埗绾э紝濡傛灉娌℃湁灏卞~杩涘幓
+                            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);
@@ -303,7 +296,7 @@
     @PreAuthorize("@ss.hasPermi('sy:syCar:getTrend')")
     @ApiOperation("鑾峰彇鏌愭补浜曚竴娈垫椂闂寸殑娴嬮噺瓒嬪娍")
     @GetMapping("getTrend")
-    public Results getTrend(GetTrendParam getTrendParam){
+    public JSONObject getTrend(GetTrendParam getTrendParam){
         String url = configService.getHealth();
         Map<String , Object> map = new HashMap<String , Object>();
         map.put("MeasureKey", getTrendParam.getMeasureKey());
@@ -312,29 +305,35 @@
         JSONObject j = new JSONObject();
         String result = ARDSoapUtil.postSoapResult(url ,"GetTrend" ,  map);
         if ("".equals(result)){
-            return Results.succeed("娌℃湁娴嬬偣淇℃伅");
+            j.put("msg", "娌℃湁娴嬬偣淇℃伅");
+            j.put("code", 500);
         }
         Map<String,Object> mapResult = (Map<String, Object>) JSON.parse((String)result);
         if ( (int) mapResult.get("code") == 200){
             j.put("code", mapResult.get("code"));
             List<Map<String , Object>> listResult = (List<Map<String, Object>>)JSON.parse((String)mapResult.get("resdata"));
-            for(int i = 0 ; i<listResult.size(); i++){
-                Map<String , Object> mapTemp = listResult.get(i);
-                int id = (Integer)mapTemp.get("id");   //涓婚敭id
-                BigDecimal value = (BigDecimal)mapTemp.get("Value");  //鏁板��
-                String measureStr = (String)mapTemp.get("MeasureDate");  //娴嬮噺鏃堕棿
-                measureStr = measureStr.substring(measureStr.indexOf("(")+1, measureStr.indexOf(")",2));
-                SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                String measureDate = f.format(Long.valueOf(measureStr));
-                mapTemp.put("MeasureDate", measureDate);
-                j.put(id +"" , mapTemp);
+
+            if(listResult.size()>0){
+                for(int i = 0 ; i<listResult.size(); i++){
+                    Map<String , Object> mapTemp = listResult.get(i);
+                    BigDecimal value = (BigDecimal)mapTemp.get("Value");  //鏁板��
+                    String measureStr = (String)mapTemp.get("MeasureDate");  //娴嬮噺鏃堕棿
+                    measureStr = measureStr.substring(measureStr.indexOf("(")+1, measureStr.indexOf(")",2));
+                    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    String measureDate = f.format(Long.valueOf(measureStr));
+                    mapTemp.put("MeasureDate", measureDate);
+                    mapTemp.put("Value", value.setScale(2, BigDecimal.ROUND_HALF_UP));
+                }
+                j.put("data",listResult);
+            }else {
+                j.put("data",new ArrayList<>());
             }
         }else{
             //閿欒鎻愮ず
-            j.put("errmsg", mapResult.get("errmsg"));
+            j.put("msg", mapResult.get("errmsg"));
             j.put("code", mapResult.get("code"));
         }
-        return Results.succeed(j);
+        return j;
     }
 
     @PreAuthorize("@ss.hasPermi('sy:syCar:getWaveDataByIndex')")

--
Gitblit v1.9.3