luodangjia
2024-12-10 ee7ce5d1cbf80bee0a15c1e5bc5eaa30858d812b
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
package com.hollywood.manage.controller;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.hollywood.common.basic.ApiResult;
import com.hollywood.common.basic.PageInfo;
import com.hollywood.common.log.OperationLog;
import com.hollywood.common.model.OperLog;
import com.hollywood.common.utils.TimeUtils;
import com.hollywood.common.utils.WebUtils;
import com.hollywood.manage.query.OperLogQuery;
import com.hollywood.manage.service.OperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
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.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
 
/**
 * <p>
 * 操作日志 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2022-09-21
 */
@Slf4j
@Api(tags = "操作日志")
@RestController
@RequestMapping("/oper-log")
public class OperLogController {
 
    private final OperLogService operLogService;
 
    @Autowired
    public OperLogController(OperLogService operLogService) {
        this.operLogService = operLogService;
    }
 
    @ApiOperation(value = "操作日志分页列表查询")
    @PostMapping("/page-list")
    public ApiResult<PageInfo<OperLog>> pageList(@RequestBody OperLogQuery query) {
        return ApiResult.success(operLogService.pageList(query));
    }
 
    @OperationLog(operType = "导出", operDesc = "导出操作日志列表", operModul = "操作日志")
    @ApiOperation(value = "导出操作日志列表")
    @PostMapping("/export/oper-log")
    public void exportOperLog(@RequestBody OperLogQuery query) {
        PageInfo<OperLog> pageInfo = operLogService.pageList(query);
        List<OperLog> operLogList = pageInfo.getRecords();
        for (OperLog operLog : operLogList) {
            operLog.setOperOperationTimeExport(TimeUtils.localDateTimeToString(operLog.getOperOperationTime()));
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("操作日志信息", "操作日志信息"), OperLog.class, operLogList);
        HttpServletResponse response = WebUtils.response();
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("操作日志信息.xlsx", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
            log.error("操作日志信息导出失败!");
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
}