流量报表兼容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.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@@ -15,18 +16,16 @@ import java.util.List;
*/ */
@Mapper @Mapper
public interface ReportMapper { public interface ReportMapper {
/** /**
* 基于用户维度的流量报表 * 基于用户维度的流量报表
* @param req * @param userId
* @return * @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 * @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.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists; 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.PageInfo;
import fun.asgc.neutrino.proxy.server.base.page.PageQuery; import fun.asgc.neutrino.proxy.server.base.page.PageQuery;
import fun.asgc.neutrino.proxy.server.controller.req.LicenseFlowReportReq; 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.Component;
import org.noear.solon.annotation.Inject; import org.noear.solon.annotation.Inject;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@@ -32,6 +35,8 @@ public class ReportService {
private MapperFacade mapperFacade; private MapperFacade mapperFacade;
@Db @Db
private ReportMapper reportMapper; private ReportMapper reportMapper;
@Inject
private DbConfig dbConfig;
/** /**
* 用户流量报表分页 * 用户流量报表分页
@@ -41,7 +46,8 @@ public class ReportService {
*/ */
public PageInfo<UserFlowReportRes> userFlowReportPage(PageQuery pageQuery, UserFlowReportReq req) { public PageInfo<UserFlowReportRes> userFlowReportPage(PageQuery pageQuery, UserFlowReportReq req) {
Page<UserFlowReportRes> result = PageHelper.startPage(pageQuery.getCurrent(), pageQuery.getSize()); 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); fillUserFlowReport(list);
return PageInfo.of(list, result.getTotal(), pageQuery.getCurrent(), pageQuery.getSize()); 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) { public PageInfo<LicenseFlowReportRes> licenseFlowReportPage(PageQuery pageQuery, LicenseFlowReportReq req) {
Page<LicenseFlowReportRes> result = PageHelper.startPage(pageQuery.getCurrent(), pageQuery.getSize()); 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); fillLicenseFlowReport(list);
return PageInfo.of(list, result.getTotal(), pageQuery.getCurrent(), pageQuery.getSize()); return PageInfo.of(list, result.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
} }
@@ -17,14 +17,14 @@
FROM `user` u 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_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 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 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 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 GROUP BY user_id) frm2 ON u.id = frm2.user_id
<where> <where>
<if test="req.userId != null"> <if test="userId != null">
AND u.id = #{req.userId} AND u.id = #{userId}
</if> </if>
</where> </where>
GROUP BY u.id GROUP BY u.id
@@ -48,14 +48,14 @@
LEFT JOIN `user` u ON l.user_id = u.id 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_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 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 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 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 GROUP BY license_id)frm2 ON l.id = frm2.license_id
<where> <where>
<if test="req.userId != null"> <if test="userId != null">
AND u.id = #{req.userId} AND u.id = #{userId}
</if> </if>
</where> </where>
GROUP BY l.id GROUP BY l.id