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.LoginLog;
|
import com.hollywood.common.security.JwtTokenUtils;
|
import com.hollywood.common.utils.TimeUtils;
|
import com.hollywood.common.utils.WebUtils;
|
import com.hollywood.manage.query.LoginLogQuery;
|
import com.hollywood.manage.service.LoginLogService;
|
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("/login-log")
|
public class LoginLogController {
|
|
private final LoginLogService loginLogService;
|
|
@Autowired
|
public LoginLogController(LoginLogService loginLogService) {
|
this.loginLogService = loginLogService;
|
}
|
|
@ApiOperation(value = "登录日志分页列表查询")
|
@PostMapping("/page-list")
|
public ApiResult<PageInfo<LoginLog>> pageList(@RequestBody LoginLogQuery query) {
|
return ApiResult.success(loginLogService.pageList(query));
|
}
|
|
@OperationLog(operType = "导出", operDesc = "导出登录日志列表", operModul = "登录日志")
|
@ApiOperation(value = "导出登录日志列表")
|
@PostMapping("/export/login-log")
|
public void exportLoginLog(@RequestBody LoginLogQuery query) {
|
PageInfo<LoginLog> pageInfo = loginLogService.pageList(query);
|
List<LoginLog> loginLogList = pageInfo.getRecords();
|
for (LoginLog loginLog : loginLogList) {
|
loginLog.setLoginTimeExport(TimeUtils.localDateTimeToString(loginLog.getLoginTime()));
|
}
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("登录日志信息", "登录日志信息"), LoginLog.class, loginLogList);
|
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();
|
}
|
}
|
}
|
|
}
|