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

    <resultMap type="ProRecoilMaterial" id="ProRecoilMaterialResult">
        <result property="id" column="id"/>
        <result property="recoilMaterialCode" column="recoil_material_code"/>
        <result property="itemId" column="item_id"/>
        <result property="itemName" column="item_name"/>
        <result property="sapItemCode" column="sap_item_code"/>
        <result property="taskId" column="task_id"/>
        <result property="taskWorkunitId" column="task_workunit_id"/>
        <result property="batchNo" column="batch_no"/>
        <result property="packNo" column="pack_no"/>
        <result property="quantity" column="quantity"/>
        <result property="status" column="status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectProRecoilMaterialVo">
        select id,
               recoil_material_code,
               item_id,
               item_name,
               sap_item_code,
               task_id,
               task_workunit_id,
               batch_no,
               pack_no,
               quantity,
               status,
               create_by,
               create_time,
               update_by,
               update_time
        from pro_recoil_material
    </sql>

    <select id="selectProRecoilMaterialList" parameterType="ProRecoilMaterial" resultMap="ProRecoilMaterialResult">
        <include refid="selectProRecoilMaterialVo"/>
        <where>
            <if test="recoilMaterialCode != null  and recoilMaterialCode != ''">and recoil_material_code =
                #{recoilMaterialCode}
            </if>
            <if test="itemId != null ">and item_id = #{itemId}</if>
            <if test="taskId != null ">and task_id = #{taskId}</if>
            <if test="taskWorkunitId != null ">and task_workunit_id = #{taskWorkunitId}</if>
            <if test="batchNo != null  and batchNo != ''">and batch_no = #{batchNo}</if>
            <if test="packNo != null  and packNo != ''">and pack_no = #{packNo}</if>
        </where>
    </select>

    <select id="selectProRecoilMaterialById" parameterType="Long" resultMap="ProRecoilMaterialResult">
        <include refid="selectProRecoilMaterialVo"/>
        where id = #{id}
    </select>

    <insert id="insertProRecoilMaterial" parameterType="ProRecoilMaterial" useGeneratedKeys="true"
            keyProperty="id">
        insert into pro_recoil_material
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recoilMaterialCode != null">recoil_material_code,</if>
            <if test="itemId != null">item_id,</if>
            <if test="itemName != null">item_name,</if>
            <if test="sapItemCode != null">sap_item_code,</if>
            <if test="taskId != null">task_id,</if>
            <if test="taskWorkunitId != null">task_workunit_id,</if>
            <if test="batchNo != null">batch_no,</if>
            <if test="packNo != null">pack_no,</if>
            <if test="quantity != null">quantity,</if>
            <if test="status != null">status,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="recoilMaterialCode != null">#{recoilMaterialCode},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="itemName != null">#{itemName},</if>
            <if test="sapItemCode != null">#{sapItemCode},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="taskWorkunitId != null">#{taskWorkunitId},</if>
            <if test="batchNo != null">#{batchNo},</if>
            <if test="packNo != null">#{packNo},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="status != null">#{status},</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>
        </trim>
    </insert>

    <update id="updateProRecoilMaterial" parameterType="ProRecoilMaterial">
        update pro_recoil_material
        <trim prefix="SET" suffixOverrides=",">
            <if test="recoilMaterialCode != null">recoil_material_code = #{recoilMaterialCode},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="itemName != null">item_name = #{itemName},</if>
            <if test="sapItemCode != null">sap_item_code = #{sapItemCode},</if>
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="taskWorkunitId != null">task_workunit_id = #{taskWorkunitId},</if>
            <if test="batchNo != null">batch_no = #{batchNo},</if>
            <if test="packNo != null">pack_no = #{packNo},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="status != null">status = #{status},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProRecoilMaterialById" parameterType="Long">
        delete
        from pro_recoil_material
        where id = #{id}
    </delete>

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