<?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.TmnLandMapper">
    
    <resultMap type="TmnLand" id="TmnLandResult">
        <result property="tmnlandId"    column="tmnlandId"    />
        <result property="tmnId"    column="tmnId"    />
        <result property="landId"    column="landId"    />
        <result property="tmnlandAssigndate"    column="tmnlandAssigndate"    />
    </resultMap>

    <sql id="selectTmnLandVo">
        select tmnlandId, tmnId, landId, tmnlandAssigndate from TmnLand
    </sql>

    <select id="selectTmnLandList" parameterType="TmnLand" resultType="TmnLand">
        select *
        from TmnLand as tl
            LEFT JOIN TmnBase as tb ON tl.tmnId = tb.tmnId
        <where>  
            <if test="tmnId != null  and tmnId != ''"> and tmnId = #{tmnId}</if>
            <if test="landId != null  and landId != ''"> and landId = #{landId}</if>
            <if test="tmnlandAssigndate != null  and tmnlandAssigndate != ''"> and tmnlandAssigndate = #{tmnlandAssigndate}</if>
        </where>
    </select>
    
    <select id="selectTmnLandByTmnlandId" parameterType="String" resultType="TmnLand">
        <include refid="selectTmnLandVo"/>
        where tmnlandId = #{tmnlandId}
    </select>

    <select id="selectTmnLandByTmnId" parameterType="String" resultType="TmnLand">
        select tmnlandId, tmnId, landId, tmnlandAssigndate from TmnLand
        WHERE tmnId IN
        <foreach item="tmnId" collection="array" open="(" separator="," close=")">
            #{tmnId}
        </foreach>
    </select>
        
    <insert id="insertTmnLand" parameterType="TmnLand">
        insert into TmnLand
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tmnlandId != null">tmnlandId,</if>
            <if test="tmnId != null">tmnId,</if>
            <if test="landId != null">landId,</if>
            <if test="tmnlandAssigndate != null">tmnlandAssigndate,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tmnlandId != null">#{tmnlandId},</if>
            <if test="tmnId != null">#{tmnId},</if>
            <if test="landId != null">#{landId},</if>
            <if test="tmnlandAssigndate != null">#{tmnlandAssigndate},</if>
         </trim>
    </insert>

    <insert id="insertTmnLandBatch" parameterType="TmnLand">
        <foreach collection="list" item="item" separator=";">
            insert into TmnLand
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="item.tmnlandId != null">tmnlandId,</if>
                <if test="item.tmnId != null">tmnId,</if>
                <if test="item.landId != null">landId,</if>
                <if test="item.tmnlandAssigndate != null">tmnlandAssigndate,</if>
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="item.tmnlandId != null">#{item.tmnlandId},</if>
                <if test="item.tmnId != null">#{item.tmnId},</if>
                <if test="item.landId != null">#{item.landId},</if>
                <if test="item.tmnlandAssigndate != null">#{item.tmnlandAssigndate},</if>
            </trim>
        </foreach>
    </insert>

    <update id="updateTmnLand" parameterType="TmnLand">
        update TmnLand
        <trim prefix="SET" suffixOverrides=",">
            <if test="tmnId != null">tmnId = #{tmnId},</if>
            <if test="landId != null">landId = #{landId},</if>
            <if test="tmnlandAssigndate != null">tmnlandAssigndate = #{tmnlandAssigndate},</if>
        </trim>
        where tmnlandId = #{tmnlandId}
    </update>

    <delete id="deleteTmnLandByTmnlandId" parameterType="String">
        delete from TmnLand where tmnlandId = #{tmnlandId}
    </delete>

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