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
package com.matrix.system.hiveErp.action;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.DateUtil;
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.bean.reqVO.OperationLogReqVo;
import com.matrix.system.common.bean.respVO.OperationLogRespVo;
import com.matrix.system.common.service.OperationLogService;
import com.matrix.system.common.tools.ResponseHeadUtil;
import com.matrix.system.hive.action.util.QueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
 
@RestController
@RequestMapping(value = "admin/operation")
public class OperationLogController {
 
 
    @Autowired
    private OperationLogService operationLogService;
 
    /**
     * 查询单据操作记录
     *
     * @param operationLogReqVo
     * @return
     */
    @PostMapping(value = "/getOperation")
    public
    AjaxResult getOperation(@RequestBody OperationLogReqVo operationLogReqVo) {
        QueryUtil.setQueryLimitCom(operationLogReqVo);
        Page<OperationLogReqVo> page = new Page<>(operationLogReqVo.getPageNum(),operationLogReqVo.getPageSize());
 
        Page<OperationLogRespVo> pageResult = operationLogService.selectPage(page,operationLogReqVo);
 
        return AjaxResult.buildSuccessInstance(pageResult.getRecords(),pageResult.getTotal());
    }
 
    /**
     * 导出操作记录
     */
    @RequestMapping(value = "/exportExcel")
    public void exportExcel(ModelMap model, HttpServletRequest request, HttpServletResponse response,OperationLogReqVo operationLogReqVo) throws Exception {
 
        doExportExcel(response, operationLogReqVo);
    }
 
 
    private void doExportExcel(HttpServletResponse response, OperationLogReqVo operationLogReqVo) throws IOException {
 
 
 
        List<ExcelSheetPO> res = new ArrayList<>();
        ExcelSheetPO orderSheet = new ExcelSheetPO();
        String title = "系统操作记录";
        orderSheet.setSheetName(title);
        orderSheet.setTitle(title);
        String[] header = {"门店","操作用户", "操作时间", "操作功能","操作按钮", "单据号","操作会员","备注","IP地址"};
        orderSheet.setHeaders(header);
 
        QueryUtil.setQueryLimitCom(operationLogReqVo);
        Page<OperationLogReqVo> page = new Page<>(operationLogReqVo.getPageNum(),operationLogReqVo.getPageSize());
 
        Page<OperationLogRespVo> pageResult = operationLogService.selectPage(page,operationLogReqVo);
 
        List<List<Object>> list = new ArrayList<>();
        if (pageResult.getRecords().size() > 0) {
            for (OperationLogRespVo item : pageResult.getRecords()) {
                List<Object> temp = new ArrayList<>();
                temp.add(item.getShopName());
                temp.add(item.getOpeUser());
                temp.add(DateUtil.dateToString(item.getCreateTime(), DateUtil.DATE_FORMAT_MM));
                temp.add(item.getOpeFunctionLabel());
                temp.add(item.getOpeButLabel());
                temp.add(item.getBillNo());
                temp.add(item.getVipName());
                temp.add(item.getNote());
                temp.add(item.getIp());
                list.add(temp);
            }
        }
        orderSheet.setDataList(list);
        res.add(orderSheet);
        response = ResponseHeadUtil.setExcelHead(response);
        response.setHeader("Content-Disposition",
                "attachment;filename=" + URLEncoder.encode(title + DateUtil.getTimeMark() + ".xlsx".trim(), "UTF-8"));
        OutputStream os = response.getOutputStream();
        ExcelUtil.createWorkbookAtOutStream(ExcelVersion.V2007, res, os, true);
    }
 
}