<?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.pro.mapper.proWorkOrder.ProWorkOrderSoDirectiveMapper">

    <resultMap type="ProWorkOrderSoDirective" id="ProWorkOrderSoDirectiveResult">
        <result property="workorderSoDirectiveId" column="workorder_so_directive_id"/>
        <result property="workorderId" column="workorder_id"/>
        <result property="workorderCode" column="workorder_code"/>
        <result property="clientCmd" column="client_cmd"/>
        <result property="dispatchMultiple" column="dispatch_multiple"/>
        <result property="lossNum" column="loss_num"/>
        <result property="salesVoucher" column="sales_voucher"/>
        <result property="salesVoucherItem" column="sales_voucher_item"/>
        <result property="clientCode" column="client_code"/>
        <result property="clientName" column="client_name"/>
        <result property="sizeGroup" column="size_group"/>
        <result property="clientSizeUnit" column="client_size_unit"/>
        <result property="typeNo" column="type_no"/>
        <result property="colorNo" column="color_no"/>
        <result property="color" column="color"/>
        <result property="salePath" column="sale_path"/>
        <result property="segment" column="segment"/>
        <result property="quarter" column="quarter"/>
        <result property="wholeSize" column="whole_size"/>
        <result property="specSize" column="spec_size"/>
        <result property="poNo" column="po_no"/>
        <result property="wipNo" column="wip_no"/>
        <result property="packingNum" column="packing_num"/>
        <result property="region" column="region"/>
        <result property="cycle" column="cycle"/>
        <result property="skNo" column="sk_no"/>
        <result property="patentNo" column="patent_no"/>
        <result property="materialDesc" column="material_desc"/>
        <result property="signer" column="signer"/>
        <result property="shipToId" column="ship_to_id"/>
        <result property="prodSpec" column="prod_spec"/>
        <result property="prodUsage" column="prod_usage"/>
        <result property="thickness" column="thickness"/>
        <result property="packMode" column="pack_mode"/>
        <result property="printingDirection" column="printing_direction"/>
        <result property="plantCode" column="plant_code"/>
        <result property="purchaseOrg" column="purchase_org"/>
        <result property="quantityProduced" column="quantity_produced"/>
        <result property="quantity" column="quantity"/>
        <result property="quantityQualify" column="quantity_qualify"/>
        <result property="quantityUnqualify" column="quantity_unqualify"/>
        <result property="packNum" column="pack_num"/>
        <result property="packType" column="pack_type"/>
        <result property="packUnit" column="pack_unit"/>
        <result property="lossPack" column="loss_pack"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <sql id="selectProWorkOrderSoDirectiveVo">
        select t.workorder_so_directive_id,
               t.workorder_id,
               t.workorder_code,
               t.client_cmd,
               t.dispatch_multiple,
               t.loss_num,
               t.pack_num,
               t.pack_type,
               t.pack_unit,
               t.loss_pack,
               t.sales_voucher,
               t.sales_voucher_item,
               t.client_code,
               t.client_name,
               t.size_group,
               t.client_size_unit,
               t.type_no,
               t.color_no,
               t.color,
               t.sale_path,
               t.segment,
               t.quarter,
               t.whole_size,
               t.spec_size,
               t.po_no,
               t.wip_no,
               t.packing_num,
               t.region,
               t.cycle,
               t.sk_no,
               t.patent_no,
               t.material_desc,
               t.signer,
               t.ship_to_id,
               t.prod_spec,
               t.prod_usage,
               t.thickness,
               t.pack_mode,
               t.printing_direction,
               t.plant_code,
               t.purchase_org,
               t.quantity,
               t.quantity_produced,
               t.quantity_qualify,
               t.quantity_unqualify
        from pro_work_order_so_directive t
    </sql>

    <select id="selectProWorkOrderSoDirectiveList" parameterType="ProWorkOrderSoDirective"
            resultMap="ProWorkOrderSoDirectiveResult">
        <include refid="selectProWorkOrderSoDirectiveVo"/>
        <where>
            <if test="workorderId != null ">and t.workorder_id = #{workorderId}</if>
            <if test="clientCmd != null  and clientCmd != ''">and t.client_cmd = #{clientCmd}</if>
            <if test="dispatchMultiple != null  ">and t.dispatch_multiple = #{dispatchMultiple}</if>
            <if test="lossNum != null ">and t.loss_num = #{lossNum}</if>
            <if test="salesVoucher != null  and salesVoucher != ''">and t.sales_voucher = #{salesVoucher}</if>
            <if test="salesVoucherItem != null  and salesVoucherItem != ''">and t.sales_voucher_item =
                #{salesVoucherItem}
            </if>
            <if test="clientCode != null  and clientCode != ''">and t.client_code = #{clientCode}</if>
            <if test="clientName != null  and clientName != ''">and t.client_name = #{clientName}</if>
            <if test="sizeGroup != null  and sizeGroup != ''">and t.size_group = #{sizeGroup}</if>
            <if test="clientSizeUnit != null  and clientSizeUnit != ''">and t.client_size_unit = #{clientSizeUnit}</if>
            <if test="typeNo != null  and typeNo != ''">and t.type_no = #{typeNo}</if>
            <if test="colorNo != null  and colorNo != ''">and t.color_no = #{colorNo}</if>
            <if test="color != null  and color != ''">and t.color = #{color}</if>
            <if test="salePath != null  and salePath != ''">and t.sale_path = #{salePath}</if>
            <if test="segment != null  and segment != ''">and t.segment = #{segment}</if>
            <if test="quarter != null  and quarter != ''">and t.quarter = #{quarter}</if>
            <if test="wholeSize != null  and wholeSize != ''">and t.whole_size = #{wholeSize}</if>
            <if test="specSize != null  and specSize != ''">and t.spec_size = #{specSize}</if>
            <if test="poNo != null  and poNo != ''">and t.po_no = #{poNo}</if>
            <if test="wipNo != null  and wipNo != ''">and t.wip_no = #{wipNo}</if>
            <if test="packingNum != null  and packingNum != ''">and t.packing_num = #{packingNum}</if>
            <if test="region != null  and region != ''">and t.region = #{region}</if>
            <if test="cycle != null  and cycle != ''">and t.cycle = #{cycle}</if>
            <if test="skNo != null  and skNo != ''">and t.sk_no = #{skNo}</if>
            <if test="patentNo != null  and patentNo != ''">and t.patent_no = #{patentNo}</if>
            <if test="materialDesc != null  and materialDesc != ''">and t.material_desc = #{materialDesc}</if>
            <if test="signer != null  and signer != ''">and t.signer = #{signer}</if>
            <if test="shipToId != null  and shipToId != ''">and t.ship_to_id = #{shipToId}</if>
            <if test="prodSpec != null  and prodSpec != ''">and t.prod_spec = #{prodSpec}</if>
            <if test="prodUsage != null  and prodUsage != ''">and t.prod_usage = #{prodUsage}</if>
            <if test="thickness != null  and thickness != ''">and t.thickness = #{thickness}</if>
            <if test="packMode != null  and packMode != ''">and t.pack_mode = #{packMode}</if>
            <if test="printingDirection != null  and printingDirection != ''">and t.printing_direction =
                #{printingDirection}
            </if>
            <if test="plantCode != null  and plantCode != ''">and t.plant_code = #{plantCode}</if>
            <if test="purchaseOrg != null  and purchaseOrg != ''">and t.purchase_org = #{purchaseOrg}</if>
        </where>
    </select>

    <select id="selectProWorkOrderSoDirectiveByWorkorderSoDirectiveId" parameterType="Long"
            resultMap="ProWorkOrderSoDirectiveResult">
        <include refid="selectProWorkOrderSoDirectiveVo"/>
        where t.workorder_so_directive_id = #{workorderSoDirectiveId}
    </select>
    <select id="selectProWorkOrderSoDirectiveByWorkorderId"
            parameterType="Long"
            resultMap="ProWorkOrderSoDirectiveResult">
        <include refid="selectProWorkOrderSoDirectiveVo"/>
        where t.workorder_id = #{workorderId}
    </select>

    <insert id="insertProWorkOrderSoDirective" parameterType="ProWorkOrderSoDirective" useGeneratedKeys="true"
            keyProperty="workorderSoDirectiveId">
        insert into pro_work_order_so_directive
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workorderId != null">workorder_id,</if>
            <if test="workorderCode != null">workorder_code,</if>
            <if test="quantity != null">quantity,</if>
            <if test="quantityProduced != null">quantity_produced,</if>
            <if test="clientCmd != null">client_cmd,</if>
            <if test="dispatchMultiple != null">dispatch_multiple,</if>
            <if test="lossNum != null">loss_num,</if>
            <if test="salesVoucher != null">sales_voucher,</if>
            <if test="salesVoucherItem != null">sales_voucher_item,</if>
            <if test="clientCode != null">client_code,</if>
            <if test="clientName != null">client_name,</if>
            <if test="sizeGroup != null">size_group,</if>
            <if test="clientSizeUnit != null">client_size_unit,</if>
            <if test="typeNo != null">type_no,</if>
            <if test="colorNo != null">color_no,</if>
            <if test="color != null">color,</if>
            <if test="salePath != null">sale_path,</if>
            <if test="segment != null">segment,</if>
            <if test="quarter != null">quarter,</if>
            <if test="wholeSize != null">whole_size,</if>
            <if test="specSize != null">spec_size,</if>
            <if test="poNo != null">po_no,</if>
            <if test="wipNo != null">wip_no,</if>
            <if test="packingNum != null">packing_num,</if>
            <if test="region != null">region,</if>
            <if test="cycle != null">cycle,</if>
            <if test="skNo != null">sk_no,</if>
            <if test="patentNo != null">patent_no,</if>
            <if test="materialDesc != null">material_desc,</if>
            <if test="signer != null">signer,</if>
            <if test="shipToId != null">ship_to_id,</if>
            <if test="prodSpec != null">prod_spec,</if>
            <if test="prodUsage != null">prod_usage,</if>
            <if test="thickness != null">thickness,</if>
            <if test="packMode != null">pack_mode,</if>
            <if test="printingDirection != null">printing_direction,</if>
            <if test="plantCode != null">plant_code,</if>
            <if test="purchaseOrg != null">purchase_org,</if>
            <if test="packNum != null">pack_num,</if>
            <if test="packType != null">pack_type,</if>
            <if test="packUnit != null">pack_unit,</if>
            <if test="lossPack != null">loss_pack,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workorderId != null">#{workorderId},</if>
            <if test="workorderCode != null">#{workorderCode},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="quantityProduced != null">#{quantityProduced},</if>

            <if test="clientCmd != null">#{clientCmd},</if>
            <if test="dispatchMultiple != null">#{dispatchMultiple},</if>
            <if test="lossNum != null">#{lossNum},</if>
            <if test="salesVoucher != null">#{salesVoucher},</if>
            <if test="salesVoucherItem != null">#{salesVoucherItem},</if>
            <if test="clientCode != null">#{clientCode},</if>
            <if test="clientName != null">#{clientName},</if>
            <if test="sizeGroup != null">#{sizeGroup},</if>
            <if test="clientSizeUnit != null">#{clientSizeUnit},</if>
            <if test="typeNo != null">#{typeNo},</if>
            <if test="colorNo != null">#{colorNo},</if>
            <if test="color != null">#{color},</if>
            <if test="salePath != null">#{salePath},</if>
            <if test="segment != null">#{segment},</if>
            <if test="quarter != null">#{quarter},</if>
            <if test="wholeSize != null">#{wholeSize},</if>
            <if test="specSize != null">#{specSize},</if>
            <if test="poNo != null">#{poNo},</if>
            <if test="wipNo != null">#{wipNo},</if>
            <if test="packingNum != null">#{packingNum},</if>
            <if test="region != null">#{region},</if>
            <if test="cycle != null">#{cycle},</if>
            <if test="skNo != null">#{skNo},</if>
            <if test="patentNo != null">#{patentNo},</if>
            <if test="materialDesc != null">#{materialDesc},</if>
            <if test="signer != null">#{signer},</if>
            <if test="shipToId != null">#{shipToId},</if>
            <if test="prodSpec != null">#{prodSpec},</if>
            <if test="prodUsage != null">#{prodUsage},</if>
            <if test="thickness != null">#{thickness},</if>
            <if test="packMode != null">#{packMode},</if>
            <if test="printingDirection != null">#{printingDirection},</if>
            <if test="plantCode != null">#{plantCode},</if>
            <if test="purchaseOrg != null">#{purchaseOrg},</if>
            <if test="packNum != null">#{packNum},</if>
            <if test="packType != null">#{packType},</if>
            <if test="packUnit != null">#{packUnit},</if>
            <if test="lossPack != null">#{lossPack},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateProWorkOrderSoDirective" parameterType="ProWorkOrderSoDirective">
        update pro_work_order_so_directive
        <trim prefix="SET" suffixOverrides=",">
            <if test="workorderId != null">workorder_id = #{workorderId},</if>
            <if test="workorderCode != null">workorder_code = #{workorderCode},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="quantityProduced != null">quantity_produced = #{quantityProduced},</if>
            <if test="clientCmd != null">client_cmd = #{clientCmd},</if>
            <if test="dispatchMultiple != null">dispatch_multiple = #{dispatchMultiple},</if>
            <if test="lossNum != null">loss_num = #{lossNum},</if>
            <if test="salesVoucher != null">sales_voucher = #{salesVoucher},</if>
            <if test="salesVoucherItem != null">sales_voucher_item = #{salesVoucherItem},</if>
            <if test="clientCode != null">client_code = #{clientCode},</if>
            <if test="clientName != null">client_name = #{clientName},</if>
            <if test="sizeGroup != null">size_group = #{sizeGroup},</if>
            <if test="clientSizeUnit != null">client_size_unit = #{clientSizeUnit},</if>
            <if test="typeNo != null">type_no = #{typeNo},</if>
            <if test="colorNo != null">color_no = #{colorNo},</if>
            <if test="color != null">color = #{color},</if>
            <if test="salePath != null">sale_path = #{salePath},</if>
            <if test="segment != null">segment = #{segment},</if>
            <if test="quarter != null">quarter = #{quarter},</if>
            <if test="wholeSize != null">whole_size = #{wholeSize},</if>
            <if test="specSize != null">spec_size = #{specSize},</if>
            <if test="poNo != null">po_no = #{poNo},</if>
            <if test="wipNo != null">wip_no = #{wipNo},</if>
            <if test="packingNum != null">packing_num = #{packingNum},</if>
            <if test="region != null">region = #{region},</if>
            <if test="cycle != null">cycle = #{cycle},</if>
            <if test="skNo != null">sk_no = #{skNo},</if>
            <if test="patentNo != null">patent_no = #{patentNo},</if>
            <if test="materialDesc != null">material_desc = #{materialDesc},</if>
            <if test="signer != null">signer = #{signer},</if>
            <if test="shipToId != null">ship_to_id = #{shipToId},</if>
            <if test="prodSpec != null">prod_spec = #{prodSpec},</if>
            <if test="prodUsage != null">prod_usage = #{prodUsage},</if>
            <if test="thickness != null">thickness = #{thickness},</if>
            <if test="packMode != null">pack_mode = #{packMode},</if>
            <if test="printingDirection != null">printing_direction = #{printingDirection},</if>
            <if test="plantCode != null">plant_code = #{plantCode},</if>
            <if test="purchaseOrg != null">purchase_org = #{purchaseOrg},</if>
            <if test="packNum != null">pack_num = #{packNum},</if>
            <if test="packType != null">pack_type = #{packType},</if>
            <if test="packUnit != null">pack_unit = #{packUnit},</if>
            <if test="lossPack != null">loss_pack = #{lossPack},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where workorder_so_directive_id = #{workorderSoDirectiveId}
    </update>

    <delete id="deleteProWorkOrderSoDirectiveByWorkorderSoDirectiveId" parameterType="Long">
        delete
        from pro_work_order_so_directive
        where workorder_so_directive_id = #{workorderSoDirectiveId}
    </delete>

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