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
<?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, 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 where   in_parking_time >= #{sixBefore}
    </select>
    <select id="pageList" resultType="com.ruoyi.chargingPile.api.vo.TParkingRecordVO">
        select
        tpr.id, 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.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.licensePlate 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>
            AND tpr.status = 3
        </where>
        ORDER BY tpr.create_time DESC
    </select>
    <select id="getParkingRecordCount" resultType="com.ruoyi.chargingPile.api.vo.TParkingRecordPageInfoVO">
        SELECT count(id) as orderCount,
               sum(timeout_amount) as timeoutAmountSum,
               sum(parking_duration - free_duration) as feeDurationSum,
               sum(parking_duration) as parkingDurationSum
        from t_parking_record
        <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 licensePlate 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>
            AND status = 3
        </where>
        group by create_time
        ORDER BY create_time DESC
    </select>
    <select id="parkingData" resultType="java.util.Map">
        SELECT
            DATE_FORMAT( create_time, '%Y-%m-%d %H' ) AS time,
    count( 1 ) AS orders,
    SUM( timeout_amount ) AS timeoutAmount
        FROM
            t_parking_record
        where DATE(create_time ) = CURDATE()
        <if test="parkingRecordQueryDto.parkingLotId !=null">
            AND parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
        </if>
        GROUP BY
            time
        ORDER BY
            time
    </select>
    <select id="parkingDataByDate" resultType="java.util.Map">
        SELECT
            DATE_FORMAT( create_time, '%Y-%m-%d' ) AS time,
    count( 1 ) AS orders,
    SUM( timeout_amount ) AS timeoutAmount
        FROM
            t_parking_record
        <where>
            <if test="parkingRecordQueryDto.parkingLotId !=null">
                AND parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
            </if>
            <if test="parkingRecordQueryDto.dayType == 2">
                AND WEEKOFYEAR( create_time ) = WEEKOFYEAR( CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 3">
                AND MONTH( create_time ) = MONTH(CURDATE())
            </if>
            <if test="parkingRecordQueryDto.dayType == 4">
                AND YEAR( create_time ) = YEAR(CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 5">
                <if test="parkingRecordQueryDto.startTime != null">
                    AND create_time >= #{parkingRecordQueryDto.startTime}
                </if>
                <if test="parkingRecordQueryDto.endTime != null">
                    AND create_time &lt;= #{parkingRecordQueryDto.endTime}
                </if>
            </if>
        </where>
        GROUP BY
            time
        ORDER BY
            time
 
 
    </select>
    <select id="getCarColor" resultType="java.util.Map">
        SELECT
            vehicle_color,count(1) as counts
        FROM
            t_parking_record
        <where>
            <if test="parkingRecordQueryDto.parkingLotId !=null">
                AND parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
            </if>
        <if test="parkingRecordQueryDto.dayType == 1">
            AND DATE( create_time ) = CURDATE()
        </if>
        <if test="parkingRecordQueryDto.dayType == 2">
            AND WEEKOFYEAR( create_time ) = WEEKOFYEAR( CURDATE() )
        </if>
        <if test="parkingRecordQueryDto.dayType == 3">
            AND MONTH( create_time ) = MONTH(CURDATE())
        </if>
        <if test="parkingRecordQueryDto.dayType == 4">
            AND YEAR( create_time ) = YEAR(CURDATE() )
        </if>
        <if test="parkingRecordQueryDto.dayType == 5">
            <if test="parkingRecordQueryDto.startTime != null">
                AND create_time >= #{parkingRecordQueryDto.startTime}
            </if>
            <if test="parkingRecordQueryDto.endTime != null">
                AND create_time &lt;= #{parkingRecordQueryDto.endTime}
            </if>
        </if>
        </where>
        GROUP BY vehicle_color
 
    </select>
    <select id="getOutType" resultType="java.util.Map">
        SELECT
            out_parking_type,count(1) as counts
        FROM
            t_parking_record
        <where>
            <if test="parkingRecordQueryDto.parkingLotId !=null">
                AND parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
            </if>
            <if test="parkingRecordQueryDto.dayType == 1">
                AND DATE( create_time ) = CURDATE()
            </if>
            <if test="parkingRecordQueryDto.dayType == 2">
                AND WEEKOFYEAR( create_time ) = WEEKOFYEAR( CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 3">
                AND MONTH( create_time ) = MONTH(CURDATE())
            </if>
            <if test="parkingRecordQueryDto.dayType == 4">
                AND YEAR( create_time ) = YEAR(CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 5">
                <if test="parkingRecordQueryDto.startTime != null">
                    AND create_time >= #{parkingRecordQueryDto.startTime}
                </if>
                <if test="parkingRecordQueryDto.endTime != null">
                    AND create_time &lt;= #{parkingRecordQueryDto.endTime}
                </if>
            </if>
        </where>
        GROUP BY out_parking_type
    </select>
    <select id="getIsCharge" resultType="java.util.Map">
        SELECT
            CASE
                WHEN charging_order_id IS NOT NULL THEN 'WithChargingOrder'
                ELSE 'WithoutChargingOrder'
                END AS order_status,
            COUNT(*) AS counts
        FROM
            `t_parking_record`
        <where>
            <if test="parkingRecordQueryDto.parkingLotId !=null">
                AND parking_lot_id = #{parkingRecordQueryDto.parkingLotId}
            </if>
            <if test="parkingRecordQueryDto.dayType == 1">
                AND DATE( create_time ) = CURDATE()
            </if>
            <if test="parkingRecordQueryDto.dayType == 2">
                AND WEEKOFYEAR( create_time ) = WEEKOFYEAR( CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 3">
                AND MONTH( create_time ) = MONTH(CURDATE())
            </if>
            <if test="parkingRecordQueryDto.dayType == 4">
                AND YEAR( create_time ) = YEAR(CURDATE() )
            </if>
            <if test="parkingRecordQueryDto.dayType == 5">
                <if test="parkingRecordQueryDto.startTime != null">
                    AND create_time >= #{parkingRecordQueryDto.startTime}
                </if>
                <if test="parkingRecordQueryDto.endTime != null">
                    AND create_time &lt;= #{parkingRecordQueryDto.endTime}
                </if>
            </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>