xuhy
2025-05-19 508f3e225df87e0da974424981e7782fc5ce875c
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?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.system.mapper.TOrderMealMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.TOrderMeal">
        <id column="id" property="id" />
        <result column="boardId" property="boardId" />
        <result column="mealType" property="mealType" />
        <result column="mealPerson" property="mealPerson" />
        <result column="orderMoney" property="orderMoney" />
        <result column="payMoney" property="payMoney" />
        <result column="payType" property="payType" />
        <result column="createTime" property="createTime" />
        <result column="updateTime" property="updateTime" />
        <result column="disabled" property="disabled" />
        <result column="createBy" property="createBy" />
        <result column="updateBy" property="updateBy" />
        <result column="orderNum" property="orderNum" />
        <result column="status" property="status" />
        <result column="isCover" property="isCover" />
        <result column="shopId" property="shopId" />
        <result column="generatorId" property="generatorId" />
        <result column="remark" property="remark" />
        <result column="mealTime" property="mealTime" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, boardId, mealType, mealPerson, orderMoney, payMoney, payType, createTime, updateTime, disabled,
            createBy, updateBy, orderNum, status,isCover,shopId,generatorId,remark,mealTime
    </sql>
    <delete id="deleteByShopId">
        delete from t_order_meal where shopId = #{shopId}
    </delete>
    <select id="pageList" resultType="com.ruoyi.system.vo.TOrderMealVO">
        select
        tom.id, tom.boardId, tom.mealType, tom.mealPerson, tom.orderMoney, tom.payMoney, tom.payType, tom.createTime, tom.updateTime, tom.disabled,
        tom.createBy, tom.updateBy, tom.orderNum, tom.status,tom.isCover,tom.shopId,tom.generatorId,tom.remark,tom.mealTime,tb.boardName
        from t_order_meal tom
        left join t_board tb on tb.id = tom.boardId
        <where>
            <if test="query.mealType != null">
                and tom.mealType = #{query.mealType}
            </if>
            <if test="query.payType != null">
                and tom.payType = #{query.payType}
            </if>
            <if test="query.status != null">
                and tom.status = #{query.status}
            </if>
            <if test="query.orderNum != null and query.orderNum != ''">
                and tom.orderNum LIKE concat('%',#{query.orderNum},'%')
            </if>
            <if test="query.shopId != null">
                and tom.shopId = #{query.shopId}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND tom.isCover = 1
        </where>
        ORDER BY tom.mealTime DESC , tom.createTime DESC
    </select>
    <select id="amountSum" resultType="com.ruoyi.system.vo.AmountSumVO">
        select
            COUNT(tom.id) AS orderCount,
            IFNULL(SUM(tom.orderMoney),0) AS saleAmount,
            IFNULL(SUM(tom.payMoney),0) AS payAmount,
            IFNULL(SUM(tom.orderMoney - tom.payMoney),0) AS obligation
        from t_order_meal tom
        left join t_board tb on tb.id = tom.boardId
        <where>
            <if test="query.mealType != null">
                and tom.mealType = #{query.mealType}
            </if>
            <if test="query.payType != null">
                and tom.payType = #{query.payType}
            </if>
            <if test="query.status != null">
                and tom.status = #{query.status}
            </if>
            <if test="query.orderNum != null and query.orderNum">
                and tom.orderNum LIKE concat('%',#{query.orderNum},'%')
            </if>
            <if test="query.shopId != null">
                and tom.shopId = #{query.shopId}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND tom.isCover = 1
        </where>
    </select>
    <select id="salesVolume" resultType="com.ruoyi.system.vo.SalesVolumeVO">
        select
            IFNULL(SUM(CASE WHEN payType = 1 THEN payMoney ELSE 0 END),0) AS moneyPay,
            IFNULL(SUM(CASE WHEN payType = 2 THEN payMoney ELSE 0 END),0) AS aliPay,
            IFNULL(SUM(CASE WHEN payType = 3 THEN payMoney ELSE 0 END),0) AS weiXinPay,
            IFNULL(SUM(CASE WHEN payType = 4 THEN payMoney ELSE 0 END),0) AS cardPay,
            IFNULL(SUM(CASE WHEN payType = 5 THEN payMoney ELSE 0 END),0) AS otherPay
        from t_order_meal
        <where>
            <if test="query.shopId != null">
                and shopId = #{query.shopId}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND isCover = 1
            AND status = 2
        </where>
    </select>
    <select id="exportOrderMeal" resultType="com.ruoyi.system.vo.TOrderMealVO">
        select
        tom.id, tom.boardId, tom.mealType, tom.mealPerson, tom.orderMoney, tom.payMoney, tom.payType, tom.createTime, tom.updateTime, tom.disabled,
        tom.createBy, tom.updateBy, tom.orderNum, tom.status,tom.isCover,tom.shopId,tom.remark,tom.mealTime,tb.boardName
        from t_order_meal tom
        left join t_board tb on tb.id = tom.boardId
        <where>
            <if test="query.mealType != null">
                and tom.mealType = #{query.mealType}
            </if>
            <if test="query.payType != null">
                and tom.payType = #{query.payType}
            </if>
            <if test="query.status != null">
                and tom.status = #{query.status}
            </if>
            <if test="query.orderNum != null and query.orderNum">
                and tom.orderNum LIKE concat('%',#{query.orderNum},'%')
            </if>
            <if test="query.shopId != null">
                and tom.shopId = #{query.shopId}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.createTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        ORDER BY tom.createTime DESC
    </select>
    <select id="orderingTrends" resultType="com.ruoyi.system.vo.OrderTrendsVO">
        select
        DATE_FORMAT(mealTime, '%Y-%m-%d') AS dayTime,
        COUNT(id) AS orderCount
        from t_order_meal
        <where>
            <if test="query.shopId != null">
                AND shopId = #{query.shopId}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND isCover = 1
            AND status = 2
        </where>
        GROUP BY DATE_FORMAT(mealTime, '%Y-%m-%d')
    </select>
    <select id="personnelStatistics" resultType="com.ruoyi.system.vo.PersonnelStatisticsVO">
        select
        tb.boardName,tom.mealPerson AS personCount, ROUND((tom.payMoney/tom.mealPerson),2) AS avgAmount
        from t_order_meal tom
        left join t_board tb on tb.id = tom.boardId
        <where>
            <if test="query.shopId != null">
                AND tom.shopId = #{query.shopId}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND tom.isCover = 1
            AND tom.status = 2
        </where>
    </select>
    <select id="pageListGenerator" resultType="com.ruoyi.system.vo.TOrderMealVO">
        select
        tom.id, tom.boardId, tom.mealType, tom.mealPerson, tom.orderMoney, tom.payMoney, tom.payType, tom.createTime, tom.updateTime, tom.disabled,
        tom.createBy, tom.updateBy, tom.orderNum, tom.status,tom.isCover,tom.shopId,tom.generatorId,tom.remark,tom.mealTime,tb.boardName
        from t_order_meal tom
        left join t_board tb on tb.id = tom.boardId
        <where>
            <if test="query.generatorId != null">
                and tom.generatorId = #{query.generatorId}
            </if>
            <if test="query.payType != null">
                and tom.payType = #{query.payType}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.mealTime BETWEEN CONCAT(DATE_FORMAT(#{query.startTime},'%Y-%m-%d %H:%i:%s'),' 00:00:00')
                    AND CONCAT(DATE_FORMAT(#{query.endTime},'%Y-%m-%d %H:%i:%s'),' 23:59:59'))
            </if>
        </where>
        ORDER BY tom.mealTime DESC
    </select>
    <select id="getDataGeneratorMealDetail" resultType="java.util.Map">
        SELECT
            IFNULL(SUM(CASE WHEN payType = 1 THEN payMoney ELSE 0 END),0) AS moneyPay,
            IFNULL(SUM(CASE WHEN payType = 2 THEN payMoney ELSE 0 END),0) AS aliPay,
            IFNULL(SUM(CASE WHEN payType = 3 THEN payMoney ELSE 0 END),0) AS weiXinPay,
            IFNULL(SUM(CASE WHEN payType = 4 THEN payMoney ELSE 0 END),0) AS cardPay,
            IFNULL(SUM(CASE WHEN payType = 5 THEN payMoney ELSE 0 END),0) AS otherPay
        from t_order_meal
        <where>
            <if test="query.generatorId != null">
                and generatorId = #{query.generatorId}
            </if>
            <if test="query.payType != null">
                and payType = #{query.payType}
            </if>
            <if test="query.generatorId != null">
                and generatorId = #{query.generatorId}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
    </select>
    <select id="mealGeneratorExport" resultType="com.ruoyi.system.vo.TOrderMealVO">
        select
        tom.id, tom.boardId, tom.mealType, tom.mealPerson, tom.orderMoney, tom.payMoney, tom.payType, tom.createTime, tom.updateTime, tom.disabled,
        tom.createBy, tom.updateBy, tom.orderNum, tom.status,tom.isCover,tom.shopId,tom.remark,tom.mealTime,tb.boardName
        from t_order_meal tom
        left join t_board tb on tb.id = tom.boardId
        <where>
            <if test="query.payType != null">
                and tom.payType = #{query.payType}
            </if>
            <if test="query.generatorId != null">
                and tom.generatorId = #{query.generatorId}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.mealTime BETWEEN CONCAT(DATE_FORMAT(#{query.startTime},'%Y-%m-%d %H:%i:%s'),' 00:00:00')
                AND CONCAT(DATE_FORMAT(#{query.endTime},'%Y-%m-%d %H:%i:%s'),' 23:59:59'))
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        ORDER BY tom.mealTime DESC
    </select>
    <select id="mealGeneratorListExport" resultType="com.ruoyi.system.vo.TDataGeneratorVO">
        select tdg.id, tdg.userId, tdg.userName, tdg.shopId, tdg.startTime, tdg.endTime, tdg.minMoney, tdg.maxMoney, tdg.status, tdg.createTime,
        tdg.updateTime, tdg.disabled, tdg.createBy, tdg.updateBy,tdg.orderType,tdg.weiXinPay,tdg.aliPay,tdg.cardPay,tdg.moneyPay,tdg.otherPay,
        ts.shopName
        from t_data_generator tdg
        left join t_shop ts on tdg.shopId = ts.id
        <where>
            <if test="query.shopName != null and query.shopName != ''">
                and ts.shopName like concat('%', #{query.shopName}, '%')
            </if>
            <if test="query.userName != null and query.userName != ''">
                and tdg.shopName like concat('%', #{query.userName}, '%')
            </if>
            <if test="query.status != null">
                and tdg.status = #{query.status}
            </if>
            <if test="query.ids != null and query.ids.size()>0">
                and tdg.id IN
                <foreach collection="query.ids" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="query.orderType != null">
                and tdg.orderType = #{query.orderType}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tdg.mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND tdg.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            and tdg.orderType = 1
        </where>
        ORDER BY tdg.createTime DESC
    </select>
    <select id="profitDetails" resultType="com.ruoyi.system.vo.GoodsProfitVO">
        SELECT
        tomg.goodsName,
        tomg.typeName,
        IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount,
        IFNULL(SUM( tomg.goodsCount * tomg.goodsSalePrice ),0) AS goodsSaleAmount,
        IFNULL(SUM( tomg.goodsCount * tomg.costPrice ),0) AS goodsCostAmount,
        IFNULL(SUM(tomg.goodsCount *(tomg.goodsSalePrice - tomg.costPrice)),0) AS goodsProfitAmount
        FROM t_order_meal_goods tomg
        LEFT JOIN t_order_meal tom ON tom.id = tomg.orderId
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            <if test="query.goodsName != null and query.goodsName != ''">
                AND tomg.goodsName like concat('%', #{query.goodsName}, '%')
            </if>
            <if test="query.typeId != null and query.typeId != ''">
                AND tomg.typeId = #{query.typeId}
            </if>
            <if test="query.shopId != null">
                AND tom.shopId = #{query.shopId}
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND tom.isCover = 1
            AND tom.status = 2
        </where>
        GROUP BY tomg.goodsName
    </select>
    <select id="profitDetailsStatistics" resultType="java.util.Map">
        SELECT
        IFNULL(SUM(a.goodsSaleAmount),0) AS totalSales,
        IFNULL(SUM(a.goodsCostAmount),0) AS totalCosts,
        IFNULL(SUM(a.goodsProfitAmount),0) AS totalProfits
        FROM (
        SELECT
        tomg.goodsName,
        tomg.typeName,
        IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount,
        IFNULL(SUM( tomg.goodsCount * tomg.goodsSalePrice ),0) AS goodsSaleAmount,
        IFNULL(SUM( tomg.goodsCount * tomg.costPrice ),0) AS goodsCostAmount,
        IFNULL(SUM(tomg.goodsCount *(tomg.goodsSalePrice - tomg.costPrice)),0) AS goodsProfitAmount
        FROM t_order_meal_goods tomg
        LEFT JOIN t_order_meal tom ON tom.id = tomg.orderId
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            <if test="query.goodsName != null and query.goodsName != ''">
                AND tomg.goodsName like concat('%', #{query.goodsName}, '%')
            </if>
            <if test="query.typeId != null and query.typeId != ''">
                AND tomg.typeId = #{query.typeId}
            </if>
            <if test="query.shopId != null">
                AND tom.shopId = #{query.shopId}
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND tom.isCover = 1
            AND tom.status = 2
        </where>
        GROUP BY tomg.goodsName) a
    </select>
    <select id="profitDetailsExport" resultType="com.ruoyi.system.vo.GoodsProfitVO">
        SELECT
        tomg.goodsName,
        tomg.typeName,
        IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount,
        IFNULL(SUM( tomg.goodsCount * tomg.goodsSalePrice ),0) AS goodsSaleAmount,
        IFNULL(SUM( tomg.goodsCount * tomg.costPrice ),0) AS goodsCostAmount,
        IFNULL(SUM(tomg.goodsCount *(tomg.goodsSalePrice - tomg.costPrice)),0) AS goodsProfitAmount
        FROM t_order_meal_goods tomg
        LEFT JOIN t_order_meal tom ON tom.id = tomg.orderId
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            <if test="query.goodsName != null and query.goodsName != ''">
                AND tomg.goodsName like concat('%', #{query.goodsName}, '%')
            </if>
            <if test="query.typeId != null and query.typeId != ''">
                AND tomg.typeId = #{query.typeId}
            </if>
            <if test="query.shopId != null">
                AND tom.shopId = #{query.shopId}
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND tom.isCover = 1
            AND tom.status = 2
        </where>
        GROUP BY tomg.goodsName
    </select>
    <select id="getDataGeneratorMealDetailOrderMoney" resultType="java.util.Map">
        SELECT
        IFNULL(SUM(CASE WHEN payType = 1 THEN orderMoney ELSE 0 END),0) AS moneyPay,
        IFNULL(SUM(CASE WHEN payType = 2 THEN orderMoney ELSE 0 END),0) AS aliPay,
        IFNULL(SUM(CASE WHEN payType = 3 THEN orderMoney ELSE 0 END),0) AS weiXinPay,
        IFNULL(SUM(CASE WHEN payType = 4 THEN orderMoney ELSE 0 END),0) AS cardPay,
        IFNULL(SUM(CASE WHEN payType = 5 THEN orderMoney ELSE 0 END),0) AS otherPay
        from t_order_meal
        <where>
            <if test="query.generatorId != null">
                and generatorId = #{query.generatorId}
            </if>
            <if test="query.payType != null">
                and payType = #{query.payType}
            </if>
            <if test="query.generatorId != null">
                and generatorId = #{query.generatorId}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
    </select>
    <select id="sumExport" resultType="com.ruoyi.system.export.SumGeneratorDetailClient">
        select
        DATE_FORMAT(mealTime, '%Y-%m-%d') AS dayTime,
        IFNULL(SUM(payMoney),0) AS actualAmount,
        IFNULL(COUNT(id),0) AS orderCount,
        IFNULL(SUM(mealPerson),0) AS perCount
        from t_order_meal
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (mealTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        GROUP BY DATE_FORMAT(mealTime, '%Y-%m-%d')
    </select>
</mapper>