1.修改查询视频视频点播巡检结果,在MonitorService中将listChannelPlayStates做成调度任务,每天的6点5分执行一次,查询当前时间截止向前推1天

This commit is contained in:
yitonglei 2022-05-16 09:14:01 +08:00
parent ae96948655
commit 50fbfd6645
9 changed files with 188 additions and 60 deletions

View File

@ -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<String,Object> 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<String,Object> 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<SedimentTrail> list = sedimentTrailService.listSedimentTrailByPoints(longitude,latitude,raidus,start,end);
return Result.success(list);
Map<String,List<SedimentTrail>> map = sedimentTrailService.listSedimentTrailByPoints(longitude,latitude,raidus,start,end);
return Result.success(map);
}
@RequestMapping("passengerFlow")
//测试
public List<Map> passengerFlow(){
List<Map> list = passengerFlowService.passengerFlow();
return list;
}
//从提供方获取实时客流列表
//从提供方获取最新的实时客流列表
@RequestMapping("listPassengerFlow")
public List<Map> listPassengerFlow(){
List<Map> list = passengerFlowService.passengerFlow();

View File

@ -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;
}

View File

@ -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;

View File

@ -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<CameraChannel> {
void updateCameraStatus(List<String> list);
List<CameraChannelDto> 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}")

View File

@ -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<String,Object> map){
@Scheduled(cron="0 5 6 * * ?")
public Result listChannelPlayStates(){
//获取当前时间和前一天的UTC时间
Map<String,Object> 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<String,Object> 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);
//查询数据的页数
int pageCount = 0;
//查询结果
List<Map> list = new ArrayList<>();
HttpEntity<Map<String,Object>> request = new HttpEntity<>(map,headers);
ResponseEntity<JSONObject> responseEntity = restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class );
JSONObject result = responseEntity.getBody();
jsonArray.add(result.get("results"));
nextPage = result.getIntValue("nextPage");
thisPage = nextPage;
JSONObject entityBody = responseEntity.getBody();
List<Map> results = (List<Map>) entityBody.get("results");
if(!results.isEmpty()){
list.addAll(results);
pageCount = entityBody.getIntValue("totalCount")/500 + 1;
}
List<Map> list = JSONObject.parseArray(JSONObject.toJSONString(jsonArray),Map.class);
for(int i = 2;i<=pageCount;i++){
map.put("page",i);
HttpEntity<Map<String,Object>> request2 = new HttpEntity<>(map,headers);
ResponseEntity<JSONObject> responseEntity2 = restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class );
JSONObject entityBody2 = responseEntity.getBody();
List<Map> results2 = (List<Map>) entityBody.get("results");
if(!results2.isEmpty()){
list.addAll(results);
}
}
// List<CameraCheck> list1 = JSONObject.parseArray(JSONObject.toJSONString(jsonArray),CameraCheck.class);
// Map<String, CameraCheck> 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<String> set = new HashSet<>();
List<List<Map>> listMap = Lists.partition(list,500);
for(List<Map> ll:listMap){
cameraChannelMapper.updateState(ll);
for(Map m:list){
set.add(m.get("channelCode").toString());
}
List<String> lists = new ArrayList<>(set.size());
lists.addAll(set);
//根据channel_code对t_camera_channel表的status字段进行更新0
List<List<String>> listMap = Lists.partition(lists,100);
for(List<String> 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();

View File

@ -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<String> responseEntity;
List<Map> 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};
}
}

View File

@ -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<SedimentTrail> listSedimentTrailByPoints(double longitude, double latitude, Integer raidus,String start,String end){
public Map<String,List<SedimentTrail>> listSedimentTrailByPoints(double longitude, double latitude, Integer raidus,String start,String end){
double[] points = LongLatUtil.getAround(longitude,latitude,raidus);
QueryWrapper<SedimentTrail> 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<Map> maps = new ArrayList<>();
Map<String, List<SedimentTrail>> map = new HashMap<>();
try{
List<SedimentTrail> list = sedimentTrailMapper.selectList(wrapper);
map = list.stream().collect(Collectors.groupingBy(SedimentTrail::getSimCardNum));
}catch (Exception e){
log.error("[listSedimentTrailByPoints] Exception:",e.getMessage());
}
return map;
}
}

View File

@ -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

View File

@ -1,13 +1,13 @@
<?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.CameraChannelMapper">
<update id="updateState" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
update CameraChannel set state =#{item.estAmount,jdbcType=NUMERIC}
where t.licai_id = #{item.licaiId,jdbcType=NUMERIC}
</foreach>
<!-- <update id="updateState" parameterType="java.util.List">-->
<!-- <foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">-->
<!-- update CameraChannel set state =#{item.estAmount,jdbcType=NUMERIC}-->
<!-- where t.licai_id = #{item.licaiId,jdbcType=NUMERIC}-->
<!-- </foreach>-->
</update>
<!-- </update>-->
<select id="selectAll" resultType="com.hisense.monitormanage.dto.CameraChannelDto">
select c.* from t_camera_channel c
@ -17,4 +17,11 @@
<!-- limit #{page},#{pageSize}-->
</select>
<update id="updateCameraStatus" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" separator=";">
update t_camera_channel set check_status = 0
where channel_code = #{item,jdbcType=VARCHAR}
</foreach>
</update>
</mapper>