aijinhui
2023-09-19 2b0d7956faa548b2f913a333fbd2d0d99aedfa90
ard-work/src/main/java/com/ruoyi/health/controller/HealthController.java
@@ -1,12 +1,24 @@
package com.ruoyi.health.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.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;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.health.client.EquipmentsHealthClient;
import com.ruoyi.health.param.GetEquipmentAlertInfoParam;
import com.ruoyi.health.param.GetFMTrendParam;
import com.ruoyi.health.param.GetTrendParam;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.utils.result.Results;
import com.ruoyi.utils.soap.ARDSoapUtil;
import io.swagger.annotations.Api;
@@ -17,8 +29,10 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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;
@@ -33,6 +47,160 @@
    @Autowired
    ISysConfigService configService;
    @Resource
    private IArdAlarmpointsWellService ardAlarmpointsWellService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private ISysDeptService sysDeptService;
    @PreAuthorize("@ss.hasPermi('sy:syCar:getEquipmentListByUser')")
    @ApiOperation("根据权限获取设备列表")
    @GetMapping("getEquipmentListByUser")
    public Results getEquipmentListByUser(){
        String usersId = SecurityUtils.getUserId();
        //根据userId查询部门Id
        SysUser sysUser = sysUserService.selectUserById(usersId);
        //根据当前deptId或者当前及所属下级的所有deptId
        List<Long> deptList = sysDeptService.deptIdBySub(sysUser.getDeptId());
        //根据deptId获取对应所有兴趣点数据
        List<ArdAlarmpointsWellDeptVo> list = ardAlarmpointsWellService.wellListDept(deptList);
        //查询接口返回的设备列表
        String url = configService.getHealth();
        Map<String, Object> map = new HashMap();
        String result = ARDSoapUtil.postSoapResult(url, "GetEquipmentList", map);
        if ("".equals(result)) {
            //返回结果为空
            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)){
                                //返回设备数据
                                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);
                                if(listResult.get(i).get("EquipLevel").equals("0")){
                                    count0++;
                                }else if(listResult.get(i).get("EquipLevel").equals("1")){
                                    count1++;
                                }else if(listResult.get(i).get("EquipLevel").equals("2")){
                                    count2++;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            //用逗号分隔字符后的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;
                    }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;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            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"));
        }
    }
    @PreAuthorize("@ss.hasPermi('sy:syCar:getEquipmentList')")
    @ApiOperation("获取设备列表")
@@ -322,7 +490,9 @@
    @PreAuthorize("@ss.hasPermi('sy:syCar:GetEquipmentAlertInfo')")
    @ApiOperation("根据ID获取详细说明")
    @GetMapping("GetEquipmentAlertInfo")
    public Results GetEquipmentAlertInfo(Integer id){
    public  Results GetEquipmentAlertInfo(GetEquipmentAlertInfoParam param){
        Integer id = param.getId();
        String key = param.getPosition();
        List<SysConfig> sysConfigs = configService.getAccPwd();
        String account = null,password = null,url = null;
        for (int i = 0; i < sysConfigs.size(); i++) {
@@ -340,8 +510,19 @@
        String tokenUrl = url+"/RoadFlowApi/Home/ValidLogin";
        Map<String, Object> loginResult = EquipmentsHealthClient.getToken(tokenUrl, account, password);
        String token = (String) ((Map<String, Object>) ((Map<String, Object>) loginResult.get("data")).get("data")).get("token");
        String GetPartsAlertLeveUrl = url + "/RoadFlowApi/ZX/MeasureData/GetEquipmentAlertInfo";
        Map<String, Object> map = EquipmentsHealthClient.GetPartsAlertLeve(GetPartsAlertLeveUrl, token,id);
        return Results.succeed(map);
        String GetEquipmentAlertInfoUrl = url + "/RoadFlowApi/ZX/MeasureData/GetEquipmentAlertInfo";
        Map<String, Object> map = EquipmentsHealthClient.GetEquipmentAlertInfo(GetEquipmentAlertInfoUrl, token,id);
        List<Object> list = (List<Object>) ((Map<String, Object>) map.get("data")).get("rows");
        List<Map<String,Object>> rList = new ArrayList<>();
        if(list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                Map<String,Object> listMap = (Map<String, Object>) list.get(i);
                String position = (String) listMap.get("position");
                if(key.equals(position)){
                    rList.add(listMap);
                }
            }
        }
        return Results.succeed(rList);
    }
}