leutu
2024-05-20 a4e99a6a39284643fdf2b04dbe55212e5954973c
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
package com.skyline.electricity.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.*;
import org.springframework.beans.factory.annotation.*;
import com.skyline.electricity.service.*;
import com.skyline.electricity.entity.*;
import com.skyline.electricity.utils.*;
import org.springframework.web.client.*;
import org.springframework.http.client.*;
import java.nio.charset.*;
import org.springframework.http.converter.*;
import cn.hutool.json.*;
import org.springframework.util.*;
import org.springframework.http.*;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.*;
import com.skyline.electricity.pojo.*;
import java.util.*;
import org.slf4j.*;
 
@Controller
@RequestMapping({ "/device" })
@Api("基于Swagger的电力区域报警系统")
@CrossOrigin
public class DeviceController
{
    private static Logger log;
    @Autowired
    private DetectService detectService;
    @Autowired
    OutService outService;
    @Autowired
    private ConfigInfo configInfo;
 
    @RequestMapping(value = { "/getCameraEntity" }, method = { RequestMethod.POST })
    @ApiOperation("获取摄像头实体列表")
    @ResponseBody
    public Object getCameraEntity(final String modId, final String modKey, final Integer pageNum, final Integer pageSize) {
        final RestTemplate restTemplate = new RestTemplate((ClientHttpRequestFactory)new HttpsClientRequestFactory());
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        final Map<Object, Object> params = new HashMap<Object, Object>();
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        params.put("modId", modId);
        params.put("modKey", modKey);
        params.put("pageNum", pageNum);
        params.put("pageSize", pageSize);
        final cn.hutool.json.JSONObject jsonObject = JSONUtil.parseFromMap((Map)params);
        final HttpEntity<cn.hutool.json.JSONObject> httpEntity = (HttpEntity<cn.hutool.json.JSONObject>)new HttpEntity((Object)jsonObject, (MultiValueMap)headers);
        final ResponseEntity<String> responseEntity = (ResponseEntity<String>)restTemplate.postForEntity(this.configInfo.getDevice_ip()+   "/restapi/iot/iotinfomgr/entityList?apikey="  + this.configInfo.getApikey(), (Object)httpEntity, (Class)String.class, new Object[0]);
        final String body = (String)responseEntity.getBody();
        final JSONObject jsonObjectResult = JSONObject.parseObject(body);
        return jsonObjectResult.get((Object)"data");
    }
 
    @RequestMapping(value = { "/getCloudplatformInfo" }, method = { RequestMethod.POST })
    @ApiOperation("获取摄像头云台操作信息")
    @ResponseBody
    public Object getCloudplatformInfo(final String modId, final String modKey, final String cameraIndex, final Integer action, final String command, final String speed) {
        final RestTemplate restTemplate = new RestTemplate((ClientHttpRequestFactory)new HttpsClientRequestFactory());
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        final Map<Object, Object> params = new HashMap<Object, Object>();
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        params.put("modId", modId);
        params.put("modKey", modKey);
        params.put("cameraIndex", cameraIndex);
        params.put("action", action);
        params.put("command", command);
        params.put("speed", speed);
        final cn.hutool.json.JSONObject jsonObject = JSONUtil.parseFromMap((Map)params);
        final HttpEntity<cn.hutool.json.JSONObject> httpEntity = (HttpEntity<cn.hutool.json.JSONObject>)new HttpEntity((Object)jsonObject, (MultiValueMap)headers);
        final ResponseEntity<String> responseEntity = (ResponseEntity<String>)restTemplate.postForEntity(this.configInfo.getDevice_ip()+   "/restapi/iot/iotinfomgr/service/invoke/cameras/ptzControl?apikey="  + this.configInfo.getApikey(), (Object)httpEntity, (Class)String.class, new Object[0]);
        return responseEntity.getBody();
    }
 
    @RequestMapping(value = { "/getPreviewUrls" }, method = { RequestMethod.POST })
    @ApiOperation("获取摄像头获取预览流url")
    @ResponseBody
    public Object getPreviewUrls(final String modId, final String modKey, final String cameraIndex, final Integer streamType, final Integer transmode, final String protocol, final String expand) {
        final RestTemplate restTemplate = new RestTemplate((ClientHttpRequestFactory)new HttpsClientRequestFactory());
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        final Map<Object, Object> params = new HashMap<Object, Object>();
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        params.put("modId", modId);
        params.put("modKey", modKey);
        params.put("cameraIndex", cameraIndex);
        params.put("transmode", transmode);
        params.put("streamType", streamType);
        params.put("protocol", protocol);
        if (expand != null) {
            params.put("expand", expand);
        }
        final cn.hutool.json.JSONObject jsonObject = JSONUtil.parseFromMap((Map)params);
        final HttpEntity<cn.hutool.json.JSONObject> httpEntity = (HttpEntity<cn.hutool.json.JSONObject>)new HttpEntity((Object)jsonObject, (MultiValueMap)headers);
        final ResponseEntity<String> responseEntity = (ResponseEntity<String>)restTemplate.postForEntity(this.configInfo.getDevice_ip() +  "/restapi/iot/iotinfomgr/service/invoke/cameras/previewURLs?apikey=" +  this.configInfo.getApikey(), (Object)httpEntity, (Class)String.class, new Object[0]);
        final JSON json = (JSON)JSON.parse((String)responseEntity.getBody());
 
        return json;
    }
 
    @RequestMapping(value = { "/getDoorAccessEntity" }, method = { RequestMethod.POST })
    @ApiOperation("获取门禁实体列表")
    @ResponseBody
    public Object getDoorAccessEntity(final String modId, final String modKey, final Integer pageNum, final Integer pageSize) {
        final RestTemplate restTemplate = new RestTemplate((ClientHttpRequestFactory)new HttpsClientRequestFactory());
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        final Map<Object, Object> params = new HashMap<Object, Object>();
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        params.put("modId", modId);
        params.put("modKey", modKey);
        params.put("pageNum", pageNum);
        params.put("pageSize", pageSize);
        final cn.hutool.json.JSONObject jsonObject = JSONUtil.parseFromMap((Map)params);
        final HttpEntity<cn.hutool.json.JSONObject> httpEntity = (HttpEntity<cn.hutool.json.JSONObject>)new HttpEntity((Object)jsonObject, (MultiValueMap)headers);
        final ResponseEntity<String> responseEntity = (ResponseEntity<String>)restTemplate.postForEntity(this.configInfo.getDevice_ip()+   "/restapi/iot/iotinfomgr/entityList?apikey=" +  this.configInfo.getApikey(), (Object)httpEntity, (Class)String.class, new Object[0]);
        final String body = (String)responseEntity.getBody();
        final JSONObject jsonObjectResult = JSONObject.parseObject(body);
        return jsonObjectResult.get((Object)"data");
    }
 
    @RequestMapping(value = { "/getPlaybackURLs" }, method = { RequestMethod.POST })
    @ApiOperation("摄像头获取回放流url")
    @ResponseBody
    public Object getPlaybackURLs(final String modId, final String modKey, final String expand, final String cameraIndex, final String protocol, final String beginTime, final String endTime) {
        final RestTemplate restTemplate = new RestTemplate((ClientHttpRequestFactory)new HttpsClientRequestFactory());
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        final Map<Object, Object> params = new HashMap<Object, Object>();
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        params.put("modId", modId);
        params.put("modKey", modKey);
        params.put("expand", expand);
        params.put("cameraIndex", cameraIndex);
        params.put("beginTime", beginTime);
        params.put("endTime", endTime);
        params.put("protocol", protocol);
        final cn.hutool.json.JSONObject jsonObject = JSONUtil.parseFromMap((Map)params);
        final HttpEntity<cn.hutool.json.JSONObject> httpEntity = (HttpEntity<cn.hutool.json.JSONObject>)new HttpEntity((Object)jsonObject, (MultiValueMap)headers);
        final ResponseEntity<String> responseEntity = (ResponseEntity<String>)restTemplate.postForEntity(this.configInfo.getDevice_ip()+   "/restapi/iot/iotinfomgr/service/invoke/cameras/playbackURLs?apikey="  + this.configInfo.getApikey(), (Object)httpEntity, (Class)String.class, new Object[0]);
        final JSON json = (JSON)JSON.parse((String)responseEntity.getBody());
        return json;
    }
 
    @RequestMapping(value = { "/getHistoryDoorAccess" }, method = { RequestMethod.POST })
    @ApiOperation("获取历史门禁信息")
    @ResponseBody
    public Object getHistoryDoorAccess(final String modId, final String modKey, final Integer pageNo, final Integer pageSize, final String doorIndex, final String startTime, final String endTime) {
        final RestTemplate restTemplate = new RestTemplate((ClientHttpRequestFactory)new HttpsClientRequestFactory());
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        final Map<Object, Object> params = new HashMap<Object, Object>();
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        params.put("modId", modId);
        params.put("modKey", modKey);
        params.put("pageNo", pageNo);
        params.put("pageSize", pageSize);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("doorIndex", doorIndex);
        final cn.hutool.json.JSONObject jsonObject = JSONUtil.parseFromMap((Map)params);
        final HttpEntity<cn.hutool.json.JSONObject> httpEntity = (HttpEntity<cn.hutool.json.JSONObject>)new HttpEntity((Object)jsonObject, (MultiValueMap)headers);
        final ResponseEntity<String> responseEntity = (ResponseEntity<String>)restTemplate.postForEntity(this.configInfo.getDevice_ip()  + "/restapi/iot/iotinfomgr/service/invoke/door/events?apikey="  + this.configInfo.getApikey(), (Object)httpEntity, (Class)String.class, new Object[0]);
        final JSON json = (JSON)JSON.parse((String)responseEntity.getBody());
        return json;
    }
 
    @RequestMapping(value = { "/getEquipmentInfo" }, method = { RequestMethod.POST })
    @ApiOperation("设备信息获取")
    @ResponseBody
    public Object getEquipmentInfo(final String id) {
        final RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        final Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        final ResponseEntity<String> responseEntity = (ResponseEntity<String>)restTemplate.getForEntity(this.configInfo.getSafeSystem_ip() +  "/a/in/inGetByKks/equipLogicData?id={id}", (Class)String.class, (Map)map);
        final JSON json = (JSON)JSON.parse((String)responseEntity.getBody());
        return json;
    }
 
    @RequestMapping(value = { "/getReconditionInfo" }, method = { RequestMethod.POST })
    @ApiOperation("获取设备的检修历史")
    @ResponseBody
    public Object getReconditionInfo(final String id) {
        final RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        final Map<String, String> map = new HashMap<String, String>();
        map.put("id", id);
        final ResponseEntity<String> responseEntity = (ResponseEntity<String>)restTemplate.getForEntity(this.configInfo.getSafeSystem_ip() +  "/a/in/inGetByKks/equipPiData?id={id}", (Class)String.class, (Map)map);
        final JSON json = (JSON)JSON.parse((String)responseEntity.getBody());
        return json;
    }
 
    @RequestMapping(value = { "/getDeviceKKSInfo" }, method = { RequestMethod.POST })
    @ApiOperation("获取设备的KKS信息")
    @ResponseBody
    public Object getDeviceKKSInfo() {
        final List<String> deviceIdList = (List<String>)this.detectService.getDeviceId();
        final Map<Object, Object> map = new HashMap<Object, Object>();
        final List<DeviceKKSDto> deviceList = new ArrayList<DeviceKKSDto>();
        for (final String device_id : deviceIdList) {
            final List<DeviceKKS> list = (List<DeviceKKS>)this.detectService.getDeviceKKSInfo(device_id);
            final DeviceKKSDto dto = new DeviceKKSDto();
            final List<KKSInfo> kksInfo = new ArrayList<KKSInfo>();
            for (int i = 0; i < list.size();   ++i) {
                final KKSInfo kks = new KKSInfo();
                dto.setDevice_id(list.get(0).getDevice_id());
                dto.setDevice_name(list.get(0).getDevice_name());
                dto.setAccount(list.get(0).getAccount());
                kks.setCode(list.get(i).getCode());
                kks.setTest_point(list.get(i).getTest_point());
                kks.setKkstype(list.get(i).getKkstype());
                kksInfo.add(kks);
            }
            dto.setMsg((List)kksInfo);
            deviceList.add(dto);
        }
        map.put("list", deviceList);
        return map;
    }
 
    @RequestMapping(value = { "/getDuty" }, method = { RequestMethod.POST })
    @ApiOperation("获取当值值长")
    @ResponseBody
    public Object getDuty() {
        final RestTemplate template = new RestTemplate();
        template.getMessageConverters().add(new StringHttpMessageConverter(StandardCharsets.UTF_8));
        final Map<String, Object> map = new HashMap<String, Object>();
        final String dzzzresponse = (String)template.getForObject(this.configInfo.getDzzzUrl(), (Class)String.class, new Object[0]);
        final JSONObject json = JSONObject.parseObject(dzzzresponse);
        //System.out.println(json.getJSONObject("data").getString("id"));
        DeviceController.log.warn(dzzzresponse.toString());
        return dzzzresponse;
    }
 
    @RequestMapping(value = { "/getOutPeople" }, method = { RequestMethod.GET })
    @ApiOperation("获取外包人员")
    @ResponseBody
    public Object getOutPeople(final String id) {
        final List<Map> list = (List<Map>)this.outService.selectExternPeople(id);
        DeviceController.log.warn(list.toString());
        return list;
    }
 
    static {
        DeviceController.log = LoggerFactory.getLogger((Class)DeviceController.class);
    }
}