|  |  |  | 
|---|
|  |  |  | 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.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; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Administrator | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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(){ | 
|---|
|  |  |  | //查询用户ID | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | //等级 | 
|---|
|  |  |  | int count0 = 0,count1 = 0,count2 = 0; | 
|---|
|  |  |  | //装数据 | 
|---|
|  |  |  | 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++) { | 
|---|
|  |  |  | String equipNumber = (String) listResult.get(i).get("EquipNumber"); | 
|---|
|  |  |  | if(equipNumber!=null){ | 
|---|
|  |  |  | for (int j = 0; j < list.size(); j++) { | 
|---|
|  |  |  | String wellId = list.get(j).getWellId(); | 
|---|
|  |  |  | if(wellId!=null){ | 
|---|
|  |  |  | if(wellId.equals(equipNumber)){ | 
|---|
|  |  |  | //返回设备数据 | 
|---|
|  |  |  | 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")){ | 
|---|
|  |  |  | count1++; | 
|---|
|  |  |  | }else if(listResult.get(i).get("EquipLevel").equals("2")){ | 
|---|
|  |  |  | count2++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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 { | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 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("获取设备列表") | 
|---|
|  |  |  | 
|---|
|  |  |  | @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()); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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')") | 
|---|
|  |  |  | 
|---|
|  |  |  | @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++) { | 
|---|
|  |  |  | 
|---|
|  |  |  | String token = (String) ((Map<String, Object>) ((Map<String, Object>) loginResult.get("data")).get("data")).get("token"); | 
|---|
|  |  |  | String GetEquipmentAlertInfoUrl = url + "/RoadFlowApi/ZX/MeasureData/GetEquipmentAlertInfo"; | 
|---|
|  |  |  | Map<String, Object> map = EquipmentsHealthClient.GetEquipmentAlertInfo(GetEquipmentAlertInfoUrl, token,id); | 
|---|
|  |  |  | return Results.succeed(map); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|