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
<?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.TOrderSaleMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.TOrderSale">
        <id column="id" property="id" />
        <result column="orderTime" property="orderTime" />
        <result column="remark" property="remark" />
        <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="orderMoney" property="orderMoney" />
        <result column="payMoney" property="payMoney" />
        <result column="shopId" property="shopId" />
        <result column="generatorId" property="generatorId" />
        <result column="payType" property="payType" />
        <result column="isCover" property="isCover" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, orderTime, remark, createTime, updateTime, disabled, createBy, updateBy, orderNum, status,orderMoney,payMoney,shopId,generatorId,payType,isCover
    </sql>
    <delete id="deleteByShopId">
        delete from t_order_sale where shopId = #{shopId}
    </delete>
    <select id="pageList" resultType="com.ruoyi.system.vo.TOrderSaleVO">
        select id, orderTime, remark, createTime, updateTime, disabled, createBy, updateBy, orderNum, status,orderMoney,payMoney,shopId,generatorId,payType,isCover
        from t_order_sale
        <where>
            <if test="query.orderNum != null and query.orderNum != ''">
                AND orderNum LIKE concat('%', #{query.orderNum}, '%')
            </if>
            <if test="query.payType != null">
                AND payType = #{query.payType}
            </if>
            <if test="query.status != null">
                AND status = #{query.status}
            </if>
            <if test="query.shopId != null">
                and shopId = #{query.shopId}
            </if>
            <if test="query.isCover != null">
                and isCover = #{query.isCover}
            </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 (orderTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        ORDER BY orderTime DESC
    </select>
    <select id="amountSum" resultType="com.ruoyi.system.vo.AmountSumVO">
        select
        COUNT(id) AS orderCount,
        IFNULL(SUM(orderMoney),0) AS saleAmount,
        IFNULL(SUM(payMoney),0) AS payAmount,
        IFNULL(SUM(orderMoney - IFNULL(payMoney,0)),0) AS obligation
        from t_order_sale
        <where>
            <if test="query.orderNum != null and query.orderNum != ''">
                AND orderNum LIKE concat('%', #{query.orderNum}, '%')
            </if>
            <if test="query.payType != null">
                AND payType = #{query.payType}
            </if>
            <if test="query.status != null">
                AND status = #{query.status}
            </if>
            <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 (orderTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND 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_sale
        <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 (orderTime 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="exportOrderSale" resultType="com.ruoyi.system.vo.TOrderSaleVO">
        select id, orderTime, remark, createTime, updateTime, disabled, createBy, updateBy, orderNum, status,orderMoney,payMoney,shopId,payType
        from t_order_sale
        <where>
            <if test="query.orderNum != null and query.orderNum != ''">
                AND orderNum LIKE concat('%', #{query.orderNum}, '%')
            </if>
            <if test="query.payType != null">
                AND payType = #{query.payType}
            </if>
            <if test="query.status != null">
                AND status = #{query.status}
            </if>
            <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 (orderTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            AND isCover = 1
        </where>
        ORDER BY orderTime DESC
    </select>
    <select id="orderingTrends" resultType="com.ruoyi.system.vo.OrderTrendsVO">
        select
        DATE_FORMAT(orderTime, '%Y-%m-%d') AS dayTime,
        COUNT(id) AS orderCount
        from t_order_sale
        <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 (orderTime 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(orderTime, '%Y-%m-%d')
    </select>
    <select id="getDataGeneratorSaleDetail" 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_sale
        <where>
            <if test="query.generatorId != null">
                and generatorId = #{query.generatorId}
            </if>
            <if test="query.orderNum != null and query.orderNum != ''">
                AND orderNum LIKE concat('%', #{query.orderNum}, '%')
            </if>
            <if test="query.payType != null">
                and payType = #{query.payType}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (orderTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
    </select>
    <select id="saleGeneratorExport" resultType="com.ruoyi.system.vo.TOrderSaleVO">
        select id, orderTime, remark, createTime, updateTime, disabled, createBy, updateBy, orderNum, status,orderMoney,payMoney,shopId,payType
        from t_order_sale
        <where>
            <if test="query.generatorId != null">
                and generatorId = #{query.generatorId}
            </if>
            <if test="query.orderNum != null and query.orderNum != ''">
                AND orderNum LIKE concat('%', #{query.orderNum}, '%')
            </if>
            <if test="query.payType != null">
                and payType = #{query.payType}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (orderTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        ORDER BY orderTime DESC
    </select>
    <select id="saleGeneratorListExport" 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.userName 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.createTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND tdg.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            and tdg.orderType = 2
        </where>
        ORDER BY tdg.createTime DESC
    </select>
    <select id="profitDetails" resultType="com.ruoyi.system.vo.GoodsProfitVO">
        SELECT
        tomg.goodsName,
        (select typeName from t_goods_type where id = tomg.typeId) AS typeName,
        IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount,
        IFNULL(SUM( tomg.goodsCount * tomg.thisSalePrice ),0) AS goodsSaleAmount,
        IFNULL(SUM( tomg.goodsCount * tomg.goodsCostPrice ),0) AS goodsCostAmount,
        IFNULL(SUM(tomg.goodsCount *(tomg.thisSalePrice - tomg.goodsCostPrice)),0) AS goodsProfitAmount
        FROM t_order_sale_goods tomg
        LEFT JOIN t_order_sale tom ON tom.id = tomg.orderId
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.orderTime 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,
        IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount,
        IFNULL(SUM( tomg.goodsCount * tomg.thisSalePrice ),0) AS goodsSaleAmount,
        IFNULL(SUM( tomg.goodsCount * tomg.goodsCostPrice ),0) AS goodsCostAmount,
        IFNULL(SUM(tomg.goodsCount * (tomg.thisSalePrice - tomg.goodsCostPrice)),0) AS goodsProfitAmount
        FROM t_order_sale_goods tomg
        LEFT JOIN t_order_sale tom ON tom.id = tomg.orderId
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.orderTime 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,
        (select typeName from t_goods_type where id = tomg.typeId) AS typeName,
        IFNULL(SUM( tomg.goodsCount ),0) AS totalSalesCount,
        IFNULL(SUM( tomg.goodsCount * tomg.thisSalePrice ),0) AS goodsSaleAmount,
        IFNULL(SUM( tomg.goodsCount * tomg.goodsCostPrice ),0) AS goodsCostAmount,
        IFNULL(SUM(tomg.goodsCount *(tomg.thisSalePrice - tomg.goodsCostPrice)),0) AS goodsProfitAmount
        FROM t_order_sale_goods tomg
        LEFT JOIN t_order_sale tom ON tom.id = tomg.orderId
        <where>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (tom.orderTime 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="getDataGeneratorSaleDetailOrderMoney" 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_sale
        <where>
            <if test="query.generatorId != null">
                and generatorId = #{query.generatorId}
            </if>
            <if test="query.orderNum != null and query.orderNum != ''">
                AND orderNum LIKE concat('%', #{query.orderNum}, '%')
            </if>
            <if test="query.payType != null">
                and payType = #{query.payType}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND (orderTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
    </select>
 
</mapper>