1、新增启迪中台对接接口

This commit is contained in:
yitonglei 2022-05-07 17:42:29 +08:00
parent 7d112072ac
commit fb26b55e75
5 changed files with 317 additions and 145 deletions

View File

@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.time.Clock;
import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -89,50 +91,6 @@ public class Controller {
return "startScenic finish"; 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<String,Object> 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<String,Object> 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<String,Object> map = new HashMap<>();
map.put("location",location);
return monitorService.reverseGeocode(map);
}
/** /**
* 查询摄像头 * 查询摄像头
@ -175,4 +133,84 @@ public class Controller {
return success; 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<String,Object> 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<String,Object> map = new HashMap<>();
map.put("condition",condition);
map.put("page",page);
map.put("pageSize",pageSize);
monitorService.listChannelPlayStates(map);
return null;
}
//道路统计数据与排名
@RequestMapping("roadData")
public List<Map> roadData(
@RequestParam(value="groupId") String groupId,
@RequestParam(value="timeType") String timeType,
@RequestParam(value="dt") String dt
){
Map<String,String> 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<Map> resCatalogApply(){
return monitorService.resCatalogApplyZTYS();
}
//环卫车轨迹数据
@RequestMapping("resCatalogApplyHJWS")
public List<Map> resCatalogApplyHJWS(){
return monitorService.resCatalogApplyHJWS();
}
//工地信息
@RequestMapping("resCatalogApplyGDYS")
public List<Map> resCatalogApplyGDYS(){
return monitorService.resCatalogApplyGDYS();
}
//环卫车辆数据1基础
@RequestMapping("resCatalogApplyHJWSBase")
public List<Map> resCatalogApplyHJWSBase(){
return monitorService.resCatalogApplyHJWSBase();
}
//环卫车辆数据1作业
@RequestMapping("resCatalogApplyHJWSZY")
public List<Map> resCatalogApplyHJWSZY(){
return monitorService.resCatalogApplyHJWSZY();
}
//环卫道路明细数据
@RequestMapping("resCatalogApplyHJWSRoad")
public List<Map> resCatalogApplyHJWSRoad(){
return monitorService.resCatalogApplyHJWSRoad();
}
} }

View File

@ -6,6 +6,7 @@ import com.hisense.monitormanage.dto.ChengguanDto;
import com.hisense.monitormanage.entity.CameraChannel; import com.hisense.monitormanage.entity.CameraChannel;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List; import java.util.List;
@ -20,7 +21,8 @@ public interface CameraChannelMapper extends BaseMapper<CameraChannel> {
@Select("select * from (select a.*,c.* from t_channel_mtm_label b JOIN t_label a JOIN t_camera_channel c " + @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} ") "ON a.label_code = b.label_code AND b.channel_code = c.channel_code ) m where m.label_code = #{labelCode} ")
List<ChannelLabelDto> selectLabel(@Param("labelCode") String labelCode); List<ChannelLabelDto> selectLabel(@Param("labelCode") String labelCode);
//@Update("update t_camera_channel set state = list")
void updateState(@Param("list") List list);
} }

View File

@ -1,6 +1,9 @@
package com.hisense.monitormanage.service; package com.hisense.monitormanage.service;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hisense.monitormanage.entity.*; import com.hisense.monitormanage.entity.*;
import com.hisense.monitormanage.mapper.*; import com.hisense.monitormanage.mapper.*;
@ -14,7 +17,10 @@ import org.springframework.http.*;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Base64Utils; import org.springframework.util.Base64Utils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -295,67 +301,6 @@ public class MonitorService {
} }
//地名地址搜索服务的Suggest操作
public Result suggest(Map<String,Object> 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<String> 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<String,Object> 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<String> 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<String,Object> 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<String> 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<Map>(); static public List cameras = new LinkedList<Map>();
public void videoService(String parentId, String path) throws IOException, InterruptedException { public void videoService(String parentId, String path) throws IOException, InterruptedException {
@ -380,41 +325,228 @@ public class MonitorService {
if (forEntity == null) return; if (forEntity == null) return;
List<Map> 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); //查询视频点播巡检结果
public void listChannelPlayStates(Map<String,Object> map){
cameraChannelMapper.insert(cameraChannel); 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<Map<String,Object>> request = new HttpEntity<>(map,headers);
ResponseEntity<JSONObject> 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<Map> list = JSONObject.parseArray(JSONObject.toJSONString(jsonArray),Map.class);
List<List<Map>> listMap = ListUtil.partition(list,500);
for(List<Map> ll:listMap){
cameraChannelMapper.updateState(ll);
} }
} }
public List<Map> roadData(Map<String,String> map){
String url = "http://outerdata.novaecs.com/api/qingdaoData/roadData?groupId={groupId}&timeType={timeType}&dt={dt}";
ResponseEntity<JSONObject> responseEntity;
List<Map> 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<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
ResponseEntity<JSONObject> 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<Map> 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<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(null, headers);
ResponseEntity<JSONObject> 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<Map> 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<MultiValueMap<String, String>> request = new HttpEntity<>(null, headers);
ResponseEntity<JSONObject> 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<Map> 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<MultiValueMap<String, String>> request = new HttpEntity<>(null, headers);
ResponseEntity<JSONObject> 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<Map> 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<MultiValueMap<String, String>> request = new HttpEntity<>(null, headers);
ResponseEntity<JSONObject> 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<Map> 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<String, String> map = new LinkedMultiValueMap<>();
map.add("pageNo", "1");
map.add("pageSize", "1000");
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
ResponseEntity<JSONObject> responseEntity;
List<Map> 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<Map> 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<MultiValueMap<String, String>> request = new HttpEntity<>(null, headers);
ResponseEntity<JSONObject> 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;
}
} }
} }

View File

@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hisense.monitormanage.mapper.CameraChannelMapper"> <mapper namespace="com.hisense.monitormanage.mapper.CameraChannelMapper">
<update id="updateState" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
update CameraChannel set state =#{item.estAmount,jdbcType=NUMERIC}
where t.licai_id = #{item.licaiId,jdbcType=NUMERIC}
</foreach>
</update>
</mapper> </mapper>

View File

@ -20,13 +20,6 @@ class MonitorManageApplicationTests {
void contextLoads() { void contextLoads() {
} }
@Test
public void reverseGeocodeTest(){
String location = "location";
Map<String,Object> map = new HashMap<>();
map.put("location",location);
monitorService.reverseGeocode(map);
}
@Test @Test
void videoService()throws IOException ,InterruptedException{ void videoService()throws IOException ,InterruptedException{