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

    <resultMap type="QcAbnormalInformation" id="QcAbnormalInformationResult">
        <result property="abnormalId"    column="abnormal_id"    />
        <result property="abnormalType"    column="abnormal_type"    />
        <result property="abnormalReason"    column="abnormal_reason"    />
        <result property="remark"    column="remark"    />
        <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="selectQcAbnormalInformationVo">
        select abnormal_id, abnormal_type, abnormal_reason, remark, create_by, create_time, update_by, update_time from qc_abnormal_information
    </sql>

    <select id="selectQcAbnormalInformationList" parameterType="QcAbnormalInformation" resultMap="QcAbnormalInformationResult">
        <include refid="selectQcAbnormalInformationVo"/>
        <where>
            <if test="abnormalType != null  and abnormalType != ''"> and abnormal_type = #{abnormalType}</if>
            <if test="abnormalReason != null  and abnormalReason != ''"> and abnormal_reason = #{abnormalReason}</if>
        </where>
    </select>

    <select id="selectQcAbnormalInformationByAbnormalId" parameterType="Long" resultMap="QcAbnormalInformationResult">
        <include refid="selectQcAbnormalInformationVo"/>
        where abnormal_id = #{abnormalId}
    </select>

    <insert id="insertQcAbnormalInformation" parameterType="QcAbnormalInformation" useGeneratedKeys="true" keyProperty="abnormalId">
        insert into qc_abnormal_information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="abnormalType != null">abnormal_type,</if>
            <if test="abnormalReason != null">abnormal_reason,</if>
            <if test="remark != null">remark,</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="abnormalType != null">#{abnormalType},</if>
            <if test="abnormalReason != null">#{abnormalReason},</if>
            <if test="remark != null">#{remark},</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="updateQcAbnormalInformation" parameterType="QcAbnormalInformation">
        update qc_abnormal_information
        <trim prefix="SET" suffixOverrides=",">
            <if test="abnormalType != null">abnormal_type = #{abnormalType},</if>
            <if test="abnormalReason != null">abnormal_reason = #{abnormalReason},</if>
            <if test="remark != null">remark = #{remark},</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 abnormal_id = #{abnormalId}
    </update>

    <delete id="deleteQcAbnormalInformationByAbnormalId" parameterType="Long">
        delete from qc_abnormal_information where abnormal_id = #{abnormalId}
    </delete>

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