<?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.agri.system.mapper.SysAgriAlarmRelationMapper">
    
    <resultMap type="SysAgriAlarmRelation" id="SysAgriAlarmRelationResult">
        <result property="id"    column="id"    />
        <result property="agriId"    column="agri_id"    />
        <result property="imei"    column="imei"    />
        <result property="typeCode"    column="type_code"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="isDeleted"    column="is_deleted"    />
        <result property="agriName"    column="agri_name"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSysAgriAlarmRelationVo">
        select id, agri_id, imei, type_code, create_by, create_time, is_deleted, agri_name, update_by, update_time from sys_agri_alarm_relation
    </sql>

    <select id="selectSysAgriAlarmRelationList" parameterType="SysAgriAlarmRelation" resultMap="SysAgriAlarmRelationResult">
        <include refid="selectSysAgriAlarmRelationVo"/>
        <where>  
            <if test="agriId != null "> and agri_id = #{agriId}</if>
            <if test="imei != null  and imei != ''"> and imei like concat('%', #{imei}, '%')</if>
            <if test="typeCode != null  and typeCode != ''"> and type_code = #{typeCode}</if>
            <if test="isDeleted != null "> and is_deleted = #{isDeleted}</if>
            <if test="agriName != null  and agriName != ''"> and agri_name like concat('%', #{agriName}, '%')</if>
        </where>
    </select>
    
    <select id="selectSysAgriAlarmRelationById" parameterType="Long" resultMap="SysAgriAlarmRelationResult">
        <include refid="selectSysAgriAlarmRelationVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysAgriAlarmRelation" parameterType="SysAgriAlarmRelation" useGeneratedKeys="true" keyProperty="id">
        insert into sys_agri_alarm_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="agriId != null">agri_id,</if>
            <if test="imei != null and imei != ''">imei,</if>
            <if test="typeCode != null and typeCode != ''">type_code,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isDeleted != null">is_deleted,</if>
            <if test="agriName != null and agriName != ''">agri_name,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="agriId != null">#{agriId},</if>
            <if test="imei != null and imei != ''">#{imei},</if>
            <if test="typeCode != null and typeCode != ''">#{typeCode},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isDeleted != null">#{isDeleted},</if>
            <if test="agriName != null and agriName != ''">#{agriName},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateSysAgriAlarmRelation" parameterType="SysAgriAlarmRelation">
        update sys_agri_alarm_relation
        <trim prefix="SET" suffixOverrides=",">
            <if test="agriId != null">agri_id = #{agriId},</if>
            <if test="imei != null and imei != ''">imei = #{imei},</if>
            <if test="typeCode != null and typeCode != ''">type_code = #{typeCode},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isDeleted != null">is_deleted = #{isDeleted},</if>
            <if test="agriName != null and agriName != ''">agri_name = #{agriName},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysAgriAlarmRelationById" parameterType="Long">
        delete from sys_agri_alarm_relation where id = #{id}
    </delete>

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