yanghb
2023-04-10 b2f678ad387ca24e05a11100ea4583f0f2f730f0
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?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.stylefeng.guns.modular.system.dao.IncomeMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.Income">
        <id column="id" property="id"/>
        <result column="userType" property="userType"/>
        <result column="objectId" property="objectId"/>
        <result column="type" property="type"/>
        <result column="incomeId" property="incomeId"/>
        <result column="orderType" property="orderType"/>
        <result column="money" property="money"/>
        <result column="insertTime" property="insertTime"/>
    </resultMap>
 
 
    <select id="summaryOfIncomeDetailsList" resultType="map">
        select * from (
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as  insertTime
        from t_income where userType = 1 and money > 0
        <if test="null != companyId">
            and objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by DATE_FORMAT(insertTime, '%Y/%m/%d')
        ) as aa order by aa.insertTime desc
        <if test="null != offset and null != limit">
            limit #{offset}, #{limit}
        </if>
    </select>
 
 
    <select id="summaryOfIncomeDetailsListCount" resultType="int">
        select count(1) from (
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as  insertTime
        from t_income where userType = 1 and money > 0
        <if test="null != companyId">
            and objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by DATE_FORMAT(insertTime, '%Y/%m/%d')
        ) as aa
    </select>
 
 
    <select id="summaryOfIncomeDetailsListSum" resultType="map">
        select
        ifnull(ROUND(sum(aa.orderRevenue), 2), 0) as orderRevenue,
        ifnull(ROUND(sum(aa.taxiCardRevenue), 2), 0) as taxiCardRevenue,
        ifnull(ROUND(sum(aa.overtimeDeduction), 2), 0) as overtimeDeduction,
        ifnull(ROUND(sum(aa.complaintDeductionProceeds), 2), 0) as complaintDeductionProceeds,
        ifnull(ROUND(sum(aa.other), 2), 0) as other
        from (
        select sum(money) as orderRevenue, 0 as taxiCardRevenue, 0 as overtimeDeduction, 0 as complaintDeductionProceeds, 0 as other from t_income where userType = 1 and money > 0 and type = 2
        <if test="null != companyId">
            and objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select 0 as orderRevenue, sum(money) as taxiCardRevenue, 0 as overtimeDeduction, 0 as complaintDeductionProceeds, 0 as other from t_income where userType = 1 and money > 0 and type = 5
        <if test="null != companyId">
            and objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select 0 as orderRevenue, 0 as taxiCardRevenue, sum(money) as overtimeDeduction, 0 as complaintDeductionProceeds, 0 as other from t_income where userType = 1 and money > 0 and type in (7, 9)
        <if test="null != companyId">
            and objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select 0 as orderRevenue, 0 as taxiCardRevenue, 0 as overtimeDeduction, sum(money) as complaintDeductionProceeds, 0 as other from t_income where userType = 1 and money > 0 and type = 8
        <if test="null != companyId">
            and objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select 0 as orderRevenue, 0 as taxiCardRevenue, 0 as overtimeDeduction, 0 as complaintDeductionProceeds, sum(money) as other from t_income where userType = 1 and money > 0 and type in (1, 3, 4, 6)
        <if test="null != companyId">
            and objectId = #{companyId}
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        ) as aa
 
    </select>
 
 
 
    <select id="summaryOfIncomeDetailsListGroupSum" resultType="map">
        select * from (
        select
        aa.userType,
        aa.objectId,
        aa.type,
        aa.orderType,
        aa.insertTime,
        ifnull(sum(aa.payMoney), 0) as payMoney,
        aa.nickName,
        aa.phone,
        ifnull(sum(aa.overtimeDeduction), 0) as overtimeDeduction,
        ifnull(sum(aa.money), 0) as money,
        ifnull(sum(aa.complaint), 0) as complaint
        from (
            select
            a.userType,
            a.objectId,
            a.type,
            a.orderType,
            DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
            if(a.orderType = 1, b.payMoney, if(a.orderType = 2, c.payMoney, if(a.orderType = 3, d.payMoney, if(a.orderType = 4, e.payMoney, if(a.orderType = 5, f.payMoney, if(a.orderType = 6, 0, if(a.orderType = 7, h.payMoney, 0))))))) as payMoney,
            if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
            if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone,
            0 as overtimeDeduction,
            if(a.orderType = 1 and a.incomeId = b.id, a.money, if(a.orderType = 2 and a.incomeId = c.id, a.money, if(a.orderType = 3 and a.incomeId = d.id, a.money, if(a.orderType = 4 and a.incomeId = e.id, a.money, if(a.orderType = 5 and a.incomeId = f.id, a.money, if(a.orderType = 6 and a.incomeId = g.id, a.money, if(a.orderType = 7 and a.incomeId = h.id, a.money, 0))))))) as money,
            0 as complaint
            from t_income a
            left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
            left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
            left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
            left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
            left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
            left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
            left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
            left join t_user u1 on (b.userId = u1.id)
            left join t_user u2 on (c.userId = u2.id)
            left join t_user u3 on (d.userId = u3.id)
            left join t_user u4 on (e.userId = u4.id)
            left join t_user u5 on (f.userId = u5.id)
            left join t_user u6 on (g.userId = u6.id)
            left join t_user u7 on (h.userId = u7.id)
            where a.type = 2
 
            union all
 
            select
            a.userType,
            a.objectId,
            a.type,
            a.orderType,
            DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
            0 as payMoney,
            if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
            if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone,
            if(a.orderType = 1 and a.incomeId = b.id, a.money, if(a.orderType = 2 and a.incomeId = c.id, a.money, if(a.orderType = 3 and a.incomeId = d.id, a.money, if(a.orderType = 4 and a.incomeId = e.id, a.money, if(a.orderType = 5 and a.incomeId = f.id, a.money, if(a.orderType = 6 and a.incomeId = g.id, a.money, if(a.orderType = 7 and a.incomeId = h.id, a.money, 0))))))) as overtimeDeduction,
            0 as money,
            0 as complaint
            from t_income a
            left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
            left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
            left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
            left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
            left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
            left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
            left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
            left join t_user u1 on (b.userId = u1.id)
            left join t_user u2 on (c.userId = u2.id)
            left join t_user u3 on (d.userId = u3.id)
            left join t_user u4 on (e.userId = u4.id)
            left join t_user u5 on (f.userId = u5.id)
            left join t_user u6 on (g.userId = u6.id)
            left join t_user u7 on (h.userId = u7.id)
            where a.type = 7
 
            union all
 
            select
            a.userType,
            a.objectId,
            a.type,
            a.orderType,
            DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
            0 as payMoney,
            '' as nickName,
            '' as phone,
            0 as overtimeDeduction,
            0 as money,
            a.money as complaint
            from t_income a
            where a.type = 8
            ) as aa group by aa.userType, aa.objectId, aa.type, aa.orderType, aa.insertTime, aa.nickName, aa.phone
        ) as datas where 1 = 1
        <if test="null != userType">
            and datas.userType = #{userType}
        </if>
        <if test="null != objectId">
            and datas.objectId = #{objectId}
        </if>
        <if test="null != insertTime">
            and datas.insertTime = #{insertTime}
        </if>
        order by datas.phone
    </select>
 
 
    <select id="getSumData" resultType="double">
        select
        ifnull(sum(aa.money), 0) as money
        from (
        select money,userType,objectId,DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime
        from t_income where 1 = 1
        <if test="null != userType">
            and userType = #{userType}
        </if>
        <if test="null != objectId">
            and objectId = #{objectId}
        </if>
        <if test="null != insertTime">
            and DATE_FORMAT(insertTime, '%Y/%m/%d') = #{insertTime}
        </if>
        <if test="null != types">
            and type in
            <foreach collection="types" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ) as aa group by aa.userType,aa.objectId,aa.insertTime
    </select>
 
 
    <select id="summaryOfSpendingDetailsList" resultType="map">
        select * from (
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as  insertTime
        from t_income where userType = 2 and money > 0
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by DATE_FORMAT(insertTime, '%Y/%m/%d')
        ) as aa order by aa.insertTime desc
        <if test="null != offset and null != limit">
            limit #{offset}, #{limit}
        </if>
    </select>
 
 
    <select id="summaryOfSpendingDetailsListCount" resultType="int">
        select count(1) from (
        select
        DATE_FORMAT(insertTime, '%Y/%m/%d') as  insertTime
        from t_income where userType = 1 and money > 0
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
        group by DATE_FORMAT(insertTime, '%Y/%m/%d')
        ) as aa
    </select>
 
    <select id="summaryOfSpendingDetailsListSum" resultType="map">
        select
        ifnull(ROUND(sum(aa.orderRevenue), 2), 0) as orderRevenue,
        ifnull(ROUND(sum(aa.activityAward), 2), 0) as activityAward,
        ifnull(ROUND(sum(aa.other), 2), 0) as other,
        ROUND(ifnull(sum(aa.orderRevenue), 0) + ifnull(sum(aa.activityAward), 0) + ifnull(sum(aa.other), 0), 2) as `all`
        from (
        select sum(money) as orderRevenue, 0 as activityAward, 0 as other from t_income where userType = 2 and money > 0 and type = 2
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select 0 as orderRevenue, sum(money) as activityAward, 0 as other from t_income where userType = 2 and money > 0 and type = 1
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        union all
 
        select 0 as orderRevenue, 0 as activityAward, sum(money) as other from t_income where userType = 2 and money > 0 and type in (3, 4, 5, 6, 7, 8, 9)
        <if test="null != companyId">
            and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
        </if>
 
        ) as aa
 
    </select>
 
 
    <select id="summaryOfSpendingDetailsList1" resultType="map">
        select
        aa.insertTime,
        aa.orderType,
        aa.type,
        bb.`name`,
        bb.phone,
        aa.objectId,
        ROUND(sum(aa.orderRevenue), 2) as orderRevenue,
        ROUND(sum(aa.activityAward), 2) as activityAward,
        ROUND(sum(aa.other), 2) as other,
        ROUND((sum(aa.orderRevenue) + sum(aa.activityAward) + sum(aa.other)), 2) as `all`
        from (
            select
            DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
            orderType,
            '跑单收入' as type,
            objectId,
            sum(money) as orderRevenue,
            0 as activityAward,
            0 as other
            from t_income where userType = 2 and type = 2 and DATE_FORMAT(insertTime, '%Y/%m/%d') = #{insertTime} group by  DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType, objectId
 
            union all
 
            select
            DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
            orderType,
            '活动收入' as type,
            objectId,
            0 as orderRevenue,
            sum(money) as activityAward,
            0 as other
            from t_income where userType = 2 and type = 1 and DATE_FORMAT(insertTime, '%Y/%m/%d') = #{insertTime} group by  DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType, objectId
 
            union all
 
            select
            DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
            orderType,
            '其他' as type,
            objectId,
            0 as orderRevenue,
            0 as activityAward,
            sum(money) as other
            from t_income where userType = 2 and type in (6, 9) and DATE_FORMAT(insertTime, '%Y/%m/%d') = #{insertTime} group by  DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType, objectId
        ) as aa
        left join t_driver bb on (aa.objectId = bb.id)
        group by aa.insertTime, aa.orderType, aa.type, aa.objectId
    </select>
</mapper>