diff --git a/src/main/java/com/hisense/monitormanage/controller/Controller.java b/src/main/java/com/hisense/monitormanage/controller/Controller.java index 227ef5f..b1c96c3 100644 --- a/src/main/java/com/hisense/monitormanage/controller/Controller.java +++ b/src/main/java/com/hisense/monitormanage/controller/Controller.java @@ -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 projects = projectMapper.selectList(null); @@ -147,23 +154,6 @@ public class Controller { } - /** - * 根据channelId查询摄像头详细信息 - * @param channelId - * @return - */ - @RequestMapping("selectByChannelId") - public Result selectByChannelId(String channelId){ - - List list = cameraChannelMapper.selectByChannelId(channelId); - - Result success = Result.success(list); - - return success; - - - } - /** * 根据标签查询对应摄像头 * @return @@ -251,6 +241,7 @@ public class Controller { public List roadData(){ return monitorService.roadData(); } + //启迪中台 //登录 @RequestMapping("qidiToken") @@ -324,6 +315,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(){ @@ -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 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 a650d6b..290dc41 100644 --- a/src/main/java/com/hisense/monitormanage/service/MonitorService.java +++ b/src/main/java/com/hisense/monitormanage/service/MonitorService.java @@ -533,7 +533,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..d2d5e7b 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); @@ -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 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 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{ 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..91f3f30 --- /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