puzhibing
2023-02-15 2811bab657aab4145b65a45a824fb63e93b58e30
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.UserCouponRecord;
import com.stylefeng.guns.modular.system.dao.UserCouponRecordMapper;
import com.stylefeng.guns.modular.system.service.ITCompanyService;
import com.stylefeng.guns.modular.system.service.IUserCouponRecordService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 用户优惠券记录 服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2020-06-17
 */
@Service
public class UserCouponRecordServiceImpl extends ServiceImpl<UserCouponRecordMapper, UserCouponRecord> implements IUserCouponRecordService {
 
    @Autowired
    private ITCompanyService companyService;
 
 
 
 
 
    @Override
    public List<Map<String, Object>> getList(Page<Map<String, Object>> page, String beginTime, String endTime, String userName, String userPhone, Integer couponActivityId, Integer activityType,Integer state) {
        return this.baseMapper.getList(page,beginTime,endTime,userName,userPhone,couponActivityId,activityType,state);
    }
    @Override
    public List<Map<String, Object>> getRedList(Page<Map<String, Object>> page, String beginTime, String endTime, String userName, String userPhone, Integer couponActivityId,Integer state) {
        return this.baseMapper.getRedList(page,beginTime,endTime,userName,userPhone,couponActivityId,state);
    }
    @Override
    public Map<String, Object> getCouponStatic(String beginTime, String endTime, Integer activityId, Integer activityType) {
        return this.baseMapper.getCouponStatic(beginTime,endTime,activityId,activityType);
    }
 
    @Override
    public Map<String, Object> getRedStatic(String beginTime, String endTime, Integer activityId) {
        return this.baseMapper.getRedStatic(beginTime,endTime,activityId);
    }
 
    @Override
    public Map<String, Object> getRegStatic(String beginTime, String endTime, Integer activityId) {
        return this.baseMapper.getRegStatic(beginTime,endTime,activityId);
    }
 
    @Override
    public Map<String, Object> getDiscountStatic(String beginTime, String endTime, Integer activityId) {
        return this.baseMapper.getDiscountStatic(beginTime,endTime,activityId);
    }
 
    @Override
    public List<Map<String, Object>> getBlanceList(Page<Map<String, Object>> page, String beginTime, String endTime, Integer activityId) {
        return this.baseMapper.getBlanceList(page,beginTime,endTime,activityId);
    }
 
 
    /**
     * 获取优惠券领取统计
     * @param type
     * @param name
     * @param time
     * @param companyId
     * @param offset
     * @param limit
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryCouponRegister(Integer type, String name, String time, Integer companyId, Integer offset, Integer limit) throws Exception {
        Map<String, Object> map = new HashMap<>();
        String start = null;
        String end = null;
        if(ToolUtil.isNotEmpty(time)){
            start = time.split(" - ")[0];
            end = time.split(" - ")[1];
        }
        List<Map<String, Object>> list = this.baseMapper.queryCouponRegister(type, name, start, end, companyId, offset, limit);
        int i = this.baseMapper.queryCouponRegisterCount(type, name, start, end, companyId);
        map.put("rows", list);
        map.put("total", i);
        return map;
    }
 
    /**
     * 下载优惠券领取数据
     * @param type
     * @param name
     * @param time
     * @param companyId
     * @return
     * @throws Exception
     */
    @Override
    public HSSFWorkbook downloadCouponRegister(Integer type, String name, String time, Integer companyId) throws Exception {
        String start = null;
        String end = null;
        if(ToolUtil.isNotEmpty(time)){
            start = time.split(" - ")[0];
            end = time.split(" - ")[1];
        }
        List<Map<String, Object>> maps = this.baseMapper.queryCouponRegister(type, name, start, end, companyId, null, null);
        List<List<String>> lists = new ArrayList<>();
        List<String> list = new ArrayList<>();
        list.add("活动名称:");
        list.add(name);
        if(type == 2){
            list.add("");
        }
        list.add("起止时间:");
        list.add(time);
        list.add("");
        list.add("运营商:");
        list.add(null != companyId ? companyService.selectById(companyId).getName() : "");
        lists.add(list);
        list = new ArrayList<>();
        list.add("时间");
        list.add("领取情况");
        if(type == 2){
            list.add("");
        }
        list.add("");
        list.add("");
        list.add("使用情况");
        list.add("");
        list.add("");
        lists.add(list);
        list = new ArrayList<>();
        list.add("");
        list.add("注册领取人数");
        if(type == 2){
            list.add("赠送派发人数");
        }
        list.add("合计");
        list.add("领取金额");
        list.add("使用人数");
        list.add("使用张数");
        list.add("使用金额");
        lists.add(list);
 
        List<List<List<String>>> lists1 = new ArrayList<>();
        List<List<String>> lists2 = new ArrayList<>();
        for(Map<String, Object> map : maps){
            List<String> list2 = new ArrayList<>();
            list2.add(null != map.get("time") ? map.get("time").toString() : "");
            list2.add(null != map.get("receivePeople") ? map.get("receivePeople").toString() : "");
            if(type == 2){
                list2.add(null != map.get("giving") ? map.get("giving").toString() : "");
            }
            list2.add(null != map.get("receive") ? map.get("receive").toString() : "");
            list2.add(null != map.get("receiveMoney") ? map.get("receiveMoney").toString() : "");
            list2.add(null != map.get("usePeople") ? map.get("usePeople").toString() : "");
            list2.add(null != map.get("use") ? map.get("use").toString() : "");
            list2.add(null != map.get("useMoney") ? map.get("useMoney").toString() : "");
            lists2.add(list2);
        }
        lists1.add(lists2);
 
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
        HSSFSheet hssfSheet = hssfWorkbook.createSheet();
        hssfSheet.setColumnWidth(0, 6 * 256);
        hssfSheet.setDefaultRowHeightInPoints(20f);
        for(int i = 0; i < lists.size(); i++){
            HSSFRow hssfRow = hssfSheet.createRow(i);//设置第一行数据(标题)
            HSSFCellStyle style = hssfWorkbook.createCellStyle();
            HSSFFont font = hssfWorkbook.createFont();
            font.setBold(true);
            style.setFont(font);
            style.setAlignment(HorizontalAlignment.CENTER);
            for (int l = 0; l < lists.get(i).size(); l++) {
                HSSFCell hssfCell = hssfRow.createCell(l);
                hssfCell.setCellType(CellType.STRING);//设置表格类型
                hssfCell.setCellValue(lists.get(i).get(l));
                hssfCell.setCellStyle(style);
                if(l > 0) {
                    hssfSheet.setColumnWidth(l , 20 * 256);
                }
 
            }
        }
        //这个就是合并单元格
        //参数说明:1:开始行 2:结束行  3:开始列 4:结束列
        //比如我要合并 第二行到第四行的    第六列到第八列     sheet.addMergedRegion(new CellRangeAddress(1,3,5,7));
        if(type == 2){
            hssfSheet.addMergedRegion(new CellRangeAddress(0,0,1,2));
            hssfSheet.addMergedRegion(new CellRangeAddress(0,0,4,5));
            hssfSheet.addMergedRegion(new CellRangeAddress(1,2,0,0));
            hssfSheet.addMergedRegion(new CellRangeAddress(1,1,1,4));
            hssfSheet.addMergedRegion(new CellRangeAddress(1,1,5,7));
        }else{
            hssfSheet.addMergedRegion(new CellRangeAddress(0,0,3,4));
            hssfSheet.addMergedRegion(new CellRangeAddress(1,2,0,0));
            hssfSheet.addMergedRegion(new CellRangeAddress(1,1,1,3));
            hssfSheet.addMergedRegion(new CellRangeAddress(1,1,4,6));
        }
 
 
 
        for(int i = 0; i < lists1.size(); i++){
            //将数据添加到表格中
            List<String> data = null;
            for (int l = 0; l < lists1.get(i).size(); l++) {
                HSSFRow row = hssfSheet.createRow(l + 3);
                data = lists1.get(i).get(l);
                for (int j = 0; j < data.size(); j++) {
                    HSSFCell hssfCell = row.createCell(j);
                    hssfCell.setCellType(CellType.STRING);//设置表格类型
                    hssfCell.setCellValue(data.get(j));
                }
            }
        }
        return hssfWorkbook;
    }
 
 
    /**
     * 获取优惠券统计明细
     * @param type
     * @param name
     * @param time
     * @param companyId
     * @param offset
     * @param limit
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryCouponRegisterInfo(Integer type, String name, String time, Integer companyId, Integer offset, Integer limit) throws Exception {
        String start = null;
        String end = null;
        if(ToolUtil.isNotEmpty(time)){
            start = time.split(" - ")[0];
            end = time.split(" - ")[1];
        }
        List<Map<String, Object>> list = this.baseMapper.queryCouponRegisterInfo(type, name, start, end, companyId, offset, limit);
        int i = this.baseMapper.queryCouponRegisterInfoCount(type, name, start, end, companyId);
        Map<String, Object> map = new HashMap<>();
        map.put("rows", list);
        map.put("total", i);
        return map;
    }
 
    @Override
    public HSSFWorkbook downloadCouponRegisterInfo(Integer type, String name, String time, Integer companyId) {
        String start = null;
        String end = null;
        if(ToolUtil.isNotEmpty(time)){
            start = time.split(" - ")[0];
            end = time.split(" - ")[1];
        }
        List<Map<String, Object>> maps = this.baseMapper.queryCouponRegisterInfo(type, name, start, end, companyId, null, null);
 
        List<List<String>> lists = new ArrayList<>();
        List<String> list = new ArrayList<>();
        list.add("活动名称:");
        list.add(name);
        list.add("");
        list.add("起止时间:");
        list.add(time);
        list.add("");
        list.add("运营商:");
        list.add(null != companyId ? companyService.selectById(companyId).getName() : "");
        lists.add(list);
        list = new ArrayList<>();
        list.add("领取时间");
        list.add("领取人");
        list.add("领取人电话");
        list.add("领取金额");
        list.add("到期时间");
        list.add("领取类型");
        list.add("状态");
        list.add("使用时间");
        lists.add(list);
 
        List<List<List<String>>> lists1 = new ArrayList<>();
        List<List<String>> lists2 = new ArrayList<>();
        for(Map<String, Object> map : maps){
            List<String> list2 = new ArrayList<>();
            list2.add(null != map.get("time") ? map.get("time").toString() : "");
            list2.add(null != map.get("userName") ? map.get("userName").toString() : "");
            list2.add(null != map.get("phone") ? map.get("phone").toString() : "");
            list2.add(null != map.get("money") ? map.get("money").toString() : "");
            list2.add(null != map.get("expirationTime") ? map.get("expirationTime").toString() : "");
            list2.add(null != map.get("couponType") ? map.get("couponType").toString() : "");
            list2.add(null != map.get("state") ? map.get("state").toString() : "");
            list2.add(null != map.get("endTime") ? map.get("endTime").toString() : "");
            lists2.add(list2);
        }
        lists1.add(lists2);
 
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
        HSSFSheet hssfSheet = hssfWorkbook.createSheet();
        hssfSheet.setColumnWidth(0, 6 * 256);
        hssfSheet.setDefaultRowHeightInPoints(20f);
        for(int i = 0; i < lists.size(); i++){
            HSSFRow hssfRow = hssfSheet.createRow(i);//设置第一行数据(标题)
            HSSFCellStyle style = hssfWorkbook.createCellStyle();
            HSSFFont font = hssfWorkbook.createFont();
            font.setBold(true);
            style.setFont(font);
            style.setAlignment(HorizontalAlignment.CENTER);
            for (int l = 0; l < lists.get(i).size(); l++) {
                HSSFCell hssfCell = hssfRow.createCell(l);
                hssfCell.setCellType(CellType.STRING);//设置表格类型
                hssfCell.setCellValue(lists.get(i).get(l));
                hssfCell.setCellStyle(style);
                if(l > 0) {
                    hssfSheet.setColumnWidth(l , 20 * 256);
                }
 
            }
        }
        //这个就是合并单元格
        //参数说明:1:开始行 2:结束行  3:开始列 4:结束列
        //比如我要合并 第二行到第四行的    第六列到第八列     sheet.addMergedRegion(new CellRangeAddress(1,3,5,7));
        hssfSheet.addMergedRegion(new CellRangeAddress(0,0,1,2));
        hssfSheet.addMergedRegion(new CellRangeAddress(0,0,4,5));
 
        for(int i = 0; i < lists1.size(); i++){
            //将数据添加到表格中
            List<String> data = null;
            for (int l = 0; l < lists1.get(i).size(); l++) {
                HSSFRow row = hssfSheet.createRow(l + 2);
                data = lists1.get(i).get(l);
                for (int j = 0; j < data.size(); j++) {
                    HSSFCell hssfCell = row.createCell(j);
                    hssfCell.setCellType(CellType.STRING);//设置表格类型
                    hssfCell.setCellValue(data.get(j));
                }
            }
        }
        return hssfWorkbook;
    }
 
    @Override
    public HSSFWorkbook downloadCouponRegisterInfo1(String name, String time, Integer companyId) {
        String start = null;
        String end = null;
        if(ToolUtil.isNotEmpty(time)){
            start = time.split(" - ")[0];
            end = time.split(" - ")[1];
        }
        List<Map<String, Object>> maps = this.baseMapper.queryCouponRegisterInfo1(name, start, end, companyId, null, null);
 
        List<List<String>> lists = new ArrayList<>();
        List<String> list = new ArrayList<>();
        list.add("活动名称:");
        list.add(name);
        list.add("");
        list.add("起止时间:");
        list.add(time);
        list.add("");
        list.add("运营商:");
        list.add(null != companyId ? companyService.selectById(companyId).getName() : "");
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        list.add("");
        lists.add(list);
        list = new ArrayList<>();
        list.add("充值时间");
        list.add("充值人");
        list.add("充值人电话");
        list.add("充值金额");
        list.add("通用券领取总数");
        list.add("通用券使用总数");
        list.add("通用券使用总金额");
        list.add("专车券领取总数");
        list.add("专车券使用总数");
        list.add("专车券使用总金额");
        list.add("出租车券领取总数");
        list.add("出租车券使用总数");
        list.add("出租车券使用总金额");
        list.add("跨城券领取总数");
        list.add("跨城券使用总数");
        list.add("跨城券使用总金额");
        lists.add(list);
 
        List<List<List<String>>> lists1 = new ArrayList<>();
        List<List<String>> lists2 = new ArrayList<>();
        for(Map<String, Object> map : maps){
            List<String> list2 = new ArrayList<>();
            list2.add(null != map.get("time") ? map.get("time").toString() : "");
            list2.add(null != map.get("userName") ? map.get("userName").toString() : "");
            list2.add(null != map.get("phone") ? map.get("phone").toString() : "");
            list2.add(null != map.get("amount") ? map.get("amount").toString() : "");
            list2.add(null != map.get("tyNum") ? map.get("tyNum").toString() : "");
            list2.add(null != map.get("tyUseNum") ? map.get("tyUseNum").toString() : "");
            list2.add(null != map.get("tyUseMoney") ? map.get("tyUseMoney").toString() : "");
            list2.add(null != map.get("zcNum") ? map.get("zcNum").toString() : "");
            list2.add(null != map.get("zcUseNum") ? map.get("zcUseNum").toString() : "");
            list2.add(null != map.get("zcUseMoney") ? map.get("zcUseMoney").toString() : "");
            list2.add(null != map.get("czcNum") ? map.get("czcNum").toString() : "");
            list2.add(null != map.get("czcUseNum") ? map.get("czcUseNum").toString() : "");
            list2.add(null != map.get("czcUseMoney") ? map.get("czcUseMoney").toString() : "");
            list2.add(null != map.get("kcNum") ? map.get("kcNum").toString() : "");
            list2.add(null != map.get("kcUseNum") ? map.get("kcUseNum").toString() : "");
            list2.add(null != map.get("kcUseMoney") ? map.get("kcUseMoney").toString() : "");
            lists2.add(list2);
        }
        lists1.add(lists2);
 
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
        HSSFSheet hssfSheet = hssfWorkbook.createSheet();
        hssfSheet.setColumnWidth(0, 6 * 256);
        hssfSheet.setDefaultRowHeightInPoints(20f);
        for(int i = 0; i < lists.size(); i++){
            HSSFRow hssfRow = hssfSheet.createRow(i);//设置第一行数据(标题)
            HSSFCellStyle style = hssfWorkbook.createCellStyle();
            HSSFFont font = hssfWorkbook.createFont();
            font.setBold(true);
            style.setFont(font);
            style.setAlignment(HorizontalAlignment.CENTER);
            for (int l = 0; l < lists.get(i).size(); l++) {
                HSSFCell hssfCell = hssfRow.createCell(l);
                hssfCell.setCellType(CellType.STRING);//设置表格类型
                hssfCell.setCellValue(lists.get(i).get(l));
                hssfCell.setCellStyle(style);
                if(l > 0) {
                    hssfSheet.setColumnWidth(l , 20 * 256);
                }
 
            }
        }
        //这个就是合并单元格
        //参数说明:1:开始行 2:结束行  3:开始列 4:结束列
        //比如我要合并 第二行到第四行的    第六列到第八列     sheet.addMergedRegion(new CellRangeAddress(1,3,5,7));
        hssfSheet.addMergedRegion(new CellRangeAddress(0,0,1,2));
        hssfSheet.addMergedRegion(new CellRangeAddress(0,0,4,5));
        hssfSheet.addMergedRegion(new CellRangeAddress(0,0,7,8));
 
        for(int i = 0; i < lists1.size(); i++){
            //将数据添加到表格中
            List<String> data = null;
            for (int l = 0; l < lists1.get(i).size(); l++) {
                HSSFRow row = hssfSheet.createRow(l + 2);
                data = lists1.get(i).get(l);
                for (int j = 0; j < data.size(); j++) {
                    HSSFCell hssfCell = row.createCell(j);
                    hssfCell.setCellType(CellType.STRING);//设置表格类型
                    hssfCell.setCellValue(data.get(j));
                }
            }
        }
        return hssfWorkbook;
    }
 
    @Override
    public Map<String, Object> queryCouponRegisterInfo1(String name, String time, Integer companyId, Integer offset, Integer limit) throws Exception {
        String start = null;
        String end = null;
        if(ToolUtil.isNotEmpty(time)){
            start = time.split(" - ")[0];
            end = time.split(" - ")[1];
        }
        List<Map<String, Object>> list = this.baseMapper.queryCouponRegisterInfo1(name, start, end, companyId, offset, limit);
        int i = this.baseMapper.queryCouponRegisterInfo1Count(name, start, end, companyId);
        Map<String, Object> map = new HashMap<>();
        map.put("rows", list);
        map.put("total", i);
        return map;
    }
}