<?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.hw.wms.mapper.WmsRawInstockDetailMapper">

    <resultMap type="WmsRawInstockDetail" id="WmsRawInstockDetailResult">
        <result property="rawInstockDetailId"    column="raw_instock_detail_id"    />
        <result property="rawInstockId"    column="raw_instock_id"    />
        <result property="locationCode"    column="location_code"    />
        <result property="materialBarcode"    column="material_barcode"    />
        <result property="instockBatch"    column="instock_batch"    />
        <result property="materialId"    column="material_id"    />
        <result property="poNo"    column="po_no"    />
        <result property="materialProductionDate"    column="material_production_date"    />
        <result property="planAmount"    column="plan_amount"    />
        <result property="instockAmount"    column="instock_amount"    />
        <result property="executeStatus"    column="execute_status"    />
        <result property="erpStatus"    column="erp_status"    />
        <result property="instockPerson"    column="instock_person"    />
        <result property="instockTime"    column="instock_time"    />
        <result property="instockWay"    column="instock_way"    />
        <result property="machineName"    column="machine_name"    />
        <result property="qualityStatus"    column="quality_status"    />
        <result property="stackAmount"    column="stack_amount"    />
        <result property="createBy"    column="create_by"    />
        <result property="createDate"    column="create_date"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateDate"    column="update_date"    />
        <result property="activeFlag"    column="active_flag"    />
        <result property="poLine"    column="po_line"    />
    </resultMap>

    <sql id="selectWmsRawInstockDetailVo">
        select raw_instock_detail_id, raw_instock_id, location_code, material_barcode, instock_batch, material_id, po_no, material_production_date, plan_amount, instock_amount, execute_status, erp_status, instock_person, instock_time, instock_way, machine_name, quality_status, stack_amount, create_by, create_date, update_by, update_date, active_flag, po_line from wms_raw_instock_detail
    </sql>

    <select id="selectWmsRawInstockDetailList" parameterType="WmsRawInstockDetail" resultMap="WmsRawInstockDetailResult">
        <include refid="selectWmsRawInstockDetailVo"/>
        <where>
            <if test="rawInstockId != null "> and raw_instock_id = #{rawInstockId}</if>
            <if test="locationCode != null  and locationCode != ''"> and location_code = #{locationCode}</if>
            <if test="materialBarcode != null  and materialBarcode != ''"> and material_barcode = #{materialBarcode}</if>
            <if test="instockBatch != null  and instockBatch != ''"> and instock_batch = #{instockBatch}</if>
            <if test="materialId != null "> and material_id = #{materialId}</if>
            <if test="poNo != null  and poNo != ''"> and po_no = #{poNo}</if>
            <if test="materialProductionDate != null "> and material_production_date = #{materialProductionDate}</if>
            <if test="planAmount != null "> and plan_amount = #{planAmount}</if>
            <if test="instockAmount != null "> and instock_amount = #{instockAmount}</if>
            <if test="executeStatus != null  and executeStatus != ''"> and execute_status = #{executeStatus}</if>
            <if test="erpStatus != null  and erpStatus != ''"> and erp_status = #{erpStatus}</if>
            <if test="instockPerson != null  and instockPerson != ''"> and instock_person = #{instockPerson}</if>
            <if test="instockTime != null "> and instock_time = #{instockTime}</if>
            <if test="instockWay != null  and instockWay != ''"> and instock_way = #{instockWay}</if>
            <if test="machineName != null  and machineName != ''"> and machine_name like concat('%', #{machineName}, '%')</if>
            <if test="qualityStatus != null  and qualityStatus != ''"> and quality_status = #{qualityStatus}</if>
            <if test="stackAmount != null "> and stack_amount = #{stackAmount}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
            <if test="activeFlag != null  and activeFlag != ''"> and active_flag = #{activeFlag}</if>
            <if test="poLine != null  and poLine != ''"> and po_line = #{poLine}</if>
        </where>
    </select>

    <select id="selectWmsRawInstockDetailByRawInstockDetailId" parameterType="Long" resultMap="WmsRawInstockDetailResult">
        <include refid="selectWmsRawInstockDetailVo"/>
        where raw_instock_detail_id = #{rawInstockDetailId}
    </select>

    <insert id="insertWmsRawInstockDetail" parameterType="WmsRawInstockDetail" useGeneratedKeys="true" keyProperty="rawInstockDetailId">
        insert into wms_raw_instock_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="rawInstockId != null">raw_instock_id,</if>
            <if test="locationCode != null and locationCode != ''">location_code,</if>
            <if test="materialBarcode != null and materialBarcode != ''">material_barcode,</if>
            <if test="instockBatch != null">instock_batch,</if>
            <if test="materialId != null">material_id,</if>
            <if test="poNo != null">po_no,</if>
            <if test="materialProductionDate != null">material_production_date,</if>
            <if test="planAmount != null">plan_amount,</if>
            <if test="instockAmount != null">instock_amount,</if>
            <if test="executeStatus != null and executeStatus != ''">execute_status,</if>
            <if test="erpStatus != null">erp_status,</if>
            <if test="instockPerson != null">instock_person,</if>
            <if test="instockTime != null">instock_time,</if>
            <if test="instockWay != null and instockWay != ''">instock_way,</if>
            <if test="machineName != null">machine_name,</if>
            <if test="qualityStatus != null">quality_status,</if>
            <if test="stackAmount != null">stack_amount,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createDate != null">create_date,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="activeFlag != null">active_flag,</if>
            <if test="poLine != null">po_line,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="rawInstockId != null">#{rawInstockId},</if>
            <if test="locationCode != null and locationCode != ''">#{locationCode},</if>
            <if test="materialBarcode != null and materialBarcode != ''">#{materialBarcode},</if>
            <if test="instockBatch != null">#{instockBatch},</if>
            <if test="materialId != null">#{materialId},</if>
            <if test="poNo != null">#{poNo},</if>
            <if test="materialProductionDate != null">#{materialProductionDate},</if>
            <if test="planAmount != null">#{planAmount},</if>
            <if test="instockAmount != null">#{instockAmount},</if>
            <if test="executeStatus != null and executeStatus != ''">#{executeStatus},</if>
            <if test="erpStatus != null">#{erpStatus},</if>
            <if test="instockPerson != null">#{instockPerson},</if>
            <if test="instockTime != null">#{instockTime},</if>
            <if test="instockWay != null and instockWay != ''">#{instockWay},</if>
            <if test="machineName != null">#{machineName},</if>
            <if test="qualityStatus != null">#{qualityStatus},</if>
            <if test="stackAmount != null">#{stackAmount},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="activeFlag != null">#{activeFlag},</if>
            <if test="poLine != null">#{poLine},</if>
         </trim>
    </insert>

    <update id="updateWmsRawInstockDetail" parameterType="WmsRawInstockDetail">
        update wms_raw_instock_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="rawInstockId != null">raw_instock_id = #{rawInstockId},</if>
            <if test="locationCode != null and locationCode != ''">location_code = #{locationCode},</if>
            <if test="materialBarcode != null and materialBarcode != ''">material_barcode = #{materialBarcode},</if>
            <if test="instockBatch != null">instock_batch = #{instockBatch},</if>
            <if test="materialId != null">material_id = #{materialId},</if>
            <if test="poNo != null">po_no = #{poNo},</if>
            <if test="materialProductionDate != null">material_production_date = #{materialProductionDate},</if>
            <if test="planAmount != null">plan_amount = #{planAmount},</if>
            <if test="instockAmount != null">instock_amount = #{instockAmount},</if>
            <if test="executeStatus != null and executeStatus != ''">execute_status = #{executeStatus},</if>
            <if test="erpStatus != null">erp_status = #{erpStatus},</if>
            <if test="instockPerson != null">instock_person = #{instockPerson},</if>
            <if test="instockTime != null">instock_time = #{instockTime},</if>
            <if test="instockWay != null and instockWay != ''">instock_way = #{instockWay},</if>
            <if test="machineName != null">machine_name = #{machineName},</if>
            <if test="qualityStatus != null">quality_status = #{qualityStatus},</if>
            <if test="stackAmount != null">stack_amount = #{stackAmount},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="activeFlag != null">active_flag = #{activeFlag},</if>
            <if test="poLine != null">po_line = #{poLine},</if>
        </trim>
        where raw_instock_detail_id = #{rawInstockDetailId}
    </update>

    <delete id="deleteWmsRawInstockDetailByRawInstockDetailId" parameterType="Long">
        delete from wms_raw_instock_detail where raw_instock_detail_id = #{rawInstockDetailId}
    </delete>

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