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

    <resultMap type="ProWorkOrderDtaRecord" id="ProWorkOrderDtoRecordResult">
        <result property="id" column="id"/>
        <result property="workorderId" column="workorder_id"/>
        <result property="workorderCode" column="workorder_code"/>
        <result property="saleCode" column="sale_code"/>
        <result property="itemId" column="item_id"/>
        <result property="sapItemCode" column="sap_item_code"/>
        <result property="itemName" column="item_name"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <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="selectProWorkOrderDtoRecordVo">
        select id,
               workorder_id,
               workorder_code,
               sale_code,
               item_id,
               sap_item_code,
               item_name,
               start_time,
               end_time,
               create_by,
               create_time,
               update_by,
               update_time
        from pro_work_order_dta_record
    </sql>

    <select id="selectProWorkOrderDtaRecordList" parameterType="ProWorkOrderDtaRecord"
            resultMap="ProWorkOrderDtoRecordResult">
        <include refid="selectProWorkOrderDtoRecordVo"/>
        <where>
            <if test="workorderId != null ">and workorder_id = #{workorderId}</if>
            <if test="workorderCode != null ">and workorder_code = #{workorderCode}</if>
            <if test="saleCode != null ">and sale_code = #{saleCode}</if>
            <if test="itemId != null ">and item_id = #{itemId}</if>
            <if test="sapItemCode != null  and sapItemCode != ''">and sap_item_code = #{sapItemCode}</if>
            <if test="itemName != null  and itemName != ''">and item_name like concat('%', #{itemName}, '%')</if>
            <if test="startTime != null ">and start_time = #{startTime}</if>
            <if test="endTime != null ">and end_time = #{endTime}</if>
        </where>
    </select>

    <select id="selectProWorkOrderDtaRecordById" parameterType="Long" resultMap="ProWorkOrderDtoRecordResult">
        <include refid="selectProWorkOrderDtoRecordVo"/>
        where id = #{id}
    </select>

    <insert id="insertProWorkOrderDtaRecord" parameterType="ProWorkOrderDtaRecord" useGeneratedKeys="true"
            keyProperty="id">
        insert into pro_work_order_dta_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workorderId != null">workorder_id,</if>
            <if test="workorderCode != null">workorder_code,</if>
            <if test="saleCode != null">sale_code,</if>
            <if test="itemId != null">item_id,</if>
            <if test="sapItemCode != null">sap_item_code,</if>
            <if test="itemName != null">item_name,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</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="workorderId != null">#{workorderId},</if>
            <if test="workorderCode != null">#{workorderCode},</if>
            <if test="saleCode != null">#{saleCode},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="sapItemCode != null">#{sapItemCode},</if>
            <if test="itemName != null">#{itemName},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</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="updateProWorkOrderDtaRecord" parameterType="ProWorkOrderDtaRecord">
        update pro_work_order_dta_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="workorderId != null">workorder_id = #{workorderId},</if>
            <if test="workorderCode != null">workorder_code = #{workorderCode},</if>
            <if test="saleCode != null">sale_code = #{saleCode},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="sapItemCode != null">sap_item_code = #{sapItemCode},</if>
            <if test="itemName != null">item_name = #{itemName},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProWorkOrderDtaRecordById" parameterType="Long">
        delete
        from pro_work_order_dta_record
        where id = #{id}
    </delete>

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