Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/hisense/monitormanage/controller/Controller.java
This commit is contained in:
wuweida 2022-05-11 17:23:24 +08:00
commit 540df792eb
7 changed files with 222 additions and 33 deletions

View File

@ -1,13 +1,17 @@
package com.hisense.monitormanage.controller;
import com.hisense.monitormanage.dto.*;
import com.hisense.monitormanage.dto.CameraChannelDto;
import com.hisense.monitormanage.dto.ChannelLabelDto;
import com.hisense.monitormanage.dto.ChengguanDto;
import com.hisense.monitormanage.dto.ScenicCameraDto;
import com.hisense.monitormanage.entity.*;
import com.hisense.monitormanage.mapper.*;
import com.hisense.monitormanage.service.MonitorService;
import com.hisense.monitormanage.service.PassengerFlowService;
import com.hisense.monitormanage.service.SedimentTrailService;
import com.hisense.monitormanage.service.TrailSanitationService;
import com.hisense.monitormanage.service.*;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@ -49,6 +53,9 @@ public class Controller {
@Autowired
private TrailSanitationService trailSanitationService;
@Autowired
private RoadDataService roadDataService;
@RequestMapping("all")
public Object all(){
List<Project> projects = projectMapper.selectList(null);
@ -147,23 +154,6 @@ public class Controller {
}
/**
* 根据channelId查询摄像头详细信息
* @param channelId
* @return
*/
@RequestMapping("selectByChannelId")
public Result selectByChannelId(String channelId){
List<CameraChannelDto1> list = cameraChannelMapper.selectByChannelId(channelId);
Result success = Result.success(list);
return success;
}
/**
* 根据标签查询对应摄像头
* @return
@ -251,6 +241,7 @@ public class Controller {
public List<Map> roadData(){
return monitorService.roadData();
}
//启迪中台
//登录
@RequestMapping("qidiToken")
@ -324,6 +315,12 @@ public class Controller {
List<Map> list = passengerFlowService.passengerFlow();
return list;
}
//从提供方获取实时客流列表
@RequestMapping("listPassengerFlow")
public List<Map> listPassengerFlow(){
List<Map> list = passengerFlowService.passengerFlow();
return list;
}
//获取实时客流并保存到表t_passenger_flow
@RequestMapping("savePassengerFlow")
public Result savePassengerFlow(){
@ -344,7 +341,7 @@ public class Controller {
@RequestParam(value="raidus") Integer raidus,
@RequestParam(value="timeId") String timeId
){
return Result.success(String.valueOf(passengerFlowService.passengerNums(longitude,latitude,raidus,timeId)));
return Result.success(passengerFlowService.passengerNums(longitude,latitude,raidus,timeId));
}
//查询并保存环卫车轨迹到表t_trail_sanitation

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

@ -533,7 +533,7 @@ public class MonitorService {
return Result.success();
}
//道路统计数据与排名
//道路统计数据与排名调用公开接口
public List<Map> roadData(){
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;
}
@Scheduled(cron = "0 31 10-22/1 * * ? ")
//提供的接口能查到当前时间2个小时之前的数据每隔15分钟一次我们只取整点从早8点到晚8点的整点数据
//10:31 到晚上1031每小时的31分执行一次
public void passengerFlowSchedule(){
//JSONObject map = new JSONObject();
@ -112,7 +113,7 @@ public class PassengerFlowService {
LocalDateTime dateNow = LocalDateTime.now();
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";
map.put("APIKEY",APIKEY);
@ -167,23 +168,32 @@ public class PassengerFlowService {
}
//根据半径一个经纬度和hour_id查询游客总数
public Integer passengerNums(double longitude, double latitude, Integer raidus,String timeId){
public JSONObject passengerNums(double longitude, double latitude, Integer raidus,String timeId){
double[] points = LongLatUtil.getAround(longitude,latitude,raidus);
QueryWrapper<PassengerFlow> wrapper = new QueryWrapper<>();
wrapper.eq("time_id",timeId).between("longitude",points[0],points[2]).between("latitude",points[1],points[3]);
int count = 0;
int allCount = 0;
int localCount = 0;
int nonLocalCount = 0;
JSONObject result = new JSONObject();
try{
List<PassengerFlow> list = passengerFlowMapper.selectList(wrapper);
for(PassengerFlow p:list){
count+=p.getAllNums();
allCount+=p.getAllNums();
localCount+=p.getLocalNums();
nonLocalCount+=p.getNonlocalNums();
}
result.put("local_nums",localCount);
result.put("nonlocal_nums",nonLocalCount);
result.put("all_nums",allCount);
}catch (Exception e){
log.error("[passengerNums] Exception:"+e.getMessage());
return count;
return result;
}
return count;
return result;
}
@ -197,9 +207,9 @@ public class PassengerFlowService {
System.out.println(time1);
String mm = time1.substring(time1.length() -2,time1.length());
System.out.println(mm);
if(0 < Integer.parseInt(mm) &&Integer.parseInt(mm)<30){
t1 = time1.substring(0,time1.length() -2)+"30";
}else if(Integer.parseInt(mm)>30){
if(0 < Integer.parseInt(mm) &&Integer.parseInt(mm)>=30){
t1 = time1.substring(0,time1.length() -2)+"00";
}else if(Integer.parseInt(mm)<30){
LocalDateTime lastHour = LocalDateTime.parse(time1,dateTimeFormatter).plus(1,ChronoUnit.HOURS);
t1 = lastHour.format(dateTimeFormatter2)+"00";
}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>