流量统计-小时报表
This commit is contained in:
@@ -288,6 +288,30 @@ public class DateUtil {
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定小时开始时间
|
||||
* @param date 日期
|
||||
* @return 指定小时开始时间
|
||||
*/
|
||||
public static Date getHourBegin(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
setCalender(calendar, calendar.get(Calendar.HOUR), 0, 0, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定小时结束时间
|
||||
* @param date 日期
|
||||
* @return 指定小时结束时间
|
||||
*/
|
||||
public static Date getHourEnd(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
setCalender(calendar, calendar.get(Calendar.HOUR), 59, 59, 999);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天开始时间
|
||||
*
|
||||
|
||||
+5
@@ -30,6 +30,7 @@ import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.FlowReportMinuteDO;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -47,6 +48,10 @@ public interface FlowReportMinuteMapper extends SqlMapper {
|
||||
@Select("select * from flow_report_minute where license_id in (:licenseIds) and date = :date")
|
||||
List<FlowReportMinuteDO> findList(@Param("licenseIds") Set<Integer> licenseIds, @Param("date") String date);
|
||||
|
||||
@ResultType(FlowReportMinuteDO.class)
|
||||
@Select("select * from flow_report_minute where date >= :startDate and date <= :endDate")
|
||||
List<FlowReportMinuteDO> findListByDateRange(@Param("startDate") Date startDate, @Param("endDate") Date endDate);
|
||||
|
||||
@Insert("insert into flow_report_minute(`user_id`,`license_id`,`write_bytes`,`read_bytes`,`date`,`date_str`,`create_time`) values(:userId,:licenseId,:writeBytes,:readBytes,:date,:dateStr,:createTime)")
|
||||
void add(FlowReportMinuteDO flowReportMinuteDO);
|
||||
}
|
||||
|
||||
+25
-1
@@ -26,11 +26,19 @@ import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.NonIntercept;
|
||||
import fun.asgc.neutrino.core.quartz.IJobHandler;
|
||||
import fun.asgc.neutrino.core.quartz.annotation.JobHandler;
|
||||
import fun.asgc.neutrino.core.util.CollectionUtil;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/10/28
|
||||
@@ -46,10 +54,26 @@ public class FlowReportForHourJob implements IJobHandler {
|
||||
private LicenseMapper licenseMapper;
|
||||
@Autowired
|
||||
private FlowReportMinuteMapper flowReportMinuteMapper;
|
||||
@Autowired
|
||||
private FlowReportHourMapper flowReportHourMapper;
|
||||
|
||||
@Override
|
||||
public void execute(String param) throws Exception {
|
||||
// TODO
|
||||
Date now = new Date();
|
||||
String dateStr = DateUtil.format(DateUtil.addDate(now, Calendar.HOUR, -1), "yyyy-MM-dd HH");
|
||||
Date date = DateUtil.parse(dateStr, "yyyy-MM-dd HH");
|
||||
Date startHourDate = DateUtil.getHourBegin(date);
|
||||
Date endHourDate = DateUtil.getHourEnd(date);
|
||||
|
||||
// 删除原来的记录 TODO
|
||||
|
||||
// 查询前一个小时的分钟级别统计数据
|
||||
List<FlowReportMinuteDO> flowReportMinuteDOList = flowReportMinuteMapper.findListByDateRange(startHourDate, endHourDate);
|
||||
if (CollectionUtil.isEmpty(flowReportMinuteDOList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 汇总前一个小时的小时级别统计数据 TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user