From 8b1ecd7b9decce4b0c856dfa31448360517748c6 Mon Sep 17 00:00:00 2001 From: wuweida <2918581207@qq.com> Date: Tue, 14 Jun 2022 15:36:02 +0800 Subject: [PATCH] =?UTF-8?q?qidi=E6=8E=A5=E5=8F=A3=E7=94=B1monitorService?= =?UTF-8?q?=E8=BD=AC=E7=A7=BB=E5=88=B0QidiService=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=AE=89=E4=BF=9D=E5=8C=BA=E5=9F=9F=E4=BA=BA=E6=B5=81=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E7=AE=97=E6=B3=95=E6=8E=A5=E5=8F=A3=20=E5=AE=89?= =?UTF-8?q?=E4=BF=9D=E5=8C=BA=E5=9F=9F=E4=BA=BA=E6=B5=81=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E7=AE=97=E6=B3=95=E5=81=9A=E8=B0=83=E5=BA=A6=E6=AF=8F=E5=A4=A9?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitormanage/controller/Controller.java | 19 +- .../controller/PeopleRecognizeController.java | 36 ++ .../monitormanage/entity/PeopleRecognize.java | 21 + .../mapper/PeopleRecognizeMapper.java | 7 + .../monitormanage/mapper/RoadDataMapper.java | 2 - .../monitormanage/service/MonitorService.java | 388 +++++------------- .../monitormanage/service/QidiService.java | 290 +++++++++++++ .../service/RoadDataService.java | 29 ++ .../service/SanitationService.java | 12 +- .../service/SedimentTrailService.java | 4 +- .../service/TrailSanitationService.java | 4 +- .../monitormanage/utils/LongLatUtil.java | 6 +- .../mapper/PeopleRecognizeMapper.xml | 5 + src/main/resources/mapper/RoadDataMapper.xml | 5 - 14 files changed, 510 insertions(+), 318 deletions(-) create mode 100644 src/main/java/com/hisense/monitormanage/controller/PeopleRecognizeController.java create mode 100644 src/main/java/com/hisense/monitormanage/entity/PeopleRecognize.java create mode 100644 src/main/java/com/hisense/monitormanage/mapper/PeopleRecognizeMapper.java create mode 100644 src/main/java/com/hisense/monitormanage/service/QidiService.java create mode 100644 src/main/resources/mapper/PeopleRecognizeMapper.xml diff --git a/src/main/java/com/hisense/monitormanage/controller/Controller.java b/src/main/java/com/hisense/monitormanage/controller/Controller.java index a59fb1f..cebe1b6 100644 --- a/src/main/java/com/hisense/monitormanage/controller/Controller.java +++ b/src/main/java/com/hisense/monitormanage/controller/Controller.java @@ -73,8 +73,7 @@ public class Controller { private TrailSanitationMapper trailSanitationMapper; @Autowired - private RoadDataMapper roadDataMapper; - + private QidiService qidiService; @GetMapping("all") public Object all(){ @@ -337,7 +336,7 @@ public class Controller { @GetMapping("roadData") @ApiOperation("道路统计数据与排名,根据后台dt调用接口") public List roadData(){ - return monitorService.roadData(); + return roadDataService.roadData(); } //启迪中台 @@ -345,48 +344,48 @@ public class Controller { @GetMapping("qidiToken") @ApiOperation("启迪数据中台登录获取token") public String qidiToken(){ - return monitorService.qidiToken(); + return qidiService.qidiToken(); } //渣土车轨迹数据 @GetMapping("resCatalogApplyZTYS") @ApiOperation("获取渣土车轨迹数据,根据后台UPLOADTIME调用接口") public List resCatalogApply(){ - return monitorService.resCatalogApplyZTYS(); + return qidiService.resCatalogApplyZTYS(); } //环卫车轨迹数据 @GetMapping("resCatalogApplyHJWS") @ApiOperation("环卫车轨迹数据,根据后台updatetime调用接口") public List resCatalogApplyHJWS(){ - return monitorService.resCatalogApplyHJWS(); + return qidiService.resCatalogApplyHJWS(); } //工地信息 @GetMapping("resCatalogApplyGDYS") @ApiOperation("获取工地信息-表中获取") public List resCatalogApplyGDYS(){ - return monitorService.resCatalogApplyGDYS(); + return qidiService.resCatalogApplyGDYS(); } //环卫车辆数据1,基础 @GetMapping("resCatalogApplyHJWSBase") @ApiOperation("环卫车辆数据1,基础--根据后台updatetime调用接口") public List resCatalogApplyHJWSBase(){ - return monitorService.resCatalogApplyHJWSBase(); + return qidiService.resCatalogApplyHJWSBase(); } //环卫车辆数据1,作业 @GetMapping("resCatalogApplyHJWSZY") @ApiOperation("环卫车辆数据1,作业--根据后台ZYRQ调用接口") public List resCatalogApplyHJWSZY(){ - return monitorService.resCatalogApplyHJWSZY(); + return qidiService.resCatalogApplyHJWSZY(); } //环卫道路明细数据 @GetMapping("resCatalogApplyHJWSRoad") @ApiOperation("环卫道路明细数据,根据后台updatetime调用接口") public List resCatalogApplyHJWSRoad(){ - return monitorService.resCatalogApplyHJWSRoad(); + return qidiService.resCatalogApplyHJWSRoad(); } //获取渣土车轨迹并保存到t_trail_sediment diff --git a/src/main/java/com/hisense/monitormanage/controller/PeopleRecognizeController.java b/src/main/java/com/hisense/monitormanage/controller/PeopleRecognizeController.java new file mode 100644 index 0000000..ec534fa --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/controller/PeopleRecognizeController.java @@ -0,0 +1,36 @@ +package com.hisense.monitormanage.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.hisense.monitormanage.entity.PeopleRecognize; +import com.hisense.monitormanage.entity.Result; +import com.hisense.monitormanage.mapper.PeopleRecognizeMapper; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("api/project/people") +@Api(tags = "人流识别算法") +public class PeopleRecognizeController { + + @Autowired + private PeopleRecognizeMapper peopleRecognizeMapper; + + /** + * 查询全部安保区域人流 + * @return + */ + @GetMapping("selectPeopleRecognize") + @ApiOperation("查询全部安保区域人流") + public Result selectPeopleRecognize(){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + List list = peopleRecognizeMapper.selectList(queryWrapper); + Result success = Result.success(list); + return success; + } +} diff --git a/src/main/java/com/hisense/monitormanage/entity/PeopleRecognize.java b/src/main/java/com/hisense/monitormanage/entity/PeopleRecognize.java new file mode 100644 index 0000000..b12a3b5 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/entity/PeopleRecognize.java @@ -0,0 +1,21 @@ +package com.hisense.monitormanage.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("t_people_recognize") +public class PeopleRecognize { + @TableId + private String id; + private String channelCode; + private String channelName; + private String picUrl; + private Integer personNum; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date pushTime; +} diff --git a/src/main/java/com/hisense/monitormanage/mapper/PeopleRecognizeMapper.java b/src/main/java/com/hisense/monitormanage/mapper/PeopleRecognizeMapper.java new file mode 100644 index 0000000..d93b737 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/mapper/PeopleRecognizeMapper.java @@ -0,0 +1,7 @@ +package com.hisense.monitormanage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hisense.monitormanage.entity.PeopleRecognize; + +public interface PeopleRecognizeMapper extends BaseMapper { +} diff --git a/src/main/java/com/hisense/monitormanage/mapper/RoadDataMapper.java b/src/main/java/com/hisense/monitormanage/mapper/RoadDataMapper.java index cb1aade..3351764 100644 --- a/src/main/java/com/hisense/monitormanage/mapper/RoadDataMapper.java +++ b/src/main/java/com/hisense/monitormanage/mapper/RoadDataMapper.java @@ -16,6 +16,4 @@ import java.util.Map; */ public interface RoadDataMapper extends BaseMapper { public void batchSave(List list); - - /*List selectRoadData(@Param("page") Integer page, @Param("pageSize") Integer pageSize);*/ } diff --git a/src/main/java/com/hisense/monitormanage/service/MonitorService.java b/src/main/java/com/hisense/monitormanage/service/MonitorService.java index 28e3e6d..f6c179c 100644 --- a/src/main/java/com/hisense/monitormanage/service/MonitorService.java +++ b/src/main/java/com/hisense/monitormanage/service/MonitorService.java @@ -67,6 +67,10 @@ public class MonitorService { @Autowired private BoothMapper boothMapper; + @Autowired + private PeopleRecognizeMapper peopleRecognizeMapper; + + @Value("${hwx.file.work-path}") private String fileDir; @Value("${hwx.file.pic-host}") @@ -589,7 +593,7 @@ public class MonitorService { log.info("[monitor-capture]: start capture"); - List labels = cameraChannelMapper.selectLabelAndChannel("1004,1006"); + List labels = cameraChannelMapper.selectLabelAndChannel("1006,1004"); labels.forEach(label -> { String channelCode = label.getChannelCode(); try { @@ -624,6 +628,101 @@ public class MonitorService { } } + /** + * 海水浴场人群图片算法识别 + */ + public void bathingBeach () { + try { + + log.info("[monitor-capture]: start capture"); + + List labels = cameraChannelMapper.selectLabelAndChannel("1006"); + labels.forEach(label -> { + String channelCode = label.getChannelCode(); + try { + BufferedImage bufferedImage = capturecreenshot(channelCode); + String fileName = channelCode + ".jpg"; + ImageIO.write(bufferedImage, "jpg", new File(fileDir + "/images/" + fileName)); + String picUrl = picHost + "/images/" + fileName; + //人流识别 + String personNumUrl = "http://15.72.184.10:8003/cshi_rpc/v1.0/person"; + Map personImage = new HashMap<>(); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + ImageIO.write(bufferedImage, "png", stream); + String imgBase64 = Base64Utils.encodeToString(stream.toByteArray()); + stream.flush(); + stream.close(); + personImage.put("img_base64", imgBase64); + ResponseEntity responseEntity = restTemplate.postForEntity(personNumUrl, personImage, HashMap.class); + HashMap body = responseEntity.getBody(); + if (body != null && (Integer) body.get("code") == 200){ + Map data = (Map) body.get("data"); + log.info(picUrl); + log.info("人流识别算法" + data); + } + }catch (Exception e){ + log.info( "[monitor-capture] " +channelCode + " 截图图片失败 " + e.getMessage()); + } + }); + log.info("[monitor-capture]: end capture"); + }catch (Exception exception){ + exception.printStackTrace(); + } + } + + /** + * 安保区域人群图片算法识别并保存到数据库 + */ + @Scheduled(cron = "0 0 8/2 * * ?") + public void peopleRecognize() { + try { + log.info("[monitor-capture]: start capture"); + + List labels = cameraChannelMapper.selectLabelAndChannel("1042"); + labels.forEach(label -> { + String channelCode = label.getChannelCode(); + try { + BufferedImage bufferedImage = capturecreenshot(channelCode); + String fileName = channelCode + ".jpg"; + ImageIO.write(bufferedImage, "jpg", new File(fileDir + "/images/" + fileName)); + String picUrl = picHost + "/images/" + fileName; + //人流识别 + String personNumUrl = "http://15.72.184.10:8003/cshi_rpc/v1.0/person"; + Map personImage = new HashMap<>(); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + ImageIO.write(bufferedImage, "png", stream); + String imgBase64 = Base64Utils.encodeToString(stream.toByteArray()); + stream.flush(); + stream.close(); + personImage.put("img_base64", imgBase64); + ResponseEntity responseEntity = restTemplate.postForEntity(personNumUrl, personImage, HashMap.class); + HashMap body = responseEntity.getBody(); + if (body != null && (Integer) body.get("code") == 200){ + Map data = (Map) body.get("data"); + Integer personNum = (Integer) data.get("person_num"); + PeopleRecognize peopleRecognize = new PeopleRecognize(); + peopleRecognize.setChannelCode(channelCode); + peopleRecognize.setChannelName(label.getChannelName()); + peopleRecognize.setPicUrl(picUrl); + peopleRecognize.setPersonNum(personNum); + peopleRecognize.setPushTime(new Date()); + PeopleRecognize id = peopleRecognizeMapper.selectById(channelCode); + if (id == null){ + peopleRecognizeMapper.insert(peopleRecognize); + }else { + peopleRecognizeMapper.updateById(peopleRecognize); + } + } + }catch (Exception e){ + log.info( "[monitor-capture] " +channelCode + " 截图图片失败 " + e.getMessage()); + } + }); + log.info("[monitor-capture]: end capture"); + }catch (Exception exception){ + exception.printStackTrace(); + } + } + /** * 景区人流量识别 */ @@ -891,294 +990,7 @@ public class MonitorService { return Result.success(); } - //道路统计数据与排名,调用公开接口 - public List roadData(){ - String url = "http://outerdata.novaecs.com/api/qingdaoData/roadData?groupId={groupId}&timeType={timeType}&dt={dt}"; - Map map = new HashMap<>(); - - map.put("dt",this.dateTimeStr()); - map.put("groupId",1); - map.put("timeType","日"); - - 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(); - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - - Map map = new HashMap<>(); - JSONObject search = new JSONObject(); - search.put("opt","LIKE"); - search.put("key","UPLOADTIME"); - search.put("val",this.dateStr()); - -// search.put("opt","EQ"); -// search.put("key","SPEED"); -// search.put("val","0"); - map.put("json",search); - - String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_ZTYS_307013600000000022_2?search=[{json}]"; - - HttpEntity httpEntity = new HttpEntity<>(null, headers); - ResponseEntity responseEntity; - try { - responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, JSONObject.class,map); - - JSONObject jsonObject = responseEntity.getBody(); - JSONArray jsonArray = jsonObject.getJSONArray("list"); - log.info("[resCatalogApplyZTYS] 返回数据的数量:{}",jsonArray.size()); - 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?search=[{json}]"; - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - - Map map = new HashMap<>(); - JSONObject search = new JSONObject(); - search.put("opt","LIKE"); - search.put("key","updatetime"); - search.put("val",this.dateStr()); -// search.put("opt","EQ"); -// search.put("key","SIMKH"); -// search.put("val","13302959786"); - map.put("json",search); - - HttpEntity> request = new HttpEntity<>(null, headers); - ResponseEntity responseEntity; - try { - responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); - 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?search=[{json}]"; - 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); - - Map map = new HashMap<>(); - JSONObject search = new JSONObject(); - search.put("opt","LIKE"); - search.put("key","updatetime"); - search.put("val",this.dateStr()); -// search.put("opt","EQ"); -// search.put("key","SSDQ"); -// search.put("val","西海岸新区"); - map.put("json",search); - - HttpEntity> request = new HttpEntity<>(null, headers); - ResponseEntity responseEntity; - try { - //responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); - 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?search=[{json}]"; - 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); - - Map map = new HashMap<>(); - JSONObject search = new JSONObject(); -// search.put("opt","LIKE"); -// search.put("key","updatetime"); -// search.put("val",this.dateStr()); - search.put("opt","EQ"); - search.put("key","SSQY"); - search.put("val","胶州市"); - map.put("json",search); - - HttpEntity> request = new HttpEntity<>(null, headers); - ResponseEntity responseEntity; - try { - //responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); - 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,作业,5月20号已经把能查到的都保存到表中了(忘了保存updatetime) - public List resCatalogApplyHJWSZY () { - String token = this.qidiToken(); - String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1"; - //String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1?search=[{json}]"; - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - - Map map = new HashMap<>(); - JSONObject search = new JSONObject(); -// search.put("opt","LIKE"); -// search.put("key","ZYRQ"); -// search.put("val",this.dateStr()); - map.put("json",search); - - HttpEntity> request = new HttpEntity<>(null, headers); - ResponseEntity responseEntity; - try { - responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); - //responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); - 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; - } - } - - public List resCatalogApplyHJWSZY(String updatetime) throws Exception{ - String token = this.qidiToken(); - String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1?search=[{json}]"; - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - - List maps = new ArrayList<>(); - Map map = new HashMap<>(); - JSONObject search = new JSONObject(); - search.put("opt","GT"); - search.put("key","updatetime"); - search.put("val",updatetime); - map.put("json",search); - - HttpEntity> request = new HttpEntity<>(null, headers); - ResponseEntity responseEntity; - responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); - JSONObject jsonObject = responseEntity.getBody(); - JSONArray jsonArray = jsonObject.getJSONArray("list"); - maps = JSONObject.parseArray(JSONObject.toJSONString(jsonArray), Map.class); - - return maps; - } - //环卫道路明细数据 - public List resCatalogApplyHJWSRoad () { - String token = this.qidiToken(); - String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000370_2"; - //String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000370_2?search=[{json}]"; - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + token); - - Map map = new HashMap<>(); - // JSONObject search = new JSONObject(); -// search.put("opt","LIKE"); -// search.put("key","updatetime"); -// search.put("val",this.dateStr()); -// search.put("opt","EQ"); -// search.put("key","QDLKDLMC"); -// search.put("val","宜昌路"); -// map.put("json",search); - - HttpEntity> request = new HttpEntity<>(null, headers); - ResponseEntity responseEntity; - try { - //responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); - 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 new ArrayList<>(); - } - } - //获取当前日期的时间串,2022-05-08 00:00:00 - private String dateTimeStr(){ - LocalDate localDate = LocalDate.now(); - LocalDate yestDay = localDate.minusDays(1); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime dateTime = LocalDateTime.of(yestDay.getYear(),yestDay.getMonth(),yestDay.getDayOfMonth(),0,0,0); - return dateTime.format(formatter); - } - //获取当前日期的时间串,2022-05-08 - private String dateStr(){ - LocalDate localDate = LocalDate.now(); - LocalDate yestDay = localDate.minusDays(1); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - - return yestDay.format(formatter); - } } diff --git a/src/main/java/com/hisense/monitormanage/service/QidiService.java b/src/main/java/com/hisense/monitormanage/service/QidiService.java new file mode 100644 index 0000000..02811db --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/service/QidiService.java @@ -0,0 +1,290 @@ +package com.hisense.monitormanage.service; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +@Slf4j +public class QidiService { + + @Autowired + private RestTemplate restTemplate; + + //启迪数据中台相关 + //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(); + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + Map map = new HashMap<>(); + JSONObject search = new JSONObject(); + search.put("opt","LIKE"); + search.put("key","UPLOADTIME"); + search.put("val",this.dateStr()); + +// search.put("opt","EQ"); +// search.put("key","SPEED"); +// search.put("val","0"); + map.put("json",search); + + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_ZTYS_307013600000000022_2?search=[{json}]"; + + HttpEntity httpEntity = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, JSONObject.class,map); + + JSONObject jsonObject = responseEntity.getBody(); + JSONArray jsonArray = jsonObject.getJSONArray("list"); + log.info("[resCatalogApplyZTYS] 返回数据的数量:{}",jsonArray.size()); + 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?search=[{json}]"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + Map map = new HashMap<>(); + JSONObject search = new JSONObject(); + search.put("opt","LIKE"); + search.put("key","updatetime"); + search.put("val",this.dateStr()); +// search.put("opt","EQ"); +// search.put("key","SIMKH"); +// search.put("val","13302959786"); + map.put("json",search); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); + 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?search=[{json}]"; + 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); + + Map map = new HashMap<>(); + JSONObject search = new JSONObject(); + search.put("opt","LIKE"); + search.put("key","updatetime"); + search.put("val",this.dateStr()); +// search.put("opt","EQ"); +// search.put("key","SSDQ"); +// search.put("val","西海岸新区"); + map.put("json",search); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + //responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); + 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?search=[{json}]"; + 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); + + Map map = new HashMap<>(); + JSONObject search = new JSONObject(); +// search.put("opt","LIKE"); +// search.put("key","updatetime"); +// search.put("val",this.dateStr()); + search.put("opt","EQ"); + search.put("key","SSQY"); + search.put("val","胶州市"); + map.put("json",search); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + //responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); + 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,作业,5月20号已经把能查到的都保存到表中了(忘了保存updatetime) + public List resCatalogApplyHJWSZY () { + String token = this.qidiToken(); + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1"; + //String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1?search=[{json}]"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + Map map = new HashMap<>(); + JSONObject search = new JSONObject(); +// search.put("opt","LIKE"); +// search.put("key","ZYRQ"); +// search.put("val",this.dateStr()); + map.put("json",search); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); + //responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); + 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; + } + } + + public List resCatalogApplyHJWSZY(String updatetime) throws Exception{ + String token = this.qidiToken(); + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1?search=[{json}]"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + List maps = new ArrayList<>(); + Map map = new HashMap<>(); + JSONObject search = new JSONObject(); + search.put("opt","GT"); + search.put("key","updatetime"); + search.put("val",updatetime); + map.put("json",search); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); + JSONObject jsonObject = responseEntity.getBody(); + JSONArray jsonArray = jsonObject.getJSONArray("list"); + maps = JSONObject.parseArray(JSONObject.toJSONString(jsonArray), Map.class); + + return maps; + } + //环卫道路明细数据 + public List resCatalogApplyHJWSRoad () { + String token = this.qidiToken(); + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000370_2"; + //String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000370_2?search=[{json}]"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + Map map = new HashMap<>(); + // JSONObject search = new JSONObject(); +// search.put("opt","LIKE"); +// search.put("key","updatetime"); +// search.put("val",this.dateStr()); +// search.put("opt","EQ"); +// search.put("key","QDLKDLMC"); +// search.put("val","宜昌路"); +// map.put("json",search); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + try { + //responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); + 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 new ArrayList<>(); + } + } + //获取当前日期的时间串,2022-05-08 00:00:00 + private String dateTimeStr(){ + LocalDate localDate = LocalDate.now(); + LocalDate yestDay = localDate.minusDays(1); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime dateTime = LocalDateTime.of(yestDay.getYear(),yestDay.getMonth(),yestDay.getDayOfMonth(),0,0,0); + return dateTime.format(formatter); + } + //获取当前日期的时间串,2022-05-08 + private String dateStr(){ + LocalDate localDate = LocalDate.now(); + LocalDate yestDay = localDate.minusDays(1); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + return yestDay.format(formatter); + } +} diff --git a/src/main/java/com/hisense/monitormanage/service/RoadDataService.java b/src/main/java/com/hisense/monitormanage/service/RoadDataService.java index e94cffe..0148540 100644 --- a/src/main/java/com/hisense/monitormanage/service/RoadDataService.java +++ b/src/main/java/com/hisense/monitormanage/service/RoadDataService.java @@ -38,6 +38,35 @@ public class RoadDataService { @Autowired private RoadDataMapper roadDataMapper; + //道路统计数据与排名,调用公开接口 + public List roadData(){ + String url = "http://outerdata.novaecs.com/api/qingdaoData/roadData?groupId={groupId}&timeType={timeType}&dt={dt}"; + + Map map = new HashMap<>(); + + map.put("dt",this.dateTimeStr()); + map.put("groupId",1); + map.put("timeType","日"); + + 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; + } + } + //道路统计数据与排名(道路污染),调用公开接口并保存到表t_road_data @Scheduled(cron="0 0 8 * * ?") public void saveRoadData(){ diff --git a/src/main/java/com/hisense/monitormanage/service/SanitationService.java b/src/main/java/com/hisense/monitormanage/service/SanitationService.java index 5c4e74c..5315b2e 100644 --- a/src/main/java/com/hisense/monitormanage/service/SanitationService.java +++ b/src/main/java/com/hisense/monitormanage/service/SanitationService.java @@ -31,13 +31,13 @@ public class SanitationService { @Autowired private RestTemplate restTemplate; @Autowired - private MonitorService monitorService; + private QidiService qidiService; @Autowired private SanitationTaskMapper sanitationTaskMapper; public Result saveSantation(){ - List list = monitorService.resCatalogApplyHJWSBase(); + List list = qidiService.resCatalogApplyHJWSBase(); if(list.size() > 0){ List> maps = Lists.partition(list,100); @@ -47,7 +47,7 @@ public class SanitationService { } public Result saveSanitationRoad(){ - List list = monitorService.resCatalogApplyHJWSRoad(); + List list = qidiService.resCatalogApplyHJWSRoad(); try{ if(list.size() > 0){ List> maps = Lists.partition(list,100); @@ -62,7 +62,7 @@ public class SanitationService { } public Result saveSanitationTask(){ - List list = monitorService.resCatalogApplyHJWSZY(); + List list = qidiService.resCatalogApplyHJWSZY(); try{ if(list.size() > 0){ List> maps = Lists.partition(list,100); @@ -86,10 +86,10 @@ public class SanitationService { try{ if(sanitationTask != null){ - maps = monitorService.resCatalogApplyHJWSZY(String.valueOf(sanitationTask.getUpdatetime())); + maps = qidiService.resCatalogApplyHJWSZY(String.valueOf(sanitationTask.getUpdatetime())); }else{ - maps = monitorService.resCatalogApplyHJWSZY(); + maps = qidiService.resCatalogApplyHJWSZY(); } if(maps.size() > 0){ diff --git a/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java b/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java index beb3843..631b8a9 100644 --- a/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java +++ b/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java @@ -29,13 +29,13 @@ public class SedimentTrailService { private SedimentTrailMapper sedimentTrailMapper; @Autowired - private MonitorService monitorService; + private QidiService qidiService; //获取渣土车轨迹并保存到表t_trail_sediment //@Transactional(rollbackFor = Exception.class) public boolean batchSaveSedimentTrail(){ try{ - List maps = monitorService.resCatalogApplyZTYS(); + List maps = qidiService.resCatalogApplyZTYS(); Lists.partition(maps,200).forEach( item-> sedimentTrailMapper.batchaSave(item) ); diff --git a/src/main/java/com/hisense/monitormanage/service/TrailSanitationService.java b/src/main/java/com/hisense/monitormanage/service/TrailSanitationService.java index 313a4d8..6071850 100644 --- a/src/main/java/com/hisense/monitormanage/service/TrailSanitationService.java +++ b/src/main/java/com/hisense/monitormanage/service/TrailSanitationService.java @@ -18,12 +18,12 @@ public class TrailSanitationService { @Autowired private TrailSanitationMapper trailSanitationMapper; @Autowired - private MonitorService monitorService; + private QidiService qidiService; public boolean saveTrailSanitation(){ boolean result = false; try{ - List list = monitorService.resCatalogApplyHJWS(); + List list = qidiService.resCatalogApplyHJWS(); List> lists = Lists.partition(list,200); lists.forEach(l->trailSanitationMapper.batchaSave(l)); result = true; diff --git a/src/main/java/com/hisense/monitormanage/utils/LongLatUtil.java b/src/main/java/com/hisense/monitormanage/utils/LongLatUtil.java index d76d6b9..2eb499d 100644 --- a/src/main/java/com/hisense/monitormanage/utils/LongLatUtil.java +++ b/src/main/java/com/hisense/monitormanage/utils/LongLatUtil.java @@ -45,16 +45,16 @@ public class LongLatUtil { Double longitude = lon; Double degree = (24901 * 1609) / 360.0; - double raidusMile = radius; + double radiusMile = radius; Double dpmLat = 1 / degree; - Double radiusLat = dpmLat * raidusMile; + Double radiusLat = dpmLat * radiusMile; Double minLat = latitude - radiusLat; Double maxLat = latitude + radiusLat; Double mpdLng = degree * Math.cos(latitude * (PI / 180)); Double dpmLng = 1 / mpdLng; - Double radiusLng = dpmLng * raidusMile; + Double radiusLng = dpmLng * radiusMile; Double minLng = longitude - radiusLng; Double maxLng = longitude + radiusLng; return new double[]{minLng,minLat, maxLng, maxLat}; diff --git a/src/main/resources/mapper/PeopleRecognizeMapper.xml b/src/main/resources/mapper/PeopleRecognizeMapper.xml new file mode 100644 index 0000000..f1cd304 --- /dev/null +++ b/src/main/resources/mapper/PeopleRecognizeMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/RoadDataMapper.xml b/src/main/resources/mapper/RoadDataMapper.xml index 843666b..23d6ca5 100644 --- a/src/main/resources/mapper/RoadDataMapper.xml +++ b/src/main/resources/mapper/RoadDataMapper.xml @@ -16,10 +16,5 @@ - \ No newline at end of file