<?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.purchase.mapper.PurchasePartDetailsMapper">
    <resultMap type="com.bonus.material.purchase.domain.PurchasePartDetails" id="PurchasePartDetailsResult">
        <result property="id"    column="id"    />
        <result property="taskId"    column="task_id"    />
        <result property="partId"    column="part_id"    />
        <result property="purchasePrice"    column="purchase_price"    />
        <result property="purchaseNum"    column="purchase_num"    />
        <result property="supplierId"    column="supplier_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="productionTime"    column="production_time"    />
        <result property="checkNum"    column="check_num"    />
        <result property="checkResult"    column="check_result"    />
        <result property="inputNum"    column="input_num"    />
        <result property="inputTime"    column="input_time"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileUrl"    column="file_url"    />
        <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"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectPurchasePartDetailsVo">
        select id, task_id, part_id, purchase_price, purchase_num, supplier_id, create_by, production_time, check_num, check_result, input_num, input_time, file_name, file_url, create_time, update_by, update_time, remark, company_id, status from purchase_part_details
    </sql>

    <select id="selectPurchasePartDetailsList" parameterType="com.bonus.material.purchase.domain.PurchasePartDetails" resultMap="PurchasePartDetailsResult">
        <include refid="selectPurchasePartDetailsVo"/>
        <where>  
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="partId != null "> and part_id = #{partId}</if>
            <if test="purchasePrice != null "> and purchase_price = #{purchasePrice}</if>
            <if test="purchaseNum != null "> and purchase_num = #{purchaseNum}</if>
            <if test="supplierId != null "> and supplier_id = #{supplierId}</if>
            <if test="productionTime != null "> and production_time = #{productionTime}</if>
            <if test="checkNum != null "> and check_num = #{checkNum}</if>
            <if test="checkResult != null  and checkResult != ''"> and check_result = #{checkResult}</if>
            <if test="inputNum != null "> and input_num = #{inputNum}</if>
            <if test="inputTime != null "> and input_time = #{inputTime}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectPurchasePartDetailsById" parameterType="Long" resultMap="PurchasePartDetailsResult">
        <include refid="selectPurchasePartDetailsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPurchasePartDetails" parameterType="com.bonus.material.purchase.domain.PurchasePartDetails" useGeneratedKeys="true" keyProperty="id">
        insert into purchase_part_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="partId != null">part_id,</if>
            <if test="purchasePrice != null">purchase_price,</if>
            <if test="purchaseNum != null">purchase_num,</if>
            <if test="supplierId != null">supplier_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="productionTime != null">production_time,</if>
            <if test="checkNum != null">check_num,</if>
            <if test="checkResult != null">check_result,</if>
            <if test="inputNum != null">input_num,</if>
            <if test="inputTime != null">input_time,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileUrl != null">file_url,</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>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="partId != null">#{partId},</if>
            <if test="purchasePrice != null">#{purchasePrice},</if>
            <if test="purchaseNum != null">#{purchaseNum},</if>
            <if test="supplierId != null">#{supplierId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="productionTime != null">#{productionTime},</if>
            <if test="checkNum != null">#{checkNum},</if>
            <if test="checkResult != null">#{checkResult},</if>
            <if test="inputNum != null">#{inputNum},</if>
            <if test="inputTime != null">#{inputTime},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileUrl != null">#{fileUrl},</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>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updatePurchasePartDetails" parameterType="com.bonus.material.purchase.domain.PurchasePartDetails">
        update purchase_part_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="partId != null">part_id = #{partId},</if>
            <if test="purchasePrice != null">purchase_price = #{purchasePrice},</if>
            <if test="purchaseNum != null">purchase_num = #{purchaseNum},</if>
            <if test="supplierId != null">supplier_id = #{supplierId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="productionTime != null">production_time = #{productionTime},</if>
            <if test="checkNum != null">check_num = #{checkNum},</if>
            <if test="checkResult != null">check_result = #{checkResult},</if>
            <if test="inputNum != null">input_num = #{inputNum},</if>
            <if test="inputTime != null">input_time = #{inputTime},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</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>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePurchasePartDetailsById" parameterType="Long">
        delete from purchase_part_details where id = #{id}
    </delete>

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