xuhy
2024-09-04 c92aa3899e11a355cddfcfeaececcc843d7ad1bb
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
<?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="shopId" property="shopId" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, boardId, mealType, mealPerson, orderMoney, payMoney, payType, createTime, updateTime, disabled,
            createBy, updateBy, orderNum, status,isCover,shopId
    </sql>
    <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,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.status},'%')
            </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="amountSum" resultType="com.ruoyi.system.vo.AmountSumVO">
        select
            COUNT(tom.id) AS orderCount,
            SUM(tom.orderMoney) AS saleAmount,
            SUM(tom.payMoney) AS payAmount,
            SUM(tom.orderMoney - tom.payMoney) 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.status},'%')
            </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>
    </select>
    <select id="salesVolume" resultType="com.ruoyi.system.vo.SalesVolumeVO">
        select
            SUM(CASE WHEN payType = 1 THEN payMoney ELSE 0 END) AS moneyPay,
            SUM(CASE WHEN payType = 2 THEN payMoney ELSE 0 END) AS aliPay,
            SUM(CASE WHEN payType = 3 THEN payMoney ELSE 0 END) AS weiXinPay,
            SUM(CASE WHEN payType = 4 THEN payMoney ELSE 0 END) AS cardPay,
            SUM(CASE WHEN payType = 5 THEN payMoney ELSE 0 END) 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 (createTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </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,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.status},'%')
            </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(createTime, '%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 (createTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
    </select>
    <select id="personnelStatistics" resultType="com.ruoyi.system.vo.PersonnelStatisticsVO">
        select
        tb.boardName,tom.mealPerson, (tom.payMoney/tom.mealPerson) 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.createTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND tom.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
    </select>
 
</mapper>