Commit 439959c0 by 熊付

【事件处理管理平台】

1 parent 66bbb9fe
Showing 34 changed files with 3320 additions and 0 deletions
group 'com.viontech'
version '1.0-SNAPSHOT'
buildscript {
repositories {
jcenter()
}
repositories {
maven { url 'http://192.168.9.220:8081/nexus/content/groups/public/' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
}
}
/***
* 使用的插件
*/
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
/**
* 设置jdk的版本
*/
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked'
options.deprecation = true
}
repositories {
mavenCentral()
}
/***
* 依赖
*/
dependencies {
compile("org.springframework.boot:spring-boot-starter-parent:1.5.2.RELEASE"){
exclude module: 'hibernate-core'
exclude module: 'hibernate-entitymanager'
}
compile("org.springframework.boot:spring-boot-starter-web:1.5.2.RELEASE")
// hibernate 集成
compile('org.hibernate:hibernate-core:5.2.12.Final')
compile('org.hibernate:hibernate-entitymanager:5.2.12.Final')
compile('org.hibernate:hibernate-ehcache:5.2.12.Final')
compile("org.postgresql:postgresql:9.3-1102-jdbc41")
compile("org.springframework.boot:spring-boot-starter-data-jpa:1.5.2.RELEASE"){
exclude module: 'hibernate-core'
exclude module: 'hibernate-entitymanager'
}
compile("javax:javaee-api:7.0")
compile("org.springframework.boot:spring-boot-starter-websocket")
compile("org.springframework.boot:spring-boot-starter-jdbc:1.5.2.RELEASE")
compile("org.springframework.boot:spring-boot-starter-activemq")
compile("org.apache.activemq:activemq-pool")
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'org.springframework:spring-core'
compile 'org.springframework.boot:spring-boot-autoconfigure'
compile ('org.springframework.boot:spring-boot-starter-tomcat')
compile("org.springframework.kafka:spring-kafka:1.1.2.RELEASE")
compile group: 'com.alibaba', name: 'druid', version: '1.0.18'
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.47'
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.4'
compile("org.apache.commons:commons-lang3:3.5")
compile group: 'net.sf.json-lib', name: 'json-lib', version: '2.4',classifier:'jdk15'
}
package com.viontech;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication(scanBasePackages = {"com.viontech"})
public class HandleApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(HandleApplication.class, args);
}
}
package com.viontech.common;
import org.hibernate.dialect.PostgreSQL94Dialect;
import java.sql.Types;
/**
* Created by Administrator on 2019/3/26.
*/
public class JsonbPostgresDialect extends PostgreSQL94Dialect {
public JsonbPostgresDialect() {
this.registerColumnType(Types.JAVA_OBJECT,"jsonb");
}
}
package com.viontech.common;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.type.SerializationException;
import org.hibernate.usertype.UserType;
import org.postgresql.util.PGobject;
import org.springframework.util.ObjectUtils;
import java.io.IOException;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2019/4/3.
*/
public class VionTechJsonbType implements UserType {
private final ObjectMapper mapper = new ObjectMapper();
@Override
public Object deepCopy(Object originalValue) throws HibernateException {
if (originalValue != null) {
try {
if(originalValue instanceof List){
return originalValue;
}else{
return mapper.readValue(mapper.writeValueAsString(originalValue),
returnedClass());
}
} catch (IOException e) {
throw new HibernateException("Failed to deep copy object", e);
}
}
return null;
}
@Override
public Serializable disassemble(Object value) throws HibernateException {
Object copy = deepCopy(value);
if (copy instanceof Serializable) {
return (Serializable) copy;
}
throw new SerializationException(String.format("Cannot serialize '%s', %s is not Serializable.", value, value.getClass()), null);
}
@Override
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return deepCopy(cached);
}
@Override
public Object replace(Object original, Object target, Object owner) throws HibernateException {
return deepCopy(original);
}
@Override
public boolean isMutable() {
return true;
}
@Override
public int hashCode(Object x) throws HibernateException {
if (x == null) {
return 0;
}
return x.hashCode();
}
@Override
public Object nullSafeGet(ResultSet resultSet, String[] strings, SharedSessionContractImplementor sharedSessionContractImplementor, Object owner) throws HibernateException, SQLException {
PGobject o = (PGobject) resultSet.getObject(strings[0]);
if (o.getValue() != null) {
try {
return mapper.readValue(o.getValue(),Map.class);
}catch (IOException e){
e.printStackTrace();
}
}
return new HashMap<String, Object>();
}
@Override
public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index, SharedSessionContractImplementor sharedSessionContractImplementor) throws HibernateException, SQLException {
if (value == null) {
preparedStatement.setNull(index, Types.OTHER);
} else {
try{
preparedStatement.setObject(index, mapper.writeValueAsString(value), Types.OTHER);
}catch (IOException e){
e.printStackTrace();
}
}
}
@Override
public boolean equals(Object x, Object y) throws HibernateException {
return ObjectUtils.nullSafeEquals(x, y);
}
@Override
public Class<?> returnedClass() {
return Map.class;
}
@Override
public int[] sqlTypes() {
return new int[]{Types.JAVA_OBJECT};
}
}
package com.viontech.config;
import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/***
* 当使用springboot启动时打开即可 不然websocket不起作用 若是使用tomcat启动则必须关闭
*/
//@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
package com.viontech.consumer;
import com.viontech.service.adapter.behavior.IBehaviorService;
import com.viontech.util.JavaBean2Json;
import com.viontech.vo.EventDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
/****
* 综治事件数据消费
*/
@Component
public class BehaviorDataConsumer {
@Autowired
IBehaviorService iBehaviorService;
@JmsListener(destination = "behavior")
public void reciveDate(String msg){
iBehaviorService.recvBehaviorData(JavaBean2Json.Json2JavaBean(msg, EventDataVo.class));
}
}
package com.viontech.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by Administrator
*/
@RestController
@RequestMapping("/api/v1/integrated")
public class BaseController {
}
package com.viontech.controller.websocket;
import com.viontech.util.JavaBean2Json;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
/***
* 实时推送结果数据websocket
* @author Administrator
*
*/
@Component
@ServerEndpoint("/websocket/api/v1/handle/connects/{connection_unid}")
@Slf4j
public class WebsocketController {
public static Map<String, Session> clients = new ConcurrentHashMap<String, Session>();
/**
* 打开连接时触发
* @param connection_unid
* @param session
*/
@OnOpen
public void onOpen(@PathParam("connection_unid") String connection_unid, Session session){
log.info("Websocket Start Connecting:" + connection_unid);
clients.put(session.getId(), session);
}
/**
* 收到客户端消息时触发
* @param connection_unid
* @param message
* @return
*/
@OnMessage
public void onMessage(@PathParam("connection_unid") String connection_unid, String message, Session session) {
/*if(message.indexOf("keep_alive") != -1) {
session.getAsyncRemote().sendText(connection_unid);
//return onKeepAlive(connection_unid);
}else{
session.getAsyncRemote().sendText(message.replace("request", "response"));
}*/
if (session.isOpen() && StringUtils.isNotBlank(message)) {
session.getAsyncRemote().sendText(message.replace("request", "response"));
}
}
/**
* 异常时触发
* @param connection_unid
* @param throwable
*/
@OnError
public void onError(@PathParam("connection_unid") String connection_unid, Throwable throwable,Session session) {
log.info(throwable.getMessage(), throwable);
try {
Optional.ofNullable(clients.get(session.getId())).map(s -> {
try {
s.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
});
} finally {
removeSession(session.getId());
}
}
/**
* 关闭连接时触发
* @param connection_unid
*/
@OnClose
public void onClose(@PathParam("connection_unid") String connection_unid,Session session) {
log.info("Websocket Close Connection:" + connection_unid);
try {
Optional.ofNullable(clients.get(session.getId())).map(s -> {
try {
s.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
});
} finally {
removeSession(session.getId());
}
}
/**
* 将数据传回客户端
* 异步的方式
* @param message
*/
public static void broadcast(String message) {
Session se = null;
synchronized(clients) {
Optional.ofNullable(clients).map(cs ->{
cs.forEach((k,v)->{
if(v.isOpen()){
v.getAsyncRemote().sendText(message);
}
});
return null;
});
}
}
private String onKeepAlive(String connection_unid) {
Map activeMsg = new HashMap<>(6);
activeMsg.put("type", "response");
activeMsg.put("id", System.currentTimeMillis());
activeMsg.put("mts", System.currentTimeMillis());
activeMsg.put("command", String.format("get /wsapi/v1/%s/keep_alive", connection_unid));
activeMsg.put("code", "200");
activeMsg.put("emsg", "OK");
return JavaBean2Json.javaBean2Json(activeMsg);
}
private void removeSession(String sessionId) {
for (String key : clients.keySet()) {
if(sessionId.equals(key)) {
clients.remove(key);
}
}
}
}
package com.viontech.dao;
import com.viontech.vo.report.traffic.TrafficOverWeekReqVo;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator
*/
public interface ITrafficDao {
List<Map<String,Object>> statisticalTrafficByWeek(TrafficOverWeekReqVo tafficOverWeekReqVo);
List<Map<String,Object>> statisticalTrafficIllegalByWeek(TrafficOverWeekReqVo tafficOverWeekReqVo);
}
package com.viontech.dao.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
* Created by Administrator
*/
@Component
public class BaseDao {
@Autowired
public JdbcTemplate jdbcTemplate;
@PersistenceContext
public EntityManager entityManager;
}
/*
package com.viontech.dao.impl;
import com.viontech.dao.ITrafficDao;
import com.viontech.vo.report.traffic.TrafficOverWeekReqVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
*/
/**
* Created by Administrator
*//*
@Slf4j
@Component
public class TrafficDaoImpl extends BaseDao implements ITrafficDao {
@Override
public List<Map<String,Object>> statisticalTrafficByWeek(TrafficOverWeekReqVo tafficOverWeekReqVo) {
StringBuffer weeksql = new StringBuffer("SELECT event_type,tb_traffic_vehicle.body_type_code,EXTRACT(dow FROM event_dt::TIMESTAMP )||'' as week,COUNT(1) as total_num FROM tb_event_data ");
weeksql.append(" LEFT JOIN tb_traffic_vehicle ON tb_event_data.event_unid=tb_traffic_vehicle.event_unid");
weeksql.append(" where ( 1=1 AND event_cate='traffic' ");
if(StringUtils.isNotBlank(tafficOverWeekReqVo.getEvent_dt__gte()) ){
weeksql.append(" AND tb_event_data.event_dt >='"+tafficOverWeekReqVo.getEvent_dt__gte() +"' ");
}
if(StringUtils.isNotBlank(tafficOverWeekReqVo.getEvent_dt__lt()) ){
weeksql.append(" AND tb_event_data.event_dt <'"+tafficOverWeekReqVo.getEvent_dt__lt() +"' ");
}
weeksql.append(" ) ");
weeksql.append(" GROUP BY event_type,week,tb_traffic_vehicle.body_type_code ");
weeksql.append(" ORDER BY week,event_type ASC ");
//Query query = entityManager.createQuery(weeksql.toString());
//query.getResultList();
log.debug("statisticalTrafficByWeek sql:\n{}",weeksql.toString());
return jdbcTemplate.query(weeksql.toString(),(rs,row) -> getTrafficOverWeekResVo(rs));
}
*/
/****
* 违法事件week统计
* @param tafficOverWeekReqVo
* @return
*//*
@Override
public List<Map<String,Object>> statisticalTrafficIllegalByWeek(TrafficOverWeekReqVo tafficOverWeekReqVo) {
String weeksql = illeagSql(tafficOverWeekReqVo,tafficOverWeekReqVo.getIlleag());
log.debug("statisticalTrafficIllegalByWeek sql:\n{}",weeksql);
return jdbcTemplate.query(weeksql,(rs,row) -> {
return getTrafficOverWeekResVo(rs);
});
}
private String illeagSql(TrafficOverWeekReqVo tafficOverWeekReqVo, boolean isIllegal){
StringBuffer weeksql = new StringBuffer("SELECT EXTRACT(dow FROM event_dt::TIMESTAMP )||'' as week,COUNT(1) as total_num FROM tb_event_data ");
weeksql.append(" where ( 1=1 AND event_cate='traffic' ");
if(StringUtils.isNotBlank(tafficOverWeekReqVo.getEvent_dt__gte()) ){
weeksql.append(" AND tb_event_data.event_dt >='"+tafficOverWeekReqVo.getEvent_dt__gte() +"' ");
}
if(StringUtils.isNotBlank(tafficOverWeekReqVo.getEvent_dt__lt()) ){
weeksql.append(" AND tb_event_data.event_dt <'"+tafficOverWeekReqVo.getEvent_dt__lt() +"' ");
}
if(isIllegal){
weeksql.append(" AND tb_event_data.event_unid in(select tb_traffic_illegal.event_unid from tb_traffic_illegal) ");
}else {
weeksql.append(" AND tb_event_data.event_unid not in(select tb_traffic_illegal.event_unid from tb_traffic_illegal) ");
}
weeksql.append(" ) ");
//weeksql.append(" GROUP BY EXTRACT(dow FROM event_dt::TIMESTAMP )");
//weeksql.append(" ORDER BY EXTRACT(dow FROM event_dt::TIMESTAMP ) ASC ");
weeksql.append(" GROUP BY week");
weeksql.append(" ORDER BY week ASC ");
return weeksql.toString();
}
private Map<String,Object> getTrafficOverWeekResVo(ResultSet rs) throws SQLException {
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
Map<String,Object> result = new HashMap<String,Object>(columnCount);
for(int i = 1 ;i <= columnCount ; i++){
result.put(rsmd.getColumnLabel(i),rs.getObject(i));
}
return result;
}
}
*/
package com.viontech.entity;
/**
* Created by Administrator
* 安防事件
*/
//@Entity
//@Table(name = "tb_behavior")
public class BehaviorEntity extends EventDataEntity {
//@Id
//@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer event_unid;
public Integer getEvent_unid() {
return event_unid;
}
public void setEvent_unid(Integer event_unid) {
this.event_unid = event_unid;
}
}
package com.viontech.entity;
import com.alibaba.fastjson.annotation.JSONField;
import com.viontech.common.VionTechJsonbType;
import com.viontech.entity.archive.EventArchiveRelEntity;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator
*/
@Entity
@Table(name = "tb_event_data")
@Inheritance(strategy = InheritanceType.JOINED)
@TypeDef(name = "json", typeClass = VionTechJsonbType.class)
public class EventDataEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer event_unid;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@Column(name = "event_dt", nullable = true)
Date eventDt;
@Column(name = "task_type", nullable = true)
private String taskType;
@Column(name = "task_id", nullable = true)
private String taskId;
@Column(name = "event_type", nullable = true)
private String eventType;
@Column(name = "event_refid", nullable = true)
private String eventRefid;
@Column(name = "pics", nullable = true, columnDefinition = "jsonb")
@Type(type = "json")
private List pics;
@Column(name = "event_cate", nullable = true)
private String eventCate;
@Column(name = "video", nullable = true, columnDefinition = "jsonb")
@Type(type = "json")
private List video;
@Column(name = "subtask_id", nullable = true)
private String subtaskId;
@Column(name = "source_type", nullable = true)
private String sourceType;
@Column(name = "location_name", nullable = true)
private String locationName;
@Column(name = "location_code", nullable = true)
private String locationCode;
@Column(name = "original_json", nullable = true, columnDefinition = "jsonb")
@Type(type = "json")
private Object originalJson;
@OneToMany(cascade={CascadeType.ALL,CascadeType.REMOVE})
@JoinColumn(name="event_unid")
private List<EventArchiveRelEntity> eventArchiveRelEntitys;
@Column(name="is_archive")
private Boolean isArchive=false;
public Integer getEvent_unid() {
return event_unid;
}
public void setEvent_unid(Integer event_unid) {
this.event_unid = event_unid;
}
public Date getEventDt() {
return eventDt;
}
public void setEventDt(Date eventDt) {
this.eventDt = eventDt;
}
public String getTaskType() {
return taskType;
}
public void setTaskType(String taskType) {
this.taskType = taskType;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getEventType() {
return eventType;
}
public void setEventType(String eventType) {
this.eventType = eventType;
}
public String getEventRefid() {
return eventRefid;
}
public void setEventRefid(String eventRefid) {
this.eventRefid = eventRefid;
}
public String getEventCate() {
return eventCate;
}
public void setEventCate(String eventCate) {
this.eventCate = eventCate;
}
public String getSubtaskId() {
return subtaskId;
}
public void setSubtaskId(String subtaskId) {
this.subtaskId = subtaskId;
}
public String getSourceType() {
return sourceType;
}
public void setSourceType(String sourceType) {
this.sourceType = sourceType;
}
public String getLocationName() {
return locationName;
}
public void setLocationName(String locationName) {
this.locationName = locationName;
}
public String getLocationCode() {
return locationCode;
}
public void setLocationCode(String locationCode) {
this.locationCode = locationCode;
}
public Object getOriginalJson() {
return originalJson;
}
public void setOriginalJson(Object originalJson) {
this.originalJson = originalJson;
}
public List<EventArchiveRelEntity> getEventArchiveRelEntitys() {
return eventArchiveRelEntitys;
}
public void setEventArchiveRelEntitys(List<EventArchiveRelEntity> eventArchiveRelEntitys) {
this.eventArchiveRelEntitys = eventArchiveRelEntitys;
}
public List getPics() {
return pics;
}
public void setPics(List pics) {
this.pics = pics;
}
public List getVideo() {
return video;
}
public void setVideo(List video) {
this.video = video;
}
public Boolean getArchive() {
return isArchive;
}
public void setArchive(Boolean archive) {
isArchive = archive;
}
}
package com.viontech.entity.archive;
import com.alibaba.fastjson.annotation.JSONField;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
/***
* 事件归档
*/
@Entity
@Table(name = "tb_behavior_archive")
public class BehaviorArchiveEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer unid;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@Column(name = "start_dt", nullable = true)
Date startDt;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@Column(name = "end_dt", nullable = true)
Date endDt;
@Column(name = "event_type", nullable = false)
private String eventType;
@Column(name = "location_name", nullable = true)
private String locationName;
@Column(name = "location_code", nullable = true)
private String locationCode;
/***
* 责任
*/
@Column(name = "duty", nullable = true)
private Integer duty;
/****
* 审核状态值为:0待审核、1审核通过、2审核不通过、4事件结束、5定时关闭
*/
@Column(name = "audit_status", nullable = false)
private Integer auditStatus=0;
@Column(name = "audit_info", nullable = true)
private String auditInfo;
@OneToMany(cascade={CascadeType.ALL,CascadeType.REMOVE})
@JoinColumn(name="archive_unid")
private List<EventArchiveRelEntity> eventArchiveRelEntitys;
public Integer getUnid() {
return unid;
}
public void setUnid(Integer unid) {
this.unid = unid;
}
public Date getStartDt() {
return startDt;
}
public void setStartDt(Date startDt) {
this.startDt = startDt;
}
public Date getEndDt() {
return endDt;
}
public void setEndDt(Date endDt) {
this.endDt = endDt;
}
public String getEventType() {
return eventType;
}
public void setEventType(String eventType) {
this.eventType = eventType;
}
public String getLocationName() {
return locationName;
}
public void setLocationName(String locationName) {
this.locationName = locationName;
}
public String getLocationCode() {
return locationCode;
}
public void setLocationCode(String locationCode) {
this.locationCode = locationCode;
}
public Integer getDuty() {
return duty;
}
public void setDuty(Integer duty) {
this.duty = duty;
}
public Integer getAuditStatus() {
return auditStatus;
}
public void setAuditStatus(Integer auditStatus) {
this.auditStatus = auditStatus;
}
public String getAuditInfo() {
return auditInfo;
}
public void setAuditInfo(String auditInfo) {
this.auditInfo = auditInfo;
}
public List<EventArchiveRelEntity> getEventArchiveRelEntitys() {
return eventArchiveRelEntitys;
}
public void setEventArchiveRelEntitys(List<EventArchiveRelEntity> eventArchiveRelEntitys) {
this.eventArchiveRelEntitys = eventArchiveRelEntitys;
}
}
package com.viontech.entity.archive;
import com.viontech.entity.EventDataEntity;
import javax.persistence.*;
import java.util.List;
/****
* 事件与归档中间表
*/
@Entity
@Table(name = "tb_event_archive_rel")
public class EventArchiveRelEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer unid;
@Column(name = "event_unid")
private Integer eventUnid;
@Column(name = "archive_unid")
private Integer archiveUnid;
}
package com.viontech.enums;
/***
* 综治类型枚举
*/
public enum BehaviorTypeEnum {
BEHAVIOR_daoluposun("道路破损"),
BEHAVIOR_5("奔跑"),
BEHAVIOR_baitan("摆摊"),
BEHAVIOR_lajiduiji("垃圾堆积"),
BEHAVIOR_wuliaoduiji("物料堆积"),
BEHAVIOR_zixingcheluanfang("自行车乱放"),
BEHAVIOR_huangtuluolu("黄土裸露"),
BEHAVIOR_4("打架"),
BEHAVIOR_0("单向越界"),
BEHAVIOR_11("蒙面"),
BEHAVIOR_32("人群聚集"),
BEHAVIOR_2("进入区域"),
BEHAVIOR_14("区域徘徊"),
BEHAVIOR_13("异常声音"),
BEHAVIOR_1("双向越界"),
BEHAVIOR_19("摩的"),
BEHAVIOR_20("违章摆摊"),
BEHAVIOR_3("离开区域"),
BEHAVIOR_33("安全帽"),
BEHAVIOR_22("区域人数密度超过阈值"),
BEHAVIOR_21("区域排队长度超过阈值"),
BEHAVIOR_yongdu("拥堵"),
BEHAVIOR_24("遗撒"),
BEHAVIOR_shigu("事故"),
BEHAVIOR_pedestrian("行人违法事件"),
BEHAVIOR_34("物品遗留"),
BEHAVIOR_35("物品丢失"),
BEHAVIOR_36("跨域闸机"),
BEHAVIOR_shigongzhandao("施工占道"),
BEHAVIOR_jishui("积水"),
BEHAVIOR_duiji("堆积"),
BEHAVIOR_lajiyichu("垃圾溢出"),
BEHAVIOR_jinggaidiushi("井盖丢失"),
BEHAVIOR_jinggaiposun("井盖破损"),
BEHAVIOR_daobantingche("道板停车");
private String name;
BehaviorTypeEnum(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.viontech.enums;
/**
* Created by Administrator
* 事件大类型枚举
*/
public enum EventCateEnum {
TRAFFIC("traffic"){
@Override
public String apply(){
return getType();
}
},BEHAVIOR("behavior"){
@Override
public String apply(){
return getType();
}
},FACE("face"){
@Override
public String apply(){
return getType();
}
},FLOW("flow"){
@Override
public String apply(){
return getType();
}
};
private String type;
EventCateEnum(String type) {
this.type = type;
}
public abstract String apply();
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package com.viontech.enums;
public enum IllegalTypeEnum {
ILLEGAL_36("未系安全带"),
ILLEGAL_38("使用手持电话"),
ILLEGAL_44("国际2014右转闯红灯"),
ILLEGAL_42("国际2014直行闯红灯"),
ILLEGAL_23("大货车禁行"),
ILLEGAL_41("畅通"),
ILLEGAL_76("渣土车冒尖"),
ILLEGAL_75("车载货物超长超宽"),
ILLEGAL_74("夜间行车不开灯"),
ILLEGAL_73("夜间开车放下遮阳板"),
ILLEGAL_72("危险品运输车无押运员"),
ILLEGAL_37("黄标车禁行"),
ILLEGAL_71("非机动车占用机动车道"),
ILLEGAL_07("违章掉头"),
ILLEGAL_47("超速50%-70%"),
ILLEGAL_33("区间超速"),
ILLEGAL_51("区间测速超速50%-70%"),
ILLEGAL_57("不按规定使用远光灯"),
ILLEGAL_32("外地车限行"),
ILLEGAL_27("禁止左转"),
ILLEGAL_09("左转闯红灯"),
ILLEGAL_24("限时单行"),
ILLEGAL_30("绿灯滞留"),
ILLEGAL_21("车辆超速"),
ILLEGAL_02("小车走公交车道"),
ILLEGAL_62("渣土车"),
ILLEGAL_63("渣土车未盖苫盖"),
ILLEGAL_22("占用应急车道"),
ILLEGAL_65("拥堵时滞留人行横道"),
ILLEGAL_70("号牌污损"),
ILLEGAL_10("右转闯红灯"),
ILLEGAL_45("超速10%-20%"),
ILLEGAL_56("不按规定未依次交替驶入"),
ILLEGAL_29("路口滞留"),
ILLEGAL_52("区间测速超速70%以上"),
ILLEGAL_43("国际2014左转闯红灯"),
ILLEGAL_25("压白线"),
ILLEGAL_08("直行闯红灯"),
ILLEGAL_16("遗撒"),
ILLEGAL_53("黑名单车辆"),
ILLEGAL_05("压实线或者黄线"),
ILLEGAL_12("机动车占用非机动车道"),
ILLEGAL_46("超速20%-50%"),
ILLEGAL_69("前排抱小孩"),
ILLEGAL_68("压倒流带"),
ILLEGAL_67("机动车违反禁令指示"),
ILLEGAL_66("旧领馆车牌"),
ILLEGAL_20("不礼让行人"),
ILLEGAL_58("行人闯红灯"),
ILLEGAL_55("左转机动车未让直行车辆先行"),
ILLEGAL_40("缓行"),
ILLEGAL_59("危险品车辆"),
ILLEGAL_01("流量拥堵时间报警"),
ILLEGAL_17("交通事故"),
ILLEGAL_60("右转未让非机动车"),
ILLEGAL_14("非法左转"),
ILLEGAL_48("超速70%以上"),
ILLEGAL_19("超低速"),
ILLEGAL_49("区间测速超速10%-20%"),
ILLEGAL_64("抛洒物"),
ILLEGAL_15("行人"),
ILLEGAL_61("非机动车逆行"),
ILLEGAL_06("逆行"),
ILLEGAL_03("异常停车"),
ILLEGAL_18("超高速"),
ILLEGAL_28("禁止右转"),
ILLEGAL_11("疑似直行闯红灯"),
ILLEGAL_13("非法右转"),
ILLEGAL_50("区间测速超速20%-50%"),
ILLEGAL_00("正常"),
ILLEGAL_26("跨线变道"),
ILLEGAL_04("非法停车"),
ILLEGAL_54("大弯小转"),
ILLEGAL_31("限号");
private String name;
private String type_code;
IllegalTypeEnum(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.viontech.enums;
/***
* 车辆类型枚举
*/
public enum VehicleTypeEnum {
K13("大型卧铺客车"),
B32("轻型厢式半挂车"), B18("重型仓栅式半挂车"),H45("微型自卸货车"),H12("重型厢式货车"),Z51("重型专项作业车"),
B19("重型旅居半挂车"),
H11("重型普通货车"),
H29("中型仓栅式货车"),
K22("中型双层客车"),
H52("厢式低速货车"),
H47("微型仓栅式货车"),
D12("有轨电车"),
M21("普通二轮摩托车"),B33("轻型罐式半挂车"),
K21("中型普通客车"),
J12("轮式挖掘机械"),
K41("微型普通客车"),
G10("重型全挂车"),
Q10("重型牵引车"),
H38("轻型特殊结构货车"),
B36("轻型仓栅式半挂车"),
Z21("中型专项作业车"),
D11("无轨电车"),
H31("轻型普通货车"),
Q20("中型牵引车"),
B39("轻型低平板半挂车"),
G37("轻型旅居全挂车"),
B37("轻型旅居半挂车"),
B25("中型集装箱半挂车"),
G27("中型仓栅式全挂车"),
K23("中型卧铺客车"),
B29("中型旅居半挂车"),
Z41("微型专项作业车"),
B23("中型罐式半挂车"),
G36("轻型仓栅式全挂车"),
H50("低速货车"),
X99("其他"),
Q21("中型半挂牵引车"),
G33("轻型罐式全挂车"),
H24("中型罐式货车"),
K42("微型越野客车"),
B22("中型厢式半挂车"),
H55("仓栅式低速货车"),
G16("重型自卸全挂车"),
G22("中型厢式全挂车"),
H54("自卸低速货车"),
H40("微型货车"),
K31("小型普通客车"),
H44("微型罐式货车"),
K24("中型铰接客车"),
B2A("中型专项作业半挂车"),
K20("中型客车"),
H34("轻型罐式货车"),
N11("三轮汽车"),
H25("中型平板货车"),
T23("手扶变形运输机"),
G32("轻型厢式全挂车"),
G19("重型专项作业全挂车"),
H51("普通低速货车"),
K43("微型轿车"),
K33("小型轿车"),
H35("轻型平板货车"),
B1B("重型低平板半挂车"),
G25("中型集装箱全挂车"),
H33("轻型封闭货车"),
G29("中型专项作业全挂车"),
H19("重型仓栅式货车"),
K17("大型专用客车"),
M14("正三轮载货摩托车"),
H18("重型特殊结构货车"),
B20("中型半挂车"),
H53("罐式低速货车"),
B13("重型罐式半挂车"),
K15("大型越野客车"),
B35("轻型自卸半挂车"),
G30("轻型全挂车"),
G38("轻型专项作业全挂车"),
K25("中型越野客车"),
B26("中型自卸半挂车"),
H23("中型封闭货车"),
Q11("重型半挂牵引车"),
B14("重型平板半挂车"),
G12("重型厢式全挂车"),
K14("大型铰接客车"),
Q12("重型全挂牵引车"),
Q31("轻型半挂牵引车"),
H43("微型封闭货车"),
G31("轻型普通全挂车"),
B21("中型普通半挂车"),
M10("三轮摩托车"),
G28("中型旅居全挂车"),
M12("轻便正三轮摩托车"),
H28("中型特殊结构货车"),
B31("轻型普通半挂车"),
G34("轻型平板全挂车"),
J13("轮式平地机械"),
G26("中型自卸全挂车"),
H26("中型集装厢车"),
G21("中型普通全挂车"),
H41("微型普通货车"),
G15("重型集装箱全挂车"),
B24("中型平板半挂车"),
T11("大型轮式拖拉机"),
G17("重型仓栅式全挂车"),
B16("重型自卸半挂车"),
G18("重型旅居全挂车"),
H17("重型自卸货车"),
K16("大型轿车"),
H46("微型特殊结构货车"),
B10("重型半挂车"),
M20("二轮摩托车"),
K34("小型专用客车"),
M13("正三轮载客摩托车"),
B28("中型仓栅式半挂车"),
H27("中型自卸货车"),
M15("侧三轮摩托车"),
H14("重型罐式货车"),
G11("重型普通全挂车"),
B1A("重型专项作业半挂车"),
H13("重型封闭货车"),
T20("小型拖拉机"),
H42("微型厢式货车"),
H39("轻型仓栅式货车"),
Z11("大型专项作业车"),
J11("轮式装载机械"),
H10("重型货车"),
K11("大型普通客车"),
H15("重型平板货车"),
M11("普通正三轮摩托车"),
H16("重型集装厢车"),
Z71("轻型专项作业车"),
Q30("轻型牵引车"),
G23("中型罐式全挂车"),
B27("中型特殊结构半挂车"),
M22("轻便二轮摩托车"),
B30("轻型半挂车"),
T21("小型轮式拖拉机"),
K10("大型客车"),
H20("中型货车"),
Q22("中型全挂牵引车"),
H37("轻型自卸货车"),
K40("微型客车"),
B38("轻型专项作业半挂车"),
G14("重型平板全挂车"),
B2B("中型低平板半挂车"),
T22("手扶拖拉机"),
K32("小型越野客车"),
Q32("轻型全挂牵引车"),
H22("中型厢式货车"),
B17("重型特殊结构半挂车"),
H32("轻型厢式货车"),
H30("轻型货车"),
G35("轻型自卸全挂车"),
B12("重型厢式半挂车"),
B11("重型普通半挂车"),
B15("重型集装箱半挂车"),
G13("重型罐式全挂车"),
G20("中型全挂车"),
K12("大型双层客车"),
H21("中型普通货车"),
B34("轻型平板半挂车"),
Z31("小型专项作业车"),
K27("中型专用客车"),
K30("面包车"),
G24("中型平板全挂车");
private String name;
VehicleTypeEnum(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.viontech.enums;
/**
* Created by Administrator
*/
public enum WeekEnum {
MONDAY("monday"),TUESDAY("tuesday"),WEDNESDAY("wednesday"),THURSDAY("thursday"),FRIDAY("friday"),SATURDAY("saturday"),SUNDAY("sunday"),
WEEK_1("monday"),WEEK_2("tuesday"),WEEK_3("wednesday"),WEEK_4("thursday"),WEEK_5("friday"),WEEK_6("saturday"),WEEK_7("sunday"),WEEK_0("sunday");
private String week;
WeekEnum(String week){
this.week = week;
}
public String getWeek() {
return week;
}
public void setWeek(String week) {
this.week = week;
}
}
package com.viontech.repository;
import com.viontech.entity.archive.BehaviorArchiveEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface EventArchiveRepository extends JpaRepository<BehaviorArchiveEntity, Integer>,
JpaSpecificationExecutor<BehaviorArchiveEntity> {
}
package com.viontech.repository;
import com.viontech.entity.EventDataEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* Created by Administrator
*/
public interface EventDataRepository extends JpaRepository<EventDataEntity, Integer>,
JpaSpecificationExecutor<EventDataEntity> {
}
package com.viontech.service.adapter;
/**
* Created by Administrator
*/
public interface IEventDataService {
}
package com.viontech.service.adapter.behavior;
import com.viontech.service.adapter.IEventDataService;
import com.viontech.vo.BehaviorArchiveVo;
public interface IBehaviorArchiveService extends IEventDataService {
Object archive(BehaviorArchiveVo behaviorArchiveVo);
}
package com.viontech.service.adapter.behavior;
import com.viontech.vo.EventDataVo;
/**
* Created by Administrator
*/
public interface IBehaviorService {
Object recvBehaviorData(EventDataVo eventDataVo);
}
package com.viontech.service.impl;
/**
* Created by Administrator on 2019/5/9.
*/
public class EventDataServiceImpl {
}
package com.viontech.service.impl.behavior;
import com.viontech.service.adapter.behavior.IBehaviorArchiveService;
import com.viontech.vo.BehaviorArchiveVo;
import org.springframework.stereotype.Service;
@Service
public class BehaviorArchiveServiceImpl implements IBehaviorArchiveService {
/***
* 新增归档信息
* @param behaviorArchiveVo
* @return
*/
@Override
public Object archive(BehaviorArchiveVo behaviorArchiveVo) {
return null;
}
}
package com.viontech.service.impl.behavior;
import com.viontech.entity.EventDataEntity;
import com.viontech.repository.EventDataRepository;
import com.viontech.service.adapter.behavior.IBehaviorService;
import com.viontech.util.DateUtil;
import com.viontech.util.JavaBean2Json;
import com.viontech.vo.EventDataVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* Created by Administrator
* 事件类型
*/
@Slf4j
@Service
@SuppressWarnings("unchecked")
public class BehaviorServiceImpl implements IBehaviorService {
@Autowired
EventDataRepository eventDataRepository;
@Override
public Object recvBehaviorData(EventDataVo eventDataVo) {
try {
Map event_data = eventDataVo.getEvent_data();
EventDataEntity eventDataEntity = new EventDataEntity();
// 位置
if (event_data.containsKey("location")) {
Map location = (Map) event_data.get("location");
String code = (String) location.get("code");
String name = (String) location.get("name");
eventDataEntity.setLocationCode(code);
eventDataEntity.setLocationName(name);
}
eventDataEntity.setEventCate(eventDataVo.getEvent_cate());
eventDataEntity.setEventDt(DateUtil.FORMAT_YYYY_MM_DD_HH_MM_SS_SSS.parse(eventDataVo.getEvent_dt()));
eventDataEntity.setEventRefid(eventDataVo.getEvent_refid());
eventDataEntity.setEventType(eventDataVo.getEvent_type());
eventDataEntity.setSourceType(eventDataVo.getSource_type());
eventDataEntity.setSubtaskId(eventDataVo.getSubtask_id());
eventDataEntity.setTaskId(eventDataVo.getTask_id());
eventDataEntity.setTaskType(eventDataVo.getTask_type());
eventDataEntity.setPics(eventDataVo.getPics());
eventDataEntity.setVideo(eventDataVo.getVideo());
eventDataEntity.setOriginalJson(JavaBean2Json.Json2JavaBean(JavaBean2Json.javaBean2Json(eventDataVo),Map.class));
eventDataRepository.save(eventDataEntity);
} catch (Exception e) {
log.error("新增behavior事件异常:"+e.getLocalizedMessage(),e);
}
return null;
}
}
package com.viontech.util;
import org.apache.commons.lang3.StringUtils;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@SuppressWarnings({"unchecked","deprecation"})
public class DateUtil {
private static DateFormatSymbols dateformatSymbols = new DateFormatSymbols(Locale.getDefault());
static {
dateformatSymbols.setShortWeekdays(new String[]{"", "周日", "周一", "周二", "周三", "周四", "周五", "周六"});
}
/**
* 英文简写(默认)如:2010
*/
public static SimpleDateFormat FORMAT_YYYY = new SimpleDateFormat("yyyy");
/**
* 英文简写(默认)如:2010
*/
public static SimpleDateFormat FORMAT_YYYY_CN = new SimpleDateFormat("yyyy年");
/**
* 英文简写(默认)如:2010-12
*/
public static SimpleDateFormat FORMAT_YYYY_MM = new SimpleDateFormat("yyyy-MM");
/**
* 英文简写(默认)如:2010-12
*/
public static SimpleDateFormat FORMAT_YYYY_MM_CN = new SimpleDateFormat("yyyy年MM月");
/**
* 英文简写(默认)如:2010-12-01
*/
public static SimpleDateFormat FORMAT_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");
/**
* 中文简写 如:2010年12月01日
*/
public static SimpleDateFormat FORMAT_YYYY_MM_DD_CN = new SimpleDateFormat("yyyy年MM月dd日");
/**
* 中文简写 如:2010年12月01日(周日)
*/
public static SimpleDateFormat FORMAT_SHORT_CN_WEEK = new SimpleDateFormat("yyyy年MM月dd日(E)", dateformatSymbols);
/**
* 英文简写 如:2010-12-01(sunday)
*/
public static SimpleDateFormat FORMAT_SHORT_WEEK = new SimpleDateFormat("yyyy-MM-dd(E)", dateformatSymbols);
/**
* 英文简写(默认)如:2010-12-31 24
*/
public static SimpleDateFormat FORMAT_YYYY_MM_DD_HH = new SimpleDateFormat("yyyy-MM-dd HH");
/**
* 英文全称 如:2010-12-01 23:15
*/
public static SimpleDateFormat FORMAT_YYYY_MM_DD_HH_MM = new SimpleDateFormat("yyyy-MM-dd HH:mm");
/**
* 英文全称 如:2010-12-01 23:15:06
*/
public static SimpleDateFormat FORMAT_YYYY_MM_DD_HH_MM_SS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 中文全称 如:2010年12月01日 23时15分06秒
*/
public static SimpleDateFormat FORMAT_YYYY_MM_DD_HH_MM_SS_CN = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
/**
* 精确到毫秒的完整时间 如:2010-12-01 23:15:06.999
*/
public static SimpleDateFormat FORMAT_YYYY_MM_DD_HH_MM_SS_S = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
/**
* 精确到毫秒的完整中文时间 如:2010年12月01日 23时15分06秒999毫秒
*/
public static SimpleDateFormat FORMAT_YYYY_MM_DD_HH_MM_SS_S_CN = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒SSS毫秒");
/**
* 精确到毫秒的完整UTC时间 如:2017-07-04T15:50:18.223
*/
public static SimpleDateFormat FORMAT_YYYY_MM_DD_HH_MM_SS_S_UTC = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
/**
* 精确到毫秒的完整UTC时间 如:2017-07-04T15:50:18.223
*/
public static SimpleDateFormat FORMAT_YYYY_MM_DD_HH_MM_SS_SSS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
/**
* 英文简写(默认)如:12-31
*/
public static SimpleDateFormat FORMAT_MM_DD = new SimpleDateFormat("MM-dd");
/**
* 英文简写带星期(默认)如:12-31(周三)
*/
public static SimpleDateFormat FORMAT_MM_DD_E = new SimpleDateFormat("MM-dd(E)", dateformatSymbols);
/**
* 英文简写(默认)如:12-31 24
*/
public static SimpleDateFormat FORMAT_MM_DD_HH = new SimpleDateFormat("MM-dd HH");
/**
* 英文简写(默认)如:31
*/
public static SimpleDateFormat FORMAT_DD = new SimpleDateFormat("dd");
/**
* 英文简写(默认)如:31 24
*/
public static SimpleDateFormat FORMAT_DD_HH = new SimpleDateFormat("dd HH");
/**
* 英文简写(默认)如:24
*/
public static SimpleDateFormat FORMAT_HH = new SimpleDateFormat("HH");
public static SimpleDateFormat FORMAT_HHMMSSS = new SimpleDateFormat("HH:mm:ss.S");
public static SimpleDateFormat FORMAT_HHMMSS = new SimpleDateFormat("HH:mm:ss");
public static SimpleDateFormat FORMAT_HHMM = new SimpleDateFormat("HH:mm");
/**
* 星期的简写 周一 周二 周三 周四等
*/
public static SimpleDateFormat FORMAT_DAY_OF_WEEK_SORT = new SimpleDateFormat("E", dateformatSymbols);
public static final int FIRST_DAY_OF_WEEK = Calendar.MONDAY; // 中国周一是一周的第一天
/**
* 获取上周同期
*
* @param date
* @return 上周同天
*/
public static Date getLastWeek(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.WEEK_OF_MONTH, -1);
return calendar.getTime();
}
/**
* 获取上月同期
*
* @param date 当日
* @return
*/
public static Date getLastMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, -1);
return calendar.getTime();
}
/**
* 获取下月同期
*
* @param date 当日
* @return
*/
public static Date getNextMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, 1);
return calendar.getTime();
}
/**
* 获取去年同期
*
* @param date 当日
* @return
*/
public static Date getLastYear(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.YEAR, -1);
return calendar.getTime();
}
/**
* 获取昨日日期
*
* @param date 当日
* @return
*/
public static Date getYesterday(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_YEAR, -1);
return calendar.getTime();
}
/**
* 获取明天日期
*
* @param date 当日
* @return
*/
public static Date getTorromow(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_YEAR, 1);
return calendar.getTime();
}
/**
* 获取下一小时
*
* @param date 日期
* @return
*/
public static Date getNextHour(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, 8);
return calendar.getTime();
}
/**
* 获取前一小时
*
* @param date 日期
* @return
*/
public static Date getPreviousHour(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -1);
return calendar.getTime();
}
/**
* 获取下10分钟--数字可以任意取值
* @param date 日期
* @return
*/
public static Date getNextMinute(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MINUTE, 10);
return calendar.getTime();
}
public static Date getNextMin(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MINUTE, -30);
return calendar.getTime();
}
/**
* 判断 yesterDay 是否是 today 的昨天
*
* @param today 今天日期
* @param yesterDay 昨天日期
* @return
*/
public static boolean isYesterday(Date today, Date yesterDay) {
return isSameDay(getYesterday(today), yesterDay);
}
/**
* 判断 lastWeekDay 是否是 today 的上周同期
*
* @param today 今天日期
* @param lastWeekDay 上周同期日期
* @return
*/
public static boolean isLastWeekDay(Date today, Date lastWeekDay) {
return isSameDay(getLastWeek(today), lastWeekDay);
}
/**
* 判断 lastMonthDay 是否是 today 的上月同期
*
* @param today 今天日期
* @param lastMonthDay 上月同期
* @return
*/
public static boolean isLastMonthDay(Date today, Date lastMonthDay) {
return isSameDay(getLastMonth(today), lastMonthDay);
}
/**
* 判断 lastYearDay 是否是 today 的去年同期
*
* @param today 今天日期
* @param lastYearDay 去年同期日期
* @return
*/
public static boolean isLastYearDay(Date today, Date lastYearDay) {
return isSameDay(getLastYear(today), lastYearDay);
}
/**
* 判断两个日期是否是同一天
*
* @param date1 日期1
* @param date2 日期2
* @return
*/
public static boolean isSameHour(Date date1, Date date2) {
if (!isSameDay(date1, date2)) {
return false;
}
if (date1.getHours() != date2.getHours()) {
return false;
}
return true;
}
/**
* 判断两个日期是否是同一天
*
* @param date1 日期1
* @param date2 日期2
* @return
*/
public static boolean isSameDay(Date date1, Date date2) {
if (!isSameMonth(date1, date2)) {
return false;
}
if (date1.getDate() != date2.getDate()) {
return false;
}
return true;
}
/**
* 判断两个日期是否是同一周
*
* @param week 日期1
* @param otherWeek 日期2
* @return
*/
public static boolean isSameWeek(Date week, Date otherWeek) {
return isSameDay(getMondayOfWeek(week), getMondayOfWeek(otherWeek));
}
/**
* 判断两个日期是否是同一月
*
* @param date1 日期1
* @param date2 日期2
* @return
*/
public static boolean isSameMonth(Date date1, Date date2) {
if (date1.getYear() != date2.getYear()) {
return false;
}
if (date1.getMonth() != date2.getMonth()) {
return false;
}
return true;
}
/***
* 判断日期2是否是日期1的上周
* @param date1
* @param date2
* @return
*/
public static boolean isLastWeek(Date date1, Date date2) {
return isSameWeek(getLastWeek(date1), date2);
}
/***
/***
* 判断日期2是否是日期1的上月
* @param date1
* @param date2
* @return
*/
public static boolean isLastMonth(Date date1, Date date2) {
return isSameMonth(getLastMonth(date1), date2);
}
/***
* 判断日期2是否是日期1的去年同月
* @param date1
* @param date2
* @return
*/
public static boolean isLastYearMonth(Date date1, Date date2) {
return isSameMonth(getLastYear(date1), date2);
}
/**
* 判断两个日期是否是同一季度
*
* @param date1 日期1
* @param date2 日期2
* @return
*/
public static boolean isSameSeason(Date date1, Date date2) {
return getSeason(date1) == getSeason(date2);
}
/**
* 判断 日期2 是否是 日期1的 上一季度
*
* @param date1 日期1
* @param date2 日期2
* @return
*/
public static boolean isLastSeason(Date date1, Date date2) {
return getSeason(date1) == getSeason(date2) + 1;
}
/**
* 判断两个日期是否是同一年
*
* @param date1 日期1
* @param date2 日期2
* @return
*/
public static boolean isSameYear(Date date1, Date date2) {
if (date1.getYear() != date2.getYear()) {
return false;
}
return true;
}
/**
* 将HH:mm解析成整点对象
*
* @param HMStr
* @param before true 往前取整 false 往后取整
* @return
* @throws ParseException 解析异常
*/
public static Date parseHMDate2NowTime(String HMStr, boolean before) throws ParseException {
Calendar calendar = Calendar.getInstance();
Date HMTime = FORMAT_HHMM.parse(HMStr);
calendar.setTime(HMTime);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
int milliSecond = calendar.get(Calendar.MILLISECOND);
if (before) {
hour = hour;
minute = 0;
second = 0;
milliSecond = 0;
} else {
hour = hour;
minute = 59;
second = 59;
milliSecond = 999;
}
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, second);
calendar.set(Calendar.MILLISECOND, milliSecond);
return calendar.getTime();
}
/**
* 将日期设置为整点
*
* @param date 需要设置的日期
* @param HMTime 小时分钟信息
* @param- before true 是指向前取整 false 向后取整 小时会+1
* @return
*/
public static Date setDayHMS(Date date, Date HMTime) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, HMTime.getHours());
calendar.set(Calendar.MINUTE, HMTime.getMinutes());
calendar.set(Calendar.SECOND, HMTime.getSeconds());
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/**
* 将日期设置为对应的时分信息
*
* @param date 需要设置的日期
* @param HMTimeStr 小时分钟信息
* @return
* @throws ParseException
*/
public static Date setDayHM(Date date, String HMTimeStr) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);//HH:mm:ss.S
Date HMTime = null;
try {
HMTime = FORMAT_HHMM.parse(HMTimeStr);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar hmCalendar = Calendar.getInstance();
hmCalendar.setTime(HMTime);//HH:mm:ss.S
calendar.set(Calendar.HOUR_OF_DAY, hmCalendar.get(Calendar.HOUR_OF_DAY));
calendar.set(Calendar.MINUTE, hmCalendar.get(Calendar.MINUTE));
calendar.set(Calendar.SECOND, 0);
return calendar.getTime();
}
/**
* 将日期设置为对应的时分秒
*
* @param date 需要设置的日期
* @param HMSTimeStr 小时分钟秒信息
* @return
* @throws ParseException
*/
public static Date setDayHMS(Date date, String HMSTimeStr) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);//HH:mm:ss.S
Date HMSTime = null;
try {
HMSTime = FORMAT_HHMMSS.parse(HMSTimeStr);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar hmsCalendar = Calendar.getInstance();
hmsCalendar.setTime(HMSTime);//HH:mm:ss.S
calendar.set(Calendar.HOUR_OF_DAY, hmsCalendar.get(Calendar.HOUR_OF_DAY));
calendar.set(Calendar.MINUTE, hmsCalendar.get(Calendar.MINUTE));
calendar.set(Calendar.SECOND, hmsCalendar.get(Calendar.SECOND));
return calendar.getTime();
}
/**
* 将日期设置为对应的时分秒
*
* @param date 需要设置的日期
* @param HTimeStr 小时分钟秒信息
* @return
* @throws ParseException
*/
public static Date setDayH(Date date, String HTimeStr) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);//HH:mm:ss.S
Date HTime = null;
try {
HTime = FORMAT_HH.parse(HTimeStr);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar hCalendar = Calendar.getInstance();
hCalendar.setTime(HTime);//HH:mm:ss.S
calendar.set(Calendar.HOUR_OF_DAY, hCalendar.get(Calendar.HOUR_OF_DAY));
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
return calendar.getTime();
}
/**
* 获取时间戳
* 如:2017-06-02 17:42:20.350
*/
public static String getTimeString() {
Calendar calendar = Calendar.getInstance();
return FORMAT_YYYY_MM_DD_HH_MM_SS_S.format(calendar.getTime());
}
/**
* 获取时间戳
* 如:2017-06-02T17:42:20.350
*/
public static String getTstring() {
Calendar calendar = Calendar.getInstance();
return FORMAT_YYYY_MM_DD_HH_MM_SS_S_UTC.format(calendar.getTime());
}
/**
* 获取时间戳13位
* 如:1496396907810
*/
public static Long getTimestamp() {
Calendar calendar = Calendar.getInstance();
return calendar.getTime().getTime();
}
/**
* 获取服务器UTC时间
* @return
*/
public static Calendar getCurrentUTC() {
Calendar cal = Calendar.getInstance(Locale.CHINA);
int zoneOffset = cal.get(Calendar.ZONE_OFFSET);
int dstOffset = cal.get(Calendar.DST_OFFSET);
cal.add(Calendar.MILLISECOND, -(zoneOffset + dstOffset));
return cal;
}
/**
* UTC转本地时间
* @return
*/
public static String UTC2LocalTime(Date date) {
try {
Calendar cal = Calendar.getInstance(Locale.CHINA);
cal.setTime(date);
int zoneOffset = cal.get(Calendar.ZONE_OFFSET);
int dstOffset = cal.get(Calendar.DST_OFFSET);
cal.add(Calendar.MILLISECOND, zoneOffset + dstOffset);
return FORMAT_YYYY_MM_DD_HH_MM_SS_CN.format(cal.getTime());
} catch (Exception e) {
System.out.println("字符串格式不正确yyyy-MM-dd HH:mm:ss.S");
}
return "error";
}
/**
* 获取日期年份
*
* @param date 日期
* @return
*/
public static int getYear(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.YEAR);
}
/**
* 功能描述:返回月
*
* @param date Date 日期
* @return 返回月份
*/
public static int getMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.MONTH) + 1;
}
/**
* 功能描述:返回日
*
* @param date Date 日期
* @return 返回日份
*/
public static int getDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.DAY_OF_MONTH);
}
/**
* 功能描述:返回小时
*
* @param date 日期
* @return 返回小时
*/
public static int getHour(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.HOUR_OF_DAY);
}
/**
* 功能描述:返回分
*
* @param date 日期
* @return 返回分钟
*/
public static int getMinute(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.MINUTE);
}
/**
* 功能描述:返回分
*
* @param date 日期
* @return 返回分钟
*/
public static int getMinuteOfDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE);
}
/**
* 返回秒钟
*
* @param date Date 日期
* @return 返回秒钟
*/
public static int getSecond(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.SECOND);
}
/**
* 功能描述:返回毫秒
*
* @param date 日期
* @return 返回毫
*/
public static int getMillis(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(calendar.MILLISECOND);
}
/**
* 取得当天日期是周几
*
* @param date
* @return
*/
public static int getDayOfWeek(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
c.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
int day_of_week = c.get(Calendar.DAY_OF_WEEK);
day_of_week -= 1;
if (day_of_week == 0) {
day_of_week = 7;
}
return day_of_week;
}
/**
* 获取一个月 周一 到 周日 的个数 用count存储
*
* @param date
* @return 下标0 代表周一的天数 下表1代表周二的天数 依次类推
*/
public static int[] getCountDayOfWeekInMonth(Date date) {
int[] count = new int[7];
Date firstDate = getFirstDateOfMonth(date);
int dayOfWeek = getDayOfWeek(firstDate);
int dayOfMonth = getPassDayOfMonth(date);
for (int i = 0; i < dayOfMonth; i++) {
count[dayOfWeek - 1]++;
dayOfWeek++;
if (dayOfWeek > 7) {
dayOfWeek = 1;
}
}
return count;
}
/**
* 取得一月的第几周
*
* @param date
* @return
*/
public static int getWeekOfMonth(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
int week_of_year = c.get(Calendar.WEEK_OF_MONTH);
return week_of_year;
}
/**
* 取得一年的第几周
*
* @param date
* @return
*/
public static int getWeekOfYear(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
int week_of_year = c.get(Calendar.WEEK_OF_YEAR);
return week_of_year;
}
/**
* 根据日期取得对应周周一日期
*
* @param date
* @return
*/
public static Date getMondayOfWeek(Date date) {
Calendar monday = Calendar.getInstance();
monday.setTime(date);
monday.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
monday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
return monday.getTime();
}
/**
* 根据日期取得对应周周日日期
*
* @param date
* @return
*/
public static Date getSundayOfWeek(Date date) {
Calendar sunday = Calendar.getInstance();
sunday.setTime(date);
sunday.setFirstDayOfWeek(FIRST_DAY_OF_WEEK);
sunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
return sunday.getTime();
}
/**
* 根据日期取得对应月的第一个相同周几
*
* @param date
* @return
*/
public static Date getFirsSametWeekOfMonth(Date date) {
Calendar c = Calendar.getInstance();
date = setDayMinTime(date);
c.setTime(date);
int weekIndex = c.get(Calendar.DAY_OF_WEEK);
c.set(Calendar.DAY_OF_MONTH, 1);
while (true) {
if (weekIndex == c.get(Calendar.DAY_OF_WEEK))
break;
c.add(Calendar.DAY_OF_MONTH, 1);
}
return c.getTime();
}
/**
* 取得月的剩余天数
*
* @param date
* @return
*/
public static int getRemainDayOfMonth(Date date) {
int dayOfMonth = getDayOfMonth(date);
int day = getPassDayOfMonth(date);
return dayOfMonth - day;
}
/**
* 取得月已经过的天数
*
* @param date
* @return
*/
public static int getPassDayOfMonth(Date date) {
Date monthStart = setDayMinTime(getFirstDateOfMonth(new Date()));
if (monthStart.after(date))
return getDayOfMonth(date);
Date monthEnd = setDayMaxTime(getLastDateOfMonth(new Date()));
if (monthEnd.before(date))
return 0;
Calendar c = Calendar.getInstance();
c.setTime(new Date());
return c.get(Calendar.DAY_OF_MONTH);
}
/**
* 取得月天数
*
* @param date
* @return
*/
public static int getDayOfMonth(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
return c.getActualMaximum(Calendar.DAY_OF_MONTH);
}
/**
* 取得月第一天
*
* @param date
* @return
*/
public static Date getFirstDateOfMonth(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
return c.getTime();
}
/**
* 取得月最后一天
*
* @param date
* @return
*/
public static Date getLastDateOfMonth(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
return c.getTime();
}
/**
* 取得季度第一天
*
* @param date
* @return
*/
public static Date getFirstDateOfSeason(Date date) {
return getFirstDateOfMonth(getSeasonDate(date)[0]);
}
/**
* 取得季度最后一天
*
* @param date
* @return
*/
public static Date getLastDateOfSeason(Date date) {
return getLastDateOfMonth(getSeasonDate(date)[2]);
}
/**
* 取得季度天数
*
* @param date
* @return
*/
public static int getDayOfSeason(Date date) {
int day = 0;
Date[] seasonDates = getSeasonDate(date);
for (Date date2 : seasonDates) {
day += getDayOfMonth(date2);
}
return day;
}
/**
* 取得季度剩余天数
*
* @param date
* @return
*/
public static int getRemainDayOfSeason(Date date) {
return getDayOfSeason(date) - getPassDayOfSeason(date);
}
/**
* 取得季度已过天数
*
* @param date
* @return
*/
public static int getPassDayOfSeason(Date date) {
int day = 0;
Date[] seasonDates = getSeasonDate(date);
Calendar c = Calendar.getInstance();
c.setTime(date);
int month = c.get(Calendar.MONTH);
if (month == Calendar.JANUARY || month == Calendar.APRIL
|| month == Calendar.JULY || month == Calendar.OCTOBER) {// 季度第一个月
day = getPassDayOfMonth(seasonDates[0]);
} else if (month == Calendar.FEBRUARY || month == Calendar.MAY
|| month == Calendar.AUGUST || month == Calendar.NOVEMBER) {// 季度第二个月
day = getDayOfMonth(seasonDates[0])
+ getPassDayOfMonth(seasonDates[1]);
} else if (month == Calendar.MARCH || month == Calendar.JUNE
|| month == Calendar.SEPTEMBER || month == Calendar.DECEMBER) {// 季度第三个月
day = getDayOfMonth(seasonDates[0]) + getDayOfMonth(seasonDates[1])
+ getPassDayOfMonth(seasonDates[2]);
}
return day;
}
/**
* 取得季度月
*
* @param date
* @return
*/
public static Date[] getSeasonDate(Date date) {
Date[] season = new Date[3];
Calendar c = Calendar.getInstance();
c.setTime(date);
int nSeason = getSeason(date);
if (nSeason == 1) {// 第一季度
c.set(Calendar.MONTH, Calendar.JANUARY);
season[0] = c.getTime();
c.set(Calendar.MONTH, Calendar.FEBRUARY);
season[1] = c.getTime();
c.set(Calendar.MONTH, Calendar.MARCH);
season[2] = c.getTime();
} else if (nSeason == 2) {// 第二季度
c.set(Calendar.MONTH, Calendar.APRIL);
season[0] = c.getTime();
c.set(Calendar.MONTH, Calendar.MAY);
season[1] = c.getTime();
c.set(Calendar.MONTH, Calendar.JUNE);
season[2] = c.getTime();
} else if (nSeason == 3) {// 第三季度
c.set(Calendar.MONTH, Calendar.JULY);
season[0] = c.getTime();
c.set(Calendar.MONTH, Calendar.AUGUST);
season[1] = c.getTime();
c.set(Calendar.MONTH, Calendar.SEPTEMBER);
season[2] = c.getTime();
} else if (nSeason == 4) {// 第四季度
c.set(Calendar.MONTH, Calendar.OCTOBER);
season[0] = c.getTime();
c.set(Calendar.MONTH, Calendar.NOVEMBER);
season[1] = c.getTime();
c.set(Calendar.MONTH, Calendar.DECEMBER);
season[2] = c.getTime();
}
return season;
}
/**
* 1 第一季度 2 第二季度 3 第三季度 4 第四季度
*
* @param date
* @return
*/
public static int getSeason(Date date) {
int season = 0;
Calendar c = Calendar.getInstance();
c.setTime(date);
int month = c.get(Calendar.MONTH);
switch (month) {
case Calendar.JANUARY:
case Calendar.FEBRUARY:
case Calendar.MARCH:
season = 1;
break;
case Calendar.APRIL:
case Calendar.MAY:
case Calendar.JUNE:
season = 2;
break;
case Calendar.JULY:
case Calendar.AUGUST:
case Calendar.SEPTEMBER:
season = 3;
break;
case Calendar.OCTOBER:
case Calendar.NOVEMBER:
case Calendar.DECEMBER:
season = 4;
break;
default:
break;
}
return season;
}
/**
* 取得年第一天
*
* @param date
* @return
*/
public static Date getFirstDateOfYear(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.DAY_OF_YEAR, c.getActualMinimum(Calendar.DAY_OF_YEAR));
return setDayMinTime(c.getTime());
}
/**
* 取得年最后一天
*
* @param date
* @return
*/
public static Date getLastDateOfYear(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.DAY_OF_YEAR, c.getActualMaximum(Calendar.DAY_OF_YEAR));
return setDayMaxTime(c.getTime());
}
/**
* String转Date
* 支持:2010-12-01 23:15:06.999
* 2010-12-01 23:15:06
* 2010-12-01 23:15
* 2010-12-01
*
* @param dateStr
* @return
* @throws ParseException
*/
public static Date dateFormat(String dateStr) throws ParseException {
if (dateStr.length() == 23||dateStr.length() ==22){
if(dateStr.contains("T")){
return DateUtil.FORMAT_YYYY_MM_DD_HH_MM_SS_S_UTC.parse(dateStr);
}
return DateUtil.FORMAT_YYYY_MM_DD_HH_MM_SS_S.parse(dateStr);
}
if (dateStr.length() == 19)
return DateUtil.FORMAT_YYYY_MM_DD_HH_MM_SS.parse(dateStr);
else if (dateStr.length() == 16)
return DateUtil.FORMAT_YYYY_MM_DD_HH_MM.parse(dateStr);
else if (dateStr.length() == 10)
return DateUtil.FORMAT_YYYY_MM_DD.parse(dateStr);
else
return null;
}
/**
* @Title: longToString
* @Description:把13位的毫秒值转化为String类型格式化的时间格式
*/
public static String longToString(long time) {
Date date = new Date(time);
String newDate = FORMAT_YYYY_MM_DD_HH_MM_SS_S_UTC.format(date);
return newDate;
}
/**
* 设置一天的最大值
*
* @param date
* @return
*/
public static Date setDayMaxTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.HOUR_OF_DAY, c.getActualMaximum(Calendar.HOUR_OF_DAY));
c.set(Calendar.MINUTE, c.getActualMaximum(Calendar.MINUTE));
c.set(Calendar.SECOND, c.getActualMaximum(Calendar.SECOND));
c.set(Calendar.MILLISECOND, c.getActualMaximum(Calendar.MILLISECOND));
return c.getTime();
}
/**
* 设置一天的最小值
*
* @param date
* @return
*/
public static Date setDayMinTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.HOUR_OF_DAY, c.getActualMinimum(Calendar.HOUR_OF_DAY));
c.set(Calendar.MINUTE, c.getActualMinimum(Calendar.MINUTE));
c.set(Calendar.SECOND, c.getActualMinimum(Calendar.SECOND));
c.set(Calendar.MILLISECOND, c.getActualMinimum(Calendar.MILLISECOND));
return c.getTime();
}
/**
* 当前日期加n毫秒
*
* @param date
* @param num
* @return
*/
public static Date dateAddMillisecond(Date date, int num) {
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.MILLISECOND, num);
return c.getTime();
}
/**
* 获取两个时间点之间的天
*
* @param startDate 开始时间
* @param endDate 结束时间
* @return
*/
public static List<Date> getDaysBetweenStartDateAndEndDate(Date startDate, Date endDate) {
List<Date> dates = new ArrayList<>();
Calendar c = Calendar.getInstance();
c.setTime(startDate);
while (c.getTime().before(endDate)) {
dates.add(c.getTime());
c.add(Calendar.DAY_OF_MONTH, 1);
}
dates.add(endDate);
return dates;
}
/**
* 将字符串解析成时间,如果无法解析返回null
*
* @param sdf
* @param dateStr
* @return
*/
public static Date parseDate(SimpleDateFormat sdf, String dateStr) {
try {
return sdf.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public static Date maxDate(Date date1, Date date2) {
if (date1.before(date2)) {
return date2;
} else {
return date1;
}
}
public static Date minDate(Date date1, Date date2) {
if (date1.before(date2)) {
return date1;
} else {
return date2;
}
}
/**
* 获取月的所有天数,不返回未到达的日期
*
* @param date
* @return
*/
public static List<Date> getMonthDyas(Date date) {
Date monthStart = getFirstDateOfMonth(date);
Date monthEnd = getLastDateOfMonth(date);
Date currentDate = new Date();
monthEnd = monthEnd.before(currentDate) ? monthEnd : currentDate;
List<Date> dates = getDaysBetweenStartDateAndEndDate(monthStart, monthEnd);
return dates;
}
public static long getDistanceSecond(Date date1, Date date2) {
return (date1.getTime() - date2.getTime()) / 1000;
}
public static long getDistanceMillisecond(Date date1, Date date2) {
return (date1.getTime() - date2.getTime());
}
/**
* 日期转星期
*
* @param datetime
* @return
*/
public static String dateToWeek(String datetime) {
SimpleDateFormat f = null;
if (datetime.contains("T")) {
f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
}else{
f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
}
String[] weekDays = { "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" };
Calendar cal = Calendar.getInstance(); // 获得一个日历
Date datet = null;
try {
datet = f.parse(datetime);
cal.setTime(datet);
} catch (ParseException e) {
try {
datet = f.parse("yyyy-MM-dd'T'HH:mm:ss.SSS");
cal.setTime(datet);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
if (w < 0)
w = 0;
return weekDays[w];
}
/**
* 时区转换
* @param time 时间字符串
* @param pattern 格式 "yyyy-MM-dd HH:mm"
* @param nowTimeZone eg:+8,0,+9,-1 等等
* @param targetTimeZone 同nowTimeZone
* @return
*/
public static String timeZoneTransfer(String time, String pattern, String nowTimeZone, String targetTimeZone) {
if(StringUtils.isBlank(time)){
return "";
}
SimpleDateFormat simpleDateFormat = null;
if (time.contains("T")) {
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
}else{
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
}
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT" + nowTimeZone));
Date date=null;
try {
date = simpleDateFormat.parse(time);
} catch (ParseException e) {
return "";
}
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT" + targetTimeZone));
return simpleDateFormat.format(date);
}
public static int[] gethourminutesecond(String pattern,String baseTime){
try {
int[] times = new int[3];
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
calendar.setTime(sdf.parse(baseTime));
int hour = calendar.get(Calendar.HOUR_OF_DAY);
times[0]=hour;
int minute = calendar.get(Calendar.MINUTE);
times[1]=minute;
int second = calendar.get(Calendar.SECOND);
times[2]=second;
return times;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) throws ParseException {
/*Date date1 = new Date();
Date date2 = DateUtils.addSeconds(date1, 10);
System.out.println(Math.abs(getDistanceMillisecond(date2,date1)));*/
// SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
// Date date = format.parse("20170427105959");
// System.out.println(FORMAT_YYYY_MM_DD_HH_MM_SS.format(date));
// Date time = getLastWeek(new Date());
// String format = FORMAT_YYYY_MM_DD_HH_MM_SS_S_UTC.format(time);
// System.out.println(format);
/*String dd ="2017-03-21 12:11:56.123";
Date date = dateFormat("2018-01-29");
System.out.println(FORMAT_YYYY_MM_DD_HH_MM_SS_S_UTC.format(date));
System.out.println(FORMAT_YYYY_MM_DD_HH_MM_SS_SSS.format(date));
System.out.println(date.getTime());
long a=1490069516*1000l;
String s = longToString(a);
System.out.println(s);*/
/*String date_dt = "2018-10-07 16:01:00.000";
System.out.println(DateUtil.dateToWeek(date_dt));
System.out.println(date_dt.split(" ")[1]);
date_dt = timeZoneTransfer(date_dt,"yyyy-MM-dd HH:mm:ss.SSS", "0", "+8");
System.out.println(date_dt);
Calendar calendar = Calendar.getInstance();
Date HMTime = FORMAT_YYYY_MM_DD_HH_MM_SS_SSS.parse(date_dt);
calendar.setTime(HMTime);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
int milliSecond = calendar.get(Calendar.MILLISECOND);
System.out.println(hour);
System.out.println(minute);
System.out.println(second);
System.out.println(milliSecond);
Date time = FORMAT_HHMMSS.parse("08:00:00");
HMTime = FORMAT_YYYY_MM_DD_HH_MM_SS_SSS.parse(date_dt);
calendar.setTime(time);
hour = calendar.get(Calendar.HOUR_OF_DAY);
minute = calendar.get(Calendar.MINUTE);
second = calendar.get(Calendar.SECOND);
System.out.println("=========");
System.out.println(hour);
System.out.println(minute);
System.out.println(second);
System.out.println(milliSecond);
Date d = new Date();
System.out.println(FORMAT_YYYY_MM_DD_HH_MM_SS_SSS.format(d));
Date nowdate = setDayHMS(d,"16:01:00");
System.out.println(FORMAT_YYYY_MM_DD_HH_MM_SS_SSS.format(nowdate));*/
System.out.println(gethourminutesecond("yyyy-MM-dd HH:mm:ss.SSS",timeZoneTransfer("2018-10-07 16:01:00.000","yyyy-MM-dd HH:mm:ss.SSS", "0", "+8")));
System.out.println(gethourminutesecond("HH:mm:ss","08:00:00"));
}
}
package com.viontech.util;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.PropertyFilter;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.*;
@SuppressWarnings({"unchecked","deprecation"})
public class JavaBean2Json {
public static String javaBean2Json(Object obj) {
return JSONObject.fromObject(obj,getJsonConfig()).toString();
}
public static <T> T Json2JavaBean(String json,Class<T> clas) {
try {
ObjectMapper om = new ObjectMapper();
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return om.readValue(json, clas);
} catch (Exception e) {
JSONObject jsb = new JSONObject();
return (T) jsb.toBean(JSONObject.fromObject(json), clas, getJsonConfig());
}
}
/**
* json转List
* @param json
* @param clazz
* @param <T>
* @return
*/
public static <T> List<T> json2List(String json,Class<T> clazz) {
if(json.startsWith("[")){//json.indexOf("[")==0
JSONArray array = JSONArray.fromObject(json);
List<T> list = JSONArray.toList(array, clazz);
return list;
}
return null;
}
/**
* json转Array
* @param json
* @param clazz
* @param <T>
* @return
*/
public static <T> T[] json2Array(String json,Class<T> clazz) {
if(json.indexOf("[")==0){
JSONArray array = JSONArray.fromObject(json);
T[] ray = (T[]) JSONArray.toArray(array, clazz);
return ray;
}
return null;
}
private static JsonConfig getJsonConfig(){
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
public boolean apply(Object source/* 属性的拥有者 */, String name /* 属性名字 */,Object value/* 属性值 */) {
if(value instanceof List){
List<Object> list = (List<Object>) value;
if (list == null || list.size()==0) {
return true;
}
}else if(value instanceof Map){
Map map = (Map) value;
if (map == null || map.size() == 0) {
return true;
}
}
return null == value || "".equals(value);
}
});
return jsonConfig;
}
public static void jsonToMap(String json, Map map) {
JSONObject jsonObject = JSONObject.fromObject(json);
populate(jsonObject, map);
}
private static void populate(JSONObject jsonObject, Map map) {
for (Iterator iterator = jsonObject.entrySet().iterator(); iterator
.hasNext();) {
String entryStr = String.valueOf(iterator.next());
String key = entryStr.substring(0, entryStr.indexOf("="));
String value = entryStr.substring(entryStr.indexOf("=") + 1,entryStr.length());
if (jsonObject.get(key).getClass().equals(JSONObject.class)) {
HashMap _map = new HashMap();
map.put(key, _map);
populate(jsonObject.getJSONObject(key), ((Map) (_map)));
} else if (jsonObject.get(key).getClass().equals(JSONArray.class)) {
ArrayList list = new ArrayList();
map.put(key, list);
populateArray(jsonObject.getJSONArray(key), list);
} else {
map.put(key, jsonObject.get(key));
}
}
}
private static void populateArray(JSONArray jsonArray, List list) {
for (int i = 0; i < jsonArray.size(); i++)
if (jsonArray.get(i).getClass().equals(JSONArray.class)) {
ArrayList _list = new ArrayList();
list.add(_list);
populateArray(jsonArray.getJSONArray(i), _list);
} else if (jsonArray.get(i).getClass().equals(JSONObject.class)) {
HashMap _map = new HashMap();
list.add(_map);
populate(jsonArray.getJSONObject(i), _map);
} else {
list.add(jsonArray.get(i));
}
}
/***
* 判断发过来的信息是否是json格式
*
* @param json
* @return
*/
public static boolean isJson(String json) {
try {
JSONObject.fromObject(json);
return true;
} catch (Exception e) {
return false;
}
}
public static Object mulMapVal(Object object,String keys) {
if (object != null) {
String[] key = keys.split(",");
for (int i=0;i<key.length;i++) {
if (object instanceof Map) {
Map dbobj = (Map) object;
object = dbobj.get(key[i]);
}
}
return object;
}
return null;
}
public static Map<String, Object> transBean2Map(Object obj) {
if(obj == null){
return null;
}
Map<String, Object> map = new HashMap<String, Object>();
try {
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor property : propertyDescriptors) {
String key = property.getName();
// 过滤class属性
if (!key.equals("class")) {
// 得到property对应的getter方法
Method getter = property.getReadMethod();
Object value = getter.invoke(obj);
map.put(key, value);
}
}
} catch (Exception e) {
System.out.println("transBean2Map Error " + e);
}
return map;
}
public static void main(String[] args) {
Map<String, Object> map = new HashMap<>();
String json="{\"id\":\"32\", \"vehicle\" : {\n" +
" \"global_feature\" : {\n" +
" \"AlignParameters\" : null, \n" +
" \"FeatureVector\" : null\n" +
" }, \n" +
" \"image\" : \"全景1\", \n" +
" \"local_feature\" : {\n" +
" \"FeatureVector\" : null, \n" +
" \"nFeatureCount\" : 1097913940\n" +
" }, \n" +
" \"plate\" : {\n" +
" \"char_count\" : 7, \n" +
" \"color_code\" : \"2\", \n" +
" \"color_name\" : \"蓝色\", \n" +
" \"head_text\" : \"京\", \n" +
" \"image\" : \"全景1\", \n" +
" \"other_text\" : \"RS5T48\", \n" +
" \"rect\" : {\n" +
" \"bottom\" : 0.8336397, \n" +
" \"left\" : 0.7838542, \n" +
" \"right\" : 0.83177084, \n" +
" \"top\" : 0.8134191\n" +
" }, \n" +
" \"score\" : 0, \n" +
" \"text\" : \"京RS5T48\", \n" +
" \"type_code\" : \"02\"\n" +
" }, \n" +
" \"rect\" : {\n" +
" \"bottom\" : 0.89966905, \n" +
" \"left\" : 0.66406256, \n" +
" \"right\" : 0.95156246, \n" +
" \"top\" : 0.61216915\n" +
" }\n" +
" }\n" +
"\t\t}\n";
JavaBean2Json.jsonToMap(json,map);
System.out.println("map = " + map);
String plate_text =(String) JavaBean2Json.mulMapVal(map, "vehicle,plate,text");
System.out.println("plate_text = " + plate_text);
}
}
package com.viontech.vo;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
@Data
public class BehaviorArchiveVo {
Integer unid;
String startDt;
String endDt;
private String eventType;
private String locationName;
private String locationCode;
/***
* 责任
*/
private Integer duty;
/****
* 审核状态值为:0待审核、1审核通过、2审核不通过、4事件结束、5定时关闭
*/
private Integer auditStatus=0;
private String auditInfo;
}
package com.viontech.vo;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2019/5/7.
* 事件统一接收Vo实体
*/
public class EventDataVo {
private String task_type;
private String task_id;
private String event_type;
private String event_refid;
private String event_dt;
private String dev_unid;
private Map aux_dev_info;
private Map event_data;
private List pics;
private String event_cate;
private String vdev_unid;
private String vchan_duid;
private String vchan_refid;
private List video;
private String test_pic_file;
private String test_frame_no;
private String subtask_id;
private String source_type;
public String getTask_type() {
return task_type;
}
public void setTask_type(String task_type) {
this.task_type = task_type;
}
public String getTask_id() {
return task_id;
}
public void setTask_id(String task_id) {
this.task_id = task_id;
}
public String getEvent_type() {
return event_type;
}
public void setEvent_type(String event_type) {
this.event_type = event_type;
}
public String getEvent_refid() {
return event_refid;
}
public void setEvent_refid(String event_refid) {
this.event_refid = event_refid;
}
public String getEvent_dt() {
return event_dt;
}
public void setEvent_dt(String event_dt) {
this.event_dt = event_dt;
}
public String getDev_unid() {
return dev_unid;
}
public void setDev_unid(String dev_unid) {
this.dev_unid = dev_unid;
}
public Map getAux_dev_info() {
return aux_dev_info;
}
public void setAux_dev_info(Map aux_dev_info) {
this.aux_dev_info = aux_dev_info;
}
public Map getEvent_data() {
return event_data;
}
public void setEvent_data(Map event_data) {
this.event_data = event_data;
}
public List getPics() {
return pics;
}
public void setPics(List pics) {
this.pics = pics;
}
public String getEvent_cate() {
return event_cate;
}
public void setEvent_cate(String event_cate) {
this.event_cate = event_cate;
}
public String getVdev_unid() {
return vdev_unid;
}
public void setVdev_unid(String vdev_unid) {
this.vdev_unid = vdev_unid;
}
public String getVchan_duid() {
return vchan_duid;
}
public void setVchan_duid(String vchan_duid) {
this.vchan_duid = vchan_duid;
}
public String getVchan_refid() {
return vchan_refid;
}
public void setVchan_refid(String vchan_refid) {
this.vchan_refid = vchan_refid;
}
public List getVideo() {
return video;
}
public void setVideo(List video) {
this.video = video;
}
public String getTest_pic_file() {
return test_pic_file;
}
public void setTest_pic_file(String test_pic_file) {
this.test_pic_file = test_pic_file;
}
public String getTest_frame_no() {
return test_frame_no;
}
public void setTest_frame_no(String test_frame_no) {
this.test_frame_no = test_frame_no;
}
public String getSubtask_id() {
return subtask_id;
}
public void setSubtask_id(String subtask_id) {
this.subtask_id = subtask_id;
}
public String getSource_type() {
return source_type;
}
public void setSource_type(String source_type) {
this.source_type = source_type;
}
}
package com.viontech.vo;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2019/3/26.
*/
@Data
public class VehicleVo {
private String task_type;
private String task_id;
private String event_type;
private String event_refid;
private String event_dt;
private String dev_unid;
private Map aux_dev_info;
private Map event_data;
private List pics;
private String event_cate;
private String vdev_unid;
private String vchan_duid;
private String vchan_refid;
private List video;
private String test_pic_file;
private String test_frame_no;
private String subtask_id;
private String source_type;
}
server:
port: 8086
spring:
datasource:
url: jdbc:postgresql://192.168.9.133:5432/event_data_handle
username: postgres
password: authpass
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: org.postgresql.Driver
# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
initialSize: 5
minIdle: 5
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
jpa:
show-sql: true
database: postgresql
hibernate:
ddl-auto: update
#database-platform: org.hibernate.dialect.PostgreSQL9Dialect
database-platform: com.viontech.common.JsonbPostgresDialect
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQL9Dialect
hbm2ddl:
auto: update
temp:
use_jdbc_metadata_defaults: false
format_sql: true
activemq:
user: admin
password: admin
broker-url: tcp://192.168.9.133:61616
jms:
pub-sub-domain: true
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!