puzhibing
2026-09-02 e0f72812f2752914ed882d0512b848930036f12e
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
<?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.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="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>