xuhy
2024-09-19 20cd42287efb95254ea788ce2b6d0c559e378e04
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
<?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" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, orderTime, remark, createTime, updateTime, disabled, createBy, updateBy, orderNum, status,orderMoney,payMoney,shopId,generatorId,payType
    </sql>
    <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
        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.generatorId != null">
                and generatorId = #{query.generatorId}
            </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>
        ORDER BY orderTime DESC
    </select>
    <select id="amountSum" resultType="com.ruoyi.system.vo.AmountSumVO">
        select
            COUNT(id) AS orderCount,
            SUM(orderMoney) AS saleAmount,
            SUM(payMoney) AS payAmount,
            SUM(orderMoney - payMoney) 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 (createTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </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 (createTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </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
        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 (createTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </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 (createTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
    </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 (createTime 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
        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 (createTime 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.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.createTime BETWEEN #{query.startTime} AND #{query.endTime})
            </if>
            AND tdg.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            and tdg.orderType = 2
        </where>
    </select>
 
</mapper>