<?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.CoChargingConfigMapper">
    
    <resultMap type="com.ruoyi.ems.domain.CoChargingConfig" id="CoChargingConfigResult">
        <result property="id"    column="id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="areaName"    column="area_name"    />
        <result property="areaShortName"    column="area_short_name"    />
        <result property="elecUnitPrice"    column="elec_unit_price"    />
        <result property="elecGtComputeType"    column="elec_gt_compute_type"    />
        <result property="elecComputeDesc"    column="elec_compute_desc"    />
        <result property="waterUnitPrice"    column="water_unit_price"    />
        <result property="waterGtComputeType"    column="water_gt_compute_type"    />
        <result property="waterComputeDesc"    column="water_compute_desc"    />
    </resultMap>

    <sql id="selectCoChargingConfigVo">
        select
            c.id, c.area_code, a.area_name, a.short_name as area_short_name, c.elec_unit_price, c.elec_gt_compute_type, c.elec_compute_desc, c.water_unit_price, c.water_gt_compute_type, c.water_compute_desc
        from adm_co_charging_config c
          LEFT JOIN adm_area a ON c.area_code = a.area_code
    </sql>

    <select id="selectCoChargingConfigList" parameterType="com.ruoyi.ems.domain.CoChargingConfig" resultMap="CoChargingConfigResult">
        <include refid="selectCoChargingConfigVo"/>
        <where>  
            <if test="areaCode != null  and areaCode != ''"> and a.area_code = #{areaCode}</if>
        </where>
    </select>
    
    <select id="selectCoChargingConfigById" parameterType="Long" resultMap="CoChargingConfigResult">
        <include refid="selectCoChargingConfigVo"/>

    </select>

    <select id="selectByArea" parameterType="java.lang.String" resultMap="CoChargingConfigResult">
        <include refid="selectCoChargingConfigVo"/>
        where a.area_code = #{areaCode}
    </select>

    <insert id="insertCoChargingConfig" parameterType="com.ruoyi.ems.domain.CoChargingConfig" useGeneratedKeys="true" keyProperty="id">
        insert into adm_co_charging_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code,</if>
            <if test="elecUnitPrice != null">elec_unit_price,</if>
            <if test="elecGtComputeType != null">elec_gt_compute_type,</if>
            <if test="elecComputeDesc != null">elec_compute_desc,</if>
            <if test="waterUnitPrice != null">water_unit_price,</if>
            <if test="waterGtComputeType != null">water_gt_compute_type,</if>
            <if test="waterComputeDesc != null">water_compute_desc,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
            <if test="elecUnitPrice != null">#{elecUnitPrice},</if>
            <if test="elecGtComputeType != null">#{elecGtComputeType},</if>
            <if test="elecComputeDesc != null">#{elecComputeDesc},</if>
            <if test="waterUnitPrice != null">#{waterUnitPrice},</if>
            <if test="waterGtComputeType != null">#{waterGtComputeType},</if>
            <if test="waterComputeDesc != null">#{waterComputeDesc},</if>
         </trim>
    </insert>

    <update id="updateCoChargingConfig" parameterType="com.ruoyi.ems.domain.CoChargingConfig">
        update adm_co_charging_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="elecUnitPrice != null">elec_unit_price = #{elecUnitPrice},</if>
            <if test="elecGtComputeType != null">elec_gt_compute_type = #{elecGtComputeType},</if>
            <if test="elecComputeDesc != null">elec_compute_desc = #{elecComputeDesc},</if>
            <if test="waterUnitPrice != null">water_unit_price = #{waterUnitPrice},</if>
            <if test="waterGtComputeType != null">water_gt_compute_type = #{waterGtComputeType},</if>
            <if test="waterComputeDesc != null">water_compute_desc = #{waterComputeDesc},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCoChargingConfigById" parameterType="Long">
        delete from adm_co_charging_config where id = #{id}
    </delete>

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