Pu Zhibing
2024-10-16 c4664502dfdaffff555b532e65b51a57ac8b29c2
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
<?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.chargingPile.mapper.TChargingGunMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.chargingPile.api.model.TChargingGun">
        <id column="id" property="id" />
        <result column="code" property="code" />
        <result column="site_id" property="siteId" />
        <result column="partner_id" property="partnerId" />
        <result column="charging_pile_id" property="chargingPileId" />
        <result column="`name`" property="name" />
        <result column="`type`" property="type" />
        <result column="status" property="status" />
        <result column="charge_mode" property="chargeMode" />
        <result column="accounting_strategy_id" property="accountingStrategyId" />
        <result column="upper_rated_voltage" property="upperRatedVoltage" />
        <result column="lower_limit_of_rated_voltage" property="lowerLimitOfRatedVoltage" />
        <result column="rated_current" property="ratedCurrent" />
        <result column="rated_power" property="ratedPower" />
        <result column="charging_power" property="chargingPower" />
        <result column="parking_number" property="parkingNumber" />
        <result column="parking_status" property="parkingStatus" />
        <result column="parking_lock_state" property="parkingLockState" />
        <result column="national_standard" property="nationalStandard" />
        <result column="remark" property="remark" />
        <result column="create_time" property="createTime" />
        <result column="del_flag" property="delFlag" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, code, site_id, partner_id, charging_pile_id, `name`, `type`, status, charge_mode, accounting_strategy_id, upper_rated_voltage, lower_limit_of_rated_voltage, rated_current, rated_power, parking_number, parking_status, parking_lock_state, national_standard, remark, create_time, del_flag
    </sql>
    <select id="pageList" resultType="com.ruoyi.chargingPile.api.vo.TChargingGunVO">
        SELECT
        tcg.id, tcg.code, tcg.site_id, tcg.partner_id, tcg.charging_pile_id, tcg.`name`, tcg.`type`, tcg.status, tcg.charge_mode, tcg.accounting_strategy_id,
        tcg.upper_rated_voltage, tcg.lower_limit_of_rated_voltage, tcg.rated_current, tcg.rated_power, tcg.parking_number, tcg.parking_status,
        tcg.parking_lock_state, tcg.national_standard, tcg.remark, tcg.create_time, tcg.del_flag,tas.name AS strategyName
        FROM t_charging_gun tcg
        LEFT JOIN t_accounting_strategy tas ON tas.id = tcg.accounting_strategy_id
        <where>
            <if test="query.siteId != null">
                AND tcg.site_id = #{query.siteId}
            </if>
            <if test="query.chargingPileId != null">
                AND tcg.charging_pile_id = #{query.chargingPileId}
            </if>
            <if test="query.name != null and query.name != ''">
                AND tcg.`name` LIKE concat('%',#{query.name},'%')
            </if>
            <if test="query.type != null">
                AND tcg.`type` = #{query.type}
            </if>
            <if test="query.status != null">
                AND tcg.status = #{query.status}
            </if>
            <if test="query.chargeMode != null">
                AND tcg.charge_mode = #{query.chargeMode}
            </if>
            <if test="null != siteIds">
                and tcg.site_id in
                <foreach collection="siteIds" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            AND tcg.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        </where>
        ORDER BY tcg.create_time DESC
    </select>
    <select id="getModeStatistics" resultType="java.util.Map">
        SELECT
        charge_mode,
        IFNULL(COUNT(charge_mode),0) AS modeCount
        FROM t_charging_gun
        WHERE del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        <if test="siteIds != null and siteIds.size()>0">
            AND site_id IN
            <foreach collection="siteIds" item="siteId" open="(" separator="," close=")">
                #{siteId}
            </foreach>
        </if>
        GROUP BY charge_mode
    </select>
    <select id="getStatusModeStatistics" resultType="com.ruoyi.chargingPile.api.vo.StatusModeStatisticsVO">
        SELECT
        charge_mode,
        IFNULL((SELECT COUNT(*) FROM t_charging_gun WHERE status = 2),0) AS freeCount,
        IFNULL((SELECT COUNT(*) FROM t_charging_gun WHERE status = 5),0) AS filledCount,
        IFNULL((SELECT COUNT(*) FROM t_charging_gun WHERE status = 3),0) AS insertCount,
        IFNULL((SELECT COUNT(*) FROM t_charging_gun WHERE status = 4),0) AS chargingCount
        FROM t_charging_gun
        WHERE del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()} AND charge_mode = #{chargeMode}
        <if test="siteIds != null and siteIds.size()>0">
            AND site_id IN
            <foreach collection="siteIds" item="siteId" open="(" separator="," close=")">
                #{siteId}
            </foreach>
        </if>
        GROUP BY charge_mode
    </select>
 
</mapper>