<?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.ProcessParameterTagMapper">


    <select id="getProcessParamInfoPage" resultType="com.lutao.cloud.oil.pojo.vo.ProcessParametersTagVO">
        SELECT
        DISTINCT ppt.tag_code,
        pi.platform_name AS platformName,
        pi.oil_gas_name AS oilGasName,
        pi.operating_company AS operatingCompany,
        ai.app_name AS appName,
        ppt.tag_type AS tagType,
        ppt.tag_name AS tagName,
        CONCAT(CONCAT(CONCAT( threshold_lo, '~', threshold_up ),'(',CONCAT( threshold_los, '~', threshold_ups )),')') AS
        upperLimit,
        CONCAT(ppt.threshold_los, '~', ppt.threshold_ups) AS upperUpperLimit,
        ppt.unit,

        ROUND(pd.rt_value, 2) AS rtValue,
        ppt.status
        FROM process_parameters_tag ppt
        LEFT JOIN platform_info pi ON ppt.platform_code = pi.platform_code
        LEFT JOIN app_info ai ON ai.id = ppt.app_id
        LEFT JOIN perception_dynamic pd ON ppt.tag_code = pd.tag_code
        <where>
            pi.delete_flag = '0' and ppt.del_flag = '0'
            <if test="param.platformId != null and param.platformId != ''">
                and ppt.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and ppt.app_id = #{param.appId}
            </if>
            <if test="param.operatingCompany != null and param.operatingCompany != ''">
                and pi.operating_company = #{param.operatingCompany}
            </if>
            <if test="param.oilGasName != null and param.oilGasName != ''">
                and pi.oil_gas_name = #{param.oilGasName}
            </if>
            <if test="param.paramType != null and param.paramType != ''">
                and ppt.tag_type = #{param.paramType}
            </if>
            <if test="true">
                and ppt.tag_type IN (
                2,3,5
                )
            </if>
            <if test="param.startDate != null">
                and pd.collect_time &gt;= #{param.startDate}
            </if>
            <if test="param.endDate != null">
                and pd.collect_time &lt;= #{param.endDate}
            </if>
            <if test="param.status != null and param.status != ''">
                and ppt.status = #{param.status}
            </if>
        </where>
        ORDER BY ppt.status  ASC, appName,platformName,oilGasName,operatingCompany ASC
    </select>
    <select id="earlyWarningMonitoringPointStatistic" resultType="com.lutao.cloud.oil.pojo.vo.MonitorPointVO">
        SELECT
        COUNT(*) AS pointNum,
        ai.app_name AS appName
        FROM
        process_parameters_tag ppt
        LEFT JOIN app_info ai ON ai.id = ppt.app_id
        LEFT JOIN platform_info pi ON ppt.platform_code = pi.platform_code
        <where>
            pi.delete_flag = '0' and ppt.del_flag = '0'
            AND ppt.tag_type IN ( 2, 3, 5 )
            AND ppt.STATUS = '0'
            <if test="param.platformId != null and param.platformId != ''">
                and ppt.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and ppt.app_id = #{param.appId}
            </if>
        </where>
        GROUP BY ai.app_name

    </select>
    <select id="selectCountWithPlatform" resultType="java.lang.Long">
        select count(*) from process_parameters_tag ppt
                                 left join platform_info pi on pi.platform_code = ppt.platform_code
        where ppt.status = '0' and pi.delete_flag = '0' and ppt.del_flag = '0'
    </select>
</mapper>