<?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.zsElectric.boot.business.mapper.ChargeOrderInfoMapper">

    <!-- 获取充电订单信息分页列表 -->
    <select id="getChargeOrderInfoPage" resultType="com.zsElectric.boot.business.model.vo.ChargeOrderInfoVO">
        SELECT
        a.id,
        a.user_id,
        a.order_type,
        a.equipment_id,
        a.charge_order_no,
        a.start_time,
        a.end_time,
        a.charge_time,
        a.status,
        a.third_party_total_cost,
        a.third_party_serverfee,
        a.third_party_elecfee,
        a.total_charge,
        a.real_cost,
        a.real_service_cost,
        a.stop_type,
        a.phone_num,
        a.plate_num,
        a.stop_reason,
        a.charge_details,
        a.third_party_station_id,
        a.pre_amt,
        a.real_predict_service_cost,
        a.masp_amount,
        a.masp_real_amount,
        a.total_masp_money,
        a.masp_status,
        a.masp_time,
        a.masp_desc,
        a.discount_money,
        a.discount_desc,
        a.discount_info_id,
        a.real_third_cost,
        a.firm_id,
        a.firm_price,
        a.coupon_price,
        a.coupon_id,
        a.remark,
        a.create_by,
        a.create_time,
        a.update_by,
        a.update_time,
        a.version,
        a.is_deleted,
        b.phone
        FROM
        c_charge_order_info a
        left join c_user_info b ON a.user_id = b.id
        <where>
            a.is_deleted = 0
            <if test="queryParams.equipmentId != null">
                AND a.equipment_id = #{queryParams.equipmentId}
            </if>
            <if test="queryParams.maspStatus != null">
                AND a.masp_status = #{queryParams.maspStatus}
            </if>
            <if test="queryParams.status != null">
                AND a.status = #{queryParams.status}
            </if>
            <if test="queryParams.startTime != null">
                AND a.create_time <![CDATA[  >=  ]]> #{queryParams.startTime,jdbcType=DATE}
            </if>
            <if test="queryParams.endTime != null">
                AND a.create_time <![CDATA[  <=  ]]> #{queryParams.endTime,jdbcType=DATE}
            </if>
            <if test="queryParams.stopType != null">
                AND a.stop_type = #{queryParams.stopType}
            </if>
            <if test="queryParams.orderType != null">
                AND a.order_type = #{queryParams.orderType}
            </if>
            <if test="queryParams.phoneNum != null and queryParams.phoneNum != ''">
                AND b.phone like concat('%',#{queryParams.phoneNum},'%')
            </if>
            <if test="queryParams.chargeOrderNo != null and queryParams.chargeOrderNo != ''">
                AND a.charge_order_no like concat('%',#{queryParams.chargeOrderNo},'%')
            </if>
        </where>
        ORDER BY a.create_time DESC
    </select>
    <select id="getPage" resultType="com.zsElectric.boot.business.model.vo.ChargeOrderInfoVO">
        SELECT
        coi.id,
        coi.user_id,
        coi.order_type,
        coi.equipment_id,
        coi.charge_order_no,
        coi.start_time,
        coi.end_time,
        coi.charge_time,
        coi.status,
        coi.third_party_total_cost,
        coi.third_party_serverfee,
        coi.third_party_elecfee,
        coi.total_charge,
        coi.real_cost,
        coi.real_service_cost,
        coi.stop_type,
        coi.phone_num,
        coi.plate_num,
        coi.stop_reason,
        coi.charge_details,
        coi.third_party_station_id,
        coi.pre_amt,
        coi.real_predict_service_cost,
        coi.masp_amount,
        coi.masp_real_amount,
        coi.total_masp_money,
        coi.masp_status,
        coi.masp_time,
        coi.masp_desc,
        coi.discount_money,
        coi.discount_desc,
        coi.discount_info_id,
        coi.real_third_cost,
        coi.firm_id,
        coi.firm_price,
        coi.coupon_price,
        coi.coupon_id,
        coi.remark,
        coi.create_by,
        coi.create_time,
        coi.update_by,
        coi.update_time,
        coi.version,
        coi.is_deleted,
        pci.connector_id,
        pci.connector_name,
        psi.station_name
        FROM
        c_charge_order_info coi
        left JOIN third_party_connector_info pci ON coi.connector_id = pci.connector_id
        LEFT JOIN third_party_station_info psi ON pci.station_id = psi.station_id
        <where>
            coi.is_deleted = 0
            <if test="queryParams.userId != null">
                AND coi.user_id = #{queryParams.userId}
            </if>
            <if test="queryParams.status != null">
                AND coi.status = #{queryParams.status}
            </if>
            <if test="queryParams.startTime != null">
                AND coi.create_time <![CDATA[  >=  ]]> #{queryParams.startTime,jdbcType=DATE}
            </if>
            <if test="queryParams.endTime != null">
                AND coi.create_time <![CDATA[  <=  ]]> #{queryParams.endTime,jdbcType=DATE}
            </if>
        </where>
        ORDER BY
        create_time DESC
    </select>
    <select id="queryOrder" resultType="com.zsElectric.boot.business.model.vo.ChargeOrderInfoVO">
        SELECT
        coi.id,
        coi.user_id,
        coi.order_type,
        coi.equipment_id,
        coi.charge_order_no,
        coi.start_time,
        coi.end_time,
        coi.charge_time,
        coi.status,
        coi.third_party_total_cost,
        coi.third_party_serverfee,
        coi.third_party_elecfee,
        coi.total_charge,
        coi.real_cost,
        coi.real_service_cost,
        coi.stop_type,
        coi.phone_num,
        coi.plate_num,
        coi.stop_reason,
        coi.charge_details,
        coi.third_party_station_id,
        coi.pre_amt,
        coi.real_predict_service_cost,
        coi.masp_amount,
        coi.masp_real_amount,
        coi.total_masp_money,
        coi.masp_status,
        coi.masp_time,
        coi.masp_desc,
        coi.discount_money,
        coi.discount_desc,
        coi.discount_info_id,
        coi.real_third_cost,
        coi.firm_id,
        coi.firm_price,
        coi.coupon_price,
        coi.coupon_id,
        coi.remark,
        coi.create_by,
        coi.create_time,
        coi.update_by,
        coi.update_time,
        coi.version,
        coi.is_deleted,
        pci.connector_id,
        pci.connector_name,
        psi.station_name
        FROM
        c_charge_order_info coi
        left JOIN third_party_connector_info pci ON coi.connector_id = pci.connector_id
        LEFT JOIN third_party_station_info psi ON pci.station_id = psi.station_id
        <where>
            coi.is_deleted = 0
            <if test="chargeOrderNo != null and chargeOrderNo !=''">
                AND coi.charge_order_no = #{chargeOrderNo}
            </if>
        </where>
    </select>

</mapper>
