<?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.ruoyi.project.production.mapper.TMonthlyProductionPriceMapper">
    
    <resultMap type="TMonthlyProductionPrice" id="TMonthlyProductionPriceResult">
        <result property="id"                       column="id"    />
        <result property="reportMonth"              column="report_month"    />
        <result property="reportYear"               column="report_year"    />
        <result property="subConElectricPrice"      column="sub_con_electric_price"    />
        <result property="subConNgPrice"            column="sub_con_ng_price"    />
        <result property="subConFgFrEuPrice"        column="sub_con_fg_fr_eu_price"    />
        <result property="subConLpgPrice"           column="sub_con_lpg_price"    />
        <result property="subConHhpSteamPrice"      column="sub_con_hhp_steam_price"    />
        <result property="subConPCondensatePrice"   column="sub_con_p_condensate_price"    />
        <result property="subConCwPrice"            column="sub_con_cw_price"    />
        <result property="subConIaPaPrice"          column="sub_con_ia_pa_price"    />
        <result property="subConBfwPrice"           column="sub_con_bfw_price"    />
        <result property="subConEoEgPurgeGasPrice"  column="sub_con_eo_eg_purge_gas_price"    />
        <result property="subConH2FulePrice"        column="sub_con_h2_fule_price"    />
    </resultMap>

    <sql id="selectTMonthlyProductionPriceVo">
        select d.id, d.report_month, d.report_year, d.sub_con_electric_price, d.sub_con_ng_price, d.sub_con_fg_fr_eu_price, d.sub_con_lpg_price, d.sub_con_hhp_steam_price, d.sub_con_p_condensate_price, d.sub_con_cw_price, d.sub_con_ia_pa_price, d.sub_con_bfw_price, d.sub_con_eo_eg_purge_gas_price, d.sub_con_h2_fule_price ,s.dept_name from t_monthly_production_price d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMonthlyProductionPriceByDate" parameterType="int" resultMap="TMonthlyProductionPriceResult">
        select *
        from t_monthly_production_price d
        where d.report_month = #{reportMonth} and d.report_year = #{reportYear}
    </select>

    <select id="selectTMonthlyProductionPriceCountByDate" parameterType="int" resultType="int">
        select count(id)
        from t_monthly_production_price d
        where d.report_month = #{reportMonth} and d.report_year = #{reportYear}
    </select>

    <select id="selectPriceByYear" parameterType="Long" resultMap="TMonthlyProductionPriceResult">
        select
               d.id, d.report_month, d.report_year,
               d.sub_con_electric_price,
               d.sub_con_ng_price,
               d.sub_con_fg_fr_eu_price,
               d.sub_con_lpg_price,
               d.sub_con_hhp_steam_price,
               d.sub_con_p_condensate_price,
               d.sub_con_cw_price,
               d.sub_con_ia_pa_price,
               d.sub_con_bfw_price,
               d.sub_con_eo_eg_purge_gas_price,
               d.sub_con_h2_fule_price
        from
             t_monthly_production_price d
        where d.report_year = #{year}
    </select>

    <select id="selectTMonthlyProductionPriceList" parameterType="TMonthlyProductionPrice" resultMap="TMonthlyProductionPriceResult">
        <include refid="selectTMonthlyProductionPriceVo"/>
        <where>  
            <if test="reportMonth != null "> and report_month = #{reportMonth}</if>
            <if test="reportYear != null "> and report_year = #{reportYear}</if>
            <if test="subConElectricPrice != null  and subConElectricPrice != ''"> and sub_con_electric_price = #{subConElectricPrice}</if>
            <if test="subConNgPrice != null  and subConNgPrice != ''"> and sub_con_ng_price = #{subConNgPrice}</if>
            <if test="subConFgFrEuPrice != null  and subConFgFrEuPrice != ''"> and sub_con_fg_fr_eu_price = #{subConFgFrEuPrice}</if>
            <if test="subConLpgPrice != null  and subConLpgPrice != ''"> and sub_con_lpg_price = #{subConLpgPrice}</if>
            <if test="subConHhpSteamPrice != null  and subConHhpSteamPrice != ''"> and sub_con_hhp_steam_price = #{subConHhpSteamPrice}</if>
            <if test="subConPCondensatePrice != null  and subConPCondensatePrice != ''"> and sub_con_p_condensate_price = #{subConPCondensatePrice}</if>
            <if test="subConCwPrice != null  and subConCwPrice != ''"> and sub_con_cw_price = #{subConCwPrice}</if>
            <if test="subConIaPaPrice != null  and subConIaPaPrice != ''"> and sub_con_ia_pa_price = #{subConIaPaPrice}</if>
            <if test="subConBfwPrice != null  and subConBfwPrice != ''"> and sub_con_bfw_price = #{subConBfwPrice}</if>
            <if test="subConEoEgPurgeGasPrice != null  and subConEoEgPurgeGasPrice != ''"> and sub_con_eo_eg_purge_gas_price = #{subConEoEgPurgeGasPrice}</if>
            <if test="subConH2FulePrice != null  and subConH2FulePrice != ''"> and sub_con_h2_fule_price = #{subConH2FulePrice}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTMonthlyProductionPriceById" parameterType="Long" resultMap="TMonthlyProductionPriceResult">
        <include refid="selectTMonthlyProductionPriceVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTMonthlyProductionPrice" parameterType="TMonthlyProductionPrice">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_monthly_production_price.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_monthly_production_price
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="reportMonth != null">report_month,</if>
            <if test="reportYear != null">report_year,</if>
            <if test="subConElectricPrice != null">sub_con_electric_price,</if>
            <if test="subConNgPrice != null">sub_con_ng_price,</if>
            <if test="subConFgFrEuPrice != null">sub_con_fg_fr_eu_price,</if>
            <if test="subConLpgPrice != null">sub_con_lpg_price,</if>
            <if test="subConHhpSteamPrice != null">sub_con_hhp_steam_price,</if>
            <if test="subConPCondensatePrice != null">sub_con_p_condensate_price,</if>
            <if test="subConCwPrice != null">sub_con_cw_price,</if>
            <if test="subConIaPaPrice != null">sub_con_ia_pa_price,</if>
            <if test="subConBfwPrice != null">sub_con_bfw_price,</if>
            <if test="subConEoEgPurgeGasPrice != null">sub_con_eo_eg_purge_gas_price,</if>
            <if test="subConH2FulePrice != null">sub_con_h2_fule_price,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="reportMonth != null">#{reportMonth},</if>
            <if test="reportYear != null">#{reportYear},</if>
            <if test="subConElectricPrice != null">#{subConElectricPrice},</if>
            <if test="subConNgPrice != null">#{subConNgPrice},</if>
            <if test="subConFgFrEuPrice != null">#{subConFgFrEuPrice},</if>
            <if test="subConLpgPrice != null">#{subConLpgPrice},</if>
            <if test="subConHhpSteamPrice != null">#{subConHhpSteamPrice},</if>
            <if test="subConPCondensatePrice != null">#{subConPCondensatePrice},</if>
            <if test="subConCwPrice != null">#{subConCwPrice},</if>
            <if test="subConIaPaPrice != null">#{subConIaPaPrice},</if>
            <if test="subConBfwPrice != null">#{subConBfwPrice},</if>
            <if test="subConEoEgPurgeGasPrice != null">#{subConEoEgPurgeGasPrice},</if>
            <if test="subConH2FulePrice != null">#{subConH2FulePrice},</if>
         </trim>
    </insert>

    <update id="updateTMonthlyProductionPrice" parameterType="TMonthlyProductionPrice">
        update t_monthly_production_price
        <trim prefix="SET" suffixOverrides=",">
            <if test="reportMonth != null">report_month = #{reportMonth},</if>
            <if test="reportYear != null">report_year = #{reportYear},</if>
            <if test="subConElectricPrice != null">sub_con_electric_price = #{subConElectricPrice},</if>
            <if test="subConNgPrice != null">sub_con_ng_price = #{subConNgPrice},</if>
            <if test="subConFgFrEuPrice != null">sub_con_fg_fr_eu_price = #{subConFgFrEuPrice},</if>
            <if test="subConLpgPrice != null">sub_con_lpg_price = #{subConLpgPrice},</if>
            <if test="subConHhpSteamPrice != null">sub_con_hhp_steam_price = #{subConHhpSteamPrice},</if>
            <if test="subConPCondensatePrice != null">sub_con_p_condensate_price = #{subConPCondensatePrice},</if>
            <if test="subConCwPrice != null">sub_con_cw_price = #{subConCwPrice},</if>
            <if test="subConIaPaPrice != null">sub_con_ia_pa_price = #{subConIaPaPrice},</if>
            <if test="subConBfwPrice != null">sub_con_bfw_price = #{subConBfwPrice},</if>
            <if test="subConEoEgPurgeGasPrice != null">sub_con_eo_eg_purge_gas_price = #{subConEoEgPurgeGasPrice},</if>
            <if test="subConH2FulePrice != null">sub_con_h2_fule_price = #{subConH2FulePrice},</if>
        </trim>
        where report_month = #{reportMonth} and report_year = #{reportYear}
    </update>

    <update id="deleteTMonthlyProductionPriceById" parameterType="Long">
        update t_monthly_production_price set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTMonthlyProductionPriceByIds" parameterType="String">
        update t_monthly_production_price set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>