<?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.base.mapper.SamplingInspectionMapper">

    <resultMap type="SamplingInspection" id="SamplingInspectionResult">
        <result property="objId" column="obj_id" />
        <result property="inspectionNo" column="inspection_no" />
        <result property="productCode" column="product_code" />
        <result property="productName" column="product_name" />
        <result property="workOrderNo" column="work_order_no" />
        <result property="batchNo" column="batch_no" />
        <result property="batchQty" column="batch_qty" />
        <result property="samplingPlanCode" column="sampling_plan_code" />
        <result property="sampleSize" column="sample_size" />
        <result property="inspector" column="inspector" />
        <result property="inspectionTime" column="inspection_time" />
        <result property="inspectionResult" column="inspection_result" />
        <result property="qualifiedQty" column="qualified_qty" />
        <result property="unqualifiedQty" column="unqualified_qty" />
        <result property="acceptNumber" column="accept_number" />
        <result property="rejectNumber" column="reject_number" />
        <result property="defectDescription" column="defect_description" />
        <result property="remark" column="remark" />
        <result property="status" column="status" />
        <result property="createdTime" column="created_time" />
        <result property="updatedTime" column="updated_time" />
    </resultMap>

    <sql id="selectSamplingInspectionVo">
        select "obj_id", "inspection_no", "product_code", "product_name", "work_order_no", "batch_no",
               "batch_qty", "sampling_plan_code", "sample_size", "inspector", "inspection_time", "inspection_result",
               "qualified_qty", "unqualified_qty", "accept_number", "reject_number", "defect_description",
               "remark", "status", "created_time", "updated_time"
        from "sampling_inspection"
    </sql>

    <select id="selectSamplingInspectionList" parameterType="SamplingInspection" resultMap="SamplingInspectionResult">
        <include refid="selectSamplingInspectionVo"/>
        <where>
            <if test="inspectionNo != null and inspectionNo != ''"> and "inspection_no" = #{inspectionNo}</if>
            <if test="productCode != null and productCode != ''"> and "product_code" = #{productCode}</if>
            <if test="productName != null and productName != ''"> and "product_name" like concat(concat('%', #{productName}), '%')</if>
            <if test="workOrderNo != null and workOrderNo != ''"> and "work_order_no" = #{workOrderNo}</if>
            <if test="batchNo != null and batchNo != ''"> and "batch_no" = #{batchNo}</if>
            <if test="inspector != null and inspector != ''"> and "inspector" = #{inspector}</if>
            <if test="inspectionResult != null and inspectionResult != ''"> and "inspection_result" = #{inspectionResult}</if>
            <if test="status != null and status != ''"> and "status" = #{status}</if>
        </where>
        order by "obj_id" desc
    </select>

    <select id="selectSamplingInspectionByObjId" parameterType="Long" resultMap="SamplingInspectionResult">
        <include refid="selectSamplingInspectionVo"/>
        where "obj_id" = #{objId}
    </select>

    <insert id="insertSamplingInspection" parameterType="SamplingInspection">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_sampling_inspection.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into "sampling_inspection"
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">"obj_id",</if>
            <if test="inspectionNo != null">"inspection_no",</if>
            <if test="productCode != null">"product_code",</if>
            <if test="productName != null">"product_name",</if>
            <if test="workOrderNo != null">"work_order_no",</if>
            <if test="batchNo != null">"batch_no",</if>
            <if test="batchQty != null">"batch_qty",</if>
            <if test="samplingPlanCode != null">"sampling_plan_code",</if>
            <if test="sampleSize != null">"sample_size",</if>
            <if test="inspector != null">"inspector",</if>
            <if test="inspectionTime != null">"inspection_time",</if>
            <if test="inspectionResult != null">"inspection_result",</if>
            <if test="qualifiedQty != null">"qualified_qty",</if>
            <if test="unqualifiedQty != null">"unqualified_qty",</if>
            <if test="acceptNumber != null">"accept_number",</if>
            <if test="rejectNumber != null">"reject_number",</if>
            <if test="defectDescription != null">"defect_description",</if>
            <if test="remark != null">"remark",</if>
            <if test="status != null">"status",</if>
            <if test="createdTime != null">"created_time",</if>
            <if test="updatedTime != null">"updated_time",</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="inspectionNo != null">#{inspectionNo},</if>
            <if test="productCode != null">#{productCode},</if>
            <if test="productName != null">#{productName},</if>
            <if test="workOrderNo != null">#{workOrderNo},</if>
            <if test="batchNo != null">#{batchNo},</if>
            <if test="batchQty != null">#{batchQty},</if>
            <if test="samplingPlanCode != null">#{samplingPlanCode},</if>
            <if test="sampleSize != null">#{sampleSize},</if>
            <if test="inspector != null">#{inspector},</if>
            <if test="inspectionTime != null">#{inspectionTime},</if>
            <if test="inspectionResult != null">#{inspectionResult},</if>
            <if test="qualifiedQty != null">#{qualifiedQty},</if>
            <if test="unqualifiedQty != null">#{unqualifiedQty},</if>
            <if test="acceptNumber != null">#{acceptNumber},</if>
            <if test="rejectNumber != null">#{rejectNumber},</if>
            <if test="defectDescription != null">#{defectDescription},</if>
            <if test="remark != null">#{remark},</if>
            <if test="status != null">#{status},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
        </trim>
    </insert>

    <update id="updateSamplingInspection" parameterType="SamplingInspection">
        update "sampling_inspection"
        <trim prefix="SET" suffixOverrides=",">
            <if test="inspectionNo != null">"inspection_no" = #{inspectionNo},</if>
            <if test="productCode != null">"product_code" = #{productCode},</if>
            <if test="productName != null">"product_name" = #{productName},</if>
            <if test="workOrderNo != null">"work_order_no" = #{workOrderNo},</if>
            <if test="batchNo != null">"batch_no" = #{batchNo},</if>
            <if test="batchQty != null">"batch_qty" = #{batchQty},</if>
            <if test="samplingPlanCode != null">"sampling_plan_code" = #{samplingPlanCode},</if>
            <if test="sampleSize != null">"sample_size" = #{sampleSize},</if>
            <if test="inspector != null">"inspector" = #{inspector},</if>
            <if test="inspectionTime != null">"inspection_time" = #{inspectionTime},</if>
            <if test="inspectionResult != null">"inspection_result" = #{inspectionResult},</if>
            <if test="qualifiedQty != null">"qualified_qty" = #{qualifiedQty},</if>
            <if test="unqualifiedQty != null">"unqualified_qty" = #{unqualifiedQty},</if>
            <if test="acceptNumber != null">"accept_number" = #{acceptNumber},</if>
            <if test="rejectNumber != null">"reject_number" = #{rejectNumber},</if>
            <if test="defectDescription != null">"defect_description" = #{defectDescription},</if>
            <if test="remark != null">"remark" = #{remark},</if>
            <if test="status != null">"status" = #{status},</if>
            <if test="createdTime != null">"created_time" = #{createdTime},</if>
            <if test="updatedTime != null">"updated_time" = #{updatedTime},</if>
        </trim>
        where "obj_id" = #{objId}
    </update>

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

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