From bf6038a5ef43ea5baf3bf9886f791e939d0574fd Mon Sep 17 00:00:00 2001 From: haungweixiong Date: Tue, 29 Nov 2022 14:33:54 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E5=BE=B7=E7=83=AD=E5=8A=9B=E5=9B=BE?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GaodeController.java | 52 ++++++++++++++----- .../monitormanage/entity/CrowdFlow.java | 16 ++++++ 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/hisense/monitormanage/controller/GaodeController.java b/src/main/java/com/hisense/monitormanage/controller/GaodeController.java index 50342a0..2c283eb 100644 --- a/src/main/java/com/hisense/monitormanage/controller/GaodeController.java +++ b/src/main/java/com/hisense/monitormanage/controller/GaodeController.java @@ -50,7 +50,10 @@ public class GaodeController { @ApiImplicitParam(name = "page", value = "页码", required = false, dataType = "Integer"), @ApiImplicitParam(name = "size", value = "页码大小", required = false, dataType = "Integer") }) - public Result crowflowList(Integer page, Integer size, String start, String end, Integer cValue) { + public Result crowflowList(Integer page, Integer size, + String start, String end, + Integer cValue, + Boolean needAreaData) { LambdaQueryWrapper queryWrapper = new QueryWrapper().lambda(); if (start != null) { @@ -63,6 +66,13 @@ public class GaodeController { queryWrapper.gt(CrowdFlow::getCnt, cValue); } + if (needAreaData == null || needAreaData == false) { + queryWrapper.select(CrowdFlow::getId, + CrowdFlow::getCaptureTime, + CrowdFlow::getCnt, + CrowdFlow::getVisitCnt); + } + Page flowPage = new Page<>(); flowPage.addOrder(OrderItem.desc("id")); if (page != null && page > 0) { @@ -83,16 +93,18 @@ public class GaodeController { * @param date 格式yyyyMMddHHmm 202211261700 */ @GetMapping("fetchGaodeData") - public void fetchGaodeDataByHand(String date) { + public void fetchGaodeDataByHand(String date) throws InterruptedException { Date currentDate = new Date(); if (date != null) { currentDate = DateUtil.parse(date, "yyyyMMddHHmm"); } Integer cnt = _fetchGaodeData(currentDate, "total_flow"); + Thread.sleep(1 * 1000); Integer visitCnt = _fetchGaodeData(currentDate, "visit_flow"); - + Thread.sleep(1 * 1000); String total_flow = _fetchGaodeHotData(currentDate, "total_flow"); - System.out.println(total_flow); + Thread.sleep(1 * 1000); + String visit_flow = _fetchGaodeHotData(currentDate, "visit_flow"); LambdaQueryWrapper queryWrapper = new QueryWrapper().lambda() .eq(CrowdFlow::getCaptureTime, currentDate); CrowdFlow entity = crowdFlowMapper.selectOne(queryWrapper); @@ -102,9 +114,11 @@ public class GaodeController { crowdFlow.setCnt(cnt); crowdFlow.setVisitCnt(visitCnt); crowdFlowMapper.insert(crowdFlow); - }else if (cnt != entity.getCnt() || visitCnt != entity.getVisitCnt()){ + }else { entity.setCnt(cnt); entity.setVisitCnt(visitCnt); + entity.setTotalAreaData(total_flow); + entity.setVisitAreaData(visit_flow); crowdFlowMapper.updateById(entity); } } @@ -124,15 +138,22 @@ public class GaodeController { crowdFlowPage = crowdFlowMapper.selectPage(flowPage, null); List crowdFlows = crowdFlowPage.getRecords(); for (CrowdFlow crowdFlow : crowdFlows) { + //限流策略, 每秒不超过3次。每分钟不超过100次,每小时不超过1000次 Integer cnt = _fetchGaodeData(crowdFlow.getCaptureTime(), "total_flow"); + Thread.sleep(3 * 1000); Integer visitCnt = _fetchGaodeData(crowdFlow.getCaptureTime(), "visit_flow"); //接口有限流,调一会就不通了,延时一会 - Thread.sleep(4 * 1000); - if (crowdFlow.getVisitCnt() != visitCnt) { - crowdFlow.setVisitCnt(visitCnt); - } - if (crowdFlow.getCnt() != cnt) { + Thread.sleep(3 * 1000); + String total_flow = _fetchGaodeHotData(crowdFlow.getCaptureTime(), "total_flow"); + Thread.sleep(3 * 1000); + String visit_flow = _fetchGaodeHotData(crowdFlow.getCaptureTime(), "visit_flow"); + if (crowdFlow.getVisitCnt() != visitCnt || crowdFlow.getCnt() != cnt || + crowdFlow.getVisitAreaData() == null || + crowdFlow.getTotalAreaData() == null) { crowdFlow.setCnt(cnt); + crowdFlow.setVisitCnt(visitCnt); + crowdFlow.setTotalAreaData(total_flow); + crowdFlow.setVisitAreaData(visit_flow); crowdFlowMapper.updateById(crowdFlow); } } @@ -190,7 +211,8 @@ public class GaodeController { parame.put("appname","dz-qingdao-chengguan"); parame.put("apiid","484"); - parame.put("areaId","WY00017X7U"); +// parame.put("areaId","WY00017X7U"); + parame.put("areaId","WY00017X7V"); parame.put("timeType","15m"); parame.put("flowType", flowType); String ds = DateUtil.format(currentDate, "yyyyMMddHHmm"); @@ -212,7 +234,7 @@ public class GaodeController { Map data = (Map) forObject.get("data"); if (data != null) { Map indexData = (Map) data.get("index_data"); - Map analysis = (Map) indexData.get("analysis"); + Map analysis = (Map) indexData.get("query"); if (analysis != null && analysis.get("area_data") != null) { return JSON.toJSONString(analysis.get("area_data")); } @@ -233,7 +255,6 @@ public class GaodeController { @Scheduled(cron = "0 0/15 * * * ?") public void fetchGaodeData() { - System.out.println(Thread.currentThread().getName()); DateTime dateTime = DateUtil.date().setField(DateField.MILLISECOND, 0); DateTime currentDate = DateUtil.offsetMinute(dateTime, -15); @@ -246,10 +267,15 @@ public class GaodeController { if (visitCnt == null) { visitCnt = 0; } + + String total_flow = _fetchGaodeHotData(currentDate, "total_flow"); + String visit_flow = _fetchGaodeHotData(currentDate, "visit_flow"); CrowdFlow crowdFlow = new CrowdFlow(); crowdFlow.setCaptureTime(currentDate); crowdFlow.setCnt(cnt); crowdFlow.setVisitCnt(visitCnt); + crowdFlow.setVisitAreaData(visit_flow); + crowdFlow.setTotalAreaData(total_flow); crowdFlowMapper.insert(crowdFlow); } diff --git a/src/main/java/com/hisense/monitormanage/entity/CrowdFlow.java b/src/main/java/com/hisense/monitormanage/entity/CrowdFlow.java index a86dbb5..9d5eec8 100644 --- a/src/main/java/com/hisense/monitormanage/entity/CrowdFlow.java +++ b/src/main/java/com/hisense/monitormanage/entity/CrowdFlow.java @@ -21,8 +21,24 @@ public class CrowdFlow { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date captureTime; + /** + * 总人数 + */ private Integer cnt; + /** + * 访客总人数 + */ private Integer visitCnt; + /** + * 区域总热力数据 + */ + private String totalAreaData; + + /** + * 区域访客热力数据 + */ + private String visitAreaData; + }