|
|
|
|
@ -91,34 +91,24 @@
|
|
|
|
|
</foreach>
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<!-- 最新参数聚合查询:每设备每参数取最新一条记录 -->
|
|
|
|
|
<!-- 最新参数聚合查询:每设备每参数取最新一条记录,限制返回200条 -->
|
|
|
|
|
<select id="selectLatestBaseDeviceParamValList" parameterType="BaseDeviceParamVal" resultMap="BaseDeviceParamValResult">
|
|
|
|
|
WITH t AS (
|
|
|
|
|
SELECT * FROM (
|
|
|
|
|
SELECT
|
|
|
|
|
record_id,
|
|
|
|
|
param_code,
|
|
|
|
|
device_code,
|
|
|
|
|
device_id,
|
|
|
|
|
param_name,
|
|
|
|
|
param_value,
|
|
|
|
|
collect_time,
|
|
|
|
|
record_time,
|
|
|
|
|
ROW_NUMBER() OVER (PARTITION BY device_code, device_id, param_code ORDER BY NVL(record_time, collect_time) DESC, record_id DESC) AS rn
|
|
|
|
|
FROM base_device_param_val
|
|
|
|
|
<where>
|
|
|
|
|
<if test="paramCode != null and paramCode != ''"> and param_code = #{paramCode}</if>
|
|
|
|
|
<if test="deviceCode != null and deviceCode != ''"> and device_code = #{deviceCode}</if>
|
|
|
|
|
<if test="deviceId != null "> and device_id = #{deviceId}</if>
|
|
|
|
|
<if test="paramName != null and paramName != ''"> and param_name like concat(concat('%', #{paramName}), '%')</if>
|
|
|
|
|
<if test="paramValue != null and paramValue != ''"> and param_value = #{paramValue}</if>
|
|
|
|
|
<!-- 时间条件若提供,将在给定范围内取最新记录 -->
|
|
|
|
|
<if test="collectTime != null "> and collect_time = #{collectTime}</if>
|
|
|
|
|
<if test="recordTime != null "> and record_time = #{recordTime}</if>
|
|
|
|
|
</where>
|
|
|
|
|
)
|
|
|
|
|
SELECT record_id, param_code, device_code, device_id, param_name, param_value, collect_time, record_time
|
|
|
|
|
FROM t
|
|
|
|
|
WHERE rn = 1
|
|
|
|
|
ORDER BY device_code, device_id, param_code
|
|
|
|
|
record_id, param_code, device_code, device_id, param_name, param_value, collect_time, record_time,
|
|
|
|
|
ROW_NUMBER() OVER (ORDER BY device_code, param_code) AS row_num
|
|
|
|
|
FROM (
|
|
|
|
|
SELECT
|
|
|
|
|
record_id, param_code, device_code, device_id, param_name, param_value, collect_time, record_time,
|
|
|
|
|
ROW_NUMBER() OVER (PARTITION BY device_code, param_code ORDER BY NVL(record_time, collect_time) DESC) AS rn
|
|
|
|
|
FROM base_device_param_val
|
|
|
|
|
<where>
|
|
|
|
|
<if test="deviceCode != null and deviceCode != ''">and device_code = #{deviceCode}</if>
|
|
|
|
|
<if test="paramCode != null and paramCode != ''">and param_code = #{paramCode}</if>
|
|
|
|
|
<if test="deviceId != null">and device_id = #{deviceId}</if>
|
|
|
|
|
<if test="paramName != null and paramName != ''">and param_name like '%' || #{paramName} || '%'</if>
|
|
|
|
|
</where>
|
|
|
|
|
) WHERE rn = 1
|
|
|
|
|
) WHERE row_num <= 200
|
|
|
|
|
</select>
|
|
|
|
|
</mapper>
|