<?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.order.mapper.XhpcStatisticsServiceMapper">

    <resultMap type="com.xhpc.order.domain.XhpcStatisticsTimeInterval" id="StatisticsTimeIntervalResult">
        <result column="statistics_time_interval_id" property="statisticsTimeIntervalId"/>
        <result column="status" property="status"/>
        <result column="charging_degree" property="chargingDegree"/>
        <result column="charging_time" property="chargingTime"/>
        <result column="charging_number" property="chargingNumber"/>
        <result column="power_price" property="powerPrice"/>
        <result column="service_price" property="servicePrice"/>
        <result column="total_price" property="totalPrice"/>
        <result column="promotion_discount" property="promotionDiscount"/>
        <result column="internet_commission" property="internetCommission"/>
        <result column="internet_svc_commission" property="internetSvcCommission"/>
        <result column="platform_commission" property="platformCommission"/>
        <result column="platform_svc_commisssion" property="platformSvcCommisssion"/>
        <result column="operation_commission" property="operationCommission"/>
        <result column="operation_svc_commission" property="operationSvcCommission"/>
        <result column="operator_id" property="operatorId"/>
        <result column="internet_user_id" property="internetUserId"/>
        <result column="charging_station_id" property="chargingStationId"/>
        <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="terminalId" column="terminal_id"/>
        <result property="startTimeEvcs" column="start_time_evcs"/>
        <result property="endTimeEvcs" column="end_time_evcs"/>
        <result property="elecPriceEvcs" column="elec_price_evcs"/>
        <result property="servicePriceEvcs" column="service_price_evcs"/>
    </resultMap>

    <select id="getTimeIntervalPage" resultType="map">
        select
        format(ifnull(sum(act_price),0), 2) actPrice,
        format(ifnull(sum(act_power_price),0), 2) actPowerPrice,
        format(ifnull(sum(act_service_price),0), 2) actServicePrice,
        format(ifnull(sum(act_service_price + act_power_price),0), 2) actTotalPrice,
        format(ifnull(sum(activity_power_price_total),0), 2) activityPowerPriceTotal,
        format(ifnull(sum(activity_service_price_total),0), 2) activityServicePriceTotal,
        format(ifnull(sum(activity_total_price),0), 2) activityTotalPrice,
        format(ifnull(sum(charging_degree),0), 4) chargingDegree,
        format(ifnull(sum(charging_time),0), 2) chargingTime,
        ifnull(sum(charging_number),0) chargingNumber,
        format(ifnull(sum(power_price),0), 2) powerPrice,
        format(ifnull(sum(service_price),0), 2) servicePrice,
        format(ifnull(sum(total_price),0), 2) totalPrice,
        format(ifnull(sum(promotion_discount),0), 2) promotionDiscount,
        format(ifnull(sum(internet_commission),0), 2) internetCommission,
        format(ifnull(sum(internet_svc_commission),0), 2) internetSvcCommission,
        format(ifnull(sum(internet_degree_commission),0), 2) internetDegreeCommission,
        format(ifnull(sum(platform_commission),0), 2) platformCommission,
        format(ifnull(sum(platform_svc_commisssion),0), 2) platformSvcCommisssion,
        format(ifnull(sum(operation_commission),0), 2) operationCommission,
        format(ifnull(sum(operation_svc_commission),0), 2) operationSvcCommission,
              status,
        case  when status=1 then "00:00-01:00"
              when status=2 then "01:00-02:00"
              when status=3 then "02:00-03:00"
              when status=4 then "03:00-04:00"
              when status=5 then "04:00-05:00"
              when status=6 then "05:00-06:00"
              when status=7 then "06:00-07:00"
              when status=8 then "07:00-08:00"
              when status=9 then "08:00-09:00"
              when status=10 then "09:00-10:00"
              when status=11 then "10:00-11:00"
              when status=12 then "11:00-12:00"
              when status=13 then "12:00-13:00"
              when status=14 then "13:00-14:00"
              when status=15 then "14:00-15:00"
              when status=16 then "15:00-16:00"
              when status=17 then "16:00-17:00"
              when status=18 then "17:00-18:00"
              when status=19 then "18:00-19:00"
              when status=20 then "19:00-20:00"
              when status=21 then "20:00-21:00"
              when status=22 then "21:00-22:00"
              when status=23 then "22:00-23:00"
              when status=24 then "23:00-24:00"
              end time
        from xhpc_statistics_time_interval
        where del_flag=0 and total_price &gt;=0
        <if test="chargingStationIds !=null and chargingStationIds.size()>0">
            and charging_station_id in
            <foreach collection="chargingStationIds"   open="(" item="chargingStationId" separator="," close=")" >
                #{chargingStationId}
            </foreach>
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id =#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId} and del_flag =0)
        </if>
        <if test="terminalId !=null">
            and terminal_id =#{terminalId}
        </if>
        <if test="startTime !=null and startTime !=''">
            and create_time &gt;= #{startTime}
        </if>
        <if test="endTime !=null and endTime !=''">
            and create_time &lt;= #{endTime}
        </if>
        <if test="type==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="type==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="operatorId !=null">
            and operator_id =#{operatorId}
        </if>
        and operator_id is not null
        group by status
        order by status
    </select>

    <select id="getDateIntervalPage" resultType="map">
        select
        format(ifnull(sum(charging_degree),0), 4) chargingDegree,
        format(ifnull(sum(charging_time),0), 2) chargingTime,
        ifnull(sum(charging_number),0) chargingNumber,
        format(ifnull(sum(power_price),0), 2) powerPrice,
        format(ifnull(sum(service_price),0), 2) servicePrice,
        format(ifnull(sum(total_price),0), 2) totalPrice,
        format(ifnull(sum(activity_power_price_total),0), 2) activityPowerPriceTotal,
        format(ifnull(sum(activity_service_price_total),0), 2) activityServicePriceTotal,
        format(ifnull(sum(activity_total_price),0), 2) activityTotalPrice,
        format(ifnull(sum(act_price),0), 2) actPrice,
        format(ifnull(sum(act_power_price),0), 2) actPowerPrice,
        format(ifnull(sum(act_service_price),0), 2) actServicePrice,
        format(ifnull(sum(promotion_discount),0), 2) promotionDiscount,
        format(ifnull(sum(internet_commission),0), 2) internetCommission,
        format(ifnull(sum(internet_svc_commission),0), 2) internetSvcCommission,
        format(ifnull(sum(internet_degree_commission),0), 2) internetDegreeCommission,
        format(ifnull(sum(platform_commission),0), 2) platformCommission,
        format(ifnull(sum(platform_svc_commisssion),0), 2) platformSvcCommisssion,
        format(ifnull(sum(operation_commission),0), 2) operationCommission,
        format(ifnull(sum(operation_svc_commission),0), 2) operationSvcCommission,
        format(ifnull(sum(act_power_price + act_service_price),0), 2) actTotalPrice,
        DATE_FORMAT(create_time,'%Y-%m-%d') createTime
        from xhpc_statistics_station
        where del_flag=0 and type=1 and total_price &gt;=0
        <if test="chargingStationIds !=null and chargingStationIds.size()>0">
            and charging_station_id in
            <foreach collection="chargingStationIds"   open="(" item="chargingStationId" separator="," close=")" >
                #{chargingStationId}
            </foreach>
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id =#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId} and del_flag =0)
        </if>
        <if test="terminalId !=null">
            and terminal_id =#{terminalId}
        </if>
        <if test="startTime !=null and startTime !=''">
            and create_time &gt;= #{startTime}
        </if>
        <if test="endTime !=null and endTime !=''">
            and create_time &lt;= #{endTime}
        </if>
        <if test="type==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="type==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="operatorId !=null">
            and operator_id =#{operatorId}
        </if>
        and operator_id is not null
        group by DATE_FORMAT(create_time,'%Y-%m-%d')
        order by DATE_FORMAT(create_time,'%Y-%m-%d') desc
    </select>

    <select id="getStationIntervalPage" resultType="map">
        select
        format(ifnull(sum(ss.charging_degree),0), 4) chargingDegree,
        format(ifnull(sum(ss.charging_time),0), 2) chargingTime,
        ifnull(sum(ss.charging_number),0) chargingNumber,
        format(ifnull(sum(ss.power_price),0), 2) powerPrice,
        format(ifnull(sum(ss.service_price),0), 2) servicePrice,
        format(ifnull(sum(ss.total_price),0), 2) totalPrice,
        format(ifnull(sum(ss.activity_power_price_total),0), 2) activityPowerPriceTotal,
        format(ifnull(sum(ss.activity_service_price_total),0), 2) activityServicePriceTotal,
        format(ifnull(sum(ss.activity_total_price),0), 2) activityTotalPrice,
        format(ifnull(sum(ss.act_price),0), 2) actPrice,
        format(ifnull(sum(ss.act_power_price),0), 2) actPowerPrice,
        format(ifnull(sum(ss.act_service_price),0), 2) actServicePrice,
        format(ifnull(sum(ss.act_service_price + ss.act_power_price), 0), 2) actTotalPrice,
        format(ifnull(sum(ss.promotion_discount),0), 2) promotionDiscount,
        format(ifnull(sum(ss.internet_commission),0), 2) internetCommission,
        format(ifnull(sum(ss.internet_svc_commission),0), 2) internetSvcCommission,
        format(ifnull(sum(ss.internet_degree_commission),0), 2) internetDegreeCommission,
        format(ifnull(sum(ss.platform_commission),0), 2) platformCommission,
        format(ifnull(sum(ss.platform_svc_commisssion),0), 2) platformSvcCommisssion,
        format(ifnull(sum(ss.operation_commission),0), 2) operationCommission,
        format(ifnull(sum(ss.operation_svc_commission),0), 2) operationSvcCommission,
        cs.name chargingStationName,
        op.name operatorName,
        DATE_FORMAT(ss.create_time,'%Y-%m-%d') createTime
        from xhpc_statistics_station as ss
        left join xhpc_charging_station as cs on cs.charging_station_id = ss.charging_station_id
        left join xhpc_operator as op on op.operator_id = ss.operator_id
        where ss.del_flag=0 and ss.type=2 and ss.total_price &gt;=0
        <if test="startTime !=null and startTime !=''">
            and ss.create_time &gt;= #{startTime}
        </if>
        <if test="chargingStationId !=null">
            and ss.charging_station_id =#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and ss.terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId} and del_flag =0)
        </if>
        <if test="terminalId !=null">
            and ss.terminal_id =#{terminalId}
        </if>
        <if test="endTime !=null and endTime !=''">
            and ss.create_time &lt;= #{endTime}
        </if>
        <if test="type==1">
            and ss.charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="type==2">
            and ss.charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId})
        </if>
        <if test="chargingStationIds !=null and chargingStationIds.size()>0">
            and ss.charging_station_id in
            <foreach collection="chargingStationIds"   open="(" item="chargingStationId" separator="," close=")" >
                #{chargingStationId}
            </foreach>
        </if>
        <if test="operatorUserId !=null and operatorUserId.size()>0">
            and ss.operator_id in
            <foreach collection="operatorUserId"   open="(" item="operatorId" separator="," close=")" >
                #{operatorId}
            </foreach>
        </if>

        <if test="operatorId !=null">
            and ss.operator_id =#{operatorId}
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and ss.tenant_id = #{tenantId}
        </if>
        and ss.operator_id is not null
        group by ss.charging_station_id
    </select>

    <select id="getOperatorIntervalPage" resultType="map">
        select
        format(ifnull(sum(ss.charging_degree),0), 4) chargingDegree,
        format(ifnull(sum(ss.charging_time),0), 2) chargingTime,
        ifnull(sum(ss.charging_number),0) chargingNumber,
        format(ifnull(sum(ss.power_price),0), 2) powerPrice,
        format(ifnull(sum(ss.service_price),0), 2) servicePrice,
        format(ifnull(sum(ss.total_price),0), 2) totalPrice,
        format(ifnull(sum(ss.activity_power_price_total),0), 2) activityPowerPriceTotal,
        format(ifnull(sum(ss.activity_service_price_total),0), 2) activityServicePriceTotal,
        format(ifnull(sum(ss.activity_total_price),0), 2) activityTotalPrice,
        format(ifnull(sum(ss.act_price),0), 2) actPrice,
        format(ifnull(sum(ss.act_power_price),0), 2) actPowerPrice,
        format(ifnull(sum(ss.act_service_price),0), 2) actServicePrice,
        format(ifnull(sum(ss.act_service_price + ss.act_power_price),0), 2) actTotalPrice,
        format(ifnull(sum(ss.promotion_discount),0), 2) promotionDiscount,
        format(ifnull(sum(ss.internet_commission),0), 2) internetCommission,
        format(ifnull(sum(ss.internet_svc_commission),0), 2) internetSvcCommission,
        format(ifnull(sum(ss.internet_degree_commission),0), 2) internetDegreeCommission,
        format(ifnull(sum(ss.platform_commission),0), 2) platformCommission,
        format(ifnull(sum(ss.platform_svc_commisssion),0), 2) platformSvcCommisssion,
        format(ifnull(sum(ss.operation_commission),0), 2) operationCommission,
        format(ifnull(sum(ss.operation_svc_commission),0), 2) operationSvcCommission,
        op.name operatorName,
        DATE_FORMAT(ss.create_time,'%Y-%m-%d') createTime
        from xhpc_statistics_station as ss
        left join xhpc_operator as op on op.operator_id = ss.operator_id
        where ss.del_flag=0 and ss.type=2 and ss.total_price &gt;=0
        <if test="startTime !=null and startTime !=''">
            and ss.create_time &gt;= #{startTime}
        </if>
        <if test="chargingStationId !=null">
            and ss.charging_station_id =#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and ss.terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId} and del_flag =0)
        </if>
        <if test="terminalId !=null">
            and ss.terminal_id =#{terminalId}
        </if>
        <if test="endTime !=null and endTime !=''">
            and ss.create_time &lt;= #{endTime}
        </if>
        <if test="operatorUserId !=null and operatorUserId.size()>0">
            and ss.operator_id in
            <foreach collection="operatorUserId"   open="(" item="operatorIds" separator="," close=")" >
                #{operatorIds}
            </foreach>
        </if>
        <if test="type==1">
            and ss.charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="type==2">
            and ss.charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and ss.tenant_id = #{tenantId}
        </if>
        <if test="operatorId !=null">
            and ss.operator_id =#{operatorId}
        </if>
         and ss.operator_id is not null
        group by ss.operator_id
    </select>

    <select id="getInternetUserIntervalPage" resultType="map">
        select
        format(ifnull(sum(ss.charging_degree),0), 4)  chargingDegree,
        format(ifnull(sum(ss.charging_time),0), 2)  chargingTime,
        ifnull(sum(ss.charging_number),0)  chargingNumber,
        format(ifnull(sum(ss.power_price),0), 2)  powerPrice,
        format(ifnull(sum(ss.service_price),0), 2)  servicePrice,
        format(ifnull(sum(ss.total_price),0), 2)  totalPrice,
        format(ifnull(sum(ss.activity_power_price_total),0), 2) activityPowerPriceTotal,
        format(ifnull(sum(ss.activity_service_price_total),0), 2) activityServicePriceTotal,
        format(ifnull(sum(ss.activity_total_price),0), 2) activityTotalPrice,
        format(ifnull(sum(ss.act_price),0), 2)  actPrice,
        format(ifnull(sum(ss.act_power_price),0), 2)  actPowerPrice,
        format(ifnull(sum(ss.act_service_price),0), 2)  actServicePrice,
        format(ifnull(sum(ss.promotion_discount),0), 2)  promotionDiscount,
        format(ifnull(sum(ss.internet_commission),0), 2)  internetCommission,
        format(ifnull(sum(ss.internet_svc_commission),0), 2)  internetSvcCommission,
        format(ifnull(sum(ss.internet_degree_commission),0), 2)  internetDegreeCommission,
        format(ifnull(sum(ss.platform_commission),0), 2)  platformCommission,
        format(ifnull(sum(ss.platform_svc_commisssion),0), 2)  platformSvcCommisssion,
        format(ifnull(sum(ss.operation_commission),0), 2)  operationCommission,
        format(ifnull(sum(ss.operation_svc_commission),0), 2)  operationSvcCommission,
        iu.name internetUserName,
        DATE_FORMAT(ss.create_time,'%Y-%m-%d') createTime
        from xhpc_statistics_station as ss
        left join xhpc_internet_user as iu on iu.internet_user_id = ss.internet_user_id
        where ss.del_flag=0 and ss.type=2 and ss.internet_user_id is not null and ss.total_price &gt;=0
        <if test="startTime !=null and startTime !=''">
            and ss.create_time &gt;= #{startTime}
        </if>
        <if test="endTime !=null and endTime !=''">
            and ss.create_time &lt;= #{endTime}
        </if>
        <if test="internetIds !=null and internetIds.size()>0">
            and ss.internet_user_id in
            <foreach collection="internetIds"   open="(" item="internetId" separator="," close=")" >
                #{internetId}
            </foreach>
        </if>
        <if test="type==3">
            and ss.internet_user_id =#{internetUserId}
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and ss.tenant_id = #{tenantId}
        </if>
        <if test="operatorId !=null">
            and ss.operator_id =#{operatorId}
        </if>
        and ss.operator_id is not null
        group by ss.internet_user_id
    </select>

    <select id="getTerminalIntervalPage" resultType="map">
        select
        format(ifnull(sum(ss.charging_degree),0), 4) chargingDegree,
        format(ifnull(sum(ss.charging_time),0), 2) chargingTime,
        ifnull(sum(ss.charging_number),0) chargingNumber,
        format(ifnull(sum(ss.power_price),0), 2) powerPrice,
        format(ifnull(sum(ss.service_price),0), 2) servicePrice,
        format(ifnull(sum(ss.total_price),0), 2) totalPrice,
        format(ifnull(sum(ss.activity_power_price_total),0), 2) activityPowerPriceTotal,
        format(ifnull(sum(ss.activity_service_price_total),0), 2) activityServicePriceTotal,
        format(ifnull(sum(ss.activity_total_price),0), 2) activityTotalPrice,
        format(ifnull(sum(ss.act_price),0), 2) actPrice,
        format(ifnull(sum(ss.act_power_price),0), 2) actPowerPrice,
        format(ifnull(sum(ss.act_service_price),0), 2) actServicePrice,
        format(ifnull(sum(ss.act_service_price + ss.act_power_price),0), 2) actTotalPrice,
        format(ifnull(sum(ss.promotion_discount),0), 2) promotionDiscount,
        format(ifnull(sum(ss.internet_commission),0), 2) internetCommission,
        format(ifnull(sum(ss.internet_svc_commission),0), 2) internetSvcCommission,
        format(ifnull(sum(ss.internet_degree_commission),0), 2) internetDegreeCommission,
        format(ifnull(sum(ss.platform_commission),0), 2) platformCommission,
        format(ifnull(sum(ss.platform_svc_commisssion),0), 2) platformSvcCommisssion,
        format(ifnull(sum(ss.operation_commission),0), 2) operationCommission,
        format(ifnull(sum(ss.operation_svc_commission),0), 2) operationSvcCommission,
        cs.name chargingStationName,
        te.name terminalName,
        DATE_FORMAT(ss.create_time,'%Y-%m-%d') createTime
        from xhpc_statistics_station as ss
        left join xhpc_charging_station as cs on cs.charging_station_id = ss.charging_station_id
        left join xhpc_terminal as te on te.terminal_id = ss.terminal_id
        where ss.del_flag=0 and ss.type=3 and ss.total_price &gt;=0
        <if test="startTime !=null and startTime !=''">
            and ss.create_time &gt;= #{startTime}
        </if>
        <if test="endTime !=null and endTime !=''">
            and ss.create_time &lt;= #{endTime}
        </if>
        <if test="chargingStationId !=null and chargingStationId !=''">
            and cs.charging_station_id=#{chargingStationId}
        </if>
        <if test="terminalId !=null and terminalId !=''">
            and te.terminal_id=#{terminalId}
        </if>
        <if test="type==1">
            and ss.charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="type==2">
            and ss.charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and ss.tenant_id = #{tenantId}
        </if>
        <if test="operatorId !=null">
            and ss.operator_id =#{operatorId}
        </if>
        and ss.operator_id is not null
        group by ss.terminal_id
    </select>

    <select id="getChargingStationList" resultType="map">
        select
        name as stationName,
        charging_station_id as chargingStationId
        from xhpc_charging_station
        where del_flag =0
        <if test="type==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="type==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="operatorId !=null">
            and operator_id =#{operatorId}
        </if>
    </select>

    <select id="getChargingPileList" resultType="map">
        select
        concat(cp.name,"号桩--",cs.name) as chargingPileName,
        cp.charging_pile_id as chargingPileId
        from xhpc_charging_pile as cp
        left join xhpc_charging_station cs on cs.charging_station_id = cp.charging_station_id
        where cp.del_flag =0
        <if test="type==1">
            and cp.charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="type==2">
            and cp.charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and cp.tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and cp.charging_station_id = #{chargingStationId}
        </if>
        order by cp.serial_number asc
    </select>

    <select id="getOperatorList" resultType="map">
        select
        operator_id as operatorId,
        name as operatorName
        from xhpc_operator
        where del_flag =0
        <if test="type==1">
            and operator_id in (select operator_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="type==2">
            and operator_id in (select operator_id from xhpc_charging_station where charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId}))
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
    </select>

    <select id="getTenantList" resultType="map">
        select
            xt.tenant_id as tenantId,
            xt.tenant_name as tenantName
        from xhpc_operator as xo
        join xhpc_tenant as xt on xt.tenant_id = xo.tenant_id
        where xt.is_deleted =0 and xo.del_flag =0
        <if test="type==1">
            and xo.operator_id=#{userId}
        </if>
        <if test="type==2">
            and xo.operator_id in (select operator_id from xhpc_charging_station where charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId}))
        </if>
        group by xt.tenant_id
    </select>


    <select id="getInternetUserIList" resultType="map">
        select
        internet_user_id as operinternetUserId,
        name as operinternetUserName
        from xhpc_internet_user
        where 1=1
        <if test="type==2">
            and internet_user_id =#{internetUserId}
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
    </select>

    <select id="getTerminalList" resultType="map">
        select
        terminal_id as terminalId,
        name as terminalName
        from xhpc_terminal
        where del_flag =0

        <if test="chargingStationId!=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId!=null">
            and charging_pile_id=#{chargingPileId}
        </if>
        <if test="operatorId !=null">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="type==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="type==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
    </select>

    <select id="getMechanismPage" resultType="map">
        select
        format(ifnull(sum(charging_degree),0), 4) chargingDegree,
        format(ifnull(sum(charging_time),0), 2) chargingTime,
        ifnull(sum(charging_number),0) chargingNumber,
        format(ifnull(sum(power_price),0), 2) powerPrice,
        format(ifnull(sum(service_price),0), 2) servicePrice,
        format(ifnull(sum(total_price),0), 2) totalPrice,
        format(ifnull(sum(act_price),0), 2) actPrice,
        format(ifnull(sum(activity_power_price_total),0), 2) activityPowerPriceTotal,
        format(ifnull(sum(activity_service_price_total),0), 2) activityServicePriceTotal,
        format(ifnull(sum(activity_total_price),0), 2) activityTotalPrice,
        format(ifnull(sum(act_power_price),0), 2) actPowerPrice,
        format(ifnull(sum(act_service_price),0), 2) actServicePrice,
        format(ifnull(sum(act_service_price + act_power_price),0), 2) actTotalPrice,
        format(ifnull(sum(promotion_discount),0), 2) promotionDiscount,
        format(ifnull(sum(internet_commission),0), 2) internetCommission,
        format(ifnull(sum(internet_svc_commission),0), 2) internetSvcCommission,
        format(ifnull(sum(internet_degree_commission),0), 2) internetDegreeCommission,
        format(ifnull(sum(platform_commission),0), 2) platformCommission,
        format(ifnull(sum(platform_svc_commisssion),0), 2) platformSvcCommisssion,
        format(ifnull(sum(operation_commission),0) , 2)operationCommission,
        format(ifnull(sum(operation_svc_commission),0), 2) operationSvcCommission,
        DATE_FORMAT(create_time,'%Y-%m-%d') createTime,
        source as source,
        CASE
        WHEN source = 2 THEN
        "社区用户"
        WHEN source = 3 THEN
        "B端用户"
        ELSE
        "未知用户"
        END sourceName
        from xhpc_statistics_station
        where del_flag=0 and type=2 and source !=0 and source !=1
        <if test="source !=null and source !=-1">
            and source=#{source}
        </if>
        <if test="source ==null">
            and source in (2,3)
        </if>
        <if test="operatorId !=null">
            and operator_id =#{operatorId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id =#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId} and del_flag =0)
        </if>
        <if test="terminalId !=null">
            and terminal_id =#{terminalId}
        </if>
        <if test="chargingStationIds !=null and chargingStationIds.size()>0">
            and charging_station_id in
            <foreach collection="chargingStationIds"   open="(" item="chargingStationId" separator="," close=")" >
                #{chargingStationId}
            </foreach>
        </if>
        <if test="startTime !=null and startTime !=''">
            and create_time &gt;= #{startTime}
        </if>
        <if test="endTime !=null and endTime !=''">
            and create_time &lt;= #{endTime}
        </if>
        <if test="type==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="type==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        and operator_id is not null
        group by source
    </select>

    <insert id="addStatisticsTime">
        insert into xhpc_statistics_time_interval
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="null != status ">
                status,
            </if>
            <if test="null != chargingDegree ">
                charging_degree,
            </if>
            <if test="null != chargingTime ">
                charging_time,
            </if>
            <if test="null != chargingNumber ">
                charging_number,
            </if>
            <if test="null != powerPrice ">
                power_price,
            </if>
            <if test="null != servicePrice ">
                service_price,
            </if>
            <if test="null != totalPrice ">
                total_price,
            </if>
            <if test="null != promotionDiscount ">
                promotion_discount,
            </if>
            <if test="null != actPrice ">
                act_price,
            </if>
            <if test="null != actPowerPrice ">
                act_power_price,
            </if>
            <if test="null != actServicePrice ">
                act_service_price,
            </if>
            <if test="null != internetCommission ">
                internet_commission,
            </if>
            <if test="null != internetSvcCommission ">
                internet_svc_commission,
            </if>
            <if test="null != platformCommission ">
                platform_commission,
            </if>
            <if test="null != platformSvcCommisssion ">
                platform_svc_commisssion,
            </if>
            <if test="null != operationCommission ">
                operation_commission,
            </if>
            <if test="null != operationSvcCommission ">
                operation_svc_commission,
            </if>
            <if test="null != internetUserId ">
                internet_user_id,
            </if>
            <if test="null != operatorId ">
                operator_id,
            </if>
            <if test="null != chargingStationId ">
                charging_station_id,
            </if>
            <if test="null != delFlag ">
                del_flag,
            </if>
            <if test="null != createTime ">
                create_time,
            </if>
            <if test="null != remark ">
                remark,
            </if>
            <if test="null != terminalId ">
                terminal_id,
            </if>
            <if test="null != historyOrderId ">
                history_order_id,
            </if>
            <if test="null != startTimeEvcs ">
                start_time_evcs,
            </if>
            <if test="null != endTimeEvcs ">
                end_time_evcs,
            </if>
            <if test="null != elecPriceEvcs ">
                elec_price_evcs,
            </if>
            <if test="null != servicePriceEvcs ">
                service_price_evcs,
            </if>
            <if test="null != internetDegreeCommission ">
                internet_degree_commission,
            </if>
            <if test="null != activityPowerPriceTotal ">
                activity_power_price_total,
            </if>
            <if test="null != activityServicePriceTotal ">
                activity_service_price_total,
            </if>
            <if test="null != activityTotalPrice ">
                activity_total_price,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="null != status ">
                #{status},
            </if>
            <if test="null != chargingDegree ">
                #{chargingDegree},
            </if>
            <if test="null != chargingTime ">
                #{chargingTime},
            </if>
            <if test="null != chargingNumber ">
                #{chargingNumber},
            </if>
            <if test="null != powerPrice ">
                #{powerPrice},
            </if>
            <if test="null != servicePrice ">
                #{servicePrice},
            </if>
            <if test="null != totalPrice ">
                #{totalPrice},
            </if>
            <if test="null != promotionDiscount ">
                #{promotionDiscount},
            </if>
            <if test="null != actPrice ">
                #{actPrice},
            </if>
            <if test="null != actPowerPrice ">
                #{actPowerPrice},
            </if>
            <if test="null != actServicePrice ">
                #{actServicePrice},
            </if>
            <if test="null != internetCommission ">
                #{internetCommission},
            </if>
            <if test="null != internetSvcCommission ">
                #{internetSvcCommission},
            </if>
            <if test="null != platformCommission ">
                #{platformCommission},
            </if>
            <if test="null != platformSvcCommisssion ">
                #{platformSvcCommisssion},
            </if>
            <if test="null != operationCommission ">
                #{operationCommission},
            </if>
            <if test="null != operationSvcCommission ">
                #{operationSvcCommission},
            </if>
            <if test="null != internetUserId ">
                #{internetUserId},
            </if>
            <if test="null != operatorId ">
                #{operatorId},
            </if>
            <if test="null != chargingStationId ">
                #{chargingStationId},
            </if>
            <if test="null != delFlag ">
                #{delFlag},
            </if>
            <if test="null != createTime ">
                #{createTime},
            </if>
            <if test="null != remark ">
                #{remark},
            </if>
            <if test="null != terminalId ">
                #{terminalId},
            </if>
            <if test="null != historyOrderId ">
                #{historyOrderId},
            </if>
            <if test="null != startTimeEvcs ">
                #{startTimeEvcs},
            </if>
            <if test="null != endTimeEvcs ">
                #{endTimeEvcs},
            </if>
            <if test="null != elecPriceEvcs ">
                #{elecPriceEvcs},
            </if>
            <if test="null != servicePriceEvcs ">
                #{servicePriceEvcs},
            </if>
            <if test="null != internetDegreeCommission ">
                #{internetDegreeCommission},
            </if>
            <if test="null != activityPowerPriceTotal ">
                #{activityPowerPriceTotal},
            </if>
            <if test="null != activityServicePriceTotal ">
                #{activityServicePriceTotal},
            </if>
            <if test="null != activityTotalPrice ">
                #{activityTotalPrice},
            </if>
        </trim>
    </insert>

    <insert id="addStatisticsStation">
        insert into xhpc_statistics_station
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="null != chargingDegree ">
                charging_degree,
            </if>
            <if test="null != chargingTime ">
                charging_time,
            </if>
            <if test="null != chargingNumber ">
                charging_number,
            </if>
            <if test="null != powerPrice ">
                power_price,
            </if>
            <if test="null != servicePrice ">
                service_price,
            </if>
            <if test="null != totalPrice ">
                total_price,
            </if>
            <if test="null != promotionDiscount ">
                promotion_discount,
            </if>
            <if test="null != actPrice ">
                act_price,
            </if>
            <if test="null != actPowerPrice ">
                act_power_price,
            </if>
            <if test="null != actServicePrice ">
                act_service_price,
            </if>
            <if test="null != internetCommission ">
                internet_commission,
            </if>
            <if test="null != internetSvcCommission ">
                internet_svc_commission,
            </if>
            <if test="null != platformCommission ">
                platform_commission,
            </if>
            <if test="null != platformSvcCommisssion ">
                platform_svc_commisssion,
            </if>
            <if test="null != operationCommission ">
                operation_commission,
            </if>
            <if test="null != operationSvcCommission ">
                operation_svc_commission,
            </if>
            <if test="null != internetUserId ">
                internet_user_id,
            </if>
            <if test="null != operatorId ">
                operator_id,
            </if>
            <if test="null != chargingPileId ">
                charging_pile_id,
            </if>
            <if test="null != chargingStationId ">
                charging_station_id,
            </if>
            <if test="null != delFlag ">
                del_flag,
            </if>
            <if test="null != createTime ">
                create_time,
            </if>
            <if test="null != remark ">
                remark,
            </if>
            <if test="null != terminalId ">
                terminal_id,
            </if>
            <if test="null != type ">
                type,
            </if>
            <if test="null != historyOrderId ">
                history_order_id,
            </if>
            <if test="chargingMode != null">
                charging_mode,
            </if>
            <if test="null != internetDegreeCommission ">
                internet_degree_commission,
            </if>
            <if test="null != source ">
                source,
            </if>
            <if test="null != activityPowerPriceTotal ">
                activity_power_price_total,
            </if>
            <if test="null != activityServicePriceTotal ">
                activity_service_price_total,
            </if>
            <if test="null != activityTotalPrice ">
                activity_total_price,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="null != chargingDegree ">
                #{chargingDegree},
            </if>
            <if test="null != chargingTime ">
                #{chargingTime},
            </if>
            <if test="null != chargingNumber ">
                #{chargingNumber},
            </if>
            <if test="null != powerPrice ">
                #{powerPrice},
            </if>
            <if test="null != servicePrice ">
                #{servicePrice},
            </if>
            <if test="null != totalPrice ">
                #{totalPrice},
            </if>
            <if test="null != promotionDiscount ">
                #{promotionDiscount},
            </if>
            <if test="null != actPrice ">
                #{actPrice},
            </if>
            <if test="null != actPowerPrice ">
                #{actPowerPrice},
            </if>
            <if test="null != actServicePrice ">
                #{actServicePrice},
            </if>
            <if test="null != internetCommission ">
                #{internetCommission},
            </if>
            <if test="null != internetSvcCommission ">
                #{internetSvcCommission},
            </if>
            <if test="null != platformCommission ">
                #{platformCommission},
            </if>
            <if test="null != platformSvcCommisssion ">
                #{platformSvcCommisssion},
            </if>
            <if test="null != operationCommission ">
                #{operationCommission},
            </if>
            <if test="null != operationSvcCommission ">
                #{operationSvcCommission},
            </if>
            <if test="null != internetUserId ">
                #{internetUserId},
            </if>
            <if test="null != operatorId ">
                #{operatorId},
            </if>
            <if test="null != chargingPileId ">
                #{chargingPileId},
            </if>
            <if test="null != chargingStationId ">
                #{chargingStationId},
            </if>
            <if test="null != delFlag ">
                #{delFlag},
            </if>
            <if test="null != createTime ">
                #{createTime},
            </if>
            <if test="null != remark ">
                #{remark},
            </if>
            <if test="null != terminalId ">
                #{terminalId},
            </if>
            <if test="null != type ">
                #{type},
            </if>
            <if test="null != historyOrderId ">
                #{historyOrderId},
            </if>
            <if test="chargingMode != null">
                #{chargingMode},
            </if>
            <if test="null != internetDegreeCommission ">
                #{internetDegreeCommission},
            </if>
            <if test="null != source ">
                #{source},
            </if>
            <if test="null != activityPowerPriceTotal ">
                #{activityPowerPriceTotal},
            </if>
            <if test="null != activityServicePriceTotal ">
                #{activityServicePriceTotal},
            </if>
            <if test="null != activityTotalPrice ">
                #{activityTotalPrice},
            </if>
        </trim>
    </insert>

    <select id="getInternetList" resultType="map">
        SELECT
            internet_user_id as id,name
        FROM
            xhpc_internet_user
        WHERE
            del_flag = 0
        <if test="userId !=null">
            and internet_user_id=#{userId}
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
    </select>

    <select id="getLandUser" resultType="map">
        select user_id as userId,user_type as userType,operator_id as operatorId  from sys_user where user_id =#{userId}
    </select>

    <select id="getSumSourceList" resultType="map">
        select
        format(ifnull(sum(ss.charging_degree),0), 4) chargingDegree,
        format(ifnull(sum(ss.charging_time),0), 2) chargingTime,
        ifnull(sum(ss.charging_number),0) chargingNumber,
        format(ifnull(sum(ss.power_price),0), 2) powerPrice,
        format(ifnull(sum(ss.service_price),0), 2) servicePrice,
        format(ifnull(sum(ss.total_price),0), 2) totalPrice,
        format(ifnull(sum(ss.activity_power_price_total),0), 2) activityPowerPriceTotal,
        format(ifnull(sum(ss.activity_service_price_total),0), 2) activityServicePriceTotal,
        format(ifnull(sum(ss.activity_total_price),0), 2) activityTotalPrice,
        format(ifnull(sum(ss.act_price),0), 2) actPrice,
        format(ifnull(sum(ss.act_power_price),0), 2) actPowerPrice,
        format(ifnull(sum(ss.act_service_price),0), 2) actServicePrice,
        format(ifnull(sum(ss.act_service_price + ss.act_power_price),0), 2) actTotalPrice,
        format(ifnull(sum(ss.promotion_discount),0), 2) promotionDiscount,
        format(ifnull(sum(ss.internet_commission),0), 2) internetCommission,
        format(ifnull(sum(ss.internet_svc_commission),0), 2) internetSvcCommission,
        format(ifnull(sum(ss.internet_degree_commission),0), 2) internetDegreeCommission,
        format(ifnull(sum(ss.platform_commission),0), 2) platformCommission,
        format(ifnull(sum(ss.platform_svc_commisssion),0), 2) platformSvcCommisssion,
        format(ifnull(sum(ss.operation_commission),0), 2) operationCommission,
        format(ifnull(sum(ss.operation_svc_commission),0), 2) operationSvcCommission,
        IF(iu.name IS NULL,ss.charging_mode, iu.name) as internetUserName,
        DATE_FORMAT(ss.create_time,'%Y-%m-%d') createTime
        from xhpc_statistics_station as ss
        left join xhpc_internet_user as iu on iu.internet_user_id = ss.charging_mode
        where ss.del_flag=0 and ss.type=2
        <if test="startTime !=null and startTime !=''">
            and ss.create_time &gt;= #{startTime}
        </if>
        <if test="endTime !=null and endTime !=''">
            and ss.create_time &lt;= #{endTime}
        </if>
        <if test="operatorId !=null">
            and ss.operator_id =#{operatorId}
        </if>
        <if test="chargingStationId !=null">
            and ss.charging_station_id =#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and ss.terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId} and del_flag =0)
        </if>
        <if test="terminalId !=null">
            and ss.terminal_id =#{terminalId}
        </if>
        <if test="sourceIds !=null and sourceIds.size()>0">
            and ss.charging_mode in
            <foreach collection="sourceIds"   open="(" item="sourceId" separator="," close=")" >
                #{sourceId}
            </foreach>
        </if>
        <if test="chargingStationIdList !=null and chargingStationIdList.size()>0">
            and ss.charging_station_id in
            <foreach collection="chargingStationIdList"   open="(" item="chargingStationId" separator="," close=")" >
                #{chargingStationId}
            </foreach>
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and ss.tenant_id = #{tenantId}
        </if>
        <if test="number==1">
            and ss.charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{sysUserId})
        </if>
        <if test="number==2">
            and ss.charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{sysUserId})
        </if>
        and ss.operator_id is not null
        and ss.charging_mode is not null
        group by ss.charging_mode
    </select>

    <select id="getStatisticsTimeHistoryOrderId" resultType="int">
        select count(statistics_time_interval_id) from xhpc_statistics_time_interval where history_order_id=#{historyOrderId}
    </select>
    <select id="getStatisticsStationHistoryOrderId" resultType="int">
        select count(statistics_station_id) from xhpc_statistics_station where history_order_id=#{historyOrderId} and type=#{type}
    </select>

    <select id="getTodayStatusNumber" resultType="map">
        SELECT
            COUNT(status) value,
            case  when status=-1 then "无效订单"
            when status=0 then "充电中订单"
            when status=1 then "自动结算订单"
            when status=2 then "异常订单"
            when status=3 then "平台结算订单"
            else "其他订单"
            end name
        FROM
            xhpc_charge_order
        WHERE
            create_time &gt;=#{beginOfDay} and create_time &lt;= #{endOfDay}
        <if test="operatorId !=null">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId})
        </if>
        <if test="status==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{logOperatorId})
        </if>
        <if test="status==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{logOperatorId})
        </if>
        group by status
    </select>

    <select id="getTodayOrderNumber" resultType="int">
        SELECT
        COUNT(charge_order_id) number
        FROM
        xhpc_charge_order
        WHERE
        create_time &gt;=#{beginOfDay} and create_time &lt;= #{endOfDay}
        <if test="operatorId !=null">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId})
        </if>
        <if test="status==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{logOperatorId})
        </if>
        <if test="status==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{logOperatorId})
        </if>
    </select>

    <select id="getTodayNUmber" resultType="int">
        SELECT
        COUNT(charge_order_id) number
        FROM
        xhpc_charge_order
        WHERE
        create_time &gt;=#{beginOfDay} and create_time &lt;= #{endOfDay}
        <if test="operatorId !=null">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId})
        </if>
        <if test="status==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{logOperatorId})
        </if>
        <if test="status==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{logOperatorId})
        </if>
    </select>

    <select id="getTodayDegreeNUmber" resultType="int">
        SELECT
        IFNULL(sum(total_power),0) number
        FROM
        xhpc_history_order
        WHERE
        end_time &gt;=#{beginOfDay} and end_time &lt;= #{endOfDay}
        <if test="operatorId !=null and operatorId !=''">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId})
        </if>
        <if test="status==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{logOperatorId})
        </if>
        <if test="status==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{logOperatorId})
        </if>
    </select>

    <select id="getTodayAmount" resultType="double">
        SELECT
        IFNULL(sum(total_price),0) number
        FROM
        xhpc_history_order
        WHERE
        end_time &gt;=#{beginOfDay} and end_time &lt;= #{endOfDay}
        <if test="operatorId !=null and ''!=operatorId">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId})
        </if>
        <if test="status==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{logOperatorId})
        </if>
        <if test="status==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{logOperatorId})
        </if>
    </select>

    <select id="getTerminal" resultType="String">
        select serial_number as serialNumber
        from xhpc_terminal
        where del_flag = 0
        <if test="operatorId !=null and ''!=operatorId">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and charging_pile_id=#{chargingPileId}
        </if>
        <if test="status==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{logOperatorId})
        </if>
        <if test="status==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{logOperatorId})
        </if>
    </select>

    <select id="getDateOrder" resultType="map">
        select
            ifnull(sum(total_power),0) totalPower,
            ifnull(sum(total_price),0) totalPrice,
            ifnull(sum(power_price_total),0) powerPriceTotal,
            ifnull(sum(service_price_total),0)servicePriceTotal,
        <if test="type!=null and type ==4">
            date_format(end_time, '%Y-%m') time
        </if>
        <if test="type !=4">
            DATE_FORMAT(end_time, '%Y-%m-%d') time
        </if>
        from xhpc_history_order
        where end_time &gt;=#{beginOfDay} and end_time &lt;= #{endOfDay}
        <if test="operatorId !=null and ''!=operatorId">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId})
        </if>
        <if test="status==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{logOperatorId})
        </if>
        <if test="status==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{logOperatorId})
        </if>
        GROUP BY time
        order by end_time
    </select>

    <select id="getDateOrderNUmber" resultType="int">
        select
        IFNULL(sum(total_power),0) totalPower
        from xhpc_history_order
        where end_time &gt;=#{beginOfDay} and end_time &lt;= #{endOfDay}
        <if test="operatorId !=null and ''!=operatorId">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId})
        </if>
        <if test="status==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{logOperatorId})
        </if>
        <if test="status==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{logOperatorId})
        </if>
    </select>

    <select id="getDateOrderCount" resultType="map">
        select
        count(history_order_id) number,
        <if test="type!=null and type ==4">
            date_format(end_time, '%Y-%m') time
        </if>
        <if test="type !=4">
            DATE_FORMAT(end_time, '%Y-%m-%d') time
        </if>
        from xhpc_history_order
        where end_time &gt;=#{beginOfDay} and end_time &lt;= #{endOfDay}
        <if test="operatorId !=null and ''!=operatorId">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId})
        </if>
        <if test="status==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{logOperatorId})
        </if>
        <if test="status==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{logOperatorId})
        </if>
        GROUP BY time
        order by end_time
    </select>

    <select id="getDateOrderCountNUmber" resultType="int">
        select
        count(history_order_id) number
        from xhpc_history_order
        where end_time &gt;=#{beginOfDay} and end_time &lt;= #{endOfDay}
        <if test="operatorId !=null and ''!=operatorId">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{operatorId})
        </if>
        <if test="tenantId !=null and tenantId !=''">
            and tenant_id = #{tenantId}
        </if>
        <if test="chargingStationId !=null">
            and charging_station_id=#{chargingStationId}
        </if>
        <if test="chargingPileId !=null">
            and terminal_id in (select terminal_id from xhpc_terminal where charging_pile_id=#{chargingPileId})
        </if>
        <if test="status==1">
            and charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{logOperatorId})
        </if>
        <if test="status==2">
            and charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{logOperatorId})
        </if>
    </select>
</mapper>
