Commit 23f23e5e by 杜广伟

实现审核功能;

添加feign调用外部接口功能;
1 parent 92e3a415
事件管理平台
#系统环境
##系统整体架构使用Springboot
##架包管理使用gradle,本地需要安装gradle
##项目中使用了lombok,需要在开发工具中添加相应的插件
\ No newline at end of file
group 'com.viontech'
version '1.0-SNAPSHOT'
buildscript {
/*repositories {
jcenter()
}*/
repositories {
maven { url 'http://192.168.9.220:8081/nexus/content/groups/public/' }
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.3.RELEASE")
}
}
......@@ -17,7 +16,11 @@ buildscript {
*/
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'idea'
// 使用spring boot
apply plugin: "org.springframework.boot"
// 使用spring boot的自动依赖管理
apply plugin: 'io.spring.dependency-management'
/**
* 设置jdk的版本
......@@ -30,7 +33,7 @@ tasks.withType(JavaCompile) {
options.deprecation = true
}
repositories {
mavenCentral()
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
......@@ -39,34 +42,36 @@ repositories {
* 依赖
*/
dependencies {
compile("org.springframework.boot:spring-boot-starter-parent:1.5.2.RELEASE"){
compile("org.springframework.boot:spring-boot-starter-parent:2.1.3.RELEASE") {
exclude module: 'hibernate-core'
exclude module: 'hibernate-entitymanager'
}
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-data-jpa") {
exclude module: 'hibernate-core'
exclude module: 'hibernate-entitymanager'
}
compile("org.springframework.boot:spring-boot-starter-web:1.5.2.RELEASE")
compile ("org.springframework.boot:spring-boot-starter-websocket")
compile ("org.springframework.boot:spring-boot-starter-jdbc")
compile ("org.springframework.boot:spring-boot-starter-activemq")
compile ("org.springframework.boot:spring-boot-autoconfigure")
compile ("org.springframework.kafka:spring-kafka")
compile ("org.apache.activemq:activemq-pool")
compile ('org.springframework.cloud:spring-cloud-starter-openfeign:2.1.3.RELEASE')
// compileOnly('org.springframework.boot:spring-boot-starter-tomcat')s
// 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('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("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")
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'org.springframework:spring-core'
compile 'org.springframework.boot:spring-boot-autoconfigure'
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'
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'
compile("net.sf.json-lib:json-lib:2.4:jdk15")
}
\ No newline at end of file
package com.viontech;
import com.google.gson.Gson;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import java.util.ArrayList;
import java.util.List;
@SpringBootApplication(scanBasePackages = {"com.viontech.*"})
@Configuration
@EnableScheduling
@EnableFeignClients
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
/**
*@Description: //解决返回类型转换错误
*@param:[gson]
*@return :org.springframework.http.converter.json.GsonHttpMessageConverter
*@Date:2019/11/26
*@Author:dugw
*/
@Bean
public GsonHttpMessageConverter gsonHttpMessageConverter(Gson gson) {
GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
converter.setGson(gson);
List<MediaType> supportedMediaTypes = converter.getSupportedMediaTypes();
if (! supportedMediaTypes.contains(MediaType.TEXT_PLAIN)) {
supportedMediaTypes = new ArrayList<>(supportedMediaTypes);
supportedMediaTypes.add(MediaType.TEXT_PLAIN);
converter.setSupportedMediaTypes(supportedMediaTypes);
}
return converter;
}
@Configuration
public class CorsConfig {
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("*");
config.setAllowCredentials(true);
config.addAllowedMethod("*");
config.addAllowedHeader("*");
config.setMaxAge(3600L);
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
configSource.registerCorsConfiguration("/**", config);
return new CorsFilter(configSource);
}
}
}
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.*"})
@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.consumer;
import com.viontech.service.adapter.behavior.IBehaviorService;
import com.viontech.service.adapter.behavior.IBehaviorEventService;
import com.viontech.util.JavaBean2Json;
import com.viontech.vo.EventDataVo;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -14,7 +14,7 @@ import org.springframework.stereotype.Component;
public class BehaviorDataConsumer {
@Autowired
IBehaviorService iBehaviorService;
IBehaviorEventService iBehaviorService;
@JmsListener(destination = "behavior")
public void reciveDate(String msg){
......
package com.viontech.controller;
import com.viontech.service.adapter.behavior.IBehaviorArchiveService;
import com.viontech.service.adapter.behavior.IBehaviorService;
import com.viontech.service.adapter.behavior.IBehaviorEventService;
import com.viontech.vo.BehaviorArchiveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
......@@ -18,7 +18,7 @@ public class BehaviorArchiveController extends BaseController{
@Resource
IBehaviorArchiveService iBehaviorArchiveService;
@Autowired
IBehaviorService iBehaviorService;
IBehaviorEventService iBehaviorEventService;
@GetMapping("/behavior/archive")
@ResponseBody
......@@ -29,7 +29,7 @@ public class BehaviorArchiveController extends BaseController{
@GetMapping("/behavior/archive/{unid}")
@ResponseBody
public Object getOneEvents(BehaviorArchiveVo behaviorArchiveVo){
return iBehaviorService.selectAllByArchive(behaviorArchiveVo);
return iBehaviorEventService.selectAllByArchive(behaviorArchiveVo);
}
@DeleteMapping("/behavior/archive/{unid}")
......
......@@ -11,10 +11,9 @@ public class BehaviorAuditController extends BaseController{
@Autowired
IBehaviorAuditService iBehaviorAuditService;
@PostMapping("/behavior/audit/{eventunid}")
@PostMapping("/behavior/audit/{archiveId}")
@ResponseBody
public Object audit(@RequestBody AuditVo auditVo,@PathVariable("eventunid") Integer eventunid){
auditVo.setEventUnid(eventunid);
return iBehaviorAuditService.audit(auditVo);
public Object audit(@RequestBody AuditVo auditVo,@PathVariable("archiveId") Integer archiveId){
return iBehaviorAuditService.audit(auditVo,archiveId);
}
}
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.controller;
import com.alibaba.fastjson.JSON;
import com.viontech.feginService.MessagePushAPIHandler;
import com.viontech.service.adapter.behavior.IBehaviorEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
public class BehaviorEventController extends BaseController{
@Autowired
IBehaviorEventService iBehaviorService;
@Autowired
private MessagePushAPIHandler messagePushAPIHandler;
@DeleteMapping("/behavior/events/{unid}")
@ResponseBody
public Object delete(@PathVariable("unid") Integer event_unid){
return iBehaviorService.deleteEventByUnid(event_unid);
}
@RequestMapping(value = "/test",method = RequestMethod.POST )
public Object testFeign(){
String message = "{\"pics\": [{\"hight\": 1080, \"width\": 1920, \"format\": \"jpg\", \"src_url\": \"http://192.168.9.133:20080/static/pics/cache/2019-11-24/pic-89/84eb0c25d0c148c88e8822931441a101.jpg\", \"pic_unid\": \"84eb0c25d0c148c88e8822931441a101\", \"shoot_dt\": \"2019-11-24 16:09:24.230\", \"ofilename\": \"172.17.0.620191125000925172_00.jpg\"}], \"video\": [{\"fps\": 25, \"width\": 1920, \"end_dt\": \"2019-11-24 16:09:24.230\", \"format\": \"mp4\", \"height\": 1080, \"start_dt\": \"2019-11-24 16:09:22.917\", \"ofilename\": \"/2019-11-25/00/20191124160919230325.mp4\", \"video_unid\": \"20191124160919230325\"}], \"task_id\": \"5db2a97042f94d52bc91da5f1bd4aa94\", \"event_dt\": \"2019-11-24 16:09:22.917\", \"task_type\": \"normal\", \"event_cate\": \"behavior\", \"event_data\": {\"lane\": {\"code\": \"00\", \"number\": 0}, \"end_dt\": \"2019-11-24 16:09:24.230\", \"laneNO\": 0, \"laneType\": \"00\", \"start_dt\": \"2019-11-24 16:09:22.917\", \"direction\": {\"code\": \"1\"}, \"direction_id\": \"1\"}, \"event_type\": \"yongdu\", \"subtask_id\": \"f25e1c91f25647e3a7e6b686349a7d0d\", \"event_refid\": \"172.17.0.620191125000925172\", \"source_type\": \"pull_video_stream\", \"vchan_refid\": \"19fa23d0e59b4b18813b3ede3eb56a66\"}";
Map map = messagePushAPIHandler.auditMessagePush(JSON.parseObject(message));
return map;
}
}
......@@ -122,7 +122,7 @@ public class WebsocketController {
}
private String onKeepAlive(String connection_unid) {
Map activeMsg = new HashMap<>(6);
Map<String,Object> activeMsg = new HashMap<>(6);
activeMsg.put("type", "response");
activeMsg.put("id", System.currentTimeMillis());
activeMsg.put("mts", System.currentTimeMillis());
......
......@@ -14,12 +14,10 @@ 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;
......@@ -82,7 +80,7 @@ public class BehaviorArchiveDaoImpl implements IBehaviorArchiveDao {
@Override
public BehaviorArchiveVo deleteByUnid(Integer unid) {
jdbcTemplate.execute("delete tb_event_archive_rel where archive_unid="+unid);
eventArchiveRepository.delete(unid);
eventArchiveRepository.deleteById(unid);
return null;
}
......
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 lombok.ToString;
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
......@@ -19,6 +17,7 @@ import java.util.Map;
@Table(name = "tb_event_data")
@Inheritance(strategy = InheritanceType.JOINED)
@TypeDef(name = "json", typeClass = VionTechJsonbType.class)
@ToString
public class EventDataEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......
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;
import java.util.List;
//import com.fasterxml.jackson.annotation.JsonIgnore;
/***
* 事件归档
*/
......@@ -41,7 +41,6 @@ public class BehaviorArchiveEntity {
private String locationCode;
/***
* 责任
*/
......@@ -144,7 +143,8 @@ public class BehaviorArchiveEntity {
this.eventArchiveRelEntitys = eventArchiveRelEntitys;
}
// public Integer getTotalEvents() {
// public Integer getTotalEvents() {
// return totalEvents;
// }
//
......
package com.viontech.feginService;
import feign.Headers;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.Map;
/**
* 拾联对接接口
*/
@Repository
@FeignClient(name="mssagePush-httpClient",url="${message.audit.httpUrl:127.0.0.1:80}")
public interface MessagePushAPIHandler {
/**
* 审核信息推送到对方平台,
* @param params
* @return
*/
@Headers({"Content-Type: application/json","Accept: application/json"})
@PostMapping(value = "/testCode/reciveMessage")
Map auditMessagePush(@RequestBody Map params);
}
......@@ -3,5 +3,5 @@ package com.viontech.service.adapter.behavior;
import com.viontech.vo.AuditVo;
public interface IBehaviorAuditService {
Object audit(AuditVo auditVo);
Object audit(AuditVo auditVo,Integer archiveId);
}
......@@ -9,7 +9,7 @@ import java.util.List;
/**
* Created by Administrator
*/
public interface IBehaviorService {
public interface IBehaviorEventService {
Object recvBehaviorData(EventDataVo eventDataVo);
List<EventDataEntity> selectAllByArchive(BehaviorArchiveVo behaviorArchiveVo);
......
......@@ -2,23 +2,29 @@ package com.viontech.service.impl.behavior;
import com.viontech.entity.EventDataEntity;
import com.viontech.entity.archive.BehaviorArchiveEntity;
import com.viontech.feginService.MessagePushAPIHandler;
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.util.JavaBean2Json;
import com.viontech.util.JsonMessageUtil;
import com.viontech.vo.AuditVo;
import com.viontech.vo.BehaviorArchiveVo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
@Slf4j
public class BehaviorAuditServiceImpl implements IBehaviorAuditService {
@Autowired
......@@ -29,46 +35,68 @@ public class BehaviorAuditServiceImpl implements IBehaviorAuditService {
@Autowired
EventArchiveRepository eventArchiveRepository;
@Autowired
MessagePushAPIHandler messagePushAPIHandler;
@Value("${message.audit.isOpen:false}")
private Boolean auditMessageFlag;
/***
*
* @param auditVo
* 修改归档事件状态
* @param auditVo 第一条事件数据
* @param archiveId 归档事件Id
* @return
*/
@Override
public Object audit(AuditVo auditVo) {
EventDataEntity eventDataEntity =eventDataRepository.findOne(auditVo.getEventUnid());
if ( Objects.isNull(eventDataEntity) ){
return null;
@Transactional
public Object audit(AuditVo auditVo,Integer archiveId) {
//修改归档的状态值
Integer eventUnid = auditVo.getEventUnid();
if(eventUnid == null || archiveId == null){
return JsonMessageUtil.getErrorJsonMsg("请求参数传递缺失。eventUnid:"+eventUnid+",archiveId:"+archiveId);
}
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 ");
Integer auditStatus = auditVo.getAuditStatus();
String updateArchiveStatusSQL = "UPDATE tb_behavior_archive SET audit_status = "+ auditStatus
+" where archive_unid ="+archiveId;
jdbcTemplate.execute(updateArchiveStatusSQL);
//获取第一条参数的数据
EventDataEntity eventDataEntity =eventDataRepository.getOne(eventUnid);
//审核通过,通知第三方系统
if (auditStatus == 1 && auditMessageFlag){
String originalJson = ""+eventDataEntity.getOriginalJson();
if (originalJson.length() <= 0){
log.error("原始数据Json未找到,第三方接口调用失败,eventDataEntity:"+eventDataEntity.toString());
return JsonMessageUtil.getErrorJsonMsg("原始数据Json未找到,第三方接口调用失败");
}
Map sendMessageMap = new HashedMap();
JavaBean2Json.jsonToMap(originalJson,sendMessageMap);
Map responMessageMap = messagePushAPIHandler.auditMessagePush(sendMessageMap);
}
//审核不通过需要判断系统中是否存在相同地点的相同类型的审核不通过事件,如果存在则归档事件合并
if(auditStatus == 2){
BehaviorArchiveEntity behaviorArchiveEntity = eventArchiveRepository.getOne(archiveId);
if (behaviorArchiveEntity == null){
log.error("归档ID未找到对应归档.id:"+archiveId);
return JsonMessageUtil.getErrorJsonMsg("归档ID未找到对应归档.id:"+archiveId);
}
String eventType = behaviorArchiveEntity.getEventType();
String locationCode = behaviorArchiveEntity.getLocationCode();
String getArchiveListSQL = "SELECT * from tb_behavior_archive where event_type = '"+eventType+"' and location_code = '"+locationCode+"' and audit_status = 2 order by start_dt ASC";
RowMapper<BehaviorArchiveEntity> behaviorArchiveEntityRowMapper = new BeanPropertyRowMapper<>(BehaviorArchiveEntity.class);
List<BehaviorArchiveEntity> archiveEntityList = jdbcTemplate.query(getArchiveListSQL, behaviorArchiveEntityRowMapper);
if (archiveEntityList.size() == 1){
return JsonMessageUtil.getSuccessJsonMsg("事件审核未通过操作成功");
}
String archiveIds = archiveEntityList.stream().map(model -> model.getArchive_unid().toString())
.collect(Collectors.joining(","));
BehaviorArchiveEntity firstArchiveData = archiveEntityList.get(0);
Integer firstArchiveId = firstArchiveData.getArchive_unid();
String updateArchive2EventRel = "UPDATE tb_event_archive_rel SET archive_unid = "+firstArchiveId+" where archive_unid in ("+archiveIds+")";
jdbcTemplate.update(updateArchive2EventRel);
//若是没有则新增归档信息
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"));
archiveEntityList.remove(0);
eventArchiveRepository.deleteAll(archiveEntityList);
}
updateEventArchiveRelSql.append(" where event_unid=").append(eventDataEntity.getEvent_unid());
jdbcTemplate.execute(updateEventArchiveRelSql.toString());
return null;
return JsonMessageUtil.getSuccessJsonMsg("操作成功");
}
}
......@@ -3,7 +3,7 @@ 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.service.adapter.behavior.IBehaviorEventService;
import com.viontech.util.DateUtil;
import com.viontech.util.JavaBean2Json;
import com.viontech.vo.BehaviorArchiveVo;
......@@ -18,7 +18,6 @@ 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;
......@@ -28,7 +27,8 @@ import java.util.Map;
*/
@Slf4j
@Service
public class BehaviorServiceImpl implements IBehaviorService {
public class BehaviorEventServiceImpl implements IBehaviorEventService {
@Autowired
EventDataRepository eventDataRepository;
@Autowired
......@@ -69,22 +69,18 @@ public class BehaviorServiceImpl implements IBehaviorService {
@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) {
return eventDataRepository.findAll((Specification<EventDataEntity>) (root, query, 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);
eventDataRepository.deleteById(unid);
return null;
}
}
package com.viontech.util;
public class JsonMessageUtil {
/**
* 返回成功json信息
*
* @param msg
* 成功信息
* @param data
* 对应的数据
* @return json消息对象
*/
public static <T> JsonMessage<T> getSuccessJsonMsg(String msg, T data) {
JsonMessage jsonMessage = getJsonMessageInstance();
jsonMessage.setSuccess(true);
jsonMessage.setCode(200);
jsonMessage.setMsg(msg);
jsonMessage.setData(data);
return jsonMessage;
}
public static<T> JsonMessage<T> getSuccessJsonMsg(T data) {
return getSuccessJsonMsg("", data);
}
public static JsonMessage getSuccessJsonMsg(String msg) {
return getSuccessJsonMsg(msg, null);
}
/**
* 返回失败json信息
*
* @param msg
* 成功信息
* @return json消息对象
*/
public static JsonMessage getErrorJsonMsg(String msg) {
JsonMessage jsonMessage = getJsonMessageInstance();
jsonMessage.setSuccess(false);
jsonMessage.setCode(500);
jsonMessage.setMsg(msg);
jsonMessage.setData(null);
return jsonMessage;
}
/**
* 返回失败json信息
*
* @param msg
* 成功信息
* @return json消息对象
*/
public static JsonMessage getErrorJsonMsg(Integer code,String msg) {
JsonMessage jsonMessage = getJsonMessageInstance();
jsonMessage.setSuccess(false);
jsonMessage.setCode(code);
jsonMessage.setMsg(msg);
jsonMessage.setData(null);
return jsonMessage;
}
/**
* Json消息对象,用来返回给前台json
*
* @author suman 2016年8月15日 上午10:55:05
*/
public static JsonMessage getJsonMessageInstance(){
return new JsonMessageUtil.JsonMessage();
}
public static class JsonMessage<T> {
private boolean success;
private int code;
private String msg;
private T data;
public JsonMessage() {
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
}
server:
port: 8086
spring:
main:
allow-bean-definition-overriding: true
datasource:
url: jdbc:postgresql://192.168.9.133:5432/event_data_handle
username: postgres
......@@ -40,3 +42,7 @@ spring:
broker-url: tcp://192.168.9.133:61616
jms:
pub-sub-domain: true
message:
audit:
isOpen: false
httpUrl: 127.0.0.1:16060
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!