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 params = new HashMap(); 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 httpEntity = (HttpEntity)new HttpEntity((Object)jsonObject, (MultiValueMap)headers); final ResponseEntity responseEntity = (ResponseEntity)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 params = new HashMap(); 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 httpEntity = (HttpEntity)new HttpEntity((Object)jsonObject, (MultiValueMap)headers); final ResponseEntity responseEntity = (ResponseEntity)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 params = new HashMap(); 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 httpEntity = (HttpEntity)new HttpEntity((Object)jsonObject, (MultiValueMap)headers); final ResponseEntity responseEntity = (ResponseEntity)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 params = new HashMap(); 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 httpEntity = (HttpEntity)new HttpEntity((Object)jsonObject, (MultiValueMap)headers); final ResponseEntity responseEntity = (ResponseEntity)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 params = new HashMap(); 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 httpEntity = (HttpEntity)new HttpEntity((Object)jsonObject, (MultiValueMap)headers); final ResponseEntity responseEntity = (ResponseEntity)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 params = new HashMap(); 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 httpEntity = (HttpEntity)new HttpEntity((Object)jsonObject, (MultiValueMap)headers); final ResponseEntity responseEntity = (ResponseEntity)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 map = new HashMap(); map.put("id", id); final ResponseEntity responseEntity = (ResponseEntity)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 map = new HashMap(); map.put("id", id); final ResponseEntity responseEntity = (ResponseEntity)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 deviceIdList = (List)this.detectService.getDeviceId(); final Map map = new HashMap(); final List deviceList = new ArrayList(); for (final String device_id : deviceIdList) { final List list = (List)this.detectService.getDeviceKKSInfo(device_id); final DeviceKKSDto dto = new DeviceKKSDto(); final List kksInfo = new ArrayList(); 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 map = new HashMap(); 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 list = (List)this.outService.selectExternPeople(id); DeviceController.log.warn(list.toString()); return list; } static { DeviceController.log = LoggerFactory.getLogger((Class)DeviceController.class); } }