<?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.TLpgGasBottleFilesMapper">
    
    <resultMap type="TLpgGasBottleFiles" id="TLpgGasBottleFilesResult">
        <result property="gasBottleFilesId"    column="f_gas_bottle_files_id"    />
        <result property="regCode"    column="f_reg_code"    />
        <result property="equNo"    column="f_equ_no"    />
        <result property="equType"    column="f_equ_type"    />
        <result property="medium"    column="f_medium"    />
        <result property="makeDate"    column="f_make_date"    />
        <result property="makeInfo"    column="f_make_info"    />
        <result property="selfId"    column="f_self_id"    />
        <result property="pressure"    column="f_pressure"    />
        <result property="volume"    column="f_volume"    />
        <result property="appId"    column="f_app_id"    />
        <result property="qrcode"    column="f_q_rcode"    />
        <result property="buildUser"    column="f_build_user"    />
        <result property="optName"    column="f_opt_name"    />
        <result property="addTime"    column="f_add_time"    />
        <result property="upTime"    column="f_up_time"    />
        <result property="state"    column="f_state"    />
        <result property="upOptName"    column="f_up_opt_name"    />
        <result property="pchkDate"    column="f_p_chk_date"    />
        <result property="nchkDate"    column="f_n_chk_date"    />
        <result property="productDate"    column="f_product_date"    />
        <result property="discardDate"    column="f_discard_date"    />
        <result property="safeJudgeDate"    column="f_safe_judge_date"    />
        <result property="wpressure"    column="f_g_pressure"    />
        <result property="gpressure"    column="f_w_pressure"    />
        <result property="selfWeight"    column="f_self_weight"    />
        <result property="thickness"    column="f_thickness"    />
        <result property="permitNo"    column="f_permit_no"    />
        <result property="valveName"    column="f_valve_name"    />
        <result property="payImage"    column="f_pay_image"    />
        <result property="batchImage"    column="f_batch_image"    />
        <result property="deviceImage"    column="f_device_image"    />
        <result property="checkImage"    column="f_check_image"    />
        <result property="equNoImage"    column="f_equ_no_image"    />
        <result property="selfIdImage"    column="f_self_id_image"    />
        <result property="botImage"    column="f_bot_image"    />
        <result property="botSpecName"    column="f_bot_spec_name"    />
        <result property="bottleType"    column="f_bottle_type"    />
        <result property="inspectedTimes"    column="f_inspected_times"    />
        <result property="isSpecialized"    column="f_is_specialized"    />
        <result property="valveManuFacturer"    column="f_valve_manu_facturer"    />
        <result property="inspectionLabel"    column="f_inspection_label"    />
        <result property="thirdPartyLabel"    column="f_third_party_label"    />
        <result property="holeCode"    column="f_hole_code"    />
        <result property="bottleStorageType"    column="f_bottle_storage_type"    />
        <result property="rowVersion"    column="f_row_version"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterpriseName"    />
    </resultMap>

    <sql id="selectTLpgGasBottleFilesVo">
        select files.f_gas_bottle_files_id, files.f_reg_code, files.f_equ_no, files.f_equ_type, files.f_medium, files.f_make_date, files.f_make_info,
               files.f_self_id,files.f_pressure, files.f_volume, files.f_app_id, files.f_q_rcode,files.f_build_user,files.f_p_chk_date, files.f_n_chk_date,
               files.f_product_date, files.f_discard_date, files.f_safe_judge_date, files.f_g_pressure, files.f_w_pressure, files.f_self_weight,
               files.f_thickness, files.f_permit_no, files.f_valve_name, files.f_pay_image, files.f_batch_image, files.f_device_image, files.f_check_image,
               files.f_equ_no_image, files.f_self_id_image, files.f_bot_image, files.f_bot_spec_name, files.f_bottle_type, files.f_inspected_times,
               ( CASE files.f_is_specialized WHEN '1' THEN '专用' WHEN '2' THEN '托管' ELSE '-' END ) AS f_is_specialized,
                files.f_valve_manu_facturer, files.f_inspection_label, files.f_third_party_label, files.f_hole_code, files.f_bottle_storage_type,
               ( CASE files.f_state WHEN '1' THEN '新增' WHEN '2' THEN '修改' WHEN '-1' THEN '删除' ELSE '-' END ) AS f_state,
                files.f_opt_name, files.f_add_time, files.f_up_time, files.f_up_opt_name, files.f_row_version,files.enterprise_id,
                enterprise.enterprise_name as enterpriseName
        from t_lpg_gas_bottle_files files
        left join t_enterprise_info enterprise on files.enterprise_id = enterprise.enterprise_id
    </sql>

    <sql id="exportTLpgGasBottleFilesVo">
        select files.f_gas_bottle_files_id, files.f_reg_code, files.f_equ_no, files.f_equ_type, files.f_medium, files.f_make_date,
               files.f_make_info, files.f_self_id,files.f_pressure, files.f_volume, files.f_app_id, files.f_q_rcode,files.f_build_user,
               files.f_p_chk_date, files.f_n_chk_date, files.f_product_date, files.f_discard_date, files.f_safe_judge_date,
               files.f_g_pressure, files.f_w_pressure, files.f_self_weight, files.f_thickness, files.f_permit_no, files.f_valve_name,
               files.f_pay_image, files.f_batch_image, files.f_device_image, files.f_check_image, files.f_equ_no_image,
               files.f_self_id_image, files.f_bot_image, files.f_bot_spec_name, files.f_bottle_type, files.f_inspected_times,
               files.f_is_specialized,files.f_valve_manu_facturer, files.f_inspection_label, files.f_third_party_label,
               files.f_hole_code, files.f_bottle_storage_type,files.f_state,files.f_opt_name, files.f_add_time, files.f_up_time,
               files.f_up_opt_name, files.f_row_version,enterprise.enterprise_name as enterpriseName
        from t_lpg_gas_bottle_files files
        left join t_enterprise_info enterprise on files.enterprise_id = enterprise.enterprise_id
    </sql>

    <select id="selectTLpgGasBottleFilesList" parameterType="TLpgGasBottleFiles" resultMap="TLpgGasBottleFilesResult">
        <include refid="selectTLpgGasBottleFilesVo"/>
        <where>  
            <if test="pchkDate != null "> and f_p_chk_date = #{pchkDate}</if>
            <if test="nchkDate != null "> and f_n_chk_date = #{nchkDate}</if>
            <if test="productDate != null "> and f_product_date = #{productDate}</if>
            <if test="discardDate != null "> and f_discard_date = #{discardDate}</if>
            <if test="safeJudgeDate != null "> and f_safe_judge_date = #{safeJudgeDate}</if>
            <if test="gpressure != null "> and f_g_pressure = #{gpressure}</if>
            <if test="wpressure != null "> and f_w_pressure = #{wpressure}</if>
            <if test="selfWeight != null "> and f_self_weight = #{selfWeight}</if>
            <if test="permitNo != null  and fPermitNo != ''"> and f_permit_no = #{permitNo}</if>
            <if test="valveName != null "> and f_valve_name like concat('%', #{valveName}, '%')</if>
            <if test="qrcode != null and qrcode != ''"> and f_q_rcode like concat('%', #{qrcode}, '%')</if>
            <if test="state != null "> and f_state = #{state}</if>
        </where>
    </select>

    <select id="exportTLpgGasBottleFilesList" parameterType="TLpgGasBottleFiles" resultMap="TLpgGasBottleFilesResult">
        <include refid="exportTLpgGasBottleFilesVo"/>
        <where>
            <if test="pchkDate != null "> and f_p_chk_date = #{pchkDate}</if>
            <if test="nchkDate != null "> and f_n_chk_date = #{nchkDate}</if>
            <if test="productDate != null "> and f_product_date = #{productDate}</if>
            <if test="discardDate != null "> and f_discard_date = #{discardDate}</if>
            <if test="safeJudgeDate != null "> and f_safe_judge_date = #{safeJudgeDate}</if>
            <if test="gpressure != null "> and f_g_pressure = #{gpressure}</if>
            <if test="wpressure != null "> and f_w_pressure = #{wpressure}</if>
            <if test="selfWeight != null "> and f_self_weight = #{selfWeight}</if>
            <if test="permitNo != null  and fPermitNo != ''"> and f_permit_no = #{permitNo}</if>
            <if test="valveName != null "> and f_valve_name like concat('%', #{valveName}, '%')</if>
            <if test="qrcode != null and qrcode != ''"> and f_q_rcode like concat('%', #{qrcode}, '%')</if>
            <if test="state != null "> and f_state = #{state}</if>
        </where>
    </select>
    <select id="queryAllByFQRcodeList" resultMap="TLpgGasBottleFilesResult">
        <include refid="selectTLpgGasBottleFilesVo"/>
        where f_q_rcode in
            <foreach collection="codeList" close=")" index="i" item="item" open="(" separator=",">
                #{item}
            </foreach>
    </select>
    <select id="queryAllByQrcodeAndEnterpriseList" resultMap="TLpgGasBottleFilesResult">

        <include refid="selectTLpgGasBottleFilesVo"/>
        where files.enterprise_id = #{enterpriseId} and files.f_q_rcode in
        <foreach collection="list" close=")" index="i" item="item" open="(" separator=",">
            #{item}
        </foreach>
    </select>
    
    <select id="selectTLpgGasBottleFilesById" parameterType="Long" resultMap="TLpgGasBottleFilesResult">
        <include refid="selectTLpgGasBottleFilesVo"/>
        where f_gas_bottle_files_id = #{fGasBottleFilesId}
    </select>
    <update id="updateBatch" parameterType="list">

        <foreach collection="list" item="item"  index="index" separator=";">
            UPDATE t_lpg_gas_bottle_files
            <set>
                f_reg_code = #{item.regCode,jdbcType=VARCHAR},
                f_equ_no = #{item.equNo,jdbcType=VARCHAR},
                f_equ_type = #{item.equType,jdbcType=VARCHAR},
                f_medium = #{item.medium,jdbcType=VARCHAR},
                f_make_date = #{item.makeDate},
                f_make_info = #{item.makeInfo},
                f_self_id = #{item.selfId},
                f_pressure = #{item.pressure},
                f_volume = #{item.volume},
                f_app_id = #{item.appId},
                f_build_user = #{item.buildUser},
                f_p_chk_date = #{item.pchkDate},
                f_n_chk_date = #{item.nchkDate},
                f_product_date = #{item.productDate},
                f_discard_date = #{item.discardDate},
                f_safe_judge_date = #{item.safeJudgeDate},
                f_g_pressure = #{item.gpressure},
                f_w_pressure = #{item.wpressure},
                f_self_weight = #{item.selfWeight},

                f_thickness = #{item.thickness},
                f_permit_no = #{item.permitNo},
                f_valve_name = #{item.valveName},
                f_bot_spec_name = #{item.botSpecName},
                f_bottle_type = #{item.bottleType},
                f_inspected_times = #{item.inspectedTimes},

                f_is_specialized = #{item.isSpecialized},
                f_valve_manu_facturer = #{item.valveManuFacturer},
                f_inspection_label = #{item.inspectionLabel},
                f_third_party_label = #{item.thirdPartyLabel},
                f_hole_code = #{item.holeCode},
                f_bottle_storage_type = #{item.bottleStorageType},

                f_pay_image = #{item.payImage},
                f_batch_image = #{item.batchImage},
                f_device_image = #{item.deviceImage},
                f_check_image = #{item.checkImage},
                f_bot_image = #{item.botImage},
            </set>
            WHERE f_q_rcode = #{item.qrcode} and enterprise_id = #{item.enterpriseId}
        </foreach>
    </update>
    <insert id="insertBatch" parameterType="list">
        insert into t_lpg_gas_bottle_files (f_reg_code, f_equ_no,f_equ_type,f_medium,f_make_date,f_make_info,
        f_self_id,f_pressure,f_volume,f_app_id,f_q_rcode,f_build_user,f_p_chk_date,f_n_chk_date,f_product_date,
        f_discard_date,f_safe_judge_date,f_g_pressure,f_w_pressure,f_self_weight,f_thickness,f_permit_no,
        f_valve_name,f_bot_spec_name,f_bottle_type,f_inspected_times,f_is_specialized,f_valve_manu_facturer,
        f_inspection_label, f_third_party_label,f_hole_code,f_bottle_storage_type,f_state,f_opt_name,f_add_time,
        f_up_time,f_up_opt_name,f_row_version,enterprise_id,f_pay_image,f_batch_image,f_device_image,f_check_image,f_bot_image)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.regCode,jdbcType=VARCHAR}, #{item.equNo}, #{item.equType,jdbcType=VARCHAR},
            #{item.medium,jdbcType=VARCHAR}, #{item.makeDate,jdbcType=VARCHAR}, #{item.makeInfo},
            #{item.selfId},#{item.pressure},#{item.volume},#{item.appId},
            #{item.qrcode},#{item.buildUser},#{item.pchkDate},#{item.nchkDate},#{item.productDate},
            #{item.discardDate,jdbcType=VARCHAR}, #{item.safeJudgeDate}, #{item.gpressure,jdbcType=VARCHAR},
            #{item.wpressure,jdbcType=VARCHAR}, #{item.selfWeight,jdbcType=VARCHAR}, #{item.thickness},
            #{item.permitNo},#{item.valveName},#{item.botSpecName},#{item.bottleType},
            #{item.inspectedTimes},#{item.isSpecialized},#{item.valveManuFacturer},#{item.inspectionLabel},#{item.thirdPartyLabel},
            #{item.holeCode,jdbcType=VARCHAR}, #{item.bottleStorageType}, #{item.state,jdbcType=VARCHAR},
            #{item.optName,jdbcType=VARCHAR}, #{item.addTime}, #{item.upTime},
            #{item.upOptName},#{item.rowVersion},#{item.enterpriseId},#{item.payImage},#{item.batchImage},#{item.deviceImage},
             #{item.checkImage},#{item.botImage})
        </foreach>

    </insert>

    <insert id="insertTLpgGasBottleFiles" parameterType="TLpgGasBottleFiles" useGeneratedKeys="true" keyProperty="fGasBottleFilesId">
        insert into t_lpg_gas_bottle_files
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="regCode != null">f_reg_code,</if>
            <if test="equNo != null">f_equ_no,</if>
            <if test="equType != null">f_equ_type,</if>
            <if test="medium != null">f_medium,</if>
            <if test="makeDate != null">f_make_date,</if>
            <if test="makeInfo != null">f_make_info,</if>
            <if test="selfId != null">f_self_id,</if>

            <if test="pressure != null">f_pressure,</if>
            <if test="volume != null">f_volume,</if>
            <if test="appId != null">f_app_id,</if>
            <if test="qrcode != null">f_q_rcode,</if>
            <if test="buildUser != null">f_build_user,</if>
            <if test="pchkDate != null">f_p_chk_date,</if>
            <if test="nchkDate != null">f_n_chk_date,</if>
            <if test="productDate != null">f_product_date,</if>
            <if test="discardDate != null">f_discard_date,</if>
            <if test="safeJudgeDate != null">f_safe_judge_date,</if>
            <if test="gpressure != null">f_g_pressure,</if>
            <if test="wpressure != null">f_w_pressure,</if>
            <if test="selfWeight != null">f_self_weight,</if>
            <if test="thickness != null">f_thickness,</if>
            <if test="permitNo != null">f_permit_no,</if>
            <if test="valveName != null">f_valve_name,</if>
            <if test="payImage != null">f_pay_image,</if>
            <if test="batchImage != null">f_batch_image,</if>
            <if test="deviceImage != null">f_device_image,</if>
            <if test="checkImage != null">f_check_image,</if>
            <if test="equNoImage != null">f_equ_no_image,</if>
            <if test="selfIdImage != null">f_self_id_image,</if>
            <if test="botImage != null">f_bot_image,</if>
            <if test="botSpecName != null">f_bot_spec_name,</if>
            <if test="bottleType != null">f_bottle_type,</if>
            <if test="inspectedTimes != null">f_inspected_times,</if>
            <if test="isSpecialized != null">f_is_specialized,</if>
            <if test="valveManuFacturer != null">f_valve_manu_facturer,</if>
            <if test="inspectionLabel != null">f_inspection_label,</if>
            <if test="thirdPartyLabel != null">f_third_party_label,</if>
            <if test="holeCode != null">f_hole_code,</if>
            <if test="bottleStorageType != null">f_bottle_storage_type,</if>
            <if test="state != null">f_state,</if>
            <if test="optName != null">f_opt_name,</if>
            <if test="addTime != null">f_add_time,</if>
            <if test="upTime != null">f_up_time,</if>
            <if test="upOptName != null">f_up_opt_name,</if>
            <if test="rowVersion != null">f_row_version,</if>
            <if test="enterpriseId != null">enterprise_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="regCode != null">#{regCode},</if>
            <if test="equNo != null">#{equNo},</if>
            <if test="equType != null">#{equType},</if>
            <if test="medium != null">#{medium},</if>
            <if test="makeDate != null">#{makeDate},</if>
            <if test="makeInfo != null">#{makeInfo},</if>
            <if test="selfId != null">#{selfId},</if>

            <if test="pressure != null">#{pressure},</if>
            <if test="volume != null">#{volume},</if>
            <if test="appId != null">#{appId},</if>
            <if test="qrcode != null">#{qrcode},</if>
            <if test="buildUser != null">#{buildUser},</if>
            <if test="pchkDate != null">#{pchkDate},</if>
            <if test="nchkDate != null">#{nchkDate},</if>
            <if test="productDate != null">#{productDate},</if>
            <if test="discardDate != null">#{discardDate},</if>
            <if test="safeJudgeDate != null">#{safeJudgeDate},</if>
            <if test="gpressure != null">#{gpressure},</if>
            <if test="wpressure != null">#{wpressure},</if>
            <if test="selfWeight != null">#{selfWeight},</if>
            <if test="fThickness != null">#{fThickness},</if>
            <if test="permitNo != null">#{permitNo},</if>
            <if test="valveName != null">#{valveName},</if>
            <if test="payImage != null">#{payImage},</if>
            <if test="batchImage != null">#{batchImage},</if>
            <if test="deviceImage != null">#{deviceImage},</if>
            <if test="checkImage != null">#{checkImage},</if>
            <if test="equNoImage != null">#{equNoImage},</if>
            <if test="selfIdImage != null">#{selfIdImage},</if>
            <if test="botImage != null">#{botImage},</if>
            <if test="botSpecName != null">#{botSpecName},</if>
            <if test="bottleType != null">#{bottleType},</if>
            <if test="inspectedTimes != null">#{inspectedTimes},</if>
            <if test="isSpecialized != null">#{isSpecialized},</if>
            <if test="valveManuFacturer != null">#{valveManuFacturer},</if>
            <if test="inspectionLabel != null">#{inspectionLabel},</if>
            <if test="thirdPartyLabel != null">#{thirdPartyLabel},</if>
            <if test="holeCode != null">#{holeCode},</if>
            <if test="bottleStorageType != null">#{bottleStorageType},</if>
            <if test="state != null">#{state},</if>
            <if test="optName != null">#{optName},</if>
            <if test="addTime != null">#{addTime},</if>
            <if test="upTime != null">#{upTime},</if>

            <if test="upOptName != null">#{upOptName},</if>
            <if test="rowVersion != null">#{rowVersion},</if>
            <if test="enterpriseId != null">#{enterpriseId},</if>
         </trim>
    </insert>

    <update id="updateTLpgGasBottleFiles" parameterType="TLpgGasBottleFiles">
        update t_lpg_gas_bottle_files
        <trim prefix="SET" suffixOverrides=",">
            <if test="regCode != null">f_reg_code = #{regCode},</if>
            <if test="equNo != null">f_equ_no = #{equNo},</if>
            <if test="equType != null">f_equ_type = #{equType},</if>
            <if test="medium != null">f_medium = #{medium},</if>
            <if test="makeDate != null">f_make_date = #{makeDate},</if>
            <if test="makeInfo != null">f_make_info = #{makeInfo},</if>
            <if test="selfId != null">f_self_id = #{selfId},</if>

            <if test="pressure != null">f_pressure = #{pressure},</if>
            <if test="volume != null">f_volume = #{volume},</if>
            <if test="appId != null">f_app_id = #{appId},</if>
            <if test="qrcode != null">f_q_rcode = #{qrcode},</if>
            <if test="buildUser != null">f_build_user = #{buildUser},</if>
            <if test="pchkDate != null">f_p_chk_date = #{pchkDate},</if>
            <if test="nchkDate != null">f_n_chk_date = #{nchkDate},</if>
            <if test="productDate != null">f_product_date = #{productDate},</if>
            <if test="discardDate != null">f_discard_date = #{discardDate},</if>
            <if test="safeJudgeDate != null">f_safe_judge_date = #{safeJudgeDate},</if>
            <if test="gpressure != null">f_g_pressure = #{gpressure},</if>
            <if test="wpressure != null">f_w_pressure = #{wpressure},</if>
            <if test="selfWeight != null">f_self_weight = #{selfWeight},</if>
            <if test="thickness != null">f_thickness = #{thickness},</if>
            <if test="permitNo != null">f_permit_no = #{permitNo},</if>
            <if test="valveName != null">f_valve_name = #{valveName},</if>
            <if test="payImage != null">f_pay_image = #{payImage},</if>
            <if test="batchImage != null">f_batch_image = #{batchImage},</if>
            <if test="deviceImage != null">f_device_image = #{deviceImage},</if>
            <if test="checkImage != null">f_check_image = #{checkImage},</if>
            <if test="equNoImage != null">f_equ_no_image = #{equNoImage},</if>
            <if test="selfIdImage != null">f_self_id_image = #{selfIdImage},</if>
            <if test="botImage != null">f_bot_image = #{botImage},</if>
            <if test="botSpecName != null">f_bot_spec_name = #{botSpecName},</if>
            <if test="bottleType != null">f_bottle_type = #{bottleType},</if>
            <if test="inspectedTimes != null">f_inspected_times = #{inspectedTimes},</if>
            <if test="isSpecialized != null">f_is_specialized = #{isSpecialized},</if>
            <if test="valveManuFacturer != null">f_valve_manu_facturer = #{valveManuFacturer},</if>
            <if test="inspectionLabel != null">f_inspection_label = #{inspectionLabel},</if>
            <if test="thirdPartyLabel != null">f_third_party_label = #{thirdPartyLabel},</if>
            <if test="holeCode != null">f_hole_code = #{holeCode},</if>
            <if test="bottleStorageType != null">f_bottle_storage_type = #{bottleStorageType},</if>
            <if test="state != null">f_state = #{state},</if>
            <if test="optName != null">f_opt_name = #{optName},</if>
            <if test="addTime != null">f_add_time = #{addTime},</if>
            <if test="upTime != null">f_up_time = #{upTime},</if>
            <if test="upOptName != null">f_up_opt_name = #{upOptName},</if>
            <if test="rowVersion != null">f_row_version = #{rowVersion},</if>
            <if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
        </trim>
        where f_gas_bottle_files_id = #{fGasBottleFilesId}
    </update>

    <delete id="deleteTLpgGasBottleFilesById" parameterType="Long">
        delete from t_lpg_gas_bottle_files where f_gas_bottle_files_id = #{fGasBottleFilesId}
    </delete>

    <delete id="deleteTLpgGasBottleFilesByIds" parameterType="String">
        delete from t_lpg_gas_bottle_files where f_gas_bottle_files_id in 
        <foreach item="fGasBottleFilesId" collection="array" open="(" separator="," close=")">
            #{fGasBottleFilesId}
        </foreach>
    </delete>
</mapper>