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();
|
}
|
}
|
}
|
|
}
|