<?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.xhpc.log.mapper.XhpcChargingStationMapper">

    <select id="selectXhpcChargingStationList" resultType="java.util.Map">
        select
        cs.charging_station_id as chargingStationId,
        cs.name as name,
        ope.name as operatorName,
        cs.address as address,
        (select url from xhpc_img where img_id = cs.img_id and del_flag =0 limit 1) as url,
        cs.client_visible as clientVisible,
        cs.status as status
        from xhpc_charging_station as cs
        left join xhpc_operator as ope on cs.operator_id = ope.operator_id
        where cs.del_flag =0
        <if test="params.number == 1">
            and cs.charging_station_id in(select charging_station_id from xhpc_charging_station where operator_id=#{params.operatorId})
        </if>
        <if test="params.number == 2">
            and cs.charging_station_id in(select charging_station_id from xhpc_user_privilege where user_id=#{params.operatorId})
        </if>
        <if test="params.tenantId != null and params.tenantId != ''">
            and cs.tenant_id=#{params.tenantId}
        </if>
    </select>


    <select id="selectRateListByStationId" resultType="map">
        select
            rate_model_id as 'rateId',
            create_time as 'createTime',
            create_by as 'createBy'
        from xhpc_rate_time
        where charging_station_id=#{stationId}
        group by rate_model_id
    </select>


    <select id="selectRateTimeListByRateId" resultType="map">
        select rt.start_time                                as startTime,
               replace(rt.end_time, '00:00:00', '24:00:00') AS endTime,
               rt.rate_id                                   as rateId,
               rt.rate_value                                as id,
               ra.name                                      as rateName,
               ra.power_fee                                 as powerFee,
               ra.service_fee                               as serviceFee
        from xhpc_rate_time as rt
                 left join xhpc_rate as ra on ra.rate_id = rt.rate_id
        where rt.rate_model_id =#{rateId}
    </select>


    <select id="selectBaseRateTimeListByRateId" resultType="map">
        SELECT
            name as 'name',
            power_fee as 'powerFee',
            service_fee as 'serviceFee'
        FROM xhpc_rate
        WHERE rate_model_id=#{rateId};
    </select>
</mapper>
