package com.ard.work.health.controller; import com.alibaba.fastjson.JSON; import com.ard.common.core.constant.SecurityConstants; import com.ard.common.core.domain.R; import com.ard.common.core.web.controller.BaseController; import com.ard.common.core.web.domain.AjaxResult; import com.ard.common.core.web.domain.TreeDeptWell; import com.ard.common.core.web.domain.TreeSelectWellJson; import com.ard.common.security.annotation.InnerAuth; import com.ard.common.security.annotation.RequiresPermissions; import com.ard.common.security.utils.SecurityUtils; import com.ard.system.api.RemoteDeptService; import com.ard.system.api.RemoteUserService; import com.ard.system.api.domain.SysDept; import com.ard.system.api.domain.SysUser; import com.ard.work.api.domian.AlertInfoDto; import com.ard.work.health.domain.GetEquipmentAlertInfoParam; import com.ard.work.health.domain.GetFMTrendParam; import com.ard.work.health.domain.GetTrendParam; import com.ard.work.health.service.HealthService; import com.ard.work.point.well.domain.ArdWellDeptVo; import com.ard.work.point.well.service.IArdWellService; import com.ard.work.utils.soap.ARDSoapUtil; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; import jakarta.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.*; /** * 设备健康管理Controller * * @author XiaJiJian * @date 2024-09-18 */ @Tag(name = "设备健康管理") @RestController @RequestMapping("/health") public class HealthController extends BaseController { @Resource private HealthService healthService; @Resource private RemoteUserService remoteUserService; @Resource private RemoteDeptService remoteDeptService; @Resource private IArdWellService ardWellService; @Value("${health.url}") private String url; /** * 根据权限获取设备列表 */ @Operation(summary = "根据权限获取设备列表") @RequiresPermissions("point:health:listByUser") @GetMapping("/listByUser") public AjaxResult getListByUser() { Long usersId = SecurityUtils.getUserId(); //根据userId查询部门Id SysUser sysUser = remoteUserService.getUserInfoByUserId(usersId, SecurityConstants.INNER).getData(); Long deptid = sysUser.getDeptId(); //根据deptI的获取当前及所属下级,所有deptId List deptList = remoteDeptService.getDeptIdBySub(deptid, SecurityConstants.INNER).getData(); //根据deptId获取对应所有兴趣点数据 List list = ardWellService.wellListDept(deptList); if (list.isEmpty()) { //返回结果为空 return AjaxResult.success("根据deptId获取对应所有兴趣点数据为空"); } Map map = new HashMap(); String result = ARDSoapUtil.postSoapResult(url, "GetEquipmentList", map); if ("".equals(result)) { //返回结果为空 return AjaxResult.success("没有设备信息"); } Map mapResult = (Map) JSON.parse((String) result); //等级 int count0 = 0, count1 = 0, count2 = 0; //组装数据 List treeDeptWells = new ArrayList<>(); if ((int) mapResult.get("code") == 200) { List> listResult = (List>) JSON.parse((String) mapResult.get("resdata")); //System.out.println(String.valueOf(listResult)); //循环得到权限下匹配数据 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 sysDepts = remoteDeptService.getAllByUser(deptList.toArray(new Long[0]), SecurityConstants.INNER).getData(); //循环查询出该用户的所有上级ID List 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; } } //把部门层级和数据结合 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 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 = deptService.selectDeptById(ancestor); SysDept sysDept1 = remoteDeptService.getDeptById(ancestor, SecurityConstants.INNER).getData(); TreeDeptWell treeDeptWell = new TreeDeptWell(); treeDeptWell.setDeptId(ancestor); treeDeptWell.setAncestors(sysDept1.getAncestors()); treeDeptWell.setDeptName(sysDept1.getDeptName()); treeDeptWell.setParentId(sysDept1.getParentId()); treeDeptWells.add(treeDeptWell); } } } } } if (treeDeptWells.size() > 0) { List tree = remoteDeptService.getWellTree(treeDeptWells, SecurityConstants.INNER).getData(); TreeSelectWellJson treeSelectWellJson = new TreeSelectWellJson(); treeSelectWellJson.setWellList(tree); treeSelectWellJson.setCount0(count0); treeSelectWellJson.setCount1(count1); treeSelectWellJson.setCount2(count2); return AjaxResult.success(treeSelectWellJson); } else { return AjaxResult.error("无匹配数据"); } } else { //错误提示 return AjaxResult.error((String) mapResult.get("errmsg")); } } /*@Operation(summary = "根据权限获取设备列表") @RequiresPermissions("point:health:listByUser") @GetMapping("/listByUser")//zns改 public AjaxResult getListByUser() { return AjaxResult.success(); }*/ /** * 获取设备列表 */ @Operation(summary = "获取设备列表") @RequiresPermissions("point:health:getEquipmentList") @GetMapping("/getEquipmentList") public AjaxResult getEquipmentList() { return success(healthService.getEquipmentList()); } /** * 根据name获取某个油井测点列表 */ @Operation(summary = "根据name获取某个油井测点列表") @RequiresPermissions("point:health:getMeasureByEquipName") @GetMapping("/getMeasureByEquipName") public AjaxResult getMeasureByEquipName(String equipNumber) { return success(healthService.getMeasureByEquipName(equipNumber)); } /** * 获取某油井一段时间的测量趋势 */ @Operation(summary = "获取某油井一段时间的测量趋势") @RequiresPermissions("point:health:getTrend") @GetMapping("/getTrend") public AjaxResult getTrend(GetTrendParam getTrendParam) { return success(healthService.getTrend(getTrendParam)); } /** * 获取某次测量数据的图谱 */ @Operation(summary = "获取某次测量数据的图谱") @RequiresPermissions("point:health:getWaveDataByIndex") @GetMapping("/getWaveDataByIndex") public AjaxResult getWaveDataByIndex(String id) { return success(healthService.getWaveDataByIndex(id)); } /** * 获取某个测点的最后一次报警信息 */ @Operation(summary = "获取某个测点的最后一次报警信息") @RequiresPermissions("point:health:getAlertInfo") @GetMapping("/getAlertInfo") public AjaxResult getAlertInfo(String number) { return success(healthService.getAlertInfo(number)); } /** * 获取某异常问题(失效模式)的趋势 */ @Operation(summary = "获取某异常问题(失效模式)的趋势") @RequiresPermissions("point:health:getFMTrend") @GetMapping("/getFMTrend") public AjaxResult getFMTrend(GetFMTrendParam getFMTrendParam) { return success(healthService.getFMTrend(getFMTrendParam)); } /** * 根据key获取某个油井测点列表 */ @Operation(summary = "根据key获取某个油井测点列表") @RequiresPermissions("point:health:getMeasureByEquipKey") @GetMapping("/getMeasureByEquipKey") public AjaxResult getMeasureByEquipKey(String equipKey) { return success(healthService.getMeasureByEquipKey(equipKey)); } /** * 获取ID获取点位 */ @Operation(summary = "获取ID获取点位") @RequiresPermissions("point:health:GetPartsAlertLevel") @GetMapping("/GetPartsAlertLevel") public AjaxResult GetPartsAlertLevel(Integer id) { return success(healthService.GetPartsAlertLevel(id)); } /** * 根据ID获取详细说明 */ @Operation(summary = "根据ID获取详细说明") @RequiresPermissions("point:health:GetEquipmentAlertInfo") @GetMapping("/GetEquipmentAlertInfo") public AjaxResult GetEquipmentAlertInfo(GetEquipmentAlertInfoParam param) { return success(healthService.GetEquipmentAlertInfo(param)); } /** * 获取油井列表 */ @Operation(summary = "获取油井列表") @RequiresPermissions("point:health:GetTreeJsonX") @GetMapping("/GetTreeJsonX") public AjaxResult getTreeJsonX() { return success(healthService.getTreeJsonX()); } /** * 内部接口-获取某个测点的最后一次报警信息 */ @InnerAuth @GetMapping("/getAlertInfoInner") public R> getAlertInfoInner() { //报警接口要传number,目前没有找到文档说明number是做什么的,传什么结果都未变化。 String number = "1"; List alertInfoLs = healthService.getAlertInfo(number); return R.ok(alertInfoLs); } }