<?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.ems.mapper.ElecGwPriceConfigMapper">
    
    <resultMap type="com.ruoyi.ems.domain.ElecGwPriceConfig" id="elecPriceConfigResult">
        <result property="id"    column="id"    />
        <result property="cfgCode"    column="cfg_code"    />
        <result property="elecType"    column="elec_type"    />
        <result property="elecTypeName"    column="elec_type_name"    />
        <result property="voltageLevel"    column="voltage_level"    />
        <result property="degreePrice"    column="degree_price"    />
        <result property="fsPeakDegreePrice"    column="fs_peak_degree_price"    />
        <result property="fsHighDegreePrice"    column="fs_high_degree_price"    />
        <result property="fsFlatDegreePrice"    column="fs_flat_degree_price"    />
        <result property="fsLowDegreePrice"    column="fs_low_degree_price"    />
        <result property="maxReqPrice"    column="max_req_price"    />
        <result property="transCapacityPrice"    column="trans_capacity_price"    />
    </resultMap>

    <sql id="selectElecPriceConfigVo">
        select
            v.id, v.cfg_code, v.elec_type, t.`name` as elec_type_name, v.voltage_level, v.degree_price, v.fs_peak_degree_price, v.fs_high_degree_price, v.fs_flat_degree_price, v.fs_low_degree_price, v.max_req_price, v.trans_capacity_price
        from adm_gw_elecprice_config v
            LEFT JOIN dim_ems_elecprice_type t ON v.elec_type = t.`code`
    </sql>

    <select id="selectElecPriceConfigList" parameterType="com.ruoyi.ems.domain.ElecGwPriceConfig" resultMap="elecPriceConfigResult">
        <include refid="selectElecPriceConfigVo"/>
        <where>  
            <if test="cfgCode != null  and cfgCode != ''"> and v.cfg_code = #{cfgCode}</if>
            <if test="elecType != null "> and v.elec_type = #{elecType}</if>
            <if test="voltageLevel != null  and voltageLevel != ''"> and v.voltage_level = #{voltageLevel}</if>
            <if test="degreePrice != null "> and v.degree_price = #{degreePrice}</if>
            <if test="fsPeakDegreePrice != null "> and v.fs_peak_degree_price = #{fsPeakDegreePrice}</if>
            <if test="fsHighDegreePrice != null "> and v.fs_high_degree_price = #{fsHighDegreePrice}</if>
            <if test="fsFlatDegreePrice != null "> and v.fs_flat_degree_price = #{fsFlatDegreePrice}</if>
            <if test="fsLowDegreePrice != null "> and v.fs_low_degree_price = #{fsLowDegreePrice}</if>
            <if test="maxReqPrice != null "> and v.max_req_price = #{maxReqPrice}</if>
            <if test="transCapacityPrice != null "> and v.trans_capacity_price = #{transCapacityPrice}</if>
        </where>
    </select>
    
    <select id="selectElecPriceConfigById" parameterType="Long" resultMap="elecPriceConfigResult">
        <include refid="selectElecPriceConfigVo"/>
        where v.id = #{id}
    </select>
        
    <insert id="insertElecPriceConfig" parameterType="com.ruoyi.ems.domain.ElecGwPriceConfig" useGeneratedKeys="true" keyProperty="id">
        insert into adm_gw_elecprice_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cfgCode != null and cfgCode != ''">cfg_code,</if>
            <if test="elecType != null">elec_type,</if>
            <if test="voltageLevel != null and voltageLevel != ''">voltage_level,</if>
            <if test="degreePrice != null">degree_price,</if>
            <if test="fsPeakDegreePrice != null">fs_peak_degree_price,</if>
            <if test="fsHighDegreePrice != null">fs_high_degree_price,</if>
            <if test="fsFlatDegreePrice != null">fs_flat_degree_price,</if>
            <if test="fsLowDegreePrice != null">fs_low_degree_price,</if>
            <if test="maxReqPrice != null">max_req_price,</if>
            <if test="transCapacityPrice != null">trans_capacity_price,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cfgCode != null and cfgCode != ''">#{cfgCode},</if>
            <if test="elecType != null">#{elecType},</if>
            <if test="voltageLevel != null and voltageLevel != ''">#{voltageLevel},</if>
            <if test="degreePrice != null">#{degreePrice},</if>
            <if test="fsPeakDegreePrice != null">#{fsPeakDegreePrice},</if>
            <if test="fsHighDegreePrice != null">#{fsHighDegreePrice},</if>
            <if test="fsFlatDegreePrice != null">#{fsFlatDegreePrice},</if>
            <if test="fsLowDegreePrice != null">#{fsLowDegreePrice},</if>
            <if test="maxReqPrice != null">#{maxReqPrice},</if>
            <if test="transCapacityPrice != null">#{transCapacityPrice},</if>
         </trim>
    </insert>

    <update id="updateElecPriceConfig" parameterType="com.ruoyi.ems.domain.ElecGwPriceConfig">
        update adm_gw_elecprice_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="cfgCode != null and cfgCode != ''">cfg_code = #{cfgCode},</if>
            <if test="elecType != null">elec_type = #{elecType},</if>
            <if test="voltageLevel != null and voltageLevel != ''">voltage_level = #{voltageLevel},</if>
            <if test="degreePrice != null">degree_price = #{degreePrice},</if>
            <if test="fsPeakDegreePrice != null">fs_peak_degree_price = #{fsPeakDegreePrice},</if>
            <if test="fsHighDegreePrice != null">fs_high_degree_price = #{fsHighDegreePrice},</if>
            <if test="fsFlatDegreePrice != null">fs_flat_degree_price = #{fsFlatDegreePrice},</if>
            <if test="fsLowDegreePrice != null">fs_low_degree_price = #{fsLowDegreePrice},</if>
            <if test="maxReqPrice != null">max_req_price = #{maxReqPrice},</if>
            <if test="transCapacityPrice != null">trans_capacity_price = #{transCapacityPrice},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteElecPriceConfigById" parameterType="Long">
        delete from adm_gw_elecprice_config where id = #{id}
    </delete>

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