From fb26b55e7587018d19e66665433eb8660137bcfb Mon Sep 17 00:00:00 2001 From: yitonglei Date: Sat, 7 May 2022 17:42:29 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=96=B0=E5=A2=9E=E5=90=AF=E8=BF=AA?= =?UTF-8?q?=E4=B8=AD=E5=8F=B0=E5=AF=B9=E6=8E=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitormanage/controller/Controller.java | 126 ++++--- .../mapper/CameraChannelMapper.java | 4 +- .../monitormanage/service/MonitorService.java | 318 +++++++++++++----- .../resources/mapper/CameraChannelMapper.xml | 7 + .../MonitorManageApplicationTests.java | 7 - 5 files changed, 317 insertions(+), 145 deletions(-) diff --git a/src/main/java/com/hisense/monitormanage/controller/Controller.java b/src/main/java/com/hisense/monitormanage/controller/Controller.java index 78703df..2700f04 100644 --- a/src/main/java/com/hisense/monitormanage/controller/Controller.java +++ b/src/main/java/com/hisense/monitormanage/controller/Controller.java @@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.time.Clock; +import java.time.LocalDateTime; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -89,50 +91,6 @@ public class Controller { return "startScenic finish"; } - //根据用户已输入的文字请求输入建议信息 - //text:用户输入的文字信息,必填 - //maxSuggestions:最大建议数量,0~10,默认2 - @RequestMapping("suggest") - public Result suggest( - @RequestParam(value ="text") String text, - @RequestParam(value = "maxSuggestions",required = false,defaultValue = "2") Integer maxSuggestions - ){ - Map map = new HashMap<>(); - map.put("text",text); - map.put("maxSuggestions",maxSuggestions); - return monitorService.suggest(map); - } - - //根据用户已输入的文字请求匹配的地址信息 - //singleLine:用户输入的文字性地名地址信息,必填 - //maxSuggestions:最大建议数量,0~10,默认2 - //magicKey:地名地址唯一ID,Suggest操作返回的JSON数组中包含的magicKey - //outSR:坐标系信息,包含"wkid"属性,是表示空间参考的ID,示例:{ "wkid":4490 } - @RequestMapping("geocode") - public Result geocode( - @RequestParam(value="singleLine") String singleLine, - @RequestParam(value = "maxSuggestions",required = false,defaultValue = "2") Integer maxSuggestions, - @RequestParam(value = "magicKey",required = false,defaultValue = "") String magicKey, - @RequestParam(value = "outSR",required = false,defaultValue = "") String outSR - ){ - Map map = new HashMap<>(); - map.put("SingleLine",singleLine); - map.put("maxSuggestions",maxSuggestions); - map.put("magicKey",magicKey); - map.put("outSR",outSR); - return monitorService.geocode(map); - } - - //根据用户已输入的坐标请求附近的地址信息 - //location:坐标,必填,请注意编码,示例:{"x":120.40632244540544,"y":36.08136665300961,"spatialReference":{"wkid":4490,"latestWkid":4490}} - @RequestMapping("reverseGeocode") - public Result reverseGeocode( - @RequestParam(value="location") String location - ){ - Map map = new HashMap<>(); - map.put("location",location); - return monitorService.reverseGeocode(map); - } /** * 查询摄像头 @@ -175,4 +133,84 @@ public class Controller { return success; } + + //查询视频点播巡检结果,只取异常的 + @RequestMapping("listChannelPlayStates") + public Result listChannelPlayStates( + @RequestParam(value="page",required = false,defaultValue = "1") Integer page, + @RequestParam(value="pageSize",required = false,defaultValue = "20") String pageSize + ){ + Map condition = new HashMap<>(); + LocalDateTime localDateTime = LocalDateTime.now(Clock.systemUTC()); + + LocalDateTime startTime = localDateTime.minusDays(7); + condition.put("checkStatus",0); + condition.put("startTime",startTime.toString()); + condition.put("endTime",localDateTime.toString()); + + Map map = new HashMap<>(); + map.put("condition",condition); + map.put("page",page); + map.put("pageSize",pageSize); + monitorService.listChannelPlayStates(map); + return null; + } + + //道路统计数据与排名 + @RequestMapping("roadData") + public List roadData( + @RequestParam(value="groupId") String groupId, + @RequestParam(value="timeType") String timeType, + @RequestParam(value="dt") String dt + ){ + Map map = new HashMap<>(); + map.put("groupId",groupId); + map.put("timeType",timeType); + map.put("dt",dt); + return monitorService.roadData(map); + } + //启迪中台 + //登录 + @RequestMapping("qidiToken") + public String qidiToken(){ + return monitorService.qidiToken(); + } + + //渣土车轨迹数据 + @RequestMapping("resCatalogApplyZTYS") + public List resCatalogApply(){ + return monitorService.resCatalogApplyZTYS(); + } + + //环卫车轨迹数据 + @RequestMapping("resCatalogApplyHJWS") + public List resCatalogApplyHJWS(){ + return monitorService.resCatalogApplyHJWS(); + } + + //工地信息 + @RequestMapping("resCatalogApplyGDYS") + public List resCatalogApplyGDYS(){ + return monitorService.resCatalogApplyGDYS(); + } + + //环卫车辆数据1,基础 + @RequestMapping("resCatalogApplyHJWSBase") + public List resCatalogApplyHJWSBase(){ + return monitorService.resCatalogApplyHJWSBase(); + } + //环卫车辆数据1,作业 + @RequestMapping("resCatalogApplyHJWSZY") + public List resCatalogApplyHJWSZY(){ + return monitorService.resCatalogApplyHJWSZY(); + } + + //环卫道路明细数据 + @RequestMapping("resCatalogApplyHJWSRoad") + public List resCatalogApplyHJWSRoad(){ + return monitorService.resCatalogApplyHJWSRoad(); + } + + + } diff --git a/src/main/java/com/hisense/monitormanage/mapper/CameraChannelMapper.java b/src/main/java/com/hisense/monitormanage/mapper/CameraChannelMapper.java index 936962f..6d40d01 100644 --- a/src/main/java/com/hisense/monitormanage/mapper/CameraChannelMapper.java +++ b/src/main/java/com/hisense/monitormanage/mapper/CameraChannelMapper.java @@ -6,6 +6,7 @@ import com.hisense.monitormanage.dto.ChengguanDto; import com.hisense.monitormanage.entity.CameraChannel; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; import java.util.List; @@ -20,7 +21,8 @@ public interface CameraChannelMapper extends BaseMapper { @Select("select * from (select a.*,c.* from t_channel_mtm_label b JOIN t_label a JOIN t_camera_channel c " + "ON a.label_code = b.label_code AND b.channel_code = c.channel_code ) m where m.label_code = #{labelCode} ") List selectLabel(@Param("labelCode") String labelCode); - + //@Update("update t_camera_channel set state = list") + void updateState(@Param("list") List list); } diff --git a/src/main/java/com/hisense/monitormanage/service/MonitorService.java b/src/main/java/com/hisense/monitormanage/service/MonitorService.java index e5b265f..9de1d08 100644 --- a/src/main/java/com/hisense/monitormanage/service/MonitorService.java +++ b/src/main/java/com/hisense/monitormanage/service/MonitorService.java @@ -1,6 +1,9 @@ package com.hisense.monitormanage.service; +import cn.hutool.core.collection.ListUtil; import cn.hutool.crypto.SecureUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hisense.monitormanage.entity.*; import com.hisense.monitormanage.mapper.*; @@ -14,7 +17,10 @@ import org.springframework.http.*; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.util.Base64Utils; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; @@ -295,67 +301,6 @@ public class MonitorService { } - //地名地址搜索服务的Suggest操作 - public Result suggest(Map map){ - String url = "http://q3d.qd.gov.cn:8195/portalproxy/qcserver/rest/services/qcgd/GeocodeServer/suggest?"+"text={text}&key={key}"; - map.put("key",key); - - ResponseEntity responseEntity; - try{ - responseEntity = restTemplate.getForEntity(url, String.class,map); - HttpStatus statusCode = responseEntity.getStatusCode(); - if(statusCode.is2xxSuccessful()){ - return Result.success(responseEntity.getBody()); - }else{ - return Result.error(String.valueOf(statusCode.value())); - } - } catch (Exception e){ - log.info("[suggest] exception:{}",e.getMessage()); - return Result.error(e.getMessage()); - } - } - - //地名地址搜索服务的Geocode操作 - public Result geocode(Map map){ - String url = "http://q3d.qd.gov.cn:8195/portalproxy/qcserver/rest/services/qcgd/GeocodeServer/findAddressCandidates?" - +"SingleLine={SingleLine}&key={key}"; - map.put("key",key); - - ResponseEntity responseEntity; - try{ - responseEntity = restTemplate.getForEntity(url, String.class,map); - HttpStatus statusCode = responseEntity.getStatusCode(); - if(statusCode.is2xxSuccessful()){ - return Result.success(responseEntity.getBody()); - }else{ - return Result.error(String.valueOf(statusCode.value())); - } - } catch (Exception e){ - log.info("[geocode] exception:{}",e.getMessage()); - return Result.error(e.getMessage()); - } - } - - //地名地址搜索服务的reverseGeocode操作 - public Result reverseGeocode(Map map){ - String url = "http://q3d.qd.gov.cn:8195/portalproxy/qcserver/rest/services/qcgd/GeocodeServer/reverseGeocode?" - +"location={location}&key={key}"; - map.put("key",key); - - ResponseEntity responseEntity; - try { - responseEntity = restTemplate.getForEntity(url, String.class, map); - HttpStatus statusCode = responseEntity.getStatusCode(); - if(statusCode.is2xxSuccessful()){ - return Result.success(responseEntity.getBody()); - }else{ - return Result.error(String.valueOf(statusCode.value())); - } - }catch (HttpClientErrorException e){ - log.info("[reverseGeocode] exception:{}",e.getMessage()); - return Result.error(e.getMessage()); - } - } static public List cameras = new LinkedList(); public void videoService(String parentId, String path) throws IOException, InterruptedException { @@ -380,41 +325,228 @@ public class MonitorService { if (forEntity == null) return; - - List results = forEntity.getBody(); - -// log.debug("response {}", JSONObject.toJSONString(results)); - String sep = "->"; - - for (Map result : results) { - Boolean isParent = (Boolean) result.get("isParent"); - - if (isParent){ - CameraOrgan cameraOrgan = JSONObject.parseObject(JSONObject.toJSONString(result), CameraOrgan.class); - - cameraOrgenMapper.insert(cameraOrgan); - - videoService((String) result.get("id"),path + sep + result.get("name")); - }else { - if (result.get("channelId") != null){ - CameraChannel cameraChannel = JSONObject.parseObject(JSONObject.toJSONString(result), CameraChannel.class); - - String id = (String)result.get("parentId"); - - if (path != null && path.startsWith(sep)) { - path = path.substring(sep.length()); - } - cameraChannel.setNodeName(path); - - cameraChannel.setParentId(id); - - cameraChannelMapper.insert(cameraChannel); - - } - } + + //查询视频点播巡检结果 + public void listChannelPlayStates(Map map){ + String url = monitorDomain + "/nms/api/channel/play/list"; + HttpHeaders headers = new HttpHeaders(); + headers.add("X-Subject-Token",token); + + int nextPage = 0; + int thisPage = 1; + JSONArray jsonArray = new JSONArray(); + while(nextPage >= 0){ + map.put("page",thisPage); + HttpEntity> request = new HttpEntity<>(map,headers); + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class ); + JSONObject result = responseEntity.getBody(); + jsonArray.add(result.get("results")); + nextPage = result.getIntValue("nextPage"); + thisPage = nextPage; + } + List list = JSONObject.parseArray(JSONObject.toJSONString(jsonArray),Map.class); + List> listMap = ListUtil.partition(list,500); + for(List ll:listMap){ + cameraChannelMapper.updateState(ll); } } + public List roadData(Map map){ + String url = "http://outerdata.novaecs.com/api/qingdaoData/roadData?groupId={groupId}&timeType={timeType}&dt={dt}"; + + ResponseEntity responseEntity; + List list = new ArrayList<>(); + try { + responseEntity = restTemplate.getForEntity(url, JSONObject.class, map); + HttpStatus statusCode = responseEntity.getStatusCode(); + if (statusCode.is2xxSuccessful()) { + JSONObject re = responseEntity.getBody(); + if (re.getIntValue("status") == 0) { + JSONArray jsonArray = re.getJSONArray("data"); + list = JSONArray.parseArray(JSONObject.toJSONString(jsonArray), Map.class); + } + } + return list; + } catch (Exception e) { + log.info("[roadData] exception:{}", e.getMessage()); + return list; + } + } + + //启迪数据中台相关 + //1.登录 + + public String qidiToken () { + String url = "http://120.221.95.13:9090/apin/authorization/oauth/token"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Basic dGVzdF9jbGllbnQ6ZTk4OWQ0NmZkYmMxYzM3NmMxOWE0M2FhZjg1MjI3YTQ="); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + + MultiValueMap map = new LinkedMultiValueMap(); + map.add("username", "dlwr"); + map.add("password", "C61026E841A2F96E17564AB7333D92E8");//dlwr123!,需要MD5加密 + map.add("scope", "read"); + map.add("grant_type", "password"); + map.add("vc", "NO"); + + HttpEntity> request = new HttpEntity<>(map, headers); + ResponseEntity responseEntity; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class); + JSONObject jsonObject = responseEntity.getBody(); + if (jsonObject.getBooleanValue("success") == true) { + JSONObject resultJson = jsonObject.getJSONObject("result"); + return resultJson.getString("accessToken"); + } else { + return null; + } + } catch (Exception e) { + log.info("[qidiToken] exception:{}", e.getMessage()); + return null; + } + } + + //渣土车轨迹数据 + public List resCatalogApplyZTYS () { + String token = this.qidiToken(); + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_ZTYS_307013600000000022_2"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + HttpEntity> httpEntity = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, JSONObject.class); + JSONObject jsonObject = responseEntity.getBody(); + JSONArray jsonArray = jsonObject.getJSONArray("list"); + return JSONObject.parseArray(JSONObject.toJSONString(jsonArray), Map.class); + } catch (Exception e) { + log.info("[resCatalogApplyZTYS] exception:{}", e.getMessage()); + return null; + } + } + + //环卫车轨迹数据 + public List resCatalogApplyHJWS () { + String token = this.qidiToken(); + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000442_1"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class); + JSONObject jsonObject = responseEntity.getBody(); + JSONArray jsonArray = jsonObject.getJSONArray("list"); + return JSONObject.parseArray(JSONObject.toJSONString(jsonArray), Map.class); + } catch (Exception e) { + log.info("[resCatalogApplyHJWS] exception:{}", e.getMessage()); + return null; + } + } + + //工地信息 + public List resCatalogApplyGDYS () { + String token = this.qidiToken(); + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_ZTYS_307013600000000025_1"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class); + JSONObject jsonObject = responseEntity.getBody(); + JSONArray jsonArray = jsonObject.getJSONArray("list"); + return JSONObject.parseArray(JSONObject.toJSONString(jsonArray), Map.class); + } catch (Exception e) { + log.info("[resCatalogApplyGDYS] exception:{}", e.getMessage()); + return null; + } + } + + //环卫车辆数据1,基础 + public List resCatalogApplyHJWSBase () { + String token = this.qidiToken(); + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000365_1"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class); + JSONObject jsonObject = responseEntity.getBody(); + JSONArray jsonArray = jsonObject.getJSONArray("list"); + return JSONObject.parseArray(JSONObject.toJSONString(jsonArray), Map.class); + } catch (Exception e) { + log.info("[resCatalogApplyHJWSBase] exception:{}", e.getMessage()); + return null; + } + } + + //环卫车辆数据2,作业 + public List resCatalogApplyHJWSZY () { + String token = this.qidiToken(); + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + MultiValueMap map = new LinkedMultiValueMap<>(); + map.add("pageNo", "1"); + map.add("pageSize", "1000"); + HttpEntity> request = new HttpEntity<>(map, headers); + ResponseEntity responseEntity; + List result; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class); + JSONObject jsonObject = responseEntity.getBody(); + int count = jsonObject.getIntValue("count"); + result = new ArrayList<>(count); + JSONArray jsonArray = jsonObject.getJSONArray("list"); + result.addAll(JSONObject.parseArray(JSONObject.toJSONString(jsonArray), Map.class)); + if (count > 1000) { + int i = count / 1000; + for (int j = 2; j <= i + 1; j++) { + map.add("pageNo", String.valueOf(j)); + responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class); + JSONObject jsonObject1 = responseEntity.getBody(); + JSONArray jsonArray1 = jsonObject.getJSONArray("list"); + result.addAll(JSONObject.parseArray(JSONObject.toJSONString(jsonArray1), Map.class)); + } + } + return result; + } catch (Exception e) { + log.info("[resCatalogApplyHJWSZY] exception:{}", e.getMessage()); + return null; + } + } + + //环卫道路明细数据 + public List resCatalogApplyHJWSRoad () { + String token = this.qidiToken(); + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000370_2"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class); + JSONObject jsonObject = responseEntity.getBody(); + JSONArray jsonArray = jsonObject.getJSONArray("list"); + return JSONObject.parseArray(JSONObject.toJSONString(jsonArray), Map.class); + } catch (Exception e) { + log.info("[resCatalogApplyHJWSRoad] exception:{}", e.getMessage()); + return null; + } + } + } + + + + diff --git a/src/main/resources/mapper/CameraChannelMapper.xml b/src/main/resources/mapper/CameraChannelMapper.xml index f769d84..399fb6b 100644 --- a/src/main/resources/mapper/CameraChannelMapper.xml +++ b/src/main/resources/mapper/CameraChannelMapper.xml @@ -1,5 +1,12 @@ + + + update CameraChannel set state =#{item.estAmount,jdbcType=NUMERIC} + where t.licai_id = #{item.licaiId,jdbcType=NUMERIC} + + + \ No newline at end of file diff --git a/src/test/java/com/hisense/monitormanage/MonitorManageApplicationTests.java b/src/test/java/com/hisense/monitormanage/MonitorManageApplicationTests.java index 50f0744..ba9ddfc 100644 --- a/src/test/java/com/hisense/monitormanage/MonitorManageApplicationTests.java +++ b/src/test/java/com/hisense/monitormanage/MonitorManageApplicationTests.java @@ -20,13 +20,6 @@ class MonitorManageApplicationTests { void contextLoads() { } - @Test - public void reverseGeocodeTest(){ - String location = "location"; - Map map = new HashMap<>(); - map.put("location",location); - monitorService.reverseGeocode(map); - } @Test void videoService()throws IOException ,InterruptedException{