zhubaomin
2024-10-28 cef410f571a2960e979ca9383d9c8dd01ecc862c
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
<?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.dy.pipIrrGlobal.daoSe.SeGeneralMapper">
  <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoSe.SeGeneral">
    <!--@mbg.generated-->
    <!--@Table se_general-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="cashier_id" jdbcType="BIGINT" property="cashierId" />
    <result column="cashier_name" jdbcType="VARCHAR" property="cashierName" />
    <result column="trade_amount" jdbcType="FLOAT" property="tradeAmount" />
    <result column="gift" jdbcType="FLOAT" property="gift" />
    <result column="refund_amount" jdbcType="FLOAT" property="refundAmount" />
    <result column="operate_date" jdbcType="TIMESTAMP" property="operateDate" />
    <result column="audit_status" jdbcType="TINYINT" property="auditStatus" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, cashier_id, cashier_name, trade_amount, gift, refund_amount, operate_date, audit_status
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from se_general
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from se_general
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoSe.SeGeneral">
    <!--@mbg.generated-->
    insert into se_general (id, cashier_id, cashier_name, 
      trade_amount, gift, refund_amount,
      operate_date, audit_status)
    values (#{id,jdbcType=BIGINT}, #{cashierId,jdbcType=BIGINT}, #{cashierName,jdbcType=VARCHAR}, 
      #{tradeAmount,jdbcType=FLOAT}, #{gift,jdbcType=FLOAT}, #{refundAmount,jdbcType=FLOAT},
      #{operateDate,jdbcType=TIMESTAMP}, #{auditStatus,jdbcType=TINYINT})
  </insert>
  <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoSe.SeGeneral">
    <!--@mbg.generated-->
    insert into se_general
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="cashierId != null">
        cashier_id,
      </if>
      <if test="cashierName != null">
        cashier_name,
      </if>
      <if test="tradeAmount != null">
        trade_amount,
      </if>
      <if test="gift != null">
        gift,
      </if>
      <if test="refundAmount != null">
        refund_amount,
      </if>
      <if test="operateDate != null">
        operate_date,
      </if>
      <if test="auditStatus != null">
        audit_status,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="cashierId != null">
        #{cashierId,jdbcType=BIGINT},
      </if>
      <if test="cashierName != null">
        #{cashierName,jdbcType=VARCHAR},
      </if>
      <if test="tradeAmount != null">
        #{tradeAmount,jdbcType=FLOAT},
      </if>
      <if test="gift != null">
        #{gift,jdbcType=FLOAT},
      </if>
      <if test="refundAmount != null">
        #{refundAmount,jdbcType=FLOAT},
      </if>
      <if test="operateDate != null">
        #{operateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="auditStatus != null">
        #{auditStatus,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoSe.SeGeneral">
    <!--@mbg.generated-->
    update se_general
    <set>
      <if test="cashierId != null">
        cashier_id = #{cashierId,jdbcType=BIGINT},
      </if>
      <if test="cashierName != null">
        cashier_name = #{cashierName,jdbcType=VARCHAR},
      </if>
      <if test="tradeAmount != null">
        trade_amount = #{tradeAmount,jdbcType=FLOAT},
      </if>
      <if test="gift != null">
        gift = #{gift,jdbcType=FLOAT},
      </if>
      <if test="refundAmount != null">
        refund_amount = #{refundAmount,jdbcType=FLOAT},
      </if>
      <if test="operateDate != null">
        operate_date = #{operateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="auditStatus != null">
        audit_status = #{auditStatus,jdbcType=TINYINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoSe.SeGeneral">
    <!--@mbg.generated-->
    update se_general
    set cashier_id = #{cashierId,jdbcType=BIGINT},
      cashier_name = #{cashierName,jdbcType=VARCHAR},
      trade_amount = #{tradeAmount,jdbcType=FLOAT},
      gift = #{gift,jdbcType=FLOAT},
      refund_amount = #{refundAmount,jdbcType=FLOAT},
      operate_date = #{operateDate,jdbcType=TIMESTAMP},
      audit_status = #{auditStatus,jdbcType=TINYINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
 
  <!--获取未生成总账的交易日期列表(当天的交易记录不生成总账)-->
  <select id="getDatesOfNotInGenerals" resultType="java.util.HashMap">
    SELECT
      DISTINCT Date(ope.operate_dt) AS operateDate
    FROM se_card_operate ope
    WHERE Date(ope.operate_dt) NOT IN(SELECT operate_date FROM se_general)
<!--      取消当天限制-->
<!--      AND Date(ope.operate_dt) != CURDATE()-->
  </select>
 
  <!--根据交易日期获取总账记录列表(待生成的)  -->
  <select id="getGeneralByOperateDate" resultType="com.dy.pipIrrGlobal.pojoSe.SeGeneral">
    SELECT
        us.id AS cashierId,
        us.`name` AS cashierName,
        (IFNULL(SUM(ope.trade_amount),0) + IFNULL(SUM(ope.card_cost),0)) AS tradeAmount,
        IFNULL(SUM(ope.gift),0) AS gift,
        IFNULL(SUM(ope.refund_amount),0) AS refundAmount,
        Date(ope.operate_dt) AS operateDate,
        1 AS auditStatus
    FROM se_card_operate ope
        INNER JOIN ba_user us ON ope.operator = us.id
    WHERE Date(ope.operate_dt) = #{operateDate}
    GROUP BY ope.operator, Date(ope.operate_dt)
 
    UNION ALL
 
    SELECT
        1000000 AS cashierId,
        '微信' AS cashierName,
        IFNULL(SUM(amount), 0) AS tradeAmount,
        0 AS gift,
        0 AS refundAmount,
        Date(recharge_time) AS operateDate,
        1 AS auditStatus
    FROM se_wallet_recharge
    WHERE Date(recharge_time) = #{operateDate}
    GROUP BY Date(recharge_time)
 
    UNION ALL
 
    SELECT
        1000000 AS cashierId,
        '微信' AS cashierName,
        IFNULL(-SUM(refund_amount), 0) AS tradeAmount,
        0 AS gift,
        0 AS refundAmount,
        Date(audit_time) AS operateDate,
        1 AS auditStatus
    FROM se_refund
    WHERE Date(audit_time) = #{operateDate}
    GROUP BY Date(audit_time)
  </select>
 
  <!--根据指定条件获取总账记录数-->
  <select id="getRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
    SELECT
    COUNT(*) AS recordCount
    FROM se_general
    <where>
      <if test = "cashierName != null and cashierName !=''">
        AND cashier_name like CONCAT('%',#{cashierName},'%')
      </if>
 
      <if test = "auditStatus != null and auditStatus > 0">
        AND audit_status = #{auditStatus}
      </if>
 
      <if test = "operateDateStart != null and operateDateStop != null">
        AND Date(operate_date) BETWEEN #{operateDateStart} AND #{operateDateStop}
      </if>
    </where>
  </select>
 
  <!--根据指定条件获取总账记录-->
  <select id="getGenerals" resultType="com.dy.pipIrrGlobal.voSe.VoGeneral">
    SELECT
        id AS generalId,
        cashier_id AS cashierId,
        cashier_name AS cashierName,
        trade_amount AS tradeAmount,
        gift,
        refund_amount AS refundAmount,
        (trade_amount + gift - refund_amount) AS totalAmount,
        Date(operate_date) AS operateDate,
        (CASE
          WHEN audit_status = 1 THEN '未审核'
          WHEN audit_status = 2 THEN '同意'
          WHEN audit_status = 3 THEN '驳回'
        END) AS auditStatus
    FROM se_general
    <where>
      <if test = "cashierName != null and cashierName !=''">
        AND cashier_name like CONCAT('%',#{cashierName},'%')
      </if>
 
      <if test = "auditStatus != null and auditStatus > 0">
        AND audit_status = #{auditStatus}
      </if>
 
      <if test = "operateDateStart != null and operateDateStop != null">
        AND Date(operate_date) BETWEEN #{operateDateStart} AND #{operateDateStop}
      </if>
    </where>
    ORDER BY Date(operate_date) DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
 
  <!--获取指定日期、指定收银员、指定支付方式实收金额合计-->
  <select id="getPaymentSums" resultType="java.lang.Float">
    SELECT
        (SUM(ope.trade_amount) + SUM(ope.card_cost)) AS tradeAmount
    FROM se_card_operate ope
    <where>
      AND ope.operate_valid = 2
      <if test = "tradeDate != null and tradeDate !=''">
        AND Date(ope.operate_dt) = #{tradeDate}
      </if>
 
      <if test = "paymentId != null and paymentId >0">
        AND ope.payment_id = #{paymentId}
      </if>
 
      <if test = "cashierId != null and cashierId >0">
        AND ope.operator = #{cashierId}
      </if>
    </where>
<!--    GROUP BY ope.payment_id,  Date(ope.operate_dt)-->
  </select>
 
  <!--  财务对账审核页,收银员+日期分组,排除交易类型分组,记录数-->
<!--  <select id="getToAuditRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">-->
<!--    SELECT-->
<!--    COUNT(*) AS recordCount-->
<!--    FROM v_trade_summary-->
<!--    <where>-->
<!--      <if test = "cashierId != null and cashierId > 0">-->
<!--        AND cashierId = ${cashierId}-->
<!--      </if>-->
 
<!--      <if test = "tradeDate != null">-->
<!--        AND tradeDate = #{tradeDate}-->
<!--      </if>-->
<!--    </where>-->
<!--  </select>-->
 
  <!--开卡系统交易统计,收银员+日期+类型分组-->
  <select id="getSummaries" resultType="com.dy.pipIrrGlobal.voSe.VoTransactionStatistics">
    SELECT
        CASE
            WHEN ope.operate_type = 1 THEN '开卡'
            WHEN ope.operate_type = 2 THEN '充值'
            WHEN ope.operate_type = 3 THEN '销卡'
            WHEN ope.operate_type = 4 THEN '补卡'
            WHEN ope.operate_type = 5 THEN '返还'
            WHEN ope.operate_type = 10 THEN '反写'
        END AS operateType,
        Date(ope.operate_dt) AS tradeDate,
        COUNT(*) AS count,
        (IFNULL(SUM(ope.trade_amount), 0) + IFNULL(SUM(ope.card_cost), 0)) AS received,
        IFNULL(SUM(ope.gift), 0) AS gift,
        IFNULL(sum(ope.refund_amount),0) AS refundAmount,
        us.id AS cashierId
    FROM se_card_operate ope
        INNER JOIN ba_user us ON us.id = ope.operator
    <where>
      AND ope.operate_type IN(1,2,3,4,5,10)
      AND ope.operate_valid = 2
      <if test = "cashierId != null and cashierId > 0">
        AND us.id = #{cashierId}
      </if>
 
      <if test = "timeStart != null and timeStop != null">
        AND Date(ope.operate_dt) BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
    GROUP BY ope.operate_type,  Date(ope.operate_dt), us.id
    ORDER BY tradeDate
 
<!--    SELECT * FROM v_trade_summary-->
<!--    <where>-->
<!--      <if test = "cashierId != null and cashierId > 0">-->
<!--        AND cashierId = #{cashierId}-->
<!--      </if>-->
 
<!--      <if test = "timeStart != null and timeStop != null">-->
<!--        AND Date(tradeDate) BETWEEN #{timeStart} AND #{timeStop}-->
<!--      </if>-->
<!--    </where>-->
<!--    ORDER BY tradeDate-->
  </select>
 
  <!--  根据收银员ID及日期获取财务对账_交易明细记录数-->
  <select id="getTradeDetailsRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
    SELECT
        COUNT(*) AS recordCount
    FROM v_trade_details
    <where>
      <if test = "cashierId != null and cashierId > 0">
        AND cashierId = #{cashierId}
      </if>
 
      <if test = "tradeDate != null">
        AND Date(tradeTime) = #{tradeDate}
      </if>
    </where>
  </select>
 
  <!--根据收银员ID及日期获取财务对账_交易明细记录-->
  <select id="getTradeDetails" resultType="com.dy.pipIrrGlobal.voSe.VoTradeDetails">
    SELECT * FROM v_trade_details
    <where>
      <if test = "cashierId != null and cashierId > 0">
        AND cashierId = #{cashierId}
      </if>
 
      <if test = "tradeDate != null">
        AND Date(tradeTime) = #{tradeDate}
      </if>
    </where>
    ORDER BY tradeTime
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
</mapper>