<?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.springblade.modules.business.warning.mapper.RtuWarningMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="rtuWarningInfoEntityResultMap"
               type="org.springblade.modules.business.warning.entity.RtuWarningInfoEntity">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="rtu_code" property="rtuCode"/>
        <result column="warning_kind" property="warningKind"/>
        <result column="warning_desc" property="warningDesc"/>
        <result column="warning_happen_time" property="warningHappenTime"/>
        <result column="warning_recovery_time" property="warningRecoveryTime"/>
        <result column="warning_status" property="warningStatus"/>
        <result column="data_from_id" property="dataFromId"/>
    </resultMap>

    <!-- 通用查询映射结果 -->
    <resultMap id="rtuWarningInfoVOResultMap" type="org.springblade.modules.business.warning.vo.RtuWarningInfoVO">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="rtu_code" property="rtuCode"/>
        <result column="warning_kind" property="warningKind"/>
        <result column="warning_desc" property="warningDesc"/>
        <result column="warning_happen_time" property="warningHappenTime"/>
        <result column="warning_recovery_time" property="warningRecoveryTime"/>
        <result column="warning_status" property="warningStatus"/>
        <result column="data_from_id" property="dataFromId"/>
        <result column="rtu_name" property="rtuName"/>
    </resultMap>


    <select id="selectPage" resultMap="rtuWarningInfoVOResultMap">
        SELECT
        w.*, rtu.rtu_name
        FROM
        rtu_warning w
        LEFT JOIN rtu_info rtu ON rtu.rtu_code = w.rtu_code
        WHERE
        w.is_deleted = 0
        <if test="rtuWarningInfoDTO.rtuCode!=null">
            and rtu.rtu_code = #{rtuWarningInfoDTO.rtuCode}
        </if>
        order by w.warning_happen_time desc
    </select>

    <select id="warningRtuCount" resultType="java.lang.Long">
        SELECT
        count(*)
        FROM
        rtu_warning w
        LEFT JOIN rtu_info rtu ON rtu.rtu_code = w.rtu_code
        WHERE
        w.is_deleted = 0
        <if test="rtuWarningInfoDTO.orgId!=null">
            and rtu.org_id = #{rtuWarningInfoDTO.orgId}
        </if>
        and w.warning_status = 1

    </select>
</mapper>
