<?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.ElecPvPriceConfigMapper">
    
    <resultMap type="com.ruoyi.ems.domain.ElecPvPriceConfig" id="pvPriceConfigResult">
        <result property="id"    column="id"    />
        <result property="cfgCode"    column="cfg_code"    />
        <result property="priceName"    column="price_name"    />
        <result property="objPrice"    column="obj_price"    />
        <result property="stateSubsidy"    column="state_subsidy"    />
        <result property="localSubsidy"    column="local_subsidy"    />
    </resultMap>

    <sql id="selectPvPriceConfigVo">
        select id, cfg_code, price_name, obj_price, state_subsidy, local_subsidy from adm_pv_elecprice_config
    </sql>

    <select id="selectPvPriceConfigList" parameterType="com.ruoyi.ems.domain.ElecPvPriceConfig" resultMap="pvPriceConfigResult">
        <include refid="selectPvPriceConfigVo"/>
        <where>  
            <if test="cfgCode != null  and cfgCode != ''"> and cfg_code = #{cfgCode}</if>
            <if test="priceName != null  and priceName != ''"> and price_name like concat('%', #{priceName}, '%')</if>
            <if test="objPrice != null "> and obj_price = #{objPrice}</if>
            <if test="stateSubsidy != null "> and state_subsidy = #{stateSubsidy}</if>
            <if test="localSubsidy != null "> and local_subsidy = #{localSubsidy}</if>
        </where>
    </select>
    
    <select id="selectPvPriceConfigById" parameterType="Long" resultMap="pvPriceConfigResult">
        <include refid="selectPvPriceConfigVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPvPriceConfig" parameterType="com.ruoyi.ems.domain.ElecPvPriceConfig" useGeneratedKeys="true" keyProperty="id">
        insert into adm_pv_elecprice_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cfgCode != null and cfgCode != ''">cfg_code,</if>
            <if test="priceName != null and priceName != ''">price_name,</if>
            <if test="objPrice != null">obj_price,</if>
            <if test="stateSubsidy != null">state_subsidy,</if>
            <if test="localSubsidy != null">local_subsidy,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cfgCode != null and cfgCode != ''">#{cfgCode},</if>
            <if test="priceName != null and priceName != ''">#{priceName},</if>
            <if test="objPrice != null">#{objPrice},</if>
            <if test="stateSubsidy != null">#{stateSubsidy},</if>
            <if test="localSubsidy != null">#{localSubsidy},</if>
         </trim>
    </insert>

    <update id="updatePvPriceConfig" parameterType="com.ruoyi.ems.domain.ElecPvPriceConfig">
        update adm_pv_elecprice_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="cfgCode != null and cfgCode != ''">cfg_code = #{cfgCode},</if>
            <if test="priceName != null and priceName != ''">price_name = #{priceName},</if>
            <if test="objPrice != null">obj_price = #{objPrice},</if>
            <if test="stateSubsidy != null">state_subsidy = #{stateSubsidy},</if>
            <if test="localSubsidy != null">local_subsidy = #{localSubsidy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePvPriceConfigById" parameterType="Long">
        delete from adm_pv_elecprice_config where id = #{id}
    </delete>

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