mitao
2024-04-30 ab4ea7b8f10c9b66aed9c2ea161a08b25c3851a7
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
package com.sinata.modular.system.controller;
 
import com.sinata.core.base.controller.BaseController;
import com.sinata.core.util.DateUtils2;
import com.sinata.core.util.ExcelExportUtil;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.sinata.core.common.constant.factory.PageFactory;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import com.sinata.modular.system.model.MyUserSubstanceCoupon;
import com.sinata.modular.system.service.IMyUserSubstanceCouponService;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.util.StringUtils;
 
import javax.servlet.http.HttpServletResponse;
 
/**
 * 实物优惠券信息控制器
 * @author goku
 */
@Controller
@RequestMapping("/myUserSubstanceCoupon")
public class MyUserSubstanceCouponController extends BaseController {
 
    private String PREFIX = "/system/myUserSubstanceCoupon/";
 
    @Autowired
    private IMyUserSubstanceCouponService myUserSubstanceCouponService;
 
    /**
     * 跳转到实物优惠券信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "myUserSubstanceCoupon.html";
    }
 
 
    /**
     * 获取实物优惠券信息列表
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object list(String beginTime, String endTime, String condition) {
        Page<Map<String, Object>> page = new PageFactory().defaultPage();
        Wrapper wrapper = new EntityWrapper<MyUserSubstanceCoupon>().orderBy("id", false);
 
        // 时间搜索
        if(!StringUtils.isEmpty(beginTime)) {
            wrapper.ge("create_time", beginTime + " 00:00:00");
        }
        if(!StringUtils.isEmpty(endTime)) {
            wrapper.le("create_time", endTime + " 23:59:59");
        }
        if(!StringUtils.isEmpty(condition)) {
            wrapper.like("real_name", "%" +condition+ "%");
        }
 
        // 查询数据列表
        List<Map<String, Object>> list = myUserSubstanceCouponService.selectMapsPage(page, wrapper).getRecords();
 
        page.setRecords(list);
        return super.packForBT(page);
    }
 
    @ResponseBody
    @RequestMapping(value = "/export")
    public void export(String beginTime, String endTime, String condition, Integer status, HttpServletResponse response) {
        Page<Map<String, Object>> page = new PageFactory().defaultPage(999999,0);
        Wrapper wrapper = new EntityWrapper<MyUserSubstanceCoupon>().orderBy("id", false);
 
        // 时间搜索
        if(!StringUtils.isEmpty(beginTime)) {
            wrapper.ge("create_time", beginTime + " 00:00:00");
        }
        if(!StringUtils.isEmpty(endTime)) {
            wrapper.le("create_time", endTime + " 23:59:59");
        }
        if(!StringUtils.isEmpty(condition)) {
            wrapper.like("real_name", "%" +condition+ "%");
        }
 
        // 查询数据列表
        List<Map<String, Object>> list = myUserSubstanceCouponService.selectMapsPage(page, wrapper).getRecords();
 
        // 表格数据【封装】
        List<List<Object>> dataList = new ArrayList<>();
 
        // 头部列【封装】
        List<Object> shellList = new ArrayList<>();
        shellList.add("申请时间");
        shellList.add("申请人姓名");
        shellList.add("收件人姓名");
        shellList.add("收件人电话");
        shellList.add("收件人地址");
        dataList.add(shellList);
 
        // 详细数据列【封装】
        for (Map<String, Object> map : list) {
            shellList = new ArrayList<>();
            shellList.add(DateUtils2.getTime((Date) map.get("createTime")));
            shellList.add( map.get("realName")+"");
            shellList.add( map.get("takeName")+"");
            shellList.add( map.get("takePhone")+"");
            shellList.add( map.get("takeAddress")+"");
            dataList.add( shellList);
        }
        try {
            // 调用工具类进行导出
            ExcelExportUtil.easySheet("导出数据"+ DateUtils2.formatDate(new Date(), "YYYYMMddHHmmSS"), "导出数据", dataList, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
}