流量统计-小时报完善
This commit is contained in:
+4
@@ -24,6 +24,7 @@ package fun.asgc.neutrino.proxy.server.dal;
|
||||
import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
import fun.asgc.neutrino.core.db.annotation.Insert;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
|
||||
@@ -41,4 +42,7 @@ public interface FlowReportHourMapper extends SqlMapper {
|
||||
|
||||
@Insert("insert into flow_report_hour(`user_id`,`license_id`,`write_bytes`,`read_bytes`,`date`,`date_str`,`create_time`) values(:userId,:licenseId,:writeBytes,:readBytes,:date,:dateStr,:createTime)")
|
||||
void add(FlowReportHourDO flowReportHourDO);
|
||||
|
||||
@Delete("delete from flow_report_hour where date_str = :dateStr")
|
||||
void deleteByDateStr(@Param("dateStr") String dateStr);
|
||||
}
|
||||
|
||||
+27
-5
@@ -31,13 +31,12 @@ import fun.asgc.neutrino.core.util.DateUtil;
|
||||
import fun.asgc.neutrino.proxy.server.dal.FlowReportHourMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.FlowReportMinuteMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.LicenseMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportHourDO;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportMinuteDO;
|
||||
import fun.asgc.neutrino.proxy.server.service.FlowReportService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
@@ -65,7 +64,8 @@ public class FlowReportForHourJob implements IJobHandler {
|
||||
Date startHourDate = DateUtil.getHourBegin(date);
|
||||
Date endHourDate = DateUtil.getHourEnd(date);
|
||||
|
||||
// 删除原来的记录 TODO
|
||||
// 删除原来的记录
|
||||
flowReportHourMapper.deleteByDateStr(dateStr);
|
||||
|
||||
// 查询前一个小时的分钟级别统计数据
|
||||
List<FlowReportMinuteDO> flowReportMinuteDOList = flowReportMinuteMapper.findListByDateRange(startHourDate, endHourDate);
|
||||
@@ -73,7 +73,29 @@ public class FlowReportForHourJob implements IJobHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// 汇总前一个小时的小时级别统计数据 TODO
|
||||
// 汇总前一个小时的小时级别统计数据
|
||||
Map<Integer, FlowReportHourDO> map = new HashMap<>();
|
||||
for (FlowReportMinuteDO item : flowReportMinuteDOList) {
|
||||
FlowReportHourDO report = map.get(item.getLicenseId());
|
||||
if (null == report) {
|
||||
report = new FlowReportHourDO();
|
||||
map.put(item.getLicenseId(), report);
|
||||
}
|
||||
Long writeBytes = report.getWriteBytes() == null ? 0 : report.getWriteBytes();
|
||||
Long readBytes = report.getReadBytes() == null ? 0 : report.getReadBytes();
|
||||
|
||||
report.setUserId(item.getUserId());
|
||||
report.setLicenseId(item.getLicenseId());
|
||||
report.setWriteBytes(writeBytes + item.getWriteBytes());
|
||||
report.setReadBytes(readBytes + item.getReadBytes());
|
||||
report.setDate(date);
|
||||
report.setDateStr(dateStr);
|
||||
report.setCreateTime(now);
|
||||
}
|
||||
|
||||
for (FlowReportHourDO item : map.values()) {
|
||||
flowReportHourMapper.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,4 +4,6 @@ INSERT INTO job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create
|
||||
INSERT INTO job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(2, '数据清理任务', 'DataCleanJob', '0 0 1 * * ?', '', 1, STRFTIME('%s000', 'NOW'), STRFTIME('%s000', 'NOW'));
|
||||
INSERT INTO job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(3, '流量统计报表-分钟', 'FlowReportForMinuteJob', '0 */1 * * * ?', '', 1, STRFTIME('%s000', 'NOW'), STRFTIME('%s000', 'NOW'));
|
||||
(3, '流量统计报表-分钟', 'FlowReportForMinuteJob', '0 */1 * * * ?', '', 1, STRFTIME('%s000', 'NOW'), STRFTIME('%s000', 'NOW'));
|
||||
INSERT INTO job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(4, '流量统计报表-小时', 'FlowReportForHourJob', '0 0 */1 * * ?', '', 1, STRFTIME('%s000', 'NOW'), STRFTIME('%s000', 'NOW'));
|
||||
Reference in New Issue
Block a user