<?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.charging.station.mapper.XhpcRateTimeMapper">

    <resultMap id="BaseResultMap" type="com.xhpc.common.domain.XhpcRateTime">
        <result property="rateTimeId" column="rate_time_id"/>
        <result property="chargingStationId" column="charging_station_id"/>
        <result property="rateId" column="rate_id"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="status" column="status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="rateModelId" column="rate_model_id"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="remark" column="remark"/>
        <result property="sort" column="sort"/>
        <result property="type" column="type"/>
        <result property="rateValue" column="rate_value"/>
    </resultMap>

    <select id="getXhpcRateTime" resultType="map">
        select rate_time_id as rateTimeId,
               rate_id      as rateId,
               start_time   as startTime,
               end_time     as endTime
        from xhpc_rate_time
        where charging_station_id = #{datchargingStationId}
          and start_time &lt;= #{date}
          and replace(end_time, '00:00:00', '24:00:00') &gt;= #{date}
          and status = 0
          and del_flag = 0
          limit 1
    </select>

    <select id="getXhpcTimeType" resultType="map">
        select ra.power_fee   as powerFee,
               ra.service_fee as serviceFee
        from xhpc_rate as ra
        where ra.charging_station_id = #{datchargingStationId}
          and ra.status = 0
          and ra.del_flag = 0
          and ra.rate_id = #{rateId}
    </select>

    <select id="getXhpcRateTimeType" resultType="map">
        select ra.power_fee   as powerFee,
               ra.service_fee as serviceFee
        from xhpc_rate as ra
        where ra.charging_station_id = #{datchargingStationId}
          and ra.status = 0
          and ra.del_flag = 0
          and ra.rate_id = (select rate_id
                            from xhpc_rate_time
                            where status = 0 and del_flag = 0 and charging_station_id = #{datchargingStationId}
            LIMIT 1)
    </select>


</mapper>
