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
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 com.sinata.modular.system.model.MyUserSubstanceCoupon;
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.service.IMyUserCouponOrderService;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletResponse;
 
/**
 * 有价优惠券订单控制器
 * @author goku
 */
@Controller
@RequestMapping("/myUserCouponOrder")
public class MyUserCouponOrderController extends BaseController {
 
    @Autowired
    private IMyUserCouponOrderService myUserCouponOrderService;
 
    /**
     * 获取有价优惠券订单列表
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object list(String beginTime, String endTime, String orderNo, String userName, String phone
            , String couponName,Integer state) {
        Page<Map<String, Object>> page = new PageFactory().defaultPage();
        // 查询数据列表
        List<Map<String, Object>> list = myUserCouponOrderService.getUserOrderList(page, beginTime, endTime, orderNo, userName, phone, couponName, state);
        page.setRecords(list);
        return super.packForBT(page);
    }
    @ResponseBody
    @RequestMapping(value = "/export")
    public void export(String beginTime, String endTime, String orderNo, String userName, String phone
            , String couponName,Integer state, HttpServletResponse response) {
        Page<Map<String, Object>> page = new PageFactory().defaultPage(999999,0);
        Wrapper wrapper = new EntityWrapper<MyUserSubstanceCoupon>().orderBy("id", false);
 
        // 查询数据列表
        List<Map<String, Object>> list = myUserCouponOrderService.getUserOrderList(page, beginTime, endTime, orderNo, userName, phone, couponName, state);
 
        // 表格数据【封装】
        List<List<Object>> dataList = new ArrayList<>();
 
        // 头部列【封装】
        List<Object> shellList = new ArrayList<>();
        shellList.add("下单时间");
        shellList.add("订单编号");
        shellList.add("优惠券名称");
        shellList.add("代金券");
        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("create_time")));
            shellList.add( map.get("order_no")+"");
            shellList.add( map.get("couponName")+"");
            shellList.add( map.get("amount")+"");
            shellList.add( map.get("price")+"");
            shellList.add( map.get("nick_name")+"");
            shellList.add( map.get("phone")+"");
            shellList.add( map.get("price")+"");
            String is_use = map.get("is_use")+"";
            String pay_status = map.get("pay_status")+"";
            String payName = "";
            if(is_use.equals("1")){
                payName = "已使用";
            }else if(pay_status.equals("1")){
                payName =  "未支付";
            }else if(pay_status.equals("2")){
                payName =  "待使用";
            }else if(pay_status.equals("3")){
                payName =  "已取消";
            }
            shellList.add(payName);
            dataList.add( shellList);
        }
        try {
            // 调用工具类进行导出
            ExcelExportUtil.easySheet("导出数据"+ DateUtils2.formatDate(new Date(), "YYYYMMddHHmmSS"), "导出数据", dataList, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
}