<?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="org.jeecg.modules.newWarning.mapper.PumpingPressureWarnLogMapper">
    <select id="getWarnLogList" resultType="org.jeecg.modules.newWarning.dto.WarnLogComprehensiveDto">
        SELECT
        k.jh,
        k.yjlb,
        k.zxbjsj,
        k.lsbjcs,
        k.yjms
        FROM
        (
        SELECT
        c.jh,
        '泵压变化异常' AS yjlb,
        c.zxbjsj,
        i.lsbjcs,
        f.warn_des AS yjms
        FROM
        (
        SELECT
        b.jh,
        MAX( b.WARN_TIME ) AS zxbjsj
        FROM
        ( SELECT DISTINCT a.jh, a.WARN_TIME AS warn_time FROM PUMPING_PRESSURE_WARN_LOG a ) b
        WHERE
        b.warn_time BETWEEN TO_DATE(#{params.strDate}, 'yyyy-mm-dd' )
        AND TO_DATE(#{params.endDate}, 'yyyy-mm-dd' )
        GROUP BY
        jh
        ) c
        LEFT JOIN (
        SELECT
        d.JH,
        COUNT( 1 ) LSBJCS
        FROM
        (
        SELECT
        h.JH,
        h.warn_time
        FROM
        ( SELECT DISTINCT g.jh,  g.WARN_TIME AS warn_time FROM PUMPING_PRESSURE_WARN_LOG g ) h
        WHERE
        h.WARN_TIME BETWEEN TO_DATE(#{params.strDate}, 'yyyy-mm-dd' )
        AND TO_DATE(#{params.endDate}, 'yyyy-mm-dd' )
        ) d
        GROUP BY
        d.jh
        ) i ON i.jh = c.jh
        LEFT JOIN (
        SELECT
        *
        FROM
        ( SELECT DISTINCT e.jh,  e.WARN_TIME AS warn_time, WARN_DES FROM PUMPING_PRESSURE_WARN_LOG e ) j
        WHERE
        j.WARN_TIME BETWEEN TO_DATE(#{params.strDate}, 'yyyy-mm-dd' )
        AND TO_DATE(#{params.endDate}, 'yyyy-mm-dd' )
        ) f ON f.warn_time = c.zxbjsj
        AND f.jh = c.jh
        ) k
        WHERE 1=1
        <choose>
            <when test="params.jhs!=null and params.jhs.size() >0">
                and  k.jh IN
                <foreach collection="params.jhs" item="item" index="index" open="(" separator="," close=")">
                    #{item,jdbcType=VARCHAR}
                </foreach>
            </when>
            <when test="params.jhs==null and params.jhs.size() ==0">
                and  k.jh =''
            </when>
        </choose>
    </select>

    <select id="getWarnLogCount" resultType="org.jeecg.modules.newWarning.dto.WarnLogStatisticsDto">
        SELECT
        jh,
        zxbjrq,
        bjcs
        FROM
        (
        SELECT
        b.jh,
        max( b.warn_time ) AS zxbjrq,
        COUNT( 1 ) AS bjcs
        FROM
        ( SELECT DISTINCT a.jh,  a.warn_time AS warn_time FROM PUMPING_PRESSURE_WARN_LOG a ) b
        GROUP BY
        jh
        )
        <if test="ew != null">
            ${ew.customSqlSegment}
        </if>
    </select>
</mapper>
