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

    <resultMap type="com.xhpc.order.domain.XhpcHistoryOrder" id="XhpcHistoryOrderResult">
        <id column="history_order_id" jdbcType="BIGINT" property="historyOrderId"/>
        <result column="charging_station_id" jdbcType="BIGINT" property="chargingStationId"/>
        <result column="charge_order_id" jdbcType="BIGINT" property="chargeOrderId"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="terminal_id" jdbcType="BIGINT" property="terminalId"/>
        <result column="serial_number" jdbcType="VARCHAR" property="serialNumber"/>
        <result column="internet_serial_number" jdbcType="VARCHAR" property="internetSerialNumber"/>
        <result column="power_price_total" jdbcType="DECIMAL" property="powerPriceTotal"/>
        <result column="service_price_total" jdbcType="DECIMAL" property="servicePriceTotal"/>
        <result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
        <result column="promotion_discount" jdbcType="DECIMAL" property="promotionDiscount"/>
        <result column="act_price" jdbcType="DECIMAL" property="actPrice"/>
        <result column="act_power_price" jdbcType="DECIMAL" property="actPowerPrice"/>
        <result column="act_service_price" jdbcType="DECIMAL" property="actServicePrice"/>
        <result column="internet_commission" jdbcType="DECIMAL" property="internetCommission"/>
        <result column="internet_svc_commission" jdbcType="DECIMAL" property="internetSvcCommission"/>
        <result column="platform_commission" jdbcType="DECIMAL" property="platformCommission"/>
        <result column="platform_svc_commisssion" jdbcType="DECIMAL" property="platformSvcCommisssion"/>
        <result column="operation_commission" jdbcType="DECIMAL" property="operationCommission"/>
        <result column="operation_svc_commission" jdbcType="DECIMAL" property="operationSvcCommission"/>
        <result column="start_soc" jdbcType="VARCHAR" property="startSoc"/>
        <result column="end_soc" jdbcType="VARCHAR" property="endSoc"/>
        <result column="reconciliation_status" jdbcType="INTEGER" property="reconciliationStatus"/>
        <result column="sorting_status" jdbcType="INTEGER" property="sortingStatus"/>
        <result column="type" jdbcType="TINYINT" property="type"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="create_by" jdbcType="VARCHAR" property="createBy"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="state" jdbcType="INTEGER" property="state"/>
        <result column="vin_normal" jdbcType="VARCHAR" property="vinNormal"/>
        <result column="search_value" jdbcType="VARCHAR" property="searchValue"/>
        <result column="operator_id_evcs" jdbcType="VARCHAR" property="operatorIdEvcs"/>
        <result column="charge_model_evcs" jdbcType="INTEGER" property="chargeModelEvcs"/>
        <result column="connector_power_evcs" jdbcType="DOUBLE" property="connectorPowerEvcs"/>
        <result column="meter_value_end_evcs" jdbcType="DOUBLE" property="meterValueEndEvcs"/>
        <result column="meter_value_start_evcs" jdbcType="DOUBLE" property="meterValueStartEvcs"/>
        <result column="operator_id3rdpty_evcs" jdbcType="VARCHAR" property="operatorId3rdptyEvcs"/>
        <result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
        <result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
        <result column="stop_reason_evcs" jdbcType="INTEGER" property="stopReasonEvcs"/>
        <result column="rate_model_id" jdbcType="BIGINT" property="rateModelId"/>
        <result column="total_power" jdbcType="DOUBLE" property="totalPower"/>
        <result column="user_name_evcs" jdbcType="VARCHAR" property="userNameEvcs"/>
        <result column="phone" jdbcType="VARCHAR" property="phone"/>
    </resultMap>
    <sql id="Base_Column_List">
        history_order_id, charging_station_id, charge_order_id, user_id, terminal_id, serial_number,
        internet_serial_number, power_price_total, service_price_total, total_price, promotion_discount,
        act_price, act_power_price, act_service_price, internet_commission, internet_svc_commission,
        platform_commission, platform_svc_commisssion, operation_commission, operation_svc_commission,
        start_soc, end_soc, reconciliation_status, sorting_status, `type`, `status`, del_flag,
        create_time, create_by, update_time, update_by, remark, `state`, vin_normal, search_value,
        operator_id_evcs, charge_model_evcs, connector_power_evcs, meter_value_end_evcs,
        meter_value_start_evcs, operator_id3rdpty_evcs, start_time, stop_reason_evcs, total_power,
        user_name_evcs, phone, rate_model_id
    </sql>
    <insert id="insert" parameterType="com.xhpc.order.domain.XhpcHistoryOrder" useGeneratedKeys="true"
            keyProperty="historyOrderId">
        INSERT INTO xhpc_history_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="chargingStationId != null">
                charging_station_id,
            </if>
            <if test="chargeOrderId != null">
                charge_order_id,
            </if>
            <if test="userId != null">
                user_id,
            </if>
            <if test="terminalId != null">
                terminal_id,
            </if>
            <if test="serialNumber != null">
                serial_number,
            </if>
            <if test="internetSerialNumber != null">
                internet_serial_number,
            </if>
            <if test="powerPriceTotal != null">
                power_price_total,
            </if>
            <if test="servicePriceTotal != null">
                service_price_total,
            </if>
            <if test="totalPrice != null">
                total_price,
            </if>
            <if test="promotionDiscount != null">
                promotion_discount,
            </if>
            <if test="actPrice != null">
                act_price,
            </if>
            <if test="actPowerPrice != null">
                act_power_price,
            </if>
            <if test="actServicePrice != null">
                act_service_price,
            </if>
            <if test="internetCommission != null">
                internet_commission,
            </if>
            <if test="internetSvcCommission != null">
                internet_svc_commission,
            </if>
            <if test="platformCommission != null">
                platform_commission,
            </if>
            <if test="platformSvcCommisssion != null">
                platform_svc_commisssion,
            </if>
            <if test="operationCommission != null">
                operation_commission,
            </if>
            <if test="operationSvcCommission != null">
                operation_svc_commission,
            </if>
            <if test="startSoc != null">
                start_soc,
            </if>
            <if test="endSoc != null">
                end_soc,
            </if>
            <if test="reconciliationStatus != null">
                reconciliation_status,
            </if>
            <if test="sortingStatus != null">
                sorting_status,
            </if>
            <if test="type != null">
                `type`,
            </if>
            <if test="status != null">
                `status`,
            </if>
            <if test="delFlag != null">
                del_flag,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="createBy != null">
                create_by,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="updateBy != null">
                update_by,
            </if>
            <if test="remark != null">
                remark,
            </if>
            <if test="state != null">
                `state`,
            </if>
            <if test="vinNormal != null">
                vin_normal,
            </if>
            <if test="searchValue != null">
                search_value,
            </if>
            <if test="operatorIdEvcs != null">
                operator_id_evcs,
            </if>
            <if test="chargeModelEvcs != null">
                charge_model_evcs,
            </if>
            <if test="connectorPowerEvcs != null">
                connector_power_evcs,
            </if>
            <if test="meterValueEndEvcs != null">
                meter_value_end_evcs,
            </if>
            <if test="meterValueStartEvcs != null">
                meter_value_start_evcs,
            </if>
            <if test="operatorId3rdptyEvcs != null">
                operator_id3rdpty_evcs,
            </if>
            <if test="startTime != null">
                start_time,
            </if>
            <if test="endTime != null">
                end_time,
            </if>
            <if test="stopReasonEvcs != null">
                stop_reason_evcs,
            </if>
            <if test="null != rateModelId">
                rate_model_id,
            </if>
            <if test="totalPower != null">
                total_power,
            </if>
            <if test="userNameEvcs != null">
                user_name_evcs,
            </if>
            <if test="phone != null">
                phone,
            </if>
            <if test="chargingMode != null">
                charging_mode,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="chargingStationId != null">
                #{chargingStationId,jdbcType=BIGINT},
            </if>
            <if test="chargeOrderId != null">
                #{chargeOrderId,jdbcType=BIGINT},
            </if>
            <if test="userId != null">
                #{userId,jdbcType=BIGINT},
            </if>
            <if test="terminalId != null">
                #{terminalId,jdbcType=BIGINT},
            </if>
            <if test="serialNumber != null">
                #{serialNumber,jdbcType=VARCHAR},
            </if>
            <if test="internetSerialNumber != null">
                #{internetSerialNumber,jdbcType=VARCHAR},
            </if>
            <if test="powerPriceTotal != null">
                #{powerPriceTotal,jdbcType=DECIMAL},
            </if>
            <if test="servicePriceTotal != null">
                #{servicePriceTotal,jdbcType=DECIMAL},
            </if>
            <if test="totalPrice != null">
                #{totalPrice,jdbcType=DECIMAL},
            </if>
            <if test="promotionDiscount != null">
                #{promotionDiscount,jdbcType=DECIMAL},
            </if>
            <if test="actPrice != null">
                #{actPrice,jdbcType=DECIMAL},
            </if>
            <if test="actPowerPrice != null">
                #{actPowerPrice,jdbcType=DECIMAL},
            </if>
            <if test="actServicePrice != null">
                #{actServicePrice,jdbcType=DECIMAL},
            </if>
            <if test="internetCommission != null">
                #{internetCommission,jdbcType=DECIMAL},
            </if>
            <if test="internetSvcCommission != null">
                #{internetSvcCommission,jdbcType=DECIMAL},
            </if>
            <if test="platformCommission != null">
                #{platformCommission,jdbcType=DECIMAL},
            </if>
            <if test="platformSvcCommisssion != null">
                #{platformSvcCommisssion,jdbcType=DECIMAL},
            </if>
            <if test="operationCommission != null">
                #{operationCommission,jdbcType=DECIMAL},
            </if>
            <if test="operationSvcCommission != null">
                #{operationSvcCommission,jdbcType=DECIMAL},
            </if>
            <if test="startSoc != null">
                #{startSoc,jdbcType=VARCHAR},
            </if>
            <if test="endSoc != null">
                #{endSoc,jdbcType=VARCHAR},
            </if>
            <if test="reconciliationStatus != null">
                #{reconciliationStatus,jdbcType=INTEGER},
            </if>
            <if test="sortingStatus != null">
                #{sortingStatus,jdbcType=INTEGER},
            </if>
            <if test="type != null">
                #{type,jdbcType=TINYINT},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
            <if test="delFlag != null">
                #{delFlag,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createBy != null">
                #{createBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateBy != null">
                #{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="remark != null">
                #{remark,jdbcType=VARCHAR},
            </if>
            <if test="state != null">
                #{state,jdbcType=INTEGER},
            </if>
            <if test="vinNormal != null">
                #{vinNormal,jdbcType=VARCHAR},
            </if>
            <if test="searchValue != null">
                #{searchValue,jdbcType=VARCHAR},
            </if>
            <if test="operatorIdEvcs != null">
                #{operatorIdEvcs,jdbcType=VARCHAR},
            </if>
            <if test="chargeModelEvcs != null">
                #{chargeModelEvcs,jdbcType=INTEGER},
            </if>
            <if test="connectorPowerEvcs != null">
                #{connectorPowerEvcs,jdbcType=DOUBLE},
            </if>
            <if test="meterValueEndEvcs != null">
                #{meterValueEndEvcs,jdbcType=DOUBLE},
            </if>
            <if test="meterValueStartEvcs != null">
                #{meterValueStartEvcs,jdbcType=DOUBLE},
            </if>
            <if test="operatorId3rdptyEvcs != null">
                #{operatorId3rdptyEvcs,jdbcType=VARCHAR},
            </if>
            <if test="startTime != null">
                #{startTime,jdbcType=TIMESTAMP},
            </if>
            <if test="endTime != null">
                #{endTime,jdbcType=TIMESTAMP},
            </if>
            <if test="stopReasonEvcs != null">
                #{stopReasonEvcs,jdbcType=INTEGER},
            </if>
            <if test="null != rateModelId">
                #{rateModelId},
            </if>
            <if test="totalPower != null">
                #{totalPower,jdbcType=DOUBLE},
            </if>
            <if test="userNameEvcs != null">
                #{userNameEvcs,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                #{phone,jdbcType=VARCHAR},
            </if>
            <if test="chargingMode != null">
                #{chargingMode,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>

    <update id="update" parameterType="com.xhpc.order.domain.XhpcHistoryOrder">
        UPDATE xhpc_history_order
        <set>
            <if test="chargingStationId != null">
                charging_station_id = #{chargingStationId},
            </if>
            <if test="chargeOrderId != null">
                charge_order_id = #{chargeOrderId},
            </if>
            <if test="userId != null">
                user_id = #{userId},
            </if>
            <if test="terminalId != null">
                terminal_id = #{terminalId},
            </if>
            <if test="serialNumber != null">
                serial_number = #{serialNumber},
            </if>
            <if test="internetSerialNumber != null">
                internet_serial_number = #{internetSerialNumber},
            </if>
            <if test="powerPriceTotal != null">
                power_price_total = #{powerPriceTotal},
            </if>
            <if test="servicePriceTotal != null">
                service_price_total = #{servicePriceTotal},
            </if>
            <if test="totalPrice != null">
                total_price = #{totalPrice},
            </if>
            <if test="promotionDiscount != null">
                promotion_discount = #{promotionDiscount},
            </if>
            <if test="actPrice != null">
                act_price = #{actPrice},
            </if>
            <if test="actPowerPrice != null">
                act_power_price = #{actPowerPrice},
            </if>
            <if test="actServicePrice != null">
                act_service_price = #{actServicePrice},
            </if>
            <if test="internetCommission != null">
                internet_commission = #{internetCommission},
            </if>
            <if test="internetSvcCommission != null">
                internet_svc_commission = #{internetSvcCommission},
            </if>
            <if test="platformCommission != null">
                platform_commission = #{platformCommission},
            </if>
            <if test="platformSvcCommisssion != null">
                platform_svc_commisssion = #{platformSvcCommisssion},
            </if>
            <if test="operationCommission != null">
                operation_commission = #{operationCommission},
            </if>
            <if test="operationSvcCommission != null">
                operation_svc_commission = #{operationSvcCommission},
            </if>
            <if test="startSoc != null">
                start_soc = #{startSoc},
            </if>
            <if test="endSoc != null">
                end_soc = #{endSoc},
            </if>
            <if test="reconciliationStatus != null">
                reconciliation_status = #{reconciliationStatus},
            </if>
            <if test="sortingStatus != null">
                sorting_status = #{sortingStatus},
            </if>
            <if test="type != null">
                `type` = #{type},
            </if>
            <if test="status != null">
                `status` = #{status},
            </if>
            <if test="delFlag != null">
                del_flag = #{delFlag},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="createBy != null">
                create_by = #{createBy},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="updateBy != null">
                update_by = #{updateBy},
            </if>
            <if test="remark != null">
                remark = #{remark},
            </if>
            <if test="state != null">
                `state` = #{state},
            </if>
            <if test="vinNormal != null">
                vin_normal = #{vinNormal},
            </if>
            <if test="searchValue != null">
                search_value = #{searchValue},
            </if>
            <if test="operatorIdEvcs != null">
                operator_id_evcs = #{operatorIdEvcs},
            </if>
            <if test="chargeModelEvcs != null">
                charge_model_evcs = #{chargeModelEvcs},
            </if>
            <if test="connectorPowerEvcs != null">
                connector_power_evcs = #{connectorPowerEvcs},
            </if>
            <if test="meterValueEndEvcs != null">
                meter_value_end_evcs = #{meterValueEndEvcs},
            </if>
            <if test="meterValueStartEvcs != null">
                meter_value_start_evcs = #{meterValueStartEvcs},
            </if>
            <if test="operatorId3rdptyEvcs != null">
                operator_id3rdpty_evcs = #{operatorId3rdptyEvcs},
            </if>
            <if test="startTime != null">
                start_time = #{startTime},
            </if>
            <if test="stopReasonEvcs != null">
                stop_reason_evcs = #{stopReasonEvcs},
            </if>
            <if test="totalPower != null">
                total_power = #{totalPower},
            </if>
            <if test="userNameEvcs != null">
                user_name_evcs = #{userNameEvcs},
            </if>
            <if test="phone != null">
                phone = #{phone},
            </if>
        </set>
        where history_order_id = #{historyOrderId}
    </update>

    <select id="info" parameterType="java.lang.Long" resultMap="XhpcHistoryOrderResult">
       select *
        from xhpc_history_order xho
        where xho.del_flag = 0 and xho.history_order_id = #{historyOrderId}
    </select>

    <update id="updateReconciliation" parameterType="java.lang.String">
        update xhpc_history_order set reconciliation_status = #{status} where history_order_id in
        <foreach collection="xhpcHistoryOrderIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>

    <update id="updateSorting" parameterType="java.lang.String">
        update xhpc_history_order set sorting_status = #{status} where history_order_id in
        <foreach collection="xhpcHistoryOrderIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>

    <select id="list" resultType="map">
        SELECT
            ho.history_order_id as historyOrderId,
            ho.serial_number as serialNumber,
            ho.create_time as createTime,
            co.status as status,
            cs.name as chargingStationName,
            te.name as terminalName,
            ho.act_price as actPrice,
            co.charging_degree as chargingDegree,
            co.charging_time as chargingTime
        FROM xhpc_history_order as ho
        LEFT JOIN xhpc_charging_station as cs on cs.charging_station_id = ho.charging_station_id
        LEFT JOIN xhpc_terminal as te on te.terminal_id = ho.terminal_id
        left join xhpc_charge_order as co on co.charge_order_id =ho.charge_order_id
        where ho.status=0 and ho.del_flag=0 and ho.user_id =#{userId}
        order by ho.create_time desc
    </select>

    <select id="gethistotyOrderMessage" resultType="map">
        SELECT
            ho.history_order_id as historyOrderId,
            ho.serial_number as serialNumber,
            ho.type as type,
            cs.name as chargingStationName,
            te.name as terminalName,
            ho.act_price as actPrice,
            ho.act_power_price as actPowerPrice,
            co.charging_time as chargingTime,
            co.charging_degree as chargingDegree,
            DATE_FORMAT(co.start_time,'%m月%d日') as daysOne,
            DATE_FORMAT(co.start_time,'%H:%i:%s') as timeOne,
            DATE_FORMAT(co.end_time,'%m月%d日') as daysTwo,
            DATE_FORMAT(co.end_time,'%H:%i:%s') as timeTwo,
            co.status as status,
            co.type as type,
        case  when co.type=40 then "APP远程停止"
              when co.type=41 then "SOC达到100%"
              when co.type=42 then "充电电量满足设定条件"
              when co.type=43 then "充电金额满足设定条件"
              when co.type=44 then "充电时间满足设定条件"
              when co.type=45 then "手动停止充电"
              when co.type=46 then "手动停止充电."
              when co.type=47 then "手动停止充电.."
              when co.type=48 then "急停停止充电"
              when co.type=49 then "手动停止充电..."
              else "手动停止充电!"
              end typeName
        FROM xhpc_history_order as ho
        LEFT JOIN xhpc_charging_station as cs on cs.charging_station_id = ho.charging_station_id
        LEFT JOIN xhpc_terminal as te on te.terminal_id = ho.terminal_id
        left join xhpc_charge_order as co on co.charge_order_id =ho.charge_order_id
        where ho.status=0 and ho.del_flag=0
        <if test="userId !=null">
            and ho.user_id =#{userId}
        </if>
        <if test="historyOrderId !=null">
            and ho.history_order_id =#{historyOrderId}
        </if>
        <if test="chargingOrderId !=null">
            and ho.charge_order_id =#{chargingOrderId}
        </if>
        order by ho.create_time desc
    </select>

    <select id="getListPage" resultType="map">
        select
          ho.history_order_id as historyOrderId,
          co.charge_order_id as chargeOrderId,
          ho.serial_number as serialNumber,
          ct.name as chargingStationName,
          ter.pile_serial_number as pileSerialNumber,
          ter.name as terminalName,
          op.operator_id as operatorId,
          op.name as operatorName,
          cp.power as power,
          cp.type as type,
          ho.type as orderType,
          ho.start_soc as startSoc,
          ho.end_soc as endSoc,
          ho.vin_normal as vinCode,
          ho.internet_serial_number as internetSerialNumber,
          ho.evcs_order_no as evcsOrderNo,
          ho.total_price as totalPrice,
          ho.act_price as actPrice,
          ho.confirm_Result as confirmResult,
          co.charging_time as chargingTime,
          co.charging_degree as chargingDegree,
          co.start_time as startTime,
          co.end_time as endTime,
          co.update_time as updateTime,
          co.source as source,
          co.Plate_num as plateNum,
          dispute_order_status as disputeOrderStatus,
          inu.phone as internetUserPhone,
          inu.name as internetName,
          apu.phone as appUserPhone
        from xhpc_history_order as ho
        left join xhpc_charging_station as ct on ct.charging_station_id = ho.charging_station_id
        left join xhpc_operator as op on op.operator_id = ct.operator_id
        left join xhpc_charge_order co on co.charge_order_id = ho.charge_order_id
        left join xhpc_terminal as ter on ter.terminal_id = ho.terminal_id
        left join xhpc_charging_pile as cp on cp.charging_pile_id = ter.charging_pile_id
        left join et_dispute_orders as ed on ed.start_charge_seq = ho.internet_serial_number and ed.dispute_order_status !=2
        left join xhpc_internet_user as inu on inu.internet_user_id = ho.user_id and ho.internet_serial_number is not null
        left join xhpc_app_user as apu on apu.app_user_id = ho.user_id and ho.internet_serial_number is null
        where ho.status =0 and ho.del_flag=0
        <if test="type !=null">
            and ho.type=#{type}
        </if>
        <if test="source !=null">
            and co.source=#{source}
        </if>
        <if test="plateNum !=null and plateNum !=''">
            and co.Plate_num like concat('%', #{plateNum}, '%')
        </if>
        <if test="internetId !=null">
            and inu.internet_user_id=#{internetId}
        </if>
        <if test="internetSerialNumber !=null and internetSerialNumber !=''">
            and ho.internet_serial_number like concat('%', #{internetSerialNumber}, '%')
        </if>
        <if test="terminalName !=null and terminalName !=''">
            and ter.name like concat('%', #{terminalName}, '%')
        </if>
        <if test="vinCode !=null and vinCode !=''">
            and ho.vin_normal like concat('%', #{vinCode}, '%')
        </if>
        <if test="evcsOrderNo !=null and evcsOrderNo !=''">
            and co.evcs_order_no  like concat('%', #{evcsOrderNo}, '%')
        </if>
        <if test="beginStartTime !=null and beginStartTime !=''">
            and ho.start_time &gt;= #{beginStartTime}
        </if>
        <if test="beginEndTime !=null and beginEndTime !=''">
            and ho.start_time &lt;= #{beginEndTime}
        </if>
        <if test="overStartTime !=null and overStartTime !=''">
            and ho.end_time &gt;= #{overStartTime}
        </if>
        <if test="overEndTime !=null and overEndTime !=''">
            and ho.end_time &lt;= #{overEndTime}
        </if>
        <if test="transactionNumber !=null and transactionNumber !=''">
            and ho.serial_number like concat('%', #{transactionNumber}, '%')
        </if>
        <if test="chargingStationName !=null and chargingStationName !=''">
            and ct.name like concat('%', #{chargingStationName}, '%')
        </if>
        <if test="operatorId !=null">
            and op.operator_id =#{operatorId}
        </if>
        <if test="number==1">
            and co.user_id in (
            SELECT cro.user_id
            FROM xhpc_charge_order cro WHERE cro.source = 0 AND cro.user_id IN ( SELECT app_user_id FROM xhpc_app_user  where phone like concat('%', #{phone}, '%'))
            union
            SELECT cro.user_id FROM xhpc_charge_order cro WHERE cro.source = 1 AND cro.user_id IN (SELECT internet_user_id from xhpc_internet_user where phone like concat('%', #{phone}, '%'))
            )
        </if>
        <if test="number==2">
            <if test="source !=null and source ==0">
                and co.user_id in (
                SELECT cro.user_id FROM xhpc_charge_order cro WHERE cro.source = 0 AND cro.user_id IN ( SELECT app_user_id FROM xhpc_app_user  where phone like concat('%', #{phone}, '%')))
            </if>
            <if test="source !=null and source ==1">
                and co.user_id in (
                SELECT cro.user_id FROM xhpc_charge_order cro WHERE cro.source = 1 AND cro.user_id IN (SELECT internet_user_id from xhpc_internet_user where phone like concat('%', #{phone}, '%')))
            </if>
        </if>
        <if test="number==3">
            <if test="source !=null and source ==0">
                and co.user_id in (
                SELECT cro.user_id FROM xhpc_charge_order cro WHERE cro.source = 0 AND cro.user_id IN ( SELECT app_user_id FROM xhpc_app_user  where phone like concat('%', #{phone}, '%')))
            </if>
            <if test="source !=null and source ==1">
                and co.user_id in (
                SELECT cro.user_id FROM xhpc_charge_order cro WHERE cro.source = 1 AND cro.user_id IN (SELECT internet_user_id from xhpc_internet_user where phone like concat('%', #{phone}, '%')))
            </if>
        </if>
        <if test="status==1">
            and co.charging_station_id in (select charging_station_id from xhpc_charging_station where operator_id=#{userId})
        </if>
        <if test="status==2">
            and co.charging_station_id in (select charging_station_id from xhpc_user_privilege where user_id=#{userId})
        </if>
        order by ho.create_time desc
    </select>

    <select id="getReatTimeList" resultType="map">
        select
          rt.start_time as startTime,
          rt.end_time as endTime,
          ra.power_fee as powerFee,
          ra.service_fee as serviceFee
        from xhpc_rate_time as rt
        left join xhpc_rate ra on rt.rate_id =ra.rate_id
        WHERE
        rt.rate_time_id &gt;= (
        SELECT rate_time_id FROM xhpc_rate_time WHERE rate_model_id = #{rateModelId} AND start_time &lt;= #{startTime} AND replace(end_time, '00:00:00', '23:59:59') &gt;= #{startTime}
        )
        AND rt.rate_time_id &lt;= (
        SELECT rate_time_id FROM xhpc_rate_time WHERE rate_model_id = #{rateModelId} AND start_time &lt;= #{endTime} AND replace(end_time, '00:00:00', '23:59:59') &gt;= #{endTime}
        )
    </select>

    <select id="getById" resultType="map">
        select
          ho.history_order_id as historyOrderId,
          co.charge_order_id as chargeOrderId,
          ho.serial_number as serialNumber,
          ho.internet_serial_number as internetSerialNumber,
          co.source as source,
          ct.name as chargingStationName,
          ter.pile_serial_number as pileSerialNumber,
          ter.name as terminalName,
          op.operator_id as operatorId,
          op.name as operatorName,
          cp.type as type,
          co.type as orderType,
          co.create_time as createTime,
          co.start_time as startTime,
          co.end_time as endTime,
          co.update_time as updateTime,
          co.charging_time as chargingTimeTotal,
          ho.total_price as totalPrice,
          ho.remark as remark,
          ho.promotion_discount as promotionDiscount,
          ho.act_price as actPrice,
          co.erro_remark as erroRemark,
          ho.power_price_total as powerPriceTotal,
          ho.service_price_total as servicePriceTotal,
          ho.internet_commission as internetCommission,
          ho.internet_svc_commission as internetSvcCommission,
          ho.platform_commission as platformCommission,
          ho.platform_svc_commisssion as platformSvcCommisssion,
          ho.operation_commission as operationCommission,
          ho.operation_svc_commission as operationSvcCommission,
          ho.act_power_price as actPowerPrice,
          ho.act_service_price as actServicePrice,
          ed.total_power as sanTotalPower,
          ed.total_money as sanTotalMoney,
          case  when ed.dispute_reason=1 then "交易不存在"
              when ed.dispute_reason=2 then "交易金额错误"
              when ed.dispute_reason=3 then "交易电量错误"
              else "自定义!"
              end sanDisputeReason,
          ed.check_order_seq as sanCheckOrderSeq,
        (SELECT phone FROM xhpc_app_user where app_user_id = co.user_id) as appUserPhone,
        (SELECT phone from xhpc_internet_user where internet_user_id = co.user_id) as internetUserPhone,
        co.Plate_num as plateNum,
        (SELECT name from xhpc_internet_user where internet_user_id = co.user_id and co.source =1) as internetName,
        case  when ho.stop_reason_evcs=40 then "APP远程停止"
              when ho.stop_reason_evcs=41 then "SOC达到100%"
              when ho.stop_reason_evcs=42 then "充电电量满足设定条件"
              when ho.stop_reason_evcs=43 then "充电金额满足设定条件"
              when ho.stop_reason_evcs=44 then "充电时间满足设定条件"
              when ho.stop_reason_evcs=45 then "手动停止充电"
              when ho.stop_reason_evcs=46 then "手动停止充电."
              when ho.stop_reason_evcs=47 then "手动停止充电.."
              when ho.stop_reason_evcs=48 then "急停停止充电"
              when ho.stop_reason_evcs=49 then "手动停止充电..."
              else "手动停止充电!"
              end stopReasonRvcsName
        from xhpc_history_order ho
        left join xhpc_charging_station as ct on ct.charging_station_id = ho.charging_station_id
        left join xhpc_operator as op on op.operator_id = ct.operator_id
        left join xhpc_charge_order co on co.charge_order_id = ho.charge_order_id
        left join xhpc_terminal as ter on ter.terminal_id = ho.terminal_id
        left join xhpc_charging_pile as cp on cp.charging_pile_id = ter.charging_pile_id
        left join et_dispute_orders as ed on ed.start_charge_seq = ho.internet_serial_number and ed.dispute_order_status !=2
        where ho.history_order_id=#{historyOrderId}
    </select>

    <select id="getStatistisList" resultType="com.xhpc.order.dto.XhpcChargeHistoryOrder">
        select
            ho.history_order_id as historyOrderId,
            ho.power_price_total as powerPriceTotal,
            ho.service_price_total as servicePriceTotal,
            ho.promotion_discount as promotionDiscount,
            ho.total_price as totalPrice,
            ho.act_price as actPrice,
            ho.act_power_price as actPowerPrice,
            ho.act_service_price as actServicePrice,
            ho.internet_commission as internetCommission,
            ho.internet_svc_commission as internetSvcCommission,
            ho.platform_commission as platformCommission,
            ho.platform_svc_commisssion as platformSvcCommisssion,
            ho.operation_commission     as operationCommission,
            ho.operation_svc_commission as operationSvcCommission,
            co.source                   as source,
            co.charge_order_id          as chargeOrderId,
            co.charging_station_id      as chargingStationId,
            co.terminal_id              as terminalId,
            ho.start_time               as startTime,
            ho.end_time                 as endTime,
            co.charging_time_number     as chargingTimeNumber,
            co.charging_degree          as chargingDegree,
            co.rate_model_id            as rateModelId,
            cs.operator_id              as operatorId,
            te.charging_pile_id         as chargingPileId,
            co.user_id                  as userId,
            co.user_id                  as internetUserId,
            ho.charging_mode            as chargingMode,
            ho.create_time              as createTime
        from xhpc_history_order ho
                 left join xhpc_charge_order co on co.charge_order_id = ho.charge_order_id
                 left join xhpc_charging_station cs on cs.charging_station_id = co.charging_station_id
                 left join xhpc_terminal as te on te.terminal_id = ho.terminal_id
        where ho.state = #{state} and ho.total_price &gt;0  and ho.end_time &gt; ho.start_time  and ho.power_price_total !=0
        limit 0,#{number}
    </select>


    <update id="updateXhpcHistoryOrder">
        update xhpc_history_order set state = #{state} where history_order_id=#{historyOrderId}
    </update>

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