254 lines
9.1 KiB
XML
254 lines
9.1 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
<mapper namespace="org.dromara.neutrinoproxy.server.dal.ReportMapper">
|
|
|
|
<select id="userFlowReportList" resultType="org.dromara.neutrinoproxy.server.controller.res.report.UserFlowReportRes">
|
|
SELECT
|
|
u.id AS userId,
|
|
u.name AS userName,
|
|
SUM(COALESCE(frm.write_bytes,0) + COALESCE(frd.write_bytes,0) + COALESCE(frm2.write_bytes,0)) AS upFlowBytes,
|
|
SUM(COALESCE(frm.read_bytes,0) + COALESCE(frd.read_bytes,0) + COALESCE(frm2.read_bytes,0)) AS downFlowBytes,
|
|
COALESCE(SUM(frm.write_bytes),0) monthWriteBytes,
|
|
COALESCE(SUM(frm.read_bytes),0) monthReadBytes,
|
|
COALESCE(SUM(frd.write_bytes),0) dayWriteBytes,
|
|
COALESCE(SUM(frd.read_bytes),0) dayReadBytes,
|
|
COALESCE(SUM(frm2.write_bytes),0) minuteWriteBytes,
|
|
COALESCE(SUM(frm2.read_bytes),0) minuteReadBytes
|
|
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 >= #{curMonthBeginDate} AND date <= #{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 >= #{curDayBeginDate} AND date <= #{curDate}
|
|
GROUP BY user_id) frm2 ON u.id = frm2.user_id
|
|
<where>
|
|
<if test="userId != null">
|
|
AND u.id = #{userId}
|
|
</if>
|
|
</where>
|
|
GROUP BY u.id
|
|
</select>
|
|
|
|
<select id="licenseFLowReportList" resultType="org.dromara.neutrinoproxy.server.controller.res.report.LicenseFlowReportRes">
|
|
SELECT
|
|
l.id AS licenseId,
|
|
l.name AS licenseName,
|
|
u.id AS userId,
|
|
u.name AS userName,
|
|
SUM(COALESCE(frm.write_bytes,0) + COALESCE(frd.write_bytes,0) + COALESCE(frm2.write_bytes,0)) AS upFlowBytes,
|
|
SUM(COALESCE(frm.read_bytes,0) + COALESCE(frd.read_bytes,0) + COALESCE(frm2.read_bytes,0)) AS downFlowBytes,
|
|
COALESCE(SUM(frm.write_bytes),0) monthWriteBytes,
|
|
COALESCE(SUM(frm.read_bytes),0) monthReadBytes,
|
|
COALESCE(SUM(frd.write_bytes),0) dayWriteBytes,
|
|
COALESCE(SUM(frd.read_bytes),0) dayReadBytes,
|
|
COALESCE(SUM(frm2.write_bytes),0) minuteWriteBytes,
|
|
COALESCE(SUM(frm2.read_bytes),0) minuteReadBytes
|
|
FROM `license` l
|
|
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 >= #{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 >= #{curDayBeginDate} AND date <= #{curDate}
|
|
GROUP BY license_id)frm2 ON l.id = frm2.license_id
|
|
<where>
|
|
<if test="userId != null">
|
|
AND u.id = #{userId}
|
|
</if>
|
|
</where>
|
|
GROUP BY l.id
|
|
</select>
|
|
|
|
<select id="userFlowMonthReportList" resultType="org.dromara.neutrinoproxy.server.controller.res.report.UserFlowMonthReportRes">
|
|
SELECT
|
|
T2.user_id,
|
|
u.name AS userName,
|
|
T2.date,
|
|
T2.upFlowBytes,
|
|
T2.downFlowBytes
|
|
FROM (
|
|
|
|
SELECT
|
|
frm.user_id,
|
|
frm.date,
|
|
COALESCE(SUM(frm.write_bytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(frm.read_bytes),0) AS downFlowBytes
|
|
FROM flow_report_month frm
|
|
GROUP BY frm.user_id,frm.date
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
T1.user_id,
|
|
#{curMonthBeginDate} AS date,
|
|
COALESCE(SUM(T1.upFlowBytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(T1.downFlowBytes),0) AS downFlowBytes
|
|
FROM (
|
|
|
|
SELECT
|
|
frd.user_id,
|
|
frd.license_id,
|
|
frd.write_bytes AS upFlowBytes,
|
|
frd.read_bytes AS downFlowBytes,
|
|
frd.date
|
|
FROM flow_report_day frd
|
|
WHERE frd.date >= #{curMonthBeginDate} AND frd.date <= #{curDayBeginDate}
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
frm.user_id,
|
|
frm.license_id,
|
|
COALESCE(SUM(frm.write_bytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(frm.read_bytes),0) AS downFlowBytes,
|
|
#{curDayBeginDate} AS date
|
|
FROM flow_report_minute frm
|
|
WHERE frm.date >= #{curDayBeginDate} AND frm.date <= #{curDate}
|
|
GROUP BY frm.user_id,frm.license_id
|
|
|
|
) T1
|
|
GROUP BY T1.user_id
|
|
|
|
) T2
|
|
LEFT JOIN `user` u ON u.id = T2.user_id
|
|
<where>
|
|
<if test="userId != null">
|
|
AND u.id = #{userId}
|
|
</if>
|
|
</where>
|
|
ORDER BY T2.user_id ASC,T2.date DESC
|
|
</select>
|
|
|
|
<select id="licenseFLowMonthReportList" resultType="org.dromara.neutrinoproxy.server.controller.res.report.LicenseFlowMonthReportRes">
|
|
SELECT
|
|
T2.user_id,
|
|
u.name AS userName,
|
|
T2.license_id,
|
|
l.`name` AS licenseName,
|
|
T2.date,
|
|
T2.upFlowBytes,
|
|
T2.downFlowBytes
|
|
FROM (
|
|
|
|
SELECT
|
|
frm.user_id,
|
|
frm.license_id,
|
|
frm.date,
|
|
COALESCE(SUM(frm.write_bytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(frm.read_bytes),0) AS downFlowBytes
|
|
FROM flow_report_month frm
|
|
GROUP BY frm.user_id,frm.license_id,frm.date
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
T1.user_id,
|
|
T1.license_id,
|
|
#{curMonthBeginDate} AS date,
|
|
COALESCE(SUM(T1.upFlowBytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(T1.downFlowBytes),0) AS downFlowBytes
|
|
FROM (
|
|
|
|
SELECT
|
|
frd.user_id,
|
|
frd.license_id,
|
|
frd.write_bytes AS upFlowBytes,
|
|
frd.read_bytes AS downFlowBytes,
|
|
frd.date
|
|
FROM flow_report_day frd
|
|
WHERE frd.date >= #{curMonthBeginDate} AND frd.date <= #{curDayBeginDate}
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
frm.user_id,
|
|
frm.license_id,
|
|
COALESCE(SUM(frm.write_bytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(frm.read_bytes),0) AS downFlowBytes,
|
|
#{curDayBeginDate} AS date
|
|
FROM flow_report_minute frm
|
|
WHERE frm.date >= #{curDayBeginDate} AND frm.date <= #{curDate}
|
|
GROUP BY frm.user_id,frm.license_id
|
|
|
|
) T1
|
|
GROUP BY T1.user_id,T1.license_id
|
|
|
|
) T2
|
|
LEFT JOIN `user` u ON u.id = T2.user_id
|
|
LEFT JOIN `license` l ON l.id = T2.license_id
|
|
<where>
|
|
<if test="userId != null">
|
|
AND u.id = #{userId}
|
|
</if>
|
|
<if test="licenseId != null">
|
|
AND l.id = #{licenseId}
|
|
</if>
|
|
</where>
|
|
ORDER BY T2.user_id ASC,T2.license_id,T2.date DESC
|
|
</select>
|
|
|
|
<select id="homeTodayFlow" resultType="org.dromara.neutrinoproxy.server.service.bo.FlowBO">
|
|
SELECT
|
|
COALESCE(SUM(frm.write_bytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(frm.read_bytes),0) AS downFlowBytes
|
|
FROM flow_report_minute frm
|
|
WHERE frm.date >= #{curDayBeginDate} AND frm.date <= #{curDate}
|
|
</select>
|
|
|
|
<select id="homeTotalFlow" resultType="org.dromara.neutrinoproxy.server.service.bo.FlowBO">
|
|
SELECT
|
|
COALESCE(SUM(T.upFlowBytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(T.downFlowBytes),0) AS downFlowBytes
|
|
FROM (
|
|
|
|
SELECT
|
|
COALESCE(SUM(frm.write_bytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(frm.read_bytes),0) AS downFlowBytes
|
|
FROM flow_report_month frm
|
|
UNION ALL
|
|
|
|
SELECT
|
|
COALESCE(SUM(frd.write_bytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(frd.read_bytes),0) AS downFlowBytes
|
|
FROM flow_report_day frd
|
|
WHERE frd.date >= #{curMonthBeginDate} AND frd.date <= #{curDayBeginDate}
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
COALESCE(SUM(frm.write_bytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(frm.read_bytes),0) AS downFlowBytes
|
|
FROM flow_report_minute frm
|
|
WHERE frm.date >= #{curDayBeginDate} AND frm.date <= #{curDate}
|
|
|
|
) T
|
|
</select>
|
|
|
|
<select id="homeLast7dFlowList" resultType="org.dromara.neutrinoproxy.server.service.bo.SingleDayFlowBO">
|
|
SELECT
|
|
T.*
|
|
FROM (
|
|
|
|
SELECT
|
|
frd.date,
|
|
COALESCE(SUM(frd.write_bytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(frd.read_bytes),0) AS downFlowBytes
|
|
FROM flow_report_day frd
|
|
WHERE frd.date >= #{beginDate} AND frd.date <= #{curDayBeginDate}
|
|
GROUP BY frd.date
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
#{curDayBeginDate} AS date,
|
|
COALESCE(SUM(frm.write_bytes),0) AS upFlowBytes,
|
|
COALESCE(SUM(frm.read_bytes),0) AS downFlowBytes
|
|
FROM flow_report_minute frm
|
|
WHERE frm.date >= #{curDayBeginDate} AND frm.date <= #{curDate}
|
|
|
|
) T
|
|
</select>
|
|
</mapper>
|