<?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.back.mapper.BackApplyDetailsMapper">
    <resultMap type="com.bonus.material.back.domain.BackApplyDetails" id="BackApplyDetailsResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="parentId"    column="parent_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="preNum"    column="pre_num"    />
        <result property="auditNum"    column="audit_num"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectBackApplyDetailsVo">
        select id, code, parent_id, type_id, pre_num, audit_num, status, create_by, create_time, update_by, update_time, remark, company_id from back_apply_details
    </sql>

    <select id="selectBackApplyDetailsList" parameterType="com.bonus.material.back.domain.BackApplyDetails" resultMap="BackApplyDetailsResult">
        <include refid="selectBackApplyDetailsVo"/>
        <where>  
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="preNum != null "> and pre_num = #{preNum}</if>
            <if test="auditNum != null "> and audit_num = #{auditNum}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectBackApplyDetailsById" parameterType="Long" resultMap="BackApplyDetailsResult">
        <include refid="selectBackApplyDetailsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBackApplyDetails" parameterType="com.bonus.material.back.domain.BackApplyDetails" useGeneratedKeys="true" keyProperty="id">
        insert into back_apply_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="code != null">code,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="preNum != null">pre_num,</if>
            <if test="auditNum != null">audit_num,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="code != null">#{code},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="preNum != null">#{preNum},</if>
            <if test="auditNum != null">#{auditNum},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <update id="updateBackApplyDetails" parameterType="com.bonus.material.back.domain.BackApplyDetails">
        update back_apply_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null">code = #{code},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="preNum != null">pre_num = #{preNum},</if>
            <if test="auditNum != null">audit_num = #{auditNum},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBackApplyDetailsById" parameterType="Long">
        delete from back_apply_details where id = #{id}
    </delete>

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