Commit 92e3a415 by 熊付

【归档审核】

1 parent 439959c0
Showing 25 changed files with 566 additions and 173 deletions
group 'com.viontech'
version '1.0-SNAPSHOT'
buildscript {
repositories {
/*repositories {
jcenter()
}
}*/
repositories {
maven { url 'http://192.168.9.220:8081/nexus/content/groups/public/' }
}
......@@ -48,12 +48,13 @@ dependencies {
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('com.fasterxml.jackson.datatype:jackson-datatype-hibernate5:2.9.4')
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("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")
......@@ -61,7 +62,7 @@ dependencies {
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')
compileOnly ('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'
......
package com.viontech;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication(scanBasePackages = {"com.viontech"})
public class HandleApplication extends SpringBootServletInitializer {
@SpringBootApplication(scanBasePackages = {"com.viontech.*"})
@Configuration
@EnableScheduling
public class HandleApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(HandleApplication.class, args);
}
/*@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = jsonConverter.getObjectMapper();
objectMapper.registerModule(new Hibernate5Module());
return jsonConverter;
}*/
}
package com.viontech.common;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
......@@ -24,6 +27,10 @@ import java.util.Map;
public class VionTechJsonbType implements UserType {
private final ObjectMapper mapper = new ObjectMapper();
{
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
}
@Override
public Object deepCopy(Object originalValue) throws HibernateException {
if (originalValue != null) {
......@@ -79,12 +86,20 @@ public class VionTechJsonbType implements UserType {
@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) {
if (o != null && o.getValue() != null) {
try {
if(o.getValue().startsWith("[")){
return mapper.readValue(o.getValue(),List.class);
}
return mapper.readValue(o.getValue(),Map.class);
}catch (IOException e){
e.printStackTrace();
/*try {
return mapper.readValue(o.getValue(),List.class);
}catch (IOException ee){
ee.printStackTrace();
}*/
}
}
......
......@@ -7,6 +7,6 @@ import org.springframework.web.bind.annotation.RestController;
* Created by Administrator
*/
@RestController
@RequestMapping("/api/v1/integrated")
@RequestMapping("/api/v1/datahandle")
public class BaseController {
}
package com.viontech.controller;
import com.viontech.service.adapter.behavior.IBehaviorArchiveService;
import com.viontech.service.adapter.behavior.IBehaviorService;
import com.viontech.vo.BehaviorArchiveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
public class BehaviorArchiveController extends BaseController{
@Resource
IBehaviorArchiveService iBehaviorArchiveService;
@Autowired
IBehaviorService iBehaviorService;
@GetMapping("/behavior/archive")
@ResponseBody
public Object getAll(BehaviorArchiveVo behaviorArchiveVo){
return iBehaviorArchiveService.selectAll(behaviorArchiveVo);
}
@GetMapping("/behavior/archive/{unid}")
@ResponseBody
public Object getOneEvents(BehaviorArchiveVo behaviorArchiveVo){
return iBehaviorService.selectAllByArchive(behaviorArchiveVo);
}
@DeleteMapping("/behavior/archive/{unid}")
@ResponseBody
public Object delete(BehaviorArchiveVo behaviorArchiveVo){
return iBehaviorArchiveService.deleteByUnid(behaviorArchiveVo.getUnid());
}
}
package com.viontech.controller;
import com.viontech.service.adapter.behavior.IBehaviorAuditService;
import com.viontech.vo.AuditVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
public class BehaviorAuditController extends BaseController{
@Autowired
IBehaviorAuditService iBehaviorAuditService;
@PostMapping("/behavior/audit/{eventunid}")
@ResponseBody
public Object audit(@RequestBody AuditVo auditVo,@PathVariable("eventunid") Integer eventunid){
auditVo.setEventUnid(eventunid);
return iBehaviorAuditService.audit(auditVo);
}
}
package com.viontech.controller;
import com.viontech.service.adapter.behavior.IBehaviorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class BehaviorController extends BaseController{
@Autowired
IBehaviorService iBehaviorService;
@DeleteMapping("/behavior/events/{unid}")
@ResponseBody
public Object delete(@PathVariable("unid") Integer event_unid){
return iBehaviorService.deleteEventByUnid(event_unid);
}
}
package com.viontech.dao;
import com.viontech.dao.adapter.IBehaviorArchiveDao;
import com.viontech.entity.archive.BehaviorArchiveEntity;
import com.viontech.entity.archive.EventArchiveRelEntity;
import com.viontech.repository.EventArchiveRepository;
import com.viontech.util.DateUtil;
import com.viontech.vo.BehaviorArchiveVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.persistence.criteria.*;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class BehaviorArchiveDaoImpl implements IBehaviorArchiveDao {
@Autowired
public JdbcTemplate jdbcTemplate;
@Resource
EventArchiveRepository eventArchiveRepository;
@Override
public Object archive(BehaviorArchiveVo behaviorArchiveVo) {
return null;
}
@Override
public Page<BehaviorArchiveEntity> findAll(BehaviorArchiveVo behaviorArchiveVo) {
Pageable pageable = new PageRequest(behaviorArchiveVo.getPageNum(),behaviorArchiveVo.getPageSize(), Sort.Direction.DESC,"eventType","auditStatus");
return eventArchiveRepository.findAll(new Specification<BehaviorArchiveEntity>() {
@Override
public Predicate toPredicate(Root<BehaviorArchiveEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
query.distinct(true);
List<Predicate> listP = new ArrayList<>();
Predicate condition = null;
ListJoin<BehaviorArchiveEntity, EventArchiveRelEntity> join = root.join(root.getModel().getList("eventArchiveRelEntitys", EventArchiveRelEntity.class), JoinType.INNER);
if(StringUtils.isNotBlank(behaviorArchiveVo.getEventType())) {
condition = criteriaBuilder.equal(root.get("eventType"),behaviorArchiveVo.getEventType());
listP.add(condition);
}
if(StringUtils.isNotBlank(behaviorArchiveVo.getLocationName())) {
condition = criteriaBuilder.like(root.get("locationName"), "%"+behaviorArchiveVo.getLocationName()+"%");
listP.add(condition);
}
if(behaviorArchiveVo.getAuditStatus() != null){
condition = criteriaBuilder.equal(root.get("auditStatus"), behaviorArchiveVo.getAuditStatus());
listP.add(condition);
}
try {
if (StringUtils.isNotBlank(behaviorArchiveVo.getStartDt())){
condition = criteriaBuilder.greaterThanOrEqualTo(join.get("eventDataEntity").get("eventDt").as(Date.class), DateUtil.FORMAT_YYYY_MM_DD_HH_MM_SS.parse(behaviorArchiveVo.getStartDt()));
listP.add(condition);
}
if (StringUtils.isNotBlank(behaviorArchiveVo.getEndDt())){
condition = criteriaBuilder.lessThan(join.get("eventDataEntity").get("eventDt").as(Date.class), DateUtil.FORMAT_YYYY_MM_DD_HH_MM_SS.parse(behaviorArchiveVo.getEndDt()));
listP.add(condition);
}
} catch (ParseException e) {
e.printStackTrace();
}
query.where(listP.toArray(new Predicate[]{}));
return null;
}
},pageable);
}
@Override
public BehaviorArchiveVo deleteByUnid(Integer unid) {
jdbcTemplate.execute("delete tb_event_archive_rel where archive_unid="+unid);
eventArchiveRepository.delete(unid);
return null;
}
/***
* 未审核状态自动归档
*/
//@Scheduled(cron = "0/5 * * * * ?")
private void noneAuditAutoArchive(){
jdbcTemplate.execute("SELECT archive()");
}
}
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.adapter;
import com.viontech.entity.archive.BehaviorArchiveEntity;
import com.viontech.vo.BehaviorArchiveVo;
import org.springframework.data.domain.Page;
import java.util.List;
public interface IBehaviorArchiveDao {
Object archive(BehaviorArchiveVo behaviorArchiveVo);
Page<BehaviorArchiveEntity> findAll(BehaviorArchiveVo behaviorArchiveVo);
BehaviorArchiveVo deleteByUnid(Integer unid);
}
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;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.viontech.common.VionTechJsonbType;
import com.viontech.entity.archive.EventArchiveRelEntity;
import org.hibernate.annotations.Type;
......@@ -22,7 +23,8 @@ public class EventDataEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer event_unid;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
//@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
@Column(name = "event_dt", nullable = true)
Date eventDt;
@Column(name = "task_type", nullable = true)
......@@ -35,12 +37,12 @@ public class EventDataEntity {
private String eventRefid;
@Column(name = "pics", nullable = true, columnDefinition = "jsonb")
@Type(type = "json")
private List pics;
private Object pics;
@Column(name = "event_cate", nullable = true)
private String eventCate;
@Column(name = "video", nullable = true, columnDefinition = "jsonb")
@Type(type = "json")
private List video;
private Object video;
@Column(name = "subtask_id", nullable = true)
private String subtaskId;
@Column(name = "source_type", nullable = true)
......@@ -54,9 +56,8 @@ public class EventDataEntity {
@Type(type = "json")
private Object originalJson;
@OneToMany(cascade={CascadeType.ALL,CascadeType.REMOVE})
@JoinColumn(name="event_unid")
private List<EventArchiveRelEntity> eventArchiveRelEntitys;
@OneToOne(mappedBy = "eventDataEntity",cascade={CascadeType.ALL,CascadeType.REMOVE})
private EventArchiveRelEntity eventArchiveRelEntity;
@Column(name="is_archive")
......@@ -159,27 +160,27 @@ public class EventDataEntity {
this.originalJson = originalJson;
}
public List<EventArchiveRelEntity> getEventArchiveRelEntitys() {
return eventArchiveRelEntitys;
public EventArchiveRelEntity getEventArchiveRelEntity() {
return eventArchiveRelEntity;
}
public void setEventArchiveRelEntitys(List<EventArchiveRelEntity> eventArchiveRelEntitys) {
this.eventArchiveRelEntitys = eventArchiveRelEntitys;
public void setEventArchiveRelEntity(EventArchiveRelEntity eventArchiveRelEntity) {
this.eventArchiveRelEntity = eventArchiveRelEntity;
}
public List getPics() {
public Object getPics() {
return pics;
}
public void setPics(List pics) {
public void setPics(Object pics) {
this.pics = pics;
}
public List getVideo() {
public Object getVideo() {
return video;
}
public void setVideo(List video) {
public void setVideo(Object video) {
this.video = video;
}
......
package com.viontech.entity.archive;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
//import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
import java.util.Date;
......@@ -14,13 +17,17 @@ import java.util.List;
public class BehaviorArchiveEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer unid;
Integer archive_unid;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
//@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
@Column(name = "start_dt", nullable = true)
Date startDt;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
//@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
@Column(name = "end_dt", nullable = true)
Date endDt;
......@@ -50,18 +57,19 @@ public class BehaviorArchiveEntity {
@Column(name = "audit_info", nullable = true)
private String auditInfo;
@OneToMany(cascade={CascadeType.ALL,CascadeType.REMOVE})
@JoinColumn(name="archive_unid")
@JsonIgnore
@OneToMany(mappedBy = "behaviorArchiveEntity",cascade={CascadeType.ALL,CascadeType.REMOVE})
private List<EventArchiveRelEntity> eventArchiveRelEntitys;
public Integer getUnid() {
return unid;
//private Integer totalEvents=0;
public Integer getArchive_unid() {
return archive_unid;
}
public void setUnid(Integer unid) {
this.unid = unid;
public void setArchive_unid(Integer archive_unid) {
this.archive_unid = archive_unid;
}
public Date getStartDt() {
......@@ -135,4 +143,12 @@ public class BehaviorArchiveEntity {
public void setEventArchiveRelEntitys(List<EventArchiveRelEntity> eventArchiveRelEntitys) {
this.eventArchiveRelEntitys = eventArchiveRelEntitys;
}
// public Integer getTotalEvents() {
// return totalEvents;
// }
//
// public void setTotalEvents(Integer totalEvents) {
// this.totalEvents = totalEvents;
// }
}
......@@ -15,9 +15,11 @@ public class EventArchiveRelEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer unid;
@Column(name = "event_unid")
private Integer eventUnid;
@OneToOne
@JoinColumn(name = "event_unid")
private EventDataEntity eventDataEntity;
@Column(name = "archive_unid")
private Integer archiveUnid;
@ManyToOne
@JoinColumn(name = "archive_unid")
private BehaviorArchiveEntity behaviorArchiveEntity ;
}
package com.viontech.repository;
import com.viontech.entity.archive.BehaviorArchiveEntity;
import com.viontech.vo.BehaviorArchiveVo;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
@Repository
public interface EventArchiveRepository extends JpaRepository<BehaviorArchiveEntity, Integer>,
JpaSpecificationExecutor<BehaviorArchiveEntity> {
}
......@@ -3,10 +3,12 @@ package com.viontech.repository;
import com.viontech.entity.EventDataEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
/**
* Created by Administrator
*/
@Repository
public interface EventDataRepository extends JpaRepository<EventDataEntity, Integer>,
JpaSpecificationExecutor<EventDataEntity> {
......
package com.viontech.service.adapter.behavior;
import com.viontech.entity.archive.BehaviorArchiveEntity;
import com.viontech.service.adapter.IEventDataService;
import com.viontech.vo.BehaviorArchiveVo;
import org.springframework.data.domain.Page;
public interface IBehaviorArchiveService extends IEventDataService {
Object archive(BehaviorArchiveVo behaviorArchiveVo);
Page<BehaviorArchiveEntity> selectAll(BehaviorArchiveVo behaviorArchiveVo);
BehaviorArchiveVo deleteByUnid(Integer unid);
}
package com.viontech.service.adapter.behavior;
import com.viontech.vo.AuditVo;
public interface IBehaviorAuditService {
Object audit(AuditVo auditVo);
}
package com.viontech.service.adapter.behavior;
import com.viontech.entity.EventDataEntity;
import com.viontech.vo.BehaviorArchiveVo;
import com.viontech.vo.EventDataVo;
import java.util.List;
/**
* Created by Administrator
*/
public interface IBehaviorService {
Object recvBehaviorData(EventDataVo eventDataVo);
List<EventDataEntity> selectAllByArchive(BehaviorArchiveVo behaviorArchiveVo);
Object deleteEventByUnid(Integer unid);
}
package com.viontech.service.impl.behavior;
import com.viontech.dao.adapter.IBehaviorArchiveDao;
import com.viontech.entity.archive.BehaviorArchiveEntity;
import com.viontech.service.adapter.behavior.IBehaviorArchiveService;
import com.viontech.vo.BehaviorArchiveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
@Service
public class BehaviorArchiveServiceImpl implements IBehaviorArchiveService {
@Autowired
IBehaviorArchiveDao iBehaviorArchiveDao;
/***
* 新增归档信息
* @param behaviorArchiveVo
......@@ -16,4 +22,19 @@ public class BehaviorArchiveServiceImpl implements IBehaviorArchiveService {
public Object archive(BehaviorArchiveVo behaviorArchiveVo) {
return null;
}
@Override
public Page<BehaviorArchiveEntity> selectAll(BehaviorArchiveVo behaviorArchiveVo) {
Page<BehaviorArchiveEntity> behaviorArchiveEntity = iBehaviorArchiveDao.findAll(behaviorArchiveVo);
return behaviorArchiveEntity;
}
@Override
public BehaviorArchiveVo deleteByUnid(Integer unid) {
iBehaviorArchiveDao.deleteByUnid(unid);
return null;
}
}
package com.viontech.service.impl.behavior;
import com.viontech.entity.EventDataEntity;
import com.viontech.entity.archive.BehaviorArchiveEntity;
import com.viontech.repository.EventArchiveRepository;
import com.viontech.repository.EventDataRepository;
import com.viontech.service.adapter.behavior.IBehaviorAuditService;
import com.viontech.util.DateUtil;
import com.viontech.vo.AuditVo;
import com.viontech.vo.BehaviorArchiveVo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service
public class BehaviorAuditServiceImpl implements IBehaviorAuditService {
@Autowired
public JdbcTemplate jdbcTemplate;
@Autowired
EventDataRepository eventDataRepository;
@Autowired
EventArchiveRepository eventArchiveRepository;
/***
*
* @param auditVo
* @return
*/
@Override
public Object audit(AuditVo auditVo) {
EventDataEntity eventDataEntity =eventDataRepository.findOne(auditVo.getEventUnid());
if ( Objects.isNull(eventDataEntity) ){
return null;
}
String locationCode = StringUtils.isBlank(eventDataEntity.getLocationCode()) ? "-" : eventDataEntity.getLocationCode();
String locationName = StringUtils.isBlank(eventDataEntity.getLocationName()) ? "-" : eventDataEntity.getLocationName();
StringBuilder archiveSql = new StringBuilder("select archive_unid from tb_behavior_archive where ");
archiveSql.append(" event_type='").append(eventDataEntity.getEventType()).append("' ");
archiveSql.append(" and location_code='").append(locationCode).append("' ");
archiveSql.append(" and location_name='").append(locationName).append("' ");
archiveSql.append(" and audit_status=").append(auditVo.getAuditStatus());
List<Map<String,Object>> archive = jdbcTemplate.queryForList(archiveSql.toString());
StringBuilder updateEventArchiveRelSql = new StringBuilder("update tb_event_archive_rel ");
//若是没有则新增归档信息
if(CollectionUtils.isEmpty(archive)){
BehaviorArchiveEntity behaviorArchiveEntity = new BehaviorArchiveEntity();
behaviorArchiveEntity.setAuditInfo(auditVo.getAuditInfo());
behaviorArchiveEntity.setAuditStatus(auditVo.getAuditStatus());
behaviorArchiveEntity.setEventType(eventDataEntity.getEventType());
behaviorArchiveEntity.setStartDt(eventDataEntity.getEventDt());
behaviorArchiveEntity.setEndDt(eventDataEntity.getEventDt());
behaviorArchiveEntity.setLocationCode(locationCode);
behaviorArchiveEntity.setLocationName(locationName);
eventArchiveRepository.save(behaviorArchiveEntity);
updateEventArchiveRelSql.append(" set archive_unid=").append(behaviorArchiveEntity.getArchive_unid());
}else{
updateEventArchiveRelSql.append(" set archive_unid=").append(archive.get(0).get("archive_unid"));
}
updateEventArchiveRelSql.append(" where event_unid=").append(eventDataEntity.getEvent_unid());
jdbcTemplate.execute(updateEventArchiveRelSql.toString());
return null;
}
}
package com.viontech.service.impl.behavior;
import com.viontech.entity.EventDataEntity;
import com.viontech.entity.archive.EventArchiveRelEntity;
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.BehaviorArchiveVo;
import com.viontech.vo.EventDataVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
......@@ -18,10 +28,11 @@ import java.util.Map;
*/
@Slf4j
@Service
@SuppressWarnings("unchecked")
public class BehaviorServiceImpl implements IBehaviorService {
@Autowired
EventDataRepository eventDataRepository;
@Autowired
public JdbcTemplate jdbcTemplate;
@Override
public Object recvBehaviorData(EventDataVo eventDataVo) {
try {
......@@ -46,10 +57,34 @@ public class BehaviorServiceImpl implements IBehaviorService {
eventDataEntity.setPics(eventDataVo.getPics());
eventDataEntity.setVideo(eventDataVo.getVideo());
eventDataEntity.setOriginalJson(JavaBean2Json.Json2JavaBean(JavaBean2Json.javaBean2Json(eventDataVo),Map.class));
eventDataEntity.setArchive(false);
eventDataRepository.save(eventDataEntity);
jdbcTemplate.execute("SELECT archive()");
} catch (Exception e) {
log.error("新增behavior事件异常:"+e.getLocalizedMessage(),e);
}
return null;
}
@Override
public List<EventDataEntity> selectAllByArchive(BehaviorArchiveVo behaviorArchiveVo) {
Pageable pageable = new PageRequest(behaviorArchiveVo.getPageNum(),behaviorArchiveVo.getPageSize(), Sort.Direction.DESC,"eventDt");
return eventDataRepository.findAll(new Specification<EventDataEntity>() {
@Override
public Predicate toPredicate(Root<EventDataEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Join<EventDataEntity, EventArchiveRelEntity> join = root.join(root.getModel().getSingularAttribute("eventArchiveRelEntity", EventArchiveRelEntity.class), JoinType.INNER);
Predicate condition = cb.equal(join.get("behaviorArchiveEntity").get("archive_unid").as(Integer.class), behaviorArchiveVo.getUnid());
query.where(condition);
//query.orderBy(cb.desc(root.get("eventDt").as(Date.class)));
return null;
}
},pageable).getContent();
}
@Override
public Object deleteEventByUnid(Integer unid) {
jdbcTemplate.execute("delete tb_event_archive_rel where event_unid="+unid);
eventDataRepository.delete(unid);
return null;
}
}
package com.viontech.vo;
public class AuditVo {
private Integer eventUnid;
private Integer auditStatus;
private String auditInfo;
public Integer getEventUnid() {
return eventUnid;
}
public void setEventUnid(Integer eventUnid) {
this.eventUnid = eventUnid;
}
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;
}
}
package com.viontech.vo;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
@Data
public class BehaviorArchiveVo {
Integer unid;
String startDt;
......@@ -21,4 +16,95 @@ public class BehaviorArchiveVo {
*/
private Integer auditStatus=0;
private String auditInfo;
private Integer pageNum=0;
private Integer pageSize=20;
public Integer getUnid() {
return unid;
}
public void setUnid(Integer unid) {
this.unid = unid;
}
public String getStartDt() {
return startDt;
}
public void setStartDt(String startDt) {
this.startDt = startDt;
}
public String getEndDt() {
return endDt;
}
public void setEndDt(String 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 Integer getPageNum() {
return pageNum;
}
public void setPageNum(Integer pageNum) {
this.pageNum = pageNum;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!