<?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.WmsRawInstockMapper">

    <resultMap type="WmsRawInstock" id="WmsRawInstockResult">
        <result property="rawInstockId"    column="raw_instock_id"    />
        <result property="taskCode"    column="task_code"    />
        <result property="warehouseId"    column="warehouse_id"    />
        <result property="locationCode"    column="location_code"    />
        <result property="poNo"    column="po_no"    />
        <result property="operationType"    column="operation_type"    />
        <result property="instockType"    column="instock_type"    />
        <result property="materialId"    column="material_id"    />
        <result property="materialBarcode"    column="material_barcode"    />
        <result property="materialBatchCode"    column="material_batch_code"    />
        <result property="palletInfoCode"    column="pallet_info_code"    />
        <result property="instockAmount"    column="instock_amount"    />
        <result property="executeStatus"    column="execute_status"    />
        <result property="erpStatus"    column="erp_status"    />
        <result property="erpAmount"    column="erp_amount"    />
        <result property="applyBy"    column="apply_by"    />
        <result property="applyDate"    column="apply_date"    />
        <result property="machineName"    column="machine_name"    />
        <result property="qualityStatus"    column="quality_status"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateDate"    column="update_date"    />
        <result property="beginTime"    column="begin_time"    />
        <result property="endTime"    column="end_time"    />
    </resultMap>

    <sql id="selectWmsRawInstockVo">
        select raw_instock_id, task_code, warehouse_id, location_code, po_no, operation_type, instock_type, material_id, material_barcode, material_batch_code, pallet_info_code, instock_amount, execute_status, erp_status, erp_amount, apply_by, apply_date, machine_name, quality_status, update_by, update_date, begin_time, end_time from wms_raw_instock
    </sql>

    <select id="selectWmsRawInstockList" parameterType="WmsRawInstock" resultMap="WmsRawInstockResult">
        <include refid="selectWmsRawInstockVo"/>
        <where>
            <if test="taskCode != null  and taskCode != ''"> and task_code = #{taskCode}</if>
            <if test="warehouseId != null "> and warehouse_id = #{warehouseId}</if>
            <if test="locationCode != null  and locationCode != ''"> and location_code = #{locationCode}</if>
            <if test="poNo != null  and poNo != ''"> and po_no = #{poNo}</if>
            <if test="operationType != null  and operationType != ''"> and operation_type = #{operationType}</if>
            <if test="instockType != null  and instockType != ''"> and instock_type = #{instockType}</if>
            <if test="applyReason != null  and applyReason != ''"> and apply_reason = #{applyReason}</if>
            <if test="auditReason != null  and auditReason != ''"> and audit_reason = #{auditReason}</if>
            <if test="auditStatus != null  and auditStatus != ''"> and audit_status = #{auditStatus}</if>
            <if test="executeStatus != null  and executeStatus != ''"> and execute_status = #{executeStatus}</if>
            <if test="applyBy != null  and applyBy != ''"> and apply_by = #{applyBy}</if>
            <if test="applyDate != null "> and apply_date = #{applyDate}</if>
            <if test="auditBy != null  and auditBy != ''"> and audit_by = #{auditBy}</if>
            <if test="auditDate != null "> and audit_date = #{auditDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
            <if test="beginTime != null "> and begin_time = #{beginTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
        </where>
    </select>

    <select id="selectWmsRawInstockByRawInstockId" parameterType="Long" resultMap="WmsRawInstockResult">
        <include refid="selectWmsRawInstockVo"/>
        where raw_instock_id = #{rawInstockId}
    </select>

    <insert id="insertWmsRawInstock" parameterType="WmsRawInstock" useGeneratedKeys="true" keyProperty="rawInstockId">
        insert into wms_raw_instock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskCode != null">task_code,</if>
            <if test="warehouseId != null">warehouse_id,</if>
            <if test="locationCode != null">location_code,</if>
            <if test="poNo != null">po_no,</if>
            <if test="operationType != null and operationType != ''">operation_type,</if>
            <if test="instockType != null and instockType != ''">instock_type,</if>
            <if test="materialId != null">material_id,</if>
            <if test="materialBarcode != null">material_barcode,</if>
            <if test="materialBatchCode != null">material_batch_code,</if>
            <if test="palletInfoCode != null">pallet_info_code,</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="erpAmount != null">erp_amount,</if>
            <if test="applyBy != null">apply_by,</if>
            <if test="applyDate != null">apply_date,</if>
            <if test="machineName != null">machine_name,</if>
            <if test="qualityStatus != null">quality_status,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="beginTime != null">begin_time,</if>
            <if test="endTime != null">end_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskCode != null">#{taskCode},</if>
            <if test="warehouseId != null">#{warehouseId},</if>
            <if test="locationCode != null">#{locationCode},</if>
            <if test="poNo != null">#{poNo},</if>
            <if test="operationType != null and operationType != ''">#{operationType},</if>
            <if test="instockType != null and instockType != ''">#{instockType},</if>
            <if test="materialId != null">#{materialId},</if>
            <if test="materialBarcode != null">#{materialBarcode},</if>
            <if test="materialBatchCode != null">#{materialBatchCode},</if>
            <if test="palletInfoCode != null">#{palletInfoCode},</if>
            <if test="instockAmount != null">#{instockAmount},</if>
            <if test="executeStatus != null and executeStatus != ''">#{executeStatus},</if>
            <if test="erpStatus != null">#{erpStatus},</if>
            <if test="erpAmount != null">#{erpAmount},</if>
            <if test="applyBy != null">#{applyBy},</if>
            <if test="applyDate != null">#{applyDate},</if>
            <if test="machineName != null">#{machineName},</if>
            <if test="qualityStatus != null">#{qualityStatus},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="beginTime != null">#{beginTime},</if>
            <if test="endTime != null">#{endTime},</if>
        </trim>
    </insert>

    <update id="updateWmsRawInstock" parameterType="WmsRawInstock">
        update wms_raw_instock
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskCode != null">task_code = #{taskCode},</if>
            <if test="warehouseId != null">warehouse_id = #{warehouseId},</if>
            <if test="locationCode != null">location_code = #{locationCode},</if>
            <if test="poNo != null">po_no = #{poNo},</if>
            <if test="operationType != null and operationType != ''">operation_type = #{operationType},</if>
            <if test="instockType != null and instockType != ''">instock_type = #{instockType},</if>
            <if test="materialId != null">material_id = #{materialId},</if>
            <if test="materialBarcode != null">material_barcode = #{materialBarcode},</if>
            <if test="materialBatchCode != null">material_batch_code = #{materialBatchCode},</if>
            <if test="palletInfoCode != null">pallet_info_code = #{palletInfoCode},</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="erpAmount != null">erp_amount = #{erpAmount},</if>
            <if test="applyBy != null">apply_by = #{applyBy},</if>
            <if test="applyDate != null">apply_date = #{applyDate},</if>
            <if test="machineName != null">machine_name = #{machineName},</if>
            <if test="qualityStatus != null">quality_status = #{qualityStatus},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="beginTime != null">begin_time = #{beginTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
        </trim>
        where raw_instock_id = #{rawInstockId}
    </update>

    <delete id="deleteWmsRawInstockByRawInstockId" parameterType="Long">
        delete from wms_raw_instock where raw_instock_id = #{rawInstockId}
    </delete>

    <delete id="deleteWmsRawInstockByRawInstockIds" parameterType="String">
        delete from wms_raw_instock where raw_instock_id in
        <foreach item="rawInstockId" collection="array" open="(" separator="," close=")">
            #{rawInstockId}
        </foreach>
    </delete>






    <select id="selectWmsRawInstockByBarcode" parameterType="String" resultMap="WmsRawInstockResult">
        <include refid="selectWmsRawInstockVo"/>
        where material_barcode = #{materialBarcode}
    </select>

</mapper>
