<?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.op.mes.mapper.ProOrderWorkorderBatchMapper">

    <resultMap type="ProOrderWorkorderBatch" id="ProOrderWorkorderBatchResult">
        <result property="batchId"	column="batch_id"	/>
        <result property="workorderId"	column="workorder_id"	/>
        <result property="batchCode"	column="batch_code"	/>
        <result property="batchQuantity"	column="batch_quantity"	/>
        <result property="status"	column="status"	/>
        <result property="remark"	column="remark"	/>
        <result property="attr1"	column="attr1"	/>
        <result property="attr2"	column="attr2"	/>
        <result property="attr3"	column="attr3"	/>
        <result property="attr4"	column="attr4"	/>
        <result property="createBy"	column="create_by"	/>
        <result property="createTime"	column="create_time"	/>
        <result property="updateBy"	column="update_by"	/>
        <result property="updateTime"	column="update_time"	/>
        <result property="prodType"	column="prod_type"	/>
        <result property="factoryCode"	column="factory_code"	/>
    </resultMap>

    <sql id="selectProOrderWorkorderBatchVo">
		select batch_id, workorder_id, batch_code, batch_quantity, status, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time, prod_type, factory_code from pro_order_workorder_batch
	</sql>

    <select id="selectProOrderWorkorderBatchList" parameterType="ProOrderWorkorderBatch" resultMap="ProOrderWorkorderBatchResult">
        <include refid="selectProOrderWorkorderBatchVo"/>
        <where>
            <if test="batchId != null  and batchId != ''"> and batch_id = #{batchId}</if>
            <if test="batchCode != null  and batchCode != ''"> and batch_code = #{batchCode}</if>
            <if test="batchQuantity != null "> and batch_quantity = #{batchQuantity}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="attr1 != null  and attr1 != ''"> and attr1 = #{attr1}</if>
            <if test="attr2 != null  and attr2 != ''"> and attr2 = #{attr2}</if>
            <if test="attr3 != null  and attr3 != ''"> and attr3 = #{attr3}</if>
            <if test="attr4 != null  and attr4 != ''"> and attr4 = #{attr4}</if>
            <if test="prodType != null  and prodType != ''"> and prod_type = #{prodType}</if>
            <if test="factoryCode != null  and factoryCode != ''"> and factory_code = #{factoryCode}</if>
        </where>
    </select>

    <select id="selectProOrderWorkorderBatchByWorkorderId" parameterType="String" resultMap="ProOrderWorkorderBatchResult">
        <include refid="selectProOrderWorkorderBatchVo"/>
        where workorder_id = #{workorderId}
    </select>

    <insert id="insertProOrderWorkorderBatch" parameterType="ProOrderWorkorderBatch">
        insert into pro_order_workorder_batch
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="batchId != null and batchId != ''">batch_id,</if>
            <if test="workorderId != null">workorder_id,</if>
            <if test="batchCode != null">batch_code,</if>
            <if test="batchQuantity != null">batch_quantity,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="attr1 != null">attr1,</if>
            <if test="attr2 != null">attr2,</if>
            <if test="attr3 != null">attr3,</if>
            <if test="attr4 != null">attr4,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="prodType != null">prod_type,</if>
            <if test="factoryCode != null">factory_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="batchId != null and batchId != ''">#{batchId},</if>
            <if test="workorderId != null">#{workorderId},</if>
            <if test="batchCode != null">#{batchCode},</if>
            <if test="batchQuantity != null">#{batchQuantity},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="attr1 != null">#{attr1},</if>
            <if test="attr2 != null">#{attr2},</if>
            <if test="attr3 != null">#{attr3},</if>
            <if test="attr4 != null">#{attr4},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="prodType != null">#{prodType},</if>
            <if test="factoryCode != null">#{factoryCode},</if>
        </trim>
    </insert>

    <update id="updateProOrderWorkorderBatch" parameterType="ProOrderWorkorderBatch">
        update pro_order_workorder_batch
        <trim prefix="SET" suffixOverrides=",">
            <if test="batchId != null and batchId != ''">batch_id = #{batchId},</if>
            <if test="batchCode != null">batch_code = #{batchCode},</if>
            <if test="batchQuantity != null">batch_quantity = #{batchQuantity},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="attr1 != null">attr1 = #{attr1},</if>
            <if test="attr2 != null">attr2 = #{attr2},</if>
            <if test="attr3 != null">attr3 = #{attr3},</if>
            <if test="attr4 != null">attr4 = #{attr4},</if>
            <if test="createBy != null">create_by = #{createBy},</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="prodType != null">prod_type = #{prodType},</if>
            <if test="factoryCode != null">factory_code = #{factoryCode},</if>
        </trim>
        where workorder_id = #{workorderId}
    </update>

    <delete id="deleteProOrderWorkorderBatchByWorkorderId" parameterType="String">
		delete from pro_order_workorder_batch where workorder_id = #{workorderId}
	</delete>

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