<?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.huatek.busi.mapper.BusiEqmWarningMapper">
    <sql id="Base_Column_List">
            id as id,
            warning_code as warningCode,
            sensor_id as sensorId,
            eq_type as eqType,
            gz_type as gzType,
            warning_flag as warningFlag,
            warning_type_code as warningTypeCode,
            warning_msg as warningMsg,
            warning_time as warningTime,
            create_time as createTime,
            del_flag as delFlag,
            deal_status as dealStatus,
            deal_msg as dealMsg,
            warning_type as warningType,
            site_id as siteId,
            main_equipment_id as mainEquipmentId,
            sub_equipment_id as subEquipmentId,
            processing_time as processingTime,
            processing_user as processingUser,
            sub_equipment_install_location as subEquipmentInstallLocation,
            sub_equipment_brand as subEquipmentBrand,
            sub_equipment_manufactor as subEquipmentManufactor,
            sensor_install_location as sensorInstallLocation,
            sensor_brand as sensorBrand,
            sensor_manufactor as sensorManufactor,
            sub_equipment_name as subEquipmentName,
            sensor_name as sensorName,
            sub_tree_id as subTreeId,
            main_tree_id as mainTreeId,
            run_state as runState
    </sql>
    <!-- 关联查询的SQL返回列 -->
    <sql id="Base_Ref_Column_List">
        t.id,
        t.site_id as siteId,
        t.main_tree_id as mainTreeId,
        t.sub_tree_id as subTreeId,
        t.warning_flag as warningFlag,
        t.main_equipment_id as mainEquipmentId,
        t.sub_equipment_id as subEquipmentId,
        t.warning_code as warningCode,
        t.sensor_id as sensorId,
        t.eq_type as eqType,
        t.gz_type as gzType,
        t.warning_type_code as warningTypeCode,
        t.warning_msg as warningMsg,
        t.warning_time as warningTime,
        t.create_time as createTime,
        t.del_flag as delFlag,
        t.deal_status as dealStatus,
        t.deal_msg as dealMsg,
        t.warning_type as warningType,
        t.processing_time as processingTime,
        <!-- t.processing_user as processingUser, -->
        (SELECT su.user_name FROM sys_user su WHERE su.id = processing_user) as processingUser,
        <!-- 外挂设备相关
           t.sub_equipment_install_location,
           t.sub_equipment_brand,
           t.sub_equipment_manufactor,
           t.sub_equipment_name, -->
        ext.equipment_name AS subEquipmentName,
        ext.equipment_brand AS subEquipmentBrand,
        ext.manufactor AS subEquipmentManufactor,
        ext.install_location AS subEquipmentInstallLocation,
        <!-- 传感器相关
           t.sensor_install_location,
           t.sensor_brand,
           t.sensor_manufactor,
           t.sensor_name, -->
        CONCAT_WS('', t_sensor.sensor_name, g_sensor.sensor_name,ge_sensor.sensor_name, a_sensor.sensor_name, o_sensor.sensor_name,
        p_sensor.sensor_name) AS sensorName,
        CONCAT_WS('', t_sensor.sensor_brand, g_sensor.sensor_brand,ge_sensor.sensor_brand, a_sensor.sensor_brand, o_sensor.sensor_brand,
        p_sensor.sensor_brand) AS sensorBrand,
        CONCAT_WS('', t_sensor.manufactor, g_sensor.manufactor,ge_sensor.manufactor, a_sensor.manufactor, o_sensor.manufactor,
        p_sensor.manufactor) AS sensorManufactor,
        CONCAT_WS('', t_sensor.position_des, g_sensor.position_des,ge_sensor.position_des, a_sensor.position_des, o_sensor.position_des,
        p_sensor.position_des) AS sensorInstallLocation,
        CONCAT_WS('', t_sensor.use_date, g_sensor.use_date,ge_sensor.use_date, a_sensor.use_date, o_sensor.use_date, p_sensor.use_date) AS
        sensorUseDate,
        CONCAT_WS('',t_sensor.position,g_sensor.position,ge_sensor.position,a_sensor.position,o_sensor.position,p_sensor.position) AS
        sensorPosition,
        t.run_state as runState,
        bst.name AS mainEquipmentName,
        CONCAT_WS('',transformer_sub.equipment_type,gis_sub.equipment_type,gen_sub.equipment_type,arrester_sub.equipment_type,other_sub.equipment_type)
        as subEquipmentType
    </sql>

    <!-- 表关联 -->
    <sql id="Base_Table_Ref">
		busi_eqm_warning t
			LEFT JOIN busi_transformer_sensor t_sensor ON t.sensor_id = t_sensor.sensor_code
			LEFT JOIN busi_gis_sensor g_sensor ON t.sensor_id = g_sensor.sensor_code
			LEFT JOIN busi_arrester_sensor a_sensor ON t.sensor_id = a_sensor.sensor_code
			LEFT JOIN busi_generator_sensor ge_sensor ON t.sensor_id = ge_sensor.sensor_code
			LEFT JOIN busi_other_sensor o_sensor ON t.sensor_id = o_sensor.sensor_code
			LEFT JOIN busi_temper_point p_sensor ON t.sensor_id = p_sensor.sensor_code
            LEFT JOIN busi_cable_sensor cab_sensor ON t.sensor_id = cab_sensor.sensor_code

			LEFT JOIN busi_external_equipment ext ON CONCAT_WS('',t_sensor.equipment_id,g_sensor.equipment_id,a_sensor.equipment_id,o_sensor.equipment_id) = ext.equipment_id
			LEFT JOIN busi_transformer_sub_tree transformer_sub ON t_sensor.equipment_id = transformer_sub.id
			LEFT JOIN busi_gis_sub_tree gis_sub ON g_sensor.equipment_id = gis_sub.id
			LEFT JOIN busi_generator_sub_tree gen_sub ON ge_sensor.equipment_id = gen_sub.id
			LEFT JOIN busi_arrester_sub_tree arrester_sub ON a_sensor.equipment_id = arrester_sub.id
			LEFT JOIN busi_other_sub_tree other_sub ON o_sensor.equipment_id = other_sub.id
            LEFT JOIN busi_cable_sub_tree cab_sub ON cab_sensor.equipment_id = cab_sub.id
			LEFT JOIN busi_site_tree bst ON  CONCAT_WS('',transformer_sub.equipment_id,gis_sub.equipment_id,arrester_sub.equipment_id,other_sub.equipment_id,gen_sub.equipment_id,cab_sub.equipment_id) = bst.id
	</sql>

    <!-- 告警单分页查询 -->
    <select id="selectBusiEqmWarningPage" resultType="com.huatek.busi.vo.BusiEqmWarningVo">
        SELECT
        <include refid="Base_Ref_Column_List"/>
        FROM
        <include refid="Base_Table_Ref"/>
        WHERE warning_flag='1'
        and t.eq_type <![CDATA[!= ]]> '4'
        <if test="sensorId != null and sensorId != ''">
            and t.sensor_id like CONCAT(CONCAT('%', #{sensorId}), '%')
        </if>
        <if test="dealStatus != null and dealStatus != ''">
            and t.deal_status = #{dealStatus}
        </if>
        <if test="eqType != null and eqType != ''">
            and t.eq_type = #{eqType}
        </if>
        <if test="gzType != null and gzType != ''">
            and t.gz_type = #{gzType}
        </if>
        <if test="mainEquipmentName != null and mainEquipmentName != ''">
            and bst.name like CONCAT(CONCAT('%', #{mainEquipmentName}), '%')
        </if>
        <if test="subEquipmentName != null and subEquipmentName != ''">
            and ext.equipment_name like CONCAT(CONCAT('%', #{subEquipmentName}), '%')
        </if>
        <if test="sensorBrand != null and sensorBrand != ''">
            and CONCAT_WS('', t_sensor.sensor_brand, g_sensor.sensor_brand,ge_sensor.sensor_brand, a_sensor.sensor_brand,
            o_sensor.sensor_brand, p_sensor.sensor_brand, cab_sensor.sensor_brand) LIKE CONCAT(CONCAT('%', #{sensorBrand}), '%')
        </if>
        <if test="sensorName != null and sensorName != ''">
            and CONCAT_WS('', t_sensor.sensor_name, g_sensor.sensor_name,ge_sensor.sensor_name, a_sensor.sensor_name, o_sensor.sensor_name,
            p_sensor.sensor_name, cab_sensor.sensor_name) LIKE CONCAT(CONCAT('%', #{sensorName}), '%')
        </if>
        <if test="sensorManufactor != null and sensorManufactor != ''">
            and CONCAT_WS('', t_sensor.manufactor, g_sensor.manufactor,ge_sensor.manufactor, a_sensor.manufactor, o_sensor.manufactor,
            p_sensor.manufactor, cab_sensor.manufactor) LIKE CONCAT(CONCAT('%', #{sensorManufactor}), '%')
        </if>
        <if test="sensorInstallLocation != null and sensorInstallLocation != ''">
            and CONCAT_WS('', t_sensor.position_des, g_sensor.position_des,ge_sensor.position_des, a_sensor.position_des,
            o_sensor.position_des, p_sensor.position_des, cab_sensor.position_des) LIKE CONCAT(CONCAT('%', #{sensorInstallLocation}), '%')
        </if>
        <if test="equipmentType != null and equipmentType != ''">
            and bst.equipment_type = #{equipmentType}
        </if>
        <if test="subEquipmentType != null and subEquipmentType != ''">
            <choose>
                <when test="equipmentType == '111'.toString and subEquipmentType == '031'.toString">
                    and transformer_sub.equipment_type in ('081', '031')
                </when>
                <otherwise>
                    and
                    CONCAT_WS('',transformer_sub.equipment_type,gis_sub.equipment_type,gen_sub.equipment_type,arrester_sub.equipment_type,other_sub.equipment_type, cab_sub.equipment_type)
                    = #{subEquipmentType}
                </otherwise>
            </choose>
        </if>
        <if test="warningTime != null">
            and DATE_FORMAT(t.warning_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{warningTime},'%Y-%m-%d')
        </if>
        <if test="warningTimeEnd != null">
            and DATE_FORMAT(t.warning_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{warningTimeEnd},'%Y-%m-%d')
        </if>
        GROUP BY t.sensor_id, t.create_time, t.warning_msg
        order by t.warning_time desc
    </select>


    <!-- 告警单分页查询 -->
    <select id="queryThresholdList" resultType="com.huatek.busi.vo.BusiEqmWarningVo">
        SELECT
        <include refid="Base_Ref_Column_List"/>
        FROM
        <include refid="Base_Table_Ref"/>
        WHERE warning_flag='2'
        and t.eq_type <![CDATA[!= ]]> '4'
        <if test="sensorId != null and sensorId != ''">
            and t.sensor_id like CONCAT(CONCAT('%', #{sensorId}), '%')
        </if>
        <if test="dealStatus != null and dealStatus != ''">
            and t.deal_status = #{dealStatus}
        </if>
        <if test="eqType != null and eqType != ''">
            and t.eq_type = #{eqType}
        </if>
        <if test="gzType != null and gzType != ''">
            and t.gz_type = #{gzType}
        </if>
        <if test="mainEquipmentName != null and mainEquipmentName != ''">
            and bst.name like CONCAT(CONCAT('%', #{mainEquipmentName}), '%')
        </if>
        <if test="subEquipmentName != null and subEquipmentName != ''">
            and ext.equipment_name like CONCAT(CONCAT('%', #{subEquipmentName}), '%')
        </if>
        <if test="sensorBrand != null and sensorBrand != ''">
            and CONCAT_WS('', t_sensor.sensor_brand, g_sensor.sensor_brand, a_sensor.sensor_brand,
            o_sensor.sensor_brand, p_sensor.sensor_brand, cab_sensor.sensor_brand) LIKE CONCAT(CONCAT('%', #{sensorBrand}), '%')
        </if>
        <if test="sensorName != null and sensorName != ''">
            and CONCAT_WS('', t_sensor.sensor_name, g_sensor.sensor_name, a_sensor.sensor_name, o_sensor.sensor_name,
            p_sensor.sensor_name, cab_sensor.sensor_name) LIKE CONCAT(CONCAT('%', #{sensorName}), '%')
        </if>
        <if test="sensorManufactor != null and sensorManufactor != ''">
            and CONCAT_WS('', t_sensor.manufactor, g_sensor.manufactor, a_sensor.manufactor, o_sensor.manufactor,
            p_sensor.manufactor, cab_sensor.manufactor) LIKE CONCAT(CONCAT('%', #{sensorManufactor}), '%')
        </if>
        <if test="sensorInstallLocation != null and sensorInstallLocation != ''">
            and CONCAT_WS('', t_sensor.position_des, g_sensor.position_des, a_sensor.position_des,
            o_sensor.position_des, p_sensor.position_des, cab_sensor.position_des) LIKE CONCAT(CONCAT('%', #{sensorInstallLocation}), '%')
        </if>
        <if test="equipmentType != null and equipmentType != ''">
            and bst.equipment_type = #{equipmentType}
        </if>
        <if test="subEquipmentType != null and subEquipmentType != ''">
            <choose>
                <when test="equipmentType == '111'.toString and subEquipmentType == '031'.toString">
                    and transformer_sub.equipment_type in ('081', '031')
                </when>
                <otherwise>
                    and
                    CONCAT_WS('',transformer_sub.equipment_type,gis_sub.equipment_type,arrester_sub.equipment_type,other_sub.equipment_type, cab_sub.equipment_type)
                    = #{subEquipmentType}
                </otherwise>
            </choose>
        </if>
        <if test="warningTime != null">
            and DATE_FORMAT(t.warning_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{warningTime},'%Y-%m-%d')
        </if>
        <if test="warningTimeEnd != null">
            and DATE_FORMAT(t.warning_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{warningTimeEnd},'%Y-%m-%d')
        </if>
        GROUP BY t.sensor_id, t.create_time, t.warning_msg
        order by t.warning_time desc
    </select>

    <select id="getBusiEqmWarningCount"
            resultType="java.lang.Integer">
        SELECT
        COUNT(*) AS total
        FROM busi_eqm_warning
        <where>
            and del_flag = '1'
            <if test="mainTreeId != null and mainTreeId != '' ">
                and main_tree_id = #{mainTreeId}
            </if>
            <if test="sensorCode != null and sensorCode != '' ">
                and sensor_id = #{sensorCode}
            </if>
            <if test="warningType != null and warningType != '' ">
                and warning_type = #{warningType}
            </if>
            <if test="startTime !=null">
                and DATE_FORMAT(warning_time,'%Y-%m-%d') <![CDATA[>= ]]> DATE_FORMAT(#{startTime},'%Y-%m-%d')
            </if>
            <if test="endTime != null">
                and DATE_FORMAT(warning_time,'%Y-%m-%d') <![CDATA[<= ]]> DATE_FORMAT(#{endTime},'%Y-%m-%d')
            </if>
        </where>
    </select>

    <select id="lockDealStatus" resultType="java.lang.String">
		SELECT t.deal_status FROM busi_eqm_warning t WHERE t.id = #{id} FOR UPDATE
	</select>

<!--     <select id="findCurrentWarningList" resultType="com.huatek.busi.vo.warning.BusiHomePageWarningVo">
        SELECT
        t.warningId,
        t.sensorCode,
        t.eqType,
        t.gzType,
        t.warningMsg,
        t.warningTime,
        t.mainTreeId,
        t.siteId,
        t.warningFlag,
        t.runState
        FROM
        (
        SELECT
        b.id AS warningId,
        b.sensor_id AS sensorCode,
        b.eq_type AS eqType,
        b.gz_type AS gzType,
        b.warning_msg AS warningMsg,
        b.warning_time AS warningTime,
        b.main_tree_id AS mainTreeId,
        b.site_id as siteId,
        b.warning_flag as warningFlag,
        b.run_state as runState
        FROM
        `busi_eqm_warning` b
        <where>
            b.del_flag = '1' AND b.deal_status = '0'
            <if test="eqType != null and eqType != ''">
                AND b.eq_type = #{eqType}
            </if>
            <if test="gzType != null and gzType != ''">
                <choose>
                    <when test="gzType == '3'">
                        AND b.gz_type in ('3','8')
                    </when>
                    <otherwise>
                        AND b.gz_type = #{gzType}
                    </otherwise>
                </choose>
            </if>
            <if test="warningMsg != null and warningMsg != ''">
                AND b.warning_msg like concat('%', #{warningMsg}, '%')
            </if>
            <if test="warningTime != null">
                and DATE_FORMAT(b.warning_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{warningTime},'%Y-%m-%d')
            </if>
            <if test="warningTimeEnd != null">
                and DATE_FORMAT(b.warning_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{warningTimeEnd},'%Y-%m-%d')
            </if>
        </where>
        ORDER BY
        b.warning_time DESC limit 999999) t GROUP BY t.gzType ORDER BY t.warningTime DESC
    </select> -->

	<select id="findCurrentWarningList" parameterType="com.huatek.busi.dto.BusiEqmWarningDto" resultType="com.huatek.busi.vo.warning.BusiHomePageWarningVo">
		SELECT
			b.id AS warningId,
			b.sensor_id AS sensorCode,
			b.eq_type AS eqType,
			b.gz_type AS gzType,
			b.warning_msg AS warningMsg,
			b.warning_time AS warningTime,
			b.main_tree_id AS mainTreeId,
			b.site_id as siteId,
            b.sensor_name AS sensorName,
			b.sensor_install_location AS sensorInstallLocation,
            bb.warning_info as warningInfo
        FROM
			`busi_eqm_warning` b
        LEFT JOIN busi_eqm_warning_info bb on bb.warning_id = b.id
        <where>
			b.del_flag = '1' AND b.deal_status = '0'
			<if test="eqType != null and eqType != ''">
				AND b.eq_type = #{eqType}
			</if>
			<if test="gzType != null and gzType != ''">
				AND b.gz_type = #{gzType}
			</if>
            <if test="warningTime != null">
                and DATE_FORMAT(b.warning_time,'%Y-%m-%d') &gt;= DATE_FORMAT(#{warningTime},'%Y-%m-%d')
            </if>
            <if test="warningTimeEnd != null">
                and DATE_FORMAT(b.warning_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{warningTimeEnd},'%Y-%m-%d')
            </if>
            <if test="sensorId != null and sensorId != ''">
                AND b.sensor_id = #{sensorId}
            </if>
		</where>
		ORDER BY
			b.warning_time DESC
	</select>

<!--    <select id="getCurrentWarningSum" resultType="java.lang.Integer">-->
<!--        SELECT COUNT(*) FROM `busi_eqm_warning` b-->
<!--        <where>-->
<!--            b.del_flag = '1'-->
<!--            AND b.deal_status = '0'-->
<!--            AND b.eq_type = #{eqType}-->
<!--            AND b.gz_type = #{gzType}-->
<!--        </where>-->
<!--    </select>-->


    <select id="findCurrentWarningBySensorCodeList" parameterType="com.huatek.busi.dto.BusiEqmWarningDto" resultType="com.huatek.busi.vo.warning.BusiHomePageWarningVo">
        select
            t.sensorCode AS sensorCode,
            t.eqType AS eqType,
            t.gzType AS gzType,
            t.warningMsg AS warningMsg,
            t.warningTime AS warningTime,
            t.mainTreeId AS mainTreeId,
            t.warningId AS warningId,
            t.siteId as siteId,
            t.sensorInstallLocation AS sensorInstallLocation,
            CONCAT_WS(",",t.oName,t.cableName,t.tName,t.gName,t.aName,t.genName) as sensorName
        from (
            select
            warn.id AS warningId,
            warn.sensor_id AS sensorCode,
            warn.eq_type AS eqType,
            warn.gz_type AS gzType,
            warn.warning_msg AS warningMsg,
            warn.warning_time AS warningTime,
            warn.main_tree_id AS mainTreeId,
            warn.site_id as siteId,
            warn.sensor_install_location AS sensorInstallLocation,
            ( select os.sensor_name from busi_other_sensor os where os.sensor_code=warn.sensor_id and os.status= '1') as oName,
            ( select cable.sensor_name from busi_cable_sensor cable where cable.sensor_code=warn.sensor_id and cable.status= '1') as cableName,
            ( select ts.sensor_name from busi_transformer_sensor ts where ts.sensor_code=warn.sensor_id and ts.status= '1') as tName,
            ( select gs.sensor_name from busi_gis_sensor gs where gs.sensor_code=warn.sensor_id and gs.status= '1') as gName,
            ( select asensor.sensor_name from busi_arrester_sensor asensor where asensor.sensor_code=warn.sensor_id and asensor.status= '1') as aName,
            ( select generator.sensor_name from busi_generator_sensor generator where generator.sensor_code=warn.sensor_id and generator.status= '1') as genName
        from
            busi_eqm_warning warn
        <where>
            warn.del_flag = '1' AND warn.deal_status = '0'
            <if test="eqType != null and eqType != ''">
                AND warn.eq_type = #{eqType}
            </if>
            <if test="gzType != null and gzType != ''">
                AND warn.gz_type = #{gzType}
            </if>
        </where>
        GROUP BY warn.sensor_id
        ORDER BY
        warn.warning_time DESC
        ) t
    </select>


<!--    <select id="getCurrentWarningSum" resultType="java.lang.Integer">-->
<!--        SELECT COUNT(*) FROM `busi_eqm_warning` b-->
<!--        <where>-->
<!--            b.del_flag = '1'-->
<!--            AND b.deal_status = '0'-->
<!--            AND (b.sensor_id = #{sensorCode} OR b.sensor_id is NULL)-->
<!--        </where>-->
<!--    </select>-->

    <!--20220410修改为：-->
    <select id="getCurrentWarningSum" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM `busi_eqm_warning` b
        <where>
            b.del_flag = '1'
            AND b.deal_status = '0'
            <choose>
                <when test="sensorCode != null and sensorCode != ''">
                    AND (b.sensor_id = #{sensorCode} OR b.sensor_id is NULL)
                </when>
                <otherwise>
                    AND b.sensor_id IS NULL OR b.sensor_id = ''
                </otherwise>
            </choose>
            <if test="eqType != null and eqType != ''">
                and b.eq_type = #{eqType}
            </if>
            <if test="gzType != null and gzType != ''">
                and b.gz_type = #{gzType}
            </if>
        </where>
    </select>

    <select id="findBusiEqmWarningList" resultType="com.huatek.busi.vo.BusiEqmWarningVo">
        SELECT
        <include refid="Base_Ref_Column_List"/>
        FROM
        <include refid="Base_Table_Ref"/>
        <where>
            <if test="sensorId != null and sensorId != ''">
                and t.sensor_id = #{sensorId}
            </if>
            <if test="warningTime != null">
                and t.warning_time &gt;= #{warningTime}
            </if>
            <if test="warningTimeEnd != null">
                and t.warning_time &lt; #{warningTimeEnd}
            </if>
        </where>
    </select>

    <select id="findBusiEqmWarningById" resultType="com.huatek.busi.vo.BusiEqmWarningVo">
        SELECT
        <include refid="Base_Ref_Column_List"/>
        FROM
        <include refid="Base_Table_Ref"/>
        WHERE t.id=#{id}
    </select>

    <update id="wholeupdateBusiEqmWarning" parameterType="com.huatek.busi.dto.BusiEqmWarningDto">
        UPDATE busi_eqm_warning
        SET
        deal_msg = #{dealMsg},
        deal_status = #{dealStatus},
        warning_type = #{warningType},
        processing_user = #{processingUser},
        processing_time = #{processingTime}
        <where>
            deal_status = '0' AND del_flag = '1'
            <if test="sensorId != null and sensorId != ''">
                AND sensor_id = #{sensorId}
            </if>
            <if test="warningTime != null and warningTime != ''">
                AND create_time <![CDATA[ >= ]]> #{warningTime}
            </if>
            <if test="warningTimeEnd != null and warningTimeEnd != ''">
                AND create_time <![CDATA[ < ]]> #{warningTimeEnd}
            </if>
            <if test="eqType != null and eqType != '' ">
                AND eq_type = #{eqType}
            </if>
            <if test="gzType != null and gzType != ''">
                <choose>
                    <when test="gzType == '3'">
                        AND gz_type in ('3','8')
                    </when>
                    <otherwise>
                        AND gz_type = #{gzType}
                    </otherwise>
                </choose>
            </if>
        </where>
    </update>

    <update id="singleupdateBusiEqmWarning" parameterType="com.huatek.busi.dto.BusiEqmWarningDto">
        UPDATE busi_eqm_warning
        SET
        deal_msg = #{dealMsg},
        deal_status = #{dealStatus},
        warning_type = #{warningType},
        processing_user = #{processingUser},
        processing_time = #{processingTime}
        <where>
            deal_status = '0' AND del_flag = '1'
            <if test="sensorId != null ">
                AND sensor_id = #{sensorId}
            </if>
            <if test="warningTime != null ">
                AND warning_time = #{warningTime}
            </if>
            <if test="eqType != null  ">
                AND eq_type = #{eqType}
            </if>
            <if test="gzType != null ">
                AND gz_type = #{gzType}
            </if>
        </where>
    </update>

    <select id="getWarningCount" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM busi_eqm_warning
        <where>
            sensor_id = #{sensorCode}
            <if test="warningType != null and warningType != ''">
                AND warning_type = #{warningType}
            </if>
            <if test="startTime !=null">
                and DATE_FORMAT(warning_time,'%Y-%m-%d') <![CDATA[>= ]]> DATE_FORMAT(#{startTime},'%Y-%m-%d')
            </if>
            <if test="endTime != null">
                and DATE_FORMAT(warning_time,'%Y-%m-%d') <![CDATA[<= ]]> DATE_FORMAT(#{endTime},'%Y-%m-%d')
            </if>
        </where>
    </select>
</mapper>
