<?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.yunfeiyun.agmp.fms.mapper.FmsCropcalarmMapper">
    
    <resultMap type="FmsCropcalarm" id="FmsCropcalarmResult">
        <result property="cropcalarmId"    column="cropcalarmId"    />
        <result property="calarmId"    column="calarmId"    />
        <result property="cropName"    column="cropName"    />
    </resultMap>

    <sql id="selectFmsCropcalarmVo">
        select cropcalarmId, calarmId, cropName from FmsCropcalarm
    </sql>

    <select id="selectFmsCropcalarmList" parameterType="FmsCalarmListReqVo" resultType="FmsCalarmListResVo">
        select c.calarmId, c.calarmType, calarmName, c.calarmCloudresurl, c.calamRemark
        from FmsCropcalarm cc
        left join FmsCalarm c on cc.calarmId = c.calarmId
        <where>  
            <if test="cropName != null  and cropName != ''"> and cc.cropName = #{cropName}</if>
            <if test="calarmType != null  and calarmType != ''"> and c.calarmType = #{calarmType}</if>
        </where>
        group by cc.calarmId
    </select>

    <select id="selectNameListForCalarm" parameterType="FmsCalarmListReqVo" resultType="FmsCalarmListResVo">
        select cropName
        from FmsCropcalarm
        group by cropName
    </select>
    
    <select id="selectFmsCropcalarmByCropcalarmId" parameterType="String" resultMap="FmsCropcalarmResult">
        <include refid="selectFmsCropcalarmVo"/>
        where cropcalarmId = #{cropcalarmId}
    </select>
        
    <insert id="insertFmsCropcalarm" parameterType="FmsCropcalarm">
        insert into FmsCropcalarm
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cropcalarmId != null">cropcalarmId,</if>
            <if test="calarmId != null">calarmId,</if>
            <if test="cropName != null">cropName,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cropcalarmId != null">#{cropcalarmId},</if>
            <if test="calarmId != null">#{calarmId},</if>
            <if test="cropName != null">#{cropName},</if>
         </trim>
    </insert>

    <update id="updateFmsCropcalarm" parameterType="FmsCropcalarm">
        update FmsCropcalarm
        <trim prefix="SET" suffixOverrides=",">
            <if test="calarmId != null">calarmId = #{calarmId},</if>
            <if test="cropName != null">cropName = #{cropName},</if>
        </trim>
        where cropcalarmId = #{cropcalarmId}
    </update>

    <delete id="deleteFmsCropcalarmByCropcalarmId" parameterType="String">
        delete from FmsCropcalarm where cropcalarmId = #{cropcalarmId}
    </delete>

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