|
|
|
|
@ -100,6 +100,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
</choose>
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
质量页 WHERE 条件:
|
|
|
|
|
1. 仍按时间范围与设备范围筛选
|
|
|
|
|
2. 不在 SQL 层提前过滤位移有效值
|
|
|
|
|
这样 sampleCount 才能代表“质量统计样本总数”,不会被有效值条件提前缩小。
|
|
|
|
|
-->
|
|
|
|
|
<sql id="baseWhereQuality">
|
|
|
|
|
t.recodeTime >= #{query.beginRecordTime}
|
|
|
|
|
AND t.recodeTime <= #{query.endRecordTime}
|
|
|
|
|
<choose>
|
|
|
|
|
<when test="query.monitorId != null and query.monitorId != ''">
|
|
|
|
|
AND t.monitorId = #{query.monitorId}
|
|
|
|
|
</when>
|
|
|
|
|
<when test="query.monitorIds != null and query.monitorIds.size() > 0">
|
|
|
|
|
AND t.monitorId IN
|
|
|
|
|
<foreach collection="query.monitorIds" item="monitorId" open="(" separator="," close=")">
|
|
|
|
|
#{monitorId}
|
|
|
|
|
</foreach>
|
|
|
|
|
</when>
|
|
|
|
|
</choose>
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
原始查询:UNION ALL 多日分表 → 子查询 → 排序。
|
|
|
|
|
INNER JOIN monitor_type = 10 确保只查振动设备——这是「振动报表独立口径」的 SQL 层保障。
|
|
|
|
|
@ -184,6 +206,82 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
ORDER BY monitorId ASC, recodeTime ASC, objid ASC
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
质量页原始查询:与分析类查询不同,这里不按位移有效值过滤,
|
|
|
|
|
保证质量页分母代表“本次查询实际采到的样本数”。
|
|
|
|
|
-->
|
|
|
|
|
<sql id="rawQualityQuery">
|
|
|
|
|
SELECT *
|
|
|
|
|
FROM (
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
SELECT
|
|
|
|
|
<include refid="selectColumns"/>
|
|
|
|
|
FROM ${tableName} t
|
|
|
|
|
INNER JOIN ems_base_monitor_info ebmi
|
|
|
|
|
ON t.monitorId = ebmi.monitor_code
|
|
|
|
|
AND ebmi.monitor_type = 10
|
|
|
|
|
<where>
|
|
|
|
|
<include refid="baseWhereQuality"/>
|
|
|
|
|
</where>
|
|
|
|
|
</foreach>
|
|
|
|
|
) vibration_quality_data
|
|
|
|
|
ORDER BY vibration_quality_data.monitorId ASC, vibration_quality_data.recodeTime ASC, vibration_quality_data.objid ASC
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
质量页抽样查询:仅做时间桶抽样,不做位移有效值过滤,
|
|
|
|
|
避免质量统计在 SQL 层被“分析口径”提前污染。
|
|
|
|
|
-->
|
|
|
|
|
<sql id="samplingQualityQuery">
|
|
|
|
|
WITH sampled AS (
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
SELECT
|
|
|
|
|
<include refid="selectColumns"/>,
|
|
|
|
|
ROW_NUMBER() OVER (
|
|
|
|
|
PARTITION BY t.monitorId,
|
|
|
|
|
<choose>
|
|
|
|
|
<when test="_databaseId == 'mysql'">
|
|
|
|
|
CAST(TIMESTAMPDIFF(MINUTE, '2000-01-01 00:00:00', t.recodeTime) / #{query.samplingInterval} AS SIGNED)
|
|
|
|
|
</when>
|
|
|
|
|
<when test="_databaseId == 'postgresql' or _databaseId == 'PostgreSQL'">
|
|
|
|
|
CAST(EXTRACT(EPOCH FROM (t.recodeTime - TIMESTAMP '2000-01-01 00:00:00')) / 60 / #{query.samplingInterval} AS BIGINT)
|
|
|
|
|
</when>
|
|
|
|
|
<otherwise>
|
|
|
|
|
CAST(DATEDIFF(MINUTE, '2000-01-01 00:00:00', t.recodeTime) / #{query.samplingInterval} AS BIGINT)
|
|
|
|
|
</otherwise>
|
|
|
|
|
</choose>
|
|
|
|
|
ORDER BY t.recodeTime DESC, t.objid DESC
|
|
|
|
|
) AS rn
|
|
|
|
|
FROM ${tableName} t
|
|
|
|
|
INNER JOIN ems_base_monitor_info ebmi
|
|
|
|
|
ON t.monitorId = ebmi.monitor_code
|
|
|
|
|
AND ebmi.monitor_type = 10
|
|
|
|
|
<where>
|
|
|
|
|
<include refid="baseWhereQuality"/>
|
|
|
|
|
</where>
|
|
|
|
|
</foreach>
|
|
|
|
|
)
|
|
|
|
|
SELECT
|
|
|
|
|
objid,
|
|
|
|
|
monitorId,
|
|
|
|
|
monitor_code,
|
|
|
|
|
monitor_name,
|
|
|
|
|
temperature,
|
|
|
|
|
humidity,
|
|
|
|
|
illuminance,
|
|
|
|
|
noise,
|
|
|
|
|
concentration,
|
|
|
|
|
vibration_speed,
|
|
|
|
|
vibration_displacement,
|
|
|
|
|
vibration_acceleration,
|
|
|
|
|
vibration_temp,
|
|
|
|
|
collectTime,
|
|
|
|
|
recodeTime
|
|
|
|
|
FROM sampled
|
|
|
|
|
WHERE rn = 1
|
|
|
|
|
ORDER BY monitorId ASC, recodeTime ASC, objid ASC
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<!-- 原始明细查询入口(samplingInterval <= 1 时使用) -->
|
|
|
|
|
<select id="selectRawData" resultMap="VibrationBoardResult">
|
|
|
|
|
<include refid="rawPageQuery"/>
|
|
|
|
|
@ -193,4 +291,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
<select id="selectSampledData" resultMap="VibrationBoardResult">
|
|
|
|
|
<include refid="samplingPageQuery"/>
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 质量页原始样本查询入口(samplingInterval <= 1 时使用) -->
|
|
|
|
|
<select id="selectQualityRawData" resultMap="VibrationBoardResult">
|
|
|
|
|
<include refid="rawQualityQuery"/>
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 质量页抽样样本查询入口(samplingInterval > 1 时使用) -->
|
|
|
|
|
<select id="selectQualitySampledData" resultMap="VibrationBoardResult">
|
|
|
|
|
<include refid="samplingQualityQuery"/>
|
|
|
|
|
</select>
|
|
|
|
|
</mapper>
|
|
|
|
|
|