<?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.qc.mapper.QcTemplateProcessMapper">

    <resultMap type="QcTemplateProcess" id="QcTemplateProcessResult">
        <result property="id" column="id"/>
        <result property="templateId" column="template_id"/>
        <result property="templateName" column="template_name"/>
        <result property="itemTypeId" column="item_type_id"/>
        <result property="itemTypeName" column="item_type_name"/>
        <result property="processId" column="process_id"/>
        <result property="processName" column="process_name"/>
        <result property="maxNum" column="max_num"/>
        <result property="isConfirm" column="is_confirm"/>
        <result property="isNewProduct" column="is_new_product"/>
        <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="pcType" column="pc_type"/>
    </resultMap>

    <sql id="selectQcTemplateProcessVo">
        select t1.*, t2.template_name
        from qc_template_process t1
                 left join qc_template t2 on t1.template_id = t2.id
    </sql>

    <select id="selectQcTemplateProcessList" parameterType="QcTemplateProcess" resultMap="QcTemplateProcessResult">
        <include refid="selectQcTemplateProcessVo"/>
        <where>
            <if test="templateId != null ">and t1.template_id = #{templateId}</if>
            <if test="templateName != null ">and t2.template_name = #{templateName}</if>
            <if test="itemTypeId != null ">and item_type_id = #{itemTypeId}</if>
            <if test="itemTypeName != null  and itemTypeName != ''">and item_type_name like concat('%', #{itemTypeName},
                '%')
            </if>
            <if test="processName != null  and processName != ''">and process_name like concat('%', #{processName},
                '%')
            </if>
            <if test="maxNum != null ">and max_num = #{maxNum}</if>
            <if test="isConfirm != null ">and is_confirm = #{isConfirm}</if>
            <if test="isNewProduct != null ">and is_new_product = #{isNewProduct}</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 = #{attr3}</if>
            <if test="attr4 != null ">and attr4 = #{attr4}</if>
        </where>
    </select>

    <select id="selectQcTemplateProcessById" parameterType="Long" resultMap="QcTemplateProcessResult">
        <include refid="selectQcTemplateProcessVo"/>
        where t1.id = #{id}
    </select>

    <insert id="insertQcTemplateProcess" parameterType="QcTemplateProcess" useGeneratedKeys="true"
            keyProperty="id">
        insert into qc_template_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="templateId != null">template_id,</if>
            <if test="itemTypeId != null">item_type_id,</if>
            <if test="itemTypeName != null">item_type_name,</if>
            <if test="processId != null and processId != ''">process_id,</if>
            <if test="processName != null and processName != ''">process_name,</if>
            <if test="maxNum != null">max_num,</if>
            <if test="isConfirm != null">is_confirm,</if>
            <if test="isNewProduct != null">is_new_product,</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="qcType != null">qc_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="templateId != null">#{templateId},</if>
            <if test="itemTypeId != null">#{itemTypeId},</if>
            <if test="itemTypeName != null">#{itemTypeName},</if>
            <if test="processId != null and processId != ''">#{processId},</if>
            <if test="processName != null and processName != ''">#{processName},</if>
            <if test="maxNum != null">#{maxNum},</if>
            <if test="isConfirm != null">#{isConfirm},</if>
            <if test="isNewProduct != null">#{isNewProduct},</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="qcType != null">#{qcType},</if>
        </trim>
    </insert>

    <update id="updateQcTemplateProcess" parameterType="QcTemplateProcess">
        update qc_template_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="templateId != null">template_id = #{templateId},</if>
            <if test="itemTypeId != null">item_type_id = #{itemTypeId},</if>
            <if test="itemTypeName != null">item_type_name = #{itemTypeName},</if>
            <if test="processId != null and processId != ''">process_id = #{processId},</if>
            <if test="processName != null and processName != ''">process_name = #{processName},</if>
            <if test="maxNum != null">max_num = #{maxNum},</if>
            <if test="isConfirm != null">is_confirm = #{isConfirm},</if>
            <if test="isNewProduct != null">is_new_product = #{isNewProduct},</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="qcType != null">qc_type = #{qcType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQcTemplateProcessById" parameterType="Long">
        delete
        from qc_template_process
        where id = #{id}
    </delete>

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