<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzyl.nursing.mapper.AlertDataMapper">
    
    <resultMap type="AlertData" id="AlertDataResult">
        <result property="id"    column="id"    />
        <result property="iotId"    column="iot_id"    />
        <result property="deviceName"    column="device_name"    />
        <result property="productKey"    column="product_key"    />
        <result property="productName"    column="product_name"    />
        <result property="functionId"    column="function_id"    />
        <result property="accessLocation"    column="access_location"    />
        <result property="locationType"    column="location_type"    />
        <result property="physicalLocationType"    column="physical_location_type"    />
        <result property="deviceDescription"    column="device_description"    />
        <result property="dataValue"    column="data_value"    />
        <result property="alertRuleId"    column="alert_rule_id"    />
        <result property="alertReason"    column="alert_reason"    />
        <result property="processingResult"    column="processing_result"    />
        <result property="processorId"    column="processor_id"    />
        <result property="processorName"    column="processor_name"    />
        <result property="processingTime"    column="processing_time"    />
        <result property="type"    column="type"    />
        <result property="status"    column="status"    />
        <result property="userId"    column="user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectAlertDataVo">
        select id, iot_id, device_name, product_key, product_name, function_id, access_location, location_type, physical_location_type, device_description, data_value, alert_rule_id, alert_reason, processing_result, processor_id, processor_name, processing_time, type, status, user_id, create_time, update_time, create_by, update_by, remark from alert_data
    </sql>

    <select id="selectAlertDataList" parameterType="AlertData" resultMap="AlertDataResult">
        <include refid="selectAlertDataVo"/>
        <where>  
            <if test="iotId != null  and iotId != ''"> and iot_id = #{iotId}</if>
            <if test="deviceName != null  and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
            <if test="productKey != null  and productKey != ''"> and product_key = #{productKey}</if>
            <if test="productName != null  and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
            <if test="functionId != null  and functionId != ''"> and function_id = #{functionId}</if>
            <if test="accessLocation != null  and accessLocation != ''"> and access_location = #{accessLocation}</if>
            <if test="locationType != null "> and location_type = #{locationType}</if>
            <if test="physicalLocationType != null "> and physical_location_type = #{physicalLocationType}</if>
            <if test="deviceDescription != null  and deviceDescription != ''"> and device_description = #{deviceDescription}</if>
            <if test="dataValue != null  and dataValue != ''"> and data_value = #{dataValue}</if>
            <if test="alertRuleId != null "> and alert_rule_id = #{alertRuleId}</if>
            <if test="alertReason != null  and alertReason != ''"> and alert_reason = #{alertReason}</if>
            <if test="processingResult != null  and processingResult != ''"> and processing_result = #{processingResult}</if>
            <if test="processorId != null "> and processor_id = #{processorId}</if>
            <if test="processorName != null  and processorName != ''"> and processor_name like concat('%', #{processorName}, '%')</if>
            <if test="processingTime != null "> and processing_time = #{processingTime}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>
    
    <select id="selectAlertDataById" parameterType="Long" resultMap="AlertDataResult">
        <include refid="selectAlertDataVo"/>
        where id = #{id}
    </select>

    <insert id="insertAlertData" parameterType="AlertData" useGeneratedKeys="true" keyProperty="id">
        insert into alert_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="iotId != null and iotId != ''">iot_id,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="productKey != null and productKey != ''">product_key,</if>
            <if test="productName != null">product_name,</if>
            <if test="functionId != null and functionId != ''">function_id,</if>
            <if test="accessLocation != null">access_location,</if>
            <if test="locationType != null">location_type,</if>
            <if test="physicalLocationType != null">physical_location_type,</if>
            <if test="deviceDescription != null">device_description,</if>
            <if test="dataValue != null and dataValue != ''">data_value,</if>
            <if test="alertRuleId != null">alert_rule_id,</if>
            <if test="alertReason != null and alertReason != ''">alert_reason,</if>
            <if test="processingResult != null">processing_result,</if>
            <if test="processorId != null">processor_id,</if>
            <if test="processorName != null">processor_name,</if>
            <if test="processingTime != null">processing_time,</if>
            <if test="type != null">type,</if>
            <if test="status != null">status,</if>
            <if test="userId != null">user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="iotId != null and iotId != ''">#{iotId},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="productKey != null and productKey != ''">#{productKey},</if>
            <if test="productName != null">#{productName},</if>
            <if test="functionId != null and functionId != ''">#{functionId},</if>
            <if test="accessLocation != null">#{accessLocation},</if>
            <if test="locationType != null">#{locationType},</if>
            <if test="physicalLocationType != null">#{physicalLocationType},</if>
            <if test="deviceDescription != null">#{deviceDescription},</if>
            <if test="dataValue != null and dataValue != ''">#{dataValue},</if>
            <if test="alertRuleId != null">#{alertRuleId},</if>
            <if test="alertReason != null and alertReason != ''">#{alertReason},</if>
            <if test="processingResult != null">#{processingResult},</if>
            <if test="processorId != null">#{processorId},</if>
            <if test="processorName != null">#{processorName},</if>
            <if test="processingTime != null">#{processingTime},</if>
            <if test="type != null">#{type},</if>
            <if test="status != null">#{status},</if>
            <if test="userId != null">#{userId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateAlertData" parameterType="AlertData">
        update alert_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="iotId != null and iotId != ''">iot_id = #{iotId},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="productKey != null and productKey != ''">product_key = #{productKey},</if>
            <if test="productName != null">product_name = #{productName},</if>
            <if test="functionId != null and functionId != ''">function_id = #{functionId},</if>
            <if test="accessLocation != null">access_location = #{accessLocation},</if>
            <if test="locationType != null">location_type = #{locationType},</if>
            <if test="physicalLocationType != null">physical_location_type = #{physicalLocationType},</if>
            <if test="deviceDescription != null">device_description = #{deviceDescription},</if>
            <if test="dataValue != null and dataValue != ''">data_value = #{dataValue},</if>
            <if test="alertRuleId != null">alert_rule_id = #{alertRuleId},</if>
            <if test="alertReason != null and alertReason != ''">alert_reason = #{alertReason},</if>
            <if test="processingResult != null">processing_result = #{processingResult},</if>
            <if test="processorId != null">processor_id = #{processorId},</if>
            <if test="processorName != null">processor_name = #{processorName},</if>
            <if test="processingTime != null">processing_time = #{processingTime},</if>
            <if test="type != null">type = #{type},</if>
            <if test="status != null">status = #{status},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAlertDataById" parameterType="Long">
        delete from alert_data where id = #{id}
    </delete>

    <delete id="deleteAlertDataByIds" parameterType="String">
        delete from alert_data where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="pageQueryAlertData" resultType="com.zzyl.nursing.domain.AlertData">
        <include refid="selectAlertDataVo"/>
        <where>
            <if test="deviceName != null and deviceName != ''">AND device_name = #{deviceName}</if>
            <if test="startTime != null and endTime != null">AND create_time between #{startTime} and #{endTime}</if>
            <if test="status != null">AND status = #{status}</if>
        </where>
    </select>
</mapper>