From 50fbfd66458fdf50602d4ef4610cef5d5190fb65 Mon Sep 17 00:00:00 2001 From: yitonglei Date: Mon, 16 May 2022 09:14:01 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=AF=A2=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E8=A7=86=E9=A2=91=E7=82=B9=E6=92=AD=E5=B7=A1=E6=A3=80?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=EF=BC=8C=E5=9C=A8MonitorService=E4=B8=AD?= =?UTF-8?q?=E5=B0=86listChannelPlayStates=E5=81=9A=E6=88=90=E8=B0=83?= =?UTF-8?q?=E5=BA=A6=E4=BB=BB=E5=8A=A1=EF=BC=8C=E6=AF=8F=E5=A4=A9=E7=9A=84?= =?UTF-8?q?6=E7=82=B95=E5=88=86=E6=89=A7=E8=A1=8C=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E8=AF=A2=E5=BD=93=E5=89=8D=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=88=AA=E6=AD=A2=E5=90=91=E5=89=8D=E6=8E=A81=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitormanage/controller/Controller.java | 36 ++++---- .../monitormanage/entity/CameraCheck.java | 31 +++++++ .../monitormanage/entity/SedimentTrail.java | 1 + .../mapper/CameraChannelMapper.java | 3 + .../monitormanage/service/MonitorService.java | 83 ++++++++++++++----- .../service/PassengerFlowService.java | 36 +++++++- .../service/SedimentTrailService.java | 20 ++++- .../monitormanage/utils/EhcacheUtil.java | 19 +++-- .../resources/mapper/CameraChannelMapper.xml | 19 +++-- 9 files changed, 188 insertions(+), 60 deletions(-) create mode 100644 src/main/java/com/hisense/monitormanage/entity/CameraCheck.java diff --git a/src/main/java/com/hisense/monitormanage/controller/Controller.java b/src/main/java/com/hisense/monitormanage/controller/Controller.java index fe50795..596036c 100644 --- a/src/main/java/com/hisense/monitormanage/controller/Controller.java +++ b/src/main/java/com/hisense/monitormanage/controller/Controller.java @@ -11,6 +11,9 @@ import org.springframework.web.bind.annotation.RestController; import java.time.Clock; import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -235,25 +238,13 @@ public class Controller { } //查询视频点播巡检结果,只取异常的 - @RequestMapping("listChannelPlayStates") - public Result listChannelPlayStates( - @RequestParam(value="page",required = false,defaultValue = "1") Integer page, - @RequestParam(value="pageSize",required = false,defaultValue = "20") String pageSize - ){ - Map condition = new HashMap<>(); - LocalDateTime localDateTime = LocalDateTime.now(Clock.systemUTC()); - - LocalDateTime startTime = localDateTime.minusDays(7); - condition.put("diagnoseResultState",0); - condition.put("startTime",startTime.toString()); - condition.put("endTime",localDateTime.toString()); - - Map map = new HashMap<>(); - map.put("condition",condition); - map.put("page",page); - map.put("pageSize",pageSize); - return monitorService.listChannelPlayStates(map); - } +// @RequestMapping("listChannelPlayStates") +// public Result listChannelPlayStates( +// @RequestParam(value="page",required = false,defaultValue = "1") Integer page, +// @RequestParam(value="pageSize",required = false,defaultValue = "20") Integer pageSize +// ){ +// return monitorService.listChannelPlayStates(); +// } //道路统计数据与排名 @RequestMapping("roadData") @@ -325,16 +316,17 @@ public class Controller { @RequestParam(value = "end") String end ){ System.out.println("listSedimentTrailByPoints......"); - List list = sedimentTrailService.listSedimentTrailByPoints(longitude,latitude,raidus,start,end); - return Result.success(list); + Map> map = sedimentTrailService.listSedimentTrailByPoints(longitude,latitude,raidus,start,end); + return Result.success(map); } @RequestMapping("passengerFlow") + //测试 public List passengerFlow(){ List list = passengerFlowService.passengerFlow(); return list; } - //从提供方获取实时客流列表 + //从提供方获取最新的实时客流列表 @RequestMapping("listPassengerFlow") public List listPassengerFlow(){ List list = passengerFlowService.passengerFlow(); diff --git a/src/main/java/com/hisense/monitormanage/entity/CameraCheck.java b/src/main/java/com/hisense/monitormanage/entity/CameraCheck.java new file mode 100644 index 0000000..2b87861 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/entity/CameraCheck.java @@ -0,0 +1,31 @@ +package com.hisense.monitormanage.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; +import lombok.Setter; + +import java.time.ZonedDateTime; + +/** + * @author admin + * @version 1.0.0 + * @ClassName CameraCheck.java + * @Description 摄像头巡检类 + * @createTime 2022年05月13日 20:57:00 + */ +@Getter +@Setter +public class CameraCheck { + private String cameraType; + private String channelCode; +// private String channelName; +// private String channelSn; +// private String channelType; +// private String deviceCode; +// private String deviceIp; +// private String deviceName; +// @JsonFormat(pattern="yyyyMMdd'T'HHmmss'Z'") +// private ZonedDateTime checkTime; + + +} diff --git a/src/main/java/com/hisense/monitormanage/entity/SedimentTrail.java b/src/main/java/com/hisense/monitormanage/entity/SedimentTrail.java index ba6474f..81bce71 100644 --- a/src/main/java/com/hisense/monitormanage/entity/SedimentTrail.java +++ b/src/main/java/com/hisense/monitormanage/entity/SedimentTrail.java @@ -26,6 +26,7 @@ public class SedimentTrail{ private Integer id; private double speed; private String simCardNum; + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private LocalDateTime uploadtime; private double coordinateX; private double coordinateY; diff --git a/src/main/java/com/hisense/monitormanage/mapper/CameraChannelMapper.java b/src/main/java/com/hisense/monitormanage/mapper/CameraChannelMapper.java index b91a203..1347756 100644 --- a/src/main/java/com/hisense/monitormanage/mapper/CameraChannelMapper.java +++ b/src/main/java/com/hisense/monitormanage/mapper/CameraChannelMapper.java @@ -10,9 +10,12 @@ import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; +import java.util.Map; public interface CameraChannelMapper extends BaseMapper { + void updateCameraStatus(List list); + List selectAll(); @Select("select cc.*,cp.pic_url from t_camera_channel cc LEFT JOIN t_channel_picture cp ON cc.channel_code=cp.channel_code where cc.channel_id = #{channelId}") diff --git a/src/main/java/com/hisense/monitormanage/service/MonitorService.java b/src/main/java/com/hisense/monitormanage/service/MonitorService.java index 290dc41..0f069ef 100644 --- a/src/main/java/com/hisense/monitormanage/service/MonitorService.java +++ b/src/main/java/com/hisense/monitormanage/service/MonitorService.java @@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.*; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Base64Utils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -33,9 +34,12 @@ import java.io.File; import java.io.IOException; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.List; +import java.util.stream.Collectors; @Service @@ -77,7 +81,7 @@ public class MonitorService { // final private String userName = "chengshiyunnao"; // final private String password = "QDyjj@2021"; - final private String userName = "yunnaoshuzidizuo"; + final private String userName = "ynszdz"; final private String password = "Admin@123"; final private String monitorDomain = "http://10.132.191.3:8314"; @@ -507,29 +511,71 @@ public class MonitorService { } //查询视频点播巡检结果 - public Result listChannelPlayStates(Map map){ + @Scheduled(cron="0 5 6 * * ?") + public Result listChannelPlayStates(){ + //获取当前时间和前一天的UTC时间 + Map condition = new HashMap<>(); + ZonedDateTime endUTC = ZonedDateTime.now(ZoneOffset.UTC); + ZonedDateTime startUTC = endUTC.minusDays(1); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"); + condition.put("checkStatus",0); + condition.put("startTime",startUTC); + condition.put("endTime",endUTC); + //组装查询条件,经过验证pageSize设置过大也没效果,最大512 + Map map = new HashMap<>(); + map.put("condition",condition); + map.put("page",1); + map.put("pageSize",500);//最多一次512条 + //查询路径和请求头信息 String url = monitorDomain + "/nms/api/channel/play/list"; HttpHeaders headers = new HttpHeaders(); headers.add("X-Subject-Token",token); - int nextPage = 0; - int thisPage = 1; - JSONArray jsonArray = new JSONArray(); - while(nextPage >= 0){ - map.put("page",thisPage); - HttpEntity> request = new HttpEntity<>(map,headers); - ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class ); - JSONObject result = responseEntity.getBody(); - jsonArray.add(result.get("results")); - nextPage = result.getIntValue("nextPage"); - thisPage = nextPage; - } - List list = JSONObject.parseArray(JSONObject.toJSONString(jsonArray),Map.class); + //查询数据的页数 + int pageCount = 0; + //查询结果 + List list = new ArrayList<>(); - List> listMap = Lists.partition(list,500); - for(List ll:listMap){ - cameraChannelMapper.updateState(ll); + HttpEntity> request = new HttpEntity<>(map,headers); + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class ); + JSONObject entityBody = responseEntity.getBody(); + List results = (List) entityBody.get("results"); + if(!results.isEmpty()){ + list.addAll(results); + pageCount = entityBody.getIntValue("totalCount")/500 + 1; } + for(int i = 2;i<=pageCount;i++){ + map.put("page",i); + HttpEntity> request2 = new HttpEntity<>(map,headers); + ResponseEntity responseEntity2 = restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class ); + JSONObject entityBody2 = responseEntity.getBody(); + List results2 = (List) entityBody.get("results"); + if(!results2.isEmpty()){ + list.addAll(results); + } + } +// List list1 = JSONObject.parseArray(JSONObject.toJSONString(jsonArray),CameraCheck.class); +// Map collect = list.stream().collect(Collectors.groupingBy( +// CameraCheck::getChannelCode, +// Collectors.collectingAndThen( +// Collectors.reducing((c1, c2) -> c1.getCheckTime().compareTo(c2.getCheckTime()) > 0 ? c1 : c2), Optional::get) +// ) +// ); +// + //通过set对channel_code去重 + Set set = new HashSet<>(); + + for(Map m:list){ + set.add(m.get("channelCode").toString()); + } + List lists = new ArrayList<>(set.size()); + lists.addAll(set); + //根据channel_code对t_camera_channel表的status字段进行更新(0) + List> listMap = Lists.partition(lists,100); + for(List ll:listMap){ + cameraChannelMapper.updateCameraStatus(ll); + } + log.info("{} 查询视频点播巡检成功,发现异常数量:{}",LocalDateTime.now(),set.size()); return Result.success(); } @@ -564,7 +610,6 @@ public class MonitorService { //启迪数据中台相关 //1.登录 - public String qidiToken () { String url = "http://120.221.95.13:9090/apin/authorization/oauth/token"; HttpHeaders headers = new HttpHeaders(); diff --git a/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java b/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java index d2d5e7b..fc4a10c 100644 --- a/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java +++ b/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java @@ -49,8 +49,9 @@ public class PassengerFlowService { @Value("7eb78b134e0310904d46039ccea20c32") private String appSecret; + /** - * 实时客流 + * 最新的实时客流 * @param * @return List */ @@ -63,7 +64,7 @@ public class PassengerFlowService { LocalDateTime dateNow = LocalDateTime.now(); String timeStamp = dateNow.format(dateTimeFormatter1);//yyyyMMddHHmmss - String[] tt = this.minusMinutesStr(dateNow,180); + String[] tt = this.newMinusMinutesStr(dateNow); String url = "http://15.72.158.72:8081/getway/api/Proxy/HandleByKey/1249fcc8-0466-4897-87b4-d2111a9baf4f"; map.put("APIKEY",APIKEY); @@ -82,6 +83,7 @@ public class PassengerFlowService { map.put("ParamJson",para); System.out.println("multimap->"+map.toString()); + log.info("[passengerFlow] ->",map.toString()); ResponseEntity responseEntity; List list = new ArrayList<>(); try{ @@ -219,6 +221,36 @@ public class PassengerFlowService { t2 = t1.substring(0,t1.length()-2); System.out.println("t1->"+t1+"...t2->"+t2); return new String[]{t1,t2}; + } + //查询出最新有游客数据的时间点 + private String[] newMinusMinutesStr(LocalDateTime datetime){ + String t1,t2;//t1 yyyyMMddHHmm t2 yyyyMMddHH + LocalDateTime minus = datetime.minus(125, ChronoUnit.MINUTES); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmm"); + DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyyMMddHH"); + String time1 = minus.format(dateTimeFormatter); + System.out.println(time1); + String mm = time1.substring(time1.length() -2,time1.length()); + System.out.println(mm); + + Integer i = Integer.parseInt(mm)/15; + if(i == 0){ + t1 = time1.substring(0,time1.length() -2)+"00"; + }else{ + t1 = time1.substring(0,time1.length() -2)+String.valueOf(15*i); + } +// 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)+"30"; +// }else{ +// t1 = time1; +// } + + t2 = t1.substring(0,t1.length()-2); + System.out.println("t1->"+t1+"...t2->"+t2); + return new String[]{t1,t2}; } } diff --git a/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java b/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java index a5bec9c..44ae754 100644 --- a/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java +++ b/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java @@ -11,8 +11,12 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestParam; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collector; +import java.util.stream.Collectors; /** * @author admin @@ -50,10 +54,20 @@ public class SedimentTrailService { * @param longitude(经度) latitude(纬度) raidus(米) start(时间) end(时间) * */ - public List listSedimentTrailByPoints(double longitude, double latitude, Integer raidus,String start,String end){ + public Map> listSedimentTrailByPoints(double longitude, double latitude, Integer raidus,String start,String end){ double[] points = LongLatUtil.getAround(longitude,latitude,raidus); QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.between("update_time",start,end).between("longitude",points[0],points[2]).between("latitude",points[1],points[3]); - return sedimentTrailMapper.selectList(wrapper); + wrapper.between("update_time",start,end).between("longitude",points[0],points[2]).between("latitude",points[1],points[3]) + .orderByAsc("sim_card_num","record_time"); + List maps = new ArrayList<>(); + Map> map = new HashMap<>(); + try{ + List list = sedimentTrailMapper.selectList(wrapper); + map = list.stream().collect(Collectors.groupingBy(SedimentTrail::getSimCardNum)); + + }catch (Exception e){ + log.error("[listSedimentTrailByPoints] Exception:",e.getMessage()); + } + return map; } } diff --git a/src/main/java/com/hisense/monitormanage/utils/EhcacheUtil.java b/src/main/java/com/hisense/monitormanage/utils/EhcacheUtil.java index 25e36e6..c71c684 100644 --- a/src/main/java/com/hisense/monitormanage/utils/EhcacheUtil.java +++ b/src/main/java/com/hisense/monitormanage/utils/EhcacheUtil.java @@ -4,6 +4,9 @@ import net.sf.ehcache.CacheManager; import java.net.URL; import net.sf.ehcache.Cache; import net.sf.ehcache.Element; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.xml.ws.Action; /** * @author admin @@ -22,7 +25,7 @@ public class EhcacheUtil { manager = CacheManager.create(url); } -public static EhcacheUtil getInstance() { + public static EhcacheUtil getInstance() { if (ehCache== null) { ehCache= new EhcacheUtil(path); } @@ -35,18 +38,18 @@ public static EhcacheUtil getInstance() { cache.put(element); } -public Object get(String cacheName, String key) { - Cache cache = manager.getCache(cacheName); - Element element = cache.get(key); - return element == null ? null : element.getObjectValue(); + public Object get(String cacheName, String key) { + Cache cache = manager.getCache(cacheName); + Element element = cache.get(key); + return element == null ? null : element.getObjectValue(); } public Cache get(String cacheName) { return manager.getCache(cacheName); } -public void remove(String cacheName, String key) { - Cache cache = manager.getCache(cacheName); - cache.remove(key); + public void remove(String cacheName, String key) { + Cache cache = manager.getCache(cacheName); + cache.remove(key); } } diff --git a/src/main/resources/mapper/CameraChannelMapper.xml b/src/main/resources/mapper/CameraChannelMapper.xml index f82012f..76fe9cd 100644 --- a/src/main/resources/mapper/CameraChannelMapper.xml +++ b/src/main/resources/mapper/CameraChannelMapper.xml @@ -1,13 +1,13 @@ - - - update CameraChannel set state =#{item.estAmount,jdbcType=NUMERIC} - where t.licai_id = #{item.licaiId,jdbcType=NUMERIC} - + + + + + - + + + + update t_camera_channel set check_status = 0 + where channel_code = #{item,jdbcType=VARCHAR} + + + \ No newline at end of file