<?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.XhpcHistoryOrderMapper">

    <select id="getOrderPage" resultType="map">
        select
            co.serial_number as 'serialNumber',
            co.source as 'source',
            case co.source when 0 then 'C端用户'
            when 1 then '流量方用户'
            when 2 then '社区用户'
            when 3 then 'B端用户' end  as 'sourceName',
            co.start_time as 'startTime',
            co.end_time as 'endTime'
        from xhpc_charge_order as co
        left join xhpc_charging_station as st on st.charging_station_id =co.charging_station_id
        where co.del_flag =0
        <if test="params.number !=0 and params.number ==1">
            and co.charging_station_id in(select charging_station_id from xhpc_charging_station where operator_id=#{params.operatorId})
        </if>
        <if test="params.number !=0 and params.number ==2">
            and co.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 co.tenant_id = #{params.tenantId}
        </if>
        order by co.create_time desc
    </select>



</mapper>