From aafe76b886d4aade9a11345489d1b2ba105dacd9 Mon Sep 17 00:00:00 2001 From: yitonglei Date: Wed, 11 May 2022 14:49:54 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=81=93=E8=B7=AF=E6=B1=A1=E6=9F=93=E6=83=85=E5=86=B5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E6=B8=B8?= =?UTF-8?q?=E5=AE=A2=E6=95=B0=E6=8D=AE=E7=9A=84=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitormanage/controller/Controller.java | 30 ++++- .../monitormanage/entity/RoadData.java | 42 +++++++ .../monitormanage/mapper/RoadDataMapper.java | 18 +++ .../monitormanage/service/MonitorService.java | 2 +- .../service/PassengerFlowService.java | 9 +- .../service/RoadDataService.java | 103 ++++++++++++++++++ src/main/resources/mapper/RoadDataMapper.xml | 19 ++++ 7 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/hisense/monitormanage/entity/RoadData.java create mode 100644 src/main/java/com/hisense/monitormanage/mapper/RoadDataMapper.java create mode 100644 src/main/java/com/hisense/monitormanage/service/RoadDataService.java create mode 100644 src/main/resources/mapper/RoadDataMapper.xml diff --git a/src/main/java/com/hisense/monitormanage/controller/Controller.java b/src/main/java/com/hisense/monitormanage/controller/Controller.java index bb6b8df..8a75c36 100644 --- a/src/main/java/com/hisense/monitormanage/controller/Controller.java +++ b/src/main/java/com/hisense/monitormanage/controller/Controller.java @@ -1,16 +1,20 @@ 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.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; @@ -52,6 +56,9 @@ public class Controller { @Autowired private TrailSanitationService trailSanitationService; + @Autowired + private RoadDataService roadDataService; + @RequestMapping("all") public Object all(){ List projects = projectMapper.selectList(null); @@ -237,6 +244,7 @@ public class Controller { public List roadData(){ return monitorService.roadData(); } + //启迪中台 //登录 @RequestMapping("qidiToken") @@ -310,6 +318,12 @@ public class Controller { List list = passengerFlowService.passengerFlow(); return list; } + //从提供方获取实时客流列表 + @RequestMapping("listPassengerFlow") + public List listPassengerFlow(){ + List list = passengerFlowService.passengerFlow(); + return list; + } //获取实时客流并保存到表t_passenger_flow @RequestMapping("savePassengerFlow") public Result savePassengerFlow(){ @@ -357,4 +371,12 @@ public class Controller { List list = trailSanitationService.listSedimentTrailByPoints(longitude,latitude,raidus,start,end); return Result.success(list); } + + //查询道路污染数据 + @RequestMapping(value="listRoadData") + //2022-05-10 00:00:00 + public Result listRoadData(@RequestParam(value="dt") String dt){ + List list = roadDataService.listRoadData(dt); + return Result.success(list); + } } diff --git a/src/main/java/com/hisense/monitormanage/entity/RoadData.java b/src/main/java/com/hisense/monitormanage/entity/RoadData.java new file mode 100644 index 0000000..804813a --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/entity/RoadData.java @@ -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; +} diff --git a/src/main/java/com/hisense/monitormanage/mapper/RoadDataMapper.java b/src/main/java/com/hisense/monitormanage/mapper/RoadDataMapper.java new file mode 100644 index 0000000..44918f4 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/mapper/RoadDataMapper.java @@ -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 { + public void batchSave(List list); +} diff --git a/src/main/java/com/hisense/monitormanage/service/MonitorService.java b/src/main/java/com/hisense/monitormanage/service/MonitorService.java index fe96641..fb1420c 100644 --- a/src/main/java/com/hisense/monitormanage/service/MonitorService.java +++ b/src/main/java/com/hisense/monitormanage/service/MonitorService.java @@ -450,7 +450,7 @@ public class MonitorService { return Result.success(); } - //道路统计数据与排名 + //道路统计数据与排名,调用公开接口 public List roadData(){ String url = "http://outerdata.novaecs.com/api/qingdaoData/roadData?groupId={groupId}&timeType={timeType}&dt={dt}"; diff --git a/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java b/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java index bd23c2b..fd9da20 100644 --- a/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java +++ b/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java @@ -103,6 +103,7 @@ public class PassengerFlowService { return list; } @Scheduled(cron = "0 31 10-22/1 * * ? ") + //提供的接口能查到当前时间2个小时之前的数据,每隔15分钟一次,我们只取整点从早8点到晚8点的整点数据 //10:31 到晚上10:31,每小时的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); @@ -197,9 +198,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{ diff --git a/src/main/java/com/hisense/monitormanage/service/RoadDataService.java b/src/main/java/com/hisense/monitormanage/service/RoadDataService.java new file mode 100644 index 0000000..f62f51a --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/service/RoadDataService.java @@ -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 map = new HashMap<>(); + + map.put("dt",this.dateTimeStr()); + map.put("groupId",1); + map.put("timeType","日"); + + ResponseEntity responseEntity; + List 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 maps = list.stream().map(l->{ + l.put("points",JSONObject.toJSONString(l.get("points"))); + l.put("dt",this.dateTimeStr()); + return l; + }).collect(Collectors.toList()); + List> lists = Lists.partition(maps,200); + lists.forEach(ll->roadDataMapper.batchSave(ll)); + } + } + + //根据日期查询道路污染数据 + public List listRoadData(String dt){ + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("dt",dt); + List 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); + } +} diff --git a/src/main/resources/mapper/RoadDataMapper.xml b/src/main/resources/mapper/RoadDataMapper.xml new file mode 100644 index 0000000..5c0a104 --- /dev/null +++ b/src/main/resources/mapper/RoadDataMapper.xml @@ -0,0 +1,19 @@ + + + + + + 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 + + ( + #{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} + ) + + + + \ No newline at end of file