liujie
7 小时以前 1affeef32cf30a1765ee749db0344258058b4e2e
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
<?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.TParkingRecordMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.chargingPile.api.model.TParkingRecord">
        <id column="id" property="id" />
        <result column="app_user_id" property="appUserId" />
        <result column="license_plate" property="licensePlate" />
        <result column="vehicle_color" property="vehicleColor" />
        <result column="charging_order_id" property="chargingOrderId" />
        <result column="parking_lot_id" property="parkingLotId" />
        <result column="in_parking_time" property="inParkingTime" />
        <result column="out_parking_time" property="outParkingTime" />
        <result column="parking_duration" property="parkingDuration" />
        <result column="order_amount" property="orderAmount" />
        <result column="status" property="status" />
        <result column="out_parking_type" property="outParkingType" />
        <result column="create_time" property="createTime" />
        <result column="code" property="code" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, code,app_user_id, license_plate, vehicle_color, charging_order_id, parking_lot_id, in_parking_time, out_parking_time, parking_duration, order_amount, status, out_parking_type, create_time
    </sql>
    <select id="getSum" resultType="java.math.BigDecimal">
        select sum(timeout_amount) from t_parking_record
    </select>
    <select id="pageList" resultType="com.ruoyi.chargingPile.api.vo.TParkingRecordVO">
        select
        tpr.id, tpr.code,tpr.app_user_id, tpr.license_plate, tpr.vehicle_color, tpr.charging_order_id, tpr.parking_lot_id, tpr.in_parking_time, tpr.out_parking_time,
        tpr.parking_duration, tpr.order_amount, tpr.status, tpr.out_parking_type, tpr.create_time,(tpr.order_amount + tpr.timeout_amount) as parkingFee,tpr.timeout_amount,
        tpr.free_duration,(tpr.parking_duration - tpr.free_duration) as feeDuration,ts.name as siteName
        from t_parking_record tpr
        left join t_parking_lot tpl on tpr.parking_lot_id = tpl.id
        left join t_site ts on tpl.site_id = ts.id
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tpr.create_time BETWEEN #{query.startTime} AND #{query.endTime}
            </if>
            <if test="query.code != null and query.code != ''">
                AND tpr.code LIKE concat('%',#{query.code},'%')
            </if>
            <if test="query.licensePlate != null and query.licensePlate != ''">
                AND tpr.license_plate LIKE concat('%',#{query.licensePlate},'%')
            </if>
            <if test="query.lotIds != null and query.lotIds.size()>0">
                AND tpr.parking_lot_id IN
                <foreach collection="query.lotIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="null != query.siteIds and query.siteIds.size()>0" >
                and tpl.site_id in
                <foreach collection="query.siteIds" close=")" open="(" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            AND tpr.status = 3
        </where>
        ORDER BY tpr.create_time DESC
    </select>
    <select id="getParkingRecordCount" resultType="com.ruoyi.chargingPile.api.vo.TParkingRecordPageInfoVO">
        SELECT count(tpr.id) as orderCount,
               sum(tpr.timeout_amount) as timeoutAmountSum,
               sum(tpr.parking_duration - tpr.free_duration) as feeDurationSum,
               sum(tpr.parking_duration) as parkingDurationSum
        from t_parking_record tpr
        left join t_parking_lot tpl on tpr.parking_lot_id = tpl.id
 
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND create_time BETWEEN #{query.startTime} AND #{query.endTime}
            </if>
            <if test="query.code != null and query.code != ''">
                AND code LIKE concat('%',#{query.code},'%')
            </if>
            <if test="query.licensePlate != null and query.licensePlate != ''">
                AND license_plate LIKE concat('%',#{query.licensePlate},'%')
            </if>
            <if test="query.lotIds != null and query.lotIds.size()>0">
                AND parking_lot_id IN
                <foreach collection="query.lotIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="null != query.siteIds and query.siteIds.size()>0" >
                and tpl.site_id in
                <foreach collection="query.siteIds" close=")" open="(" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            AND status = 3
        </where>
 
    </select>
    <select id="parkingData" resultType="java.util.Map">
        SELECT
            DATE_FORMAT( t1.create_time, '%H:00' ) AS time,
            count( 1 ) AS orders,
            SUM( t1.timeout_amount ) AS timeoutAmount
        FROM
            t_parking_record t1
        left join t_parking_lot t2  on t2.id = t1.parking_lot_id
        where DATE(t1.create_time ) = CURDATE()
        <if test="parkingRecordQueryDto.parkingLotId !=null">
            AND t1.parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
        </if>
        <if test="null != parkingRecordQueryDto.siteIds and parkingRecordQueryDto.siteIds.size()>0" >
            and t2.site_id in
            <foreach collection="parkingRecordQueryDto.siteIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        GROUP BY
            time
        ORDER BY
            time
    </select>
    <select id="parkingDataByDate" resultType="java.util.Map">
        SELECT
            DATE_FORMAT( t1.create_time, '%Y-%m-%d' ) AS time,
            count( 1 ) AS orders,
            SUM( t1.timeout_amount ) AS timeoutAmount
        FROM
        t_parking_record t1
        left join t_parking_lot t2  on t2.id = t1.parking_lot_id
        <where>
            <if test="parkingRecordQueryDto.parkingLotId !=null">
                AND t1.parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
            </if>
            <if test="parkingRecordQueryDto.dayType == 2">
                AND WEEKOFYEAR( t1.
            create_time ) = WEEKOFYEAR( CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 3">
                AND MONTH( t1.create_time ) = MONTH(CURDATE())
            </if>
            <if test="parkingRecordQueryDto.dayType == 4">
                AND YEAR( t1.create_time ) = YEAR(CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 5">
                <if test="parkingRecordQueryDto.startTime != null">
                    AND t1.create_time >= #{parkingRecordQueryDto.startTime}
                </if>
                <if test="parkingRecordQueryDto.endTime != null">
                    AND t1.create_time &lt;= #{parkingRecordQueryDto.endTime}
                </if>
            </if>
            <if test="null != parkingRecordQueryDto.siteIds and parkingRecordQueryDto.siteIds.size()>0" >
                and t2.site_id in
                <foreach collection="parkingRecordQueryDto.siteIds" item="item" index="index" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY time
    </select>
    <select id="getCarColor" resultType="java.util.Map">
        SELECT
        t1.vehicle_color,count(1) as counts
        FROM
        t_parking_record t1
        left join t_parking_lot t2  on t2.id = t1.parking_lot_id
        <where>
            <if test="parkingRecordQueryDto.parkingLotId !=null">
                AND t1.parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
            </if>
        <if test="parkingRecordQueryDto.dayType == 1">
            AND DATE( t1.create_time ) = CURDATE()
        </if>
        <if test="parkingRecordQueryDto.dayType == 2">
            AND WEEKOFYEAR( t1.create_time ) = WEEKOFYEAR( CURDATE() )
        </if>
        <if test="parkingRecordQueryDto.dayType == 3">
            AND MONTH( t1.create_time ) = MONTH(CURDATE())
        </if>
        <if test="parkingRecordQueryDto.dayType == 4">
            AND YEAR( t1.create_time ) = YEAR(CURDATE() )
        </if>
        <if test="parkingRecordQueryDto.dayType == 5">
            <if test="parkingRecordQueryDto.startTime != null">
                AND t1.create_time >= #{parkingRecordQueryDto.startTime}
            </if>
            <if test="parkingRecordQueryDto.endTime != null">
                AND t1.create_time &lt;= #{parkingRecordQueryDto.endTime}
            </if>
        </if>
            <if test="null != parkingRecordQueryDto.siteIds and parkingRecordQueryDto.siteIds.size()>0" >
                and t2.site_id in
                <foreach collection="parkingRecordQueryDto.siteIds" item="item" index="index" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY t1.vehicle_color
 
    </select>
    <select id="getOutType" resultType="java.util.Map">
        SELECT
        t1.out_parking_type,count(1) as counts
        FROM
        t_parking_record t1
        left join t_parking_lot t2  on t2.id = t1.parking_lot_id
        <where>
            <if test="parkingRecordQueryDto.parkingLotId !=null">
                AND t1.parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
            </if>
            <if test="parkingRecordQueryDto.dayType == 1">
                AND DATE( t1.create_time ) = CURDATE()
            </if>
            <if test="parkingRecordQueryDto.dayType == 2">
                AND WEEKOFYEAR( t1.create_time ) = WEEKOFYEAR( CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 3">
                AND MONTH( t1.create_time ) = MONTH(CURDATE())
            </if>
            <if test="parkingRecordQueryDto.dayType == 4">
                AND YEAR( t1.create_time ) = YEAR(CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 5">
                <if test="parkingRecordQueryDto.startTime != null">
                    AND t1.create_time >= #{parkingRecordQueryDto.startTime}
                </if>
                <if test="parkingRecordQueryDto.endTime != null">
                    AND t1.create_time &lt;= #{parkingRecordQueryDto.endTime}
                </if>
            </if>
            <if test="null != parkingRecordQueryDto.siteIds and parkingRecordQueryDto.siteIds.size()>0" >
                and t2.site_id in
                <foreach collection="parkingRecordQueryDto.siteIds" item="item" index="index" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY t1.out_parking_type
    </select>
    <select id="getIsCharge" resultType="java.util.Map">
        SELECT
            CASE
                WHEN t1.charging_order_id IS NOT NULL THEN 'WithChargingOrder'
                ELSE 'WithoutChargingOrder'
                END AS order_status,
            COUNT(*) AS counts
        FROM
            `t_parking_record` t1
        left join t_parking_lot t2  on t2.id = t1.parking_lot_id
        <where>
            <if test="parkingRecordQueryDto.parkingLotId !=null">
                AND t1.parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
            </if>
            <if test="parkingRecordQueryDto.dayType == 1">
                AND DATE( t1.create_time ) = CURDATE()
            </if>
            <if test="parkingRecordQueryDto.dayType == 2">
                AND WEEKOFYEAR( t1.create_time ) = WEEKOFYEAR( CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 3">
                AND MONTH( t1.create_time ) = MONTH(CURDATE())
            </if>
            <if test="parkingRecordQueryDto.dayType == 4">
                AND YEAR( t1.create_time ) = YEAR(CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 5">
                <if test="parkingRecordQueryDto.startTime != null">
                    AND t1.create_time >= #{parkingRecordQueryDto.startTime}
                </if>
                <if test="parkingRecordQueryDto.endTime != null">
                    AND t1.create_time &lt;= #{parkingRecordQueryDto.endTime}
                </if>
            </if>
            <if test="null != parkingRecordQueryDto.siteIds and parkingRecordQueryDto.siteIds.size()>0" >
                and t2.site_id in
                <foreach collection="parkingRecordQueryDto.siteIds" item="item" index="index" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY
            order_status
    </select>
    <select id="income" resultType="java.util.Map">
        SELECT sum(pr.order_amount) as amount,pl.name
        from t_parking_record pr
                 LEFT JOIN t_parking_lot pl on pr.parking_lot_id = pl.id
        <where>
            <if test="parkingRecordQueryDto.parkingLotId !=null">
                AND pr.parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
            </if>
 
            AND DATE( pr.create_time ) between #{parkingRecordQueryDto.startTime} and #{parkingRecordQueryDto.endTime}
 
        </where>
        GROUP  BY pl.name
    </select>
 
</mapper>