<?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.wm.mapper.WmIssueRecordMapper">

    <resultMap type="WmIssueRecord" id="WmIssueRecordResult">
        <result property="issueRecordId"    column="issue_record_id"    />
        <result property="issueCode"    column="issue_code"    />
        <result property="issueName"    column="issue_name"    />
        <result property="issueType"    column="issue_type"    />
        <result property="workorderCode"    column="workorder_code"    />
        <result property="itemCode"    column="item_code"    />
        <result property="quantityIssued"    column="quantity_issued"    />
        <result property="batchCode"    column="batch_code"    />
        <result property="packNo"    column="pack_no"    />
        <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="selectWmIssueRecordVo">
        select issue_record_id, issue_code, issue_name, issue_type, workorder_code, item_code, quantity_issued, batch_code, pack_no, create_by, create_time, update_by, update_time from wm_issue_record
    </sql>

    <select id="selectWmIssueRecordList" parameterType="WmIssueRecord" resultMap="WmIssueRecordResult">
        <include refid="selectWmIssueRecordVo"/>
        <where>
            <if test="issueCode != null  and issueCode != ''"> and issue_code = #{issueCode}</if>
            <if test="issueName != null  and issueName != ''"> and issue_name like concat('%', #{issueName}, '%')</if>
            <if test="issueType != null  and issueType != ''"> and issue_type = #{issueType}</if>
            <if test="workorderCode != null "> and workorder_code = #{workorderCode}</if>
            <if test="itemCode != null  and itemCode != ''"> and item_code = #{itemCode}</if>
            <if test="quantityIssued != null "> and quantity_issued = #{quantityIssued}</if>
            <if test="batchCode != null  and batchCode != ''"> and batch_code = #{batchCode}</if>
            <if test="packNo != null  and packNo != ''"> and pack_no = #{packNo}</if>
        </where>
    </select>

    <select id="selectWmIssueRecordByIssueRecordId" parameterType="Long" resultMap="WmIssueRecordResult">
        <include refid="selectWmIssueRecordVo"/>
        where issue_record_id = #{issueRecordId}
    </select>

    <insert id="insertWmIssueRecord" parameterType="WmIssueRecord" useGeneratedKeys="true" keyProperty="issueRecordId">
        insert into wm_issue_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="issueCode != null">issue_code,</if>
            <if test="issueName != null">issue_name,</if>
            <if test="issueType != null">issue_type,</if>
            <if test="workorderCode != null">workorder_code,</if>
            <if test="itemCode != null">item_code,</if>
            <if test="quantityIssued != null">quantity_issued,</if>
            <if test="batchCode != null">batch_code,</if>
            <if test="packNo != null">pack_no,</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="issueCode != null">#{issueCode},</if>
            <if test="issueName != null">#{issueName},</if>
            <if test="issueType != null">#{issueType},</if>
            <if test="workorderCode != null">#{workorderCode},</if>
            <if test="itemCode != null">#{itemCode},</if>
            <if test="quantityIssued != null">#{quantityIssued},</if>
            <if test="batchCode != null">#{batchCode},</if>
            <if test="packNo != null">#{packNo},</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="updateWmIssueRecord" parameterType="WmIssueRecord">
        update wm_issue_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="issueCode != null">issue_code = #{issueCode},</if>
            <if test="issueName != null">issue_name = #{issueName},</if>
            <if test="issueType != null">issue_type = #{issueType},</if>
            <if test="workorderCode != null">workorder_code = #{workorderCode},</if>
            <if test="itemCode != null">item_code = #{itemCode},</if>
            <if test="quantityIssued != null">quantity_issued = #{quantityIssued},</if>
            <if test="batchCode != null">batch_code = #{batchCode},</if>
            <if test="packNo != null">pack_no = #{packNo},</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 issue_record_id = #{issueRecordId}
    </update>

    <delete id="deleteWmIssueRecordByIssueRecordId" parameterType="Long">
        delete from wm_issue_record where issue_record_id = #{issueRecordId}
    </delete>

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