| | |
| | | package com.xiaopeng.operation.controller; |
| | | |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.xiaopeng.api.model.operation.XpWhitelist; |
| | | import com.xiaopeng.api.model.operation.XpWhitelistOperlog; |
| | | import com.xiaopeng.common.core.utils.WebUtils; |
| | | import com.xiaopeng.common.core.web.domain.AjaxResult; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.operation.exportExcle.XpWhitelistExportExcel; |
| | | import com.xiaopeng.operation.exportExcle.XpWhitelistLogExportExcel; |
| | | import com.xiaopeng.operation.query.WhitelistLogPageListQuery; |
| | | import com.xiaopeng.operation.query.WhitelistPageListQuery; |
| | | import com.xiaopeng.operation.service.IXpWhitelistOperlogService; |
| | | import com.xiaopeng.operation.service.IXpWhitelistService; |
| | | 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.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @author mitao |
| | | * @since 2026-02-03 |
| | | */ |
| | | @Controller |
| | | @RequestMapping("/xp-whitelist-operlog") |
| | | @RequestMapping("/api/v1/whitelistLog") |
| | | @RestController |
| | | @Api(tags = "白名单管理") |
| | | @Slf4j |
| | | public class XpWhitelistOperlogController { |
| | | @Resource |
| | | private IXpWhitelistOperlogService xpWhitelistOperlogService; |
| | | |
| | | @ApiOperation(value = "白名单管理分页列表",response = XpWhitelist.class) |
| | | @PostMapping("/pageList") |
| | | public AjaxResult<PageInfo<XpWhitelistOperlog>> pageList(@RequestBody WhitelistLogPageListQuery query) { |
| | | PageInfo<XpWhitelistOperlog> pageList = xpWhitelistOperlogService.pageList(query); |
| | | return AjaxResult.ok(pageList); |
| | | } |
| | | @ApiOperation(value = "白名单日志导出") |
| | | @PostMapping(value = "/exportExcel") |
| | | public void exportExcel(@RequestBody WhitelistLogPageListQuery query) { |
| | | List<XpWhitelistOperlog> list = xpWhitelistOperlogService.exportList(query); |
| | | List<XpWhitelistLogExportExcel> xpWhitelistLogExportExcels = new ArrayList<>(); |
| | | for (XpWhitelistOperlog xpWhitelistOperlog : list) { |
| | | XpWhitelistLogExportExcel xpWhitelistExportExcel = new XpWhitelistLogExportExcel(); |
| | | xpWhitelistExportExcel.setId(xpWhitelistOperlog.getId()); |
| | | xpWhitelistExportExcel.setOperationAccount(xpWhitelistOperlog.getOperationAccount()); |
| | | xpWhitelistExportExcel.setOperationName(xpWhitelistOperlog.getOperationName()); |
| | | xpWhitelistExportExcel.setOperationContent(xpWhitelistOperlog.getOperationContent()); |
| | | xpWhitelistExportExcel.setOperationIp(xpWhitelistOperlog.getOperationIp()); |
| | | xpWhitelistExportExcel.setOperationType(xpWhitelistOperlog.getOperationType()); |
| | | LocalDateTime createTime = xpWhitelistOperlog.getCreateTime(); |
| | | // 将LocalDateTime转化为yyyy-MM-dd HH:mm:ss格式字符串 |
| | | xpWhitelistExportExcel.setCreateTime(createTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | xpWhitelistLogExportExcels.add(xpWhitelistExportExcel); |
| | | } |
| | | //1.获取excel模板 |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), XpWhitelistLogExportExcel.class, xpWhitelistLogExportExcels); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("白名单日志列表.xls", "utf-8"); |
| | | response.setHeader("Content-dispodition", "attachment;filename=" + fileName); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |