<?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="cn.cecep.talroad.mapper.PointIsOfflineMapper">

    <select id="selectDisorganizationListByDateTime" resultType="cn.cecep.talroad.vo.PointIsOfflineVO">
        SELECT
            po."id" as outletId,
            po.factory_id,
            pf.factory_name,
            po.outlet_name,
            segr.monitoring_time as monitoringTime
        FROM
            pc_outlet po
            INNER JOIN pc_factory pf ON pf."id" = po.factory_id
            LEFT JOIN s_env_gas_real segr ON segr.factory_id = po.factory_id AND segr.outlet_id = po."id" AND segr.data_type = 'H'
                AND segr.monitoring_time &gt;= #{startTime} AND segr.monitoring_time &lt;= #{endTime}
        WHERE
            po.pollutant_type = '3'
    </select>

    <update id="updatePcOutletWzzStatus">
        UPDATE pc_outlet SET wzz_status = #{status} WHERE "id" = #{outletId}
    </update>

    <select id="selectOnLineMonitoringListByDateTime" resultType="cn.cecep.talroad.vo.PointIsOfflineVO">
        (
            SELECT
                po."id" as outletId,
                po.factory_id,
                pf.factory_name,
                po.outlet_name,
                po.pollutant_outlet_type,
                segmr.monitoring_time
            FROM
                pc_outlet po
                INNER JOIN pc_factory pf ON pf."id" = po.factory_id
                LEFT JOIN s_env_gas_mon_real segmr ON segmr.factory_id = po.factory_id AND segmr.outlet_id = po."id"
                AND segmr.data_type = 'M' AND segmr.monitoring_time &gt;= #{startTime} AND segmr.monitoring_time &lt;= #{endTime}
            WHERE
                po.pollutant_type = '4' AND po.pollutant_outlet_type = '1'
        )
        UNION ALL
        (
            SELECT
                po."id" as outletId,
                po.factory_id,
                pf.factory_name,
                po.outlet_name,
                po.pollutant_outlet_type,
                sewmr.monitoring_time
            FROM
                pc_outlet po
                INNER JOIN pc_factory pf ON pf."id" = po.factory_id
                LEFT JOIN s_env_water_mon_real sewmr ON sewmr.factory_id = po.factory_id AND  sewmr.outlet_id = po."id"
                AND sewmr.data_type = 'M' AND sewmr.monitoring_time &gt;= #{startTime} AND sewmr.monitoring_time &lt;= #{endTime}
            WHERE
                po.pollutant_type = '4' AND po.pollutant_outlet_type = '2'
        )

    </select>

    <update id="updatePcOutletOutletStatus">
        UPDATE pc_outlet SET outlet_status = #{status} WHERE "id" = #{outletId}
    </update>

    <update id="updatePcOutletStatus">
        update pc_outlet
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="outlet_status = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.outletStatus != null">
                        when id = #{item.outletId,jdbcType=VARCHAR} then #{item.outletStatus,jdbcType=VARCHAR}
                    </if>

                </foreach>
            </trim>
            <trim prefix="wzz_status = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.wzzStatus != null">
                        when id = #{item.outletId,jdbcType=VARCHAR} then #{item.wzzStatus,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
        </trim>
        where id in
        <foreach close=")" collection="list" item="item" open="(" separator=", ">
            #{item.outletId,jdbcType=VARCHAR}
        </foreach>
    </update>
</mapper>
