|
|
|
|
@ -918,38 +918,33 @@
|
|
|
|
|
|
|
|
|
|
<!-- ==================== H. 高级分析 ==================== -->
|
|
|
|
|
|
|
|
|
|
<!-- H1. 桑基图数据(温区按时间段流转) -->
|
|
|
|
|
<!-- H1. 桑基图数据(温区按时间段流转)
|
|
|
|
|
优化:每表内部先做 DISTINCT(monitorId+桶) 缩小数据量,再 UNION ALL 小结果集做全局自关联 -->
|
|
|
|
|
<select id="selectSankeyData" resultType="org.dromara.ems.report.domain.vo.tempboard.TempBoardAdvancedVo">
|
|
|
|
|
WITH base AS (
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
SELECT t.monitorId, t.temperature, t.collectTime
|
|
|
|
|
FROM ${tableName} t
|
|
|
|
|
<include refid="baseJoin"/>
|
|
|
|
|
<where>
|
|
|
|
|
<include refid="timeFilter"/>
|
|
|
|
|
<include refid="tempFilter"/>
|
|
|
|
|
</where>
|
|
|
|
|
</foreach>
|
|
|
|
|
),
|
|
|
|
|
bucketed AS (
|
|
|
|
|
SELECT monitorId, temperature, collectTime,
|
|
|
|
|
CASE
|
|
|
|
|
WHEN DATEPART(HOUR, collectTime) < 6 THEN 'T1'
|
|
|
|
|
WHEN DATEPART(HOUR, collectTime) < 12 THEN 'T2'
|
|
|
|
|
WHEN DATEPART(HOUR, collectTime) < 18 THEN 'T3'
|
|
|
|
|
ELSE 'T4'
|
|
|
|
|
END AS timeBucket,
|
|
|
|
|
CASE
|
|
|
|
|
WHEN temperature < 15 THEN '<15'
|
|
|
|
|
WHEN temperature < 20 THEN '15-20'
|
|
|
|
|
WHEN temperature < 25 THEN '20-25'
|
|
|
|
|
ELSE '>=25'
|
|
|
|
|
END AS tempBucket
|
|
|
|
|
FROM base
|
|
|
|
|
),
|
|
|
|
|
stage AS (
|
|
|
|
|
SELECT DISTINCT monitorId, timeBucket, tempBucket
|
|
|
|
|
FROM bucketed
|
|
|
|
|
WITH stage AS (
|
|
|
|
|
SELECT DISTINCT monitorId, timeBucket, tempBucket FROM (
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
SELECT DISTINCT t.monitorId,
|
|
|
|
|
CASE
|
|
|
|
|
WHEN DATEPART(HOUR, t.collectTime) < 6 THEN 'T1'
|
|
|
|
|
WHEN DATEPART(HOUR, t.collectTime) < 12 THEN 'T2'
|
|
|
|
|
WHEN DATEPART(HOUR, t.collectTime) < 18 THEN 'T3'
|
|
|
|
|
ELSE 'T4'
|
|
|
|
|
END AS timeBucket,
|
|
|
|
|
CASE
|
|
|
|
|
WHEN t.temperature < 15 THEN '<15'
|
|
|
|
|
WHEN t.temperature < 20 THEN '15-20'
|
|
|
|
|
WHEN t.temperature < 25 THEN '20-25'
|
|
|
|
|
ELSE '>=25'
|
|
|
|
|
END AS tempBucket
|
|
|
|
|
FROM ${tableName} t
|
|
|
|
|
<include refid="baseJoin"/>
|
|
|
|
|
<where>
|
|
|
|
|
<include refid="timeFilter"/>
|
|
|
|
|
<include refid="tempFilter"/>
|
|
|
|
|
</where>
|
|
|
|
|
</foreach>
|
|
|
|
|
) raw_stage
|
|
|
|
|
),
|
|
|
|
|
flow AS (
|
|
|
|
|
SELECT
|
|
|
|
|
@ -969,27 +964,56 @@
|
|
|
|
|
ORDER BY fromNode, toNode
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- H2. 主题河流图数据 -->
|
|
|
|
|
<!-- H2. 主题河流图数据
|
|
|
|
|
优化:GROUP BY 使用 DATEADD 时间桶(可走索引),外层 CONVERT 格式化输出(仅对聚合后小结果集);
|
|
|
|
|
支持动态粒度:MINUTE / FIFTEEN_MINUTE / HOUR -->
|
|
|
|
|
<select id="selectThemeRiverData" resultType="org.dromara.ems.report.domain.vo.tempboard.TempBoardAdvancedVo">
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
SELECT
|
|
|
|
|
FORMAT(t.collectTime, 'yyyy-MM-dd HH:mm:00') AS statTime,
|
|
|
|
|
t.monitorId,
|
|
|
|
|
COALESCE(ebmi.monitor_name, t.monitorId) AS monitorName,
|
|
|
|
|
ROUND(AVG(t.temperature), 2) AS avgTemp
|
|
|
|
|
FROM ${tableName} t
|
|
|
|
|
<include refid="baseJoin"/>
|
|
|
|
|
<where>
|
|
|
|
|
<include refid="timeFilter"/>
|
|
|
|
|
<include refid="tempFilter"/>
|
|
|
|
|
</where>
|
|
|
|
|
GROUP BY FORMAT(t.collectTime, 'yyyy-MM-dd HH:mm:00'), t.monitorId,
|
|
|
|
|
COALESCE(ebmi.monitor_name, t.monitorId)
|
|
|
|
|
</foreach>
|
|
|
|
|
SELECT
|
|
|
|
|
CONVERT(VARCHAR(19), statBucket, 120) AS statTime,
|
|
|
|
|
monitorId, monitorName, avgTemp
|
|
|
|
|
FROM (
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
SELECT
|
|
|
|
|
<choose>
|
|
|
|
|
<when test="granularity == 'HOUR'">
|
|
|
|
|
DATEADD(HOUR, DATEDIFF(HOUR, 0, t.collectTime), 0)
|
|
|
|
|
</when>
|
|
|
|
|
<when test="granularity == 'FIFTEEN_MINUTE'">
|
|
|
|
|
DATEADD(MINUTE, (DATEDIFF(MINUTE, 0, t.collectTime) / 15) * 15, 0)
|
|
|
|
|
</when>
|
|
|
|
|
<otherwise>
|
|
|
|
|
DATEADD(MINUTE, DATEDIFF(MINUTE, 0, t.collectTime), 0)
|
|
|
|
|
</otherwise>
|
|
|
|
|
</choose> AS statBucket,
|
|
|
|
|
t.monitorId,
|
|
|
|
|
COALESCE(ebmi.monitor_name, t.monitorId) AS monitorName,
|
|
|
|
|
ROUND(AVG(t.temperature), 2) AS avgTemp
|
|
|
|
|
FROM ${tableName} t
|
|
|
|
|
<include refid="baseJoin"/>
|
|
|
|
|
<where>
|
|
|
|
|
<include refid="timeFilter"/>
|
|
|
|
|
<include refid="tempFilter"/>
|
|
|
|
|
</where>
|
|
|
|
|
GROUP BY
|
|
|
|
|
<choose>
|
|
|
|
|
<when test="granularity == 'HOUR'">
|
|
|
|
|
DATEADD(HOUR, DATEDIFF(HOUR, 0, t.collectTime), 0)
|
|
|
|
|
</when>
|
|
|
|
|
<when test="granularity == 'FIFTEEN_MINUTE'">
|
|
|
|
|
DATEADD(MINUTE, (DATEDIFF(MINUTE, 0, t.collectTime) / 15) * 15, 0)
|
|
|
|
|
</when>
|
|
|
|
|
<otherwise>
|
|
|
|
|
DATEADD(MINUTE, DATEDIFF(MINUTE, 0, t.collectTime), 0)
|
|
|
|
|
</otherwise>
|
|
|
|
|
</choose>,
|
|
|
|
|
t.monitorId, COALESCE(ebmi.monitor_name, t.monitorId)
|
|
|
|
|
</foreach>
|
|
|
|
|
) sub
|
|
|
|
|
ORDER BY statTime, monitorId
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- H3. 矩形树图数据(按测点平均温度+样本数) -->
|
|
|
|
|
<!-- H3. 矩形树图数据(按测点平均温度+样本数)
|
|
|
|
|
每张日表独立聚合,UNION ALL 直接输出 -->
|
|
|
|
|
<select id="selectTreemapData" resultType="org.dromara.ems.report.domain.vo.tempboard.TempBoardAdvancedVo">
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
SELECT t.monitorId,
|
|
|
|
|
@ -1007,7 +1031,8 @@
|
|
|
|
|
ORDER BY avgTemp DESC
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- H4. 旭日图数据(温区→测点层级) -->
|
|
|
|
|
<!-- H4. 旭日图数据(温区→测点层级)
|
|
|
|
|
每张日表独立聚合,UNION ALL 直接输出 -->
|
|
|
|
|
<select id="selectSunburstData" resultType="org.dromara.ems.report.domain.vo.tempboard.TempBoardAdvancedVo">
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
SELECT
|
|
|
|
|
@ -1040,7 +1065,8 @@
|
|
|
|
|
ORDER BY tempBucket, monitorId
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- H5. 平行坐标图数据(多维温度画像) -->
|
|
|
|
|
<!-- H5. 平行坐标图数据(多维温度画像)
|
|
|
|
|
每张日表独立聚合,UNION ALL 直接输出 -->
|
|
|
|
|
<select id="selectParallelData" resultType="org.dromara.ems.report.domain.vo.tempboard.TempBoardAdvancedVo">
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
SELECT t.monitorId,
|
|
|
|
|
|