Helius
2021-03-12 62bf99d419e470f5556f21682d0d8ee8b9e20412
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
package com.matrix.system.hive.statistics;
 
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.DateUtil;
import com.matrix.core.tools.LogUtil;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.excl.ExcelSheetPO;
import com.matrix.core.tools.excl.ExcelUtil;
import com.matrix.core.tools.excl.ExcelVersion;
import com.matrix.system.common.tools.DataAuthUtil;
import com.matrix.system.hive.action.util.QueryUtil;
import com.matrix.system.hive.dao.SysOrderFlowDao;
import com.matrix.system.hive.dto.OrderFlowListDto;
import com.matrix.system.hive.vo.OrderFlowVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 交易流水统计
 */
@CrossOrigin(origins = "*")
@Api(value = "OrderFlowAction", tags = "交易流水")
@RestController
@RequestMapping(value = "/admin/orderFlow")
public class OrderFlowAction {
 
    @Resource
    private SysOrderFlowDao orderFlowDao;
    /**
     * 交易流水查询
     */
 
    @ApiOperation(value = "查询交易流水")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK",  response = OrderFlowListDto.class)
    })
    @PostMapping(value = "/findOrderFlow")
    public @ResponseBody
    AjaxResult findOrderFlow(@RequestBody OrderFlowListDto orderFlowListDto) {
        if(StringUtils.isBlank(orderFlowListDto.getSort())){
            orderFlowListDto.setSort("createTime");
            orderFlowListDto.setOrder("desc");
        }
        if (!DataAuthUtil.hasAllShopAuth()) {
            QueryUtil.setQueryLimit(orderFlowListDto);
        } else {
            QueryUtil.setQueryLimitCom(orderFlowListDto);
        }
        List<OrderFlowVo> rows = orderFlowDao.selectInPage(orderFlowListDto);
        Integer total = orderFlowDao.selectTotal(orderFlowListDto);
        AjaxResult result = AjaxResult.buildSuccessInstance(rows, total);
        return result;
    }
 
    /**
     * 导出Excel
     */
    @GetMapping(value = "/exportOrderFlowExcel")
    public void exportOrderFlowExcel(OrderFlowListDto orderFlowListDto, HttpServletResponse res) {
        OutputStream os = null;
        try {
            if (!DataAuthUtil.hasAllShopAuth()) {
                QueryUtil.setQueryLimit(orderFlowListDto);
            } else {
                QueryUtil.setQueryLimitCom(orderFlowListDto);
            }
            orderFlowListDto.setLimit(null);
            List<OrderFlowVo> rows = orderFlowDao.selectInPage(orderFlowListDto);
            res.setCharacterEncoding("UTF-8");
            res.setHeader("content-type", "application/octet-stream;charset=UTF-8");
            res.setContentType("application/octet-stream;charset=UTF-8");
 
            Date date = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss");
            res.setHeader("Content-Disposition", "attachment;filename=" +
                    java.net.URLEncoder.encode("交易流水" + dateFormat.format(date) + ".xlsx".trim(), "UTF-8"));
            os = res.getOutputStream();
            ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, disPoseExcelData(rows), os, true);
        } catch (Exception e) {
            LogUtil.error("交易流水导出异常", e);
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    LogUtil.error("关闭资源异常", e);
                }
            }
        }
    }
 
    private List<ExcelSheetPO> disPoseExcelData(List<OrderFlowVo> orderFlowVos) {
        List<ExcelSheetPO> res = new ArrayList<>();
        ExcelSheetPO orderSheet = new ExcelSheetPO();
        orderSheet.setSheetName("交易流水");
        orderSheet.setTitle("交易流水");
        String[] header = new String[]{"订单编号", "交易内容", "交易时间", "交易类型", "交易金额", "会员姓名",
                "支付方式", "支付流水号", "操作人",  "门店名称"};
        orderSheet.setHeaders(header);
        List<List<Object>> body = new ArrayList<>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        for (OrderFlowVo flowVo : orderFlowVos) {
                List<Object> bodyItem = new ArrayList<>();
                bodyItem.add(flowVo.getOrderNo());
                bodyItem.add(flowVo.getFlowContent());
                bodyItem.add(DateUtil.dateFormatStr(flowVo.getCreateTime(),DateUtil.DATE_FORMAT_MM));
                bodyItem.add(flowVo.getFlowType());
                bodyItem.add(flowVo.getAmount());
                bodyItem.add(flowVo.getVipName());
                bodyItem.add(flowVo.getPayMethod());
                bodyItem.add(flowVo.getFlowNo());
                bodyItem.add(flowVo.getStaffName());
                bodyItem.add(flowVo.getShopName());
                body.add(bodyItem);
        }
        orderSheet.setDataList(body);
        res.add(orderSheet);
        return res;
    }
 
 
 
 
}