高德热力数据
This commit is contained in:
parent
0653ec5685
commit
ffdc01ef74
|
@ -1,8 +1,11 @@
|
|||
package com.hisense.monitormanage.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
|
@ -23,6 +26,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/gaode")
|
||||
|
@ -58,7 +64,7 @@ public class GaodeController {
|
|||
}
|
||||
|
||||
Page<CrowdFlow> flowPage = new Page<>();
|
||||
flowPage.addOrder(OrderItem.asc("id"));
|
||||
flowPage.addOrder(OrderItem.desc("id"));
|
||||
if (page != null && page > 0) {
|
||||
flowPage.setCurrent(page);
|
||||
}
|
||||
|
@ -67,22 +73,75 @@ public class GaodeController {
|
|||
}
|
||||
Page<CrowdFlow> result = crowdFlowMapper.selectPage(flowPage, queryWrapper);
|
||||
|
||||
return Result.success(result.getRecords());
|
||||
Result success = Result.success(result.getRecords());
|
||||
success.setCount((int) result.getTotal());
|
||||
return success;
|
||||
}
|
||||
|
||||
@GetMapping("fetchGaodeData")
|
||||
public void fetchGaodeDataByHand() {
|
||||
fetchGaodeData();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从0开始每隔15分钟执行一次,也就是0,15,30,45
|
||||
* 手动刷一条数据
|
||||
* @param date 格式yyyyMMddHHmm 202211261700
|
||||
*/
|
||||
@Scheduled(cron = "0 0/15 * * * ?")
|
||||
public void fetchGaodeData() {
|
||||
|
||||
@GetMapping("fetchGaodeData")
|
||||
public void fetchGaodeDataByHand(String date) {
|
||||
Date currentDate = new Date();
|
||||
if (date != null) {
|
||||
currentDate = DateUtil.parse(date, "yyyyMMddHHmm");
|
||||
}
|
||||
Integer cnt = _fetchGaodeData(currentDate, "total_flow");
|
||||
Integer visitCnt = _fetchGaodeData(currentDate, "visit_flow");
|
||||
|
||||
String total_flow = _fetchGaodeHotData(currentDate, "total_flow");
|
||||
System.out.println(total_flow);
|
||||
LambdaQueryWrapper<CrowdFlow> queryWrapper = new QueryWrapper<CrowdFlow>().lambda()
|
||||
.eq(CrowdFlow::getCaptureTime, currentDate);
|
||||
CrowdFlow entity = crowdFlowMapper.selectOne(queryWrapper);
|
||||
if (entity == null){
|
||||
CrowdFlow crowdFlow = new CrowdFlow();
|
||||
crowdFlow.setCaptureTime(currentDate);
|
||||
crowdFlow.setCnt(cnt);
|
||||
crowdFlow.setVisitCnt(visitCnt);
|
||||
crowdFlowMapper.insert(crowdFlow);
|
||||
}else if (cnt != entity.getCnt() || visitCnt != entity.getVisitCnt()){
|
||||
entity.setCnt(cnt);
|
||||
entity.setVisitCnt(visitCnt);
|
||||
crowdFlowMapper.updateById(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷一遍所有数据
|
||||
*
|
||||
*/
|
||||
@GetMapping("fixGaodeData")
|
||||
public void fixGaodeDataByHand() throws InterruptedException {
|
||||
|
||||
Page<CrowdFlow> flowPage = new Page<>();
|
||||
flowPage.addOrder(OrderItem.asc("id"));
|
||||
Page<CrowdFlow> crowdFlowPage = null;
|
||||
do {
|
||||
|
||||
crowdFlowPage = crowdFlowMapper.selectPage(flowPage, null);
|
||||
List<CrowdFlow> crowdFlows = crowdFlowPage.getRecords();
|
||||
for (CrowdFlow crowdFlow : crowdFlows) {
|
||||
Integer cnt = _fetchGaodeData(crowdFlow.getCaptureTime(), "total_flow");
|
||||
Integer visitCnt = _fetchGaodeData(crowdFlow.getCaptureTime(), "visit_flow");
|
||||
//接口有限流,调一会就不通了,延时一会
|
||||
Thread.sleep(4 * 1000);
|
||||
if (crowdFlow.getVisitCnt() != visitCnt) {
|
||||
crowdFlow.setVisitCnt(visitCnt);
|
||||
}
|
||||
if (crowdFlow.getCnt() != cnt) {
|
||||
crowdFlow.setCnt(cnt);
|
||||
crowdFlowMapper.updateById(crowdFlow);
|
||||
}
|
||||
}
|
||||
flowPage.setCurrent(flowPage.getCurrent()+1);
|
||||
|
||||
}while (crowdFlowPage.hasNext());
|
||||
}
|
||||
|
||||
public Integer _fetchGaodeData(Date currentDate, String flowType) {
|
||||
StringBuilder url = new StringBuilder(gaodeUrl + "/v4/biolap/abapi/query");
|
||||
url.append('?');
|
||||
TreeMap<String, Object> parame = new TreeMap<>();
|
||||
|
@ -92,8 +151,9 @@ public class GaodeController {
|
|||
parame.put("apiid","490");
|
||||
parame.put("areaId","WY00017X7U");
|
||||
parame.put("timeType","15m");
|
||||
parame.put("flowType","total_flow");
|
||||
parame.put("ds", DateUtil.format(currentDate, "yyyyMMddhhmmss"));
|
||||
parame.put("flowType", flowType);
|
||||
String ds = DateUtil.format(currentDate, "yyyyMMddHHmm");
|
||||
parame.put("ds", ds);
|
||||
parame.put("timestamp", new Date().getTime() / 1000);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
parame.forEach((key, value) -> {
|
||||
|
@ -105,20 +165,92 @@ public class GaodeController {
|
|||
parame.put("token", token);
|
||||
url.append("token={token}");
|
||||
HashMap forObject = restTemplate.getForObject(url.toString(), HashMap.class, parame);
|
||||
System.out.println(JSON.toJSONString(forObject));
|
||||
if ((Integer) forObject.get("errcode") == 0) {
|
||||
Map data = (Map) forObject.get("data");
|
||||
if (data != null) {
|
||||
Map indexData = (Map) data.get("index_data");
|
||||
List<Map> query = (List) indexData.get("query");
|
||||
if (query != null && query.size() == 1) {
|
||||
CrowdFlow crowdFlow = new CrowdFlow();
|
||||
crowdFlow.setCaptureTime(currentDate);
|
||||
crowdFlow.setCnt((Integer) query.get(0).get("index"));
|
||||
crowdFlowMapper.insert(crowdFlow);
|
||||
return (Integer) query.get(0).get("index");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String _fetchGaodeHotData(Date currentDate, String flowType) {
|
||||
StringBuilder url = new StringBuilder(gaodeUrl + "/v4/biolap/abapi/query");
|
||||
url.append('?');
|
||||
TreeMap<String, Object> parame = new TreeMap<>();
|
||||
parame.put("key","a7c2748d8af3393b6fa0531023d2b8c8");
|
||||
|
||||
parame.put("appname","dz-qingdao-chengguan");
|
||||
parame.put("apiid","484");
|
||||
parame.put("areaId","WY00017X7U");
|
||||
parame.put("timeType","15m");
|
||||
parame.put("flowType", flowType);
|
||||
String ds = DateUtil.format(currentDate, "yyyyMMddHHmm");
|
||||
parame.put("ds", ds);
|
||||
parame.put("geoLength", 10);
|
||||
parame.put("timestamp", new Date().getTime() / 1000);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
parame.forEach((key, value) -> {
|
||||
builder.append(value + ";");
|
||||
url.append(key + "={" + key + "}&");
|
||||
});
|
||||
String secretkey = "4c32a89db1f20b222e08919b29567368";
|
||||
String token = SecureUtil.md5(builder.toString() + secretkey);
|
||||
parame.put("token", token);
|
||||
url.append("token={token}");
|
||||
HashMap forObject = restTemplate.getForObject(url.toString(), HashMap.class, parame);
|
||||
System.out.println(JSON.toJSONString(forObject));
|
||||
if ((Integer) forObject.get("errcode") == 0) {
|
||||
Map data = (Map) forObject.get("data");
|
||||
if (data != null) {
|
||||
Map indexData = (Map) data.get("index_data");
|
||||
Map analysis = (Map) indexData.get("analysis");
|
||||
if (analysis != null && analysis.get("area_data") != null) {
|
||||
return JSON.toJSONString(analysis.get("area_data"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 从0开始每隔15分钟执行一次,也就是0,15,30,45
|
||||
* 为了查询准确需要查上一个15分钟
|
||||
*/
|
||||
@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);
|
||||
|
||||
Integer cnt = _fetchGaodeData(currentDate, "total_flow");
|
||||
if (cnt == null){
|
||||
cnt = 0;
|
||||
}
|
||||
|
||||
Integer visitCnt = _fetchGaodeData(currentDate, "visit_flow");
|
||||
if (visitCnt == null) {
|
||||
visitCnt = 0;
|
||||
}
|
||||
CrowdFlow crowdFlow = new CrowdFlow();
|
||||
crowdFlow.setCaptureTime(currentDate);
|
||||
crowdFlow.setCnt(cnt);
|
||||
crowdFlow.setVisitCnt(visitCnt);
|
||||
crowdFlowMapper.insert(crowdFlow);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,13 @@ import java.util.Date;
|
|||
public class CrowdFlow {
|
||||
|
||||
@TableId
|
||||
private long id;
|
||||
private Long id;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date captureTime;
|
||||
|
||||
private Integer cnt;
|
||||
|
||||
private Integer visitCnt;
|
||||
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
|||
spring.datasource.name=defaultDataSource
|
||||
# 数据库连接地址
|
||||
#spring.datasource.url=jdbc:mysql://15.72.183.91:3306/monitor_manage?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
spring.datasource.url=jdbc:mysql://15.72.183.91:3306/monitor_manage?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=true&serverTimezone=GMT%2B8
|
||||
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/monitor_manage?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=true&serverTimezone=GMT%2B8
|
||||
# 数据库用户名&密码:
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=w@CmM1mBVQkPhdrc
|
||||
#spring.datasource.password=123456
|
||||
#spring.datasource.password=w@CmM1mBVQkPhdrc
|
||||
spring.datasource.password=123456
|
||||
hwx.file.work-path=D:/tupian/
|
||||
hwx.file.pic-host=http://127.0.0.1:7009
|
||||
spring.resources.static-locations=classpath:/static,classpath:/public,file:${hwx.file.work-path}
|
||||
|
|
Loading…
Reference in New Issue