1、新增查询道路污染情况接口,修改获取游客数据的定时任务

This commit is contained in:
yitonglei 2022-05-11 14:49:54 +08:00
parent f919ae9e51
commit aafe76b886
7 changed files with 214 additions and 9 deletions

View File

@ -1,16 +1,20 @@
package com.hisense.monitormanage.controller; package com.hisense.monitormanage.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.hisense.monitormanage.dto.CameraChannelDto; import com.hisense.monitormanage.dto.CameraChannelDto;
import com.hisense.monitormanage.dto.ChannelLabelDto; import com.hisense.monitormanage.dto.ChannelLabelDto;
import com.hisense.monitormanage.dto.ChengguanDto; import com.hisense.monitormanage.dto.ChengguanDto;
import com.hisense.monitormanage.dto.ScenicCameraDto; import com.hisense.monitormanage.dto.ScenicCameraDto;
import com.hisense.monitormanage.entity.*; import com.hisense.monitormanage.entity.*;
import com.hisense.monitormanage.mapper.*; import com.hisense.monitormanage.mapper.*;
import com.hisense.monitormanage.service.MonitorService; import com.hisense.monitormanage.service.*;
import com.hisense.monitormanage.service.PassengerFlowService;
import com.hisense.monitormanage.service.SedimentTrailService;
import com.hisense.monitormanage.service.TrailSanitationService;
import org.springframework.beans.factory.annotation.Autowired; 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.web.bind.annotation.RequestMapping; 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;
@ -52,6 +56,9 @@ public class Controller {
@Autowired @Autowired
private TrailSanitationService trailSanitationService; private TrailSanitationService trailSanitationService;
@Autowired
private RoadDataService roadDataService;
@RequestMapping("all") @RequestMapping("all")
public Object all(){ public Object all(){
List<Project> projects = projectMapper.selectList(null); List<Project> projects = projectMapper.selectList(null);
@ -237,6 +244,7 @@ public class Controller {
public List<Map> roadData(){ public List<Map> roadData(){
return monitorService.roadData(); return monitorService.roadData();
} }
//启迪中台 //启迪中台
//登录 //登录
@RequestMapping("qidiToken") @RequestMapping("qidiToken")
@ -310,6 +318,12 @@ public class Controller {
List<Map> list = passengerFlowService.passengerFlow(); List<Map> list = passengerFlowService.passengerFlow();
return list; return list;
} }
//从提供方获取实时客流列表
@RequestMapping("listPassengerFlow")
public List<Map> listPassengerFlow(){
List<Map> list = passengerFlowService.passengerFlow();
return list;
}
//获取实时客流并保存到表t_passenger_flow //获取实时客流并保存到表t_passenger_flow
@RequestMapping("savePassengerFlow") @RequestMapping("savePassengerFlow")
public Result savePassengerFlow(){ public Result savePassengerFlow(){
@ -357,4 +371,12 @@ public class Controller {
List<TrailSanitation> list = trailSanitationService.listSedimentTrailByPoints(longitude,latitude,raidus,start,end); List<TrailSanitation> list = trailSanitationService.listSedimentTrailByPoints(longitude,latitude,raidus,start,end);
return Result.success(list); return Result.success(list);
} }
//查询道路污染数据
@RequestMapping(value="listRoadData")
//2022-05-10 00:00:00
public Result listRoadData(@RequestParam(value="dt") String dt){
List<RoadData> list = roadDataService.listRoadData(dt);
return Result.success(list);
}
} }

View File

@ -0,0 +1,42 @@
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.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* @author admin
* @version 1.0.0
* @ClassName RoadData.java
* @Description 道路统计数据
* @createTime 2022年05月11日 11:10:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("t_road_data")
public class RoadData {
@TableId
private Integer id;
private String regionName;
private String streetName;
private String roadName;
private String start;
private String end;
private double lng;
private double lat;
private double pm10;
private double pm25;
private Integer descPm10Rank;
private Integer ascPm10Rank;
private Integer descPm25Rank;
private Integer ascPm25Rank;
private String points;
@JsonFormat(pattern="yyyy-MM-dd mm:HH:ss",timezone = "GMT+8")
private LocalDateTime dt;
}

View File

@ -0,0 +1,18 @@
package com.hisense.monitormanage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hisense.monitormanage.entity.RoadData;
import java.util.List;
import java.util.Map;
/**
* @author admin
* @version 1.0.0
* @ClassName RoadDataMapper.java
* @Description TODO
* @createTime 2022年05月11日 11:10:00
*/
public interface RoadDataMapper extends BaseMapper<RoadData> {
public void batchSave(List<Map> list);
}

View File

@ -450,7 +450,7 @@ public class MonitorService {
return Result.success(); return Result.success();
} }
//道路统计数据与排名 //道路统计数据与排名调用公开接口
public List<Map> roadData(){ public List<Map> roadData(){
String url = "http://outerdata.novaecs.com/api/qingdaoData/roadData?groupId={groupId}&timeType={timeType}&dt={dt}"; String url = "http://outerdata.novaecs.com/api/qingdaoData/roadData?groupId={groupId}&timeType={timeType}&dt={dt}";

View File

@ -103,6 +103,7 @@ public class PassengerFlowService {
return list; return list;
} }
@Scheduled(cron = "0 31 10-22/1 * * ? ") @Scheduled(cron = "0 31 10-22/1 * * ? ")
//提供的接口能查到当前时间2个小时之前的数据每隔15分钟一次我们只取整点从早8点到晚8点的整点数据
//10:31 到晚上1031每小时的31分执行一次 //10:31 到晚上1031每小时的31分执行一次
public void passengerFlowSchedule(){ public void passengerFlowSchedule(){
//JSONObject map = new JSONObject(); //JSONObject map = new JSONObject();
@ -112,7 +113,7 @@ public class PassengerFlowService {
LocalDateTime dateNow = LocalDateTime.now(); LocalDateTime dateNow = LocalDateTime.now();
String timeStamp = dateNow.format(dateTimeFormatter1);//yyyyMMddHHmmss String timeStamp = dateNow.format(dateTimeFormatter1);//yyyyMMddHHmmss
String[] tt = this.minusMinutesStr(dateNow,180); String[] tt = this.minusMinutesStr(dateNow,120);
String url = "http://15.72.158.72:8081/getway/api/Proxy/HandleByKey/1249fcc8-0466-4897-87b4-d2111a9baf4f"; String url = "http://15.72.158.72:8081/getway/api/Proxy/HandleByKey/1249fcc8-0466-4897-87b4-d2111a9baf4f";
map.put("APIKEY",APIKEY); map.put("APIKEY",APIKEY);
@ -197,9 +198,9 @@ public class PassengerFlowService {
System.out.println(time1); System.out.println(time1);
String mm = time1.substring(time1.length() -2,time1.length()); String mm = time1.substring(time1.length() -2,time1.length());
System.out.println(mm); System.out.println(mm);
if(0 < Integer.parseInt(mm) &&Integer.parseInt(mm)<30){ if(0 < Integer.parseInt(mm) &&Integer.parseInt(mm)>=30){
t1 = time1.substring(0,time1.length() -2)+"30"; t1 = time1.substring(0,time1.length() -2)+"00";
}else if(Integer.parseInt(mm)>30){ }else if(Integer.parseInt(mm)<30){
LocalDateTime lastHour = LocalDateTime.parse(time1,dateTimeFormatter).plus(1,ChronoUnit.HOURS); LocalDateTime lastHour = LocalDateTime.parse(time1,dateTimeFormatter).plus(1,ChronoUnit.HOURS);
t1 = lastHour.format(dateTimeFormatter2)+"00"; t1 = lastHour.format(dateTimeFormatter2)+"00";
}else{ }else{

View File

@ -0,0 +1,103 @@
package com.hisense.monitormanage.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.hisense.monitormanage.entity.RoadData;
import com.hisense.monitormanage.mapper.RoadDataMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
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;
import java.util.stream.Collectors;
/**
* @author admin
* @version 1.0.0
* @ClassName RoadDataService.java
* @Description 道路统计数据service道路污染
* @createTime 2022年05月11日 11:09:00
*/
@Service
@Slf4j
public class RoadDataService {
@Autowired
private RestTemplate restTemplate;
@Autowired
private RoadDataMapper roadDataMapper;
//道路统计数据与排名(道路污染)调用公开接口并保存到表t_road_data
//@Scheduled(cron="0 0 8 * * ?")
public void saveRoadData(){
String url = "http://outerdata.novaecs.com/api/qingdaoData/roadData?groupId={groupId}&timeType={timeType}&dt={dt}";
Map<String,Object> map = new HashMap<>();
map.put("dt",this.dateTimeStr());
map.put("groupId",1);
map.put("timeType","");
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);
}
}
} catch (Exception e) {
log.info("[roadData] exception:{}", e.getMessage());
}
if(list.size() > 0){
List<Map> maps = list.stream().map(l->{
l.put("points",JSONObject.toJSONString(l.get("points")));
l.put("dt",this.dateTimeStr());
return l;
}).collect(Collectors.toList());
List<List<Map>> lists = Lists.partition(maps,200);
lists.forEach(ll->roadDataMapper.batchSave(ll));
}
}
//根据日期查询道路污染数据
public List<RoadData> listRoadData(String dt){
QueryWrapper<RoadData> wrapper = new QueryWrapper<>();
wrapper.eq("dt",dt);
List<RoadData> list = roadDataMapper.selectList(wrapper);
return list;
}
//获取当前日期的时间串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);
}
}

View File

@ -0,0 +1,19 @@
<?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">
<mapper namespace="com.hisense.monitormanage.mapper.RoadDataMapper">
<insert id="batchSave" parameterType="java.util.List">
INSERT INTO t_road_data
(region_name,street_name,road_name,start,end,lng,lat,pm10,pm25,desc_pm10_rank,asc_pm10_rank,
desc_pm25_rank,asc_pm25_rank,points)
VALUES
<foreach collection="list" item="item" separator="," >
(
#{item.regionName},#{item.streetName},#{item.roadName},#{item.start},#{item.end},
#{item.lng},#{item.lat},#{item.pm10},#{item.pm25},#{item.desc_pm10_rank},
#{item.asc_pm10_rank},#{item.desc_pm25_rank},#{item.asc_pm25_rank},#{item.points}
)
</foreach>
</insert>
</mapper>