<?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.user.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"/>
        <result column="charging_mode" jdbcType="VARCHAR" property="chargingMode"/>
        <result column="internet_degree_commission" jdbcType="DECIMAL" property="internetDegreeCommission"/>
        <result column="source" jdbcType="INTEGER" property="source"/>
    </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,
        end_time,
        stop_reason_evcs,
        total_power,
        user_name_evcs,
        phone,
        evcs_order_no,
        confirm_Result,
        rate_model_id,
        charging_mode,
        internet_degree_commission,
        source,
        tenant_id
    </sql>

    <select id="findByCondition" resultType="Map">
        SELECT
        history_order_id as historyOrderId,
        serial_number as serialNumber,
        act_price as actPrice,
        create_time as createTime,
        DATE_FORMAT(create_time,'%Y-%m') AS belongsTime
        FROM
        xhpc_history_order
        WHERE
        user_id = #{invoicedOrdersRequest.userId}
        AND source = #{invoicedOrdersRequest.userType}
        AND create_time &lt;= #{invoicedOrdersRequest.currentTime}
        <if test="lockOrderNumberList!=null">
            AND history_order_id
            <foreach collection="lockOrderNumberList" item="historyOrderId" open="not in (" close=")" separator=",">
                #{historyOrderId}
            </foreach>
        </if>
        ORDER BY
        create_time DESC
    </select>
    <select id="findAllOrdersByCondition" resultType="java.lang.Long">
        SELECT
        count(history_order_id)
        FROM
        xhpc_history_order
        WHERE
        user_id = #{invoicedOrdersRequest.userId}
        AND source = #{invoicedOrdersRequest.userType}
        <if test="lockOrderNumberList!=null">
            AND history_order_id
            <foreach collection="lockOrderNumberList" item="historyOrderId" open="not in (" close=")" separator=",">
                #{historyOrderId}
            </foreach>
        </if>
    </select>
    <select id="findById" resultMap="XhpcHistoryOrderResult">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        xhpc_history_order
        WHERE
        del_flag = 0
        <if test="collection!=null">
            AND history_order_id IN
            <foreach collection="collection" open="(" close=")" item="historyOrderId" separator=",">
                #{historyOrderId}
            </foreach>
        </if>
    </select>

</mapper>
