<?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.ximai.mes.dv.mapper.devBrandQuotation.DvBrandQuotationProcessItemMapper">

    <resultMap type="DvBrandQuotationProcessItem" id="DevBrandQuotationProcessItemResult">
        <result property="brandQuotationProcessItemId"    column="brand_quotation_process_item_id"    />
        <result property="brandQuotationProcessId"    column="brand_quotation_process_id"    />
        <result property="itemId"    column="item_id"    />
        <result property="unitOfMeasure"    column="unit_of_measure"    />
        <result property="quantity"    column="quantity"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectDevBrandQuotationProcessItemVo">
        select
            a.brand_quotation_process_item_id,
            a.brand_quotation_process_id,
            a.item_id,
           c.item_name,
           a.unit_of_measure,
            a.remark,
            a.quantity
        from dev_brand_quotation_process_item a
                 left join md_item c on a.item_id= c.item_id
    </sql>

    <select id="selectDevBrandQuotationProcessItemList" parameterType="DvBrandQuotationProcessItem" resultMap="DevBrandQuotationProcessItemResult">
        <include refid="selectDevBrandQuotationProcessItemVo"/>
        <where>
            <if test="brandQuotationProcessId != null "> and a.brand_quotation_process_id = #{brandQuotationProcessId}</if>
            <if test="itemId != null "> and a.item_id = #{itemId}</if>
            <if test="unitOfMeasure != null  and unitOfMeasure != ''"> and a.unit_of_measure = #{unitOfMeasure}</if>

            <if test="quantity != null "> and a.quantity = #{quantity}</if>
        </where>
    </select>


    <select id="selectProWorkOrderProcessItemByWorkorderProcessId"
            parameterType="Long" resultMap="DevBrandQuotationProcessItemResult">
        <include refid="selectDevBrandQuotationProcessItemVo"/>
        where a.brand_quotation_process_id = #{brandQuotationProcessId}
    </select>

    <select id="selectDevBrandQuotationProcessItemByBrandQuotationProcessItemId" parameterType="Long" resultMap="DevBrandQuotationProcessItemResult">
        <include refid="selectDevBrandQuotationProcessItemVo"/>
        where a.brand_quotation_process_item_id = #{brandQuotationProcessItemId}
    </select>

    <insert id="insertDevBrandQuotationProcessItem" parameterType="DvBrandQuotationProcessItem">
        insert into dev_brand_quotation_process_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="brandQuotationProcessItemId != null">brand_quotation_process_item_id,</if>
            <if test="brandQuotationProcessId != null">brand_quotation_process_id,</if>
            <if test="itemId != null">item_id,</if>
            <if test="unitOfMeasure != null">unit_of_measure,</if>
            <if test="quantity != null">quantity,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="brandQuotationProcessItemId != null">#{brandQuotationProcessItemId},</if>
            <if test="brandQuotationProcessId != null">#{brandQuotationProcessId},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="unitOfMeasure != null">#{unitOfMeasure},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateDevBrandQuotationProcessItem" parameterType="DvBrandQuotationProcessItem">
        update dev_brand_quotation_process_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="brandQuotationProcessId != null">brand_quotation_process_id = #{brandQuotationProcessId},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="unitOfMeasure != null">unit_of_measure = #{unitOfMeasure},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where brand_quotation_process_item_id = #{brandQuotationProcessItemId}
    </update>

    <delete id="deleteDevBrandQuotationProcessItemByBrandQuotationProcessItemId" parameterType="Long">
        delete from dev_brand_quotation_process_item where brand_quotation_process_item_id = #{brandQuotationProcessItemId}
    </delete>

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