<?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.ma.mapper.MachineAppendMapper">
    <resultMap type="com.bonus.material.ma.domain.MachineAppend" id="MachineAppendResult">
        <result property="maId"    column="ma_id"    />
        <result property="pickId"    column="pick_id"    />
        <result property="backId"    column="back_id"    />
        <result property="agreementId"    column="agreement_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMachineAppendVo">
        select ma_id, pick_id, back_id, agreement_id, company_id, create_time, update_time from ma_machine_append
    </sql>

    <select id="selectMachineAppendList" parameterType="com.bonus.material.ma.domain.MachineAppend" resultMap="MachineAppendResult">
        <include refid="selectMachineAppendVo"/>
        <where>  
            <if test="pickId != null "> and pick_id = #{pickId}</if>
            <if test="backId != null "> and back_id = #{backId}</if>
            <if test="agreementId != null  and agreementId != ''"> and agreement_id = #{agreementId}</if>
            <if test="companyId != null  and companyId != ''"> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectMachineAppendByMaId" parameterType="Long" resultMap="MachineAppendResult">
        <include refid="selectMachineAppendVo"/>
        where ma_id = #{maId}
    </select>
        
    <insert id="insertMachineAppend" parameterType="com.bonus.material.ma.domain.MachineAppend" useGeneratedKeys="true" keyProperty="maId">
        insert into ma_machine_append
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pickId != null">pick_id,</if>
            <if test="backId != null">back_id,</if>
            <if test="agreementId != null">agreement_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pickId != null">#{pickId},</if>
            <if test="backId != null">#{backId},</if>
            <if test="agreementId != null">#{agreementId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateMachineAppend" parameterType="com.bonus.material.ma.domain.MachineAppend">
        update ma_machine_append
        <trim prefix="SET" suffixOverrides=",">
            <if test="pickId != null">pick_id = #{pickId},</if>
            <if test="backId != null">back_id = #{backId},</if>
            <if test="agreementId != null">agreement_id = #{agreementId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where ma_id = #{maId}
    </update>

    <delete id="deleteMachineAppendByMaId" parameterType="Long">
        delete from ma_machine_append where ma_id = #{maId}
    </delete>

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