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

    <resultMap type="ProWorkOrderProcessQcindex" id="ProWorkOrderProcessQcindexResult">
        <result property="id" column="id"/>
        <result property="workorderProcessId" column="workorder_process_id"/>
        <result property="qcindexId" column="qcindex_id"/>
        <result property="indexName" column="index_name"/>
        <result property="indexCode" column="index_code"/>
        <result property="indexType" column="index_type"/>
        <result property="qcTool" column="qc_tool"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectProWorkOrderProcessQcindexVo">
        select pwopq.id,
               pwopq.workorder_process_id,
               pwopq.qcindex_id,
               pwopq.remark,
               qi.index_name,
               qi.index_code,
               qi.index_type,
               qi.qc_tool
        from pro_work_order_process_qcindex pwopq
                 left join qc_index qi
                           on qi.index_id = pwopq.qcindex_id
    </sql>

    <select id="selectProWorkOrderProcessQcindexList" parameterType="ProWorkOrderProcessQcindex"
            resultMap="ProWorkOrderProcessQcindexResult">
        <include refid="selectProWorkOrderProcessQcindexVo"/>
        <where>
            <if test="workorderProcessId != null ">and pwopq.workorder_process_id = #{workorderProcessId}</if>
            <if test="qcindexId != null ">and pwopq.qcindex_id = #{qcindexId}</if>
        </where>
    </select>

    <select id="selectProWorkOrderProcessQcindexById" parameterType="Long"
            resultMap="ProWorkOrderProcessQcindexResult">
        <include refid="selectProWorkOrderProcessQcindexVo"/>
        where pwopq.id = #{id}
    </select>
    <select id="selectProWorkOrderProcessQcindexByWorkorderProcessId"
            parameterType="Long" resultMap="ProWorkOrderProcessQcindexResult">
        <include refid="selectProWorkOrderProcessQcindexVo"/>
        where pwopq.workorder_process_id = #{workorderProcessId}
    </select>

    <insert id="insertProWorkOrderProcessQcindex" parameterType="ProWorkOrderProcessQcindex" useGeneratedKeys="true"
            keyProperty="id">
        insert into pro_work_order_process_qcindex
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workorderProcessId != null">workorder_process_id,</if>
            <if test="qcindexId != null">qcindex_id,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workorderProcessId != null">#{workorderProcessId},</if>
            <if test="qcindexId != null">#{qcindexId},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateProWorkOrderProcessQcindex" parameterType="ProWorkOrderProcessQcindex">
        update pro_work_order_process_qcindex
        <trim prefix="SET" suffixOverrides=",">
            <if test="workorderProcessId != null">workorder_process_id = #{workorderProcessId},</if>
            <if test="qcindexId != null">qcindex_id = #{qcindexId},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProWorkOrderProcessQcindexById" parameterType="Long">
        delete
        from pro_work_order_process_qcindex
        where id = #{id}
    </delete>

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