<?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.TLpgAirChargeFilesMapper">
    
    <resultMap type="TLpgAirChargeFiles" id="TLpgAirChargeFilesResult">
        <result property="gasAirChargeId"    column="f_gas_air_charge_id"    />
        <result property="gzId"    column="f_gz_id"    />
        <result property="stationName"    column="f_station_name"    />
        <result property="barCode"    column="f_bar_code"    />
        <result property="vaseCode"    column="f_vase_code"    />
        <result property="scaleNum"    column="f_scale_num"    />
        <result property="fillStatrTime"    column="f_fill_statr_time"    />
        <result property="fillEndTime"    column="f_fill_end_time"    />
        <result property="setWeight"    column="f_set_weight"    />
        <result property="wtNet"    column="f_wt_net"    />
        <result property="setBottleWeight"    column="f_set_bottle_weight"    />
        <result property="bottleWeight"    column="f_bottle_weight"    />
        <result property="wtGross"    column="f_wt_gross"    />
        <result property="oprateName"    column="f_oprate_name"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterpriseName"    />
    </resultMap>

    <sql id="selectTLpgAirChargeFilesVo">
        select files.f_gas_air_charge_id, files.f_gz_id, files.f_station_name, files.f_bar_code, files.f_vase_code, files.f_scale_num,
               files.f_fill_statr_time, files.f_fill_end_time, files.f_set_weight, files.f_wt_net, files.f_set_bottle_weight,
               files.f_bottle_weight, files.f_wt_gross, files.f_oprate_name, info.enterprise_name as enterpriseName
        from t_lpg_air_charge_files files
        left join t_enterprise_info info on files.enterprise_id = info.enterprise_id
    </sql>

    <select id="selectTLpgAirChargeFilesList" parameterType="TLpgAirChargeFiles" resultMap="TLpgAirChargeFilesResult">
        <include refid="selectTLpgAirChargeFilesVo"/>
        <where>  
            <if test="vaseCode != null  and vaseCode != ''"> and f_vase_code like concat('%', #{vaseCode}, '%') </if>
            <if test="barCode != null  and barCode != ''"> and f_bar_code like concat('%', #{barCode}, '%') </if>
        </where>
    </select>
    <select id="queryAllForExport" resultMap="TLpgAirChargeFilesResult">
        <include refid="selectTLpgAirChargeFilesVo"/>
        <where>
            <if test="vaseCode != null  and vaseCode != ''"> and f_vase_code like concat('%', #{vaseCode}, '%') </if>
            <if test="barCode != null  and barCode != ''"> and f_bar_code like concat('%', #{barCode}, '%') </if>
        </where>
        limit 1000
    </select>
    <select id="queryALlByBarcodeAndGizId" resultMap="TLpgAirChargeFilesResult">
        <include refid="selectTLpgAirChargeFilesVo"/>
         WHERE (f_bar_code, f_gz_id) IN
        <foreach collection="list" item="item" separator="," open="(" close=")">
            (#{item.barCode}, #{item.gzId})
        </foreach>
    </select>
    <select id="queryAllByBarCodeLimit2" resultMap="TLpgAirChargeFilesResult">
        <include refid="selectTLpgAirChargeFilesVo"></include>
        where f_bar_code = #{barCode} order by f_fill_end_time desc limit 2
    </select>
    <select id="selectTLpgAirChargeFilesById" parameterType="Long" resultMap="TLpgAirChargeFilesResult">
        <include refid="selectTLpgAirChargeFilesVo"/>
        where f_gas_air_charge_id = #{gasAirChargeId}
    </select>

    <select id="selectTLpgAirChargeFilesTotal" resultType="int">
        SELECT COUNT(*) FROM t_lpg_air_charge_files
    </select>

    <insert id="insertBatch" parameterType="list">

        insert into t_lpg_air_charge_files (f_gz_id, f_station_name, f_bar_code, f_vase_code, f_scale_num,
                                            f_fill_statr_time, f_fill_end_time, f_set_weight, f_wt_net, f_set_bottle_weight,
                                            f_bottle_weight, f_wt_gross, f_oprate_name,enterprise_id)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.gzId}, #{item.stationName,jdbcType=VARCHAR}, #{item.barCode,jdbcType=VARCHAR},
            #{item.vaseCode,jdbcType=VARCHAR}, #{item.scaleNum,jdbcType=VARCHAR}, #{item.fillStatrTime},
            #{item.fillEndTime},
            #{item.setWeight,jdbcType=VARCHAR}, #{item.wtNet,jdbcType=VARCHAR}, #{item.setBottleWeight,jdbcType=VARCHAR},
            #{item.bottleWeight,jdbcType=VARCHAR}, #{item.wtGross,jdbcType=VARCHAR}, #{item.oprateName,jdbcType=VARCHAR},
            #{item.enterpriseId,jdbcType=VARCHAR}
            )
        </foreach>
    </insert>
    <update id="updateBatch" parameterType="list">
        <foreach collection="list" item="item"  index="index" separator=";">
            UPDATE t_lpg_air_charge_files
            <set>
                f_station_name = #{item.stationName},
                f_vase_code = #{item.vaseCode},
                f_scale_num = #{item.scaleNum},
                f_fill_statr_time = #{item.fillStatrTime},
                f_fill_end_time = #{item.fillEndTime},
                f_set_weight = #{item.setWeight},
                f_wt_net = #{item.wtNet},
                f_set_bottle_weight = #{item.setBottleWeight},
                f_bottle_weight = #{item.bottleWeight},
                f_wt_gross = #{item.wtGross},
                f_oprate_name = #{item.oprateName},
            </set>
            WHERE f_bar_code = #{item.barCode} and f_gz_id = #{item.gzId} and  enterprise_id = #{item.enterpriseId}
        </foreach>
    </update>

    <insert id="insertTLpgAirChargeFiles" parameterType="TLpgAirChargeFiles" useGeneratedKeys="true" keyProperty="fGasAirChargeId">
        insert into t_lpg_air_charge_files
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="gzId != null">f_gz_id,</if>
            <if test="stationName != null">f_station_name,</if>
            <if test="barCode != null">f_bar_code,</if>
            <if test="vaseCode != null">f_vase_code,</if>
            <if test="scaleNum != null">f_scale_num,</if>
            <if test="fillStatrTime != null">f_fill_statr_time,</if>
            <if test="fillEndTime != null">f_fill_end_time,</if>
            <if test="setWeight != null">f_set_weight,</if>
            <if test="wtNet != null">f_wt_net,</if>
            <if test="setBottleWeight != null">f_set_bottle_weight,</if>
            <if test="bottleWeight != null">f_bottle_weight,</if>
            <if test="wtGross != null">f_wt_gross,</if>
            <if test="oprateName != null">f_oprate_name,</if>
            <if test="enterpriseId != null">enterprise_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="gzId != null">#{gzId},</if>
            <if test="stationName != null">#{stationName},</if>
            <if test="barCode != null">#{barCode},</if>
            <if test="vaseCode != null">#{vaseCode},</if>
            <if test="scaleNum != null">#{scaleNum},</if>
            <if test="fillStatrTime != null">#{fillStatrTime},</if>
            <if test="fillEndTime != null">#{fillEndTime},</if>
            <if test="setWeight != null">#{setWeight},</if>
            <if test="wtNet != null">#{wtNet},</if>
            <if test="setBottleWeight != null">#{setBottleWeight},</if>
            <if test="sottleWeight != null">#{sottleWeight},</if>
            <if test="wtGross != null">#{wtGross},</if>
            <if test="oprateName != null">#{oprateName},</if>
            <if test="enterpriseId != null">#{enterpriseId},</if>
         </trim>
    </insert>

    <update id="updateTLpgAirChargeFiles" parameterType="TLpgAirChargeFiles">
        update t_lpg_air_charge_files
        <trim prefix="SET" suffixOverrides=",">
            <if test="gzId != null">f_gz_id = #{gzId},</if>
            <if test="stationName != null">f_station_name = #{stationName},</if>
            <if test="barCode != null">f_bar_code = #{barCode},</if>
            <if test="vaseCode != null">f_vase_code = #{vaseCode},</if>
            <if test="scaleNum != null">f_scale_num = #{scaleNum},</if>
            <if test="fillStatrTime != null">f_fill_statr_time = #{fillStatrTime},</if>
            <if test="fillEndTime != null">f_fill_end_time = #{fillEndTime},</if>
            <if test="setWeight != null">f_set_weight = #{setWeight},</if>
            <if test="wtNet != null">f_wt_net = #{wtNet},</if>
            <if test="setBottleWeight != null">f_set_bottle_weight = #{setBottleWeight},</if>
            <if test="sottleWeight != null">f_bottle_weight = #{sottleWeight},</if>
            <if test="wtGross != null">f_wt_gross = #{wtGross},</if>
            <if test="oprateName != null">f_oprate_name = #{oprateName},</if>
            <if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
        </trim>
        where f_gas_air_charge_id = #{fGasAirChargeId}
    </update>

    <delete id="deleteTLpgAirChargeFilesById" parameterType="Long">
        delete from t_lpg_air_charge_files where f_gas_air_charge_id = #{gasAirChargeId}
    </delete>

    <delete id="deleteTLpgAirChargeFilesByIds" parameterType="String">
        delete from t_lpg_air_charge_files where f_gas_air_charge_id in 
        <foreach item="fGasAirChargeId" collection="array" open="(" separator="," close=")">
            #{fGasAirChargeId}
        </foreach>
    </delete>
</mapper>