新增三重一大、重大经济决策调查表导出功能
This commit is contained in:
120
src/main/java/com/gxwebsoft/ai/config/AuditExcelStyle.java
Normal file
120
src/main/java/com/gxwebsoft/ai/config/AuditExcelStyle.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package com.gxwebsoft.ai.config;
|
||||
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams;
|
||||
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
/**
|
||||
* 自定义Excel导出样式
|
||||
*/
|
||||
public class AuditExcelStyle implements IExcelExportStyler {
|
||||
|
||||
private Workbook workbook;
|
||||
|
||||
public AuditExcelStyle(Workbook workbook) {
|
||||
this.workbook = workbook;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CellStyle getHeaderStyle(short color) {
|
||||
CellStyle style = workbook.createCellStyle();
|
||||
|
||||
// 设置边框
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
style.setBorderTop(BorderStyle.THIN);
|
||||
|
||||
// 设置背景色 - 浅蓝色
|
||||
style.setFillForegroundColor(IndexedColors.SKY_BLUE.getIndex());
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
|
||||
// 设置字体
|
||||
Font font = workbook.createFont();
|
||||
font.setBold(true);
|
||||
font.setFontHeightInPoints((short) 11);
|
||||
font.setColor(IndexedColors.BLACK.getIndex());
|
||||
style.setFont(font);
|
||||
|
||||
// 居中对齐
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CellStyle getTitleStyle(short color) {
|
||||
CellStyle style = workbook.createCellStyle();
|
||||
|
||||
// 设置边框
|
||||
style.setBorderBottom(BorderStyle.MEDIUM);
|
||||
style.setBorderLeft(BorderStyle.MEDIUM);
|
||||
style.setBorderRight(BorderStyle.MEDIUM);
|
||||
style.setBorderTop(BorderStyle.MEDIUM);
|
||||
|
||||
// 设置背景色 - 深蓝色
|
||||
style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
|
||||
// 设置字体
|
||||
Font font = workbook.createFont();
|
||||
font.setBold(true);
|
||||
font.setFontHeightInPoints((short) 14);
|
||||
font.setColor(IndexedColors.BLACK.getIndex());
|
||||
style.setFont(font);
|
||||
|
||||
// 居中对齐
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CellStyle getStyles(boolean noneStyler, ExcelExportEntity entity) {
|
||||
CellStyle style = workbook.createCellStyle();
|
||||
|
||||
// 设置边框
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
style.setBorderTop(BorderStyle.THIN);
|
||||
|
||||
// 设置字体
|
||||
Font font = workbook.createFont();
|
||||
font.setFontHeightInPoints((short) 10);
|
||||
style.setFont(font);
|
||||
|
||||
// 自动换行
|
||||
style.setWrapText(true);
|
||||
|
||||
// 垂直居中
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
|
||||
// 根据列名设置不同的水平对齐方式
|
||||
if (entity != null && entity.getName() != null) {
|
||||
switch (entity.getName()) {
|
||||
case "类别":
|
||||
case "测试结果":
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
break;
|
||||
default:
|
||||
style.setAlignment(HorizontalAlignment.LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data) {
|
||||
return getStyles(false, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) {
|
||||
return getStyles(false, null);
|
||||
}
|
||||
}
|
||||
@@ -3,29 +3,29 @@ package com.gxwebsoft.ai.controller;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.TripleOneExportEntity;
|
||||
import com.gxwebsoft.ai.dto.export.DecisionTableExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent3TripleService;
|
||||
import com.gxwebsoft.ai.service.AuditContent3DecisionService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 审计内容3控制器 - 三重一大制度对比分析 & 重大经济决策调查表
|
||||
@@ -166,4 +166,114 @@ public class AuditContent3Controller extends BaseController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出三重一大制度对比分析表到Excel
|
||||
*/
|
||||
@Operation(summary = "导出三重一大制度对比分析表到Excel")
|
||||
@PostMapping("/exportTripleOneTable")
|
||||
public void exportTripleOneTable(@RequestBody Map<String, Object> request, HttpServletResponse response) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
// 转换为实体列表
|
||||
List<TripleOneExportEntity> exportData = convertToTripleOneEntityList(dataList);
|
||||
|
||||
// 使用工具类导出
|
||||
String fileName = "三重一大制度对比分析表_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - 三重一大制度对比分析表" : "三重一大制度对比分析表";
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, TripleOneExportEntity.class, fileName, "三重一大制度对比分析表", title, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出重大经济决策调查表到Excel
|
||||
*/
|
||||
@Operation(summary = "导出重大经济决策调查表到Excel")
|
||||
@PostMapping("/exportDecisionTable")
|
||||
public void exportDecisionTable(@RequestBody Map<String, Object> request, HttpServletResponse response) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
// 转换为实体列表
|
||||
List<DecisionTableExportEntity> exportData = convertToDecisionTableEntityList(dataList);
|
||||
|
||||
// 使用工具类导出
|
||||
String fileName = "重大经济决策调查表_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - 重大经济决策调查表" : "重大经济决策调查表";
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, DecisionTableExportEntity.class, fileName, "重大经济决策调查表", title, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为三重一大实体列表
|
||||
*/
|
||||
private List<TripleOneExportEntity> convertToTripleOneEntityList(List<Map<String, Object>> originalData) {
|
||||
return originalData.stream().map(this::convertToTripleOneEntity).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为重大经济决策调查表实体列表
|
||||
*/
|
||||
private List<DecisionTableExportEntity> convertToDecisionTableEntityList(List<Map<String, Object>> originalData) {
|
||||
return originalData.stream().map(this::convertToDecisionTableEntity).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个Map转换为三重一大实体
|
||||
*/
|
||||
private TripleOneExportEntity convertToTripleOneEntity(Map<String, Object> item) {
|
||||
TripleOneExportEntity entity = new TripleOneExportEntity();
|
||||
entity.setCategory(getStringValue(item, "category"));
|
||||
entity.setPolicyContent(getStringValue(item, "policyContent"));
|
||||
entity.setGroupSystem(getStringValue(item, "groupSystem"));
|
||||
entity.setCompanyFormulation(getStringValue(item, "companyFormulation"));
|
||||
entity.setCheckEvidence(getStringValue(item, "checkEvidence"));
|
||||
entity.setTestResult(getStringValue(item, "testResult"));
|
||||
entity.setWorkPaperIndex(formatWorkPaperIndex(item.get("workPaperIndex")));
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个Map转换为重大经济决策调查表实体
|
||||
*/
|
||||
private DecisionTableExportEntity convertToDecisionTableEntity(Map<String, Object> item) {
|
||||
DecisionTableExportEntity entity = new DecisionTableExportEntity();
|
||||
entity.setIndex(getStringValue(item, "index"));
|
||||
entity.setDecisionItem(getStringValue(item, "name"));
|
||||
entity.setMeetingTime(getStringValue(item, "meetingTime"));
|
||||
entity.setDecisionAmount(getStringValue(item, "decisionAmount"));
|
||||
entity.setProcedure(getStringValue(item, "procedure"));
|
||||
entity.setExecutionStatus(getStringValue(item, "executionStatus"));
|
||||
entity.setGood(getStringValue(item, "goods"));
|
||||
entity.setNormal(getStringValue(item, "normal"));
|
||||
entity.setBad(getStringValue(item, "bad"));
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全获取字符串值
|
||||
*/
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化工作底稿索引(如果是数组则转换为字符串)
|
||||
*/
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.gxwebsoft.ai.dto.export;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 重大经济决策调查表导出实体
|
||||
*/
|
||||
@Data
|
||||
@ExcelTarget("DecisionTableExportEntity")
|
||||
public class DecisionTableExportEntity {
|
||||
|
||||
@Excel(name = "序号", orderNum = "1", width = 8)
|
||||
private String index;
|
||||
|
||||
@Excel(name = "重大经济决策事项", orderNum = "2", width = 30)
|
||||
private String decisionItem;
|
||||
|
||||
@Excel(name = "会议时间", orderNum = "3", width = 15)
|
||||
private String meetingTime;
|
||||
|
||||
@Excel(name = "决策事项金额", orderNum = "4", width = 15)
|
||||
private String decisionAmount;
|
||||
|
||||
@Excel(name = "程序", orderNum = "5", width = 20)
|
||||
private String procedure;
|
||||
|
||||
@Excel(name = "执行情况(是/否)", orderNum = "6", width = 15)
|
||||
private String executionStatus;
|
||||
|
||||
@Excel(name = "好", orderNum = "7", width = 8)
|
||||
private String good;
|
||||
|
||||
@Excel(name = "一般", orderNum = "8", width = 8)
|
||||
private String normal;
|
||||
|
||||
@Excel(name = "差", orderNum = "9", width = 8)
|
||||
private String bad;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.gxwebsoft.ai.dto.export;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 三重一大制度对比分析表导出实体
|
||||
*/
|
||||
@Data
|
||||
@ExcelTarget("TripleOneExportEntity")
|
||||
public class TripleOneExportEntity {
|
||||
|
||||
@Excel(name = "类别", orderNum = "1", width = 15)
|
||||
private String category;
|
||||
|
||||
@Excel(name = "政策内容", orderNum = "2", width = 40)
|
||||
private String policyContent;
|
||||
|
||||
@Excel(name = "集团制度", orderNum = "3", width = 30)
|
||||
private String groupSystem;
|
||||
|
||||
@Excel(name = "公司制度", orderNum = "4", width = 30)
|
||||
private String companyFormulation;
|
||||
|
||||
@Excel(name = "检查的证据及测试内容", orderNum = "5", width = 25)
|
||||
private String checkEvidence;
|
||||
|
||||
@Excel(name = "测试结果", orderNum = "6", width = 10)
|
||||
private String testResult;
|
||||
|
||||
@Excel(name = "工作底稿索引", orderNum = "7", width = 20)
|
||||
private String workPaperIndex;
|
||||
}
|
||||
139
src/main/java/com/gxwebsoft/ai/utils/ExcelExportTool.java
Normal file
139
src/main/java/com/gxwebsoft/ai/utils/ExcelExportTool.java
Normal file
@@ -0,0 +1,139 @@
|
||||
package com.gxwebsoft.ai.utils;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import com.gxwebsoft.ai.config.AuditExcelStyle;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Excel导出工具类
|
||||
*/
|
||||
@Slf4j
|
||||
public class ExcelExportTool {
|
||||
|
||||
/**
|
||||
* 通用Excel导出方法
|
||||
*
|
||||
* @param dataList 数据列表
|
||||
* @param entityClass 实体类Class
|
||||
* @param fileName 文件名(不含扩展名)
|
||||
* @param sheetName 工作表名
|
||||
* @param title 标题
|
||||
* @param response HttpServletResponse
|
||||
*/
|
||||
public static <T> void exportExcel(List<T> dataList,
|
||||
Class<T> entityClass,
|
||||
String fileName,
|
||||
String sheetName,
|
||||
String title,
|
||||
HttpServletResponse response) {
|
||||
exportExcel(dataList, entityClass, fileName, sheetName, title, response, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用Excel导出方法(完整参数)
|
||||
*
|
||||
* @param dataList 数据列表
|
||||
* @param entityClass 实体类Class
|
||||
* @param fileName 文件名(不含扩展名)
|
||||
* @param sheetName 工作表名
|
||||
* @param title 标题
|
||||
* @param response HttpServletResponse
|
||||
* @param autoHeight 是否自适应行高
|
||||
*/
|
||||
public static <T> void exportExcel(List<T> dataList,
|
||||
Class<T> entityClass,
|
||||
String fileName,
|
||||
String sheetName,
|
||||
String title,
|
||||
HttpServletResponse response,
|
||||
boolean autoHeight) {
|
||||
try {
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
throw new RuntimeException("没有可导出的数据");
|
||||
}
|
||||
|
||||
log.info("开始导出Excel - 文件: {}, 数据条数: {}", fileName, dataList.size());
|
||||
|
||||
// 设置响应头
|
||||
setupResponse(response, fileName);
|
||||
|
||||
// 创建导出参数
|
||||
ExportParams exportParams = createExportParams(sheetName, title);
|
||||
|
||||
// 创建Workbook并导出
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entityClass, dataList);
|
||||
|
||||
// 应用样式
|
||||
if (autoHeight) {
|
||||
applyAutoStyle(workbook);
|
||||
}
|
||||
|
||||
// 写入响应流
|
||||
writeToResponse(workbook, response);
|
||||
|
||||
log.info("成功导出Excel文件: {}, 共{}条数据", fileName, dataList.size());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("导出Excel失败: {}", fileName, e);
|
||||
throw new RuntimeException("导出失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置响应头
|
||||
*/
|
||||
private static void setupResponse(HttpServletResponse response, String fileName) throws Exception {
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
String encodedFileName = URLEncoder.encode(fileName + ".xlsx", StandardCharsets.UTF_8.toString());
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + encodedFileName);
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建导出参数
|
||||
*/
|
||||
private static ExportParams createExportParams(String sheetName, String title) {
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setSheetName(sheetName);
|
||||
exportParams.setTitle(title);
|
||||
exportParams.setType(ExcelType.XSSF); // 使用xlsx格式
|
||||
exportParams.setStyle(AuditExcelStyle.class);
|
||||
return exportParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用自动样式
|
||||
*/
|
||||
private static void applyAutoStyle(Workbook workbook) {
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
// 设置自适应行高
|
||||
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
|
||||
Row row = sheet.getRow(i);
|
||||
if (row != null) {
|
||||
row.setHeight((short) -1); // 设置为自动行高
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入响应流
|
||||
*/
|
||||
private static void writeToResponse(Workbook workbook, HttpServletResponse response) throws Exception {
|
||||
try (OutputStream out = response.getOutputStream()) {
|
||||
workbook.write(out);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user