2
liusuyi
2026-05-12 9b5c9db9189493fbc6db48f55a7b7311b2a3253c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
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<Long> deptList = remoteDeptService.getDeptIdBySub(deptid, SecurityConstants.INNER).getData();
        //根据deptId获取对应所有兴趣点数据
        List<ArdWellDeptVo> list = ardWellService.wellListDept(deptList);
        if (list.isEmpty()) {
            //返回结果为空
            return AjaxResult.success("根据deptId获取对应所有兴趣点数据为空");
        }
        Map<String, Object> map = new HashMap();
        String result = ARDSoapUtil.postSoapResult(url, "GetEquipmentList", map);
        if ("".equals(result)) {
            //返回结果为空
            return AjaxResult.success("没有设备信息");
        }
        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"));
            //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<SysDept> sysDepts = remoteDeptService.getAllByUser(deptList.toArray(new Long[0]), SecurityConstants.INNER).getData();
            //循环查询出该用户的所有上级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;
                }
            }
            //把部门层级和数据结合
            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 = 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<TreeDeptWell> 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<List<AlertInfoDto>> getAlertInfoInner() {
        //报警接口要传number,目前没有找到文档说明number是做什么的,传什么结果都未变化。
        String number = "1";
        List<AlertInfoDto> alertInfoLs = healthService.getAlertInfo(number);
        return R.ok(alertInfoLs);
    }
}