Commit 42da1656 by xmh

<feat> 数据统计值写入和查询

<feat> 数据统计值表 d_data_statistic
1 parent beb46b1c
Showing 25 changed files with 2137 additions and 214 deletions
......@@ -9,7 +9,6 @@ import java.io.Serializable;
public abstract class BaseModel implements Serializable {
private Long count;
private Long id;
private Integer hour;
public BaseModel() {
super();
......@@ -30,13 +29,4 @@ public abstract class BaseModel implements Serializable {
public void setId(Long id) {
this.id = id;
}
public Integer getHour() {
return hour;
}
public BaseModel setHour(Integer hour) {
this.hour = hour;
return this;
}
}
package com.viontech.fanxing.commons.model;
import com.viontech.fanxing.commons.base.BaseModel;
import java.util.Date;
public class DataStatistic extends BaseModel {
private Long id;
private Long taskId;
private String taskName;
private Date date;
private Integer hour;
private Integer traffic;
private Integer behavior;
private Integer flow;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getTaskId() {
return taskId;
}
public void setTaskId(Long taskId) {
this.taskId = taskId;
}
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName == null ? null : taskName.trim();
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Integer getHour() {
return hour;
}
public void setHour(Integer hour) {
this.hour = hour;
}
public Integer getTraffic() {
return traffic;
}
public void setTraffic(Integer traffic) {
this.traffic = traffic;
}
public Integer getBehavior() {
return behavior;
}
public void setBehavior(Integer behavior) {
this.behavior = behavior;
}
public Integer getFlow() {
return flow;
}
public void setFlow(Integer flow) {
this.flow = flow;
}
}
\ 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.Iterator;
import java.util.List;
import java.util.Set;
public class DataStatisticExample extends BaseExample {
public DataStatisticExample() {
super();
tableName = "d_data_statistic";
tableAlias = "dataStatistic";
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_data_statistic";
}
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));
}
protected void addCriterionForJDBCDate(String condition, Date value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
addCriterion(condition, new java.sql.Date(value.getTime()), property);
}
protected void addCriterionForJDBCDate(String condition, List<Date> values, String property) {
if (values == null || values.size() == 0) {
throw new RuntimeException("Value list for " + property + " cannot be null or empty");
}
List<java.sql.Date> dateList = new ArrayList<java.sql.Date>();
Iterator<Date> iter = values.iterator();
while (iter.hasNext()) {
dateList.add(new java.sql.Date(iter.next().getTime()));
}
addCriterion(condition, dateList, property);
}
protected void addCriterionForJDBCDate(String condition, Date value1, Date value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
addCriterion(condition, new java.sql.Date(value1.getTime()), new java.sql.Date(value2.getTime()), property);
}
public Criteria andIdIsNull() {
addCriterion("`dataStatistic`.id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("`dataStatistic`.id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(Long value) {
addCriterion("`dataStatistic`.id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(Long value) {
addCriterion("`dataStatistic`.id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(Long value) {
addCriterion("`dataStatistic`.id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(Long value) {
addCriterion("`dataStatistic`.id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(Long value) {
addCriterion("`dataStatistic`.id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(Long value) {
addCriterion("`dataStatistic`.id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<Long> values) {
addCriterion("`dataStatistic`.id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<Long> values) {
addCriterion("`dataStatistic`.id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(Long value1, Long value2) {
addCriterion("`dataStatistic`.id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(Long value1, Long value2) {
addCriterion("`dataStatistic`.id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andTaskIdIsNull() {
addCriterion("`dataStatistic`.task_id is null");
return (Criteria) this;
}
public Criteria andTaskIdIsNotNull() {
addCriterion("`dataStatistic`.task_id is not null");
return (Criteria) this;
}
public Criteria andTaskIdEqualTo(Long value) {
addCriterion("`dataStatistic`.task_id =", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdNotEqualTo(Long value) {
addCriterion("`dataStatistic`.task_id <>", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdGreaterThan(Long value) {
addCriterion("`dataStatistic`.task_id >", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdGreaterThanOrEqualTo(Long value) {
addCriterion("`dataStatistic`.task_id >=", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdLessThan(Long value) {
addCriterion("`dataStatistic`.task_id <", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdLessThanOrEqualTo(Long value) {
addCriterion("`dataStatistic`.task_id <=", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdIn(List<Long> values) {
addCriterion("`dataStatistic`.task_id in", values, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdNotIn(List<Long> values) {
addCriterion("`dataStatistic`.task_id not in", values, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdBetween(Long value1, Long value2) {
addCriterion("`dataStatistic`.task_id between", value1, value2, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdNotBetween(Long value1, Long value2) {
addCriterion("`dataStatistic`.task_id not between", value1, value2, "taskId");
return (Criteria) this;
}
public Criteria andTaskNameIsNull() {
addCriterion("`dataStatistic`.task_name is null");
return (Criteria) this;
}
public Criteria andTaskNameIsNotNull() {
addCriterion("`dataStatistic`.task_name is not null");
return (Criteria) this;
}
public Criteria andTaskNameEqualTo(String value) {
addCriterion("`dataStatistic`.task_name =", value, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameNotEqualTo(String value) {
addCriterion("`dataStatistic`.task_name <>", value, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameGreaterThan(String value) {
addCriterion("`dataStatistic`.task_name >", value, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameGreaterThanOrEqualTo(String value) {
addCriterion("`dataStatistic`.task_name >=", value, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameLessThan(String value) {
addCriterion("`dataStatistic`.task_name <", value, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameLessThanOrEqualTo(String value) {
addCriterion("`dataStatistic`.task_name <=", value, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameLike(String value) {
addCriterion("`dataStatistic`.task_name like", value, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameNotLike(String value) {
addCriterion("`dataStatistic`.task_name not like", value, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameIn(List<String> values) {
addCriterion("`dataStatistic`.task_name in", values, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameNotIn(List<String> values) {
addCriterion("`dataStatistic`.task_name not in", values, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameBetween(String value1, String value2) {
addCriterion("`dataStatistic`.task_name between", value1, value2, "taskName");
return (Criteria) this;
}
public Criteria andTaskNameNotBetween(String value1, String value2) {
addCriterion("`dataStatistic`.task_name not between", value1, value2, "taskName");
return (Criteria) this;
}
public Criteria andDateIsNull() {
addCriterion("`dataStatistic`.`date` is null");
return (Criteria) this;
}
public Criteria andDateIsNotNull() {
addCriterion("`dataStatistic`.`date` is not null");
return (Criteria) this;
}
public Criteria andDateEqualTo(Date value) {
addCriterionForJDBCDate("`dataStatistic`.`date` =", value, "date");
return (Criteria) this;
}
public Criteria andDateNotEqualTo(Date value) {
addCriterionForJDBCDate("`dataStatistic`.`date` <>", value, "date");
return (Criteria) this;
}
public Criteria andDateGreaterThan(Date value) {
addCriterionForJDBCDate("`dataStatistic`.`date` >", value, "date");
return (Criteria) this;
}
public Criteria andDateGreaterThanOrEqualTo(Date value) {
addCriterionForJDBCDate("`dataStatistic`.`date` >=", value, "date");
return (Criteria) this;
}
public Criteria andDateLessThan(Date value) {
addCriterionForJDBCDate("`dataStatistic`.`date` <", value, "date");
return (Criteria) this;
}
public Criteria andDateLessThanOrEqualTo(Date value) {
addCriterionForJDBCDate("`dataStatistic`.`date` <=", value, "date");
return (Criteria) this;
}
public Criteria andDateIn(List<Date> values) {
addCriterionForJDBCDate("`dataStatistic`.`date` in", values, "date");
return (Criteria) this;
}
public Criteria andDateNotIn(List<Date> values) {
addCriterionForJDBCDate("`dataStatistic`.`date` not in", values, "date");
return (Criteria) this;
}
public Criteria andDateBetween(Date value1, Date value2) {
addCriterionForJDBCDate("`dataStatistic`.`date` between", value1, value2, "date");
return (Criteria) this;
}
public Criteria andDateNotBetween(Date value1, Date value2) {
addCriterionForJDBCDate("`dataStatistic`.`date` not between", value1, value2, "date");
return (Criteria) this;
}
public Criteria andHourIsNull() {
addCriterion("`dataStatistic`.`hour` is null");
return (Criteria) this;
}
public Criteria andHourIsNotNull() {
addCriterion("`dataStatistic`.`hour` is not null");
return (Criteria) this;
}
public Criteria andHourEqualTo(Integer value) {
addCriterion("`dataStatistic`.`hour` =", value, "hour");
return (Criteria) this;
}
public Criteria andHourNotEqualTo(Integer value) {
addCriterion("`dataStatistic`.`hour` <>", value, "hour");
return (Criteria) this;
}
public Criteria andHourGreaterThan(Integer value) {
addCriterion("`dataStatistic`.`hour` >", value, "hour");
return (Criteria) this;
}
public Criteria andHourGreaterThanOrEqualTo(Integer value) {
addCriterion("`dataStatistic`.`hour` >=", value, "hour");
return (Criteria) this;
}
public Criteria andHourLessThan(Integer value) {
addCriterion("`dataStatistic`.`hour` <", value, "hour");
return (Criteria) this;
}
public Criteria andHourLessThanOrEqualTo(Integer value) {
addCriterion("`dataStatistic`.`hour` <=", value, "hour");
return (Criteria) this;
}
public Criteria andHourIn(List<Integer> values) {
addCriterion("`dataStatistic`.`hour` in", values, "hour");
return (Criteria) this;
}
public Criteria andHourNotIn(List<Integer> values) {
addCriterion("`dataStatistic`.`hour` not in", values, "hour");
return (Criteria) this;
}
public Criteria andHourBetween(Integer value1, Integer value2) {
addCriterion("`dataStatistic`.`hour` between", value1, value2, "hour");
return (Criteria) this;
}
public Criteria andHourNotBetween(Integer value1, Integer value2) {
addCriterion("`dataStatistic`.`hour` not between", value1, value2, "hour");
return (Criteria) this;
}
public Criteria andTrafficIsNull() {
addCriterion("`dataStatistic`.traffic is null");
return (Criteria) this;
}
public Criteria andTrafficIsNotNull() {
addCriterion("`dataStatistic`.traffic is not null");
return (Criteria) this;
}
public Criteria andTrafficEqualTo(Integer value) {
addCriterion("`dataStatistic`.traffic =", value, "traffic");
return (Criteria) this;
}
public Criteria andTrafficNotEqualTo(Integer value) {
addCriterion("`dataStatistic`.traffic <>", value, "traffic");
return (Criteria) this;
}
public Criteria andTrafficGreaterThan(Integer value) {
addCriterion("`dataStatistic`.traffic >", value, "traffic");
return (Criteria) this;
}
public Criteria andTrafficGreaterThanOrEqualTo(Integer value) {
addCriterion("`dataStatistic`.traffic >=", value, "traffic");
return (Criteria) this;
}
public Criteria andTrafficLessThan(Integer value) {
addCriterion("`dataStatistic`.traffic <", value, "traffic");
return (Criteria) this;
}
public Criteria andTrafficLessThanOrEqualTo(Integer value) {
addCriterion("`dataStatistic`.traffic <=", value, "traffic");
return (Criteria) this;
}
public Criteria andTrafficIn(List<Integer> values) {
addCriterion("`dataStatistic`.traffic in", values, "traffic");
return (Criteria) this;
}
public Criteria andTrafficNotIn(List<Integer> values) {
addCriterion("`dataStatistic`.traffic not in", values, "traffic");
return (Criteria) this;
}
public Criteria andTrafficBetween(Integer value1, Integer value2) {
addCriterion("`dataStatistic`.traffic between", value1, value2, "traffic");
return (Criteria) this;
}
public Criteria andTrafficNotBetween(Integer value1, Integer value2) {
addCriterion("`dataStatistic`.traffic not between", value1, value2, "traffic");
return (Criteria) this;
}
public Criteria andBehaviorIsNull() {
addCriterion("`dataStatistic`.behavior is null");
return (Criteria) this;
}
public Criteria andBehaviorIsNotNull() {
addCriterion("`dataStatistic`.behavior is not null");
return (Criteria) this;
}
public Criteria andBehaviorEqualTo(Integer value) {
addCriterion("`dataStatistic`.behavior =", value, "behavior");
return (Criteria) this;
}
public Criteria andBehaviorNotEqualTo(Integer value) {
addCriterion("`dataStatistic`.behavior <>", value, "behavior");
return (Criteria) this;
}
public Criteria andBehaviorGreaterThan(Integer value) {
addCriterion("`dataStatistic`.behavior >", value, "behavior");
return (Criteria) this;
}
public Criteria andBehaviorGreaterThanOrEqualTo(Integer value) {
addCriterion("`dataStatistic`.behavior >=", value, "behavior");
return (Criteria) this;
}
public Criteria andBehaviorLessThan(Integer value) {
addCriterion("`dataStatistic`.behavior <", value, "behavior");
return (Criteria) this;
}
public Criteria andBehaviorLessThanOrEqualTo(Integer value) {
addCriterion("`dataStatistic`.behavior <=", value, "behavior");
return (Criteria) this;
}
public Criteria andBehaviorIn(List<Integer> values) {
addCriterion("`dataStatistic`.behavior in", values, "behavior");
return (Criteria) this;
}
public Criteria andBehaviorNotIn(List<Integer> values) {
addCriterion("`dataStatistic`.behavior not in", values, "behavior");
return (Criteria) this;
}
public Criteria andBehaviorBetween(Integer value1, Integer value2) {
addCriterion("`dataStatistic`.behavior between", value1, value2, "behavior");
return (Criteria) this;
}
public Criteria andBehaviorNotBetween(Integer value1, Integer value2) {
addCriterion("`dataStatistic`.behavior not between", value1, value2, "behavior");
return (Criteria) this;
}
public Criteria andFlowIsNull() {
addCriterion("`dataStatistic`.flow is null");
return (Criteria) this;
}
public Criteria andFlowIsNotNull() {
addCriterion("`dataStatistic`.flow is not null");
return (Criteria) this;
}
public Criteria andFlowEqualTo(Integer value) {
addCriterion("`dataStatistic`.flow =", value, "flow");
return (Criteria) this;
}
public Criteria andFlowNotEqualTo(Integer value) {
addCriterion("`dataStatistic`.flow <>", value, "flow");
return (Criteria) this;
}
public Criteria andFlowGreaterThan(Integer value) {
addCriterion("`dataStatistic`.flow >", value, "flow");
return (Criteria) this;
}
public Criteria andFlowGreaterThanOrEqualTo(Integer value) {
addCriterion("`dataStatistic`.flow >=", value, "flow");
return (Criteria) this;
}
public Criteria andFlowLessThan(Integer value) {
addCriterion("`dataStatistic`.flow <", value, "flow");
return (Criteria) this;
}
public Criteria andFlowLessThanOrEqualTo(Integer value) {
addCriterion("`dataStatistic`.flow <=", value, "flow");
return (Criteria) this;
}
public Criteria andFlowIn(List<Integer> values) {
addCriterion("`dataStatistic`.flow in", values, "flow");
return (Criteria) this;
}
public Criteria andFlowNotIn(List<Integer> values) {
addCriterion("`dataStatistic`.flow not in", values, "flow");
return (Criteria) this;
}
public Criteria andFlowBetween(Integer value1, Integer value2) {
addCriterion("`dataStatistic`.flow between", value1, value2, "flow");
return (Criteria) this;
}
public Criteria andFlowNotBetween(Integer value1, Integer value2) {
addCriterion("`dataStatistic`.flow not between", value1, value2, "flow");
return (Criteria) this;
}
}
public static class ColumnContainer extends ColumnContainerBase {
protected ColumnContainer(String tableName) {
super(tableName);
}
public ColumnContainer hasIdColumn() {
addColumnStr("`dataStatistic`.id as dataStatistic_id ");
return (ColumnContainer) this;
}
public ColumnContainer hasTaskIdColumn() {
addColumnStr("`dataStatistic`.task_id as dataStatistic_task_id ");
return (ColumnContainer) this;
}
public ColumnContainer hasTaskNameColumn() {
addColumnStr("`dataStatistic`.task_name as dataStatistic_task_name ");
return (ColumnContainer) this;
}
public ColumnContainer hasDateColumn() {
addColumnStr("`dataStatistic`.`date` as `dataStatistic_date` ");
return (ColumnContainer) this;
}
public ColumnContainer hasHourColumn() {
addColumnStr("`dataStatistic`.`hour` as `dataStatistic_hour` ");
return (ColumnContainer) this;
}
public ColumnContainer hasTrafficColumn() {
addColumnStr("`dataStatistic`.traffic as dataStatistic_traffic ");
return (ColumnContainer) this;
}
public ColumnContainer hasBehaviorColumn() {
addColumnStr("`dataStatistic`.behavior as dataStatistic_behavior ");
return (ColumnContainer) this;
}
public ColumnContainer hasFlowColumn() {
addColumnStr("`dataStatistic`.flow as dataStatistic_flow ");
return (ColumnContainer) this;
}
}
}
\ No newline at end of file
package com.viontech.fanxing.commons.vo;
import com.viontech.fanxing.commons.model.DataStatistic;
import com.viontech.fanxing.commons.vobase.DataStatisticVoBase;
public class DataStatisticVo extends DataStatisticVoBase {
public DataStatisticVo() {
super();
}
public DataStatisticVo(DataStatistic dataStatistic) {
super(dataStatistic);
}
}
\ 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.DataStatistic;
import java.util.ArrayList;
import java.util.Date;
public class DataStatisticVoBase extends DataStatistic implements VoInterface<DataStatistic> {
private DataStatistic dataStatistic;
@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<Long> taskId_arr;
@JsonIgnore
private Long taskId_gt;
@JsonIgnore
private Long taskId_lt;
@JsonIgnore
private Long taskId_gte;
@JsonIgnore
private Long taskId_lte;
@JsonIgnore
private ArrayList<String> taskName_arr;
@JsonIgnore
private String taskName_like;
@JsonIgnore
private ArrayList<Date> date_arr;
@JsonIgnore
private Date date_gt;
@JsonIgnore
private Date date_lt;
@JsonIgnore
private Date date_gte;
@JsonIgnore
private Date date_lte;
@JsonIgnore
private ArrayList<Integer> hour_arr;
@JsonIgnore
private Integer hour_gt;
@JsonIgnore
private Integer hour_lt;
@JsonIgnore
private Integer hour_gte;
@JsonIgnore
private Integer hour_lte;
@JsonIgnore
private ArrayList<Integer> traffic_arr;
@JsonIgnore
private Integer traffic_gt;
@JsonIgnore
private Integer traffic_lt;
@JsonIgnore
private Integer traffic_gte;
@JsonIgnore
private Integer traffic_lte;
@JsonIgnore
private ArrayList<Integer> behavior_arr;
@JsonIgnore
private Integer behavior_gt;
@JsonIgnore
private Integer behavior_lt;
@JsonIgnore
private Integer behavior_gte;
@JsonIgnore
private Integer behavior_lte;
@JsonIgnore
private ArrayList<Integer> flow_arr;
@JsonIgnore
private Integer flow_gt;
@JsonIgnore
private Integer flow_lt;
@JsonIgnore
private Integer flow_gte;
@JsonIgnore
private Integer flow_lte;
public DataStatisticVoBase() {
this(null);
}
public DataStatisticVoBase(DataStatistic dataStatistic) {
if(dataStatistic == null) {
dataStatistic = new DataStatistic();
}
this.dataStatistic = dataStatistic;
}
@JsonIgnore
public DataStatistic getModel() {
return dataStatistic;
}
public void setModel(DataStatistic dataStatistic) {
this.dataStatistic = dataStatistic;
}
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<Long> getTaskId_arr() {
return taskId_arr;
}
public void setTaskId_arr(ArrayList<Long> taskId_arr) {
this.taskId_arr = taskId_arr;
}
public Long getTaskId_gt() {
return taskId_gt;
}
public void setTaskId_gt(Long taskId_gt) {
this.taskId_gt = taskId_gt;
}
public Long getTaskId_lt() {
return taskId_lt;
}
public void setTaskId_lt(Long taskId_lt) {
this.taskId_lt = taskId_lt;
}
public Long getTaskId_gte() {
return taskId_gte;
}
public void setTaskId_gte(Long taskId_gte) {
this.taskId_gte = taskId_gte;
}
public Long getTaskId_lte() {
return taskId_lte;
}
public void setTaskId_lte(Long taskId_lte) {
this.taskId_lte = taskId_lte;
}
public Long getTaskId() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getTaskId();
}
public void setTaskId(Long taskId) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setTaskId(taskId);
}
public ArrayList<String> getTaskName_arr() {
return taskName_arr;
}
public void setTaskName_arr(ArrayList<String> taskName_arr) {
this.taskName_arr = taskName_arr;
}
public String getTaskName_like() {
return taskName_like;
}
public void setTaskName_like(String taskName_like) {
this.taskName_like = taskName_like;
}
public String getTaskName() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getTaskName();
}
public void setTaskName(String taskName) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setTaskName(taskName);
}
public ArrayList<Date> getDate_arr() {
return date_arr;
}
public void setDate_arr(ArrayList<Date> date_arr) {
this.date_arr = date_arr;
}
public Date getDate_gt() {
return date_gt;
}
public void setDate_gt(Date date_gt) {
this.date_gt = date_gt;
}
public Date getDate_lt() {
return date_lt;
}
public void setDate_lt(Date date_lt) {
this.date_lt = date_lt;
}
public Date getDate_gte() {
return date_gte;
}
public void setDate_gte(Date date_gte) {
this.date_gte = date_gte;
}
public Date getDate_lte() {
return date_lte;
}
public void setDate_lte(Date date_lte) {
this.date_lte = date_lte;
}
public Date getDate() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getDate();
}
public void setDate(Date date) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setDate(date);
}
public ArrayList<Integer> getHour_arr() {
return hour_arr;
}
public void setHour_arr(ArrayList<Integer> hour_arr) {
this.hour_arr = hour_arr;
}
public Integer getHour_gt() {
return hour_gt;
}
public void setHour_gt(Integer hour_gt) {
this.hour_gt = hour_gt;
}
public Integer getHour_lt() {
return hour_lt;
}
public void setHour_lt(Integer hour_lt) {
this.hour_lt = hour_lt;
}
public Integer getHour_gte() {
return hour_gte;
}
public void setHour_gte(Integer hour_gte) {
this.hour_gte = hour_gte;
}
public Integer getHour_lte() {
return hour_lte;
}
public void setHour_lte(Integer hour_lte) {
this.hour_lte = hour_lte;
}
public Integer getHour() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getHour();
}
public void setHour(Integer hour) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setHour(hour);
}
public ArrayList<Integer> getTraffic_arr() {
return traffic_arr;
}
public void setTraffic_arr(ArrayList<Integer> traffic_arr) {
this.traffic_arr = traffic_arr;
}
public Integer getTraffic_gt() {
return traffic_gt;
}
public void setTraffic_gt(Integer traffic_gt) {
this.traffic_gt = traffic_gt;
}
public Integer getTraffic_lt() {
return traffic_lt;
}
public void setTraffic_lt(Integer traffic_lt) {
this.traffic_lt = traffic_lt;
}
public Integer getTraffic_gte() {
return traffic_gte;
}
public void setTraffic_gte(Integer traffic_gte) {
this.traffic_gte = traffic_gte;
}
public Integer getTraffic_lte() {
return traffic_lte;
}
public void setTraffic_lte(Integer traffic_lte) {
this.traffic_lte = traffic_lte;
}
public Integer getTraffic() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getTraffic();
}
public void setTraffic(Integer traffic) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setTraffic(traffic);
}
public ArrayList<Integer> getBehavior_arr() {
return behavior_arr;
}
public void setBehavior_arr(ArrayList<Integer> behavior_arr) {
this.behavior_arr = behavior_arr;
}
public Integer getBehavior_gt() {
return behavior_gt;
}
public void setBehavior_gt(Integer behavior_gt) {
this.behavior_gt = behavior_gt;
}
public Integer getBehavior_lt() {
return behavior_lt;
}
public void setBehavior_lt(Integer behavior_lt) {
this.behavior_lt = behavior_lt;
}
public Integer getBehavior_gte() {
return behavior_gte;
}
public void setBehavior_gte(Integer behavior_gte) {
this.behavior_gte = behavior_gte;
}
public Integer getBehavior_lte() {
return behavior_lte;
}
public void setBehavior_lte(Integer behavior_lte) {
this.behavior_lte = behavior_lte;
}
public Integer getBehavior() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getBehavior();
}
public void setBehavior(Integer behavior) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setBehavior(behavior);
}
public ArrayList<Integer> getFlow_arr() {
return flow_arr;
}
public void setFlow_arr(ArrayList<Integer> flow_arr) {
this.flow_arr = flow_arr;
}
public Integer getFlow_gt() {
return flow_gt;
}
public void setFlow_gt(Integer flow_gt) {
this.flow_gt = flow_gt;
}
public Integer getFlow_lt() {
return flow_lt;
}
public void setFlow_lt(Integer flow_lt) {
this.flow_lt = flow_lt;
}
public Integer getFlow_gte() {
return flow_gte;
}
public void setFlow_gte(Integer flow_gte) {
this.flow_gte = flow_gte;
}
public Integer getFlow_lte() {
return flow_lte;
}
public void setFlow_lte(Integer flow_lte) {
this.flow_lte = flow_lte;
}
public Integer getFlow() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getFlow();
}
public void setFlow(Integer flow) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setFlow(flow);
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.model.FlowData;
import com.viontech.fanxing.commons.model.FlowEvent;
import com.viontech.fanxing.forward.model.TrafficFlowContent;
import com.viontech.fanxing.forward.util.CacheUtils;
import com.viontech.keliu.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -15,7 +14,6 @@ import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -41,6 +39,7 @@ public class TrafficFlowProcessor implements ItemProcessor<JSONObject, TrafficFl
log.info("收到 flow 消息 , 任务名称:[{}] , 消息ID:[{}]", taskName, eventRefid);
TrafficFlowContent content = new TrafficFlowContent();
content.setTaskName(taskName);
FlowEvent flowEvent = new FlowEvent();
flowEvent.setJsonData(item.toJSONString());
content.setFlowEvent(flowEvent);
......
......@@ -41,6 +41,7 @@ public class TrafficProcessor implements ItemProcessor<JSONObject, TrafficConten
log.info("收到 traffic 消息 , 任务名称:[{}] , 消息ID:[{}]", taskName, eventRefid);
TrafficContent content = new TrafficContent();
content.setTaskName(taskName);
Traffic traffic = new Traffic();
traffic.setJsonData(item.toJSONString());
content.setTraffic(traffic);
......
package com.viontech.fanxing.forward.batch.writer;
import com.viontech.fanxing.commons.model.Behavior;
import com.viontech.fanxing.forward.util.DataStatisticUtil;
import org.springframework.batch.item.ItemWriter;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
......@@ -25,9 +26,15 @@ public class BehaviorWriter implements ItemWriter<Behavior> {
":taskId,:eventType,:eventCate,:eventRefid,:eventTime,:eventData,:pics,:video,:channelUnid,:taskName,:eventDataNum)";
@Resource
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Resource
private DataStatisticUtil dataStatisticUtil;
@Override
public void write(List<? extends Behavior> items) throws Exception {
for (Behavior item : items) {
dataStatisticUtil.increase(item.getTaskId(), item.getTaskName(), item.getEventTime(), "behavior");
}
SqlParameterSource[] batchParam = SqlParameterSourceUtils.createBatch(items);
namedParameterJdbcTemplate.batchUpdate(INSERT_BEHAVIOR, batchParam);
}
......
......@@ -3,6 +3,7 @@ package com.viontech.fanxing.forward.batch.writer;
import com.viontech.fanxing.commons.model.FlowData;
import com.viontech.fanxing.commons.model.FlowEvent;
import com.viontech.fanxing.forward.model.TrafficFlowContent;
import com.viontech.fanxing.forward.util.DataStatisticUtil;
import org.springframework.batch.item.ItemWriter;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
......@@ -23,15 +24,13 @@ import java.util.List;
@Component
public class TrafficFlowWriter implements ItemWriter<TrafficFlowContent> {
private final static String INSERT_FLOW_EVENT = "insert into d_flow_event (" +
"task_id,event_type,event_time,event_id,device_code,device_name,location_code,location_name,json_data,pics,video_name,channel_unid) values(" +
":taskId,:eventType,:eventTime,:eventId,:deviceCode,:deviceName,:locationCode,:locationName,:jsonData,:pics,:videoName,:channelUnid)";
private final static String INSERT_FLOW_DATA = "insert into d_flow_data (" +
"flow_event_id,task_id,detection_type,road_code,direction_code,sample_dura,sample_num,velocity,velocity_unit,occupy,distance,queue_length,region_id,region_name,position_content,head_content,area,density,sample_num_in,sample_num_out,event_time,dist_time,time_occupy) values (" +
":flowEventId,:taskId,:detectionType,:roadCode,:directionCode,:sampleDura,:sampleNum,:velocity,:velocityUnit,:occupy,:distance,:queueLength,:regionId,:regionName,:positionContent,:headContent,:area,:density,:sampleNumIn,:sampleNumOut,:eventTime,:distTime,:timeOccupy)";
private final static String INSERT_FLOW_EVENT = "insert into d_flow_event (" + "task_id,event_type,event_time,event_id,device_code,device_name,location_code,location_name,json_data,pics,video_name,channel_unid) values(" + ":taskId,:eventType,:eventTime,:eventId,:deviceCode,:deviceName,:locationCode,:locationName,:jsonData,:pics,:videoName,:channelUnid)";
private final static String INSERT_FLOW_DATA = "insert into d_flow_data (" + "flow_event_id,task_id,detection_type,road_code,direction_code,sample_dura,sample_num,velocity,velocity_unit,occupy,distance,queue_length,region_id,region_name,position_content,head_content,area,density,sample_num_in,sample_num_out,event_time,dist_time,time_occupy) values (" + ":flowEventId,:taskId,:detectionType,:roadCode,:directionCode,:sampleDura,:sampleNum,:velocity,:velocityUnit,:occupy,:distance,:queueLength,:regionId,:regionName,:positionContent,:headContent,:area,:density,:sampleNumIn,:sampleNumOut,:eventTime,:distTime,:timeOccupy)";
@Resource
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Resource
private DataStatisticUtil dataStatisticUtil;
@Override
public void write(List<? extends TrafficFlowContent> list) {
......@@ -39,6 +38,8 @@ public class TrafficFlowWriter implements ItemWriter<TrafficFlowContent> {
List<FlowData> trafficFlowData = item.getFlowData();
FlowEvent flowEvent = item.getFlowEvent();
dataStatisticUtil.increase(flowEvent.getTaskId(), item.getTaskName(), flowEvent.getEventTime(), "flow");
SqlParameterSource flowEventParam = SqlParameterSourceUtils.createBatch(flowEvent)[0];
GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();
namedParameterJdbcTemplate.update(INSERT_FLOW_EVENT, flowEventParam, generatedKeyHolder);
......
......@@ -3,6 +3,7 @@ package com.viontech.fanxing.forward.batch.writer;
import com.viontech.fanxing.commons.model.Traffic;
import com.viontech.fanxing.commons.model.TrafficFace;
import com.viontech.fanxing.forward.model.TrafficContent;
import com.viontech.fanxing.forward.util.DataStatisticUtil;
import org.springframework.batch.item.ItemWriter;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
......@@ -25,20 +26,22 @@ import java.util.stream.Collectors;
@Component
public class TrafficWriter implements ItemWriter<TrafficContent> {
private final static String INSERT_TRAFFIC = "insert into d_traffic (" +
"task_id,event_cate,event_type,event_time,channel_unid,plate_color,plate_number,location_code,location_name,lane_code,direction_code,vehicle_type,vehicle_color,vehicle_logo,illegal_code,illegal_state,feature_annual_inspection_mark,feature_pendant,feature_decoration,feature_sun_shield,xcycle_type,event_id,special_type,with_helmet,json_data,pics,video_name,company) values(" +
":taskId,:eventCate,:eventType,:eventTime,:channelUnid,:plateColor,:plateNumber,:locationCode,:locationName,:laneCode,:directionCode,:vehicleType,:vehicleColor,:vehicleLogo,:illegalCode,:illegalState,:featureAnnualInspectionMark,:featurePendant,:featureDecoration,:featureSunShield,:xcycleType,:eventId,:specialType,:withHelmet,:jsonData,:pics,:videoName,:company)";
private final static String INSERT_TRAFFIC_FACE = "insert into d_traffic_face (" +
"traffic_id,state,sex,upper_color,lower_color,event_time) values (:trafficId,:state,:sex,:upperColor,:lowerColor,:eventTime)";
private final static String INSERT_TRAFFIC = "insert into d_traffic (" + "task_id,event_cate,event_type,event_time,channel_unid,plate_color,plate_number,location_code,location_name,lane_code,direction_code,vehicle_type,vehicle_color,vehicle_logo,illegal_code,illegal_state,feature_annual_inspection_mark,feature_pendant,feature_decoration,feature_sun_shield,xcycle_type,event_id,special_type,with_helmet,json_data,pics,video_name,company) values(" + ":taskId,:eventCate,:eventType,:eventTime,:channelUnid,:plateColor,:plateNumber,:locationCode,:locationName,:laneCode,:directionCode,:vehicleType,:vehicleColor,:vehicleLogo,:illegalCode,:illegalState,:featureAnnualInspectionMark,:featurePendant,:featureDecoration,:featureSunShield,:xcycleType,:eventId,:specialType,:withHelmet,:jsonData,:pics,:videoName,:company)";
private final static String INSERT_TRAFFIC_FACE = "insert into d_traffic_face (" + "traffic_id,state,sex,upper_color,lower_color,event_time) values (:trafficId,:state,:sex,:upperColor,:lowerColor,:eventTime)";
@Resource
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Resource
private DataStatisticUtil dataStatisticUtil;
@Override
public void write(List<? extends TrafficContent> list) throws Exception {
List<TrafficContent> withFace = new ArrayList<>();
List<TrafficContent> withoutFace = new ArrayList<>();
for (TrafficContent item : list) {
dataStatisticUtil.increase(item.getTraffic().getTaskId(), item.getTaskName(), item.getTraffic().getEventTime(), "traffic");
if (item.getTrafficFaces() != null && item.getTrafficFaces().size() > 0) {
withFace.add(item);
} else {
......
......@@ -16,6 +16,7 @@ import java.util.List;
@Data
public class TrafficContent {
private String taskName;
private Traffic traffic;
private List<TrafficFace> trafficFaces;
......
......@@ -16,6 +16,7 @@ import java.util.List;
@Data
public class TrafficFlowContent {
private String taskName;
private FlowEvent flowEvent;
private List<FlowData> flowData;
......
package com.viontech.fanxing.forward.runner;
import com.viontech.fanxing.commons.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* .
*
* @author 谢明辉
* @date 2022/2/10
*/
@Component
@Slf4j
public class DataStatisticPersistenceRunner {
@Resource
private RedisService redisService;
@Resource
private JdbcTemplate jdbcTemplate;
@Scheduled(cron = "10 0/2 * * * ?")
public void run() {
try {
RedissonClient client = redisService.getClient();
Iterable<String> keys = client.getKeys().getKeysByPattern("forward:dataStatistic:*");
for (String key : keys) {
try {
RMap<String, Object> map = client.getMap(key);
Long taskId = (Long) map.get("task_id");
String localDateStr = (String) map.get("date");
LocalDate localDate = LocalDate.parse(localDateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
Integer hour = (Integer) map.get("hour");
String taskName = (String) map.get("task_name");
Integer traffic = (Integer) map.get("traffic");
Integer flow = (Integer) map.get("flow");
Integer behavior = (Integer) map.get("behavior");
if (exists(taskId, localDate, hour)) {
update(taskId, localDate, hour, traffic, flow, behavior);
} else {
insert(taskId, localDate, hour, taskName, traffic, flow, behavior);
}
} catch (Exception e) {
log.error("", e);
}
}
} catch (Exception e) {
log.error("", e);
}
}
private void insert(Long taskId, LocalDate localDate, Integer hour, String taskName, Integer traffic, Integer flow, Integer behavior) {
jdbcTemplate.update("insert into d_data_statistic(task_id, task_name, date, hour, traffic, behavior, flow) values(?,?,?,?,?,?,?)", taskId, taskName, localDate, hour, traffic, behavior, flow);
}
private void update(Long taskId, LocalDate localDate, Integer hour, Integer traffic, Integer flow, Integer behavior) {
jdbcTemplate.update("update d_data_statistic set traffic=?,flow=?,behavior=? where date=? and task_id=? and hour=?", traffic, flow, behavior, localDate, taskId, hour);
}
private boolean exists(Long taskId, LocalDate localDate, Integer hour) {
Long count = jdbcTemplate.queryForObject("select count(*) from d_data_statistic where date=? and task_id=? and hour=?", Long.class, localDate, taskId, hour);
return count != null && count > 0;
}
}
package com.viontech.fanxing.forward.util;
import cn.hutool.core.date.DateUtil;
import com.viontech.fanxing.commons.model.DataStatistic;
import com.viontech.fanxing.commons.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* .
*
* @author 谢明辉
* @date 2022/2/10
*/
@Component
@Slf4j
public class DataStatisticUtil {
@Resource
private RedisService redisService;
@Resource
private JdbcTemplate jdbcTemplate;
public void increase(Long taskId, String taskName, Date date, String type) {
try {
LocalDateTime localDateTime = DateUtil.toLocalDateTime(date).plusHours(8);
RedissonClient client = redisService.getClient();
String redisKey = getRedisKey(taskId, localDateTime);
RMap<String, Object> map = client.getMap(redisKey);
if (!map.isExists()) {
RLock lockMust = redisService.getLockMust("lock:" + redisKey);
if (!map.isExists()) {
loadDataStatistic(taskId, taskName, localDateTime, redisKey);
}
lockMust.forceUnlock();
}
map.addAndGet(type, 1);
map.expire(2, TimeUnit.HOURS);
} catch (Exception e) {
log.error("写入redis失败", e);
}
}
private String getRedisKey(Long taskId, LocalDateTime date) {
String str = date.format(DateTimeFormatter.ofPattern("yyyyMMddHH"));
return "forward:dataStatistic:" + taskId + ":" + str;
}
public void loadDataStatistic(Long taskId, String taskName, LocalDateTime dateTime, String redisKey) {
LocalDate localDate = dateTime.toLocalDate();
int hour = dateTime.getHour();
List<DataStatistic> query = jdbcTemplate.query("select * from d_data_statistic where date=? and task_id=?", new BeanPropertyRowMapper<>(DataStatistic.class), localDate, hour);
RMap<String, Object> map = redisService.getClient().getMap(redisKey);
map.put("task_id", taskId);
String format = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(dateTime);
map.put("date", format);
map.put("hour", hour);
map.put("task_name", taskName);
if (query.size() > 0) {
DataStatistic dataStatistic = query.get(0);
map.addAndGet("traffic", dataStatistic.getTraffic());
map.addAndGet("flow", dataStatistic.getFlow());
map.addAndGet("behavior", dataStatistic.getBehavior());
} else {
map.addAndGet("traffic", 0);
map.addAndGet("flow", 0);
map.addAndGet("behavior", 0);
}
}
}
......@@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil;
import com.viontech.fanxing.commons.config.VionConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
......@@ -23,6 +24,7 @@ import java.time.ZoneOffset;
@Component
@Slf4j
@Profile("pro")
public class CleanJob {
@Resource
......
create table if not exists d_data_statistic
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
task_id bigint not null comment '任务ID',
task_name varchar(128) not null comment '任务名称',
date date not null default (current_date) comment '日期',
hour int not null comment '小时',
traffic int not null default 0 comment '交通数据量',
behavior int not null default 0 comment '事件数据量',
flow int not null default 0 comment '流量数据量',
key `d_data_statistic_idx` (`date`, `task_id`)
);
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.BaseService;
import com.viontech.fanxing.commons.model.DataStatistic;
import com.viontech.fanxing.commons.model.DataStatisticExample;
import com.viontech.fanxing.commons.vo.DataStatisticVo;
import com.viontech.fanxing.query.service.adapter.DataStatisticService;
import javax.annotation.Resource;
public abstract class DataStatisticBaseController extends BaseController<DataStatistic, DataStatisticVo> {
@Resource
protected DataStatisticService dataStatisticService;
@Override
protected BaseExample getExample(DataStatisticVo dataStatisticVo, int type) {
DataStatisticExample dataStatisticExample = new DataStatisticExample();
DataStatisticExample.Criteria criteria = dataStatisticExample.createCriteria();
if (dataStatisticVo.getId() != null) {
criteria.andIdEqualTo(dataStatisticVo.getId());
}
if (dataStatisticVo.getId_arr() != null) {
criteria.andIdIn(dataStatisticVo.getId_arr());
}
if (dataStatisticVo.getId_gt() != null) {
criteria.andIdGreaterThan(dataStatisticVo.getId_gt());
}
if (dataStatisticVo.getId_lt() != null) {
criteria.andIdLessThan(dataStatisticVo.getId_lt());
}
if (dataStatisticVo.getId_gte() != null) {
criteria.andIdGreaterThanOrEqualTo(dataStatisticVo.getId_gte());
}
if (dataStatisticVo.getId_lte() != null) {
criteria.andIdLessThanOrEqualTo(dataStatisticVo.getId_lte());
}
if (dataStatisticVo.getTaskId() != null) {
criteria.andTaskIdEqualTo(dataStatisticVo.getTaskId());
}
if (dataStatisticVo.getTaskId_arr() != null) {
criteria.andTaskIdIn(dataStatisticVo.getTaskId_arr());
}
if (dataStatisticVo.getTaskId_gt() != null) {
criteria.andTaskIdGreaterThan(dataStatisticVo.getTaskId_gt());
}
if (dataStatisticVo.getTaskId_lt() != null) {
criteria.andTaskIdLessThan(dataStatisticVo.getTaskId_lt());
}
if (dataStatisticVo.getTaskId_gte() != null) {
criteria.andTaskIdGreaterThanOrEqualTo(dataStatisticVo.getTaskId_gte());
}
if (dataStatisticVo.getTaskId_lte() != null) {
criteria.andTaskIdLessThanOrEqualTo(dataStatisticVo.getTaskId_lte());
}
if (dataStatisticVo.getTaskName() != null) {
criteria.andTaskNameEqualTo(dataStatisticVo.getTaskName());
}
if (dataStatisticVo.getTaskName_arr() != null) {
criteria.andTaskNameIn(dataStatisticVo.getTaskName_arr());
}
if (dataStatisticVo.getTaskName_like() != null) {
criteria.andTaskNameLike(dataStatisticVo.getTaskName_like());
}
if (dataStatisticVo.getDate() != null) {
criteria.andDateEqualTo(dataStatisticVo.getDate());
}
if (dataStatisticVo.getDate_arr() != null) {
criteria.andDateIn(dataStatisticVo.getDate_arr());
}
if (dataStatisticVo.getDate_gt() != null) {
criteria.andDateGreaterThan(dataStatisticVo.getDate_gt());
}
if (dataStatisticVo.getDate_lt() != null) {
criteria.andDateLessThan(dataStatisticVo.getDate_lt());
}
if (dataStatisticVo.getDate_gte() != null) {
criteria.andDateGreaterThanOrEqualTo(dataStatisticVo.getDate_gte());
}
if (dataStatisticVo.getDate_lte() != null) {
criteria.andDateLessThanOrEqualTo(dataStatisticVo.getDate_lte());
}
if (dataStatisticVo.getHour() != null) {
criteria.andHourEqualTo(dataStatisticVo.getHour());
}
if (dataStatisticVo.getHour_arr() != null) {
criteria.andHourIn(dataStatisticVo.getHour_arr());
}
if (dataStatisticVo.getHour_gt() != null) {
criteria.andHourGreaterThan(dataStatisticVo.getHour_gt());
}
if (dataStatisticVo.getHour_lt() != null) {
criteria.andHourLessThan(dataStatisticVo.getHour_lt());
}
if (dataStatisticVo.getHour_gte() != null) {
criteria.andHourGreaterThanOrEqualTo(dataStatisticVo.getHour_gte());
}
if (dataStatisticVo.getHour_lte() != null) {
criteria.andHourLessThanOrEqualTo(dataStatisticVo.getHour_lte());
}
if (dataStatisticVo.getTraffic() != null) {
criteria.andTrafficEqualTo(dataStatisticVo.getTraffic());
}
if (dataStatisticVo.getTraffic_arr() != null) {
criteria.andTrafficIn(dataStatisticVo.getTraffic_arr());
}
if (dataStatisticVo.getTraffic_gt() != null) {
criteria.andTrafficGreaterThan(dataStatisticVo.getTraffic_gt());
}
if (dataStatisticVo.getTraffic_lt() != null) {
criteria.andTrafficLessThan(dataStatisticVo.getTraffic_lt());
}
if (dataStatisticVo.getTraffic_gte() != null) {
criteria.andTrafficGreaterThanOrEqualTo(dataStatisticVo.getTraffic_gte());
}
if (dataStatisticVo.getTraffic_lte() != null) {
criteria.andTrafficLessThanOrEqualTo(dataStatisticVo.getTraffic_lte());
}
if (dataStatisticVo.getBehavior() != null) {
criteria.andBehaviorEqualTo(dataStatisticVo.getBehavior());
}
if (dataStatisticVo.getBehavior_arr() != null) {
criteria.andBehaviorIn(dataStatisticVo.getBehavior_arr());
}
if (dataStatisticVo.getBehavior_gt() != null) {
criteria.andBehaviorGreaterThan(dataStatisticVo.getBehavior_gt());
}
if (dataStatisticVo.getBehavior_lt() != null) {
criteria.andBehaviorLessThan(dataStatisticVo.getBehavior_lt());
}
if (dataStatisticVo.getBehavior_gte() != null) {
criteria.andBehaviorGreaterThanOrEqualTo(dataStatisticVo.getBehavior_gte());
}
if (dataStatisticVo.getBehavior_lte() != null) {
criteria.andBehaviorLessThanOrEqualTo(dataStatisticVo.getBehavior_lte());
}
if (dataStatisticVo.getFlow() != null) {
criteria.andFlowEqualTo(dataStatisticVo.getFlow());
}
if (dataStatisticVo.getFlow_arr() != null) {
criteria.andFlowIn(dataStatisticVo.getFlow_arr());
}
if (dataStatisticVo.getFlow_gt() != null) {
criteria.andFlowGreaterThan(dataStatisticVo.getFlow_gt());
}
if (dataStatisticVo.getFlow_lt() != null) {
criteria.andFlowLessThan(dataStatisticVo.getFlow_lt());
}
if (dataStatisticVo.getFlow_gte() != null) {
criteria.andFlowGreaterThanOrEqualTo(dataStatisticVo.getFlow_gte());
}
if (dataStatisticVo.getFlow_lte() != null) {
criteria.andFlowLessThanOrEqualTo(dataStatisticVo.getFlow_lte());
}
return dataStatisticExample;
}
@Override
protected BaseService<DataStatistic> getService() {
return dataStatisticService;
}
}
\ 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.DataStatisticExample;
import com.viontech.fanxing.commons.vo.DataStatisticVo;
import com.viontech.fanxing.query.controller.base.DataStatisticBaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/dataStatistics")
public class DataStatisticController extends DataStatisticBaseController {
@Override
protected BaseExample getExample(DataStatisticVo dataStatisticVo, int type) {
DataStatisticExample dataStatisticExample = (DataStatisticExample) super.getExample(dataStatisticVo, type);
return dataStatisticExample;
}
}
\ No newline at end of file
package com.viontech.fanxing.query.mapper;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.model.DataStatistic;
import com.viontech.fanxing.commons.model.DataStatisticExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface DataStatisticMapper extends BaseMapper {
int countByExample(DataStatisticExample example);
int deleteByExample(DataStatisticExample example);
int deleteByPrimaryKey(Long id);
int insert(DataStatistic record);
int insertSelective(DataStatistic record);
List<DataStatistic> selectByExample(DataStatisticExample example);
DataStatistic selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") DataStatistic record, @Param("example") DataStatisticExample example);
int updateByExample(@Param("record") DataStatistic record, @Param("example") DataStatisticExample example);
int updateByPrimaryKeySelective(DataStatistic record);
int updateByPrimaryKey(DataStatistic record);
}
\ No newline at end of file
<?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.DataStatisticMapper" >
<resultMap id="BaseResultMapRoot" type="com.viontech.fanxing.commons.model.DataStatistic" >
<id column="dataStatistic_id" property="id" />
<result column="dataStatistic_task_id" property="taskId" />
<result column="dataStatistic_task_name" property="taskName" />
<result column="dataStatistic_date" property="date" />
<result column="dataStatistic_hour" property="hour" />
<result column="dataStatistic_traffic" property="traffic" />
<result column="dataStatistic_behavior" property="behavior" />
<result column="dataStatistic_flow" property="flow" />
</resultMap>
<resultMap id="BaseResultMap" type="com.viontech.fanxing.commons.model.DataStatistic" 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" >
`dataStatistic`.id as dataStatistic_id, `dataStatistic`.task_id as dataStatistic_task_id,
`dataStatistic`.task_name as dataStatistic_task_name, `dataStatistic`.`date` as `dataStatistic_date`,
`dataStatistic`.`hour` as `dataStatistic_hour`, `dataStatistic`.traffic as dataStatistic_traffic,
`dataStatistic`.behavior as dataStatistic_behavior, `dataStatistic`.flow as dataStatistic_flow
</sql>
<sql id="Base_Column_List" >
<if test="!(_parameter.getClass().getSimpleName() == 'DataStatisticExample')" >
<include refid="com.viontech.fanxing.query.mapper.DataStatisticMapper.Base_Column_List_Root" />
</if>
<if test="_parameter.getClass().getSimpleName() == 'DataStatisticExample'" >
<foreach collection="columnContainerSet" item="columns" separator="," >
<choose >
<when test="columns.tableName == 'd_data_statistic'.toString()" >
<if test="columns.valid" >
${columns.columnContainerStr}
</if>
<if test="!columns.valid" >
<include refid="com.viontech.fanxing.query.mapper.DataStatisticMapper.Base_Column_List_Root" />
</if>
</when>
</choose>
</foreach>
</if>
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.viontech.fanxing.commons.model.DataStatisticExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from `d_data_statistic` `dataStatistic`
<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_data_statistic` `dataStatistic`
where `dataStatistic`.id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from `d_data_statistic` `dataStatistic`
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.viontech.fanxing.commons.model.DataStatisticExample" >
delete from `d_data_statistic` `dataStatistic`
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.viontech.fanxing.commons.model.DataStatistic" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `d_data_statistic` (task_id, task_name, `date`,
`hour`, traffic, behavior,
flow)
values (#{taskId,jdbcType=BIGINT}, #{taskName,jdbcType=VARCHAR}, #{date,jdbcType=DATE},
#{hour,jdbcType=INTEGER}, #{traffic,jdbcType=INTEGER}, #{behavior,jdbcType=INTEGER},
#{flow,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.viontech.fanxing.commons.model.DataStatistic" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `d_data_statistic`
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="taskId != null" >
task_id,
</if>
<if test="taskName != null" >
task_name,
</if>
<if test="date != null" >
`date`,
</if>
<if test="hour != null" >
`hour`,
</if>
<if test="traffic != null" >
traffic,
</if>
<if test="behavior != null" >
behavior,
</if>
<if test="flow != null" >
flow,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="taskId != null" >
#{taskId,jdbcType=BIGINT},
</if>
<if test="taskName != null" >
#{taskName,jdbcType=VARCHAR},
</if>
<if test="date != null" >
#{date,jdbcType=DATE},
</if>
<if test="hour != null" >
#{hour,jdbcType=INTEGER},
</if>
<if test="traffic != null" >
#{traffic,jdbcType=INTEGER},
</if>
<if test="behavior != null" >
#{behavior,jdbcType=INTEGER},
</if>
<if test="flow != null" >
#{flow,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.viontech.fanxing.commons.model.DataStatisticExample" resultType="java.lang.Integer" >
select count(*) from `d_data_statistic` `dataStatistic`
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map" >
update `d_data_statistic` `dataStatistic`
<set >
<if test="record.id != null" >
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.taskId != null" >
task_id = #{record.taskId,jdbcType=BIGINT},
</if>
<if test="record.taskName != null" >
task_name = #{record.taskName,jdbcType=VARCHAR},
</if>
<if test="record.date != null" >
`date` = #{record.date,jdbcType=DATE},
</if>
<if test="record.hour != null" >
`hour` = #{record.hour,jdbcType=INTEGER},
</if>
<if test="record.traffic != null" >
traffic = #{record.traffic,jdbcType=INTEGER},
</if>
<if test="record.behavior != null" >
behavior = #{record.behavior,jdbcType=INTEGER},
</if>
<if test="record.flow != null" >
flow = #{record.flow,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map" >
update `d_data_statistic` `dataStatistic`
set id = #{record.id,jdbcType=BIGINT},
task_id = #{record.taskId,jdbcType=BIGINT},
task_name = #{record.taskName,jdbcType=VARCHAR},
`date` = #{record.date,jdbcType=DATE},
`hour` = #{record.hour,jdbcType=INTEGER},
traffic = #{record.traffic,jdbcType=INTEGER},
behavior = #{record.behavior,jdbcType=INTEGER},
flow = #{record.flow,jdbcType=INTEGER}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.viontech.fanxing.commons.model.DataStatistic" >
update `d_data_statistic`
<set >
<if test="taskId != null" >
task_id = #{taskId,jdbcType=BIGINT},
</if>
<if test="taskName != null" >
task_name = #{taskName,jdbcType=VARCHAR},
</if>
<if test="date != null" >
`date` = #{date,jdbcType=DATE},
</if>
<if test="hour != null" >
`hour` = #{hour,jdbcType=INTEGER},
</if>
<if test="traffic != null" >
traffic = #{traffic,jdbcType=INTEGER},
</if>
<if test="behavior != null" >
behavior = #{behavior,jdbcType=INTEGER},
</if>
<if test="flow != null" >
flow = #{flow,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.viontech.fanxing.commons.model.DataStatistic" >
update `d_data_statistic`
set task_id = #{taskId,jdbcType=BIGINT},
task_name = #{taskName,jdbcType=VARCHAR},
`date` = #{date,jdbcType=DATE},
`hour` = #{hour,jdbcType=INTEGER},
traffic = #{traffic,jdbcType=INTEGER},
behavior = #{behavior,jdbcType=INTEGER},
flow = #{flow,jdbcType=INTEGER}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
......@@ -14,9 +14,9 @@ import lombok.Setter;
@Setter
public class DataOverViewModel {
private Long taskId;
private Long traffic = 0L;
private Long flow = 0L;
private Long behavior = 0L;
private Integer traffic = 0;
private Integer flow = 0;
private Integer behavior = 0;
private Integer hour;
private String taskName;
private Integer effectiveAnalysisTime;
......
package com.viontech.fanxing.query.service.adapter;
import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.DataStatistic;
public interface DataStatisticService extends BaseService<DataStatistic> {
}
\ 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.model.DataStatistic;
import com.viontech.fanxing.query.mapper.DataStatisticMapper;
import com.viontech.fanxing.query.service.adapter.DataStatisticService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class DataStatisticServiceImpl extends BaseServiceImpl<DataStatistic> implements DataStatisticService {
@Resource
private DataStatisticMapper dataStatisticMapper;
@Override
public BaseMapper<DataStatistic> getMapper() {
return dataStatisticMapper;
}
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ import com.viontech.fanxing.commons.vo.TrafficVo;
import com.viontech.fanxing.query.mapper.TrafficMapper;
import com.viontech.fanxing.query.model.DataOverViewModel;
import com.viontech.fanxing.query.service.adapter.BehaviorService;
import com.viontech.fanxing.query.service.adapter.DataStatisticService;
import com.viontech.fanxing.query.service.adapter.FlowEventService;
import com.viontech.fanxing.query.service.adapter.TrafficService;
import com.viontech.fanxing.query.service.main.TaskClientService;
......@@ -40,6 +41,9 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
@Resource
private JdbcTemplate jdbcTemplate;
@Resource
private DataStatisticService dataStatisticService;
@Override
public BaseMapper<Traffic> getMapper() {
return trafficMapper;
......@@ -73,7 +77,6 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
Map<Long, Task> taskMap = taskClientService.taskMap();
Date min = DateUtil.setDayMinTime(date);
Date max = DateUtil.setDayMaxTime(date);
HashMap<Long, DataOverViewModel> resultMap = new HashMap<>();
// 每个任务都给要列出来
for (Map.Entry<Long, Task> entry : taskMap.entrySet()) {
......@@ -88,87 +91,41 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
});
}
TrafficExample trafficExample = new TrafficExample();
TrafficExample.Criteria criteria = trafficExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max);
DataStatisticExample dataStatisticExample = new DataStatisticExample();
DataStatisticExample.Criteria criteria = dataStatisticExample.createCriteria().andDateEqualTo(min);
if (taskId != null) {
criteria.andTaskIdEqualTo(taskId);
}
trafficExample.createColumns().hasTaskIdColumn().addColumnStr("count(*) as count");
trafficExample.setGroupByClause("task_id");
trafficExample.setOrderByClause("task_id");
List<Traffic> traffic = trafficMapper.selectByExample(trafficExample);
for (Traffic t : traffic) {
if (t.getTaskId() != null) {
DataOverViewModel dov = resultMap.computeIfAbsent(t.getTaskId(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setTaskId(x);
temp.setTaskName(taskMap.get(x) == null ? "任务已删除" : taskMap.get(x).getName());
return temp;
});
dov.setTraffic(t.getCount());
}
}
FlowEventExample flowEventExample = new FlowEventExample();
FlowEventExample.Criteria criteria1 = flowEventExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max);
if (taskId != null) {
criteria1.andTaskIdEqualTo(taskId);
}
flowEventExample.createColumns().hasTaskIdColumn().addColumnStr("count(*) as count");
flowEventExample.setGroupByClause("task_id");
flowEventExample.setOrderByClause("task_id");
List<FlowEvent> flowEvents = flowEventService.getMapper().selectByExample(flowEventExample);
for (FlowEvent f : flowEvents) {
if (f.getTaskId() != null) {
DataOverViewModel dov = resultMap.computeIfAbsent(f.getTaskId(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setTaskId(x);
temp.setTaskName(taskMap.get(x) == null ? "任务已删除" : taskMap.get(x).getName());
return temp;
});
dov.setFlow(f.getCount());
}
dataStatisticExample.createColumns().hasTaskIdColumn().addColumnStr("sum(traffic) as dataStatistic_traffic,sum(flow) as dataStatistic_flow,sum(behavior) as dataStatistic_behavior,max(task_name) as dataStatistic_task_name");
dataStatisticExample.setGroupByClause("task_id");
dataStatisticExample.setOrderByClause("task_id");
List<DataStatistic> dataStatistics = dataStatisticService.selectByExample(dataStatisticExample);
for (DataStatistic item : dataStatistics) {
DataOverViewModel dov = resultMap.computeIfAbsent(item.getTaskId(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setTaskId(x);
temp.setTaskName(item.getTaskName());
return temp;
});
dov.setTraffic(item.getTraffic());
dov.setFlow(item.getFlow());
dov.setTraffic(item.getTraffic());
}
BehaviorExample behaviorExample = new BehaviorExample();
BehaviorExample.Criteria criteria2 = behaviorExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max);
if (taskId != null) {
criteria2.andTaskIdEqualTo(taskId);
}
behaviorExample.createColumns().hasTaskIdColumn().addColumnStr("count(*) as count");
behaviorExample.setGroupByClause("task_id");
behaviorExample.setOrderByClause("task_id");
List<Behavior> behaviors = behaviorService.getMapper().selectByExample(behaviorExample);
for (Behavior b : behaviors) {
if (b.getTaskId() != null) {
DataOverViewModel dov = resultMap.computeIfAbsent(b.getTaskId(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setTaskId(x);
temp.setTaskName(taskMap.get(x) == null ? "任务已删除" : taskMap.get(x).getName());
return temp;
});
dov.setBehavior(b.getCount());
}
}
Map<Long, String> task_id_unid_map = taskMap.values().stream().collect(Collectors.toMap(Task::getId, Task::getUnid, (x, y) -> x));
Map<String, JSONObject> taskStateMap = taskClientService.taskStateMap();
// 加上有效分析时长和异常次数
Collection<DataOverViewModel> values = resultMap.values();
List<DataOverViewModel> collect = values.stream()
.filter(x -> x.getTaskId() != null)
.peek(x -> {
Long id = x.getTaskId();
String unid = task_id_unid_map.get(id);
JSONObject jsonObject = taskStateMap.get(unid);
if (jsonObject != null) {
x.setEffectiveAnalysisTime(jsonObject.getInteger("effective_running_time"));
x.setExceptionNum(jsonObject.getInteger("exception_times"));
}
})
.sorted(Comparator.comparingLong(DataOverViewModel::getTaskId))
.collect(Collectors.toList());
List<DataOverViewModel> collect = values.stream().filter(x -> x.getTaskId() != null).peek(x -> {
Long id = x.getTaskId();
String unid = task_id_unid_map.get(id);
JSONObject jsonObject = taskStateMap.get(unid);
if (jsonObject != null) {
x.setEffectiveAnalysisTime(jsonObject.getInteger("effective_running_time"));
x.setExceptionNum(jsonObject.getInteger("exception_times"));
}
}).sorted(Comparator.comparingLong(DataOverViewModel::getTaskId)).collect(Collectors.toList());
List<List<DataOverViewModel>> partition = ListUtil.partition(collect, pageSize);
JSONObject jsonObject = new JSONObject();
......@@ -184,7 +141,6 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
@Override
public Collection<DataOverViewModel> overviewDetail(Date date, Long taskId) {
Date min = DateUtil.setDayMinTime(date);
Date max = DateUtil.setDayMaxTime(date);
TreeMap<Integer, DataOverViewModel> resultMap = new TreeMap<>();
for (int i = 0; i < 24; i++) {
resultMap.computeIfAbsent(i, x -> {
......@@ -193,60 +149,21 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
return temp;
});
}
TrafficExample trafficExample = new TrafficExample();
trafficExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max).andTaskIdEqualTo(taskId);
TrafficExample.ColumnContainer columns = trafficExample.createColumns().hasTaskIdColumn();
columns.addColumnStr("count(*) as count");
columns.addColumnStr("hour(date_add(event_time,interval 8 hour)) as hour");
trafficExample.setGroupByClause("task_id,hour");
trafficExample.setOrderByClause("task_id,hour");
List<Traffic> traffic = trafficMapper.selectByExample(trafficExample);
for (Traffic t : traffic) {
DataOverViewModel dov = resultMap.computeIfAbsent(t.getHour(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setHour(x);
return temp;
});
dov.setTraffic(t.getCount());
dov.setTaskId(t.getTaskId());
}
FlowEventExample flowEventExample = new FlowEventExample();
flowEventExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max).andTaskIdEqualTo(taskId);
FlowEventExample.ColumnContainer columns2 = flowEventExample.createColumns().hasTaskIdColumn();
columns2.addColumnStr("count(*) as count");
columns2.addColumnStr("hour(date_add(event_time,interval 8 hour)) as hour");
flowEventExample.setGroupByClause("task_id,hour");
flowEventExample.setOrderByClause("task_id,hour");
List<FlowEvent> flowEvents = flowEventService.getMapper().selectByExample(flowEventExample);
for (FlowEvent f : flowEvents) {
DataOverViewModel dov = resultMap.computeIfAbsent(f.getHour(), x -> {
DataStatisticExample dataStatisticExample = new DataStatisticExample();
dataStatisticExample.createCriteria().andDateEqualTo(min).andTaskIdEqualTo(taskId);
List<DataStatistic> dataStatistics = dataStatisticService.selectByExample(dataStatisticExample);
for (DataStatistic item : dataStatistics) {
DataOverViewModel dov = resultMap.computeIfAbsent(item.getHour(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setHour(x);
return temp;
});
dov.setFlow(f.getCount());
dov.setTaskId(f.getTaskId());
}
BehaviorExample behaviorExample = new BehaviorExample();
behaviorExample.createCriteria().andEventTimeGreaterThanOrEqualTo(min).andEventTimeLessThanOrEqualTo(max).andTaskIdEqualTo(taskId);
BehaviorExample.ColumnContainer columns3 = behaviorExample.createColumns().hasTaskIdColumn();
columns3.addColumnStr("count(*) as count");
columns3.addColumnStr("hour(date_add(event_time,interval 8 hour)) as hour");
behaviorExample.setGroupByClause("task_id,hour");
behaviorExample.setOrderByClause("task_id,hour");
List<Behavior> behaviors = behaviorService.getMapper().selectByExample(behaviorExample);
for (Behavior b : behaviors) {
DataOverViewModel dov = resultMap.computeIfAbsent(b.getHour(), x -> {
DataOverViewModel temp = new DataOverViewModel();
temp.setHour(x);
return temp;
});
dov.setBehavior(b.getCount());
dov.setTaskId(b.getTaskId());
dov.setTraffic(item.getTraffic());
dov.setBehavior(item.getBehavior());
dov.setFlow(item.getFlow());
dov.setTaskId(item.getTaskId());
dov.setTaskName(item.getTaskName());
}
return resultMap.values();
}
......@@ -255,15 +172,7 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
@LocalCache(value = "traffic_statics_123fds4", duration = 5)
public JSONArray statistics() {
JSONArray jsonArray = new JSONArray();
jdbcTemplate.query("select '过车数据' as dataType ,adddate(max(event_time), interval 8 hour) maxTime,adddate(min(event_time),interval 8 hour) minTime,count(pics) as picCount,count(video_name) as videoCount from d_traffic where event_type='vehicle' and illegal_state=0\n" +
"union\n" +
"select '违法数据' as dataType ,adddate(max(event_time), interval 8 hour) maxTime,adddate(min(event_time),interval 8 hour) minTime,count(pics) as picCount,count(video_name) as videoCount from d_traffic where event_type='vehicle' and illegal_state=1\n" +
"union\n" +
"select '非机动车数据' as dataType ,adddate(max(event_time), interval 8 hour) maxTime,adddate(min(event_time),interval 8 hour) minTime,count(pics) as picCount,count(video_name) as videoCount from d_traffic where event_type='xcycle'\n" +
"union\n" +
"select '行人数据' as dataType ,adddate(max(event_time), interval 8 hour) maxTime,adddate(min(event_time),interval 8 hour) minTime,count(pics) as picCount,count(video_name) as videoCount from d_traffic where event_type='pedestrian'\n" +
"union\n" +
"select '事件数据' as dataType ,adddate(max(event_time), interval 8 hour) maxTime,adddate(min(event_time),interval 8 hour) minTime,count(pics) as picCount,count(video) as videoCount from d_behavior", rs -> {
jdbcTemplate.query("select '过车数据' as dataType ,adddate(max(event_time), interval 8 hour) maxTime,adddate(min(event_time),interval 8 hour) minTime,count(pics) as picCount,count(video_name) as videoCount from d_traffic where event_type='vehicle' and illegal_state=0\n" + "union\n" + "select '违法数据' as dataType ,adddate(max(event_time), interval 8 hour) maxTime,adddate(min(event_time),interval 8 hour) minTime,count(pics) as picCount,count(video_name) as videoCount from d_traffic where event_type='vehicle' and illegal_state=1\n" + "union\n" + "select '非机动车数据' as dataType ,adddate(max(event_time), interval 8 hour) maxTime,adddate(min(event_time),interval 8 hour) minTime,count(pics) as picCount,count(video_name) as videoCount from d_traffic where event_type='xcycle'\n" + "union\n" + "select '行人数据' as dataType ,adddate(max(event_time), interval 8 hour) maxTime,adddate(min(event_time),interval 8 hour) minTime,count(pics) as picCount,count(video_name) as videoCount from d_traffic where event_type='pedestrian'\n" + "union\n" + "select '事件数据' as dataType ,adddate(max(event_time), interval 8 hour) maxTime,adddate(min(event_time),interval 8 hour) minTime,count(pics) as picCount,count(video) as videoCount from d_behavior", rs -> {
JSONObject jsonObject = new JSONObject();
jsonObject.put("dataType", rs.getString("dataType"));
jsonObject.put("maxTime", rs.getDate("maxTime"));
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 数据库驱动 -->
<classPathEntry location="libs/mysql-connector-java-8.0.25.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3" defaultModelType="flat" >
<property name="autoDelimitKeywords" value="true"/>
<property name="xmlMergeable" value="false"/>
<property name="endingDelimiter" value="`"/>
<property name="beginningDelimiter" value="`"/>
<property name="basePackage" value="com.viontech.fanxing.commons.base"/>
<!-- 数据库驱动 -->
<classPathEntry location="libs/mysql-connector-java-8.0.25.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3" defaultModelType="flat">
<property name="autoDelimitKeywords" value="true"/>
<property name="xmlMergeable" value="false"/>
<property name="endingDelimiter" value="`"/>
<property name="beginningDelimiter" value="`"/>
<property name="basePackage" value="com.viontech.fanxing.commons.base"/>
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.9.233:3306/fanxing3" userId="root"
password="123456"/>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 生成模型的包名和位置-->
<javaModelGenerator targetPackage="com.viontech.fanxing.commons.model" targetProject="F:\mybatis-generator\fanxing-forward">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
<property name="rootClass" value="com.viontech.fanxing.commons.base.BaseModel"/>
</javaModelGenerator>
<!-- 生成映射文件的包名和位置-->
<sqlMapGenerator targetPackage="com.viontech.fanxing.commons.mapping" targetProject="F:\mybatis-generator\fanxing-forward">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成DAO的包名和位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.viontech.fanxing.query.mapper" targetProject="F:\mybatis-generator\fanxing-forward" >
<property name="enableSubPackages" value="true"/>
<property name="rootInterface" value="com.viontech.fanxing.commons.base.BaseMapper"/>
</javaClientGenerator>
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.9.233:3306/fanxing3" userId="root"
password="123456"/>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 生成模型的包名和位置-->
<javaModelGenerator targetPackage="com.viontech.fanxing.commons.model"
targetProject="F:\mybatis-generator\fanxing-query">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
<property name="rootClass" value="com.viontech.fanxing.commons.base.BaseModel"/>
</javaModelGenerator>
<!-- 生成映射文件的包名和位置-->
<sqlMapGenerator targetPackage="com.viontech.fanxing.commons.mapping"
targetProject="F:\mybatis-generator\fanxing-query">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成DAO的包名和位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.viontech.fanxing.query.mapper"
targetProject="F:\mybatis-generator\fanxing-query">
<property name="enableSubPackages" value="true"/>
<property name="rootInterface" value="com.viontech.fanxing.commons.base.BaseMapper"/>
</javaClientGenerator>
<table delimitIdentifiers="true" tableName="d_behavior" alias="behavior" domainObjectName="Behavior">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<table delimitIdentifiers="true" tableName="d_flow_event" alias="flowEvent" domainObjectName="FlowEvent">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<table delimitIdentifiers="true" tableName="d_flow_data" alias="flowData" domainObjectName="FlowData">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<table delimitIdentifiers="true" tableName="d_traffic" alias="traffic" domainObjectName="Traffic">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<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>
<table delimitIdentifiers="true" tableName="d_behavior" alias="behavior" domainObjectName="Behavior">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<table delimitIdentifiers="true" tableName="d_flow_event" alias="flowEvent" domainObjectName="FlowEvent">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<table delimitIdentifiers="true" tableName="d_flow_data" alias="flowData" domainObjectName="FlowData">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<table delimitIdentifiers="true" tableName="d_traffic" alias="traffic" domainObjectName="Traffic">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<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>
<table delimitIdentifiers="true" tableName="d_data_statistic" alias="dataStatistic"
domainObjectName="DataStatistic">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
</context>
</generatorConfiguration>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!