Commit f3a5e598 by xmh

<feat> 添加 d_export_data 表,添加相关类文件

<feat> 实现数据异步导出
<feat> 实现数据存储方案页面配置化(配置存储在数据库中)
<feat> 添加获取数据存储方案接口
<feat> 添加 AbnormalQueueRollbackRunner 类,启动服务处理异常队列
1 parent a42e6bb4
Showing 48 changed files with 3366 additions and 173 deletions
......@@ -36,16 +36,14 @@ public class VionConfig {
private List<String> skipAuth;
/** 平台srs的配置 */
private Srs srs;
/** sip28181 对接的配置 */
private Sip sip;
/** 视频云平台对接的配置 */
private VideoCloud videoCloud;
public @Getter
@Setter
static class Image {
/** images 本地存储路径 */
private String path;
/** 图片保存天数 */
private Integer keep;
/** 访问 images 前缀,images 包含录像文件和分析图片 */
private String urlPrefix;
}
......@@ -65,7 +63,7 @@ public class VionConfig {
public @Getter
@Setter
static class Sip {
static class VideoCloud {
private String id;
private String url;
}
......
package com.viontech.fanxing.commons.model;
import com.viontech.fanxing.commons.base.BaseModel;
import java.util.Date;
public class ExportData extends BaseModel {
private Long id;
private Date createTime;
private String name;
private Integer type;
private Long count;
private Integer withPic;
private Integer withVideo;
private String param;
private String path;
private Integer status;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
public Integer getWithPic() {
return withPic;
}
public void setWithPic(Integer withPic) {
this.withPic = withPic;
}
public Integer getWithVideo() {
return withVideo;
}
public void setWithVideo(Integer withVideo) {
this.withVideo = withVideo;
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param == null ? null : param.trim();
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path == null ? null : path.trim();
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}
\ No newline at end of file
package com.viontech.fanxing.commons.model;
import com.viontech.fanxing.commons.base.BaseExample;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ExportDataExample extends BaseExample {
public ExportDataExample() {
super();
tableName = "d_export_data";
tableAlias = "exportData";
ignoreCase = false;
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria(this.tableName,this.ignoreCase);
return criteria;
}
public ColumnContainer createColumns() {
ColumnContainer columnContainer = (ColumnContainer) columnContainerMap.get(this.tableName);
if(columnContainer == null){
columnContainer = new ColumnContainer(this.tableName);
columnContainerMap.put(this.tableName,columnContainer);
}
return (ColumnContainer)columnContainer;
}
public static class Criteria extends GeneratedCriteria {
protected Criteria(String tableName) {
super(tableName);
tableName = "d_export_data";
}
protected Criteria(String tableName, boolean ignoreCase) {
this(tableName);
this.ignoreCase = ignoreCase;
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public void setAllCriteria(List<Criterion> criteria) {
this.criteria = criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value,ignoreCase));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andIdIsNull() {
addCriterion("`exportData`.id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("`exportData`.id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(Long value) {
addCriterion("`exportData`.id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(Long value) {
addCriterion("`exportData`.id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(Long value) {
addCriterion("`exportData`.id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(Long value) {
addCriterion("`exportData`.id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(Long value) {
addCriterion("`exportData`.id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(Long value) {
addCriterion("`exportData`.id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<Long> values) {
addCriterion("`exportData`.id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<Long> values) {
addCriterion("`exportData`.id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(Long value1, Long value2) {
addCriterion("`exportData`.id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(Long value1, Long value2) {
addCriterion("`exportData`.id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() {
addCriterion("`exportData`.create_time is null");
return (Criteria) this;
}
public Criteria andCreateTimeIsNotNull() {
addCriterion("`exportData`.create_time is not null");
return (Criteria) this;
}
public Criteria andCreateTimeEqualTo(Date value) {
addCriterion("`exportData`.create_time =", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotEqualTo(Date value) {
addCriterion("`exportData`.create_time <>", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThan(Date value) {
addCriterion("`exportData`.create_time >", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) {
addCriterion("`exportData`.create_time >=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThan(Date value) {
addCriterion("`exportData`.create_time <", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThanOrEqualTo(Date value) {
addCriterion("`exportData`.create_time <=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeIn(List<Date> values) {
addCriterion("`exportData`.create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Date> values) {
addCriterion("`exportData`.create_time not in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeBetween(Date value1, Date value2) {
addCriterion("`exportData`.create_time between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotBetween(Date value1, Date value2) {
addCriterion("`exportData`.create_time not between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andNameIsNull() {
addCriterion("`exportData`.`name` is null");
return (Criteria) this;
}
public Criteria andNameIsNotNull() {
addCriterion("`exportData`.`name` is not null");
return (Criteria) this;
}
public Criteria andNameEqualTo(String value) {
addCriterion("`exportData`.`name` =", value, "name");
return (Criteria) this;
}
public Criteria andNameNotEqualTo(String value) {
addCriterion("`exportData`.`name` <>", value, "name");
return (Criteria) this;
}
public Criteria andNameGreaterThan(String value) {
addCriterion("`exportData`.`name` >", value, "name");
return (Criteria) this;
}
public Criteria andNameGreaterThanOrEqualTo(String value) {
addCriterion("`exportData`.`name` >=", value, "name");
return (Criteria) this;
}
public Criteria andNameLessThan(String value) {
addCriterion("`exportData`.`name` <", value, "name");
return (Criteria) this;
}
public Criteria andNameLessThanOrEqualTo(String value) {
addCriterion("`exportData`.`name` <=", value, "name");
return (Criteria) this;
}
public Criteria andNameLike(String value) {
addCriterion("`exportData`.`name` like", value, "name");
return (Criteria) this;
}
public Criteria andNameNotLike(String value) {
addCriterion("`exportData`.`name` not like", value, "name");
return (Criteria) this;
}
public Criteria andNameIn(List<String> values) {
addCriterion("`exportData`.`name` in", values, "name");
return (Criteria) this;
}
public Criteria andNameNotIn(List<String> values) {
addCriterion("`exportData`.`name` not in", values, "name");
return (Criteria) this;
}
public Criteria andNameBetween(String value1, String value2) {
addCriterion("`exportData`.`name` between", value1, value2, "name");
return (Criteria) this;
}
public Criteria andNameNotBetween(String value1, String value2) {
addCriterion("`exportData`.`name` not between", value1, value2, "name");
return (Criteria) this;
}
public Criteria andTypeIsNull() {
addCriterion("`exportData`.`type` is null");
return (Criteria) this;
}
public Criteria andTypeIsNotNull() {
addCriterion("`exportData`.`type` is not null");
return (Criteria) this;
}
public Criteria andTypeEqualTo(Integer value) {
addCriterion("`exportData`.`type` =", value, "type");
return (Criteria) this;
}
public Criteria andTypeNotEqualTo(Integer value) {
addCriterion("`exportData`.`type` <>", value, "type");
return (Criteria) this;
}
public Criteria andTypeGreaterThan(Integer value) {
addCriterion("`exportData`.`type` >", value, "type");
return (Criteria) this;
}
public Criteria andTypeGreaterThanOrEqualTo(Integer value) {
addCriterion("`exportData`.`type` >=", value, "type");
return (Criteria) this;
}
public Criteria andTypeLessThan(Integer value) {
addCriterion("`exportData`.`type` <", value, "type");
return (Criteria) this;
}
public Criteria andTypeLessThanOrEqualTo(Integer value) {
addCriterion("`exportData`.`type` <=", value, "type");
return (Criteria) this;
}
public Criteria andTypeIn(List<Integer> values) {
addCriterion("`exportData`.`type` in", values, "type");
return (Criteria) this;
}
public Criteria andTypeNotIn(List<Integer> values) {
addCriterion("`exportData`.`type` not in", values, "type");
return (Criteria) this;
}
public Criteria andTypeBetween(Integer value1, Integer value2) {
addCriterion("`exportData`.`type` between", value1, value2, "type");
return (Criteria) this;
}
public Criteria andTypeNotBetween(Integer value1, Integer value2) {
addCriterion("`exportData`.`type` not between", value1, value2, "type");
return (Criteria) this;
}
public Criteria andCountIsNull() {
addCriterion("`exportData`.`count` is null");
return (Criteria) this;
}
public Criteria andCountIsNotNull() {
addCriterion("`exportData`.`count` is not null");
return (Criteria) this;
}
public Criteria andCountEqualTo(Long value) {
addCriterion("`exportData`.`count` =", value, "count");
return (Criteria) this;
}
public Criteria andCountNotEqualTo(Long value) {
addCriterion("`exportData`.`count` <>", value, "count");
return (Criteria) this;
}
public Criteria andCountGreaterThan(Long value) {
addCriterion("`exportData`.`count` >", value, "count");
return (Criteria) this;
}
public Criteria andCountGreaterThanOrEqualTo(Long value) {
addCriterion("`exportData`.`count` >=", value, "count");
return (Criteria) this;
}
public Criteria andCountLessThan(Long value) {
addCriterion("`exportData`.`count` <", value, "count");
return (Criteria) this;
}
public Criteria andCountLessThanOrEqualTo(Long value) {
addCriterion("`exportData`.`count` <=", value, "count");
return (Criteria) this;
}
public Criteria andCountIn(List<Long> values) {
addCriterion("`exportData`.`count` in", values, "count");
return (Criteria) this;
}
public Criteria andCountNotIn(List<Long> values) {
addCriterion("`exportData`.`count` not in", values, "count");
return (Criteria) this;
}
public Criteria andCountBetween(Long value1, Long value2) {
addCriterion("`exportData`.`count` between", value1, value2, "count");
return (Criteria) this;
}
public Criteria andCountNotBetween(Long value1, Long value2) {
addCriterion("`exportData`.`count` not between", value1, value2, "count");
return (Criteria) this;
}
public Criteria andWithPicIsNull() {
addCriterion("`exportData`.with_pic is null");
return (Criteria) this;
}
public Criteria andWithPicIsNotNull() {
addCriterion("`exportData`.with_pic is not null");
return (Criteria) this;
}
public Criteria andWithPicEqualTo(Integer value) {
addCriterion("`exportData`.with_pic =", value, "withPic");
return (Criteria) this;
}
public Criteria andWithPicNotEqualTo(Integer value) {
addCriterion("`exportData`.with_pic <>", value, "withPic");
return (Criteria) this;
}
public Criteria andWithPicGreaterThan(Integer value) {
addCriterion("`exportData`.with_pic >", value, "withPic");
return (Criteria) this;
}
public Criteria andWithPicGreaterThanOrEqualTo(Integer value) {
addCriterion("`exportData`.with_pic >=", value, "withPic");
return (Criteria) this;
}
public Criteria andWithPicLessThan(Integer value) {
addCriterion("`exportData`.with_pic <", value, "withPic");
return (Criteria) this;
}
public Criteria andWithPicLessThanOrEqualTo(Integer value) {
addCriterion("`exportData`.with_pic <=", value, "withPic");
return (Criteria) this;
}
public Criteria andWithPicIn(List<Integer> values) {
addCriterion("`exportData`.with_pic in", values, "withPic");
return (Criteria) this;
}
public Criteria andWithPicNotIn(List<Integer> values) {
addCriterion("`exportData`.with_pic not in", values, "withPic");
return (Criteria) this;
}
public Criteria andWithPicBetween(Integer value1, Integer value2) {
addCriterion("`exportData`.with_pic between", value1, value2, "withPic");
return (Criteria) this;
}
public Criteria andWithPicNotBetween(Integer value1, Integer value2) {
addCriterion("`exportData`.with_pic not between", value1, value2, "withPic");
return (Criteria) this;
}
public Criteria andWithVideoIsNull() {
addCriterion("`exportData`.with_video is null");
return (Criteria) this;
}
public Criteria andWithVideoIsNotNull() {
addCriterion("`exportData`.with_video is not null");
return (Criteria) this;
}
public Criteria andWithVideoEqualTo(Integer value) {
addCriterion("`exportData`.with_video =", value, "withVideo");
return (Criteria) this;
}
public Criteria andWithVideoNotEqualTo(Integer value) {
addCriterion("`exportData`.with_video <>", value, "withVideo");
return (Criteria) this;
}
public Criteria andWithVideoGreaterThan(Integer value) {
addCriterion("`exportData`.with_video >", value, "withVideo");
return (Criteria) this;
}
public Criteria andWithVideoGreaterThanOrEqualTo(Integer value) {
addCriterion("`exportData`.with_video >=", value, "withVideo");
return (Criteria) this;
}
public Criteria andWithVideoLessThan(Integer value) {
addCriterion("`exportData`.with_video <", value, "withVideo");
return (Criteria) this;
}
public Criteria andWithVideoLessThanOrEqualTo(Integer value) {
addCriterion("`exportData`.with_video <=", value, "withVideo");
return (Criteria) this;
}
public Criteria andWithVideoIn(List<Integer> values) {
addCriterion("`exportData`.with_video in", values, "withVideo");
return (Criteria) this;
}
public Criteria andWithVideoNotIn(List<Integer> values) {
addCriterion("`exportData`.with_video not in", values, "withVideo");
return (Criteria) this;
}
public Criteria andWithVideoBetween(Integer value1, Integer value2) {
addCriterion("`exportData`.with_video between", value1, value2, "withVideo");
return (Criteria) this;
}
public Criteria andWithVideoNotBetween(Integer value1, Integer value2) {
addCriterion("`exportData`.with_video not between", value1, value2, "withVideo");
return (Criteria) this;
}
public Criteria andParamIsNull() {
addCriterion("`exportData`.param is null");
return (Criteria) this;
}
public Criteria andParamIsNotNull() {
addCriterion("`exportData`.param is not null");
return (Criteria) this;
}
public Criteria andParamEqualTo(String value) {
addCriterion("`exportData`.param =", value, "param");
return (Criteria) this;
}
public Criteria andParamNotEqualTo(String value) {
addCriterion("`exportData`.param <>", value, "param");
return (Criteria) this;
}
public Criteria andParamGreaterThan(String value) {
addCriterion("`exportData`.param >", value, "param");
return (Criteria) this;
}
public Criteria andParamGreaterThanOrEqualTo(String value) {
addCriterion("`exportData`.param >=", value, "param");
return (Criteria) this;
}
public Criteria andParamLessThan(String value) {
addCriterion("`exportData`.param <", value, "param");
return (Criteria) this;
}
public Criteria andParamLessThanOrEqualTo(String value) {
addCriterion("`exportData`.param <=", value, "param");
return (Criteria) this;
}
public Criteria andParamLike(String value) {
addCriterion("`exportData`.param like", value, "param");
return (Criteria) this;
}
public Criteria andParamNotLike(String value) {
addCriterion("`exportData`.param not like", value, "param");
return (Criteria) this;
}
public Criteria andParamIn(List<String> values) {
addCriterion("`exportData`.param in", values, "param");
return (Criteria) this;
}
public Criteria andParamNotIn(List<String> values) {
addCriterion("`exportData`.param not in", values, "param");
return (Criteria) this;
}
public Criteria andParamBetween(String value1, String value2) {
addCriterion("`exportData`.param between", value1, value2, "param");
return (Criteria) this;
}
public Criteria andParamNotBetween(String value1, String value2) {
addCriterion("`exportData`.param not between", value1, value2, "param");
return (Criteria) this;
}
public Criteria andPathIsNull() {
addCriterion("`exportData`.`path` is null");
return (Criteria) this;
}
public Criteria andPathIsNotNull() {
addCriterion("`exportData`.`path` is not null");
return (Criteria) this;
}
public Criteria andPathEqualTo(String value) {
addCriterion("`exportData`.`path` =", value, "path");
return (Criteria) this;
}
public Criteria andPathNotEqualTo(String value) {
addCriterion("`exportData`.`path` <>", value, "path");
return (Criteria) this;
}
public Criteria andPathGreaterThan(String value) {
addCriterion("`exportData`.`path` >", value, "path");
return (Criteria) this;
}
public Criteria andPathGreaterThanOrEqualTo(String value) {
addCriterion("`exportData`.`path` >=", value, "path");
return (Criteria) this;
}
public Criteria andPathLessThan(String value) {
addCriterion("`exportData`.`path` <", value, "path");
return (Criteria) this;
}
public Criteria andPathLessThanOrEqualTo(String value) {
addCriterion("`exportData`.`path` <=", value, "path");
return (Criteria) this;
}
public Criteria andPathLike(String value) {
addCriterion("`exportData`.`path` like", value, "path");
return (Criteria) this;
}
public Criteria andPathNotLike(String value) {
addCriterion("`exportData`.`path` not like", value, "path");
return (Criteria) this;
}
public Criteria andPathIn(List<String> values) {
addCriterion("`exportData`.`path` in", values, "path");
return (Criteria) this;
}
public Criteria andPathNotIn(List<String> values) {
addCriterion("`exportData`.`path` not in", values, "path");
return (Criteria) this;
}
public Criteria andPathBetween(String value1, String value2) {
addCriterion("`exportData`.`path` between", value1, value2, "path");
return (Criteria) this;
}
public Criteria andPathNotBetween(String value1, String value2) {
addCriterion("`exportData`.`path` not between", value1, value2, "path");
return (Criteria) this;
}
public Criteria andStatusIsNull() {
addCriterion("`exportData`.`status` is null");
return (Criteria) this;
}
public Criteria andStatusIsNotNull() {
addCriterion("`exportData`.`status` is not null");
return (Criteria) this;
}
public Criteria andStatusEqualTo(Integer value) {
addCriterion("`exportData`.`status` =", value, "status");
return (Criteria) this;
}
public Criteria andStatusNotEqualTo(Integer value) {
addCriterion("`exportData`.`status` <>", value, "status");
return (Criteria) this;
}
public Criteria andStatusGreaterThan(Integer value) {
addCriterion("`exportData`.`status` >", value, "status");
return (Criteria) this;
}
public Criteria andStatusGreaterThanOrEqualTo(Integer value) {
addCriterion("`exportData`.`status` >=", value, "status");
return (Criteria) this;
}
public Criteria andStatusLessThan(Integer value) {
addCriterion("`exportData`.`status` <", value, "status");
return (Criteria) this;
}
public Criteria andStatusLessThanOrEqualTo(Integer value) {
addCriterion("`exportData`.`status` <=", value, "status");
return (Criteria) this;
}
public Criteria andStatusIn(List<Integer> values) {
addCriterion("`exportData`.`status` in", values, "status");
return (Criteria) this;
}
public Criteria andStatusNotIn(List<Integer> values) {
addCriterion("`exportData`.`status` not in", values, "status");
return (Criteria) this;
}
public Criteria andStatusBetween(Integer value1, Integer value2) {
addCriterion("`exportData`.`status` between", value1, value2, "status");
return (Criteria) this;
}
public Criteria andStatusNotBetween(Integer value1, Integer value2) {
addCriterion("`exportData`.`status` not between", value1, value2, "status");
return (Criteria) this;
}
}
public static class ColumnContainer extends ColumnContainerBase {
protected ColumnContainer(String tableName) {
super(tableName);
}
public ColumnContainer hasIdColumn() {
addColumnStr("`exportData`.id as exportData_id ");
return (ColumnContainer) this;
}
public ColumnContainer hasCreateTimeColumn() {
addColumnStr("`exportData`.create_time as exportData_create_time ");
return (ColumnContainer) this;
}
public ColumnContainer hasNameColumn() {
addColumnStr("`exportData`.`name` as `exportData_name` ");
return (ColumnContainer) this;
}
public ColumnContainer hasTypeColumn() {
addColumnStr("`exportData`.`type` as `exportData_type` ");
return (ColumnContainer) this;
}
public ColumnContainer hasCountColumn() {
addColumnStr("`exportData`.`count` as `exportData_count` ");
return (ColumnContainer) this;
}
public ColumnContainer hasWithPicColumn() {
addColumnStr("`exportData`.with_pic as exportData_with_pic ");
return (ColumnContainer) this;
}
public ColumnContainer hasWithVideoColumn() {
addColumnStr("`exportData`.with_video as exportData_with_video ");
return (ColumnContainer) this;
}
public ColumnContainer hasParamColumn() {
addColumnStr("`exportData`.param as exportData_param ");
return (ColumnContainer) this;
}
public ColumnContainer hasPathColumn() {
addColumnStr("`exportData`.`path` as `exportData_path` ");
return (ColumnContainer) this;
}
public ColumnContainer hasStatusColumn() {
addColumnStr("`exportData`.`status` as `exportData_status` ");
return (ColumnContainer) this;
}
}
}
\ No newline at end of file
package com.viontech.fanxing.commons.model.main;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/29
*/
@Getter
@Setter
public class ImageKeepConfig {
/** 存储类型,1按天存储,2按磁盘空间存储 */
private Integer type = 1;
/** 保留多少天 */
private Integer keep = 7;
/** 磁盘空间比率 */
private Integer rate = 75;
}
......@@ -50,6 +50,19 @@ public class RedisService {
return lock;
}
public RLock getLockMust(String lockName, Integer waitTime, Integer leaseTime, TimeUnit timeUnit) {
RLock lock = redissonClient.getLock(lockName);
boolean isLock = false;
while (!isLock) {
try {
isLock = lock.tryLock(waitTime, leaseTime, timeUnit);
Thread.sleep(50L);
} catch (Exception ignore) {
}
}
return lock;
}
public RedissonClient getClient() {
return redissonClient;
}
......
package com.viontech.fanxing.commons.vo;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.vobase.ExportDataVoBase;
public class ExportDataVo extends ExportDataVoBase {
public ExportDataVo() {
super();
}
public ExportDataVo(ExportData exportData) {
super(exportData);
}
}
\ No newline at end of file
package com.viontech.fanxing.commons.vobase;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.viontech.fanxing.commons.base.VoInterface;
import com.viontech.fanxing.commons.model.ExportData;
import java.util.ArrayList;
import java.util.Date;
public class ExportDataVoBase extends ExportData implements VoInterface<ExportData> {
private ExportData exportData;
@JsonIgnore
private ArrayList<Long> id_arr;
@JsonIgnore
private Long id_gt;
@JsonIgnore
private Long id_lt;
@JsonIgnore
private Long id_gte;
@JsonIgnore
private Long id_lte;
@JsonIgnore
private ArrayList<Date> createTime_arr;
@JsonIgnore
private Date createTime_gt;
@JsonIgnore
private Date createTime_lt;
@JsonIgnore
private Date createTime_gte;
@JsonIgnore
private Date createTime_lte;
@JsonIgnore
private Boolean name_null;
@JsonIgnore
private ArrayList<String> name_arr;
@JsonIgnore
private String name_like;
@JsonIgnore
private ArrayList<Integer> type_arr;
@JsonIgnore
private Integer type_gt;
@JsonIgnore
private Integer type_lt;
@JsonIgnore
private Integer type_gte;
@JsonIgnore
private Integer type_lte;
@JsonIgnore
private ArrayList<Long> count_arr;
@JsonIgnore
private Long count_gt;
@JsonIgnore
private Long count_lt;
@JsonIgnore
private Long count_gte;
@JsonIgnore
private Long count_lte;
@JsonIgnore
private ArrayList<Integer> withPic_arr;
@JsonIgnore
private Integer withPic_gt;
@JsonIgnore
private Integer withPic_lt;
@JsonIgnore
private Integer withPic_gte;
@JsonIgnore
private Integer withPic_lte;
@JsonIgnore
private ArrayList<Integer> withVideo_arr;
@JsonIgnore
private Integer withVideo_gt;
@JsonIgnore
private Integer withVideo_lt;
@JsonIgnore
private Integer withVideo_gte;
@JsonIgnore
private Integer withVideo_lte;
@JsonIgnore
private ArrayList<String> param_arr;
@JsonIgnore
private String param_like;
@JsonIgnore
private ArrayList<String> path_arr;
@JsonIgnore
private String path_like;
@JsonIgnore
private ArrayList<Integer> status_arr;
@JsonIgnore
private Integer status_gt;
@JsonIgnore
private Integer status_lt;
@JsonIgnore
private Integer status_gte;
@JsonIgnore
private Integer status_lte;
public ExportDataVoBase() {
this(null);
}
public ExportDataVoBase(ExportData exportData) {
if(exportData == null) {
exportData = new ExportData();
}
this.exportData = exportData;
}
@JsonIgnore
public ExportData getModel() {
return exportData;
}
public void setModel(ExportData exportData) {
this.exportData = exportData;
}
public ArrayList<Long> getId_arr() {
return id_arr;
}
public void setId_arr(ArrayList<Long> id_arr) {
this.id_arr = id_arr;
}
public Long getId_gt() {
return id_gt;
}
public void setId_gt(Long id_gt) {
this.id_gt = id_gt;
}
public Long getId_lt() {
return id_lt;
}
public void setId_lt(Long id_lt) {
this.id_lt = id_lt;
}
public Long getId_gte() {
return id_gte;
}
public void setId_gte(Long id_gte) {
this.id_gte = id_gte;
}
public Long getId_lte() {
return id_lte;
}
public void setId_lte(Long id_lte) {
this.id_lte = id_lte;
}
public Long getId() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getId();
}
public void setId(Long id) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setId(id);
}
public ArrayList<Date> getCreateTime_arr() {
return createTime_arr;
}
public void setCreateTime_arr(ArrayList<Date> createTime_arr) {
this.createTime_arr = createTime_arr;
}
public Date getCreateTime_gt() {
return createTime_gt;
}
public void setCreateTime_gt(Date createTime_gt) {
this.createTime_gt = createTime_gt;
}
public Date getCreateTime_lt() {
return createTime_lt;
}
public void setCreateTime_lt(Date createTime_lt) {
this.createTime_lt = createTime_lt;
}
public Date getCreateTime_gte() {
return createTime_gte;
}
public void setCreateTime_gte(Date createTime_gte) {
this.createTime_gte = createTime_gte;
}
public Date getCreateTime_lte() {
return createTime_lte;
}
public void setCreateTime_lte(Date createTime_lte) {
this.createTime_lte = createTime_lte;
}
public Date getCreateTime() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getCreateTime();
}
public void setCreateTime(Date createTime) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setCreateTime(createTime);
}
public Boolean getName_null() {
return name_null;
}
public void setName_null(Boolean name_null) {
this.name_null = name_null;
}
public ArrayList<String> getName_arr() {
return name_arr;
}
public void setName_arr(ArrayList<String> name_arr) {
this.name_arr = name_arr;
}
public String getName_like() {
return name_like;
}
public void setName_like(String name_like) {
this.name_like = name_like;
}
public String getName() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getName();
}
public void setName(String name) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setName(name);
}
public ArrayList<Integer> getType_arr() {
return type_arr;
}
public void setType_arr(ArrayList<Integer> type_arr) {
this.type_arr = type_arr;
}
public Integer getType_gt() {
return type_gt;
}
public void setType_gt(Integer type_gt) {
this.type_gt = type_gt;
}
public Integer getType_lt() {
return type_lt;
}
public void setType_lt(Integer type_lt) {
this.type_lt = type_lt;
}
public Integer getType_gte() {
return type_gte;
}
public void setType_gte(Integer type_gte) {
this.type_gte = type_gte;
}
public Integer getType_lte() {
return type_lte;
}
public void setType_lte(Integer type_lte) {
this.type_lte = type_lte;
}
public Integer getType() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getType();
}
public void setType(Integer type) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setType(type);
}
public ArrayList<Long> getCount_arr() {
return count_arr;
}
public void setCount_arr(ArrayList<Long> count_arr) {
this.count_arr = count_arr;
}
public Long getCount_gt() {
return count_gt;
}
public void setCount_gt(Long count_gt) {
this.count_gt = count_gt;
}
public Long getCount_lt() {
return count_lt;
}
public void setCount_lt(Long count_lt) {
this.count_lt = count_lt;
}
public Long getCount_gte() {
return count_gte;
}
public void setCount_gte(Long count_gte) {
this.count_gte = count_gte;
}
public Long getCount_lte() {
return count_lte;
}
public void setCount_lte(Long count_lte) {
this.count_lte = count_lte;
}
public Long getCount() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getCount();
}
public void setCount(Long count) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setCount(count);
}
public ArrayList<Integer> getWithPic_arr() {
return withPic_arr;
}
public void setWithPic_arr(ArrayList<Integer> withPic_arr) {
this.withPic_arr = withPic_arr;
}
public Integer getWithPic_gt() {
return withPic_gt;
}
public void setWithPic_gt(Integer withPic_gt) {
this.withPic_gt = withPic_gt;
}
public Integer getWithPic_lt() {
return withPic_lt;
}
public void setWithPic_lt(Integer withPic_lt) {
this.withPic_lt = withPic_lt;
}
public Integer getWithPic_gte() {
return withPic_gte;
}
public void setWithPic_gte(Integer withPic_gte) {
this.withPic_gte = withPic_gte;
}
public Integer getWithPic_lte() {
return withPic_lte;
}
public void setWithPic_lte(Integer withPic_lte) {
this.withPic_lte = withPic_lte;
}
public Integer getWithPic() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getWithPic();
}
public void setWithPic(Integer withPic) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setWithPic(withPic);
}
public ArrayList<Integer> getWithVideo_arr() {
return withVideo_arr;
}
public void setWithVideo_arr(ArrayList<Integer> withVideo_arr) {
this.withVideo_arr = withVideo_arr;
}
public Integer getWithVideo_gt() {
return withVideo_gt;
}
public void setWithVideo_gt(Integer withVideo_gt) {
this.withVideo_gt = withVideo_gt;
}
public Integer getWithVideo_lt() {
return withVideo_lt;
}
public void setWithVideo_lt(Integer withVideo_lt) {
this.withVideo_lt = withVideo_lt;
}
public Integer getWithVideo_gte() {
return withVideo_gte;
}
public void setWithVideo_gte(Integer withVideo_gte) {
this.withVideo_gte = withVideo_gte;
}
public Integer getWithVideo_lte() {
return withVideo_lte;
}
public void setWithVideo_lte(Integer withVideo_lte) {
this.withVideo_lte = withVideo_lte;
}
public Integer getWithVideo() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getWithVideo();
}
public void setWithVideo(Integer withVideo) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setWithVideo(withVideo);
}
public ArrayList<String> getParam_arr() {
return param_arr;
}
public void setParam_arr(ArrayList<String> param_arr) {
this.param_arr = param_arr;
}
public String getParam_like() {
return param_like;
}
public void setParam_like(String param_like) {
this.param_like = param_like;
}
public String getParam() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getParam();
}
public void setParam(String param) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setParam(param);
}
public ArrayList<String> getPath_arr() {
return path_arr;
}
public void setPath_arr(ArrayList<String> path_arr) {
this.path_arr = path_arr;
}
public String getPath_like() {
return path_like;
}
public void setPath_like(String path_like) {
this.path_like = path_like;
}
public String getPath() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getPath();
}
public void setPath(String path) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setPath(path);
}
public ArrayList<Integer> getStatus_arr() {
return status_arr;
}
public void setStatus_arr(ArrayList<Integer> status_arr) {
this.status_arr = status_arr;
}
public Integer getStatus_gt() {
return status_gt;
}
public void setStatus_gt(Integer status_gt) {
this.status_gt = status_gt;
}
public Integer getStatus_lt() {
return status_lt;
}
public void setStatus_lt(Integer status_lt) {
this.status_lt = status_lt;
}
public Integer getStatus_gte() {
return status_gte;
}
public void setStatus_gte(Integer status_gte) {
this.status_gte = status_gte;
}
public Integer getStatus_lte() {
return status_lte;
}
public void setStatus_lte(Integer status_lte) {
this.status_lte = status_lte;
}
public Integer getStatus() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getStatus();
}
public void setStatus(Integer status) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setStatus(status);
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.viontech.fanxing.forward.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
......@@ -14,6 +15,7 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter;
public class ForwardWebConfig {
@Bean
@Profile("!test")
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
......
package com.viontech.fanxing.forward.feign;
import com.viontech.fanxing.commons.model.Forward;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
......@@ -28,4 +29,7 @@ public interface OpsFeignClient {
@PostMapping("/forwards/{id}")
JsonMessageUtil.JsonMessage<Forward> updateById(@PathVariable("id") Long id, @RequestBody Forward forward);
@GetMapping("/contents/imageKeepConfig")
JsonMessageUtil.JsonMessage<ImageKeepConfig> getImageKeepConfig();
}
package com.viontech.fanxing.forward.runner;
import com.viontech.fanxing.commons.constant.RedisKeys;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RKeys;
import org.redisson.api.RQueue;
import org.redisson.api.RedissonClient;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* .
*
* @author 谢明辉
* @date 2021/11/29
*/
@Component
@Order(1)
@Profile("!test")
@Slf4j
public class AbnormalQueueRollbackRunner implements CommandLineRunner {
@Resource
private RedissonClient redissonClient;
@Override
public void run(String... args) throws Exception {
rollback(RedisKeys.FORWARD_TRAFFIC_QUEUE);
rollback(RedisKeys.FORWARD_FLOW_QUEUE);
rollback(RedisKeys.FORWARD_BEHAVIOR_QUEUE);
}
private void rollback(String queueName) {
log.info("队列处理开始:[{}]", queueName);
RKeys keys = redissonClient.getKeys();
Iterable<String> queueNames = keys.getKeysByPattern(queueName + ":workQueue:*");
for (String name : queueNames) {
RQueue<Object> queue = redissonClient.getQueue(name);
int size = queue.size();
log.info("处理队列[{}],数据量:[{}]", name, size);
for (int i = 0; i < size; i++) {
queue.pollLastAndOfferFirstTo(queueName);
}
}
log.info("队列处理完成:[{}]", queueName);
}
}
package com.viontech.fanxing.forward.runner;
import com.viontech.fanxing.commons.config.VionConfig;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import com.viontech.fanxing.forward.feign.OpsFeignClient;
import com.viontech.keliu.util.DateUtil;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.File;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/**
* .
......@@ -24,33 +31,72 @@ import java.time.format.DateTimeFormatter;
public class PicKeepRunner {
@Resource
private OpsFeignClient opsFeignClient;
@Resource
private JdbcTemplate jdbcTemplate;
@Resource
private VionConfig vionConfig;
@Scheduled(cron = "0 0 08 * * ?")
@Scheduled(cron = "0 1 8 * * ?")
public void run() {
if (vionConfig.getImage().getKeep() == -1) {
return;
JsonMessageUtil.JsonMessage<ImageKeepConfig> imageKeepConfigData = opsFeignClient.getImageKeepConfig();
ImageKeepConfig config = imageKeepConfigData.getData();
// type 为 1, 按天数保留
if (config.getType() == 1) {
keep1(config.getKeep());
}
// type 为 2, 按磁盘空间比例保留
else if (config.getType() == 2) {
}
}
private void keep1(int day) {
Date date = DateUtil.addDays(new Date(), -day);
String yyyyMMdd = DateUtil.format("yyyyMMdd", date);
String sql = "select partition_name,CAST(FROM_UNIXTIME(partition_description) as date) as date from information_schema.partitions where table_name = ? and partition_name< ?";
Set<String> yyyyMMddSet = new HashSet<>();
// 五张表都要处理
for (String tableName : new String[]{"d_traffic", "d_flow_event", "d_behavior", "d_flow_data", "d_traffic_face"}) {
ArrayList<String> partitions = new ArrayList<>();
String minPartitionName = tableName + yyyyMMdd;
// 查找要删除的数据日期和分区名称
jdbcTemplate.query(sql, rs -> {
String name = rs.getString("partition_name");
partitions.add(name);
java.sql.Date date1 = rs.getDate("date");
yyyyMMddSet.add(DateUtil.format("yyyyMMdd", date1));
}, tableName, minPartitionName);
// 删除分区
for (String partitionNeedDel : partitions) {
jdbcTemplate.update("ALTER TABLE " + tableName + " drop partition " + partitionNeedDel);
log.info("删除数据分区:[{}]", partitionNeedDel);
}
}
// 删除文件
for (String dirName : yyyyMMddSet) {
dropDir(dirName);
}
}
private void dropDir(String dirName) {
try {
long nowDay = LocalDate.now().toEpochDay();
DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
File baseDir = new File(vionConfig.getImage().getPath());
File[] files = baseDir.listFiles((dir, name) -> name.matches("[1-9]\\d{7}"));
for (File file : files) {
String name = file.getName();
LocalDate day = LocalDate.parse(name, yyyyMMdd);
long l = day.toEpochDay();
if (nowDay - l > vionConfig.getImage().getKeep()) {
log.info("删除文件夹:{}", name);
FileUtils.deleteDirectory(file);
if (files != null) {
for (File file : files) {
String name = file.getName();
if (dirName.equals(name)) {
FileUtils.deleteDirectory(file);
log.info("删除文件夹:{}", name);
}
}
}
} catch (Exception e) {
log.error("", e);
log.error("目录删除失败", e);
}
}
}
......
......@@ -8,6 +8,7 @@ import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
......@@ -21,6 +22,7 @@ import javax.annotation.Resource;
@Component
@Slf4j
@Profile("!test")
@Order(10)
public class PicRealTimeRunner implements CommandLineRunner {
@Resource
......
......@@ -57,7 +57,6 @@ pagehelper:
vion:
image:
path: G:\data
keep: 1
enable-forward: true
redisson:
path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml
......
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.constant.RedisKeys;
import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.forward.feign.TaskFeignClient;
import com.viontech.fanxing.forward.runner.PicKeepRunner;
import com.viontech.keliu.util.JsonMessageUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -33,6 +34,8 @@ public class Test0 {
private RedissonClient redissonClient;
@Resource
private TaskFeignClient taskFeignClient;
@Resource
private PicKeepRunner picKeepRunner;
@Test
public void test() {
......@@ -47,4 +50,9 @@ public class Test0 {
System.out.println(JSON.toJSONString(allTask));
}
@Test
public void picKeepRunner() {
picKeepRunner.run();
}
}
......@@ -3,13 +3,12 @@ package com.viontech.fanxing.ops.controller.web;
import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.model.ContentExample;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import com.viontech.fanxing.commons.vo.ContentVo;
import com.viontech.fanxing.ops.controller.base.ContentBaseController;
import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -43,4 +42,10 @@ public class ContentController extends ContentBaseController {
return getSuccessJsonMsg(MESSAGE_PAGE_SUCCESS, pageInfo);
}
}
@GetMapping("/imageKeepConfig")
@ResponseBody
public JsonMessageUtil.JsonMessage<ImageKeepConfig> selectImageKeepConfig() {
return JsonMessageUtil.getSuccessJsonMsg(contentService.selectImageKeepConfig());
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import com.viontech.fanxing.commons.vo.LogVo;
import com.viontech.fanxing.ops.controller.base.LogBaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@RequestMapping("/logs")
......@@ -16,4 +17,11 @@ public class LogController extends LogBaseController {
LogExample logExample = (LogExample) super.getExample(logVo, type);
return logExample;
}
@Override
public Object page(LogVo logVo, @RequestParam(value = "page", defaultValue = "-1") int page, @RequestParam(value = "pageSize", defaultValue = "100") int pageSize
, String sortName, String sortOrder) {
return super.page(logVo, page, pageSize, "date_time", "desc");
}
}
\ No newline at end of file
......@@ -3,10 +3,13 @@ package com.viontech.fanxing.ops.service.adapter;
import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.Content;
import com.viontech.fanxing.commons.model.ContentExample;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import java.util.List;
public interface ContentService extends BaseService<Content> {
List<Content> selectByExampleWithBlob(ContentExample contentExample);
ImageKeepConfig selectImageKeepConfig();
}
\ No newline at end of file
......@@ -282,22 +282,22 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
@Override
public Object pullFromVideoCloud() {
Assert.notNull(vionConfig.getSip(), "视频云配置为空");
Assert.hasText(vionConfig.getSip().getId(), "视频云对接id为空");
Assert.hasText(vionConfig.getSip().getUrl(), "视频云对接地址为空");
Assert.notNull(vionConfig.getVideoCloud(), "视频云配置为空");
Assert.hasText(vionConfig.getVideoCloud().getId(), "视频云对接id为空");
Assert.hasText(vionConfig.getVideoCloud().getUrl(), "视频云对接地址为空");
JSONObject response = WebClient.create(vionConfig.getSip().getUrl())
JSONObject response = WebClient.create(vionConfig.getVideoCloud().getUrl())
.get()
.uri(uriBuilder -> uriBuilder.path("/api/device/getAllDeviceList").queryParam("userid", vionConfig.getSip().getId()).build())
.uri(uriBuilder -> uriBuilder.path("/api/device/getAllDeviceList").queryParam("userid", vionConfig.getVideoCloud().getId()).build())
.retrieve()
.bodyToMono(JSONObject.class)
.block(Duration.ofSeconds(10));
DictCode sip28181 = dictcodeService.getOrCreateOrgCode("video_cloud", "视频云");
DictCode videoCloud = dictcodeService.getOrCreateOrgCode("video_cloud", "视频云");
if (response != null && response.containsKey("data")) {
JSONArray data = response.getJSONArray("data");
if (data.size() > 0) {
analyseVideoCloud(data, sip28181, sip28181.getCateId());
analyseVideoCloud(data, videoCloud, videoCloud.getCateId());
}
}
return null;
......
package com.viontech.fanxing.ops.service.impl;
import com.viontech.fanxing.commons.base.BaseExample;
import com.alibaba.fastjson.JSON;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.model.Content;
import com.viontech.fanxing.commons.model.ContentExample;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import com.viontech.fanxing.ops.mapper.ContentMapper;
import com.viontech.fanxing.ops.service.adapter.ContentService;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
......@@ -27,4 +28,17 @@ public class ContentServiceImpl extends BaseServiceImpl<Content> implements Cont
public List<Content> selectByExampleWithBlob(ContentExample contentExample) {
return contentMapper.selectByExampleWithBLOBs(contentExample);
}
@Override
public ImageKeepConfig selectImageKeepConfig() {
ContentExample contentExample = new ContentExample();
contentExample.createCriteria().andTypeEqualTo("platformConfig").andNameEqualTo("imageKeepConfig");
List<Content> contents = contentMapper.selectByExampleWithBLOBs(contentExample);
if (contents.size() > 0) {
String content = contents.get(0).getContent();
return JSON.parseObject(content, ImageKeepConfig.class);
} else {
return new ImageKeepConfig();
}
}
}
\ No newline at end of file
......@@ -57,10 +57,10 @@ vion:
url-prefix: http://192.168.9.233:30007/images
redisson:
path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml
sip:
id: 800d8652-d1f5-442e-9f34-4d70a6d000a8
url: http://192.168.9.233:8888
supported-video-formats:
- mp4
- avi
- h264
\ No newline at end of file
- h264
video-cloud:
id: 800d8652-d1f5-442e-9f34-4d70a6d000a8
url: http://192.168.9.233:8888
\ No newline at end of file
......@@ -29,6 +29,16 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-poi</artifactId>
<version>5.7.16</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
<build>
......
package com.viontech.fanxing.query.controller.base;
import com.viontech.fanxing.commons.base.BaseController;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.model.ExportDataExample;
import com.viontech.fanxing.commons.vo.ExportDataVo;
import com.viontech.fanxing.query.mapper.ExportDataMapper;
import com.viontech.fanxing.query.service.adapter.ExportDataService;
import javax.annotation.Resource;
public abstract class ExportDataBaseController extends BaseController<ExportData, ExportDataVo> {
@Resource
protected ExportDataService exportDataService;
@Override
protected BaseExample getExample(ExportDataVo exportDataVo, int type) {
ExportDataExample exportDataExample = new ExportDataExample();
ExportDataExample.Criteria criteria = exportDataExample.createCriteria();
if(exportDataVo.getId() != null) {
criteria.andIdEqualTo(exportDataVo.getId());
}
if(exportDataVo.getId_arr() != null) {
criteria.andIdIn(exportDataVo.getId_arr());
}
if(exportDataVo.getId_gt() != null) {
criteria.andIdGreaterThan(exportDataVo.getId_gt());
}
if(exportDataVo.getId_lt() != null) {
criteria.andIdLessThan(exportDataVo.getId_lt());
}
if(exportDataVo.getId_gte() != null) {
criteria.andIdGreaterThanOrEqualTo(exportDataVo.getId_gte());
}
if(exportDataVo.getId_lte() != null) {
criteria.andIdLessThanOrEqualTo(exportDataVo.getId_lte());
}
if(exportDataVo.getCreateTime() != null) {
criteria.andCreateTimeEqualTo(exportDataVo.getCreateTime());
}
if(exportDataVo.getCreateTime_arr() != null) {
criteria.andCreateTimeIn(exportDataVo.getCreateTime_arr());
}
if(exportDataVo.getCreateTime_gt() != null) {
criteria.andCreateTimeGreaterThan(exportDataVo.getCreateTime_gt());
}
if(exportDataVo.getCreateTime_lt() != null) {
criteria.andCreateTimeLessThan(exportDataVo.getCreateTime_lt());
}
if(exportDataVo.getCreateTime_gte() != null) {
criteria.andCreateTimeGreaterThanOrEqualTo(exportDataVo.getCreateTime_gte());
}
if(exportDataVo.getCreateTime_lte() != null) {
criteria.andCreateTimeLessThanOrEqualTo(exportDataVo.getCreateTime_lte());
}
if(exportDataVo.getName() != null) {
criteria.andNameEqualTo(exportDataVo.getName());
}
if(exportDataVo.getName_null() != null) {
if(exportDataVo.getName_null().booleanValue()) {
criteria.andNameIsNull();
} else {
criteria.andNameIsNotNull();
}
}
if(exportDataVo.getName_arr() != null) {
criteria.andNameIn(exportDataVo.getName_arr());
}
if(exportDataVo.getName_like() != null) {
criteria.andNameLike(exportDataVo.getName_like());
}
if(exportDataVo.getType() != null) {
criteria.andTypeEqualTo(exportDataVo.getType());
}
if(exportDataVo.getType_arr() != null) {
criteria.andTypeIn(exportDataVo.getType_arr());
}
if(exportDataVo.getType_gt() != null) {
criteria.andTypeGreaterThan(exportDataVo.getType_gt());
}
if(exportDataVo.getType_lt() != null) {
criteria.andTypeLessThan(exportDataVo.getType_lt());
}
if(exportDataVo.getType_gte() != null) {
criteria.andTypeGreaterThanOrEqualTo(exportDataVo.getType_gte());
}
if(exportDataVo.getType_lte() != null) {
criteria.andTypeLessThanOrEqualTo(exportDataVo.getType_lte());
}
if(exportDataVo.getCount() != null) {
criteria.andCountEqualTo(exportDataVo.getCount());
}
if(exportDataVo.getCount_arr() != null) {
criteria.andCountIn(exportDataVo.getCount_arr());
}
if(exportDataVo.getCount_gt() != null) {
criteria.andCountGreaterThan(exportDataVo.getCount_gt());
}
if(exportDataVo.getCount_lt() != null) {
criteria.andCountLessThan(exportDataVo.getCount_lt());
}
if(exportDataVo.getCount_gte() != null) {
criteria.andCountGreaterThanOrEqualTo(exportDataVo.getCount_gte());
}
if(exportDataVo.getCount_lte() != null) {
criteria.andCountLessThanOrEqualTo(exportDataVo.getCount_lte());
}
if(exportDataVo.getWithPic() != null) {
criteria.andWithPicEqualTo(exportDataVo.getWithPic());
}
if(exportDataVo.getWithPic_arr() != null) {
criteria.andWithPicIn(exportDataVo.getWithPic_arr());
}
if(exportDataVo.getWithPic_gt() != null) {
criteria.andWithPicGreaterThan(exportDataVo.getWithPic_gt());
}
if(exportDataVo.getWithPic_lt() != null) {
criteria.andWithPicLessThan(exportDataVo.getWithPic_lt());
}
if(exportDataVo.getWithPic_gte() != null) {
criteria.andWithPicGreaterThanOrEqualTo(exportDataVo.getWithPic_gte());
}
if(exportDataVo.getWithPic_lte() != null) {
criteria.andWithPicLessThanOrEqualTo(exportDataVo.getWithPic_lte());
}
if(exportDataVo.getWithVideo() != null) {
criteria.andWithVideoEqualTo(exportDataVo.getWithVideo());
}
if(exportDataVo.getWithVideo_arr() != null) {
criteria.andWithVideoIn(exportDataVo.getWithVideo_arr());
}
if(exportDataVo.getWithVideo_gt() != null) {
criteria.andWithVideoGreaterThan(exportDataVo.getWithVideo_gt());
}
if(exportDataVo.getWithVideo_lt() != null) {
criteria.andWithVideoLessThan(exportDataVo.getWithVideo_lt());
}
if(exportDataVo.getWithVideo_gte() != null) {
criteria.andWithVideoGreaterThanOrEqualTo(exportDataVo.getWithVideo_gte());
}
if(exportDataVo.getWithVideo_lte() != null) {
criteria.andWithVideoLessThanOrEqualTo(exportDataVo.getWithVideo_lte());
}
if(exportDataVo.getParam() != null) {
criteria.andParamEqualTo(exportDataVo.getParam());
}
if(exportDataVo.getParam_arr() != null) {
criteria.andParamIn(exportDataVo.getParam_arr());
}
if(exportDataVo.getParam_like() != null) {
criteria.andParamLike(exportDataVo.getParam_like());
}
if(exportDataVo.getPath() != null) {
criteria.andPathEqualTo(exportDataVo.getPath());
}
if(exportDataVo.getPath_arr() != null) {
criteria.andPathIn(exportDataVo.getPath_arr());
}
if(exportDataVo.getPath_like() != null) {
criteria.andPathLike(exportDataVo.getPath_like());
}
if(exportDataVo.getStatus() != null) {
criteria.andStatusEqualTo(exportDataVo.getStatus());
}
if(exportDataVo.getStatus_arr() != null) {
criteria.andStatusIn(exportDataVo.getStatus_arr());
}
if(exportDataVo.getStatus_gt() != null) {
criteria.andStatusGreaterThan(exportDataVo.getStatus_gt());
}
if(exportDataVo.getStatus_lt() != null) {
criteria.andStatusLessThan(exportDataVo.getStatus_lt());
}
if(exportDataVo.getStatus_gte() != null) {
criteria.andStatusGreaterThanOrEqualTo(exportDataVo.getStatus_gte());
}
if(exportDataVo.getStatus_lte() != null) {
criteria.andStatusLessThanOrEqualTo(exportDataVo.getStatus_lte());
}
return exportDataExample;
}
@Override
protected BaseService<ExportData> getService() {
return exportDataService;
}
}
\ No newline at end of file
......@@ -7,13 +7,19 @@ import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.model.BehaviorExample;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.vo.BehaviorVo;
import com.viontech.fanxing.query.controller.base.BehaviorBaseController;
import com.viontech.fanxing.query.model.export.ExportDataTypeEnum;
import com.viontech.fanxing.query.service.adapter.ExportDataService;
import com.viontech.fanxing.query.service.main.OpsClientService;
import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
......@@ -25,6 +31,8 @@ public class BehaviorController extends BehaviorBaseController {
@Resource
private OpsClientService opsClientService;
@Resource
private ExportDataService exportDataService;
@Override
protected BaseExample getExample(BehaviorVo behaviorVo, int type) {
......@@ -33,8 +41,14 @@ public class BehaviorController extends BehaviorBaseController {
return behaviorExample;
}
public BehaviorExample getExample(BehaviorVo behaviorVo) {
return (BehaviorExample) super.getExample(behaviorVo, 4);
}
@Override
public Object page(BehaviorVo behaviorVo, @RequestParam(value = "page", defaultValue = "-1") int page, @RequestParam(value = "pageSize", defaultValue = "100") int pageSize, String sortName, String sortOrder) {
@ResponseBody
public Object page(BehaviorVo behaviorVo, @RequestParam(value = "page", defaultValue = "-1") int page, @RequestParam(value = "pageSize", defaultValue = "100") int pageSize,
@RequestParam(defaultValue = "event_time") String sortName, @RequestParam(defaultValue = "desc") String sortOrder) {
Assert.notNull(behaviorVo.getEventTime_gte(), "起始时间不能为空");
Assert.notNull(behaviorVo.getEventTime_lte(), "结束时间不能为空");
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
......@@ -50,4 +64,22 @@ public class BehaviorController extends BehaviorBaseController {
PageInfo<BehaviorVo> pageInfo = behaviorService.getJsonData(baseExample, page, pageSize);
return getSuccessJsonMsg(MESSAGE_PAGE_SUCCESS, pageInfo);
}
@GetMapping("/export")
@ResponseBody
public Object export(BehaviorVo behaviorVo, @RequestParam String name
, @RequestParam(required = false, defaultValue = "0") Integer withPic, @RequestParam(required = false, defaultValue = "0") Integer withVideo) {
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
simplePropertyPreFilter.getExcludes().add("model");
String param = JSON.toJSONString(behaviorVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE);
ExportData exportData = new ExportData();
exportData.setName(name);
exportData.setParam(param);
exportData.setType(ExportDataTypeEnum.BEHAVIOR.type);
exportData.setWithPic(withPic);
exportData.setWithVideo(withVideo);
exportDataService.insertSelective(exportData);
return JsonMessageUtil.getSuccessJsonMsg();
}
}
\ No newline at end of file
package com.viontech.fanxing.query.controller.web;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.model.ExportDataExample;
import com.viontech.fanxing.commons.vo.ExportDataVo;
import com.viontech.fanxing.query.controller.base.ExportDataBaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/exportDatas")
public class ExportDataController extends ExportDataBaseController {
@Override
protected BaseExample getExample(ExportDataVo exportDataVo, int type) {
ExportDataExample exportDataExample = (ExportDataExample) super.getExample(exportDataVo, type);
return exportDataExample;
}
}
\ No newline at end of file
......@@ -5,6 +5,8 @@ import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.model.FlowEventExample;
import com.viontech.fanxing.commons.vo.FlowEventVo;
import com.viontech.fanxing.query.controller.base.FlowEventBaseController;
......@@ -12,6 +14,8 @@ import com.viontech.fanxing.query.mapper.FlowMapper;
import com.viontech.fanxing.query.model.TrafficFlowDataModel;
import com.viontech.fanxing.query.model.TrafficFlowEventModel;
import com.viontech.fanxing.query.model.TrafficFlowRequestVo;
import com.viontech.fanxing.query.model.export.ExportDataTypeEnum;
import com.viontech.fanxing.query.service.adapter.ExportDataService;
import com.viontech.fanxing.query.service.main.OpsClientService;
import com.viontech.keliu.util.JsonMessageUtil;
import org.apache.commons.lang3.StringUtils;
......@@ -20,6 +24,7 @@ import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
......@@ -34,6 +39,8 @@ public class FlowEventController extends FlowEventBaseController {
private FlowMapper flowMapper;
@Resource
private OpsClientService opsClientService;
@Resource
private ExportDataService exportDataService;
@Override
protected BaseExample getExample(FlowEventVo flowEventVo, int type) {
......@@ -41,99 +48,107 @@ public class FlowEventController extends FlowEventBaseController {
return flowEventExample;
}
@GetMapping("/statistics/export")
@ResponseBody
public Object export(TrafficFlowRequestVo trafficFlowRequestVo, @RequestParam String name) {
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
simplePropertyPreFilter.getExcludes().add("model");
String param = JSON.toJSONString(trafficFlowRequestVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE);
ExportData exportData = new ExportData();
exportData.setName(name);
exportData.setParam(param);
exportData.setType(ExportDataTypeEnum.FLOW.type);
exportData.setWithPic(0);
exportData.setWithVideo(0);
exportDataService.insertSelective(exportData);
return JsonMessageUtil.getSuccessJsonMsg();
}
@GetMapping("/statistics")
@ResponseBody
public JsonMessageUtil.JsonMessage statistics(TrafficFlowRequestVo trafficFlowRequestVo) {
Assert.hasLength(trafficFlowRequestVo.getEvent_dt__gte(), "起始时间不能为空");
Assert.hasLength(trafficFlowRequestVo.getEvent_dt__lt(), "结束时间不能为空");
Assert.notNull(trafficFlowRequestVo.getEvent_dt__gte(), "起始时间不能为空");
Assert.notNull(trafficFlowRequestVo.getEvent_dt__lt(), "结束时间不能为空");
Assert.hasLength(trafficFlowRequestVo.getStatistic_type(), "统计方式不能为空");
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
simplePropertyPreFilter.getExcludes().add("model");
opsClientService.addLog("检索分析结果,条件:" + JSON.toJSONString(trafficFlowRequestVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE));
try {
Map<String, Object> result = new HashMap<String, Object>(4);
String detection_type = trafficFlowRequestVo.getDetection_type() != null && !trafficFlowRequestVo.getDetection_type().isEmpty() ? trafficFlowRequestVo.getDetection_type().get(0) : null;
if (trafficFlowRequestVo.getOffset() == null) {
trafficFlowRequestVo.setOffset(0);
}
if (trafficFlowRequestVo.getLimit() == null) {
trafficFlowRequestVo.setLimit(100);
}
trafficFlowRequestVo.setVdev_unid("tflow_statics");
List<TrafficFlowEventModel> trafficFlowEventModels = flowMapper.selectEvents(trafficFlowRequestVo);
int counts = flowMapper.counts(trafficFlowRequestVo);
result.put("offset", trafficFlowRequestVo.getOffset());
result.put("total_num", counts);
if (trafficFlowEventModels != null && trafficFlowEventModels.size() > 0) {
Map<String, Object> result = statisticsResult(trafficFlowRequestVo);
return JsonMessageUtil.getSuccessJsonMsg(result);
}
// StringBuffer eventdts = new StringBuffer("('_1')");
// StringBuffer idList = new StringBuffer("(-1)");
// trafficFlowEventModels.forEach(trafficFlowEventModel -> {
// eventdts.append(",('").append(trafficFlowEventModel.getEvent_dt()).append("')");
// idList.append(",(").append(trafficFlowEventModel.getId()).append(")");
// });
Set<Long> collect = trafficFlowEventModels.stream().map(TrafficFlowEventModel::getId).collect(Collectors.toSet());
trafficFlowRequestVo.setIdSet(collect);
// trafficFlowRequestVo.setEventdts(eventdts.toString());
}
public Map<String, Object> statisticsResult(TrafficFlowRequestVo trafficFlowRequestVo) {
Map<String, Object> result = new HashMap<>(4);
String detection_type = trafficFlowRequestVo.getDetection_type() != null && !trafficFlowRequestVo.getDetection_type().isEmpty() ? trafficFlowRequestVo.getDetection_type().get(0) : null;
if (trafficFlowRequestVo.getOffset() == null) {
trafficFlowRequestVo.setOffset(0);
}
if (trafficFlowRequestVo.getLimit() == null) {
trafficFlowRequestVo.setLimit(100);
}
trafficFlowRequestVo.setVdev_unid("tflow_statics");
List<TrafficFlowEventModel> trafficFlowEventModels = flowMapper.selectEvents(trafficFlowRequestVo);
int counts = flowMapper.counts(trafficFlowRequestVo);
result.put("offset", trafficFlowRequestVo.getOffset());
result.put("total_num", counts);
if (trafficFlowEventModels != null && trafficFlowEventModels.size() > 0) {
Set<Long> collect = trafficFlowEventModels.stream().map(TrafficFlowEventModel::getId).collect(Collectors.toSet());
trafficFlowRequestVo.setIdSet(collect);
}
if (CollectionUtils.isEmpty(trafficFlowRequestVo.getIdSet())) {
result.put("offset", trafficFlowRequestVo.getOffset());
result.put("total_num", 0);
result.put("regionids", null);
result.put("list_data", new ArrayList<>(1));
result.put("event_type", trafficFlowRequestVo.getEvent_type());
result.put("maxRoadNum", 0);
return JsonMessageUtil.getSuccessJsonMsg(result);
}
if (StringUtils.isBlank(trafficFlowRequestVo.getStatistic_type())) {
trafficFlowRequestVo.setStatistic_type("road");
}
switch (trafficFlowRequestVo.getStatistic_type()) {
case "road":
trafficFlowRequestVo.setColumn_List(" flow_event_id,td.event_time,\n" +
"\t\tcase when te.device_name is null OR te.device_name='' then '-' else te.device_name end as device_name,\n" +
"\t\tcase when te.location_name is null OR te.location_name='' then '-' else te.location_name end as location_name,\n" +
" road_code as road,\n" +
"\t\tSUM(td.velocity*td.sample_num)/(CASE WHen sum(td.sample_num)=0 then 1 ELSE sum(td.sample_num) end) as velocity,AVG(td.occupy) as occupy,AVG(td.distance) as distance ,AVG(td.queue_length) as queue_length,AVG(td.sample_dura) as sample_dura ,\n" +
" sum(td.sample_num) as sample_num,\n" +
"\t\tAVG ( td.time_occupy ) AS time_occupy,\n" +
"\t\tAVG ( td.dist_time ) AS dist_time");
trafficFlowRequestVo.setGroupByClause(" flow_event_id,td.event_time,te.device_name,te.location_name,td.road_code ");
trafficFlowRequestVo.setOrderByClause(" td.event_time,flow_event_id,te.device_name,te.location_name,cast(road as signed INTEGER) ASC ");
List<TrafficFlowDataModel> l = flowMapper.flowstatistics(trafficFlowRequestVo);
result.put("list_data", report(trafficFlowEventModels, l, detection_type, trafficFlowRequestVo.getDevice_name()));
return JsonMessageUtil.getSuccessJsonMsg(result);
case "device":
trafficFlowRequestVo.setColumn_List(" td.event_time,flow_event_id,\n" +
"\t\tcase when te.device_name is null OR te.device_name='' then '-' else te.device_name end as device_name,\n" +
"\t\tcase when te.location_name is null OR te.location_name='' then '-' else te.location_name end as location_name,\n" +
" case when td.direction_code is null OR td.direction_code='' then '-' else td.direction_code end as direction,\n" +
"\t\tSUM(td.velocity*td.sample_num)/(CASE WHen sum(td.sample_num)=0 then 1 ELSE sum(td.sample_num) end) as velocity,AVG(td.occupy) as occupy,AVG(td.distance) as distance ,AVG(td.queue_length) as queue_length,AVG(td.sample_dura) as sample_dura ,\n" +
" sum(td.sample_num) as sample_num,\n" +
"\t\tAVG ( td.time_occupy ) AS time_occupy,\n" +
"\t\tAVG ( td.dist_time ) AS dist_time");
trafficFlowRequestVo.setGroupByClause(" td.event_time,flow_event_id,te.device_name,te.location_name,td.direction_code");
trafficFlowRequestVo.setOrderByClause(" td.event_time,flow_event_id,te.device_name,te.location_name,td.direction_code ASC ");
result.put("list_data", report(trafficFlowEventModels, flowMapper.flowstatistics(trafficFlowRequestVo), detection_type, trafficFlowRequestVo.getDevice_name()));
return JsonMessageUtil.getSuccessJsonMsg(result);
default:
return JsonMessageUtil.getSuccessJsonMsg();
}
} catch (Exception e) {
e.printStackTrace();
return JsonMessageUtil.getErrorJsonMsg("失败");
if (CollectionUtils.isEmpty(trafficFlowRequestVo.getIdSet())) {
result.put("offset", trafficFlowRequestVo.getOffset());
result.put("total_num", 0);
result.put("regionids", null);
result.put("list_data", new ArrayList<>(1));
result.put("event_type", trafficFlowRequestVo.getEvent_type());
result.put("maxRoadNum", 0);
return result;
}
if (StringUtils.isBlank(trafficFlowRequestVo.getStatistic_type())) {
trafficFlowRequestVo.setStatistic_type("road");
}
switch (trafficFlowRequestVo.getStatistic_type()) {
case "road":
trafficFlowRequestVo.setColumn_List(" flow_event_id,td.event_time,\n" +
"\t\tcase when te.device_name is null OR te.device_name='' then '-' else te.device_name end as device_name,\n" +
"\t\tcase when te.location_name is null OR te.location_name='' then '-' else te.location_name end as location_name,\n" +
" road_code as road,\n" +
"\t\tSUM(td.velocity*td.sample_num)/(CASE WHen sum(td.sample_num)=0 then 1 ELSE sum(td.sample_num) end) as velocity,AVG(td.occupy) as occupy,AVG(td.distance) as distance ,AVG(td.queue_length) as queue_length,AVG(td.sample_dura) as sample_dura ,\n" +
" sum(td.sample_num) as sample_num,\n" +
"\t\tAVG ( td.time_occupy ) AS time_occupy,\n" +
"\t\tAVG ( td.dist_time ) AS dist_time");
trafficFlowRequestVo.setGroupByClause(" flow_event_id,td.event_time,te.device_name,te.location_name,td.road_code ");
trafficFlowRequestVo.setOrderByClause(" td.event_time,flow_event_id,te.device_name,te.location_name,cast(road as signed INTEGER) ASC ");
List<TrafficFlowDataModel> l = flowMapper.flowstatistics(trafficFlowRequestVo);
result.put("list_data", report(trafficFlowEventModels, l, detection_type, trafficFlowRequestVo.getDevice_name()));
return result;
case "device":
trafficFlowRequestVo.setColumn_List(" td.event_time,flow_event_id,\n" +
"\t\tcase when te.device_name is null OR te.device_name='' then '-' else te.device_name end as device_name,\n" +
"\t\tcase when te.location_name is null OR te.location_name='' then '-' else te.location_name end as location_name,\n" +
" case when td.direction_code is null OR td.direction_code='' then '-' else td.direction_code end as direction,\n" +
"\t\tSUM(td.velocity*td.sample_num)/(CASE WHen sum(td.sample_num)=0 then 1 ELSE sum(td.sample_num) end) as velocity,AVG(td.occupy) as occupy,AVG(td.distance) as distance ,AVG(td.queue_length) as queue_length,AVG(td.sample_dura) as sample_dura ,\n" +
" sum(td.sample_num) as sample_num,\n" +
"\t\tAVG ( td.time_occupy ) AS time_occupy,\n" +
"\t\tAVG ( td.dist_time ) AS dist_time");
trafficFlowRequestVo.setGroupByClause(" td.event_time,flow_event_id,te.device_name,te.location_name,td.direction_code");
trafficFlowRequestVo.setOrderByClause(" td.event_time,flow_event_id,te.device_name,te.location_name,td.direction_code ASC ");
result.put("list_data", report(trafficFlowEventModels, flowMapper.flowstatistics(trafficFlowRequestVo), detection_type, trafficFlowRequestVo.getDevice_name()));
return result;
default:
throw new FanXingException("error");
}
}
private List report(List<TrafficFlowEventModel> trafficFlowEventModels, List<TrafficFlowDataModel> trafficFlowDataModels, String detection_type, String device_name) {
List result = Optional.ofNullable(trafficFlowEventModels).map(tfem -> {
List trees = new ArrayList<>();
private List<Map<String, Object>> report(List<TrafficFlowEventModel> trafficFlowEventModels, List<TrafficFlowDataModel> trafficFlowDataModels, String detection_type, String device_name) {
return Optional.ofNullable(trafficFlowEventModels).map(tfem -> {
List<Map<String, Object>> trees = new ArrayList<>();
try {
tfem.forEach(trafficFlowEventModel -> {
Map data;
Map<String, Object> data;
Iterator<TrafficFlowDataModel> it = trafficFlowDataModels == null ? null : trafficFlowDataModels.iterator();
while (it != null && it.hasNext()) {
data = new TreeMap();
......@@ -166,7 +181,6 @@ public class FlowEventController extends FlowEventBaseController {
e.printStackTrace();
}
return trees;
}).orElse(new ArrayList<Map>());
return result;
}).orElse(new ArrayList<>());
}
}
\ No newline at end of file
package com.viontech.fanxing.query.controller.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.model.TrafficExample;
import com.viontech.fanxing.commons.vo.TrafficVo;
import com.viontech.fanxing.query.controller.base.TrafficBaseController;
import com.viontech.fanxing.query.model.export.ExportDataTypeEnum;
import com.viontech.fanxing.query.service.adapter.ExportDataService;
import com.viontech.fanxing.query.service.main.OpsClientService;
import com.viontech.keliu.util.JsonMessageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg;
@Controller
@RestController
@RequestMapping("/traffics")
public class TrafficController extends TrafficBaseController {
@Resource
private OpsClientService opsClientService;
@Resource
private ExportDataService exportDataService;
@Override
protected BaseExample getExample(TrafficVo trafficVo, int type) {
TrafficExample trafficExample = (TrafficExample) super.getExample(trafficVo, type);
trafficExample.createColumns().hasIdColumn().hasEventTimeColumn().hasVideoNameColumn().hasPicsColumn();
return trafficExample;
return super.getExample(trafficVo, type);
}
@Override
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public Object page(TrafficVo trafficVo, @RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "pageSize", defaultValue = "30") int pageSize, String sortName, String sortOrder) {
public Object page(TrafficVo trafficVo, @RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "pageSize", defaultValue = "30") int pageSize,
@RequestParam(defaultValue = "event_time") String sortName, @RequestParam(defaultValue = "desc") String sortOrder) {
Assert.notNull(trafficVo.getEventTime_gte(), "起始时间不能为空");
Assert.notNull(trafficVo.getEventTime_lte(), "结束时间不能为空");
Assert.isTrue(pageSize > 0, "页面大小不正确");
......@@ -62,4 +65,53 @@ public class TrafficController extends TrafficBaseController {
PageInfo<TrafficVo> pageInfo = trafficService.getJsonData(baseExample, page, pageSize);
return getSuccessJsonMsg(MESSAGE_PAGE_SUCCESS, pageInfo);
}
@PostMapping("/batchRemove")
public Object batchRemove(@RequestBody JSONArray ids) {
List<Long> longs = ids.toJavaList(Long.class);
TrafficExample trafficExample = new TrafficExample();
trafficExample.createCriteria().andIdIn(longs);
trafficService.deleteByExample(trafficExample);
return JsonMessageUtil.getSuccessJsonMsg();
}
@GetMapping("/export")
public Object export(TrafficVo trafficVo, @RequestParam String name, @RequestParam Integer withPic, @RequestParam Integer withVideo) {
SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
simplePropertyPreFilter.getExcludes().add("model");
String param = JSON.toJSONString(trafficVo, SerializeConfig.globalInstance, new SerializeFilter[]{simplePropertyPreFilter}, "yyyy-MM-dd HH:mm:ss", JSON.DEFAULT_GENERATE_FEATURE);
String eventType = trafficVo.getEventType();
if (trafficVo.getIllegalState() == null) {
Assert.hasLength(eventType, "eventType不能为空");
}
int type;
if ("xcycle".equals(eventType)) {
type = ExportDataTypeEnum.XCYCLE.type;
} else if ("pedestrian".equals(eventType)) {
type = ExportDataTypeEnum.PEDESTRIAN.type;
} else if (trafficVo.getIllegalState() != null && trafficVo.getIllegalState() == 1) {
type = ExportDataTypeEnum.ILLEGAL.type;
} else if ("vehicle".equals(eventType)) {
type = ExportDataTypeEnum.TRAFFIC.type;
} else {
throw new FanXingException("参数有误");
}
ExportData exportData = new ExportData();
exportData.setName(name);
exportData.setParam(param);
exportData.setType(type);
exportData.setWithPic(withPic);
exportData.setWithVideo(withVideo);
exportDataService.insertSelective(exportData);
return JsonMessageUtil.getSuccessJsonMsg();
}
public TrafficExample getExample(TrafficVo trafficVo) {
return (TrafficExample) super.getExample(trafficVo, EXAMPLE_TYPE_PAGE);
}
}
\ No newline at end of file
......@@ -32,6 +32,12 @@ public interface OpsClient {
@GetMapping("/dictCodes")
JsonMessageUtil.JsonMessage<List<DictCode>> getDictCodeByUnid(@RequestParam("unid") String unid);
@GetMapping("/dictCodes")
JsonMessageUtil.JsonMessage<List<DictCode>> getDictCodes();
@GetMapping("/dictCates")
JsonMessageUtil.JsonMessage<List<DictCate>> getDictCates();
@PostMapping("/logs")
JsonMessageUtil.JsonMessage<Log> addLog(@RequestBody LogVo logVo);
......
package com.viontech.fanxing.query.mapper;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.commons.model.ExportDataExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface ExportDataMapper extends BaseMapper {
int countByExample(ExportDataExample example);
int deleteByExample(ExportDataExample example);
int deleteByPrimaryKey(Long id);
int insert(ExportData record);
int insertSelective(ExportData record);
List<ExportData> selectByExample(ExportDataExample example);
ExportData selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") ExportData record, @Param("example") ExportDataExample example);
int updateByExample(@Param("record") ExportData record, @Param("example") ExportDataExample example);
int updateByPrimaryKeySelective(ExportData record);
int updateByPrimaryKey(ExportData record);
}
\ No newline at end of file
......@@ -142,19 +142,17 @@
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="map" >
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from `d_behavior` `behavior`
where `behavior`.id = #{id,jdbcType=BIGINT}
and `behavior`.event_time = #{eventTime,jdbcType=TIMESTAMP}
</select>
<delete id="deleteByPrimaryKey" parameterType="map" >
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from `d_behavior` `behavior`
where id = #{id,jdbcType=BIGINT}
and event_time = #{eventTime,jdbcType=TIMESTAMP}
</delete>
<delete id="deleteByExample" parameterType="com.viontech.fanxing.commons.model.BehaviorExample" >
delete from `d_behavior` `behavior`
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.viontech.fanxing.query.mapper.ExportDataMapper" >
<resultMap id="BaseResultMapRoot" type="com.viontech.fanxing.commons.model.ExportData" >
<id column="exportData_id" property="id" />
<result column="exportData_create_time" property="createTime" />
<result column="exportData_name" property="name" />
<result column="exportData_type" property="type" />
<result column="exportData_count" property="count" />
<result column="exportData_with_pic" property="withPic" />
<result column="exportData_with_video" property="withVideo" />
<result column="exportData_param" property="param" />
<result column="exportData_path" property="path" />
<result column="exportData_status" property="status" />
</resultMap>
<resultMap id="BaseResultMap" type="com.viontech.fanxing.commons.model.ExportData" extends="BaseResultMapRoot" />
<sql id="Example_Where_Clause" >
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause" >
<where >
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List_Root" >
`exportData`.id as exportData_id, `exportData`.create_time as exportData_create_time,
`exportData`.`name` as `exportData_name`, `exportData`.`type` as `exportData_type`,
`exportData`.`count` as `exportData_count`, `exportData`.with_pic as exportData_with_pic,
`exportData`.with_video as exportData_with_video, `exportData`.param as exportData_param,
`exportData`.`path` as `exportData_path`, `exportData`.`status` as `exportData_status`
</sql>
<sql id="Base_Column_List" >
<if test="!(_parameter.getClass().getSimpleName() == 'ExportDataExample')" >
<include refid="com.viontech.fanxing.query.mapper.ExportDataMapper.Base_Column_List_Root" />
</if>
<if test="_parameter.getClass().getSimpleName() == 'ExportDataExample'" >
<foreach collection="columnContainerSet" item="columns" separator="," >
<choose >
<when test="columns.tableName == 'd_export_data'.toString()" >
<if test="columns.valid" >
${columns.columnContainerStr}
</if>
<if test="!columns.valid" >
<include refid="com.viontech.fanxing.query.mapper.ExportDataMapper.Base_Column_List_Root" />
</if>
</when>
</choose>
</foreach>
</if>
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.viontech.fanxing.commons.model.ExportDataExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from `d_export_data` `exportData`
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="groupByClause != null" >
group by ${groupByClause}
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from `d_export_data` `exportData`
where `exportData`.id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from `d_export_data` `exportData`
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.viontech.fanxing.commons.model.ExportDataExample" >
delete from `d_export_data` `exportData`
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.viontech.fanxing.commons.model.ExportData" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `d_export_data` (create_time, `name`, `type`,
`count`, with_pic, with_video,
param, `path`, `status`
)
values (#{createTime,jdbcType=TIMESTAMP}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER},
#{count,jdbcType=BIGINT}, #{withPic,jdbcType=INTEGER}, #{withVideo,jdbcType=INTEGER},
#{param,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.viontech.fanxing.commons.model.ExportData" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `d_export_data`
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="createTime != null" >
create_time,
</if>
<if test="name != null" >
`name`,
</if>
<if test="type != null" >
`type`,
</if>
<if test="count != null" >
`count`,
</if>
<if test="withPic != null" >
with_pic,
</if>
<if test="withVideo != null" >
with_video,
</if>
<if test="param != null" >
param,
</if>
<if test="path != null" >
`path`,
</if>
<if test="status != null" >
`status`,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="name != null" >
#{name,jdbcType=VARCHAR},
</if>
<if test="type != null" >
#{type,jdbcType=INTEGER},
</if>
<if test="count != null" >
#{count,jdbcType=BIGINT},
</if>
<if test="withPic != null" >
#{withPic,jdbcType=INTEGER},
</if>
<if test="withVideo != null" >
#{withVideo,jdbcType=INTEGER},
</if>
<if test="param != null" >
#{param,jdbcType=VARCHAR},
</if>
<if test="path != null" >
#{path,jdbcType=VARCHAR},
</if>
<if test="status != null" >
#{status,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.viontech.fanxing.commons.model.ExportDataExample" resultType="java.lang.Integer" >
select count(*) from `d_export_data` `exportData`
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map" >
update `d_export_data` `exportData`
<set >
<if test="record.id != null" >
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.createTime != null" >
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
<if test="record.name != null" >
`name` = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.type != null" >
`type` = #{record.type,jdbcType=INTEGER},
</if>
<if test="record.count != null" >
`count` = #{record.count,jdbcType=BIGINT},
</if>
<if test="record.withPic != null" >
with_pic = #{record.withPic,jdbcType=INTEGER},
</if>
<if test="record.withVideo != null" >
with_video = #{record.withVideo,jdbcType=INTEGER},
</if>
<if test="record.param != null" >
param = #{record.param,jdbcType=VARCHAR},
</if>
<if test="record.path != null" >
`path` = #{record.path,jdbcType=VARCHAR},
</if>
<if test="record.status != null" >
`status` = #{record.status,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map" >
update `d_export_data` `exportData`
set id = #{record.id,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=TIMESTAMP},
`name` = #{record.name,jdbcType=VARCHAR},
`type` = #{record.type,jdbcType=INTEGER},
`count` = #{record.count,jdbcType=BIGINT},
with_pic = #{record.withPic,jdbcType=INTEGER},
with_video = #{record.withVideo,jdbcType=INTEGER},
param = #{record.param,jdbcType=VARCHAR},
`path` = #{record.path,jdbcType=VARCHAR},
`status` = #{record.status,jdbcType=INTEGER}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.viontech.fanxing.commons.model.ExportData" >
update `d_export_data`
<set >
<if test="createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="name != null" >
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="type != null" >
`type` = #{type,jdbcType=INTEGER},
</if>
<if test="count != null" >
`count` = #{count,jdbcType=BIGINT},
</if>
<if test="withPic != null" >
with_pic = #{withPic,jdbcType=INTEGER},
</if>
<if test="withVideo != null" >
with_video = #{withVideo,jdbcType=INTEGER},
</if>
<if test="param != null" >
param = #{param,jdbcType=VARCHAR},
</if>
<if test="path != null" >
`path` = #{path,jdbcType=VARCHAR},
</if>
<if test="status != null" >
`status` = #{status,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.viontech.fanxing.commons.model.ExportData" >
update `d_export_data`
set create_time = #{createTime,jdbcType=TIMESTAMP},
`name` = #{name,jdbcType=VARCHAR},
`type` = #{type,jdbcType=INTEGER},
`count` = #{count,jdbcType=BIGINT},
with_pic = #{withPic,jdbcType=INTEGER},
with_video = #{withVideo,jdbcType=INTEGER},
param = #{param,jdbcType=VARCHAR},
`path` = #{path,jdbcType=VARCHAR},
`status` = #{status,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
......@@ -144,19 +144,17 @@
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="map" >
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Long">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from `d_flow_event` `flowEvent`
where `flowEvent`.id = #{id,jdbcType=BIGINT}
and `flowEvent`.event_time = #{eventTime,jdbcType=TIMESTAMP}
</select>
<delete id="deleteByPrimaryKey" parameterType="map" >
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from `d_flow_event` `flowEvent`
where id = #{id,jdbcType=BIGINT}
and event_time = #{eventTime,jdbcType=TIMESTAMP}
</delete>
<delete id="deleteByExample" parameterType="com.viontech.fanxing.commons.model.FlowEventExample" >
delete from `d_flow_event` `flowEvent`
......
......@@ -169,16 +169,15 @@
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="map" >
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from `d_traffic` `traffic`
where `traffic`.id = #{id,jdbcType=BIGINT}
and `traffic`.event_time = #{eventTime,jdbcType=TIMESTAMP}
</select>
<delete id="deleteByPrimaryKey" parameterType="map" >
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from `d_traffic` `traffic`
where id = #{id,jdbcType=BIGINT}
and event_time = #{eventTime,jdbcType=TIMESTAMP}
......
......@@ -3,14 +3,15 @@ package com.viontech.fanxing.query.model;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
import java.util.List;
import java.util.Set;
@Getter
@Setter
public class TrafficFlowRequestVo extends TrafficFlowBaseRequestVo {
private String event_dt__gte;// 可选,查询时间范围的起始时刻(包含),默认为event_dt_lt前7天。
private String event_dt__lt;//可选,查询时间范围的结束时刻(不含),默认为当前时间后10分钟。
private Date event_dt__gte;// 可选,查询时间范围的起始时刻(包含),默认为event_dt_lt前7天。
private Date event_dt__lt;//可选,查询时间范围的结束时刻(不含),默认为当前时间后10分钟。
private String dev_unid;// 可选,精确匹配,产生数据的设备的unid
private String vchan_refid;//可选,精确匹配,视频通道的参考id
private String vdev_unid;// 可选,精确匹配,视频通道所在设备的unid
......
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class EIllegalModel extends ExportBaseModel {
private String plateNumber;
private String plateColor;
private String vehicleType;
private String vehicleBrand;
private String vehicleColor;
private String illegalType;
// private String withSeatBelt;
// private String phone;
}
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class EPedestrianModel extends ExportBaseModel {
private String upColor;
private String lowColor;
private String gender;
private String height;
private String withHat;
private String location;
}
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class ETrafficModel extends ExportBaseModel {
private String plateNumber;
private String plateColor;
private String vehicleType;
private String vehicleBrand;
private String vehicleColor;
// private String seatBelt = "未知";
// private String phone = "未知";
// private String hugChild = "未知";
private String location = "未知";
}
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class EXcycleModel extends ExportBaseModel{
private String xcycleType;
private String company;
private String velocity;
private String location;
}
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class EbehaviorModel extends ExportBaseModel {
private String eventType;
private String taskName;
}
package com.viontech.fanxing.query.model.export;
import lombok.Getter;
import lombok.Setter;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@Getter
@Setter
public class ExportBaseModel {
private String picName;
private String videoName;
private String eventTime;
}
package com.viontech.fanxing.query.model.export;
/**
* .
*
* @author 谢明辉
* @date 2021/11/25
*/
public enum ExportDataTypeEnum {
/** 过车数据 */
TRAFFIC(1),
/** 非机动车 */
XCYCLE(2),
/** 行人 */
PEDESTRIAN(3),
/** 违法数据 */
ILLEGAL(4),
/** 流量数据 */
FLOW(5),
/** 事件数据 */
BEHAVIOR(6);
public int type;
ExportDataTypeEnum(int type) {
this.type = type;
}
}
package com.viontech.fanxing.query.runner;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.config.VionConfig;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.service.RedisService;
import com.viontech.fanxing.commons.vo.BehaviorVo;
import com.viontech.fanxing.commons.vo.TrafficVo;
import com.viontech.fanxing.query.controller.web.BehaviorController;
import com.viontech.fanxing.query.controller.web.FlowEventController;
import com.viontech.fanxing.query.controller.web.TrafficController;
import com.viontech.fanxing.query.model.TrafficFlowRequestVo;
import com.viontech.fanxing.query.model.export.*;
import com.viontech.fanxing.query.service.adapter.BehaviorService;
import com.viontech.fanxing.query.service.adapter.ExportDataService;
import com.viontech.fanxing.query.service.adapter.TrafficService;
import com.viontech.fanxing.query.service.main.OpsClientService;
import com.viontech.keliu.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* .
*
* @author 谢明辉
* @date 2021/11/25
*/
@Component
@Slf4j
@Profile("!test")
public class ExportDataJob {
private static final Integer LIMIT_WITH_VIDEO = 1000;
private static final Integer LIMIT_WITH_PIC = 10000;
private static final Integer LIMIT = 50000;
@Resource
private RedisService redisService;
@Resource
private ExportDataService exportDataService;
@Resource
private TrafficService trafficService;
@Resource
private VionConfig vionConfig;
@Resource
private TrafficController trafficController;
@Resource
private OpsClientService opsClientService;
@Resource
private BehaviorService behaviorService;
@Resource
private BehaviorController behaviorController;
@Resource
private FlowEventController flowEventController;
@Scheduled(fixedDelay = 10000L)
public void run() {
log.info("执行数据导出定时任务开始");
RLock lock = redisService.getLockMust("exportDataJob", 60, 59, TimeUnit.MINUTES);
try {
List<ExportData> exportData = getExportDataNeedFinished();
for (ExportData item : exportData) {
try {
log.info("开始导出数据:{}", JSON.toJSONString(item));
switch (item.getType()) {
case 1:
case 2:
case 3:
case 4:
exportTraffic(item, item.getType());
break;
case 5:
exportFlow(item);
break;
case 6:
exportBehavior(item);
break;
default:
break;
}
} catch (Exception e) {
log.error("导出任务出错", e);
}
}
} catch (Exception e) {
log.error("导出任务出错", e);
} finally {
lock.forceUnlock();
}
log.info("执行数据导出定时任务结束");
}
private void exportFlow(ExportData item) {
item.setStatus(1);
boolean withVideo = item.getWithVideo() == 1;
boolean withPic = item.getWithPic() == 1;
int pageSize = withVideo ? LIMIT_WITH_VIDEO : (withPic ? LIMIT_WITH_PIC : LIMIT);
String param = item.getParam();
TrafficFlowRequestVo trafficFlowRequestVo = JSON.parseObject(param, TrafficFlowRequestVo.class);
String statisticType = trafficFlowRequestVo.getStatistic_type();
int nextPage = 1;
List<String> pathList = new ArrayList<>();
while (nextPage != 0) {
trafficFlowRequestVo.setOffset((nextPage - 1) * pageSize);
trafficFlowRequestVo.setLimit(pageSize);
Map<String, Object> stringObjectMap = flowEventController.statisticsResult(trafficFlowRequestVo);
List<Map<String, Object>> result = (List<Map<String, Object>>) stringObjectMap.get("list_data");
int totalNum = (int) stringObjectMap.get("total_num");
if (result == null || result.size() == 0) {
break;
}
log.info("数据总量:{}", totalNum);
item.setCount(((long) totalNum));
String path = vionConfig.getImage().getPath() + "/export/" + item.getId() + "/" + nextPage + ".xlsx";
pathList.add(path);
File excel = new File(path);
excel.getParentFile().mkdirs();
try {
// 写入 excel
ExcelWriter writer = ExcelUtil.getWriter(true);
writer.addHeaderAlias("event_dt", "时间");
writer.addHeaderAlias("device_name", "相机名称");
if ("road".equals(statisticType)) {
writer.addHeaderAlias("road", "车道");
} else {
writer.addHeaderAlias("direction", "方向");
}
writer.addHeaderAlias("velocity", "平均速度(KM/H)");
writer.addHeaderAlias("occupy", "占有率");
writer.addHeaderAlias("distance", "车头间距");
writer.addHeaderAlias("queue_length", "排队长度");
writer.addHeaderAlias("sample_num", "车流量");
writer.setOnlyAlias(true);
writer.write(result, true);
writer.flush(excel);
writer.close();
} catch (Exception e) {
log.error("", e);
}
int totalpage = (totalNum / pageSize) + ((totalNum % pageSize) > 0 ? 1 : 0);
nextPage = nextPage < totalpage ? nextPage + 1 : 0;
}
item.setPath(JSON.toJSONString(pathList));
exportDataService.updateByPrimaryKeySelective(item);
}
private void exportTraffic(ExportData item, int type) {
item.setStatus(1);
boolean withVideo = item.getWithVideo() == 1;
boolean withPic = item.getWithPic() == 1;
int pageSize = withVideo ? LIMIT_WITH_VIDEO : (withPic ? LIMIT_WITH_PIC : LIMIT);
String param = item.getParam();
TrafficVo trafficVo = JSON.parseObject(param, TrafficVo.class);
TrafficExample example = trafficController.getExample(trafficVo);
int nextPage = 1;
List<String> pathList = new ArrayList<>();
while (nextPage != 0) {
PageInfo<TrafficVo> jsonData = trafficService.getJsonData(example, nextPage, pageSize);
log.info("数据总量:{}", jsonData.getTotal());
item.setCount(jsonData.getTotal());
List<TrafficVo> list = jsonData.getList();
if (list.size() == 0) {
break;
}
String path = vionConfig.getImage().getPath() + "/export/" + item.getId() + "/" + nextPage + ".zip";
pathList.add(path);
File zipFile = new File(path);
zipFile.getParentFile().mkdirs();
try (ZipOutputStream zipO = new ZipOutputStream(new FileOutputStream(zipFile))) {
List<ExportBaseModel> excelData = new ArrayList<>();
for (TrafficVo vo : list) {
// 添加数据
ExportBaseModel o;
try {
o = buildTrafficData(type, vo);
} catch (Exception e) {
log.error("", e);
continue;
}
excelData.add(o);
// 写入图片文件
if (withPic && StringUtils.isNotEmpty(vo.getPics())) {
File file = new File(vo.getPics());
o.setPicName(file.getName());
if (file.exists()) {
try {
byte[] bytes = FileUtils.readFileToByteArray(file);
zipO.putNextEntry(new ZipEntry(file.getName()));
zipO.write(bytes);
} catch (Exception e) {
log.error("", e);
}
}
}
// 写入视频文件
if (withVideo && StringUtils.isNotEmpty(vo.getVideoName())) {
File file = new File(vo.getVideoName());
o.setPicName(file.getName());
if (file.exists()) {
try {
byte[] bytes = FileUtils.readFileToByteArray(file);
zipO.putNextEntry(new ZipEntry(file.getName()));
zipO.write(bytes);
} catch (Exception e) {
log.error("", e);
}
}
}
}
// 写入 excel
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ExcelWriter writer = getExcelWriter();
writer.write(excelData, true);
writer.flush(outputStream);
writer.close();
zipO.putNextEntry(new ZipEntry("data.xlsx"));
zipO.write(outputStream.toByteArray());
} catch (Exception e) {
log.error("", e);
}
nextPage = jsonData.getNextPage();
}
item.setPath(JSON.toJSONString(pathList));
exportDataService.updateByPrimaryKeySelective(item);
}
private void exportBehavior(ExportData item) {
item.setStatus(1);
boolean withVideo = item.getWithVideo() == 1;
boolean withPic = item.getWithPic() == 1;
int pageSize = withVideo ? LIMIT_WITH_VIDEO : (withPic ? LIMIT_WITH_PIC : LIMIT);
String param = item.getParam();
BehaviorVo behaviorVo = JSON.parseObject(param, BehaviorVo.class);
BehaviorExample example = behaviorController.getExample(behaviorVo);
int nextPage = 1;
List<String> pathList = new ArrayList<>();
while (nextPage != 0) {
PageInfo<BehaviorVo> jsonData = behaviorService.getJsonData(example, nextPage, pageSize);
log.info("数据总量:{}", jsonData.getTotal());
item.setCount(jsonData.getTotal());
List<BehaviorVo> list = jsonData.getList();
if (list.size() == 0) {
break;
}
String path = vionConfig.getImage().getPath() + "/export/" + item.getId() + "/" + nextPage + ".zip";
pathList.add(path);
File zipFile = new File(path);
zipFile.getParentFile().mkdirs();
try (ZipOutputStream zipO = new ZipOutputStream(new FileOutputStream(zipFile))) {
List<ExportBaseModel> excelData = new ArrayList<>();
for (BehaviorVo vo : list) {
ExportBaseModel o = buildBehaviorModel(vo);
excelData.add(o);
// 写入图片文件
if (withPic && StringUtils.isNotEmpty(vo.getPics())) {
File file = new File(vo.getPics());
if (file.exists()) {
try {
byte[] bytes = FileUtils.readFileToByteArray(file);
zipO.putNextEntry(new ZipEntry(file.getName()));
zipO.write(bytes);
o.setPicName(file.getName());
} catch (Exception e) {
log.error("", e);
}
}
}
// 写入视频文件
if (withVideo && StringUtils.isNotEmpty(vo.getVideo())) {
File file = new File(vo.getVideo());
if (file.exists()) {
try {
byte[] bytes = FileUtils.readFileToByteArray(file);
zipO.putNextEntry(new ZipEntry(file.getName()));
zipO.write(bytes);
o.setPicName(file.getName());
} catch (Exception e) {
log.error("", e);
}
}
}
}
// 写入 excel
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ExcelWriter writer = getExcelWriter();
writer.write(excelData, true);
writer.flush(outputStream);
writer.close();
zipO.putNextEntry(new ZipEntry("data.xlsx"));
zipO.write(outputStream.toByteArray());
} catch (Exception e) {
log.error("", e);
}
nextPage = jsonData.getNextPage();
}
item.setPath(JSON.toJSONString(pathList));
exportDataService.updateByPrimaryKeySelective(item);
}
private List<ExportData> getExportDataNeedFinished() {
ExportDataExample exportDataExample = new ExportDataExample();
exportDataExample.createCriteria().andStatusEqualTo(0);
return exportDataService.selectByExample(exportDataExample);
}
private ExportBaseModel buildTrafficData(Integer type, TrafficVo trafficVo) {
String eventTime = DateUtil.format(DateUtil.FORMAT_LONG, trafficVo.getEventTime());
String locationName = trafficVo.getLocationName();
Map<String, DictCode> vehicleColorDict = opsClientService.vehicleColorDict();
JSONObject data = trafficVo.getData();
JSONObject eventData = data.getJSONObject("event_data");
String plateNumber = trafficVo.getPlateNumber();
Map<String, DictCode> vehicleTypeDict = opsClientService.vehicleTypeDict();
Map<String, DictCode> plateColorDict = opsClientService.plateColorDict();
Map<String, DictCode> vehicleBrandDict = opsClientService.vehicleBrandDict();
String plateColor;
String vehicleType;
String vehicleBrand;
String vehicleColor;
switch (type) {
case 1:
ETrafficModel e = new ETrafficModel();
e.setEventTime(eventTime);
e.setLocation(locationName);
e.setPlateNumber(plateNumber);
plateColor = Optional.ofNullable(plateColorDict.get(trafficVo.getPlateColor())).map(DictCode::getName).orElse("未识别");
vehicleType = Optional.ofNullable(vehicleTypeDict.get(trafficVo.getVehicleType())).map(DictCode::getName).orElse("未识别");
vehicleBrand = Optional.ofNullable(vehicleBrandDict.get(trafficVo.getVehicleLogo())).map(DictCode::getName).orElse("未识别");
vehicleColor = Optional.ofNullable(vehicleColorDict.get(trafficVo.getVehicleColor())).map(DictCode::getName).orElse("未识别");
e.setPlateColor(plateColor);
e.setVehicleType(vehicleType);
e.setVehicleBrand(vehicleBrand);
e.setVehicleColor(vehicleColor);
return e;
case 2:
Map<String, DictCode> companyDict = opsClientService.companyDict();
EXcycleModel x = new EXcycleModel();
x.setEventTime(eventTime);
String xcycleType = trafficVo.getXcycleType();
if ("motorcycle".equals(xcycleType)) {
x.setXcycleType("摩托车");
} else if ("bicycle".equals(xcycleType)) {
x.setXcycleType("自行车");
} else if ("tricycle".equals(xcycleType)) {
x.setXcycleType("三轮车");
} else {
x.setXcycleType("未知");
}
x.setVelocity(Optional.ofNullable(data).map(j -> j.getJSONObject("event_data")).map(j -> j.getString("speed")).orElse("未知"));
x.setLocation(trafficVo.getLocationName());
String company = Optional.ofNullable(companyDict.get(trafficVo.getCompany())).map(DictCode::getName).orElse("未知");
x.setCompany(company);
return x;
case 3:
JSONObject driver = eventData.getJSONObject("driver");
JSONObject pedestrian = eventData.getJSONObject("pedestrian");
JSONArray face = driver.getJSONArray("face");
JSONObject face1 = face.getJSONObject(0);
JSONObject upbody = face1.getJSONObject("upbody");
JSONObject lobody = face1.getJSONObject("lobody");
EPedestrianModel p = new EPedestrianModel();
String sex = face1.getString("sex");
p.setGender("1".equals(sex) ? "男" : "2".equals(sex) ? "女" : "不确定");
p.setUpColor(upbody.getString("name"));
p.setLowColor(lobody.getString("name"));
p.setHeight(String.valueOf(pedestrian.getFloat("height")));
// todo 不知道怎么定义的
p.setWithHat(String.valueOf(face1.getInteger("with_hats")));
p.setLocation(trafficVo.getLocationName());
p.setEventTime(eventTime);
return p;
case 4:
Map<String, DictCode> illegalTypedDict = opsClientService.illegalTypedDict();
EIllegalModel i = new EIllegalModel();
plateColor = Optional.ofNullable(plateColorDict.get(trafficVo.getPlateColor())).map(DictCode::getName).orElse("未识别");
vehicleType = Optional.ofNullable(vehicleTypeDict.get(trafficVo.getVehicleType())).map(DictCode::getName).orElse("未识别");
vehicleBrand = Optional.ofNullable(vehicleBrandDict.get(trafficVo.getVehicleLogo())).map(DictCode::getName).orElse("未识别");
vehicleColor = Optional.ofNullable(vehicleColorDict.get(trafficVo.getVehicleColor())).map(DictCode::getName).orElse("未识别");
String illegalType = Optional.ofNullable(illegalTypedDict.get(trafficVo.getIllegalCode())).map(DictCode::getName).orElse("未识别");
i.setPlateNumber(plateNumber);
i.setPlateColor(plateColor);
i.setVehicleType(vehicleType);
i.setVehicleBrand(vehicleBrand);
i.setVehicleColor(vehicleColor);
i.setEventTime(eventTime);
i.setIllegalType(illegalType);
return i;
default:
throw new FanXingException("类型错误 : {[]}", type);
}
}
private EbehaviorModel buildBehaviorModel(Behavior behavior) {
EbehaviorModel e = new EbehaviorModel();
e.setEventTime(DateUtil.format(DateUtil.FORMAT_LONG, behavior.getEventTime()));
Map<String, DictCode> behaviorDict = opsClientService.behaviorDict();
String eventType = Optional.ofNullable(behaviorDict.get(behavior.getEventType())).map(DictCode::getName).orElse("未知");
e.setEventType(eventType);
e.setTaskName(behavior.getTaskName());
return e;
}
private ExcelWriter getExcelWriter() {
ExcelWriter writer = ExcelUtil.getWriter(true);
writer.addHeaderAlias("upColor", "上身颜色");
writer.addHeaderAlias("lowColor", "下身颜色");
writer.addHeaderAlias("gender", "性别");
writer.addHeaderAlias("height", "身高");
writer.addHeaderAlias("withHat", "戴帽子");
writer.addHeaderAlias("eventType", "事件类型");
writer.addHeaderAlias("taskName", "任务名称");
writer.addHeaderAlias("xcycleType", "非机动车类型");
writer.addHeaderAlias("company", "运营公司");
writer.addHeaderAlias("velocity", "速率");
writer.addHeaderAlias("plateNumber", "车牌号码");
writer.addHeaderAlias("plateColor", "车牌颜色");
writer.addHeaderAlias("vehicleType", "车辆类型");
writer.addHeaderAlias("vehicleBrand", "车辆品牌");
writer.addHeaderAlias("vehicleColor", "车辆颜色");
writer.addHeaderAlias("illegalType", "违法类型");
writer.addHeaderAlias("eventTime", "抓拍时间");
writer.addHeaderAlias("location", "抓拍地点");
writer.addHeaderAlias("picName", "图片名称");
writer.addHeaderAlias("videoName", "视频名称");
return writer;
}
}
package com.viontech.fanxing.query.service.adapter;
import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.ExportData;
public interface ExportDataService extends BaseService<ExportData> {
}
\ No newline at end of file
package com.viontech.fanxing.query.service.impl;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.config.VionConfig;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.ExportData;
import com.viontech.fanxing.query.mapper.ExportDataMapper;
import com.viontech.fanxing.query.service.adapter.ExportDataService;
import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.File;
@Service
public class ExportDataServiceImpl extends BaseServiceImpl<ExportData> implements ExportDataService {
@Resource
private ExportDataMapper exportDataMapper;
@Resource
private VionConfig vionConfig;
@Override
public BaseMapper<ExportData> getMapper() {
return exportDataMapper;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteByPrimaryKey(Object b) {
int i = super.deleteByPrimaryKey(b);
File file = new File(vionConfig.getImage().getPath() + "/export/" + b.toString());
try {
FileUtils.deleteDirectory(file);
} catch (Exception e) {
throw new FanXingException("无法删除目录:{[]}", file.getPath());
}
return i;
}
}
\ No newline at end of file
package com.viontech.fanxing.query.service.main;
import com.viontech.fanxing.commons.base.LocalCache;
import com.viontech.fanxing.commons.constant.LogType;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.Content;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.StoreConfig;
import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.vo.LogVo;
import com.viontech.fanxing.query.feign.OpsClient;
import com.viontech.keliu.util.JsonMessageUtil;
......@@ -18,6 +16,9 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* .
......@@ -92,4 +93,80 @@ public class OpsClientService {
}
}
@LocalCache(value = "dictCates12312", timeunit = TimeUnit.DAYS, duration = 1)
public Map<String, DictCate> dictCates() {
JsonMessageUtil.JsonMessage<List<DictCate>> response = opsClient.getDictCates();
if (response.isSuccess()) {
List<DictCate> data = response.getData();
Map<String, DictCate> collect = data.stream().collect(Collectors.toMap(DictCate::getCode, x -> x, (a, b) -> a));
return collect;
} else {
throw new FanXingException(response.getMsg());
}
}
@LocalCache(value = "dictCodes123456789")
public Map<Long, Map<String, DictCode>> dictCodes() {
JsonMessageUtil.JsonMessage<List<DictCode>> response = opsClient.getDictCodes();
if (response.isSuccess()) {
List<DictCode> data = response.getData();
Map<Long, Map<String, DictCode>> collect = data.stream().collect(Collectors.groupingBy(DictCode::getCateId, Collectors.toMap(DictCode::getCode, x -> x, (a, b) -> a)));
return collect;
} else {
throw new FanXingException(response.getMsg());
}
}
@LocalCache(value = "plateColorDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> plateColorDict() {
return getDictByCate("plate_color");
}
@LocalCache(value = "vehicleColorDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> vehicleColorDict() {
return getDictByCate("vehicle_color");
}
@LocalCache(value = "illegalTypeDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> illegalTypeDict() {
return getDictByCate("illegal_type");
}
@LocalCache(value = "vehicleTypeDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> vehicleTypeDict() {
return getDictByCate("vehicle_type");
}
@LocalCache(value = "vehicleBrandDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> vehicleBrandDict() {
return getDictByCate("vehicle_brand");
}
@LocalCache(value = "illegalTypedDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> illegalTypedDict() {
return getDictByCate("illegal_type");
}
@LocalCache(value = "behaviorDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> behaviorDict() {
return getDictByCate("behavior");
}
@LocalCache(value = "companyDict", timeunit = TimeUnit.HOURS, duration = 1)
public Map<String, DictCode> companyDict() {
return getDictByCate("company");
}
private Map<String, DictCode> getDictByCate(String cateCode) {
Map<String, DictCate> cateMap = dictCates();
DictCate cate = cateMap.get(cateCode);
if (cate == null) {
return null;
}
Long id = cate.getId();
Map<Long, Map<String, DictCode>> dictCodes = dictCodes();
return dictCodes.get(id);
}
}
......@@ -53,4 +53,6 @@ pagehelper:
params: count=countByExample
vion:
redisson:
path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml
\ No newline at end of file
path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml
image:
path: G:\data
\ No newline at end of file
package com.viontech.fanxing.query;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.Traffic;
import com.viontech.fanxing.commons.vo.TrafficVo;
import com.viontech.fanxing.query.model.export.ETrafficModel;
import com.viontech.fanxing.query.runner.ExportDataJob;
import com.viontech.fanxing.query.service.adapter.TrafficService;
import com.viontech.fanxing.query.service.main.OpsClientService;
import com.viontech.keliu.util.DateUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Profile;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
/**
* .
*
* @author 谢明辉
* @date 2021/11/26
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
public class MainTest {
@Resource
private OpsClientService opsClientService;
@Resource
private TrafficService trafficService;
@Test
public void test() {
Traffic traffic = trafficService.selectByPrimaryKey(5808875);
TrafficVo trafficVo = new TrafficVo(traffic);
ETrafficModel e = new ETrafficModel();
Date eventTime = trafficVo.getEventTime();
e.setEventTime(DateUtil.format(DateUtil.FORMAT_FULL, eventTime));
e.setPicName(UUID.randomUUID() + ".pic");
e.setLocation(trafficVo.getLocationName());
e.setPlateNumber(trafficVo.getPlateNumber());
Map<String, DictCode> vehicleTypeDict = opsClientService.vehicleTypeDict();
Map<String, DictCode> vehicleColorDict = opsClientService.vehicleColorDict();
Map<String, DictCode> plateColorDict = opsClientService.plateColorDict();
Map<String, DictCode> vehicleBrandDict = opsClientService.vehicleBrandDict();
String plateColor = Optional.ofNullable(plateColorDict.get(trafficVo.getPlateColor())).map(DictCode::getName).orElse("未识别");
String vehicleType = Optional.ofNullable(vehicleTypeDict.get(trafficVo.getVehicleType())).map(DictCode::getName).orElse("未识别");
String vehicleBrand = Optional.ofNullable(vehicleBrandDict.get(trafficVo.getVehicleLogo())).map(DictCode::getName).orElse("未识别");
String vehicleColor = Optional.ofNullable(vehicleColorDict.get(trafficVo.getVehicleColor())).map(DictCode::getName).orElse("未识别");
e.setPlateColor(plateColor);
e.setVehicleType(vehicleType);
e.setVehicleBrand(vehicleBrand);
e.setVehicleColor(vehicleColor);
}
}
......@@ -56,5 +56,8 @@
<table delimitIdentifiers="true" tableName="d_traffic_face" alias="trafficFace" domainObjectName="TrafficFace">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<table delimitIdentifiers="true" tableName="d_export_data" alias="exportData" domainObjectName="ExportData">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
</context>
</generatorConfiguration>
......@@ -284,7 +284,8 @@ CREATE TABLE IF NOT EXISTS s_content
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
name VARCHAR(64) NOT NULL COMMENT '名称',
type VARCHAR(32) COMMENT '分组',
content TEXT COMMENT '内容'
content TEXT COMMENT '内容',
unique key `s_content_type_name_unique` (type, name)
);
insert into s_content(name, content, type)
values ('defaultConfig',
......@@ -294,8 +295,6 @@ insert into s_content(name, content, type)
values ('defaultConfigTemplate',
'<?xml version="1.0" encoding="GBK"?><root><短时录像设置><启用><AttribType>4</AttribType><AttribInfo>是否开启录像</AttribInfo><AttribDefault>0</AttribDefault><AttribRange /></启用><是否画框><AttribType>4</AttribType><AttribInfo>是否画框</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></是否画框><向前录像时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>5</AttribDefault><AttribRange>0-1000</AttribRange></向前录像时间><向后录像时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>5</AttribDefault><AttribRange>0-1000</AttribRange></向后录像时间><录像最大缓存时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>60</AttribDefault><AttribRange>0-1000</AttribRange></录像最大缓存时间></短时录像设置><车辆属性识别><识别车辆类型><AttribType>4</AttribType><AttribInfo>识别车辆类型</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车辆类型><识别车标><AttribType>4</AttribType><AttribInfo>识别车标</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车标><识别车身颜色><AttribType>4</AttribType><AttribInfo>识别车身颜色</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车身颜色><识别驾驶员><AttribType>4</AttribType><AttribInfo>识别驾驶员</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别驾驶员><识别危险品标识><AttribType>4</AttribType><AttribInfo>识别危险品标识</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别危险品标识></车辆属性识别><功能配置><抓拍参数配置><路口电警><卡口><输出卡口图片><AttribType>4</AttribType><AttribInfo/><AttribDefault>1</AttribDefault><AttribRange /></输出卡口图片><卡口抓两张图><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></卡口抓两张图><上行物体不输出卡口结果><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></上行物体不输出卡口结果><下行物体不输出卡口结果><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></下行物体不输出卡口结果><无牌车辆不输出卡口结果><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></无牌车辆不输出卡口结果><行人非机动车不输出卡口结果><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></行人非机动车不输出卡口结果></卡口></路口电警></抓拍参数配置></功能配置><算法参数设置><是否启用高速模式><AttribType>4</AttribType><AttribInfo>应用于车辆通常速度较高且视频卡顿场景</AttribInfo><AttribDefault>0</AttribDefault><AttribRange /></是否启用高速模式><车牌识别><车牌缩放比率><AttribType>1</AttribType><AttribInfo>适用非机动车和摩托车,车牌宽目标40-80像素</AttribInfo><AttribDefault>0.800000</AttribDefault><AttribRange>0.300000-3.000000</AttribRange></车牌缩放比率><本地车牌首字母><AttribType>3</AttribType><AttribInfo>只摩托车</AttribInfo><AttribDefault>0</AttribDefault><AttribRange>26:0-A&amp;1-B&amp;2-C&amp;3-D&amp;4-E&amp;5-F&amp;6-G&amp;7-H&amp;8-I&amp;9-J&amp;10-K&amp;11-L&amp;12-M&amp;13-N&amp;14-O&amp;15-P&amp;16-Q&amp;17-R&amp;18-S&amp;19-T&amp;20-U&amp;21-V&amp;22-W&amp;23-X&amp;24-Y&amp;25-Z</AttribRange></本地车牌首字母><车牌最小宽度><AttribType>0</AttribType><AttribInfo/><AttribDefault>90</AttribDefault><AttribRange>60-230</AttribRange></车牌最小宽度><车牌最大宽度><AttribType>0</AttribType><AttribInfo/><AttribDefault>130</AttribDefault><AttribRange>60-230</AttribRange></车牌最大宽度><本地汉字><AttribType>3</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange>31:0-京&amp;1-沪&amp;2-津&amp;3-渝&amp;4-冀&amp;5-晋&amp;6-蒙&amp;7-辽&amp;8-吉&amp;9-黑&amp;10-苏&amp;11-浙&amp;12-皖&amp;13-闽&amp;14-赣&amp;15-鲁&amp;16-豫&amp;17-鄂&amp;18-湘&amp;19-粤&amp;20-桂&amp;21-琼&amp;22-川&amp;23-贵&amp;24-云&amp;25-藏&amp;26-陕&amp;27-甘&amp;28-青&amp;29-宁&amp;30-新</AttribRange></本地汉字><是否识别新能源车牌><AttribType>4</AttribType><AttribInfo/><AttribDefault>1</AttribDefault><AttribRange /></是否识别新能源车牌></车牌识别><调试信息><字体大小><AttribType>0</AttribType><AttribInfo>root\算法参数设置\调试信息\字体大小</AttribInfo><AttribDefault>20</AttribDefault><AttribRange>10-100</AttribRange></字体大小><是否显示Scale><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示Scale><是否显示耗时><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示耗时><是否显示版本><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示版本></调试信息></算法参数设置><车牌宽度范围设定方法><AttribType>3</AttribType><AttribInfo/><AttribDefault>1</AttribDefault><AttribRange>2:0-手动设置&amp;1-自动计算</AttribRange></车牌宽度范围设定方法></root>',
'defaultConfig');
insert into s_content(name, content, type)
values ('illegalStopDefaultConfig',
'<?xml version="1.0" encoding="GBK"?><root><短时录像设置><录像最大缓存时间>200</录像最大缓存时间><向前录像时间>180</向前录像时间><向后录像时间>20</向后录像时间><启用>0</启用><是否画框>0</是否画框></短时录像设置><算法参数设置><是否输出无牌结果>1</是否输出无牌结果><车牌识别><本地汉字>0</本地汉字><车牌最小宽度>60</车牌最小宽度><车牌最大宽度>150</车牌最大宽度><是否识别新能源车牌>0</是否识别新能源车牌></车牌识别><车头检测分数阈值>50</车头检测分数阈值><车尾检测分数阈值>50</车尾检测分数阈值><是否画检测区域>0</是否画检测区域><同时计时抓拍>0</同时计时抓拍><违法图片间隔时间-秒><时间1>10</时间1><时间2>160</时间2><时间3>10</时间3></违法图片间隔时间-秒></算法参数设置><动态跟踪参数><使用球机3D定位-重启生效>0</使用球机3D定位-重启生效></动态跟踪参数><车辆属性识别><识别车辆类型>0</识别车辆类型><识别车标>0</识别车标><识别车身颜色>0</识别车身颜色><识别驾驶员>0</识别驾驶员><识别危险品标识>0</识别危险品标识></车辆属性识别></root>',
......@@ -304,18 +303,35 @@ insert into s_content(name, content, type)
values ('illegalStopDefaultConfigTemplate',
'<?xml version="1.0" encoding="GBK"?><root><短时录像设置><启用><AttribType>4</AttribType><AttribInfo>是否开启录像</AttribInfo><AttribDefault>0</AttribDefault><AttribRange /></启用><是否画框><AttribType>4</AttribType><AttribInfo>是否画框</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></是否画框><向前录像时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>5</AttribDefault><AttribRange>0-1000</AttribRange></向前录像时间><向后录像时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>5</AttribDefault><AttribRange>0-1000</AttribRange></向后录像时间><录像最大缓存时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>60</AttribDefault><AttribRange>0-1000</AttribRange></录像最大缓存时间></短时录像设置><车辆属性识别><识别车辆类型><AttribType>4</AttribType><AttribInfo>识别车辆类型</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车辆类型><识别车标><AttribType>4</AttribType><AttribInfo>识别车标</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车标><识别车身颜色><AttribType>4</AttribType><AttribInfo>识别车身颜色</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车身颜色><识别驾驶员><AttribType>4</AttribType><AttribInfo>识别驾驶员</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别驾驶员><识别危险品标识><AttribType>4</AttribType><AttribInfo>识别危险品标识</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别危险品标识></车辆属性识别><算法功能><是否开启车牌验证同一辆车><AttribType>4</AttribType><AttribInfo>是否开启车牌验证同一辆车</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></是否开启车牌验证同一辆车></算法功能><算法参数设置><抓拍前等待时间-秒><AttribType>0</AttribType><AttribInfo>抓拍前等待时间</AttribInfo><AttribDefault>2</AttribDefault><AttribRange>0-600</AttribRange></抓拍前等待时间-秒><违法图片间隔时间-秒><时间1><AttribType>0</AttribType><AttribInfo>图1图2间隔时间</AttribInfo><AttribDefault>10</AttribDefault><AttribRange>0-1000</AttribRange></时间1><时间2><AttribType>0</AttribType><AttribInfo>图2图3间隔时间</AttribInfo><AttribDefault>10</AttribDefault><AttribRange>0-1000</AttribRange></时间2><时间3><AttribType>0</AttribType><AttribInfo>图3图4间隔时间</AttribInfo><AttribDefault>10</AttribDefault><AttribRange>0-1000</AttribRange></时间3></违法图片间隔时间-秒><同时计时抓拍><AttribType>4</AttribType><AttribInfo>同时计时抓拍</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></同时计时抓拍><车头检测分数阈值><AttribType>0</AttribType><AttribInfo>车检分数阈值</AttribInfo><AttribDefault>50</AttribDefault><AttribRange>10-100</AttribRange></车头检测分数阈值><车尾检测分数阈值><AttribType>0</AttribType><AttribInfo>车检分数阈值</AttribInfo><AttribDefault>50</AttribDefault><AttribRange>10-100</AttribRange></车尾检测分数阈值><是否画检测区域><AttribType>4</AttribType><AttribInfo>是否画检测区域</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></是否画检测区域><是否输出无牌结果><AttribType>4</AttribType><AttribInfo>是否输出无牌结果</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></是否输出无牌结果><调试信息><字体大小><AttribType>0</AttribType><AttribInfo/><AttribDefault>20</AttribDefault><AttribRange>10-100</AttribRange></字体大小><是否显示Scale><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示Scale><是否显示耗时><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示耗时><是否显示版本><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示版本></调试信息><车牌识别><本地汉字><AttribType>3</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange>31:0-京&amp;1-沪&amp;2-津&amp;3-渝&amp;4-冀&amp;5-晋&amp;6-蒙&amp;7-辽&amp;8-吉&amp;9-黑&amp;10-苏&amp;11-浙&amp;12-皖&amp;13-闽&amp;14-赣&amp;15-鲁&amp;16-豫&amp;17-鄂&amp;18-湘&amp;19-粤&amp;20-桂&amp;21-琼&amp;22-川&amp;23-贵&amp;24-云&amp;25-藏&amp;26-陕&amp;27-甘&amp;28-青&amp;29-宁&amp;30-新</AttribRange></本地汉字><车牌最小宽度><AttribType>0</AttribType><AttribInfo/><AttribDefault>90</AttribDefault><AttribRange>60-230</AttribRange></车牌最小宽度><车牌最大宽度><AttribType>0</AttribType><AttribInfo/><AttribDefault>130</AttribDefault><AttribRange>60-230</AttribRange></车牌最大宽度><是否识别新能源车牌><AttribType>4</AttribType><AttribInfo/><AttribDefault>1</AttribDefault><AttribRange /></是否识别新能源车牌></车牌识别></算法参数设置><动态跟踪参数><使用球机3D定位-重启生效><AttribType>4</AttribType><AttribInfo>使用球机3D定位</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></使用球机3D定位-重启生效></动态跟踪参数></root>',
'defaultConfig');
insert into s_content(type, name, content)
values ('platformConfig', 'imageKeepConfig', '{"type":1,"keep":7,"rate":75}');
-- 日志表
CREATE TABLE IF NOT EXISTS s_log
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
date_time timestamp NOT NULL default CURRENT_TIMESTAMP COMMENT '名称',
date_time timestamp NOT NULL default CURRENT_TIMESTAMP COMMENT '时间',
username VARCHAR(32) COMMENT '用户名',
log_type int not null default -1 comment '操作类型',
content varchar(256) COMMENT '内容',
INDEX s_log_date_time_idx (date_time)
);
-- 数据导出表
CREATE TABLE IF NOT exists d_export_data
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
create_time timestamp NOT NULL default CURRENT_TIMESTAMP COMMENT '时间',
name varchar(64) COMMENT '名称',
type int not null comment '数据类型',
count bigint not null default 0 comment '数量',
with_pic int not null default 0 comment '下载图片',
with_video int not null default 0 comment '下载视频',
param varchar(256) not null comment '参数',
path varchar(512) comment '导出文件列表',
status int not null default 0 comment '状态'
);
-- 分表
alter TABLE d_traffic PARTITION by RANGE (UNIX_TIMESTAMP(event_time))(
......@@ -369,27 +385,6 @@ BEGIN
DEALLOCATE PREPARE stmt;
SET v_maxdate = v_maxdate + INTERVAL 1 DAY; # 最大值 加一操作
END WHILE;
-- 删除旧分区
SELECT min(CAST(FROM_UNIXTIME(partition_description) as date)) AS val
INTO v_mindate
FROM INFORMATION_SCHEMA.PARTITIONS
WHERE TABLE_NAME = v_table_name
AND TABLE_SCHEMA = v_schema;
-- 删除7天前的旧分区
WHILE v_mindate <= (v_sysdate - INTERVAL 7 DAY)
DO
SET v_pt = date_format(v_mindate - INTERVAL 1 DAY, '%Y%m%d');
SET @sql = concat('alter table ', v_table_name, ' drop partition ', v_table_name, v_pt);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET v_mindate = v_mindate + INTERVAL 1 DAY;
END WHILE;
END$$
delimiter ;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!