<?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.bonus.material.lease.mapper.LeaseSceneRegistMapper">
    <resultMap type="com.bonus.material.lease.domain.LeaseSceneRegist" id="LeaseSceneRegistResult">
        <result property="id"    column="id"    />
        <result property="agreementId"    column="agreement_id"    />
        <result property="teamId"    column="team_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="maId"    column="ma_id"    />
        <result property="num"    column="num"    />
        <result property="createTime"    column="create_time"    />
        <result property="type"    column="type"    />
        <result property="registrant"    column="registrant"    />
        <result property="telephone"    column="telephone"    />
        <result property="companyId"    column="company_id"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectLeaseSceneRegistVo">
        select id, agreement_id, team_id, type_id, ma_id, num, create_time, type, registrant, telephone, company_id, update_time from lease_scene_regist
    </sql>

    <select id="selectLeaseSceneRegistList" parameterType="com.bonus.material.lease.domain.LeaseSceneRegist" resultMap="LeaseSceneRegistResult">
        <include refid="selectLeaseSceneRegistVo"/>
        <where>  
            <if test="agreementId != null "> and agreement_id = #{agreementId}</if>
            <if test="teamId != null "> and team_id = #{teamId}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="num != null "> and num = #{num}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="registrant != null  and registrant != ''"> and registrant = #{registrant}</if>
            <if test="telephone != null  and telephone != ''"> and telephone = #{telephone}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectLeaseSceneRegistById" parameterType="Long" resultMap="LeaseSceneRegistResult">
        <include refid="selectLeaseSceneRegistVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertLeaseSceneRegist" parameterType="com.bonus.material.lease.domain.LeaseSceneRegist" useGeneratedKeys="true" keyProperty="id">
        insert into lease_scene_regist
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="agreementId != null">agreement_id,</if>
            <if test="teamId != null">team_id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="maId != null">ma_id,</if>
            <if test="num != null">num,</if>
            <if test="createTime != null">create_time,</if>
            <if test="type != null">type,</if>
            <if test="registrant != null">registrant,</if>
            <if test="telephone != null">telephone,</if>
            <if test="companyId != null">company_id,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="agreementId != null">#{agreementId},</if>
            <if test="teamId != null">#{teamId},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="maId != null">#{maId},</if>
            <if test="num != null">#{num},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="type != null">#{type},</if>
            <if test="registrant != null">#{registrant},</if>
            <if test="telephone != null">#{telephone},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateLeaseSceneRegist" parameterType="com.bonus.material.lease.domain.LeaseSceneRegist">
        update lease_scene_regist
        <trim prefix="SET" suffixOverrides=",">
            <if test="agreementId != null">agreement_id = #{agreementId},</if>
            <if test="teamId != null">team_id = #{teamId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="num != null">num = #{num},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="type != null">type = #{type},</if>
            <if test="registrant != null">registrant = #{registrant},</if>
            <if test="telephone != null">telephone = #{telephone},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLeaseSceneRegistById" parameterType="Long">
        delete from lease_scene_regist where id = #{id}
    </delete>

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