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

    <resultMap type="InspectionStandard" id="InspectionStandardResult">
        <result property="objId" column="obj_id" />
        <result property="standardCode" column="standard_code" />
        <result property="standardName" column="standard_name" />
        <result property="productCode" column="product_code" />
        <result property="productName" column="product_name" />
        <result property="inspectionType" column="inspection_type" />
        <result property="inspectionItems" column="inspection_items" />
        <result property="inspectionMethod" column="inspection_method" />
        <result property="standardValue" column="standard_value" />
        <result property="toleranceRange" column="tolerance_range" />
        <result property="samplingPlanCode" column="sampling_plan_code" />
        <result property="remark" column="remark" />
        <result property="isFlag" column="is_flag" />
        <result property="createdTime" column="created_time" />
        <result property="updatedTime" column="updated_time" />
    </resultMap>

    <sql id="selectInspectionStandardVo">
        select "obj_id", "standard_code", "standard_name", "product_code", "product_name", "inspection_type",
               "inspection_items", "inspection_method", "standard_value", "tolerance_range", "sampling_plan_code",
               "remark", "is_flag", "created_time", "updated_time"
        from "inspection_standard"
    </sql>

    <select id="selectInspectionStandardList" parameterType="InspectionStandard" resultMap="InspectionStandardResult">
        <include refid="selectInspectionStandardVo"/>
        <where>
            <if test="standardCode != null and standardCode != ''"> and "standard_code" = #{standardCode}</if>
            <if test="standardName != null and standardName != ''"> and "standard_name" like concat(concat('%', #{standardName}), '%')</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="inspectionType != null and inspectionType != ''"> and "inspection_type" = #{inspectionType}</if>
            <if test="isFlag != null"> and "is_flag" = #{isFlag}</if>
        </where>
        order by "obj_id" desc
    </select>

    <select id="selectInspectionStandardByObjId" parameterType="Long" resultMap="InspectionStandardResult">
        <include refid="selectInspectionStandardVo"/>
        where "obj_id" = #{objId}
    </select>

    <insert id="insertInspectionStandard" parameterType="InspectionStandard">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_inspection_standard.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into "inspection_standard"
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">"obj_id",</if>
            <if test="standardCode != null">"standard_code",</if>
            <if test="standardName != null">"standard_name",</if>
            <if test="productCode != null">"product_code",</if>
            <if test="productName != null">"product_name",</if>
            <if test="inspectionType != null">"inspection_type",</if>
            <if test="inspectionItems != null">"inspection_items",</if>
            <if test="inspectionMethod != null">"inspection_method",</if>
            <if test="standardValue != null">"standard_value",</if>
            <if test="toleranceRange != null">"tolerance_range",</if>
            <if test="samplingPlanCode != null">"sampling_plan_code",</if>
            <if test="remark != null">"remark",</if>
            <if test="isFlag != null">"is_flag",</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="standardCode != null">#{standardCode},</if>
            <if test="standardName != null">#{standardName},</if>
            <if test="productCode != null">#{productCode},</if>
            <if test="productName != null">#{productName},</if>
            <if test="inspectionType != null">#{inspectionType},</if>
            <if test="inspectionItems != null">#{inspectionItems},</if>
            <if test="inspectionMethod != null">#{inspectionMethod},</if>
            <if test="standardValue != null">#{standardValue},</if>
            <if test="toleranceRange != null">#{toleranceRange},</if>
            <if test="samplingPlanCode != null">#{samplingPlanCode},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
        </trim>
    </insert>

    <update id="updateInspectionStandard" parameterType="InspectionStandard">
        update "inspection_standard"
        <trim prefix="SET" suffixOverrides=",">
            <if test="standardCode != null">"standard_code" = #{standardCode},</if>
            <if test="standardName != null">"standard_name" = #{standardName},</if>
            <if test="productCode != null">"product_code" = #{productCode},</if>
            <if test="productName != null">"product_name" = #{productName},</if>
            <if test="inspectionType != null">"inspection_type" = #{inspectionType},</if>
            <if test="inspectionItems != null">"inspection_items" = #{inspectionItems},</if>
            <if test="inspectionMethod != null">"inspection_method" = #{inspectionMethod},</if>
            <if test="standardValue != null">"standard_value" = #{standardValue},</if>
            <if test="toleranceRange != null">"tolerance_range" = #{toleranceRange},</if>
            <if test="samplingPlanCode != null">"sampling_plan_code" = #{samplingPlanCode},</if>
            <if test="remark != null">"remark" = #{remark},</if>
            <if test="isFlag != null">"is_flag" = #{isFlag},</if>
            <if test="updatedTime != null">"updated_time" = #{updatedTime},</if>
        </trim>
        where "obj_id" = #{objId}
    </update>

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

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