<?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
              sum(act_price) actPrice,
              sum(act_power_price) actPowerPrice,
              sum(act_service_price) actServicePrice,
              sum(charging_degree) chargingDegree,
              sum(charging_time) chargingTime,
              sum(charging_number) chargingNumber,
              sum(power_price) powerPrice,
              sum(service_price) servicePrice,
              sum(total_price) totalPrice,
              sum(promotion_discount) promotionDiscount,
              sum(internet_commission) internetCommission,
              sum(internet_svc_commission) internetSvcCommission,
              sum(platform_commission) platformCommission,
              sum(platform_svc_commisssion) platformSvcCommisssion,
              sum(operation_commission) operationCommission,
              sum(operation_svc_commission) 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
        <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>
        group by status
        order by status
    </select>

    <select id="getDateIntervalPage" resultType="map">
        select
        sum(charging_degree) chargingDegree,
        sum(charging_time) chargingTime,
        sum(charging_number) chargingNumber,
        sum(power_price) powerPrice,
        sum(service_price) servicePrice,
        sum(total_price) totalPrice,
        sum(act_price) actPrice,
        sum(act_power_price) actPowerPrice,
        sum(act_service_price) actServicePrice,
        sum(promotion_discount) promotionDiscount,
        sum(internet_commission) internetCommission,
        sum(internet_svc_commission) internetSvcCommission,
        sum(platform_commission) platformCommission,
        sum(platform_svc_commisssion) platformSvcCommisssion,
        sum(operation_commission) operationCommission,
        sum(operation_svc_commission) operationSvcCommission,
        DATE_FORMAT(create_time,'%Y-%m-%d') createTime
        from xhpc_statistics_station
        where del_flag=0 and type=1
        <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>
        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
        sum(ss.charging_degree) chargingDegree,
        sum(ss.charging_time) chargingTime,
        sum(ss.charging_number) chargingNumber,
        sum(ss.power_price) powerPrice,
        sum(ss.service_price) servicePrice,
        sum(ss.total_price) totalPrice,
        sum(ss.act_price) actPrice,
        sum(ss.act_power_price) actPowerPrice,
        sum(ss.act_service_price) actServicePrice,
        sum(ss.promotion_discount) promotionDiscount,
        sum(ss.internet_commission) internetCommission,
        sum(ss.internet_svc_commission) internetSvcCommission,
        sum(ss.platform_commission) platformCommission,
        sum(ss.platform_svc_commisssion) platformSvcCommisssion,
        sum(ss.operation_commission) operationCommission,
        sum(ss.operation_svc_commission) 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
        <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="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>
        group by ss.charging_station_id
    </select>

    <select id="getOperatorIntervalPage" resultType="map">
        select
        sum(ss.charging_degree) chargingDegree,
        sum(ss.charging_time) chargingTime,
        sum(ss.charging_number) chargingNumber,
        sum(ss.power_price) powerPrice,
        sum(ss.service_price) servicePrice,
        sum(ss.total_price) totalPrice,
        sum(ss.act_price) actPrice,
        sum(ss.act_power_price) actPowerPrice,
        sum(ss.act_service_price) actServicePrice,
        sum(ss.promotion_discount) promotionDiscount,
        sum(ss.internet_commission) internetCommission,
        sum(ss.internet_svc_commission) internetSvcCommission,
        sum(ss.platform_commission) platformCommission,
        sum(ss.platform_svc_commisssion) platformSvcCommisssion,
        sum(ss.operation_commission) operationCommission,
        sum(ss.operation_svc_commission) 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
        <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="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>
        group by ss.operator_id
    </select>

    <select id="getInternetUserIntervalPage" resultType="map">
        select
        sum(ss.charging_degree) chargingDegree,
        sum(ss.charging_time) chargingTime,
        sum(ss.charging_number) chargingNumber,
        sum(ss.power_price) powerPrice,
        sum(ss.service_price) servicePrice,
        sum(ss.total_price) totalPrice,
        sum(ss.act_price) actPrice,
        sum(ss.act_power_price) actPowerPrice,
        sum(ss.act_service_price) actServicePrice,
        sum(ss.promotion_discount) promotionDiscount,
        sum(ss.internet_commission) internetCommission,
        sum(ss.internet_svc_commission) internetSvcCommission,
        sum(ss.platform_commission) platformCommission,
        sum(ss.platform_svc_commisssion) platformSvcCommisssion,
        sum(ss.operation_commission) operationCommission,
        sum(ss.operation_svc_commission) 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
        <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>
        group by ss.internet_user_id
    </select>

    <select id="getTerminalIntervalPage" resultType="map">
        select
        sum(ss.charging_degree) chargingDegree,
        sum(ss.charging_time) chargingTime,
        sum(ss.charging_number) chargingNumber,
        sum(ss.power_price) powerPrice,
        sum(ss.service_price) servicePrice,
        sum(ss.total_price) totalPrice,
        sum(ss.act_price) actPrice,
        sum(ss.act_power_price) actPowerPrice,
        sum(ss.act_service_price) actServicePrice,
        sum(ss.promotion_discount) promotionDiscount,
        sum(ss.internet_commission) internetCommission,
        sum(ss.internet_svc_commission) internetSvcCommission,
        sum(ss.platform_commission) platformCommission,
        sum(ss.platform_svc_commisssion) platformSvcCommisssion,
        sum(ss.operation_commission) operationCommission,
        sum(ss.operation_svc_commission) 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
        <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>
        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 1=1
        <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>
    </select>


    <select id="getOperatorList" resultType="map">
        select
        operator_id as operatorId,
        name as operatorName
        from xhpc_operator
        where 1=1

        <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>
    </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>
    </select>

    <select id="getTerminalList" resultType="map">
        select
        terminal_id as terminalId,
        name as terminalName
        from xhpc_terminal
        where 1=1
        <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>

    </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>
        </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>
        </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>
        </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>
        </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>
    </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
        sum(ss.charging_degree) chargingDegree,
        sum(ss.charging_time) chargingTime,
        sum(ss.charging_number) chargingNumber,
        sum(ss.power_price) powerPrice,
        sum(ss.service_price) servicePrice,
        sum(ss.total_price) totalPrice,
        sum(ss.act_price) actPrice,
        sum(ss.act_power_price) actPowerPrice,
        sum(ss.act_service_price) actServicePrice,
        sum(ss.promotion_discount) promotionDiscount,
        sum(ss.internet_commission) internetCommission,
        sum(ss.internet_svc_commission) internetSvcCommission,
        sum(ss.platform_commission) platformCommission,
        sum(ss.platform_svc_commisssion) platformSvcCommisssion,
        sum(ss.operation_commission) operationCommission,
        sum(ss.operation_svc_commission) operationSvcCommission,
        IF(SUM(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="sourceIds !=null and sourceIds.size()>0">
            and ss.charging_mode in
            <foreach collection="sourceIds"   open="(" item="sourceId" separator="," close=")" >
                #{sourceId}
            </foreach>
        </if>
        group by ss.charging_mode
    </select>
</mapper>
