<?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.TSupBalGasSupMapper">
    
    <resultMap type="TSupBalGasSup" id="TSupBalGasSupResult">
        <result property="fGasSupId"    column="f_gas_sup_id"    />
        <result property="fCompanyInfoId"    column="f_company_info_id"    />
        <result property="fPlanQuan"    column="f_plan_quan"    />
        <result property="fApprQuan"    column="f_appr_quan"    />
        <result property="fSupGasVol"    column="f_sup_gas_vol"    />
        <result property="fStorageVol"    column="f_storage_vol"    />
        <result property="fSupDate"    column="f_sup_date"    />
        <result property="fRepStatus"    column="f_rep_status"    />
        <result property="fRepDate"    column="f_rep_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
        <result property="calendarDate"    column="f_calendar_date"    />
        <result property="fGovUploadStatus"    column="f_gov_upload_status"    />
        <result property="fGovUploadTime"    column="f_gov_upload_time"    />
    </resultMap>

    <sql id="selectTSupBalGasSupVo">
        SELECT
            sup.f_gas_sup_id,
            sup.f_company_info_id,
            sup.f_plan_quan,
            sup.f_appr_quan,
            sup.f_sup_gas_vol,
            sup.f_storage_vol,
            sup.f_sup_date,
            sup.f_rep_status,
            sup.f_rep_date,
            sup.create_by,
            sup.create_time,
            sup.update_by,
            sup.update_time,
            sup.is_del,
            sup.remarks,
            sup.f_calendar_date,
            sup.f_gov_upload_status,
            sup.f_gov_upload_time,
            en.enterprise_name as enterpriseName
        FROM
            t_sup_bal_gas_sup sup
        LEFT JOIN t_enterprise_info en ON sup.f_company_info_id = en.enterprise_id
    </sql>

    <select id="selectTSupBalGasSupList" parameterType="TSupBalGasSup" resultMap="TSupBalGasSupResult">
        <include refid="selectTSupBalGasSupVo"/>
        <where>  
            <if test="fCompanyInfoId != null  and fCompanyInfoId != ''"> and sup.f_company_info_id = #{fCompanyInfoId}</if>
            <if test="fPlanQuan != null "> and sup.f_plan_quan = #{fPlanQuan}</if>
            <if test="fApprQuan != null "> and sup.f_appr_quan = #{fApprQuan}</if>
            <if test="fSupGasVol != null "> and sup.f_sup_gas_vol = #{fSupGasVol}</if>
            <if test="fStorageVol != null "> and sup.f_storage_vol = #{fStorageVol}</if>
            <if test="fRepStatus != null  and fRepStatus != ''"> and sup.f_rep_status = #{fRepStatus}</if>
            <if test="beginRepDate != null and endRepDate != null">and sup.f_gov_upload_time between #{beginRepDate} and #{endRepDate}</if>
            <if test="enterpriseName != null  and enterpriseName != ''"> and en.enterprise_name like concat('%', #{enterpriseName}, '%')</if>
            <if test="calendarDate != null"> and f_calendar_date = #{calendarDate}</if>
            <if test="beginCurrentMonthDate != null and endCurrentMonthDate != null">and sup.f_calendar_date between #{beginCurrentMonthDate} and #{endCurrentMonthDate}</if>
            <if test="fGovUploadStatus != null  and fGovUploadStatus != ''"> and sup.f_gov_upload_status = #{fGovUploadStatus}</if>
            <if test="fGovUploadTime != null "> and sup.f_gov_upload_time = #{fGovUploadTime}</if>
        </where>
        order by create_time desc
    </select>

    <!--查询统计信息-->
    <select id="tSupBalGasSupStatistics" resultType="com.zehong.system.domain.Statistics">
        SELECT
        SUM(f_plan_quan) as 'count',
        SUM(f_appr_quan) as 'count1',
        SUM(f_sup_gas_vol) as 'count2',
        SUM(f_storage_vol) as 'count3',
        DATE_FORMAT( f_calendar_date, '%Y-%m-%d' ) AS date
        FROM
        t_sup_bal_gas_sup
        WHERE
        is_del='0'
        <if test="companyInfoId != null">
            and f_company_info_id = #{companyInfoId}
        </if>
        and
        DATE_FORMAT( f_calendar_date, '%Y-%m-%d' ) IN
        <foreach collection="list" item="sevenDate" separator="," open="(" close=")">
            #{sevenDate}
        </foreach>
        GROUP BY
        DATE_FORMAT( f_calendar_date, '%Y-%m-%d' )
        ORDER BY
        DATE_FORMAT( f_calendar_date, '%Y-%m-%d' ) DESC;
    </select>
    
    <select id="selectTSupBalGasSupById" parameterType="Long" resultMap="TSupBalGasSupResult">
        <include refid="selectTSupBalGasSupVo"/>
        where sup.f_gas_sup_id = #{fGasSupId}
    </select>
        
    <insert id="insertTSupBalGasSup" parameterType="TSupBalGasSup" useGeneratedKeys="true" keyProperty="fGasSupId">
        insert into t_sup_bal_gas_sup
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fCompanyInfoId != null and fCompanyInfoId != ''">f_company_info_id,</if>
            <if test="fPlanQuan != null">f_plan_quan,</if>
            <if test="fApprQuan != null">f_appr_quan,</if>
            <if test="fSupGasVol != null">f_sup_gas_vol,</if>
            <if test="fStorageVol != null">f_storage_vol,</if>
            <if test="fSupDate != null">f_sup_date,</if>
            <if test="fRepStatus != null and fRepStatus != ''">f_rep_status,</if>
            <if test="fRepDate != null">f_rep_date,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
            <if test="calendarDate != 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="fPlanQuan != null">#{fPlanQuan},</if>
            <if test="fApprQuan != null">#{fApprQuan},</if>
            <if test="fSupGasVol != null">#{fSupGasVol},</if>
            <if test="fStorageVol != null">#{fStorageVol},</if>
            <if test="fSupDate != null">#{fSupDate},</if>
            <if test="fRepStatus != null and fRepStatus != ''">#{fRepStatus},</if>
            <if test="fRepDate != null">#{fRepDate},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="calendarDate != null">#{calendarDate},</if>
            <if test="fGovUploadStatus != null">#{fGovUploadStatus},</if>
            <if test="fGovUploadTime != null">#{fGovUploadTime},</if>
         </trim>
    </insert>

    <update id="updateTSupBalGasSup" parameterType="TSupBalGasSup">
        update t_sup_bal_gas_sup
        <trim prefix="SET" suffixOverrides=",">
            <if test="fCompanyInfoId != null and fCompanyInfoId != ''">f_company_info_id = #{fCompanyInfoId},</if>
            <if test="fPlanQuan != null">f_plan_quan = #{fPlanQuan},</if>
            <if test="fApprQuan != null">f_appr_quan = #{fApprQuan},</if>
            <if test="fSupGasVol != null">f_sup_gas_vol = #{fSupGasVol},</if>
            <if test="fStorageVol != null">f_storage_vol = #{fStorageVol},</if>
            <if test="fSupDate != null">f_sup_date = #{fSupDate},</if>
            <if test="fRepStatus != null and fRepStatus != ''">f_rep_status = #{fRepStatus},</if>
            <if test="fRepDate != null">f_rep_date = #{fRepDate},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="calendarDate != null">f_calendar_date = #{calendarDate},</if>
            <if test="fGovUploadStatus != null">f_gov_upload_status = #{fGovUploadStatus},</if>
            <if test="fGovUploadTime != null">f_gov_upload_time = #{fGovUploadTime},</if>
        </trim>
        where f_gas_sup_id = #{fGasSupId}
    </update>

    <delete id="deleteTSupBalGasSupById" parameterType="Long">
        delete from t_sup_bal_gas_sup where f_gas_sup_id = #{fGasSupId}
    </delete>

    <delete id="deleteTSupBalGasSupByIds" parameterType="String">
        delete from t_sup_bal_gas_sup where f_gas_sup_id in 
        <foreach item="fGasSupId" collection="array" open="(" separator="," close=")">
            #{fGasSupId}
        </foreach>
    </delete>

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