<?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.aucma.report.mapper.ReportQualityInspectionMapper">

    <resultMap type="ReportQualityInspection" id="ReportQualityInspectionResult">
        <result property="objId" column="obj_id"/>
        <result property="barCode" column="bar_code"/>
        <result property="materialName" column="material_name"/>
        <result property="processCode" column="process_code"/>
        <result property="testItemCode" column="test_item_code"/>
        <result property="qualityDefectCode" column="quality_defect_code"/>
        <result property="qualityDefectName" column="quality_defect_name"/>
        <result property="treatmentMeasure" column="treatment_measure"/>
        <result property="processResult" column="process_result"/>
        <result property="isLowerLine" column="is_lower_line"/>
        <result property="groupCode" column="group_code"/>
        <result property="inspectorCode" column="inspector_code"/>
        <result property="inspectorTime" column="inspector_time"/>
        <result property="reworkNumber" column="rework_number"/>
        <result property="finishTime" column="finish_time"/>
        <result property="isFlag" column="is_flag"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="updatedTime" column="updated_time"/>
        <result property="stationCode" column="STATION_CODE"/>
        <result property="submitQualtyId" column="SUBMINT_QUALTY_ID"/>
    </resultMap>

    <sql id="selectReportQualityInspectionVo">
        select obj_id,
               bar_code,
               material_name,
               process_code,
               test_item_code,
               quality_defect_code,
               quality_defect_name,
               treatment_measure,
               process_result,
               is_lower_line,
               group_code,
               inspector_code,
               inspector_time,
               rework_number,
               finish_time,
               is_flag,
               updated_by,
               updated_time
        from report_quality_inspection
    </sql>

    <select id="selectReportQualityInspectionList" parameterType="ReportQualityInspection"
            resultMap="ReportQualityInspectionResult">
        <include refid="selectReportQualityInspectionVo"/>
        <where>
            <if test="barCode != null  and barCode != ''">and bar_code = #{barCode}</if>
            <if test="materialName != null  and materialName != ''">and material_name like concat(concat('%',
                #{materialName}), '%')
            </if>
            <if test="processCode != null  and processCode != ''">and process_code = #{processCode}</if>
            <if test="testItemCode != null  and testItemCode != ''">and test_item_code = #{testItemCode}</if>
            <if test="qualityDefectCode != null  and qualityDefectCode != ''">and quality_defect_code =
                #{qualityDefectCode}
            </if>
            <if test="qualityDefectName != null  and qualityDefectName != ''">and quality_defect_name like
                concat(concat('%', #{qualityDefectName}), '%')
            </if>
            <if test="treatmentMeasure != null  and treatmentMeasure != ''">and treatment_measure =
                #{treatmentMeasure}
            </if>
            <if test="processResult != null  and processResult != ''">and process_result = #{processResult}</if>
            <if test="isLowerLine != null  and isLowerLine != ''">and is_lower_line = #{isLowerLine}</if>
            <if test="groupCode != null  and groupCode != ''">and group_code = #{groupCode}</if>
            <if test="inspectorCode != null  and inspectorCode != ''">and inspector_code = #{inspectorCode}</if>
            <if test="inspectorTime != null ">and inspector_time = #{inspectorTime}</if>
            <if test="reworkNumber != null ">and rework_number = #{reworkNumber}</if>
            <if test="finishTime != null ">and finish_time = #{finishTime}</if>
            <if test="isFlag != null ">and is_flag = #{isFlag}</if>
            <if test="updatedBy != null  and updatedBy != ''">and updated_by = #{updatedBy}</if>
            <if test="updatedTime != null ">and updated_time = #{updatedTime}</if>
        </where>
    </select>

    <select id="selectReportQualityInspectionByObjId" parameterType="Long" resultMap="ReportQualityInspectionResult">
        <include refid="selectReportQualityInspectionVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertReportQualityInspection" parameterType="ReportQualityInspection">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_report_quality_inspection.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into report_quality_inspection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">obj_id,</if>
            <if test="barCode != null">bar_code,</if>
            <if test="materialName != null">material_name,</if>
            <if test="processCode != null">process_code,</if>
            <if test="testItemCode != null">test_item_code,</if>
            <if test="qualityDefectCode != null">quality_defect_code,</if>
            <if test="qualityDefectName != null">quality_defect_name,</if>
            <if test="treatmentMeasure != null">treatment_measure,</if>
            <if test="processResult != null">process_result,</if>
            <if test="isLowerLine != null">is_lower_line,</if>
            <if test="groupCode != null">group_code,</if>
            <if test="inspectorCode != null">inspector_code,</if>
            <if test="inspectorTime != null">inspector_time,</if>
            <if test="reworkNumber != null">rework_number,</if>
            <if test="finishTime != null">finish_time,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedTime != null">updated_time,</if>
            <if test="updatedTime != null">updated_time,</if>
            <if test="stationCode != null">STATION_CODE,</if>
            <if test="submitQualtyId != null">SUBMINT_QUALTY_ID,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="barCode != null">#{barCode},</if>
            <if test="materialName != null">#{materialName},</if>
            <if test="processCode != null">#{processCode},</if>
            <if test="testItemCode != null">#{testItemCode},</if>
            <if test="qualityDefectCode != null">#{qualityDefectCode},</if>
            <if test="qualityDefectName != null">#{qualityDefectName},</if>
            <if test="treatmentMeasure != null">#{treatmentMeasure},</if>
            <if test="processResult != null">#{processResult},</if>
            <if test="isLowerLine != null">#{isLowerLine},</if>
            <if test="groupCode != null">#{groupCode},</if>
            <if test="inspectorCode != null">#{inspectorCode},</if>
            <if test="inspectorTime != null">#{inspectorTime},</if>
            <if test="reworkNumber != null">#{reworkNumber},</if>
            <if test="finishTime != null">#{finishTime},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
            <if test="stationCode != null">#{stationCode},</if>
            <if test="submitQualtyId != null">#{submitQualtyId},</if>
        </trim>
    </insert>

    <update id="updateReportQualityInspection" parameterType="ReportQualityInspection">
        update report_quality_inspection
        <trim prefix="SET" suffixOverrides=",">
            <if test="barCode != null">bar_code = #{barCode},</if>
            <if test="materialName != null">material_name = #{materialName},</if>
            <if test="processCode != null">process_code = #{processCode},</if>
            <if test="testItemCode != null">test_item_code = #{testItemCode},</if>
            <if test="qualityDefectCode != null">quality_defect_code = #{qualityDefectCode},</if>
            <if test="qualityDefectName != null">quality_defect_name = #{qualityDefectName},</if>
            <if test="treatmentMeasure != null">treatment_measure = #{treatmentMeasure},</if>
            <if test="processResult != null">process_result = #{processResult},</if>
            <if test="isLowerLine != null">is_lower_line = #{isLowerLine},</if>
            <if test="groupCode != null">group_code = #{groupCode},</if>
            <if test="inspectorCode != null">inspector_code = #{inspectorCode},</if>
            <if test="inspectorTime != null">inspector_time = #{inspectorTime},</if>
            <if test="reworkNumber != null">rework_number = #{reworkNumber},</if>
            <if test="finishTime != null">finish_time = #{finishTime},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteReportQualityInspectionByObjId" parameterType="Long">
        delete
        from report_quality_inspection
        where obj_id = #{objId}
    </delete>

    <delete id="deleteReportQualityInspectionByObjIds" parameterType="String">
        delete from report_quality_inspection where obj_id in
        <foreach item="objId" collection="array" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </delete>



</mapper>