<?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.activity.mapper.XhpcMessageMapper">

    <select id="getOrderMessagePage" resultType="map">
        select m.message_id as 'messageId', m.charge_order_no as 'chargeOrderNo', m.content as 'content', m.status as 'status', m.remark as 'remark', m.create_time as 'createTime'
        from xhpc_message m
        where m.charge_order_no = #{serialNumber}
    </select>


    <select id="getOrderMessageByParams" resultType="java.util.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',
            co.charging_degree as 'chargingDegree',
            co.amount_charged as 'amountCharged',
            co.charging_time as 'chargingTime',
            co.start_soc as 'startSOc',
            co.end_soc as 'endSoc',
            m.message_id as 'messageId',
            m.charge_order_no as 'chargeOrderNo',
            m.content as 'content',
            m.status as 'status',
            m.remark as 'remark',
            m.create_time as 'createTime'
        from xhpc_message m
        LEFT JOIN xhpc_charge_order as co on co.serial_number = m.charge_order_no
        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>
        <if test="params.serialNumber !=null and params.serialNumber !=''">
            and co.serial_number=#{serialNumber}
        </if>
        order by m.charge_order_no asc, m.create_time asc
    </select>
</mapper>
