‘liusuyi’
2023-09-21 c6a05cc862a98abd7d16560e7ac2ab9bf4e12feb
ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java
@@ -3,9 +3,12 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell;
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;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
@@ -30,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
@@ -55,10 +55,13 @@
    @Autowired
    private ISysDeptService sysDeptService;
    @PreAuthorize("@ss.hasPermi('sy:syCar:getEquipmentListByUser')")
    @ApiOperation("根据权限获取设备列表")
    @GetMapping("getEquipmentListByUser")
    public Results getEquipmentListByUser(){
        //查询用户ID
        String usersId = SecurityUtils.getUserId();
        //根据userId查询部门Id
        SysUser sysUser = sysUserService.selectUserById(usersId);
@@ -75,42 +78,34 @@
            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<>();
        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)){
                                String[] ancestorsArray = ancestors.split(",");
                                int max = ancestorsArray.length;
                                jsonObject.put("id",listResult.get(i).get("id"));
                                jsonObject.put("EquipName",listResult.get(i).get("EquipName"));
                                jsonObject.put("EquipNumber",listResult.get(i).get("EquipNumber"));
                                jsonObject.put("EquipLevel",listResult.get(i).get("EquipLevel"));
                                jsonObject.put("MeasureDate",listResult.get(i).get("MeasureDate"));
                                jsonObject.put("EquipKey",listResult.get(i).get("EquipKey"));
                                jsonObject.put("longitude",list.get(j).getLongitude());
                                jsonObject.put("latitude",list.get(j).getLatitude());
                                jsonObject.put("altitude",list.get(j).getAltitude());
                                jsonObject.put("deptId",list.get(j).getDeptId());
                                jsonObject.put("deptName",list.get(j).getDeptName());
                                jsonObject.put("parentId",list.get(j).getParentId());
                                jsonObject.put("ancestors",list.get(j).getAncestors());
                                jsonObject.put("tier",max);
                                jsonArray.add(jsonObject);
                                //返回设备数据
                                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());
                                healthVo.setAncestors(list.get(j).getAncestors());
                                healthVos.add(healthVo);
                                if(listResult.get(i).get("EquipLevel").equals("0")){
                                    count0++;
                                }else if(listResult.get(i).get("EquipLevel").equals("1")){
@@ -124,14 +119,85 @@
                    }
                }
            }
            //用逗号分隔字符后的size为最大的结构层数
            String[] ancestorsArray = longest.split(",");
            int max = ancestorsArray.length;
            JSONObject j = new JSONObject();
            j.put("count0",count0);
            j.put("count1",count1);
            j.put("count2",count2);
            return Results.succeed(jsonArray);
            //根据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 {
                        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 < 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);
            treeSelectWellJson.setCount1(count1);
            treeSelectWellJson.setCount2(count2);
            return Results.succeed(treeSelectWellJson);
        } else {
            //错误提示
            return Results.error((String) mapResult.get("errmsg"));