Commit 42da1656 by xmh

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

<feat> 数据统计值表 d_data_statistic
1 parent beb46b1c
Showing 25 changed files with 613 additions and 83 deletions
...@@ -9,7 +9,6 @@ import java.io.Serializable; ...@@ -9,7 +9,6 @@ import java.io.Serializable;
public abstract class BaseModel implements Serializable { public abstract class BaseModel implements Serializable {
private Long count; private Long count;
private Long id; private Long id;
private Integer hour;
public BaseModel() { public BaseModel() {
super(); super();
...@@ -30,13 +29,4 @@ public abstract class BaseModel implements Serializable { ...@@ -30,13 +29,4 @@ public abstract class BaseModel implements Serializable {
public void setId(Long id) { public void setId(Long id) {
this.id = 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 \ 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 \ No newline at end of file
...@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject; ...@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.model.FlowData; import com.viontech.fanxing.commons.model.FlowData;
import com.viontech.fanxing.commons.model.FlowEvent; import com.viontech.fanxing.commons.model.FlowEvent;
import com.viontech.fanxing.forward.model.TrafficFlowContent; import com.viontech.fanxing.forward.model.TrafficFlowContent;
import com.viontech.fanxing.forward.util.CacheUtils;
import com.viontech.keliu.util.DateUtil; import com.viontech.keliu.util.DateUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -15,7 +14,6 @@ import org.springframework.batch.item.ItemStream; ...@@ -15,7 +14,6 @@ import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException; import org.springframework.batch.item.ItemStreamException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -41,6 +39,7 @@ public class TrafficFlowProcessor implements ItemProcessor<JSONObject, TrafficFl ...@@ -41,6 +39,7 @@ public class TrafficFlowProcessor implements ItemProcessor<JSONObject, TrafficFl
log.info("收到 flow 消息 , 任务名称:[{}] , 消息ID:[{}]", taskName, eventRefid); log.info("收到 flow 消息 , 任务名称:[{}] , 消息ID:[{}]", taskName, eventRefid);
TrafficFlowContent content = new TrafficFlowContent(); TrafficFlowContent content = new TrafficFlowContent();
content.setTaskName(taskName);
FlowEvent flowEvent = new FlowEvent(); FlowEvent flowEvent = new FlowEvent();
flowEvent.setJsonData(item.toJSONString()); flowEvent.setJsonData(item.toJSONString());
content.setFlowEvent(flowEvent); content.setFlowEvent(flowEvent);
......
...@@ -41,6 +41,7 @@ public class TrafficProcessor implements ItemProcessor<JSONObject, TrafficConten ...@@ -41,6 +41,7 @@ public class TrafficProcessor implements ItemProcessor<JSONObject, TrafficConten
log.info("收到 traffic 消息 , 任务名称:[{}] , 消息ID:[{}]", taskName, eventRefid); log.info("收到 traffic 消息 , 任务名称:[{}] , 消息ID:[{}]", taskName, eventRefid);
TrafficContent content = new TrafficContent(); TrafficContent content = new TrafficContent();
content.setTaskName(taskName);
Traffic traffic = new Traffic(); Traffic traffic = new Traffic();
traffic.setJsonData(item.toJSONString()); traffic.setJsonData(item.toJSONString());
content.setTraffic(traffic); content.setTraffic(traffic);
......
package com.viontech.fanxing.forward.batch.writer; package com.viontech.fanxing.forward.batch.writer;
import com.viontech.fanxing.commons.model.Behavior; import com.viontech.fanxing.commons.model.Behavior;
import com.viontech.fanxing.forward.util.DataStatisticUtil;
import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.ItemWriter;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource;
...@@ -25,9 +26,15 @@ public class BehaviorWriter implements ItemWriter<Behavior> { ...@@ -25,9 +26,15 @@ public class BehaviorWriter implements ItemWriter<Behavior> {
":taskId,:eventType,:eventCate,:eventRefid,:eventTime,:eventData,:pics,:video,:channelUnid,:taskName,:eventDataNum)"; ":taskId,:eventType,:eventCate,:eventRefid,:eventTime,:eventData,:pics,:video,:channelUnid,:taskName,:eventDataNum)";
@Resource @Resource
private NamedParameterJdbcTemplate namedParameterJdbcTemplate; private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Resource
private DataStatisticUtil dataStatisticUtil;
@Override @Override
public void write(List<? extends Behavior> items) throws Exception { 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); SqlParameterSource[] batchParam = SqlParameterSourceUtils.createBatch(items);
namedParameterJdbcTemplate.batchUpdate(INSERT_BEHAVIOR, batchParam); namedParameterJdbcTemplate.batchUpdate(INSERT_BEHAVIOR, batchParam);
} }
......
...@@ -3,6 +3,7 @@ package com.viontech.fanxing.forward.batch.writer; ...@@ -3,6 +3,7 @@ package com.viontech.fanxing.forward.batch.writer;
import com.viontech.fanxing.commons.model.FlowData; import com.viontech.fanxing.commons.model.FlowData;
import com.viontech.fanxing.commons.model.FlowEvent; import com.viontech.fanxing.commons.model.FlowEvent;
import com.viontech.fanxing.forward.model.TrafficFlowContent; import com.viontech.fanxing.forward.model.TrafficFlowContent;
import com.viontech.fanxing.forward.util.DataStatisticUtil;
import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.ItemWriter;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource;
...@@ -23,15 +24,13 @@ import java.util.List; ...@@ -23,15 +24,13 @@ import java.util.List;
@Component @Component
public class TrafficFlowWriter implements ItemWriter<TrafficFlowContent> { public class TrafficFlowWriter implements ItemWriter<TrafficFlowContent> {
private final static String INSERT_FLOW_EVENT = "insert into d_flow_event (" + 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)";
"task_id,event_type,event_time,event_id,device_code,device_name,location_code,location_name,json_data,pics,video_name,channel_unid) values(" + 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)";
":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 @Resource
private NamedParameterJdbcTemplate namedParameterJdbcTemplate; private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Resource
private DataStatisticUtil dataStatisticUtil;
@Override @Override
public void write(List<? extends TrafficFlowContent> list) { public void write(List<? extends TrafficFlowContent> list) {
...@@ -39,6 +38,8 @@ public class TrafficFlowWriter implements ItemWriter<TrafficFlowContent> { ...@@ -39,6 +38,8 @@ public class TrafficFlowWriter implements ItemWriter<TrafficFlowContent> {
List<FlowData> trafficFlowData = item.getFlowData(); List<FlowData> trafficFlowData = item.getFlowData();
FlowEvent flowEvent = item.getFlowEvent(); FlowEvent flowEvent = item.getFlowEvent();
dataStatisticUtil.increase(flowEvent.getTaskId(), item.getTaskName(), flowEvent.getEventTime(), "flow");
SqlParameterSource flowEventParam = SqlParameterSourceUtils.createBatch(flowEvent)[0]; SqlParameterSource flowEventParam = SqlParameterSourceUtils.createBatch(flowEvent)[0];
GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder(); GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();
namedParameterJdbcTemplate.update(INSERT_FLOW_EVENT, flowEventParam, generatedKeyHolder); namedParameterJdbcTemplate.update(INSERT_FLOW_EVENT, flowEventParam, generatedKeyHolder);
......
...@@ -3,6 +3,7 @@ package com.viontech.fanxing.forward.batch.writer; ...@@ -3,6 +3,7 @@ package com.viontech.fanxing.forward.batch.writer;
import com.viontech.fanxing.commons.model.Traffic; import com.viontech.fanxing.commons.model.Traffic;
import com.viontech.fanxing.commons.model.TrafficFace; import com.viontech.fanxing.commons.model.TrafficFace;
import com.viontech.fanxing.forward.model.TrafficContent; import com.viontech.fanxing.forward.model.TrafficContent;
import com.viontech.fanxing.forward.util.DataStatisticUtil;
import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.ItemWriter;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource;
...@@ -25,20 +26,22 @@ import java.util.stream.Collectors; ...@@ -25,20 +26,22 @@ import java.util.stream.Collectors;
@Component @Component
public class TrafficWriter implements ItemWriter<TrafficContent> { public class TrafficWriter implements ItemWriter<TrafficContent> {
private final static String INSERT_TRAFFIC = "insert into d_traffic (" + 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)";
"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(" + 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)";
":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 @Resource
private NamedParameterJdbcTemplate namedParameterJdbcTemplate; private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Resource
private DataStatisticUtil dataStatisticUtil;
@Override @Override
public void write(List<? extends TrafficContent> list) throws Exception { public void write(List<? extends TrafficContent> list) throws Exception {
List<TrafficContent> withFace = new ArrayList<>(); List<TrafficContent> withFace = new ArrayList<>();
List<TrafficContent> withoutFace = new ArrayList<>(); List<TrafficContent> withoutFace = new ArrayList<>();
for (TrafficContent item : list) { for (TrafficContent item : list) {
dataStatisticUtil.increase(item.getTraffic().getTaskId(), item.getTaskName(), item.getTraffic().getEventTime(), "traffic");
if (item.getTrafficFaces() != null && item.getTrafficFaces().size() > 0) { if (item.getTrafficFaces() != null && item.getTrafficFaces().size() > 0) {
withFace.add(item); withFace.add(item);
} else { } else {
......
...@@ -16,6 +16,7 @@ import java.util.List; ...@@ -16,6 +16,7 @@ import java.util.List;
@Data @Data
public class TrafficContent { public class TrafficContent {
private String taskName;
private Traffic traffic; private Traffic traffic;
private List<TrafficFace> trafficFaces; private List<TrafficFace> trafficFaces;
......
...@@ -16,6 +16,7 @@ import java.util.List; ...@@ -16,6 +16,7 @@ import java.util.List;
@Data @Data
public class TrafficFlowContent { public class TrafficFlowContent {
private String taskName;
private FlowEvent flowEvent; private FlowEvent flowEvent;
private List<FlowData> flowData; 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; ...@@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import com.viontech.fanxing.commons.config.VionConfig; import com.viontech.fanxing.commons.config.VionConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -23,6 +24,7 @@ import java.time.ZoneOffset; ...@@ -23,6 +24,7 @@ import java.time.ZoneOffset;
@Component @Component
@Slf4j @Slf4j
@Profile("pro")
public class CleanJob { public class CleanJob {
@Resource @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 \ 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 \ 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 \ No newline at end of file
...@@ -14,9 +14,9 @@ import lombok.Setter; ...@@ -14,9 +14,9 @@ import lombok.Setter;
@Setter @Setter
public class DataOverViewModel { public class DataOverViewModel {
private Long taskId; private Long taskId;
private Long traffic = 0L; private Integer traffic = 0;
private Long flow = 0L; private Integer flow = 0;
private Long behavior = 0L; private Integer behavior = 0;
private Integer hour; private Integer hour;
private String taskName; private String taskName;
private Integer effectiveAnalysisTime; 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 \ 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 \ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration <!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration> <generatorConfiguration>
<!-- 数据库驱动 --> <!-- 数据库驱动 -->
<classPathEntry location="libs/mysql-connector-java-8.0.25.jar"/> <classPathEntry location="libs/mysql-connector-java-8.0.25.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3" defaultModelType="flat" > <context id="DB2Tables" targetRuntime="MyBatis3" defaultModelType="flat">
<property name="autoDelimitKeywords" value="true"/> <property name="autoDelimitKeywords" value="true"/>
<property name="xmlMergeable" value="false"/> <property name="xmlMergeable" value="false"/>
<property name="endingDelimiter" value="`"/> <property name="endingDelimiter" value="`"/>
<property name="beginningDelimiter" value="`"/> <property name="beginningDelimiter" value="`"/>
<property name="basePackage" value="com.viontech.fanxing.commons.base"/> <property name="basePackage" value="com.viontech.fanxing.commons.base"/>
<commentGenerator> <commentGenerator>
<property name="suppressDate" value="true"/> <property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 --> <!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/> <property name="suppressAllComments" value="true"/>
</commentGenerator> </commentGenerator>
<!--数据库链接URL,用户名、密码 --> <!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.9.233:3306/fanxing3" userId="root" connectionURL="jdbc:mysql://192.168.9.233:3306/fanxing3" userId="root"
password="123456"/> password="123456"/>
<javaTypeResolver> <javaTypeResolver>
<property name="forceBigDecimals" value="false"/> <property name="forceBigDecimals" value="false"/>
</javaTypeResolver> </javaTypeResolver>
<!-- 生成模型的包名和位置--> <!-- 生成模型的包名和位置-->
<javaModelGenerator targetPackage="com.viontech.fanxing.commons.model" targetProject="F:\mybatis-generator\fanxing-forward"> <javaModelGenerator targetPackage="com.viontech.fanxing.commons.model"
<property name="enableSubPackages" value="true"/> targetProject="F:\mybatis-generator\fanxing-query">
<property name="trimStrings" value="true"/> <property name="enableSubPackages" value="true"/>
<property name="rootClass" value="com.viontech.fanxing.commons.base.BaseModel"/> <property name="trimStrings" value="true"/>
</javaModelGenerator> <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 targetPackage="com.viontech.fanxing.commons.mapping"
</sqlMapGenerator> targetProject="F:\mybatis-generator\fanxing-query">
<!-- 生成DAO的包名和位置--> <property name="enableSubPackages" value="true"/>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.viontech.fanxing.query.mapper" targetProject="F:\mybatis-generator\fanxing-forward" > </sqlMapGenerator>
<property name="enableSubPackages" value="true"/> <!-- 生成DAO的包名和位置-->
<property name="rootInterface" value="com.viontech.fanxing.commons.base.BaseMapper"/> <javaClientGenerator type="XMLMAPPER" targetPackage="com.viontech.fanxing.query.mapper"
</javaClientGenerator> 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"> <table delimitIdentifiers="true" tableName="d_behavior" alias="behavior" domainObjectName="Behavior">
<generatedKey column="id" sqlStatement="JDBC"/> <generatedKey column="id" sqlStatement="JDBC"/>
</table> </table>
<table delimitIdentifiers="true" tableName="d_flow_event" alias="flowEvent" domainObjectName="FlowEvent"> <table delimitIdentifiers="true" tableName="d_flow_event" alias="flowEvent" domainObjectName="FlowEvent">
<generatedKey column="id" sqlStatement="JDBC"/> <generatedKey column="id" sqlStatement="JDBC"/>
</table> </table>
<table delimitIdentifiers="true" tableName="d_flow_data" alias="flowData" domainObjectName="FlowData"> <table delimitIdentifiers="true" tableName="d_flow_data" alias="flowData" domainObjectName="FlowData">
<generatedKey column="id" sqlStatement="JDBC"/> <generatedKey column="id" sqlStatement="JDBC"/>
</table> </table>
<table delimitIdentifiers="true" tableName="d_traffic" alias="traffic" domainObjectName="Traffic"> <table delimitIdentifiers="true" tableName="d_traffic" alias="traffic" domainObjectName="Traffic">
<generatedKey column="id" sqlStatement="JDBC"/> <generatedKey column="id" sqlStatement="JDBC"/>
</table> </table>
<table delimitIdentifiers="true" tableName="d_traffic_face" alias="trafficFace" domainObjectName="TrafficFace"> <table delimitIdentifiers="true" tableName="d_traffic_face" alias="trafficFace" domainObjectName="TrafficFace">
<generatedKey column="id" sqlStatement="JDBC"/> <generatedKey column="id" sqlStatement="JDBC"/>
</table> </table>
<table delimitIdentifiers="true" tableName="d_export_data" alias="exportData" domainObjectName="ExportData"> <table delimitIdentifiers="true" tableName="d_export_data" alias="exportData" domainObjectName="ExportData">
<generatedKey column="id" sqlStatement="JDBC"/> <generatedKey column="id" sqlStatement="JDBC"/>
</table> </table>
</context> <table delimitIdentifiers="true" tableName="d_data_statistic" alias="dataStatistic"
domainObjectName="DataStatistic">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
</context>
</generatorConfiguration> </generatorConfiguration>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!