Commit 7eb035d7 by 熊付

【首页统计接口】

1 parent 92e3a415
package com.viontech.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/***
* 当使用springboot启动时打开即可 不然websocket不起作用 若是使用tomcat启动则必须关闭
*/
//@Configuration
@Configuration
public class WebSocketConfig {
@Bean
......
package com.viontech.controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by Administrator
*/
@CrossOrigin(origins = "*",allowCredentials = "true")
@RestController
@RequestMapping("/api/v1/datahandle")
public class BaseController {
......
package com.viontech.controller;
import com.viontech.service.adapter.behavior.IBehaviorService;
import com.viontech.vo.EventDataVo;
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;
import org.springframework.web.bind.annotation.*;
@RestController
public class BehaviorController extends BaseController{
......@@ -19,4 +17,14 @@ public class BehaviorController extends BaseController{
return iBehaviorService.deleteEventByUnid(event_unid);
}
/****
* 批量删除
* @param eventDataVo
* @return
*/
@DeleteMapping("/behavior/events/batch/delete")
@ResponseBody
public Object batchDelete(@RequestBody EventDataVo eventDataVo){
return iBehaviorService.batchDelete(eventDataVo);
}
}
package com.viontech.controller;
import com.viontech.service.adapter.behavior.IBehaviorStatisticsService;
import com.viontech.vo.BehaviorStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class BehaviorStatisticsController extends BaseController {
@Autowired
IBehaviorStatisticsService iBehaviorStatisticsService;
@GetMapping("/statistics/type")
@ResponseBody
public Object statisticsByType(BehaviorStatisticsVo behaviorStatisticsVo){
return iBehaviorStatisticsService.statisticsByType(behaviorStatisticsVo);
}
@GetMapping("/statistics/hour")
@ResponseBody
public Object hourChart(BehaviorStatisticsVo behaviorStatisticsVo){
return iBehaviorStatisticsService.hourChart(behaviorStatisticsVo);
}
@GetMapping("/statistics/handle")
@ResponseBody
Object statisticsByEventHandle(BehaviorStatisticsVo behaviorStatisticsVo){
return iBehaviorStatisticsService.statisticsByEventHandle(behaviorStatisticsVo);
}
}
package com.viontech.controller;
import com.viontech.service.adapter.ITimeCloseService;
import com.viontech.vo.TimeCloseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TimeCloseController extends BaseController {
@Autowired
ITimeCloseService iTimeCloseService;
@PostMapping("/closetime")
@ResponseBody
public Object addTime(@RequestBody TimeCloseVo timeCloseVo){
return iTimeCloseService.add(timeCloseVo);
}
}
......@@ -20,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap;
*
*/
@Component
@ServerEndpoint("/websocket/api/v1/handle/connects/{connection_unid}")
@ServerEndpoint("/websocket/api/v1/datahandle/connects/{connection_unid}")
@Slf4j
public class WebsocketController {
......
......@@ -47,7 +47,7 @@ public class BehaviorArchiveDaoImpl implements IBehaviorArchiveDao {
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);
ListJoin<BehaviorArchiveEntity, EventArchiveRelEntity> join = root.join(root.getModel().getList("eventArchiveRelEntitys", EventArchiveRelEntity.class), JoinType.LEFT);
if(StringUtils.isNotBlank(behaviorArchiveVo.getEventType())) {
condition = criteriaBuilder.equal(root.get("eventType"),behaviorArchiveVo.getEventType());
listP.add(condition);
......@@ -67,7 +67,7 @@ public class BehaviorArchiveDaoImpl implements IBehaviorArchiveDao {
}
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()));
condition = criteriaBuilder.lessThanOrEqualTo(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) {
......@@ -81,7 +81,7 @@ public class BehaviorArchiveDaoImpl implements IBehaviorArchiveDao {
@Override
public BehaviorArchiveVo deleteByUnid(Integer unid) {
jdbcTemplate.execute("delete tb_event_archive_rel where archive_unid="+unid);
jdbcTemplate.execute("delete from tb_event_archive_rel where archive_unid="+unid);
eventArchiveRepository.delete(unid);
return null;
}
......
package com.viontech.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import javax.persistence.*;
import java.util.Date;
/***
* 系统定时关闭
*/
@Entity
@Table(name = "tb_time_close")
public class TimeCloseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer unid;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
@Column(name = "start_dt", nullable = true)
Date startDt;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
@Column(name = "end_dt", nullable = true)
Date endDt;
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;
}
}
......@@ -49,7 +49,7 @@ public class BehaviorArchiveEntity {
private Integer duty;
/****
* 审核状态值为:0待审核、1审核通过、2审核不通过、4事件结束、5定时关闭
* 审核状态值为:0待审核、1审核通过、2审核不通过、3事件结束、4定时关闭
*/
@Column(name = "audit_status", nullable = false)
private Integer auditStatus=0;
......
package com.viontech.repository;
import com.viontech.entity.TimeCloseEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
@Repository
public interface TimeCloseRepository extends JpaRepository<TimeCloseEntity, Integer>,
JpaSpecificationExecutor<TimeCloseEntity> {
}
package com.viontech.service.adapter;
import com.viontech.vo.TimeCloseVo;
public interface ITimeCloseService {
Object add(TimeCloseVo timeCloseVo);
}
......@@ -15,4 +15,6 @@ public interface IBehaviorService {
List<EventDataEntity> selectAllByArchive(BehaviorArchiveVo behaviorArchiveVo);
Object deleteEventByUnid(Integer unid);
Object batchDelete(EventDataVo eventDataVo);
}
package com.viontech.service.adapter.behavior;
import com.viontech.vo.BehaviorStatisticsVo;
public interface IBehaviorStatisticsService {
Object statisticsByType(BehaviorStatisticsVo behaviorStatisticsVo);
Object hourChart(BehaviorStatisticsVo behaviorStatisticsVo);
Object statisticsByEventHandle(BehaviorStatisticsVo behaviorStatisticsVo);
}
package com.viontech.service.impl;
import com.viontech.entity.TimeCloseEntity;
import com.viontech.repository.TimeCloseRepository;
import com.viontech.service.adapter.ITimeCloseService;
import com.viontech.util.DateUtil;
import com.viontech.vo.TimeCloseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class TimecloseServiceImpl implements ITimeCloseService {
@Autowired
TimeCloseRepository timeCloseRepository;
@Override
public Object add(TimeCloseVo timeCloseVo) {
try {
long count = timeCloseRepository.count(new Specification<TimeCloseEntity>() {
@Override
public Predicate toPredicate(Root<TimeCloseEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> listP = new ArrayList<>();
try {
Predicate start_startdt = cb.greaterThanOrEqualTo(root.get("startDt").as(Date.class), DateUtil.FORMAT_YYYY_MM_DD_HH_MM.parse(timeCloseVo.getStartDt()));
Predicate start_enddt = cb.lessThanOrEqualTo(root.get("endDt").as(Date.class), DateUtil.FORMAT_YYYY_MM_DD_HH_MM.parse(timeCloseVo.getStartDt()));
Predicate start = cb.and(start_startdt,start_enddt);
Predicate end_startdt = cb.greaterThanOrEqualTo(root.get("startDt").as(Date.class), DateUtil.FORMAT_YYYY_MM_DD_HH_MM.parse(timeCloseVo.getEndDt()));
Predicate end_enddt = cb.lessThanOrEqualTo(root.get("endDt").as(Date.class), DateUtil.FORMAT_YYYY_MM_DD_HH_MM.parse(timeCloseVo.getEndDt()));
Predicate end = cb.and(end_startdt,end_enddt);
Predicate or = cb.or(start,end);
query.where(or);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
});
if(count > 0){
return "当前设置时间段已存在";
}
TimeCloseEntity timeCloseEntity = new TimeCloseEntity();
timeCloseEntity.setEndDt(DateUtil.FORMAT_YYYY_MM_DD_HH_MM_SS.parse(timeCloseVo.getEndDt()));
timeCloseEntity.setStartDt(DateUtil.FORMAT_YYYY_MM_DD_HH_MM_SS.parse(timeCloseVo.getStartDt()));
timeCloseRepository.save(timeCloseEntity);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
......@@ -9,6 +9,8 @@ import com.viontech.util.JavaBean2Json;
import com.viontech.vo.BehaviorArchiveVo;
import com.viontech.vo.EventDataVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
......@@ -59,7 +61,10 @@ public class BehaviorServiceImpl implements IBehaviorService {
eventDataEntity.setOriginalJson(JavaBean2Json.Json2JavaBean(JavaBean2Json.javaBean2Json(eventDataVo),Map.class));
eventDataEntity.setArchive(false);
eventDataRepository.save(eventDataEntity);
jdbcTemplate.execute("SELECT archive()");
String sql = "SELECT automatic_archive("+eventDataEntity.getEvent_unid()+",'"+eventDataVo.getEvent_dt()+"','"+eventDataEntity.getEventType()+"','"+(StringUtils.isBlank(eventDataEntity.getLocationCode())?"-":eventDataEntity.getLocationCode())+"','"+(StringUtils.isBlank(eventDataEntity.getLocationName())?"-":eventDataEntity.getLocationName())+"')";
System.out.println("sql="+sql);
jdbcTemplate.execute(sql);
//jdbcTemplate.execute("SELECT archive()");
} catch (Exception e) {
log.error("新增behavior事件异常:"+e.getLocalizedMessage(),e);
}
......@@ -83,8 +88,18 @@ public class BehaviorServiceImpl implements IBehaviorService {
@Override
public Object deleteEventByUnid(Integer unid) {
jdbcTemplate.execute("delete tb_event_archive_rel where event_unid="+unid);
jdbcTemplate.execute("delete from tb_event_archive_rel where event_unid="+unid);
eventDataRepository.delete(unid);
return null;
}
@Override
public Object batchDelete(EventDataVo eventDataVo) {
if (!CollectionUtils.isEmpty(eventDataVo.getEventUnids())){
for (Integer unid : eventDataVo.getEventUnids()){
deleteEventByUnid(unid);
}
}
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.IBehaviorStatisticsService;
import com.viontech.util.DateUtil;
import com.viontech.vo.BehaviorStatisticsVo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.*;
import java.text.ParseException;
import java.util.*;
@Service
public class BehaviorStatisticsServiceImpl implements IBehaviorStatisticsService {
@Autowired
EventDataRepository eventDataRepository;
@Autowired
public JdbcTemplate jdbcTemplate;
@Override
public Object statisticsByType(BehaviorStatisticsVo behaviorStatisticsVo) {
StringBuilder stringBuilder = new StringBuilder("select count(1) as total_num ,event_type from tb_event_data WHERE 1=1 ");
if(StringUtils.isNotBlank(behaviorStatisticsVo.getStartDt())){
stringBuilder.append(" and event_dt>='").append(behaviorStatisticsVo.getStartDt()).append("'");
}
if(StringUtils.isNotBlank(behaviorStatisticsVo.getEndDt())){
stringBuilder.append(" and event_dt<='").append(behaviorStatisticsVo.getEndDt()).append("'");
}
stringBuilder.append(" group by event_type order by event_type");
Map result = new HashMap(2);
List<Map<String,Object>> list_data = jdbcTemplate.queryForList(stringBuilder.toString());
long total_num = 0L;
if( !CollectionUtils.isEmpty(list_data)){
for (Map<String,Object> map: list_data){
total_num = total_num + Long.parseLong(String.valueOf(map.get("total_num")));
}
}
result.put("total_num",total_num);
result.put("list_data",list_data);
return result;
}
@Override
public Object hourChart(BehaviorStatisticsVo behaviorStatisticsVo) {
StringBuilder stringBuilder = new StringBuilder("select count(1) as total_num ,event_type,to_char(event_dt,'HH24') as hour from tb_event_data WHERE 1=1 ");
if(StringUtils.isNotBlank(behaviorStatisticsVo.getStartDt())){
stringBuilder.append(" and event_dt>='").append(behaviorStatisticsVo.getStartDt()).append("'");
}
if(StringUtils.isNotBlank(behaviorStatisticsVo.getEndDt())){
stringBuilder.append(" and event_dt<='").append(behaviorStatisticsVo.getEndDt()).append("'");
}
stringBuilder.append(" group by event_type,hour order by hour");
Map result = new HashMap(1);
List<Map<String,Object>> list_data = jdbcTemplate.queryForList(stringBuilder.toString());
result.put("list_data",list_data);
return result;
}
@Override
public Object statisticsByEventHandle(BehaviorStatisticsVo behaviorStatisticsVo) {
StringBuilder stringBuilder = new StringBuilder("select event_unid from tb_event_data WHERE 1=1 ");
if(StringUtils.isNotBlank(behaviorStatisticsVo.getStartDt())){
stringBuilder.append(" and event_dt>='").append(behaviorStatisticsVo.getStartDt()).append("'");
}
if(StringUtils.isNotBlank(behaviorStatisticsVo.getEndDt())){
stringBuilder.append(" and event_dt<='").append(behaviorStatisticsVo.getEndDt()).append("'");
}
Map result = new HashMap(2);
List<Map<String,Object>> list_data = jdbcTemplate.queryForList(stringBuilder.toString());
result.put("snap_num",list_data.size());
result.put("audit_num",eventDataRepository.findAll(new Specification<EventDataEntity>() {
@Override
public Predicate toPredicate(Root<EventDataEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> listP = new ArrayList<>();
Join<EventDataEntity, EventArchiveRelEntity> join = root.join(root.getModel().getSingularAttribute("eventArchiveRelEntity", EventArchiveRelEntity.class), JoinType.INNER);
Path<Object> path = join.get("behaviorArchiveEntity").get("auditStatus");
CriteriaBuilder.In<Object> in = cb.in(path);
in.value(1);
in.value(2);
listP.add(in);
Predicate condition = null;
try {
if (StringUtils.isNotBlank(behaviorStatisticsVo.getStartDt())){
condition = cb.greaterThanOrEqualTo(join.get("eventDataEntity").get("eventDt").as(Date.class), DateUtil.FORMAT_YYYY_MM_DD_HH_MM_SS.parse(behaviorStatisticsVo.getStartDt()));
listP.add(condition);
}
if (StringUtils.isNotBlank(behaviorStatisticsVo.getEndDt())){
condition = cb.lessThanOrEqualTo(join.get("eventDataEntity").get("eventDt").as(Date.class), DateUtil.FORMAT_YYYY_MM_DD_HH_MM_SS.parse(behaviorStatisticsVo.getEndDt()));
listP.add(condition);
}
} catch (ParseException e) {
e.printStackTrace();
}
query.where(listP.toArray(new Predicate[]{}));
//query.orderBy(cb.desc(root.get("eventDt").as(Date.class)));
return null;
}
}).size());
return result;
}
}
......@@ -14,7 +14,7 @@ public class BehaviorArchiveVo {
/****
* 审核状态值为:0待审核、1审核通过、2审核不通过、4事件结束、5定时关闭
*/
private Integer auditStatus=0;
private Integer auditStatus;
private String auditInfo;
private Integer pageNum=0;
......@@ -97,7 +97,11 @@ public class BehaviorArchiveVo {
}
public void setPageNum(Integer pageNum) {
this.pageNum = pageNum;
if(pageNum >= 1){
this.pageNum = pageNum-1;
}else{
this.pageNum = pageNum;
}
}
public Integer getPageSize() {
......
package com.viontech.vo;
public class BehaviorStatisticsVo {
String startDt;
String endDt;
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;
}
}
......@@ -27,6 +27,7 @@ public class EventDataVo {
private String subtask_id;
private String source_type;
private List<Integer> eventUnids;
public String getTask_type() {
return task_type;
}
......@@ -170,4 +171,12 @@ public class EventDataVo {
public void setSource_type(String source_type) {
this.source_type = source_type;
}
public List<Integer> getEventUnids() {
return eventUnids;
}
public void setEventUnids(List<Integer> eventUnids) {
this.eventUnids = eventUnids;
}
}
package com.viontech.vo;
public class TimeCloseVo {
private String startDt;
private String endDt;
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;
}
}
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;
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!