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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?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.SiteMapper">
    
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.chargingPile.api.model.Site">
        <id column="id" property="id" />
        <result column="partner_id" property="partnerId" />
        <result column="`code`" property="code" />
        <result column="`name`" property="name" />
        <result column="site_type" property="siteType" />
        <result column="business_category" property="businessCategory" />
        <result column="status" property="status" />
        <result column="construction_site" property="constructionSite" />
        <result column="img_url" property="imgUrl" />
        <result column="province" property="province" />
        <result column="province_code" property="provinceCode" />
        <result column="city" property="city" />
        <result column="city_code" property="cityCode" />
        <result column="districts" property="districts" />
        <result column="districts_code" property="districtsCode" />
        <result column="lon" property="lon" />
        <result column="lat" property="lat" />
        <result column="address" property="address" />
        <result column="country_code" property="countryCode" />
        <result column="phone" property="phone" />
        <result column="service_phone" property="servicePhone" />
        <result column="guide" property="guide" />
        <result column="start_service_time" property="startServiceTime" />
        <result column="end_service_time" property="endServiceTime" />
        <result column="service_description" property="serviceDescription" />
        <result column="vehicle_description" property="vehicleDescription" />
        <result column="parking_space" property="parkingSpace" />
        <result column="rate_description" property="rateDescription" />
        <result column="space_charge_explain" property="spaceChargeExplain" />
        <result column="accounting_strategy_id" property="accountingStrategyId" />
        <result column="establishment_time" property="establishmentTime" />
        <result column="sort" property="sort" />
        <result column="remark" property="remark" />
        <result column="mark" property="mark" />
        <result column="create_time" property="createTime" />
        <result column="del_flag" property="delFlag" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, partner_id, code, `name`, site_type, business_category, status, construction_site, img_url, province, province_code, city, city_code, districts, districts_code, lon, lat, address, country_code, phone, service_phone, guide, start_service_time, end_service_time, service_description, vehicle_description, parking_space, rate_description, space_charge_explain, accounting_strategy_id, establishment_time, sort, remark, create_time, del_flag, mark
    </sql>
    
    <select id="getSiteList" resultType="com.ruoyi.chargingPile.api.dto.GetSiteListDTO">
        select
        a.id,
        a.code,
        a.name,
        a.partner_id as partnerId,
        b.name as partnerName,
        a.site_type as siteType,
        a.business_category as businessCategory,
        a.status,
        CONCAT(a.province, a.city, a.districts, a.address) as address,
        a.phone,
        a.service_phone as servicePhone,
        a.parking_space as parkingSpace,
        DATE_FORMAT(a.establishment_time, '%Y-%m-%d %H:%i:%s') as establishmentTime,
        c.num as chargingPileNumber,
        a.sort,
        a.lon,
        a.lat,
        a.accounting_strategy_id as accountingStrategyId,
        if(a.accounting_strategy_id is null, 1, if(d.site_id is null, 1, 2)) as accountingStrategyType
        from t_site a
        left join t_partner b on (a.partner_id = b.id)
        left join (select site_id, count(1) as num from t_charging_pile where del_flag = 0 group by site_id) c on (a.id = c.site_id)
        left join t_accounting_strategy d on (a.accounting_strategy_id = d.id)
        WHERE a.del_flag = 0
        <if test="null != item.name and '' != item.name">
            and a.name like CONCAT('%', #{item.name}, '%')
        </if>
        <if test="null != item.partnerName and '' != item.partnerName">
            and b.name like CONCAT('%', #{item.partnerName}, '%')
        </if>
        <if test="null != item.siteType">
            and a.site_type = #{item.siteType}
        </if>
        <if test="null != item.businessCategory">
            and a.business_category = #{item.businessCategory}
        </if>
        <if test="null != item.status">
            and a.status = #{item.status}
        </if>
        <if test="null != item.provinceCode and '' != item.provinceCode">
            and a.province_code = #{item.provinceCode}
        </if>
        <if test="null != item.cityCode and '' != item.cityCode">
            and a.city_code = #{item.cityCode}
        </if>
        <if test="null != item.districtsCode and '' != item.districtsCode">
            and a.districts_code = #{item.districtsCode}
        </if>
        <if test="null != ids">
            and a.id in
            <foreach collection="ids" item="itemm" index="index" open="(" separator="," close=")">
                #{itemm}
            </foreach>
        </if>
        order by a.sort desc, a.create_time desc
    </select>
 
    <select id="pageList" resultType="com.ruoyi.chargingPile.api.vo.SiteVO">
        select
        ts.id, ts.partner_id, ts.code, ts.`name`, ts.site_type, ts.business_category, ts.status, ts.construction_site, ts.img_url,
        ts.lon, ts.lat, ts.address, ts.country_code, ts.phone,ts.guide, ts.service_description, ts.vehicle_description,
        ts.parking_space, ts.rate_description, ts.space_charge_explain, ts.accounting_strategy_id,ts.del_flag,tcg.fastCount,
        tcg.slowCount,tcg.superCount,tasd.electrovalence,tasd.vipElectrovalence,tasd.serviceCharge,tasd.electrovalenceOriginal,tcg.superFreeCount,tcg.fastFreeCount,tcg.slowFreeCount,
        ROUND(
        6378.138 * 2 * ASIN(
        SQRT(
        POW(
        SIN(
        (
        #{query.lat} * PI() / 180 - ts.lat * PI() / 180
        ) / 2
        ),
        2
        ) + COS(#{query.lat} * PI() / 180) * COS(ts.lat * PI() / 180) * POW(
        SIN(
        (
        #{query.lon} * PI() / 180 - ts.lon * PI() / 180
        ) / 2
        ),
        2
        )
        )
        ) * 1000
        ) AS distance
        from t_site ts
        left join (
        select site_id,
            SUM(CASE WHEN charge_mode = 1 THEN 1 ELSE 0 END) AS superCount,
            SUM(CASE WHEN charge_mode = 2 THEN 1 ELSE 0 END) AS fastCount,
            SUM(CASE WHEN charge_mode = 3 THEN 1 ELSE 0 END) AS slowCount,
            SUM(CASE WHEN charge_mode = 1 and `status` = 2 THEN 1 ELSE 0 END) AS superFreeCount,
            SUM(CASE WHEN charge_mode = 2 and `status` = 2 THEN 1 ELSE 0 END) AS fastFreeCount,
            SUM(CASE WHEN charge_mode = 3 and `status` = 2 THEN 1 ELSE 0 END) AS slowFreeCount
        from
            t_charging_gun
        where
            del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        group by
            site_id) tcg on (ts.id = tcg.site_id)
        left join (
        select
            a.accounting_strategy_id,
            a.service_charge AS serviceCharge,
            a.electrovalence AS electrovalenceOriginal,
            (a.electrovalence+a.service_charge) AS electrovalence,
            (a.electrovalence + (a.service_charge*b.discount)) AS vipElectrovalence
        from
            t_accounting_strategy_detail a
        left join
                t_accounting_strategy b on (a.accounting_strategy_id = b.id)
        where b.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        AND DATE_FORMAT(NOW(), '%H:%i:%s') between a.start_time and a.end_time) tasd on (ts.accounting_strategy_id = tasd.accounting_strategy_id)
        <where>
            <if test="null != query.name and '' != query.name">
                and ts.`name` like CONCAT('%', #{query.name}, '%')
            </if>
            <if test="null != query.cityCode and '' != query.cityCode">
                and ts.cityCode = #{query.cityCode}
            </if>
            AND ts.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
            AND ts.status = ${@com.ruoyi.common.core.enums.status.SiteStatusEnum@NORMAL_USE.getCode()}
            AND ts.accounting_strategy_id IS NOT NULL
        </where>
        <if test="query.sortType != null">
            <choose>
                <when test="query.sortType == 1">
                    ORDER BY distance ASC
                </when>
                <when test="query.sortType == 2">
                    ORDER BY tasd.electrovalence ASC
                </when>
                <when test="query.sortType == 3">
                    ORDER BY (tcg.fastCount + tcg.slowCount + tcg.superCount) DESC
                </when>
            </choose>
        </if>
    </select>
    <select id="getDetailById" resultType="com.ruoyi.chargingPile.api.vo.SiteDetailVO">
        SELECT id, partner_id, code, `name`, site_type, business_category, status, construction_site, img_url, province, province_code,
               city, city_code, districts, districts_code, lon, lat, address, country_code, phone, service_phone, guide, start_service_time,
               end_service_time, service_description, vehicle_description, parking_space, rate_description, space_charge_explain,
               accounting_strategy_id, establishment_time, sort, remark, create_time, del_flag, mark,
            ROUND(
        6378.138 * 2 * ASIN(
        SQRT(
        POW(
        SIN(
        (
        #{query.lat} * PI() / 180 - lat * PI() / 180
        ) / 2
        ),
        2
        ) + COS(#{query.lat} * PI() / 180) * COS(lat * PI() / 180) * POW(
        SIN(
        (
        #{query.lon} * PI() / 180 - lon * PI() / 180
        ) / 2
        ),
        2
        )
        )
        ) * 1000
        ) AS distance
        FROM t_site WHERE id = #{query.siteId} AND del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
    </select>
    <select id="getSiteListParkLot" resultType="com.ruoyi.chargingPile.api.model.Site">
        select ts.id, ts.partner_id, ts.code, ts.`name`, ts.site_type, ts.business_category, ts.status
        from t_site ts
        <where>
            <if test="null != ids and ids.size()>0">
                AND ts.id IN
                <foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            AND ts.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        </where>
    </select>
    <select id="getSiteListGun" resultType="com.ruoyi.chargingPile.api.model.Site">
        select <include refid="Base_Column_List"></include>
        from t_site
        <where>
            <if test="null != ids and ids.size()>0">
                AND id IN
                <foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            AND del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        </where>
    </select>
    <select id="getMapSiteList" resultType="com.ruoyi.chargingPile.api.vo.SiteVO">
        select
        ts.id, ts.partner_id, ts.code, ts.`name`, ts.site_type, ts.business_category, ts.status, ts.construction_site, ts.img_url,
        ts.lon, ts.lat, ts.address, ts.country_code, ts.phone,ts.guide, ts.service_description, ts.vehicle_description,
        ts.parking_space, ts.rate_description, ts.space_charge_explain, ts.accounting_strategy_id,ts.del_flag,tcg.fastCount,
        tcg.slowCount,tcg.superCount,tasd.electrovalence,tasd.vipElectrovalence,tcg.superFreeCount,tcg.fastFreeCount,tcg.slowFreeCount,
        ROUND(
        6378.138 * 2 * ASIN(
        SQRT(
        POW(
        SIN(
        (
        #{query.lat} * PI() / 180 - ts.lat * PI() / 180
        ) / 2
        ),
        2
        ) + COS(#{query.lat} * PI() / 180) * COS(ts.lat * PI() / 180) * POW(
        SIN(
        (
        #{query.lon} * PI() / 180 - ts.lon * PI() / 180
        ) / 2
        ),
        2
        )
        )
        ) * 1000
        ) AS distance
        from t_site ts
        left join (
        select site_id,
        SUM(CASE WHEN charge_mode = 1 THEN 1 ELSE 0 END) AS superCount,
        SUM(CASE WHEN charge_mode = 2 THEN 1 ELSE 0 END) AS fastCount,
        SUM(CASE WHEN charge_mode = 3 THEN 1 ELSE 0 END) AS slowCount,
        SUM(CASE WHEN charge_mode = 1 and `status` = 2 THEN 1 ELSE 0 END) AS superFreeCount,
        SUM(CASE WHEN charge_mode = 2 and `status` = 2 THEN 1 ELSE 0 END) AS fastFreeCount,
        SUM(CASE WHEN charge_mode = 3 and `status` = 2 THEN 1 ELSE 0 END) AS slowFreeCount
        from
        t_charging_gun
        where
        del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        group by
        site_id) tcg on (ts.id = tcg.site_id)
        left join (
        select
        a.accounting_strategy_id,
        (a.electrovalence+a.service_charge) AS electrovalence,
        ((a.electrovalence+a.service_charge)*b.discount) AS vipElectrovalence
        from
        t_accounting_strategy_detail a
        left join
        t_accounting_strategy b on (a.accounting_strategy_id = b.id)
        where b.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        AND DATE_FORMAT(NOW(), '%H:%i:%s') between a.start_time and a.end_time) tasd on (ts.accounting_strategy_id = tasd.accounting_strategy_id)
        <where>
            <if test="null != query.name and '' != query.name">
                and ts.`name` like CONCAT('%', #{query.name}, '%')
            </if>
            <if test="null != query.cityCode and '' != query.cityCode">
                and ts.cityCode = #{query.cityCode}
            </if>
            AND ts.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
            AND ts.status = ${@com.ruoyi.common.core.enums.status.SiteStatusEnum@NORMAL_USE.getCode()}
        </where>
        <if test="query.sortType != null">
            <choose>
                <when test="query.sortType == 1">
                    ORDER BY distance ASC
                </when>
            </choose>
        </if>
    </select>
</mapper>