<?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.TSupBalUsgDayMapper">
    
    <resultMap type="TSupBalUsgDay" id="TSupBalUsgDayResult">
        <result property="fRepUsgDayId"    column="f_rep_usg_day_id"    />
        <result property="fCompanyInfoId"    column="f_company_info_id"    />
        <result property="fUrbanGasUsage"    column="f_urban_gas_usage"    />
        <result property="fRuralReplaceResidentsGasUsage"    column="f_rural_replace_residents_gas_usage"    />
        <result property="fNoRuralReplaceResidentsGasUsage"    column="f_no_rural_replace_residents_gas_usage"    />
        <result property="fIndustrialGasUsage"    column="f_industrial_gas_usage"    />
        <result property="fCommercialGasUsage"    column="f_commercial_gas_usage"    />
        <result property="fPublicGasUsage"    column="f_public_gas_usage"    />
        <result property="fCityHeatingGasUasge"    column="f_city_heating_gas_uasge"    />
        <result property="fCarGasUsage"    column="f_car_gas_usage"    />
        <result property="fSoldGasVolume"    column="f_sold_gas_volume"    />
        <result property="fGasUsage"    column="f_gas_usage"    />
        <result property="fUrbanLpgUsage"    column="f_urban_lpg_usage"    />
        <result property="fRuralLpgUsage"    column="f_rural_lpg_usage"    />
        <result property="fIndustrialLpgUsage"    column="f_industrial_lpg_usage"    />
        <result property="fCommercialLpgUsage"    column="f_commercial_lpg_usage"    />
        <result property="fPublicLpgUsage"    column="f_public_lpg_usage"    />
        <result property="fCarLpgUsage"    column="f_car_lpg_usage"    />
        <result property="fSoldLpgVolume"    column="f_sold_lpg_volume"    />
        <result property="fLpgUsage"    column="f_lpg_usage"    />
        <result property="fReportRecord"    column="f_report_record"    />
        <result property="fReportTime"    column="f_report_time"    />
        <result property="fCreateTime"    column="f_create_time"    />
        <result property="fUpdateTime"    column="f_update_time"    />
        <result property="fReportStatus"    column="f_report_status"    />
        <result property="fCalendarDate"    column="f_calendar_date"    />
        <result property="fGovUploadStatus"    column="f_gov_upload_status"    />
        <result property="fGovUploadTime"    column="f_gov_upload_time"    />
    </resultMap>

    <sql id="selectTSupBalUsgDayVo">
        SELECT
            da.f_rep_usg_day_id,
            da.f_company_info_id,
            da.f_urban_gas_usage,
            da.f_rural_replace_residents_gas_usage,
            da.f_no_rural_replace_residents_gas_usage,
            da.f_industrial_gas_usage,
            da.f_commercial_gas_usage,
            da.f_public_gas_usage,
            da.f_city_heating_gas_uasge,
            da.f_car_gas_usage,
            da.f_sold_gas_volume,
            da.f_gas_usage,
            da.f_urban_lpg_usage,
            da.f_rural_lpg_usage,
            da.f_industrial_lpg_usage,
            da.f_commercial_lpg_usage,
            da.f_public_lpg_usage,
            da.f_car_lpg_usage,
            da.f_sold_lpg_volume,
            da.f_lpg_usage,
            da.f_report_record,
            da.f_report_time,
            da.f_create_time,
            da.f_update_time,
            da.f_report_status,
            da.f_calendar_date,
            da.f_gov_upload_status,
            da.f_gov_upload_time,
            en.enterprise_name AS enterpriseName
        FROM
            t_sup_bal_usg_day da
        LEFT JOIN t_enterprise_info en ON en.enterprise_id = da.f_company_info_id
    </sql>

    <select id="selectTSupBalUsgDayList" parameterType="TSupBalUsgDay" resultMap="TSupBalUsgDayResult">
        <include refid="selectTSupBalUsgDayVo"/>
        <where>  
            <if test="fCompanyInfoId != null  and fCompanyInfoId != ''"> and da.f_company_info_id = #{fCompanyInfoId}</if>
            <if test="beginRepDate != null and endRepDate != null">and da.f_gov_upload_time between #{beginRepDate} and #{endRepDate}</if>
            <if test="fReportStatus != null and fReportStatus != ''">and da.f_report_status = #{fReportStatus}</if>
            <if test="enterpriseName != null  and enterpriseName != ''"> and en.enterprise_name like concat('%', #{enterpriseName}, '%')</if>
            <if test="fCalendarDate != null"> and f_calendar_date = #{fCalendarDate}</if>
            <if test="beginCurrentMonthDate != null and endCurrentMonthDate != null">and da.f_calendar_date between #{beginCurrentMonthDate} and #{endCurrentMonthDate}</if>
            <if test="fGovUploadStatus != null  and fGovUploadStatus != ''"> and da.f_gov_upload_status = #{fGovUploadStatus}</if>
            <if test="fGovUploadTime != null "> and da.f_gov_upload_time = #{fGovUploadTime}</if>
        </where>
        order by f_create_time desc
    </select>
    
    <select id="selectTSupBalUsgDayById" parameterType="Long" resultMap="TSupBalUsgDayResult">
        <include refid="selectTSupBalUsgDayVo"/>
        where da.f_rep_usg_day_id = #{fRepUsgDayId}
    </select>
        
    <insert id="insertTSupBalUsgDay" parameterType="TSupBalUsgDay" useGeneratedKeys="true" keyProperty="fRepUsgDayId">
        insert into t_sup_bal_usg_day
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fCompanyInfoId != null and fCompanyInfoId != ''">f_company_info_id,</if>
            <if test="fUrbanGasUsage != null">f_urban_gas_usage,</if>
            <if test="fRuralReplaceResidentsGasUsage != null">f_rural_replace_residents_gas_usage,</if>
            <if test="fNoRuralReplaceResidentsGasUsage != null">f_no_rural_replace_residents_gas_usage,</if>
            <if test="fIndustrialGasUsage != null">f_industrial_gas_usage,</if>
            <if test="fCommercialGasUsage != null">f_commercial_gas_usage,</if>
            <if test="fPublicGasUsage != null">f_public_gas_usage,</if>
            <if test="fCityHeatingGasUasge != null">f_city_heating_gas_uasge,</if>
            <if test="fCarGasUsage != null">f_car_gas_usage,</if>
            <if test="fSoldGasVolume != null">f_sold_gas_volume,</if>
            <if test="fGasUsage != null">f_gas_usage,</if>
            <if test="fUrbanLpgUsage != null">f_urban_lpg_usage,</if>
            <if test="fRuralLpgUsage != null">f_rural_lpg_usage,</if>
            <if test="fIndustrialLpgUsage != null">f_industrial_lpg_usage,</if>
            <if test="fCommercialLpgUsage != null">f_commercial_lpg_usage,</if>
            <if test="fPublicLpgUsage != null">f_public_lpg_usage,</if>
            <if test="fCarLpgUsage != null">f_car_lpg_usage,</if>
            <if test="fSoldLpgVolume != null">f_sold_lpg_volume,</if>
            <if test="fLpgUsage != null">f_lpg_usage,</if>
            <if test="fReportRecord != null">f_report_record,</if>
            <if test="fReportTime != null">f_report_time,</if>
            <if test="fCreateTime != null and fCreateTime != ''">f_create_time,</if>
            <if test="fUpdateTime != null">f_update_time,</if>
            <if test="fReportStatus != null and fReportStatus != ''">f_report_status,</if>
            <if test="fCalendarDate != null">f_calendar_date,</if>
            <if test="fGovUploadStatus != null">f_gov_upload_status,</if>
            <if test="fGovUploadTime != null">f_gov_upload_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fCompanyInfoId != null and fCompanyInfoId != ''">#{fCompanyInfoId},</if>
            <if test="fUrbanGasUsage != null">#{fUrbanGasUsage},</if>
            <if test="fRuralReplaceResidentsGasUsage != null">#{fRuralReplaceResidentsGasUsage},</if>
            <if test="fNoRuralReplaceResidentsGasUsage != null">#{fNoRuralReplaceResidentsGasUsage},</if>
            <if test="fIndustrialGasUsage != null">#{fIndustrialGasUsage},</if>
            <if test="fCommercialGasUsage != null">#{fCommercialGasUsage},</if>
            <if test="fPublicGasUsage != null">#{fPublicGasUsage},</if>
            <if test="fCityHeatingGasUasge != null">#{fCityHeatingGasUasge},</if>
            <if test="fCarGasUsage != null">#{fCarGasUsage},</if>
            <if test="fSoldGasVolume != null">#{fSoldGasVolume},</if>
            <if test="fGasUsage != null">#{fGasUsage},</if>
            <if test="fUrbanLpgUsage != null">#{fUrbanLpgUsage},</if>
            <if test="fRuralLpgUsage != null">#{fRuralLpgUsage},</if>
            <if test="fIndustrialLpgUsage != null">#{fIndustrialLpgUsage},</if>
            <if test="fCommercialLpgUsage != null">#{fCommercialLpgUsage},</if>
            <if test="fPublicLpgUsage != null">#{fPublicLpgUsage},</if>
            <if test="fCarLpgUsage != null">#{fCarLpgUsage},</if>
            <if test="fSoldLpgVolume != null">#{fSoldLpgVolume},</if>
            <if test="fLpgUsage != null">#{fLpgUsage},</if>
            <if test="fReportRecord != null">#{fReportRecord},</if>
            <if test="fReportTime != null">#{fReportTime},</if>
            <if test="fCreateTime != null and fCreateTime != ''">#{fCreateTime},</if>
            <if test="fUpdateTime != null">#{fUpdateTime},</if>
            <if test="fReportStatus != null and fReportStatus != ''">#{fReportStatus},</if>
            <if test="fCalendarDate != null">#{fCalendarDate},</if>
            <if test="fGovUploadStatus != null">#{fGovUploadStatus},</if>
            <if test="fGovUploadTime != null">#{fGovUploadTime},</if>
         </trim>
    </insert>

    <update id="updateTSupBalUsgDay" parameterType="TSupBalUsgDay">
        update t_sup_bal_usg_day
        <trim prefix="SET" suffixOverrides=",">
            <if test="fCompanyInfoId != null and fCompanyInfoId != ''">f_company_info_id = #{fCompanyInfoId},</if>
            <if test="fUrbanGasUsage != null">f_urban_gas_usage = #{fUrbanGasUsage},</if>
            <if test="fRuralReplaceResidentsGasUsage != null">f_rural_replace_residents_gas_usage = #{fRuralReplaceResidentsGasUsage},</if>
            <if test="fNoRuralReplaceResidentsGasUsage != null">f_no_rural_replace_residents_gas_usage = #{fNoRuralReplaceResidentsGasUsage},</if>
            <if test="fIndustrialGasUsage != null">f_industrial_gas_usage = #{fIndustrialGasUsage},</if>
            <if test="fCommercialGasUsage != null">f_commercial_gas_usage = #{fCommercialGasUsage},</if>
            <if test="fPublicGasUsage != null">f_public_gas_usage = #{fPublicGasUsage},</if>
            <if test="fCityHeatingGasUasge != null">f_city_heating_gas_uasge = #{fCityHeatingGasUasge},</if>
            <if test="fCarGasUsage != null">f_car_gas_usage = #{fCarGasUsage},</if>
            <if test="fSoldGasVolume != null">f_sold_gas_volume = #{fSoldGasVolume},</if>
            <if test="fGasUsage != null">f_gas_usage = #{fGasUsage},</if>
            <if test="fUrbanLpgUsage != null">f_urban_lpg_usage = #{fUrbanLpgUsage},</if>
            <if test="fRuralLpgUsage != null">f_rural_lpg_usage = #{fRuralLpgUsage},</if>
            <if test="fIndustrialLpgUsage != null">f_industrial_lpg_usage = #{fIndustrialLpgUsage},</if>
            <if test="fCommercialLpgUsage != null">f_commercial_lpg_usage = #{fCommercialLpgUsage},</if>
            <if test="fPublicLpgUsage != null">f_public_lpg_usage = #{fPublicLpgUsage},</if>
            <if test="fCarLpgUsage != null">f_car_lpg_usage = #{fCarLpgUsage},</if>
            <if test="fSoldLpgVolume != null">f_sold_lpg_volume = #{fSoldLpgVolume},</if>
            <if test="fLpgUsage != null">f_lpg_usage = #{fLpgUsage},</if>
            <if test="fReportRecord != null">f_report_record = #{fReportRecord},</if>
            <if test="fReportTime != null">f_report_time = #{fReportTime},</if>
            <if test="fCreateTime != null and fCreateTime != ''">f_create_time = #{fCreateTime},</if>
            <if test="fUpdateTime != null">f_update_time = #{fUpdateTime},</if>
            <if test="fReportStatus != null and fReportStatus != ''">f_report_status = #{fReportStatus},</if>
            <if test="fCalendarDate != null">f_calendar_date = #{fCalendarDate},</if>
            <if test="fGovUploadStatus != null">f_gov_upload_status = #{fGovUploadStatus},</if>
            <if test="fGovUploadTime != null">f_gov_upload_time = #{fGovUploadTime},</if>
        </trim>
        where f_rep_usg_day_id = #{fRepUsgDayId}
    </update>

    <delete id="deleteTSupBalUsgDayById" parameterType="Long">
        delete from t_sup_bal_usg_day where f_rep_usg_day_id = #{fRepUsgDayId}
    </delete>

    <delete id="deleteTSupBalUsgDayByIds" parameterType="String">
        delete from t_sup_bal_usg_day where f_rep_usg_day_id in 
        <foreach item="fRepUsgDayId" collection="array" open="(" separator="," close=")">
            #{fRepUsgDayId}
        </foreach>
    </delete>

    <select id="getReportInfoByCompany" parameterType="Map" resultMap="TSupBalUsgDayResult">
        <include refid="selectTSupBalUsgDayVo"/>
        where da.f_company_info_id = #{companyId} and da.f_calendar_date = #{calendarDate}
    </select>
</mapper>