From eff16406819ddcafa61dcfd54a96a42c4722e4d5 Mon Sep 17 00:00:00 2001 From: yuhan_jiang <1165121840@qq.com> Date: Fri, 25 Nov 2022 17:56:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AB=98=E5=BE=B7=E5=AE=A2=E6=B5=81=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/MyBatisPlusConfig.java | 19 +++ .../controller/GaodeController.java | 124 ++++++++++++++++++ .../monitormanage/entity/CrowdFlow.java | 26 ++++ .../monitormanage/mapper/CrowdFlowMapper.java | 10 ++ src/main/resources/application-pro.properties | 2 + src/main/resources/application.properties | 2 + 6 files changed, 183 insertions(+) create mode 100644 src/main/java/com/hisense/monitormanage/config/MyBatisPlusConfig.java create mode 100644 src/main/java/com/hisense/monitormanage/controller/GaodeController.java create mode 100644 src/main/java/com/hisense/monitormanage/entity/CrowdFlow.java create mode 100644 src/main/java/com/hisense/monitormanage/mapper/CrowdFlowMapper.java diff --git a/src/main/java/com/hisense/monitormanage/config/MyBatisPlusConfig.java b/src/main/java/com/hisense/monitormanage/config/MyBatisPlusConfig.java new file mode 100644 index 0000000..6186639 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/config/MyBatisPlusConfig.java @@ -0,0 +1,19 @@ +package com.hisense.monitormanage.config; + + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class MyBatisPlusConfig { + + @Bean + public MybatisPlusInterceptor paginationInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; + } +} diff --git a/src/main/java/com/hisense/monitormanage/controller/GaodeController.java b/src/main/java/com/hisense/monitormanage/controller/GaodeController.java new file mode 100644 index 0000000..31897e3 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/controller/GaodeController.java @@ -0,0 +1,124 @@ +package com.hisense.monitormanage.controller; + + +import cn.hutool.core.date.DateUtil; +import cn.hutool.crypto.SecureUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.hisense.monitormanage.entity.CrowdFlow; +import com.hisense.monitormanage.entity.Result; +import com.hisense.monitormanage.mapper.CrowdFlowMapper; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +import java.util.*; + +@RestController +@RequestMapping("api/gaode") +@Api(tags = "高德类数据") +public class GaodeController { + + @Autowired + private CrowdFlowMapper crowdFlowMapper; + + @Autowired + private RestTemplate restTemplate; + + @Value("${gaode.url}") + private String gaodeUrl; + + @GetMapping("crowflow/list") + @ApiOperation("查询不同时间客流量") + @ApiImplicitParams({ + @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) { + + LambdaQueryWrapper queryWrapper = new QueryWrapper().lambda(); + if (start != null) { + queryWrapper.gt(CrowdFlow::getCaptureTime, start); + } + if (end != null) { + queryWrapper.le(CrowdFlow::getCaptureTime, end); + } + if (cValue != null && cValue > 0) { + queryWrapper.gt(CrowdFlow::getCnt, cValue); + } + + Page flowPage = new Page<>(); + flowPage.addOrder(OrderItem.asc("id")); + if (page != null && page > 0) { + flowPage.setCurrent(page); + } + if (size != null && size > 0) { + flowPage.setSize(size); + } + Page result = crowdFlowMapper.selectPage(flowPage, queryWrapper); + + return Result.success(result.getRecords()); + } + + @GetMapping("fetchGaodeData") + public void fetchGaodeDataByHand() { + fetchGaodeData(); + } + + + /** + * 从0开始每隔15分钟执行一次,也就是0,15,30,45 + */ + @Scheduled(cron = "0 0/15 * * * ?") + public void fetchGaodeData() { + + Date currentDate = new Date(); + StringBuilder url = new StringBuilder(gaodeUrl + "/v4/biolap/abapi/query"); + url.append('?'); + TreeMap parame = new TreeMap<>(); + parame.put("key","a7c2748d8af3393b6fa0531023d2b8c8"); + + parame.put("appname","dz-qingdao-chengguan"); + 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("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); + if ((Integer) forObject.get("errcode") == 0) { + Map data = (Map) forObject.get("data"); + if (data != null) { + Map indexData = (Map) data.get("index_data"); + List query = (List) indexData.get("query"); + if (query != null && query.size() == 1) { + CrowdFlow crowdFlow = new CrowdFlow(); + crowdFlow.setCaptureTime(currentDate); + crowdFlow.setCnt(query.get(0)); + 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 new file mode 100644 index 0000000..ef44e76 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/entity/CrowdFlow.java @@ -0,0 +1,26 @@ +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_crowd_flow") +/** + * 客流表 + */ +public class CrowdFlow { + + @TableId + private long id; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date captureTime; + + private Integer cnt; + +} diff --git a/src/main/java/com/hisense/monitormanage/mapper/CrowdFlowMapper.java b/src/main/java/com/hisense/monitormanage/mapper/CrowdFlowMapper.java new file mode 100644 index 0000000..5b5cbe7 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/mapper/CrowdFlowMapper.java @@ -0,0 +1,10 @@ +package com.hisense.monitormanage.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hisense.monitormanage.entity.CrowdFlow; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface CrowdFlowMapper extends BaseMapper { +} diff --git a/src/main/resources/application-pro.properties b/src/main/resources/application-pro.properties index e740d4c..dd4bcdc 100644 --- a/src/main/resources/application-pro.properties +++ b/src/main/resources/application-pro.properties @@ -19,3 +19,5 @@ spring.resources.static-locations=classpath:/static,classpath:/public,file:${hwx #人流调度 scheduled.enable=true + +gaode.url=http://15.72.191.145:8111/amap diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index eccc1ea..c7816e1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -22,4 +22,6 @@ mybatis-plus.mapper-locations=classpath*:/mapper/*.xml swagger.enable=true scheduled.enable=false +gaode.url=http://restapi.amap.com +