<?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="com.lutao.cloud.oil.mapper.PerceptionMonitorInfoMapper">


    <select id="selectNewRecore" resultType="com.lutao.entity.PerceptionMonitorInfo">
        SELECT *
        FROM perception_monitor_info a
        WHERE #{size} > (SELECT count(*)
                         FROM perception_monitor_info b
                         WHERE b.platform_code = a.platform_code
                           AND b.id &lt; a.id)
        ORDER BY a.platform_code,
                 a.id DESC
    </select>
    <select id="getProcessParamTag" resultType="com.lutao.cloud.oil.pojo.vo.ProcessTagVO">
        SELECT
        pi.platform_name AS platformName,
        pi.oil_gas_name AS oilGasName,
        pi.operating_company AS operatingCompany,
        ai.app_name AS appName,
        pmi.rt_value AS rtValue,
        pmi.tag_name AS tagName,
        pmi.collect_time AS collectTime,
        pmi.tag_type AS tagType,
        pmi.unit AS unit,
        pmi.limits AS limits
        FROM
        perception_monitor_info pmi
        LEFT JOIN platform_info pi ON pmi.platform_code = pi.platform_code
        LEFT JOIN app_info ai ON ai.id = pmi.app_id
        <where>
            pi.delete_flag = '0'
            <if test="param.platformId != null and param.platformId != ''">
               and pmi.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and pmi.app_id = #{param.appId}
            </if>
            <if test="param.paramType != null and param.paramType != ''">
                and pmi.tag_type = #{param.paramType}
            </if>
            <if test="true">
                and pmi.tag_type IN (
                2,3,5
                )
            </if>
            ORDER BY collectTime DESC
            -- LIMIT 10000
        </where>

    </select>
    <select id="getPerceptionMonitorInfoByTagCode" resultType="com.lutao.cloud.oil.pojo.vo.ProcessParametersTagVO">
        SELECT
        pi.platform_name AS platformName,
        pi.oil_gas_name AS oilGasName,
        pi.operating_company AS operatingCompany,
        ai.app_name AS appName,
        ROUND(pmi.rt_value,2) AS rtValue,
        pmi.tag_name AS tagName,
        pmi.collect_time AS collectTime,
        ppt.tag_code AS tagCode,
        ppt.unit AS unit,
        ppt.tag_type AS tagType,
        CONCAT(CONCAT(CONCAT( threshold_lo, '~', threshold_up ),'(',CONCAT( threshold_los, '~', threshold_ups )),')') AS upperLimit,
        CONCAT( ppt.threshold_los, '~', ppt.threshold_ups ) AS upperUpperLimit,
        ppt.status AS status
        FROM
        perception_monitor_info pmi
        LEFT JOIN platform_info pi ON pmi.platform_code = pi.platform_code
        LEFT JOIN app_info ai ON ai.id = pmi.app_id
        LEFT JOIN process_parameters_tag ppt ON pmi.tag_code = ppt.tag_code
        <where>
            pi.delete_flag = '0' and ppt.del_flag = '0'
            <if test="param.platformId != null and param.platformId != ''">
               and pmi.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and pmi.app_id = #{param.appId}
            </if>
            <if test="param.paramType != null and param.paramType != ''">
                and pmi.tag_type = #{param.paramType}
            </if>
            <if test="param.tagCode != null and param.tagCode != ''">
                and pmi.tag_code = #{param.tagCode}
            </if>
            <if test="param.startDate != null">
                and DATE(pmi.collect_time) &gt;= #{param.startDate}
            </if>
            <if test="param.endDate != null">
                and DATE(pmi.collect_time) &lt;= #{param.endDate}
            </if>
            -- GROUP BY platformName,oilGasName,operatingCompany,appName,rtValue,tagName,collectTime,tagCode,unit,tagType,upperLimit,upperUpperLimit,status
            ORDER BY collectTime DESC
        </where>
    </select>
</mapper>
