Browse Source

导出文档,操作时间改为string

master
luogw 6 days ago
parent
commit
5907103063
  1. 24
      src/main/java/com/project/appeal/application/Impl/AppealApplicationImpl.java
  2. 6
      src/main/java/com/project/appeal/domain/dto/AppealExportDTO.java
  3. 26
      src/main/java/com/project/operation/application/OperationLogApplicationServiceImpl.java
  4. 6
      src/main/java/com/project/operation/domain/dto/OperationLogExportDTO.java

24
src/main/java/com/project/appeal/application/Impl/AppealApplicationImpl.java

@ -15,8 +15,8 @@ import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class AppealApplicationImpl implements AppealApplication {
@ -31,6 +31,7 @@ public class AppealApplicationImpl implements AppealApplication {
private static final String EXCEL_FILENAME = "appeal";
private static final Integer PAGE_MAX_SIZE = 5001;
private static final Integer PAGE_DEFAULT_CURRENT = 1;
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
/**
* 保存申诉
@ -57,13 +58,26 @@ public class AppealApplicationImpl implements AppealApplication {
//获取申诉列表
param.setSize(PAGE_MAX_SIZE);
param.setCurrent(PAGE_DEFAULT_CURRENT);
List<AppealExportDTO> appealExportDTOList = searchAppealDomainService.list(param).getData().getContent()
.stream().map(dto -> dto.toEntity(AppealExportDTO::new)).collect(Collectors.toList());
if (appealExportDTOList.size() == PAGE_MAX_SIZE) {
List<AppealDTO> appealDTOList = searchAppealDomainService.list(param).getData().getContent();
if (appealDTOList.size() == PAGE_MAX_SIZE) {
throw new BusinessErrorException("最大条数限制5000条超过最大限制不允许导出");
}
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
List<AppealExportDTO> appealExportDTOList = new java.util.ArrayList<>(appealDTOList.size());
for (AppealDTO dto : appealDTOList) {
AppealExportDTO exportDTO = dto.toEntity(AppealExportDTO::new);
// 格式化操作时间为字符串
if (dto.getUpdateTime() != null) {
exportDTO.setUpdateTime(sdf.format(dto.getUpdateTime()));
}
appealExportDTOList.add(exportDTO);
}
ExcelUtil<AppealExportDTO> util = new ExcelUtil<>();
util.exportExcel(response,appealExportDTOList,SHEET_NAME,EXCEL_FILENAME,AppealExportDTO.class);
util.exportExcel(response, appealExportDTOList, SHEET_NAME, EXCEL_FILENAME, AppealExportDTO.class);
}
}

6
src/main/java/com/project/appeal/domain/dto/AppealExportDTO.java

@ -1,11 +1,8 @@
package com.project.appeal.domain.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import lombok.Data;
import java.util.Date;
@Data
public class AppealExportDTO{
private Long id;
@ -16,9 +13,8 @@ public class AppealExportDTO{
@ExcelProperty("用户名")
private String username;
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
@ExcelProperty(value = "操作时间")
private Date updateTime;
private String updateTime;
@ExcelProperty("知识点")
private String kpContentsStr;

26
src/main/java/com/project/operation/application/OperationLogApplicationServiceImpl.java

@ -10,13 +10,13 @@ import com.project.operation.domain.dto.OperationLogExportDTO;
import com.project.operation.domain.param.OperationLogParam;
import com.project.operation.domain.service.SaveOperationLogDomainService;
import com.project.operation.domain.service.SearchOperationLogDomainService;
import jakarta.servlet.http.HttpServletResponse;;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class OperationLogApplicationServiceImpl implements OperationLogApplicationService {
@ -30,6 +30,7 @@ public class OperationLogApplicationServiceImpl implements OperationLogApplicati
private static final String EXCEL_FILENAME = "operationLog";
private static final Integer PAGE_MAX_SIZE = 5001;
private static final Integer PAGE_DEFAULT_CURRENT = 1;
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
/**
* 保存日志
@ -61,14 +62,27 @@ public class OperationLogApplicationServiceImpl implements OperationLogApplicati
//获取日志列表
param.setSize(PAGE_MAX_SIZE);
param.setCurrent(PAGE_DEFAULT_CURRENT);
List<OperationLogExportDTO> operationLogExportDTOList = searchOperationLogDomainService.list(param).getData().getContent()
.stream().map(dto -> dto.toEntity(OperationLogExportDTO::new)).collect(Collectors.toList());
if (operationLogExportDTOList.size() == PAGE_MAX_SIZE) {
List<OperationLogDTO> operationLogDTOList = searchOperationLogDomainService.list(param).getData().getContent();
if (operationLogDTOList.size() == PAGE_MAX_SIZE) {
throw new BusinessErrorException("最大条数限制5000条超过最大限制不允许导出");
}
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
List<OperationLogExportDTO> operationLogExportDTOList = new java.util.ArrayList<>(operationLogDTOList.size());
for (OperationLogDTO dto : operationLogDTOList) {
OperationLogExportDTO exportDTO = dto.toEntity(OperationLogExportDTO::new);
// 格式化操作时间为字符串
if (dto.getCreateTime() != null) {
exportDTO.setCreateTime(sdf.format(dto.getCreateTime()));
}
operationLogExportDTOList.add(exportDTO);
}
ExcelUtil<OperationLogExportDTO> util = new ExcelUtil<>();
util.exportExcel(response,operationLogExportDTOList,SHEET_NAME,EXCEL_FILENAME,OperationLogExportDTO.class);
util.exportExcel(response, operationLogExportDTOList, SHEET_NAME, EXCEL_FILENAME, OperationLogExportDTO.class);
}
}

6
src/main/java/com/project/operation/domain/dto/OperationLogExportDTO.java

@ -1,11 +1,8 @@
package com.project.operation.domain.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import lombok.Data;
import java.util.Date;
@Data
public class OperationLogExportDTO {
@ExcelProperty(value = "姓名")
@ -17,9 +14,8 @@ public class OperationLogExportDTO {
@ExcelProperty(value = "职位")
private String position;
@DateTimeFormat("yyyy-MM-dd HH:mm:ss")
@ExcelProperty(value = "操作时间")
private Date createTime;
private String createTime;
@ExcelProperty(value = "操作")
private String action;

Loading…
Cancel
Save