流量报表兼容sqlite

This commit is contained in:
aoshiguchen
2023-03-20 14:23:39 +08:00
parent 5a5b336baf
commit 2e34bf9bb6
3 changed files with 23 additions and 17 deletions
@@ -7,6 +7,7 @@ import fun.asgc.neutrino.proxy.server.controller.res.UserFlowReportRes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
@@ -15,18 +16,16 @@ import java.util.List;
*/
@Mapper
public interface ReportMapper {
/**
* 基于用户维度的流量报表
* @param req
* @param userId
* @return
*/
List<UserFlowReportRes> userFlowReportList(@Param("req") UserFlowReportReq req);
List<UserFlowReportRes> userFlowReportList(@Param("userId") Integer userId, @Param("curMonthBeginDate") Date curMonthBeginDate, @Param("curDayBeginDate") Date curDayBeginDate, @Param("curDate") Date curDate);
/**
* 基于license维度的流量报表
* @param req
* 基于用户维度的流量报表
* @param userId
* @return
*/
List<LicenseFlowReportRes> licenseFLowReportList(@Param("req")LicenseFlowReportReq req);
List<LicenseFlowReportRes> licenseFLowReportList(@Param("userId") Integer userId, @Param("curMonthBeginDate") Date curMonthBeginDate, @Param("curDayBeginDate") Date curDayBeginDate, @Param("curDate") Date curDate);
}
@@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import fun.asgc.neutrino.proxy.core.util.DateUtil;
import fun.asgc.neutrino.proxy.server.base.db.DbConfig;
import fun.asgc.neutrino.proxy.server.base.page.PageInfo;
import fun.asgc.neutrino.proxy.server.base.page.PageQuery;
import fun.asgc.neutrino.proxy.server.controller.req.LicenseFlowReportReq;
@@ -19,6 +21,7 @@ import org.apache.ibatis.solon.annotation.Db;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import java.util.Date;
import java.util.List;
/**
@@ -32,6 +35,8 @@ public class ReportService {
private MapperFacade mapperFacade;
@Db
private ReportMapper reportMapper;
@Inject
private DbConfig dbConfig;
/**
* 用户流量报表分页
@@ -41,7 +46,8 @@ public class ReportService {
*/
public PageInfo<UserFlowReportRes> userFlowReportPage(PageQuery pageQuery, UserFlowReportReq req) {
Page<UserFlowReportRes> result = PageHelper.startPage(pageQuery.getCurrent(), pageQuery.getSize());
List<UserFlowReportRes> list = reportMapper.userFlowReportList(req);
Date now = new Date();
List<UserFlowReportRes> list = reportMapper.userFlowReportList(req.getUserId(), DateUtil.getMonthBegin(now), DateUtil.getDayBegin(now), now);
fillUserFlowReport(list);
return PageInfo.of(list, result.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
}
@@ -54,7 +60,8 @@ public class ReportService {
*/
public PageInfo<LicenseFlowReportRes> licenseFlowReportPage(PageQuery pageQuery, LicenseFlowReportReq req) {
Page<LicenseFlowReportRes> result = PageHelper.startPage(pageQuery.getCurrent(), pageQuery.getSize());
List<LicenseFlowReportRes> list = reportMapper.licenseFLowReportList(req);
Date now = new Date();
List<LicenseFlowReportRes> list = reportMapper.licenseFLowReportList(req.getUserId(), DateUtil.getMonthBegin(now), DateUtil.getDayBegin(now), now);
fillLicenseFlowReport(list);
return PageInfo.of(list, result.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
}
@@ -17,14 +17,14 @@
FROM `user` u
LEFT JOIN (SELECT user_id,sum(write_bytes) write_bytes,sum(read_bytes) read_bytes from flow_report_month GROUP BY user_id) frm ON u.id = frm.user_id
LEFT JOIN (SELECT user_id,sum(write_bytes) write_bytes,sum(read_bytes) read_bytes from flow_report_day
WHERE date >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', month(CURDATE()), '-', '01'), '%Y-%m-%d') AND date &lt;= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', month(CURDATE()), '-', day(CURDATE())), '%Y-%m-%d')
WHERE date >= #{curMonthBeginDate} AND date &lt;= #{curDayBeginDate}
GROUP BY user_id) frd ON u.id = frd.user_id
LEFT JOIN (SELECT user_id,sum(write_bytes) write_bytes,sum(read_bytes) read_bytes from flow_report_minute
WHERE date >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', month(CURDATE()), '-', day(CURDATE())), '%Y-%m-%d') AND date &lt;= STR_TO_DATE(CONCAT(YEAR(CURDATE()),'-',MONTH(CURDATE()),'-',DAY(CURDATE()), ' ',HOUR(CURTIME()),':',MINUTE(CURTIME())), "%Y-%m-%d %H:%i")
WHERE date >= #{curDayBeginDate} AND date &lt;= #{curDate}
GROUP BY user_id) frm2 ON u.id = frm2.user_id
<where>
<if test="req.userId != null">
AND u.id = #{req.userId}
<if test="userId != null">
AND u.id = #{userId}
</if>
</where>
GROUP BY u.id
@@ -48,14 +48,14 @@
LEFT JOIN `user` u ON l.user_id = u.id
LEFT JOIN (SELECT license_id,sum(write_bytes) write_bytes,sum(read_bytes) read_bytes from flow_report_month GROUP BY license_id) frm ON l.id = frm.license_id
LEFT JOIN (SELECT license_id,sum(write_bytes) write_bytes,sum(read_bytes) read_bytes from flow_report_day
WHERE date >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', month(CURDATE()), '-', '01'), '%Y-%m-%d') AND date &lt;= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', month(CURDATE()), '-', day(CURDATE())), '%Y-%m-%d')
WHERE date >= #{curMonthBeginDate} AND #{curDayBeginDate}
GROUP BY license_id) frd ON l.id = frd.license_id
LEFT JOIN (SELECT license_id,sum(write_bytes) write_bytes,sum(read_bytes) read_bytes from flow_report_minute
WHERE date >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', month(CURDATE()), '-', day(CURDATE())), '%Y-%m-%d') AND date &lt;= STR_TO_DATE(CONCAT(YEAR(CURDATE()),'-',MONTH(CURDATE()),'-',DAY(CURDATE()), ' ',HOUR(CURTIME()),':',MINUTE(CURTIME())), "%Y-%m-%d %H:%i")
WHERE date >= #{curDayBeginDate} AND date &lt;= #{curDate}
GROUP BY license_id)frm2 ON l.id = frm2.license_id
<where>
<if test="req.userId != null">
AND u.id = #{req.userId}
<if test="userId != null">
AND u.id = #{userId}
</if>
</where>
GROUP BY l.id