<?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.zehong.system.mapper.ProductStandardInspectionMapper">

    <resultMap type="ProductStandardInspection" id="ProductStandardInspectionResult">
        <result property="productStandardInspectionId"    column="f_product_standard_inspection_id"    />
        <result property="outStoreOrderNumber"    column="f_out_store_order_number"    />
        <result property="productStandardInspectionNumber"    column="f_product_standard_inspection_number"    />
        <result property="confirmQualityInspector"    column="f_confirm_quality_inspector"    />
        <result property="remarks"    column="f_remarks"    />
        <result property="status"    column="f_status"    />
        <result property="createBy"    column="f_create_by"    />
        <result property="inspectionDep"    column="f_inspection_dep"    />
        <result property="createTime"    column="f_create_time"    />
        <result property="deleteFlag"    column="f_delete_flag"    />
        <result property="materialName"    column="f_material_name"    />
        <result property="materialCode"    column="f_material_code"    />
        <result property="specification"    column="f_specification"    />
        <result property="issuedNum"    column="f_issued_num"    />
        <result property="quantity"    column="f_quantity"    />
        <result property="qualifiedNum"    column="f_qualified_num"    />
        <result property="unQualifiedNum"    column="f_un_qualified_num"    />
        <result property="agingDuration"    column="f_aging_duration"    />
        <result property="calibrationGas"    column="f_calibration_gas"    />
        <result property="alarmValue"    column="f_alarm_value"    />
        <result property="range"    column="f_range"    />
        <result property="readingMode" column="f_reading_mode"/>
        <result property="plateType" column="f_plate_type"/>
    </resultMap>

    <sql id="selectProductStandardInspectionVo">
        select f_product_standard_inspection_id, f_out_store_order_number, f_product_standard_inspection_number,
               f_confirm_quality_inspector, f_remarks, f_status, f_create_by, f_inspection_dep, f_create_time,
               f_delete_flag, f_material_name, f_material_code, f_specification, f_issued_num, f_quantity,
               f_qualified_num, f_un_qualified_num, f_aging_duration, f_calibration_gas, f_alarm_value, f_range ,
               f_reading_mode,f_plate_type
        from t_product_standard_inspection
    </sql>

    <sql id="exportProductStandardInspectionVo">
        select f_product_standard_inspection_id, f_out_store_order_number, f_product_standard_inspection_number,
               f_confirm_quality_inspector, f_remarks, f_status, f_create_by, f_inspection_dep, f_create_time,
               f_delete_flag, f_material_name, f_material_code, f_specification, f_issued_num, f_quantity,
               f_qualified_num, f_un_qualified_num, f_aging_duration, f_calibration_gas, f_alarm_value, f_range ,
               f_reading_mode,
            case when  f_plate_type = '1' then '主体' else '主板' end as f_plate_type
        from t_product_standard_inspection
    </sql>
    <select id="selectDuringStandardInspection" resultMap="ProductStandardInspectionResult">
        <include refid="selectProductStandardInspectionVo"/>
        where f_status = 'DURING_STANDARD_INSPECTION'
    </select>
    <select id="exportExcel" parameterType="ProductStandardInspection" resultMap="ProductStandardInspectionResult">
        <include refid="exportProductStandardInspectionVo"/>
        <if test="outStoreOrderNumber != null  and outStoreOrderNumber != ''"> and f_out_store_order_number = #{outStoreOrderNumber}</if>
            <if test="productStandardInspectionNumber != null  and productStandardInspectionNumber != ''"> and f_product_standard_inspection_number = #{productStandardInspectionNumber}</if>
    </select>
    <select id="selectProductStandardInspectionList" parameterType="ProductStandardInspection" resultMap="ProductStandardInspectionResult">
        <include refid="selectProductStandardInspectionVo"/>
        <where>
            <if test="outStoreOrderNumber != null  and outStoreOrderNumber != ''"> and f_out_store_order_number = #{outStoreOrderNumber}</if>
            <if test="productStandardInspectionNumber != null  and productStandardInspectionNumber != ''"> and f_product_standard_inspection_number = #{productStandardInspectionNumber}</if>
            <if test="confirmQualityInspector != null  and confirmQualityInspector != ''"> and f_confirm_quality_inspector = #{confirmQualityInspector}</if>
            <if test="remarks != null  and remarks != ''"> and f_remarks = #{remarks}</if>
            <if test="status != null  and status != ''"> and f_status = #{status}</if>
            <if test="createBy != null  and createBy != ''"> and f_create_by = #{createBy}</if>
            <if test="inspectionDep != null  and inspectionDep != ''"> and f_inspection_dep = #{inspectionDep}</if>
            <if test="createTime != null "> and f_create_time = #{createTime}</if>
            <if test="deleteFlag != null "> and f_delete_flag = #{deleteFlag}</if>
            <if test="materialName != null  and materialName != ''"> and f_material_name like concat('%', #{materialName}, '%')</if>
            <if test="materialCode != null  and materialCode != ''"> and f_material_code = #{materialCode}</if>
            <if test="specification != null  and specification != ''"> and f_specification = #{specification}</if>
            <if test="issuedNum != null "> and f_issued_num = #{issuedNum}</if>
            <if test="quantity != null "> and f_quantity = #{quantity}</if>
            <if test="qualifiedNum != null "> and f_qualified_num = #{qualifiedNum}</if>
            <if test="unQualifiedNum != null "> and f_un_qualified_num = #{unQualifiedNum}</if>
            <if test="agingDuration != null  and agingDuration != ''"> and f_aging_duration = #{agingDuration}</if>
            <if test="calibrationGas != null  and calibrationGas != ''"> and f_calibration_gas = #{calibrationGas}</if>
            <if test="alarmValue != null  and alarmValue != ''"> and f_alarm_value = #{alarmValue}</if>
            <if test="range != null  and range != ''"> and f_range = #{range}</if>
             <if test="readingMode != null  and readingMode != ''"> and f_reading_mode = #{readingMode}</if>
        </where>
    </select>

    <select id="selectProductStandardInspectionById" parameterType="Long" resultMap="ProductStandardInspectionResult">
        <include refid="selectProductStandardInspectionVo"/>
        where f_product_standard_inspection_id = #{productStandardInspectionId}
    </select>
    <select id="selectByProductStandardInspectionNumber" parameterType="string" resultMap="ProductStandardInspectionResult">
        <include refid="selectProductStandardInspectionVo"/>
        where f_product_standard_inspection_number = #{productStandardInspectionNumber}
    </select>
    <select id="selectByNumber" parameterType="string" resultMap="ProductStandardInspectionResult">
        <include refid="selectProductStandardInspectionVo"/>
        where f_product_standard_inspection_number = #{productStandardInspectionNumber}
    </select>

    <insert id="batchInsert" parameterType="list">
        insert into t_product_standard_inspection (f_product_standard_inspection_number, f_out_store_order_number,
        f_confirm_quality_inspector,f_remarks,f_status,f_create_by,f_inspection_dep,
        f_material_name,f_material_code,f_specification,f_issued_num,f_quantity,f_aging_duration,
        f_calibration_gas,f_alarm_value,f_range,f_reading_mode,f_plate_type)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
              #{item.productStandardInspectionNumber}, #{item.outStoreOrderNumber}, #{item.confirmQualityInspector},
              #{item.remarks}, #{item.status}, #{item.createBy}, #{item.inspectionDep}, #{item.materialName},
              #{item.materialCode}, #{item.specification}, #{item.issuedNum}, #{item.quantity}, #{item.agingDuration},
              #{item.calibrationGas}, #{item.alarmValue}, #{item.range}, #{item.readingMode}, #{item.plateType}
            )
        </foreach>
    </insert>
    <insert id="insertProductStandardInspection" parameterType="ProductStandardInspection" useGeneratedKeys="true" keyProperty="productStandardInspectionId">
        insert into t_product_standard_inspection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="outStoreOrderNumber != null">f_out_store_order_number,</if>
            <if test="productStandardInspectionNumber != null and productStandardInspectionNumber != ''">f_product_standard_inspection_number,</if>
            <if test="confirmQualityInspector != null">f_confirm_quality_inspector,</if>
            <if test="remarks != null">f_remarks,</if>
            <if test="status != null">f_status,</if>
            <if test="createBy != null">f_create_by,</if>
            <if test="inspectionDep != null">f_inspection_dep,</if>
            <if test="createTime != null">f_create_time,</if>
            <if test="deleteFlag != null">f_delete_flag,</if>
            <if test="materialName != null">f_material_name,</if>
            <if test="materialCode != null">f_material_code,</if>
            <if test="specification != null">f_specification,</if>
            <if test="issuedNum != null">f_issued_num,</if>
            <if test="quantity != null">f_quantity,</if>
            <if test="qualifiedNum != null">f_qualified_num,</if>
            <if test="unQualifiedNum != null">f_un_qualified_num,</if>
            <if test="agingDuration != null">f_aging_duration,</if>
            <if test="calibrationGas != null">f_calibration_gas,</if>
            <if test="alarmValue != null">f_alarm_value,</if>
            <if test="range != null">f_range,</if>
            <if test="readingMode != null">f_reading_mode,</if>
            <if test="plateType != null">f_plate_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="outStoreOrderNumber != null">#{outStoreOrderNumber},</if>
            <if test="productStandardInspectionNumber != null and productStandardInspectionNumber != ''">#{productStandardInspectionNumber},</if>
            <if test="confirmQualityInspector != null">#{confirmQualityInspector},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="inspectionDep != null">#{inspectionDep},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="deleteFlag != null">#{deleteFlag},</if>
            <if test="materialName != null">#{materialName},</if>
            <if test="materialCode != null">#{materialCode},</if>
            <if test="specification != null">#{specification},</if>
            <if test="issuedNum != null">#{issuedNum},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="qualifiedNum != null">#{qualifiedNum},</if>
            <if test="unQualifiedNum != null">#{unQualifiedNum},</if>
            <if test="agingDuration != null">#{agingDuration},</if>
            <if test="calibrationGas != null">#{calibrationGas},</if>
            <if test="alarmValue != null">#{alarmValue},</if>
            <if test="range != null">#{range},</if>
            <if test="readingMode != null">#{readingMode},</if>
            <if test="plateType != null">#{plateType},</if>
         </trim>
    </insert>

    <update id="updateProductStandardInspection" parameterType="ProductStandardInspection">
        update t_product_standard_inspection
        <trim prefix="SET" suffixOverrides=",">
            <if test="outStoreOrderNumber != null">f_out_store_order_number = #{outStoreOrderNumber},</if>
            <if test="productStandardInspectionNumber != null and productStandardInspectionNumber != ''">f_product_standard_inspection_number = #{productStandardInspectionNumber},</if>
            <if test="confirmQualityInspector != null">f_confirm_quality_inspector = #{confirmQualityInspector},</if>
            <if test="remarks != null">f_remarks = #{remarks},</if>
            <if test="status != null">f_status = #{status},</if>
            <if test="createBy != null">f_create_by = #{createBy},</if>
            <if test="inspectionDep != null">f_inspection_dep = #{inspectionDep},</if>
            <if test="createTime != null">f_create_time = #{createTime},</if>
            <if test="deleteFlag != null">f_delete_flag = #{deleteFlag},</if>
            <if test="materialName != null">f_material_name = #{materialName},</if>
            <if test="materialCode != null">f_material_code = #{materialCode},</if>
            <if test="specification != null">f_specification = #{specification},</if>
            <if test="issuedNum != null">f_issued_num = #{issuedNum},</if>
            <if test="quantity != null">f_quantity = #{quantity},</if>
            <if test="qualifiedNum != null">f_qualified_num = #{qualifiedNum},</if>
            <if test="unQualifiedNum != null">f_un_qualified_num = #{unQualifiedNum},</if>
            <if test="agingDuration != null">f_aging_duration = #{agingDuration},</if>
            <if test="calibrationGas != null">f_calibration_gas = #{calibrationGas},</if>
            <if test="alarmValue != null">f_alarm_value = #{alarmValue},</if>
            <if test="range != null">f_range = #{range},</if>
            <if test="readingMode != null">f_reading_mode = #{readingMode},</if>
            <if test="plateType != null">f_plate_type = #{plateType},</if>
        </trim>
        where f_product_standard_inspection_id = #{productStandardInspectionId}
    </update>

    <delete id="deleteProductStandardInspectionById" parameterType="Long">
        delete from t_product_standard_inspection where f_product_standard_inspection_id = #{productStandardInspectionId}
    </delete>

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