Commit 9e042857 authored by wangjinjing's avatar wangjinjing

init

parent af2eace4
Pipeline #198 failed with stages
in 0 seconds
长兴县博物馆,每天8:30和15:00抽取监控截图,上传至服务器
\ No newline at end of file
自动推送到第三方
\ No newline at end of file
......@@ -9,10 +9,9 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.quartz.cn</groupId>
<artifactId>VideoofCultural</artifactId>
<artifactId>AlarmAutoSend</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<description>文物局视频截图推送</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......@@ -27,12 +26,6 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
......@@ -50,137 +43,39 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.15-beta2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.9.6</version>
</dependency>
<!--quartz依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.3.8</version>
</dependency>
<!-- redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--kafka依赖-->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<!-- HttpClient依赖 -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.10.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.25</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.46</version>
</dependency>
<version>8.0.27</version>
</dependency>
<!--<dependency>-->
<!--<groupId>ch.qos.logback</groupId>-->
<!--<artifactId>logback-classic</artifactId>-->
<!--<version>1.2.3</version>-->
<!--<scope>compile</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.logging.log4j</groupId>-->
<!--<artifactId>log4j-to-slf4j</artifactId>-->
<!--<version>2.10.0</version>-->
<!--<scope>compile</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.slf4j</groupId>-->
<!--<artifactId>jul-to-slf4j</artifactId>-->
<!--<version>1.7.25</version>-->
<!--<scope>compile</scope>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.alibaba</groupId>-->
<!--<artifactId>fastjson</artifactId>-->
<!--<version>1.2.46</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.logging.log4j</groupId>-->
<!--<artifactId>log4j-api</artifactId>-->
<!--<version>2.17.0</version>-->
<!--</dependency>-->
</dependencies>
......
......@@ -3,18 +3,21 @@ package com.cx.cn.cxquartz;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class CXQuartzApplication extends SpringBootServletInitializer {
public class AlarmAutoSendApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(CXQuartzApplication.class, args);
SpringApplication.run(AlarmAutoSendApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(CXQuartzApplication.class);
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
// Do any additional configuration here
return builder.build();
}
}
package com.cx.cn.cxquartz.bean;
public class PatrolCtrlAlarm {
private String cameraCode;
private String cameraName;
private String time;
private String type;
private String file;
public String getCameraCode() {
return cameraCode;
}
public void setCameraCode(String cameraCode) {
this.cameraCode = cameraCode;
}
public String getCameraName() {
return cameraName;
}
public void setCameraName(String cameraName) {
this.cameraName = cameraName;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
}
package com.cx.cn.cxquartz.bean;
public class PatrolCtrlRecord {
private String cameraCode;
private String cameraName;
private String patrolTime;
private String recordSrc;
private String file;
private String deviceid;
public String getDeviceid() {
return deviceid;
}
public void setDeviceid(String deviceid) {
this.deviceid = deviceid;
}
public String getCameraCode() {
return cameraCode;
}
public void setCameraCode(String cameraCode) {
this.cameraCode = cameraCode;
}
public String getCameraName() {
return cameraName;
}
public void setCameraName(String cameraName) {
this.cameraName = cameraName;
}
public String getPatrolTime() {
return patrolTime;
}
public void setPatrolTime(String patrolTime) {
this.patrolTime = patrolTime;
}
public String getRecordSrc() {
return recordSrc;
}
public void setRecordSrc(String recordSrc) {
this.recordSrc = recordSrc;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
}
package com.cx.cn.cxquartz.bean;
public class PictureTime {
String deviceid;
String lasttime;
public String getDeviceid() {
return deviceid;
}
public void setDeviceid(String deviceid) {
this.deviceid = deviceid;
}
public String getLasttime() {
return lasttime;
}
public void setLasttime(String lasttime) {
this.lasttime = lasttime;
}
}
package com.cx.cn.cxquartz.bean;
public class QuartzTaskErrors {
private Long id;
private String taskexecuterecordid;
private String errorkey;
private Long createtime;
private Long lastmodifytime;
private String errorvalue;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTaskexecuterecordid() {
return taskexecuterecordid;
}
public void setTaskexecuterecordid(String taskexecuterecordid) {
this.taskexecuterecordid = taskexecuterecordid == null ? null : taskexecuterecordid.trim();
}
public String getErrorkey() {
return errorkey;
}
public void setErrorkey(String errorkey) {
this.errorkey = errorkey == null ? null : errorkey.trim();
}
public Long getCreatetime() {
return createtime;
}
public void setCreatetime(Long createtime) {
this.createtime = createtime;
}
public Long getLastmodifytime() {
return lastmodifytime;
}
public void setLastmodifytime(Long lastmodifytime) {
this.lastmodifytime = lastmodifytime;
}
public String getErrorvalue() {
return errorvalue;
}
public void setErrorvalue(String errorvalue) {
this.errorvalue = errorvalue == null ? null : errorvalue.trim();
}
}
package com.cx.cn.cxquartz.bean;
public class QuartzTaskInformations {
private Long id;
private Integer version;
private String taskno;
private String taskname;
private String schedulerrule;
private String frozenstatus;
private String executorno;
private Long frozentime;
private Long unfrozentime;
private Long createtime;
private Long lastmodifytime;
private String sendtype;
private String url;
private String executeparamter;
private String timekey;
private Long objectx;
private Long objecty;
private Long objectw;
private Long objecth;
private String recordtype;
private String metatype;
private String imgsrc;
private String rtsp;
private String videoid;
public String getVideoid() {
return videoid;
}
public void setVideoid(String videoid) {
this.videoid = videoid;
}
public String getImgsrc() {
return imgsrc;
}
public void setImgsrc(String imgsrc) {
this.imgsrc = imgsrc;
}
public String getRtsp() {
return rtsp;
}
public void setRtsp(String rtsp) {
this.rtsp = rtsp;
}
public String getMetatype() {
return metatype;
}
public void setMetatype(String metatype) {
this.metatype = metatype;
}
public Long getObjectx() {
return objectx;
}
public void setObjectx(Long objectx) {
this.objectx = objectx;
}
public Long getObjecty() {
return objecty;
}
public void setObjecty(Long objecty) {
this.objecty = objecty;
}
public Long getObjectw() {
return objectw;
}
public void setObjectw(Long objectw) {
this.objectw = objectw;
}
public Long getObjecth() {
return objecth;
}
public void setObjecth(Long objecth) {
this.objecth = objecth;
}
public String getRecordtype() {
return recordtype;
}
public void setRecordtype(String recordtype) {
this.recordtype = recordtype;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public String getTaskno() {
return taskno;
}
public void setTaskno(String taskno) {
this.taskno = taskno == null ? null : taskno.trim();
}
public String getTaskname() {
return taskname;
}
public void setTaskname(String taskname) {
this.taskname = taskname == null ? null : taskname.trim();
}
public String getSchedulerrule() {
return schedulerrule;
}
public void setSchedulerrule(String schedulerrule) {
this.schedulerrule = schedulerrule == null ? null : schedulerrule.trim();
}
public String getFrozenstatus() {
return frozenstatus;
}
public void setFrozenstatus(String frozenstatus) {
this.frozenstatus = frozenstatus == null ? null : frozenstatus.trim();
}
public String getExecutorno() {
return executorno;
}
public void setExecutorno(String executorno) {
this.executorno = executorno == null ? null : executorno.trim();
}
public Long getFrozentime() {
return frozentime;
}
public void setFrozentime(Long frozentime) {
this.frozentime = frozentime;
}
public Long getUnfrozentime() {
return unfrozentime;
}
public void setUnfrozentime(Long unfrozentime) {
this.unfrozentime = unfrozentime;
}
public Long getCreatetime() {
return createtime;
}
public void setCreatetime(Long createtime) {
this.createtime = createtime;
}
public Long getLastmodifytime() {
return lastmodifytime;
}
public void setLastmodifytime(Long lastmodifytime) {
this.lastmodifytime = lastmodifytime;
}
public String getSendtype() {
return sendtype;
}
public void setSendtype(String sendtype) {
this.sendtype = sendtype == null ? null : sendtype.trim();
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url == null ? null : url.trim();
}
public String getExecuteparamter() {
return executeparamter;
}
public void setExecuteparamter(String executeparamter) {
this.executeparamter = executeparamter == null ? null : executeparamter.trim();
}
public String getTimekey() {
return timekey;
}
public void setTimekey(String timekey) {
this.timekey = timekey == null ? null : timekey.trim();
}
}
package com.cx.cn.cxquartz.bean;
public class QuartzTaskRecords {
private Long id;
private String taskno;
private String timekeyvalue;
private Long executetime;
private String taskstatus;
private Integer failcount;
private String failreason;
private Long createtime;
private Long lastmodifytime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTaskno() {
return taskno;
}
public void setTaskno(String taskno) {
this.taskno = taskno == null ? null : taskno.trim();
}
public String getTimekeyvalue() {
return timekeyvalue;
}
public void setTimekeyvalue(String timekeyvalue) {
this.timekeyvalue = timekeyvalue == null ? null : timekeyvalue.trim();
}
public Long getExecutetime() {
return executetime;
}
public void setExecutetime(Long executetime) {
this.executetime = executetime;
}
public String getTaskstatus() {
return taskstatus;
}
public void setTaskstatus(String taskstatus) {
this.taskstatus = taskstatus == null ? null : taskstatus.trim();
}
public Integer getFailcount() {
return failcount;
}
public void setFailcount(Integer failcount) {
this.failcount = failcount;
}
public String getFailreason() {
return failreason;
}
public void setFailreason(String failreason) {
this.failreason = failreason == null ? null : failreason.trim();
}
public Long getCreatetime() {
return createtime;
}
public void setCreatetime(Long createtime) {
this.createtime = createtime;
}
public Long getLastmodifytime() {
return lastmodifytime;
}
public void setLastmodifytime(Long lastmodifytime) {
this.lastmodifytime = lastmodifytime;
}
}
package com.cx.cn.cxquartz.bean;
public class User {
String id;
String loginName;
String loginCode;
String area1;
String areaName;
String organCode;
String organName;
String types;
String tatus;
String addTime;
String token;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public String getLoginCode() {
return loginCode;
}
public void setLoginCode(String loginCode) {
this.loginCode = loginCode;
}
public String getArea1() {
return area1;
}
public void setArea1(String area1) {
this.area1 = area1;
}
public String getAreaName() {
return areaName;
}
public void setAreaName(String areaName) {
this.areaName = areaName;
}
public String getOrganCode() {
return organCode;
}
public void setOrganCode(String organCode) {
this.organCode = organCode;
}
public String getOrganName() {
return organName;
}
public void setOrganName(String organName) {
this.organName = organName;
}
public String getTypes() {
return types;
}
public void setTypes(String types) {
this.types = types;
}
public String getTatus() {
return tatus;
}
public void setTatus(String tatus) {
this.tatus = tatus;
}
public String getAddTime() {
return addTime;
}
public void setAddTime(String addTime) {
this.addTime = addTime;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}
package com.cx.cn.cxquartz.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
// @Configuration
@EnableCaching //开启注解
public class RedisConfig extends CachingConfigurerSupport {
/**
* retemplate相关配置
*
* @param factory
* @return
*/
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
// 配置连接工厂
template.setConnectionFactory(factory);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jacksonSeial.setObjectMapper(om);
// 值采用json序列化
template.setValueSerializer(jacksonSeial);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template.setKeySerializer(new StringRedisSerializer());
// 设置hash key 和value序列化模式
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(jacksonSeial);
template.afterPropertiesSet();
return template;
}
/**
* 对hash类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForHash();
}
/**
* 对redis字符串类型数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForValue();
}
@Bean
public JedisConnectionFactory redisConnectionFactory() {
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
jedisConnectionFactory.setHostName("<server-hostname-here>");
jedisConnectionFactory.setPort(6379);
jedisConnectionFactory.setPassword("<server-password-here>");
jedisConnectionFactory.afterPropertiesSet();
return jedisConnectionFactory;
}
/**
* 对链表类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForList();
}
/**
* 对无序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForSet();
}
/**
* 对有序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
return redisTemplate.opsForZSet();
}
}
package com.cx.cn.cxquartz.config;
import com.cx.cn.cxquartz.service.quartz.SbtdspsrService;
import com.cx.cn.cxquartz.util.RestUtil;
import com.cx.cn.cxquartz.vo.Sbtdspsr;
import com.cx.cn.cxquartz.service.quartz.TaskService;
import com.cx.cn.cxquartz.vo.TraffrecordData;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestTemplate;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
@Configuration
@EnableScheduling
public class ScheduleTaskConfig {
private static final Logger logger = LoggerFactory.getLogger(ScheduleTaskConfig.class);
@Autowired
private SbtdspsrService sbtdspsrService;
@Value("${file.getrtspbyurl}")
private String getrtspbyurl;
RestUtil restUtil=new RestUtil();
/***
* 每隔20分钟执行一遍判断rtsp 是否变换
*/
// @Scheduled(cron = "0 0 2 * * ? ")
private void statis() {
//查询所有监控设备,更新rtsp 地址
List<Sbtdspsr> sbtdpsrList= sbtdspsrService.list();
//调用decice 端口获得新的rtsp 地址,如果与表里的一样无需更新,不一样则立即更新
for(Sbtdspsr sbtd:sbtdpsrList)
{
restUtil.rtspChangeVlue(sbtd.getSbbh(),sbtd.getSqurllj(),getrtspbyurl);
}
}
// @Scheduled(cron = "0 30/5 6-19 * * ?")//每隔5分钟统计当天目前为止的数据
// private void statistoday() {
// //判断是否为空表
// //执行查询存在更新,不存在新增
// log.info("每隔5分钟");
// Integer result= traffFlowService.insertOrUpdatevehicleTodaystatistic();
// log.info("today"+result);
//
// }
private TaskService taskService;
@Autowired
private RestTemplate restTemplate;
@Scheduled(cron = "*/5 * * * * ?")//每隔5s统计1个小时前到目前为止的数据推送
private void sendAlarm() {
try {
//查询待推送告警信息
List<TraffrecordData> list=taskService.list();
if(list.size()>0){
Map map=restTemplate.getForObject("http://countryside.51iwifi.com/gw/getAccessToken?appid=05744e80b2c211ebe32a8e271066b19e&appsecret=a55a8870b2e911ebe32a8e271066b19e",Map.class);
if(null!=map.get("code") && map.get("code").toString().equals("0")) {
Map mapobj = (Map) map.get("obj");
String accessToken = mapobj.get("accessToken").toString();
HttpHeaders headers = new HttpHeaders();
headers.add("accessToken", accessToken);
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
for (TraffrecordData traff : list) {
if(traff.getFdid().contains("3YSCA450426N3XP")){
traff.setTdmc("红菱村河道监控测试点");
traff.setXzmc("红菱村");
traff.setRecordname("河道监控");
}
if(traff.getRecordtype().equals("20")){
traff.setRecordtype("1");
}
traff.setImagedata("http://zjh189.ncpoi.cc:7180" + traff.getImagedata());
logger.info(" result:{}", new ObjectMapper().writeValueAsString(traff));
HttpEntity<TraffrecordData> requestEntity = new HttpEntity<>(traff, headers);
Map result = restTemplate.postForObject("http://countryside.51iwifi.com/gw/hesc-mq/hesc/mq/receive/cameraalarm", requestEntity, Map.class);
logger.info(" result:{}", new ObjectMapper().writeValueAsString(result));
if (null != result.get("code") && result.get("code").toString().equals("0")) {
taskService.update(traff.getAlarmnum());
logger.info(" send to countryside success");
} else {
logger.error(" send to countryside error");
}
}
}
}
} catch (Exception ex){
logger.error(" send to countryside error:{}",ex);
}
}
}
package com.cx.cn.cxquartz.controller;
import com.cx.cn.cxquartz.bean.QuartzTaskErrors;
import com.cx.cn.cxquartz.bean.QuartzTaskInformations;
import com.cx.cn.cxquartz.service.quartz.QuartzService;
import com.cx.cn.cxquartz.service.quartz.QuartzTaskRecordsService;
import com.cx.cn.cxquartz.service.quartz.SbtdspsrService;
import com.cx.cn.cxquartz.util.ResultEnum;
import com.cx.cn.cxquartz.util.ResultUtil;
import com.cx.cn.cxquartz.vo.QuartzTaskRecordsVo;
import com.cx.cn.cxquartz.vo.Sbtdspsr;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
@RequestMapping("/video")
public class SbtdspsrController {
private static final Logger logger = LoggerFactory.getLogger(SbtdspsrController.class);
@Autowired
private SbtdspsrService sbtdspsrService;
//
// @RequestMapping(value = "/getSbtdspsrbyrtsp", method = RequestMethod.GET)
// public String addTaskpage() {
// return "addtask";
// }
// @RequestMapping(value = "/list", method = RequestMethod.GET)
// @ResponseBody
// public List<Sbtdspsr> list() {
// return sbtdspsrService.list();
//
// }
}
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.vo.Code;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wjj
* @since 2021-04-29
*/
@Mapper
public interface CodeMapper {
Code selectalarmNum(String keyid);
}
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.vo.Face;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wjj
* @since 2021-04-29
*/
@Mapper
public interface FaceMapper {
int insertFace(Face face);
}
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.vo.Pedestrian;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wjj
* @since 2021-04-29
*/
@Mapper
public interface PedestrianMapper {
int insertpedestrian(Pedestrian pedestrian);
}
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.vo.PeopleRideBicyc;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wjj
* @since 2021-04-29
*/
@Mapper
public interface PeopleridebicycMapper {
int insertPeopleRideBicyc( PeopleRideBicyc peopleridebicyc);
}
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.bean.QuartzTaskErrors;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface QuartzTaskErrorsMapper {
int deleteByPrimaryKey(Long id);
int insert(QuartzTaskErrors record);
int insertSelective(QuartzTaskErrors record);
QuartzTaskErrors selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(QuartzTaskErrors record);
int updateByPrimaryKeyWithBLOBs(QuartzTaskErrors record);
int updateByPrimaryKey(QuartzTaskErrors record);
QuartzTaskErrors detailTaskErrors(String recordId);
}
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.bean.PatrolCtrlAlarm;
import com.cx.cn.cxquartz.bean.PatrolCtrlRecord;
import com.cx.cn.cxquartz.bean.PictureTime;
import com.cx.cn.cxquartz.bean.QuartzTaskInformations;
import com.cx.cn.cxquartz.vo.Sbtdspsr;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
@Mapper
public interface QuartzTaskInformationsMapper {
int deleteByPrimaryKey(Long id);
int insert(QuartzTaskInformations record);
int insertSelective(QuartzTaskInformations record);
QuartzTaskInformations selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(QuartzTaskInformations record);
int updateByPrimaryKey(QuartzTaskInformations record);
List<QuartzTaskInformations> selectList(Map<String, Object> map);
Integer selectByTaskNo(String taskNo);
QuartzTaskInformations getTaskByTaskNo(String taskNo);
List<QuartzTaskInformations> getUnfrozenTasks(String status);
int insertRecord(PatrolCtrlRecord record);
int insertAlarm(PatrolCtrlAlarm alarm);
List<PictureTime> findLastPicTime();
List< PatrolCtrlRecord> queryCameraCode(List<String> ids);
List<Sbtdspsr> selectByRtsp(String rtsp);
Integer UpdateExecuteParam(Map map);
List<QuartzTaskInformations> getTaskSByDeviceCode(String devicecode);
Integer deletetask(String tasKno);
}
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.bean.QuartzTaskRecords;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface QuartzTaskRecordsMapper {
int deleteByPrimaryKey(Long id);
long insert(QuartzTaskRecords record);
int insertSelective(QuartzTaskRecords record);
QuartzTaskRecords selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(QuartzTaskRecords record);
int updateByPrimaryKey(QuartzTaskRecords record);
List<QuartzTaskRecords> getTaskRecordsByTaskNo(String taskNo);
}
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.bean.QuartzTaskInformations;
import com.cx.cn.cxquartz.vo.Sbtdspsr;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface SbtdspsrMapper {
List<Sbtdspsr> selectByRtsp( String rtsp);
List<Sbtdspsr> list( );
List<QuartzTaskInformations> selectRecogByRtsp(String rtsp);
int updateRecogByRtsp(Map map);
}
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.vo.Storageserver;
import com.cx.cn.cxquartz.vo.TraffrecordData;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface StorageServerMapper {
List<Storageserver> queryStorageServerAll(Storageserver storageServer);
public interface TaskMapper {
List<TraffrecordData> list();
int update(Integer id);
}
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.vo.TraffAlarmRecord;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import java.util.List;
import java.util.Map;
@Mapper
public interface TraffAlarmRecordMapper {
int inserTraffAlarmRecord(TraffAlarmRecord traffalarmrecord);
int selectmax();
int updateTraffAlarmRecordUrl(TraffAlarmRecord traffalarmrecord);
List<TraffAlarmRecord> getTraffAlarmRecordByProgress(Map<String, Object> map);
int updateTraffAlarmRecordProcess(TraffAlarmRecord traffalarmrecord);
}
\ No newline at end of file
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.vo.TraffpictureParam;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TraffPictureMapper {
int inserTraffpicture(TraffpictureParam traffalarmrecord);
int updateTraffpicture(TraffpictureParam traffalarmrecord);
String queryimgpath(TraffpictureParam traffpicture);
String queryimgdataByid(String id);
int updateTraffpicturePushStatus(TraffpictureParam traffpicture );
}
\ No newline at end of file
package com.cx.cn.cxquartz.dao;
import com.cx.cn.cxquartz.vo.Traffic;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wjj
* @since 2021-04-29
*/@Mapper
public interface TrafficMapper {
int insertTraffic(Traffic traffic);
}
package com.cx.cn.cxquartz.job;
import com.cx.cn.cxquartz.bean.QuartzTaskInformations;
import com.cx.cn.cxquartz.service.quartz.QuartzService;
import com.cx.cn.cxquartz.util.CommonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicInteger;
@Component
public class KafkaListener {
@Autowired
private QuartzService quartzService;
private static final Logger logger = LoggerFactory.getLogger(KafkaListener.class);
private AtomicInteger atomicInteger;
public void messageConsumerHandler(String content) {
logger.info("监听到消息:{}", content);
atomicInteger = new AtomicInteger(0);
String id = "";
String taskNo = "";
try {
// message格式 ---------> taskNo:id:executeParameter;
String[] split = ":".split(content);
id = split[1];
taskNo = split[0];
//TODO kafka逻辑
} catch (Exception ex) {
logger.error("");
atomicInteger.incrementAndGet();
quartzService.addTaskErrorRecord(id, taskNo + ":" + ex.getMessage(), CommonUtil.getExceptionDetail(ex));
}
quartzService.updateRecordById(atomicInteger.get(), Long.parseLong(id));
QuartzTaskInformations quartzTaskInformation = new QuartzTaskInformations();
quartzTaskInformation.setId(Long.parseLong(id));
quartzTaskInformation.setLastmodifytime(System.currentTimeMillis());
quartzService.updateTask(quartzTaskInformation);
}
}
package com.cx.cn.cxquartz.job;
import com.cx.cn.cxquartz.bean.QuartzTaskInformations;
import com.cx.cn.cxquartz.bean.QuartzTaskRecords;
import com.cx.cn.cxquartz.service.quartz.QuartzService;
import com.cx.cn.cxquartz.service.quartz.impl.QuartzServiceImpl;
import com.cx.cn.cxquartz.util.ApplicationContextHolder;
import com.cx.cn.cxquartz.util.CommonUtil;
import com.cx.cn.cxquartz.util.HttpClientUtil;
import com.cx.cn.cxquartz.util.ResultEnum;
import org.apache.commons.lang.StringUtils;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import java.util.concurrent.atomic.AtomicInteger;
@DisallowConcurrentExecution
public class QuartzMainJobFactory implements Job {
private static Logger logger = LoggerFactory.getLogger(QuartzMainJobFactory.class);
private AtomicInteger atomicInteger;
@Value("${local.czurl}")
private String czurl;
@Value("${local.fxurl}")
private String fxurl;
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
atomicInteger = new AtomicInteger(0);
JobDataMap jobDataMap = jobExecutionContext.getMergedJobDataMap();
String id = jobDataMap.getString("id");
String taskNo = jobDataMap.getString("taskNo");
String executorNo = jobDataMap.getString("executorNo");
String url = jobDataMap.getString("url");
String executeParameter = jobDataMap.getString("executeParameter");
logger.info("定时任务被执行:taskNo={},executorNo={},url={},executeParameter={}", taskNo, executorNo, url, executeParameter);
QuartzService quartzService = (QuartzServiceImpl) ApplicationContextHolder.getBean("quartzServiceImpl");
QuartzTaskRecords records = null;
try {
//保存定时任务的执行记录
records = quartzService.addTaskRecords(taskNo);
if (null == records || !ResultEnum.INIT.name().equals(records.getTaskstatus())) {
logger.info("taskNo={}保存执行记录失败", taskNo);
return;
}
//if (ResultEnum.HTTP.getMessage().equals(sendType)) {
try {
String result = HttpClientUtil.doPost(taskNo.contains("cz_") ? czurl : fxurl, "text/json", taskNo);
logger.info("taskNo={},执行结果result{}", taskNo, result);
if (StringUtils.isEmpty(result)) {
throw new RuntimeException("taskNo=" + taskNo + "http方式返回null");
}
} catch (Exception ex) {
logger.error("");
throw ex;
}
// } else if (ResultEnum.KAFKA.getMessage().equals(sendType)) {
// try {
// String message = new StringBuffer(taskNo).append(":").append(id).append(":").append(executeParameter).toString();
// quartzService.sendMessage(message);
// logger.info("taskNo={},sendtype={}推送至kafka成功", taskNo, sendType);
// } catch (Exception ex) {
// logger.error("");
// throw ex;
// }
// }
} catch (Exception ex) {
String exception=CommonUtil.getExceptionDetail(ex);
logger.error(exception);
atomicInteger.incrementAndGet();
quartzService.addTaskErrorRecord(records.getId().toString(), taskNo + ":" + ex.getMessage(), exception);
}
// quartzService.updateRecordById(atomicInteger.get(), records.getId());
//QuartzTaskInformations quartzTaskInformation = new QuartzTaskInformations();
//quartzTaskInformation.setId(Long.parseLong(id));
//quartzTaskInformation.setLastmodifytime(System.currentTimeMillis());
//quartzService.updateTask(quartzTaskInformation);
}
}
package com.cx.cn.cxquartz.job;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@Component
@ServerEndpoint("/websocket/{name}")
public class WebSocket {
/**
* 与某个客户端的连接对话,需要通过它来给客户端发送消息
*/
private Session session;
/**
* 标识当前连接客户端的用户名
*/
private String name;
/**
* 用于存所有的连接服务的客户端,这个对象存储是安全的
*/
private static ConcurrentHashMap<String, WebSocket> webSocketSet = new ConcurrentHashMap<>();
@OnOpen
public void OnOpen(Session session, @PathParam(value = "name") String name) {
this.session = session;
this.name = name;
// name是用来表示唯一客户端,如果需要指定发送,需要指定发送通过name来区分
webSocketSet.put(name, this);
}
@OnClose
public void OnClose() {
webSocketSet.remove(this.name);
}
@OnError
public void OnError(@PathParam("name") String name, Throwable throwable, Session session) {
webSocketSet.remove(name);
}
@OnMessage
public void OnMessage(String message) {
//判断是否需要指定发送,具体规则自定义
if(message.indexOf("HEARTBEAT")>=0){
Map map=new HashMap();
map.put("type","HEARTBEAT");
map.put("ts",new Date().getTime());
AppointSending(name, JSONObject.toJSONString(map));
}
}
/**
* 群发
*
* @param message
*/
public static void GroupSending(String message) {
for (String name : webSocketSet.keySet()) {
try {
if (null != webSocketSet.get(name) && null != webSocketSet.get(name).session && null != webSocketSet.get(name).session.getBasicRemote())
webSocketSet.get(name).session.getBasicRemote().sendText(message);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 指定发送
*
* @param name
* @param message
*/
public void AppointSending(String name, String message) {
if (null != webSocketSet.get(name) && null != webSocketSet.get(name).session && null != webSocketSet.get(name).session.getBasicRemote()) {
synchronized (webSocketSet.get(name).session) {
try {
webSocketSet.get(name).session.getBasicRemote().sendText(message);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.dao.StorageServerMapper;
import com.cx.cn.cxquartz.vo.Storageserver;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Service
public class CacheLoadService {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Value("${redis.cachekey.ftplist}")
private String ftplistkey;
@Autowired
private StorageServerMapper storageServerMapper;
public boolean loadFtpCache() {
try {
Storageserver server = new Storageserver();
server.setServerstatus(0);//�����õ�
server.setServertype("ftp");
List<Storageserver> storageServers = storageServerMapper.queryStorageServerAll(server);
if (!storageServers.isEmpty() && storageServers.size() > 0) {
stringRedisTemplate.opsForValue().set(ftplistkey, new Gson().toJson(storageServers),60, TimeUnit.SECONDS);
} else {
System.out.println("storageServers.isEmpty");
}
return true;
} catch (Exception e) {
System.out.println(e.toString());
return false;
}
}
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.vo.Code;
/**
* <p>
* 服务类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
public interface CodeService {
Code selectalarmNum(String keyid);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.bean.PatrolCtrlAlarm;
import com.cx.cn.cxquartz.bean.PatrolCtrlRecord;
import com.cx.cn.cxquartz.bean.*;
public interface ExtService {
int insertRecord(PatrolCtrlRecord record);
int insertAlarm(PatrolCtrlAlarm alarm);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.vo.Face;
/**
* <p>
* 服务类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
public interface FaceService {
int insertFace(Face face);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.util.RedisEnum;
import com.cx.cn.cxquartz.vo.Ftp;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class FtpService {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final Logger logger = LoggerFactory.getLogger(FtpService.class);
@Autowired
private StringRedisTemplate stringRedisTemplate;
private List<Ftp> ftpList;
@Autowired
CacheLoadService cacheLoadService;
@Autowired
public FtpService(StringRedisTemplate stringRedisTemplate) {
// try {
// this.ftpList = getFtpList(stringRedisTemplate.opsForValue().get(RedisEnum.FTPLIST.getValue()));
// }catch (Exception e){
// logger.error("ftpList error:"+e.toString());
// }
}
public Ftp reloadFtp() {
try {
// cacheLoadService.loadFtpCache();
if(null==stringRedisTemplate.opsForValue().get(RedisEnum.FTPLIST.getValue())){
cacheLoadService.loadFtpCache();
}
ftpList = getFtpList(stringRedisTemplate.opsForValue().get(RedisEnum.FTPLIST.getValue()));
}catch (Exception e){
logger.error("ftpListerror:"+e.toString());
}
Long count = null;
try {
count = stringRedisTemplate.opsForValue().increment(RedisEnum.FTPLIST_INDEX.getValue(), 1L);
} catch (Exception e) {
logger.error("redis error" + e.toString());
}
if (count == null) {
count = 0L;
}
long index = count % ftpList.size();
return ftpList.get((int) index);
}
private List<Ftp> getFtpList(String ftpJson) {
try {
JavaType javaType =OBJECT_MAPPER.getTypeFactory().constructParametricType(ArrayList.class, Map.class);
List<Map> jsonArr = OBJECT_MAPPER.readValue(ftpJson, javaType);
List<Ftp> ftpList = new ArrayList<>();
for (int i = 0; i < jsonArr.size(); i++) {
Ftp ftp = new Ftp();
Map jsonObject = jsonArr.get(i);
ftp.setFtpIp(jsonObject.get("serveip").toString());
ftp.setFtpPort(Integer.parseInt(jsonObject.get("serverport")==null?"21":jsonObject.get("serverport").toString()));
ftp.setFtpUsername(jsonObject.get("serveruser").toString());
ftp.setFtpPassword(jsonObject.get("serverpassword").toString());
ftpList.add(ftp);
}
}catch (Exception ex){
logger.error("ftpListerror:"+ex.toString());
}
return ftpList;
}
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.vo.Pedestrian;
/**
* <p>
* 服务类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
public interface PedestrianService {
int insertpedestrian(Pedestrian pedestrian);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.vo.PeopleRideBicyc;
/**
* <p>
* 服务类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
public interface PeopleridebicycService {
int insertPeopleRideBicyc( PeopleRideBicyc peopleridebicyc);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.bean.*;
import com.cx.cn.cxquartz.vo.QuartzTaskRecordsVo;
import org.quartz.SchedulerException;
import java.util.List;
import java.util.Map;
public interface QuartzService {
String addTask(QuartzTaskInformations quartzTaskInformations);
List<QuartzTaskInformations> getTaskList(String taskNo, String currentPage);
QuartzTaskInformations getTaskById(String id);
String updateTask(QuartzTaskInformations quartzTaskInformations);
Integer UpdateExecuteParam(Map map);
String startJob(String taskNo,String status) throws SchedulerException;
String startOrStopJob(String taskNo,String status) throws SchedulerException;
void initLoadOnlineTasks();
void sendMessage(String message);
QuartzTaskRecords addTaskRecords(String taskNo);
Integer updateRecordById(Integer count, Long id);
Integer updateModifyTimeById(QuartzTaskInformations quartzTaskInformations);
Integer addTaskErrorRecord(String id, String errorKey, String errorValue);
List<QuartzTaskRecordsVo> taskRecords(String taskNo);
String runTaskRightNow(String taskNo);
QuartzTaskErrors detailTaskErrors(String recordId);
Integer insertRecord(PatrolCtrlRecord record);
Integer insertAlarm(PatrolCtrlAlarm alarm);
List<PictureTime> findLastPicTime();
List< PatrolCtrlRecord> queryCameraCode(List<String> ids);
List<QuartzTaskInformations> getTaskSByDeviceCode(String devicecode);
Integer deletetask(String taskno);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.bean.QuartzTaskErrors;
public interface QuartzTaskErrorsService {
Integer addTaskErrorRecord(QuartzTaskErrors quartzTaskErrors);
QuartzTaskErrors detailTaskErrors(String recordId);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.bean.PatrolCtrlAlarm;
import com.cx.cn.cxquartz.bean.PatrolCtrlRecord;
import com.cx.cn.cxquartz.bean.PictureTime;
import com.cx.cn.cxquartz.bean.QuartzTaskInformations;
import java.util.List;
import java.util.Map;
public interface QuartzTaskInformationsService {
String insert(QuartzTaskInformations quartzTaskInformations);
List<QuartzTaskInformations> selectList(String taskNo, String currentPage);
QuartzTaskInformations getTaskById(String id);
String updateTask(QuartzTaskInformations quartzTaskInformations);
Integer UpdateExecuteParam(Map map);
QuartzTaskInformations getTaskByTaskNo(String taskNo);
Integer updateStatusById(QuartzTaskInformations quartzTaskInformations);
List<QuartzTaskInformations> getUnnfrozenTasks(String status);
Integer updateModifyTimeById(QuartzTaskInformations quartzTaskInformations);
Integer insertRecord(PatrolCtrlRecord record);
Integer insertAlarm(PatrolCtrlAlarm alarm);
List<PictureTime> findLastPicTime();
List< PatrolCtrlRecord> queryCameraCode(List<String> ids);
List<QuartzTaskInformations> getTaskSByDeviceCode(String devicecode);
Integer deletetask(String taskno);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.bean.QuartzTaskRecords;
import java.util.List;
public interface QuartzTaskRecordsService {
long addTaskRecords(QuartzTaskRecords quartzTaskRecords);
Integer updateTaskRecords(QuartzTaskRecords quartzTaskRecords);
List<QuartzTaskRecords> listTaskRecordsByTaskNo(String taskNo);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.bean.QuartzTaskInformations;
import com.cx.cn.cxquartz.vo.Sbtdspsr;
import java.util.List;
import java.util.Map;
public interface SbtdspsrService {
List<Sbtdspsr> selectByRtsp(String videoid);
List<QuartzTaskInformations> selectRecogByRtsp(String rtsp);
int updateRecogByRtsp(String rtsp,String devicecode);
List<Sbtdspsr> list();
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.vo.TraffrecordData;
import java.util.List;
public interface TaskService {
List<TraffrecordData> list();
int update(Integer id );
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.vo.TraffAlarmRecord;
import java.util.List;
import java.util.Map;
public interface TraffAlarmRecordService {
int inserTraffAlarmRecord(TraffAlarmRecord traffalarmrecord);
int selectmax();
int updateTraffAlarmRecordUrl(TraffAlarmRecord record);
int updateTraffAlarmRecordProcess(TraffAlarmRecord recordid);
List<TraffAlarmRecord> getTraffAlarmRecordByProgress(Map<String, Object> map);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.vo.TraffpictureParam;
public interface TraffPictureService {
int inserTraffpicture( TraffpictureParam traffpicture);
int updateTraffpicture( TraffpictureParam traffpicture);
String queryimgpath(TraffpictureParam traffpicture);
String queryimgdataByid(String id);
}
package com.cx.cn.cxquartz.service.quartz;
import com.cx.cn.cxquartz.vo.Traffic;
/**
* <p>
* 服务类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
public interface TrafficService {
int insertTraffic(Traffic traffic);
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.dao.CodeMapper;
import com.cx.cn.cxquartz.service.quartz.CodeService;
import com.cx.cn.cxquartz.vo.Code;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
@Service
public class CodeServiceImpl implements CodeService {
@Autowired
private CodeMapper codeMapper;
@Override
public Code selectalarmNum(String keyid) {
return codeMapper.selectalarmNum(keyid);
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.bean.PatrolCtrlAlarm;
import com.cx.cn.cxquartz.bean.PatrolCtrlRecord;
import com.cx.cn.cxquartz.service.quartz.ExtService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ExtServiceImpl implements ExtService {
private static final Logger logger = LoggerFactory.getLogger(ExtServiceImpl.class);
@Autowired
private ExtService extService;
@Override
public int insertAlarm(PatrolCtrlAlarm alarm) {
int result = extService.insertAlarm(alarm);
return result;
}
/**
* 新增图片
*
* @param record
* @returnString
*/
@Override
public int insertRecord(PatrolCtrlRecord record) {
int result = extService.insertRecord(record);
return result;
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.dao.FaceMapper;
import com.cx.cn.cxquartz.service.quartz.FaceService;
import com.cx.cn.cxquartz.vo.Face;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
@Service
public class FaceServiceImpl implements FaceService {
@Autowired
private FaceMapper faceMapper;
@Override
public int insertFace(Face face) {
return faceMapper.insertFace(face);
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.dao.PedestrianMapper;
import com.cx.cn.cxquartz.service.quartz.PedestrianService;
import com.cx.cn.cxquartz.vo.Pedestrian;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
@Service
public class PedestrianServiceImpl implements PedestrianService {
@Autowired
private PedestrianMapper pedestrianMapper;
@Override
public int insertpedestrian(Pedestrian pedestrian) {
return pedestrianMapper.insertpedestrian(pedestrian);
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.dao.PeopleridebicycMapper;
import com.cx.cn.cxquartz.service.quartz.PeopleridebicycService;
import com.cx.cn.cxquartz.vo.PeopleRideBicyc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
@Service
public class PeopleridebicycServiceImpl implements PeopleridebicycService {
@Autowired
private PeopleridebicycMapper peopleridebicycMapper;
@Override
public int insertPeopleRideBicyc(PeopleRideBicyc peopleridebicyc) {
return peopleridebicycMapper.insertPeopleRideBicyc( peopleridebicyc);
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.bean.QuartzTaskErrors;
import com.cx.cn.cxquartz.dao.QuartzTaskErrorsMapper;
import com.cx.cn.cxquartz.service.quartz.QuartzTaskErrorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class QuartzTaskErrorsServiceImpl implements QuartzTaskErrorsService {
@Autowired
private QuartzTaskErrorsMapper quartzTaskErrorsMapper;
@Override
public Integer addTaskErrorRecord(QuartzTaskErrors quartzTaskErrors) {
return quartzTaskErrorsMapper.insert(quartzTaskErrors);
}
@Override
public QuartzTaskErrors detailTaskErrors(String recordId) {
return quartzTaskErrorsMapper.detailTaskErrors(recordId);
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.bean.PatrolCtrlAlarm;
import com.cx.cn.cxquartz.bean.PatrolCtrlRecord;
import com.cx.cn.cxquartz.bean.PictureTime;
import com.cx.cn.cxquartz.bean.QuartzTaskInformations;
import com.cx.cn.cxquartz.dao.QuartzTaskInformationsMapper;
import com.cx.cn.cxquartz.service.quartz.QuartzTaskInformationsService;
import com.cx.cn.cxquartz.util.ResultEnum;
import com.cx.cn.cxquartz.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class QuartzTaskInformationsServiceImpl implements QuartzTaskInformationsService {
@Autowired
private QuartzTaskInformationsMapper quartzTaskInformationsMapper;
@Override
public String insert(QuartzTaskInformations quartzTaskInformations) {
String taskNo = quartzTaskInformations.getTaskno();
quartzTaskInformations.setVersion(0);
quartzTaskInformations.setCreatetime(System.currentTimeMillis());
quartzTaskInformations.setLastmodifytime(System.currentTimeMillis());
Integer count = quartzTaskInformationsMapper.selectByTaskNo(taskNo);
//判断是否重复任务编号
if (count > 0) {
return ResultUtil.success(ResultEnum.TASKNO_EXIST.getCode(), ResultEnum.TASKNO_EXIST.getMessage());
}
int insert = quartzTaskInformationsMapper.insert(quartzTaskInformations);
if (insert < 1) {
return ResultUtil.success(ResultEnum.FAIL.getCode(), ResultEnum.FAIL.getMessage());
}
return ResultUtil.success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage());
}
@Override
public List<QuartzTaskInformations> selectList(String taskNo, String currentPage) {
Map<String, Object> map = new HashMap<>();
Integer start = Integer.parseInt(currentPage);
map.put("taskNo", taskNo);
map.put("startIndex", 10 * (start - 1));
return quartzTaskInformationsMapper.selectList(map);
}
@Override
public QuartzTaskInformations getTaskById(String id) {
return quartzTaskInformationsMapper.selectByPrimaryKey(Long.parseLong(id));
}
@Override
public String updateTask(QuartzTaskInformations quartzTaskInformations) {
Integer count = quartzTaskInformationsMapper.selectByTaskNo(quartzTaskInformations.getTaskno());
//判断是否重复任务编号
if (count >= 2) {
return ResultUtil.success(ResultEnum.TASKNO_EXIST.getCode(), ResultEnum.TASKNO_EXIST.getMessage());
}
//设置解冻时间或冻结时间及最后修改时间
if (ResultEnum.FROZEN.name().equals(quartzTaskInformations.getFrozenstatus())) {
quartzTaskInformations.setFrozentime(System.currentTimeMillis());
} else if (ResultEnum.UNFROZEN.name().equals(quartzTaskInformations.getFrozenstatus())) {
quartzTaskInformations.setUnfrozentime(System.currentTimeMillis());
}
quartzTaskInformations.setLastmodifytime(System.currentTimeMillis());
int updateCount = quartzTaskInformationsMapper.updateByPrimaryKeySelective(quartzTaskInformations);
//乐观锁控制并发修改
if (updateCount < 1) {
return ResultUtil.success(ResultEnum.UPDATE_FAIL.getCode(), ResultEnum.UPDATE_FAIL.getMessage());
}
return ResultUtil.success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage());
}
@Override
public Integer UpdateExecuteParam(Map map) {
return quartzTaskInformationsMapper.UpdateExecuteParam(map);
}
@Override
public QuartzTaskInformations getTaskByTaskNo(String taskNo) {
return quartzTaskInformationsMapper.getTaskByTaskNo(taskNo);
}
@Override
public Integer updateStatusById(QuartzTaskInformations quartzTaskInformations) {
return quartzTaskInformationsMapper.updateByPrimaryKeySelective(quartzTaskInformations);
}
@Override
public List<QuartzTaskInformations> getUnnfrozenTasks(String status) {
return quartzTaskInformationsMapper.getUnfrozenTasks(status);
}
@Override
public Integer updateModifyTimeById(QuartzTaskInformations quartzTaskInformations) {
return quartzTaskInformationsMapper.updateByPrimaryKeySelective(quartzTaskInformations);
}
@Override
public Integer insertRecord(PatrolCtrlRecord record) {
return quartzTaskInformationsMapper.insertRecord(record);
}
@Override
public Integer insertAlarm(PatrolCtrlAlarm alarm) {
return quartzTaskInformationsMapper.insertAlarm(alarm);
}
@Override
public List<PictureTime> findLastPicTime() {
return quartzTaskInformationsMapper.findLastPicTime();
}
@Override
public List<PatrolCtrlRecord> queryCameraCode(List<String> ids){
return quartzTaskInformationsMapper.queryCameraCode(ids);
}
@Override
public List<QuartzTaskInformations> getTaskSByDeviceCode(String devicecode) {
return quartzTaskInformationsMapper.getTaskSByDeviceCode(devicecode);
}
@Override
public Integer deletetask(String taskno) {
return quartzTaskInformationsMapper.deletetask(taskno);
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.bean.QuartzTaskRecords;
import com.cx.cn.cxquartz.dao.QuartzTaskRecordsMapper;
import com.cx.cn.cxquartz.service.quartz.QuartzTaskRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class QuartzTaskRecordsServiceImpl implements QuartzTaskRecordsService {
@Autowired
private QuartzTaskRecordsMapper quartzTaskRecordsMapper;
@Override
public long addTaskRecords(QuartzTaskRecords quartzTaskRecords) {
return quartzTaskRecordsMapper.insert(quartzTaskRecords);
}
@Override
public Integer updateTaskRecords(QuartzTaskRecords quartzTaskRecords) {
return quartzTaskRecordsMapper.updateByPrimaryKeySelective(quartzTaskRecords);
}
public List<QuartzTaskRecords> listTaskRecordsByTaskNo(String taskNo) {
return quartzTaskRecordsMapper.getTaskRecordsByTaskNo(taskNo);
}
;
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.bean.QuartzTaskInformations;
import com.cx.cn.cxquartz.dao.SbtdspsrMapper;
import com.cx.cn.cxquartz.service.quartz.SbtdspsrService;
import com.cx.cn.cxquartz.vo.Sbtdspsr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class SbtdspsrImpl implements SbtdspsrService {
@Autowired
private SbtdspsrMapper sbtdspsrMapper;
public List<Sbtdspsr> selectByRtsp(String videoid)
{
return sbtdspsrMapper.selectByRtsp(videoid);
}
@Override
public List<QuartzTaskInformations> selectRecogByRtsp(String rtsp) {
return sbtdspsrMapper.selectRecogByRtsp(rtsp);
}
@Override
public int updateRecogByRtsp(String rtsp, String devicecode) {
Map map =new HashMap();
map.put("rtsp",rtsp);
map.put("devicecode",devicecode);
return sbtdspsrMapper.updateRecogByRtsp(map);
}
@Override
public List<Sbtdspsr> list() {
return sbtdspsrMapper.list();
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.dao.TrafficMapper;
import com.cx.cn.cxquartz.service.quartz.TrafficService;
import com.cx.cn.cxquartz.vo.Traffic;
import com.cx.cn.cxquartz.dao.TaskMapper;
import com.cx.cn.cxquartz.service.quartz.TaskService;
import com.cx.cn.cxquartz.vo.TraffrecordData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
import java.util.List;
@Service
public class TrafficServiceImpl implements TrafficService {
public class TaskImpl implements TaskService {
@Autowired
TrafficMapper trafficMapper;
private TaskMapper taskMapper;
@Override
public List<TraffrecordData> list() {
return taskMapper.list();
}
@Override
public int insertTraffic(Traffic traffic) {
return trafficMapper.insertTraffic(traffic);
public int update(Integer id) {
return taskMapper.update(id);
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Service
public class TokenCacheService {
private static final Logger log = LoggerFactory.getLogger(TokenCacheService.class);
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Value("${countryside.eventwrite.token}")
private String qztoken;
@Value("${countryside.eventwrite.expiretoken}")
private String expiretoken;
@Value("${countryside.appid}")
private String appid;
@Value("${countryside.appsecret}")
private String appsecret;
@Value("${countryside.tokenurl}")
private String tokenurl;
public String keepAlive() {
try {
String tokencache = stringRedisTemplate.opsForValue().get(qztoken);
if (tokencache != null) {
//判断是否过期
String datetime=stringRedisTemplate.opsForValue().get(expiretoken);
if( null!=datetime){
//预留1分钟过期时间
Long expireminiseconds =Long.parseLong(datetime);
if(new Date().getTime()<expireminiseconds)
{
return tokencache;
}
}
return loginServer();
} else {
return loginServer();
}
} catch (Exception e) {
System.out.println(e.toString());
}
return null;
}
private String loginServer() {
HttpHeaders headers = getHttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
RestTemplate client = new RestTemplate();
ResponseEntity<String> response = client.getForEntity((tokenurl+"?appid="+appid+"&appsecret="+appsecret),String.class);
return getTokenData(response);
}
private HttpHeaders getHttpHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
return headers;
}
private String getTokenData(ResponseEntity<String> response){
try {
if (response != null && response.getBody() != null && response.getBody().contains("code")) {
String ret = response.getBody();
Map map= new ObjectMapper().readValue(ret,Map.class);
if ( null !=map && null!=map.get("obj") &&("0").equals(map.get("code"))) {
Map object= new ObjectMapper().readValue(map.get("obj").toString(),Map.class);
if(null!=object && null!=object.get("accessToken")) {
Long time=Long.parseLong(object.get("expire").toString())-new Date().getTime();
stringRedisTemplate.opsForValue().set(expiretoken,time.toString(),time,TimeUnit.MILLISECONDS);
stringRedisTemplate.opsForValue().set(qztoken, String.valueOf(object.get("accessToken")), time,TimeUnit.MILLISECONDS);
return String.valueOf(object.get("accessToken"));
}
} else {
log.error("getTokenData error :" + response.getBody());
}
} else {
log.error("getTokenData empty...");
}
}catch (Exception e){
System.out.println(e.toString());
log.error(e.getMessage());
}
return null;
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.dao.TraffAlarmRecordMapper;
import com.cx.cn.cxquartz.service.quartz.TraffAlarmRecordService;
import com.cx.cn.cxquartz.vo.TraffAlarmRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class TraffAlarmRecordImpl implements TraffAlarmRecordService {
@Autowired
private TraffAlarmRecordMapper traffAlarmRecordMapper;
public int inserTraffAlarmRecord(TraffAlarmRecord traffalarmrecord){
return traffAlarmRecordMapper.inserTraffAlarmRecord(traffalarmrecord);
}
public int selectmax(){
return traffAlarmRecordMapper.selectmax();
}
public int updateTraffAlarmRecordUrl(TraffAlarmRecord record){
return traffAlarmRecordMapper.updateTraffAlarmRecordUrl(record);
}
public int updateTraffAlarmRecordProcess(TraffAlarmRecord traffalarmrecord){
return traffAlarmRecordMapper.updateTraffAlarmRecordProcess(traffalarmrecord);
}
public List<TraffAlarmRecord> getTraffAlarmRecordByProgress(Map<String, Object> map){
return traffAlarmRecordMapper.getTraffAlarmRecordByProgress( map);
}
}
package com.cx.cn.cxquartz.service.quartz.impl;
import com.cx.cn.cxquartz.dao.TraffPictureMapper;
import com.cx.cn.cxquartz.service.quartz.TraffPictureService;
import com.cx.cn.cxquartz.vo.TraffpictureParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author wjj
* @since 2021-04-29
*/
@Service
public class TraffpictureServiceImpl implements TraffPictureService {
@Autowired
private TraffPictureMapper traffPictureMapper;
@Override
public int inserTraffpicture(TraffpictureParam traffpicture) {
return traffPictureMapper.inserTraffpicture(traffpicture);
}
@Override
public int updateTraffpicture(TraffpictureParam traffpicture) {
return traffPictureMapper.updateTraffpicture(traffpicture);
}
@Override
public String queryimgpath(TraffpictureParam traffpicture) {
return traffPictureMapper.queryimgpath(traffpicture);
}
@Override
public String queryimgdataByid(String id) {
return traffPictureMapper.queryimgdataByid(id);
}
}
package com.cx.cn.cxquartz.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class AdminInterceptor implements HandlerInterceptor {
/**
* 在请求处理之前进行调用(Controller方法调用之前)
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// System.out.println("执行了TestInterceptor的preHandle方法");
try {
//
// //统一拦截(查询当前session是否存在user)(这里user会在每次登陆成功后,写入session)
// String token = (String) request.getSession().getAttribute("token");
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = new HttpHeaders();
// headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// ResponseEntity<String> result = null;
// if (null == token) {
// //登录
//// String jsontoken= dologin(restTemplate,headers);
//// request.getSession().setAttribute("token",jsontoken);
// }
// else{//验证权限
// headers.add("access-token", request.getSession().getAttribute("token").toString());
// ResponseEntity<Map> response_result = restTemplate.exchange(
// "http://www.zjwwzf.cn/xzzfSpv/ext/auth/verify.do",
// HttpMethod.GET,
// new HttpEntity<String>(headers),
// Map.class,
// new HashMap<>());
// Map<Object,Object> bodyresult = response_result.getBody();
// if(null!=bodyresult.get("status") && !String.valueOf(bodyresult.get("status")).equals("0")){
// String jsontoken= dologin(restTemplate,headers);
// request.getSession().setAttribute("token",jsontoken);
// }
// }
} catch (Exception e) {
e.printStackTrace();
}
return true;//如果设置为false时,被请求时,拦截器执行到此处将不会继续操作
//如果设置为true时,请求将会继续执行后面的操作
}
/**
* 请求处理之后进行调用,但是在视图被渲染之前(Controller方法调用之后)
*/
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
// System.out.println("执行了TestInterceptor的postHandle方法");
}
/**
* 在整个请求结束之后被调用,也就是在DispatcherServlet 渲染了对应的视图之后执行(主要是用于进行资源清理工作)
*/
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
// System.out.println("执行了TestInterceptor的afterCompletion方法");
}
}
package com.cx.cn.cxquartz.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* 类描述:获取Spring代理类(上下文)
*/
@Component
public class ApplicationContextHolder implements ApplicationContextAware {
private static ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext applicationcontext)
throws BeansException {
ApplicationContextHolder.context = applicationcontext;
}
public static Object getBean(String beanName) {
return context.getBean(beanName);
}
}
package com.cx.cn.cxquartz.util;
import com.cx.cn.cxquartz.bean.PictureTime;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
public class CommonUtil {
/**
* 获取具体的异常信息
*
* @param ex
* @return
*/
public static String getExceptionDetail(Exception ex) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
ex.printStackTrace(pw);
return sw.toString();
} finally {
pw.close();
}
}
public static void removeFinishFiles( List<File> jsonFile, List<PictureTime> picturses)
{
if (picturses.size() > 0) {
//根据每个设备最新的时间进行过滤D:\imp\VideoPic\202009021049435991_0\20200906\112004.jpeg
String filetime = "";
for (int i = 0; i < jsonFile.size(); i++) {
String[] str = jsonFile.get(i).getAbsolutePath().split("\\\\");
for (PictureTime pic : picturses) {
filetime = str[str.length - 2] + str[str.length - 1].replace(".jpeg", "");
if (str[str.length - 3].equals(pic.getDeviceid())
&& pic.getLasttime().compareTo(filetime) != -1) {
jsonFile.remove(i--);
}
}
}
}
}
}
package com.cx.cn.cxquartz.util;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.Months;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.util.Date;
public class DateUtils {
private static final DateTimeFormatter YMD_HMS = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
private static final DateTimeFormatter YMDHMS = DateTimeFormat.forPattern("yyyyMMddHHmmss");
private static final DateTimeFormatter YMD = DateTimeFormat.forPattern("yyyyMMdd");
private static final DateTimeFormatter Y_M_D = DateTimeFormat.forPattern("yyyy-MM-dd");
private static final DateTimeFormatter YM= DateTimeFormat.forPattern("yyyyMM");
private static final DateTimeFormatter DD= DateTimeFormat.forPattern("dd");
public static String formatCurrDate(){
return formatCurrDateByType(YMD_HMS);
}
public static String formatCurrDateNoSign(){
return formatCurrDateByType(YMDHMS);
}
public static String formatCurrDateYMD(){
return formatCurrDateByType(Y_M_D);
}
public static String formatCurrDayNoSign(){
return formatCurrDateByType(YMD);
}
public static String formatCurrDayYM(){
return formatCurrDateByType(YM);
}
public static String formatCurrDayDD(){
return formatCurrDateByType(DD);
}
public static Date parseDate(String date){
return DateTime.parse(date,YMD_HMS).toDate();
}
public static Date parseDateNoSign(String date){
return DateTime.parse(date,YMDHMS).toDate();
}
public static String getYesterday(int day){
Date date= addDay(new Date(),day);
return new DateTime(date).toString(YMD_HMS);
}
public static String getlastMonth(int month){
Date date= addMonth(new Date(),month);
return new DateTime(date).toString(YMD_HMS);
}
public static String formatDate(Date date){
return new DateTime(date).toString(YMD_HMS);
}
public static String formatDateToNoSign(Date date){
return new DateTime(date).toString(YMDHMS);
}
public static String formatDateToNoSign(String date){
return DateTime.parse(date,YMD_HMS).toString(YMDHMS);
}
private static String formatCurrDateByType(DateTimeFormatter dateTimeFormatter){
return DateTime.now().toString(dateTimeFormatter);
}
public static Date addMinutes(Date date, int minutes) {
return new DateTime(date).plusMinutes(minutes).toDate();
}
public static Date addDay(Date date, int day) {
if(day == 0){
return date;
}
return new DateTime(date).plusDays(day).toDate();
}
public static Date addMonth(Date date, int month) {
if(month == 0){
return date;
}
return new DateTime(date).plusMonths(month).toDate();
}
public static int diffMonth(Date date1, Date date2) {
if (date1 == null || date2 == null) {
return 0;
}
DateTime dt1 = new DateTime(date1);
DateTime dt2 = new DateTime(date2);
return Months.monthsBetween(dt1, dt2).getMonths();
}
public static int diffDay(Date date1, Date date2) {
if (date1 == null || date2 == null) {
return 0;
}
DateTime dt1 = new DateTime(date1);
DateTime dt2 = new DateTime(date2);
return Days.daysBetween(dt1, dt2).getDays();
}
}
This diff is collapsed.
package com.cx.cn.cxquartz.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
public class FileUtil {
private static final Logger logger = LoggerFactory.getLogger(FileUtil.class);
public static File uploadToLocal(String path,ByteArrayOutputStream bout, String fileName) {
logger.info("file upload :{}",path+fileName);
DataOutputStream to=null;
try {
File tempFile = new File(path);
if (!tempFile.exists()) {
tempFile.mkdirs();
}
File file= new File(tempFile.getPath() + File.separator + fileName);
if (!file.exists()) {
file.createNewFile();
}
to=new DataOutputStream(new FileOutputStream(file));
bout.writeTo(to);
return file;
} catch (IOException e) {
logger.error(e.toString());
e.printStackTrace();
return null;
} catch (Exception e) {
logger.error(e.toString());
e.printStackTrace();
return null;
} finally {
try {
if(null!=bout)
bout.close();
if(null!=to){
to.close();
}
} catch (IOException e) {
logger.error(e.toString());
e.printStackTrace();
}
}
}
}
package com.cx.cn.cxquartz.util;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class LoginConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
//注册TestInterceptor拦截器
InterceptorRegistration registration = registry.addInterceptor(new AdminInterceptor());
registration.addPathPatterns("/**"); //所有路径都被拦截
registration.excludePathPatterns( //添加不拦截路径
"/**/*.html", //html静态资源
"/**/*.js", //js静态资源
"/**/*.css", //css静态资源
"/**/*.woff",
"/**/*.ttf"
);
}
}
This diff is collapsed.
This diff is collapsed.
package com.cx.cn.cxquartz.util;
/**
* 通用序列枚举类
* @author cp
*/
public enum RedisEnum {
/**
* 支队心跳
*/
DETACHMENT_HEART_BEATS("gs:traff:detachment:heartbeats"),
/**
* FTP List
*/
FTPLIST("gs:traff:global:cache:ftplist"),
/**
* ftp index
*/
FTPLIST_INDEX("gs:traff:global:cache:ftplistindex");
private String value;
RedisEnum(String value){
this.value =value;
}
public String getValue() {
return value;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment