puzhibing
2026-09-28 83188a6c8ea2f123519378da736382a9136a4331
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?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.ruoyi.order.mapper.TVinChargingOrderMapper">
 
    <sql id="queryCondition">
        <where>
            o.del_flag = 0
            <if test="query.siteIds != null and query.siteIds.size() > 0">
                AND o.site_id IN
                <foreach collection="query.siteIds" item="siteId" open="(" separator="," close=")">#{siteId}</foreach>
            </if>
            <if test="query.code != null and query.code != ''">AND o.code LIKE CONCAT('%', #{query.code}, '%')</if>
            <if test="query.vin != null and query.vin != ''">
                AND (o.actual_vin LIKE CONCAT('%', #{query.vin}, '%') OR o.expected_vin LIKE CONCAT('%', #{query.vin}, '%'))
            </if>
            <if test="query.plateNum != null and query.plateNum != ''">AND o.plate_num LIKE CONCAT('%', #{query.plateNum}, '%')</if>
            <if test="query.phone != null and query.phone != ''">AND o.phone LIKE CONCAT('%', #{query.phone}, '%')</if>
            <if test="query.companyId != null">AND o.company_id = #{query.companyId}</if>
            <if test="query.fleetId != null">AND o.fleet_id = #{query.fleetId}</if>
            <if test="query.status != null">AND o.status = #{query.status}</if>
            <if test="query.siteId != null">AND o.site_id = #{query.siteId}</if>
            <if test="query.pileId != null">AND o.charging_pile_id = #{query.pileId}</if>
            <if test="query.gunId != null">AND o.charging_gun_id = #{query.gunId}</if>
            <if test="query.startTime1 != null and query.startTime1 != ''">AND o.start_time BETWEEN #{query.startTime1} AND #{query.startTime2}</if>
            <if test="query.endTime1 != null and query.endTime1 != ''">AND o.end_time BETWEEN #{query.endTime1} AND #{query.endTime2}</if>
        </where>
    </sql>
 
    <select id="pageList" resultType="com.ruoyi.order.api.vo.ChargingOrderVO">
        SELECT o.*, COALESCE(o.actual_vin, o.expected_vin) AS actual_vin, o.plate_num AS license_plate
        FROM t_vin_charging_order o
        <include refid="queryCondition"/>
        ORDER BY o.create_time DESC, o.id DESC
        LIMIT #{offset}, #{pageSize}
    </select>
 
    <select id="count" resultType="long">
        SELECT COUNT(1) FROM t_vin_charging_order o <include refid="queryCondition"/>
    </select>
 
    <select id="countAppletOrders" resultType="long">
        SELECT COUNT(1)
        FROM t_vin_charging_order o
        WHERE o.del_flag = 0
          AND o.vin_id IN
        <foreach collection="vinIds" item="vinId" open="(" separator="," close=")">
            #{vinId}
        </foreach>
    </select>
 
    <select id="pageAppletOrders" resultType="com.ruoyi.order.dto.MyVinChargingOrderList">
        SELECT o.id,
               o.site_id AS siteId,
               o.charging_capacity AS chargingDegree,
               o.charging_gun_id AS chargingGunId,
               o.end_mode AS endMode,
               CASE WHEN o.status &lt; 4 THEN o.recharge_amount ELSE o.payment_amount END AS payMoney,
               o.create_time AS createTime,
               o.status,
               CASE WHEN EXISTS (
                   SELECT 1 FROM t_order_evaluate e
                   WHERE e.order_id = o.id AND e.order_type = 1 AND e.del_flag = 0
               ) THEN 2 ELSE 1 END AS evaluate
        FROM t_vin_charging_order o
        WHERE o.del_flag = 0
          AND o.vin_id IN
        <foreach collection="vinIds" item="vinId" open="(" separator="," close=")">
            #{vinId}
        </foreach>
        ORDER BY o.create_time DESC, o.id DESC
        LIMIT #{offset}, #{pageSize}
    </select>
 
    <select id="getChargingVinStatus" resultType="com.ruoyi.order.api.vo.VinChargingStatusVO">
        SELECT o.vin_id AS vinId, MAX(o.charging_gun_id) AS chargingGunId
        FROM t_vin_charging_order o
        WHERE o.del_flag = 0
          AND o.status = 3
          AND o.vin_id IN
        <foreach collection="vinIds" item="vinId" open="(" separator="," close=")">
            #{vinId}
        </foreach>
        GROUP BY o.vin_id
    </select>
 
    <select id="summary" resultType="java.util.LinkedHashMap">
        SELECT COUNT(1) AS orderCount,
               IFNULL(SUM(o.charging_capacity), 0) AS total,
               IFNULL(SUM(CASE WHEN o.start_time IS NOT NULL AND o.end_time IS NOT NULL THEN UNIX_TIMESTAMP(o.end_time) - UNIX_TIMESTAMP(o.start_time) ELSE 0 END), 0) AS time,
               IFNULL(SUM(o.payment_amount), 0) AS income,
               IFNULL(SUM(o.electrovalence), 0) AS electronicMoney,
               IFNULL(SUM(o.service_charge), 0) AS serviceMoney
        FROM t_vin_charging_order o
        <include refid="queryCondition"/>
    </select>
 
    <select id="countAccountingStrategies" resultType="java.util.LinkedHashMap">
        SELECT charging_order_id AS chargingOrderId, COUNT(1) AS periodCount
        FROM t_vin_charging_order_accounting_strategy
        WHERE charging_order_id IN
        <foreach collection="chargingOrderIds" item="chargingOrderId" open="(" separator="," close=")">
            #{chargingOrderId}
        </foreach>
        GROUP BY charging_order_id
    </select>
 
    <select id="accountingStrategyList" resultType="java.util.LinkedHashMap">
        SELECT id, charging_order_id AS chargingOrderId, accounting_strategy_detail_id AS accountingStrategyDetailId,
               start_time AS startTime, end_time AS endTime, type, electrovalence,
               service_charge AS serviceCharge, cost_service_charge AS costServiceCharge,
               charging_capacity AS chargingCapacity, period_electric_price AS periodElectricPrice,
               period_service_price AS periodServicePrice, create_time AS createTime
        FROM t_vin_charging_order_accounting_strategy
        WHERE charging_order_id = #{chargingOrderId}
        ORDER BY start_time ASC, id ASC
    </select>
</mapper>