55555
This commit is contained in:
parent
e47844559d
commit
333da783cb
8
pom.xml
8
pom.xml
@ -38,7 +38,7 @@
|
|||||||
<easypoi.version>4.2.0</easypoi.version>
|
<easypoi.version>4.2.0</easypoi.version>
|
||||||
<xerces.version>2.12.0</xerces.version>
|
<xerces.version>2.12.0</xerces.version>
|
||||||
<poi-scratchpad.version>4.1.1</poi-scratchpad.version>
|
<poi-scratchpad.version>4.1.1</poi-scratchpad.version>
|
||||||
<poi-ooxml-schemas.version>5.2.3</poi-ooxml-schemas.version>
|
<poi-ooxml-schemas.version>1.3</poi-ooxml-schemas.version>
|
||||||
<aws-java-sdk.version>1.11.842</aws-java-sdk.version>
|
<aws-java-sdk.version>1.11.842</aws-java-sdk.version>
|
||||||
<log4j-spring-boot.version>2.17.2</log4j-spring-boot.version>
|
<log4j-spring-boot.version>2.17.2</log4j-spring-boot.version>
|
||||||
<hutool.version>5.7.22</hutool.version>
|
<hutool.version>5.7.22</hutool.version>
|
||||||
@ -281,12 +281,6 @@
|
|||||||
<version>${easyexcel.version}</version>
|
<version>${easyexcel.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.poi</groupId>
|
|
||||||
<artifactId>poi-ooxml</artifactId>
|
|
||||||
<version>5.2.3</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aliyun.oss</groupId>
|
<groupId>com.aliyun.oss</groupId>
|
||||||
<artifactId>aliyun-sdk-oss</artifactId>
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
|||||||
@ -30,10 +30,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 病历表 Controller
|
* 病历表 Controller
|
||||||
@ -97,14 +94,18 @@ public class CaseplatformCaseExcelController {
|
|||||||
|
|
||||||
// 结算导出
|
// 结算导出
|
||||||
@ApiOperation("结算导出")
|
@ApiOperation("结算导出")
|
||||||
@GetMapping("/caseplatformCase/settlementExcel1")
|
@GetMapping("/caseplatformCase/settlementExcel")
|
||||||
public void exportExpertCaseExceli(HttpServletResponse response, @Valid CaseplatformCaseQueryForm queryForm) {
|
public void exportExpertCaseExceli(HttpServletResponse response, @Valid CaseplatformCaseQueryForm queryForm) {
|
||||||
try {
|
try {
|
||||||
List<ExportExpertCaseExcelVo> list = caseplatformCaseService.exportExpertCaseExcel(queryForm);
|
List<ExportExpertCaseExcelVo> list = caseplatformCaseService.exportExpertCaseExcel(queryForm);
|
||||||
List<ExportExpertCaseExcelVo> processedList = caseplatformCaseService.exportExpertCaseExcelProcess(list);
|
List<ExportExpertCaseExcelVo> processedList = caseplatformCaseService.exportExpertCaseExcelProcess(list);
|
||||||
|
|
||||||
// 设置本地文件路径
|
// 总计
|
||||||
String filePath = "./病例数据.xlsx";
|
double totalActual = processedList.stream().mapToDouble(e -> Optional.ofNullable(e.getActualAmount()).orElse(0.0)).sum();
|
||||||
|
double totalTax = processedList.stream().mapToDouble(e -> Optional.ofNullable(e.getTaxAmount()).orElse(0.0)).sum();
|
||||||
|
double totalTotal = processedList.stream().mapToDouble(e -> Optional.ofNullable(e.getTotalAmount()).orElse(0.0)).sum();
|
||||||
|
|
||||||
|
String filePath = "./人工肝诊疗专家劳务费.xlsx";
|
||||||
FileOutputStream outputStream = new FileOutputStream(filePath);
|
FileOutputStream outputStream = new FileOutputStream(filePath);
|
||||||
|
|
||||||
// 字段标题
|
// 字段标题
|
||||||
@ -125,17 +126,23 @@ public class CaseplatformCaseExcelController {
|
|||||||
Collections.singletonList("关联病例")
|
Collections.singletonList("关联病例")
|
||||||
);
|
);
|
||||||
|
|
||||||
// 表头样式
|
|
||||||
WriteCellStyle headStyle = new WriteCellStyle();
|
WriteCellStyle headStyle = new WriteCellStyle();
|
||||||
headStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
headStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||||
headStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
headStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
headStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
|
||||||
|
headStyle.setBorderBottom(BorderStyle.THIN);
|
||||||
|
headStyle.setBorderTop(BorderStyle.THIN);
|
||||||
|
headStyle.setBorderLeft(BorderStyle.THIN);
|
||||||
|
headStyle.setBorderRight(BorderStyle.THIN);
|
||||||
|
|
||||||
// 内容样式
|
|
||||||
WriteCellStyle contentStyle = new WriteCellStyle();
|
WriteCellStyle contentStyle = new WriteCellStyle();
|
||||||
contentStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
contentStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||||
contentStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
contentStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
contentStyle.setBorderBottom(BorderStyle.THIN);
|
||||||
|
contentStyle.setBorderTop(BorderStyle.THIN);
|
||||||
|
contentStyle.setBorderLeft(BorderStyle.THIN);
|
||||||
|
contentStyle.setBorderRight(BorderStyle.THIN);
|
||||||
|
|
||||||
// 1. 创建ExcelWriter
|
|
||||||
ExcelWriter writer = EasyExcel.write(outputStream, ExportExpertCaseExcelVo.class)
|
ExcelWriter writer = EasyExcel.write(outputStream, ExportExpertCaseExcelVo.class)
|
||||||
.head(head)
|
.head(head)
|
||||||
.excelType(ExcelTypeEnum.XLSX)
|
.excelType(ExcelTypeEnum.XLSX)
|
||||||
@ -144,29 +151,97 @@ public class CaseplatformCaseExcelController {
|
|||||||
|
|
||||||
WriteSheet writeSheet = EasyExcel.writerSheet("劳务费明细")
|
WriteSheet writeSheet = EasyExcel.writerSheet("劳务费明细")
|
||||||
.needHead(true)
|
.needHead(true)
|
||||||
.relativeHeadRowIndex(2) // 数据从第三行开始
|
.relativeHeadRowIndex(1) // 数据从第3行开始,前2行为标题
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// 2. 用 POI 操作 sheet,合并第一行并写入大标题
|
// 写数据
|
||||||
|
writer.write(processedList, writeSheet);
|
||||||
|
|
||||||
|
// 合并大标题
|
||||||
Workbook workbook = (Workbook) writer.writeContext().writeWorkbookHolder().getWorkbook();
|
Workbook workbook = (Workbook) writer.writeContext().writeWorkbookHolder().getWorkbook();
|
||||||
Sheet sheet = workbook.getSheetAt(0);
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, head.size() - 1));
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, head.size() - 1));
|
||||||
Row row = sheet.getRow(0);
|
Row titleRow = sheet.createRow(0);
|
||||||
if (row == null) {
|
titleRow.setHeightInPoints(30); // 设置标题行高
|
||||||
row = sheet.createRow(0);
|
Cell titleCell = titleRow.createCell(0);
|
||||||
|
titleCell.setCellValue("人工肝诊疗病例征集项目专家劳务费表");
|
||||||
|
CellStyle titleStyle = workbook.createCellStyle();
|
||||||
|
Font font = workbook.createFont();
|
||||||
|
font.setFontHeightInPoints((short) 16);
|
||||||
|
font.setBold(true);
|
||||||
|
titleStyle.setFont(font);
|
||||||
|
titleStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
titleStyle.setBorderRight(BorderStyle.THIN); // 最后一格加右边框
|
||||||
|
titleCell.setCellStyle(titleStyle);
|
||||||
|
|
||||||
|
// === 设置行高 ===
|
||||||
|
sheet.getRow(1).setHeightInPoints(25); // 表头行
|
||||||
|
for (int i = 2; i <= processedList.size() + 2; i++) {
|
||||||
|
Row row = sheet.getRow(i);
|
||||||
|
if (row != null) {
|
||||||
|
row.setHeightInPoints(22);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Cell cell = row.createCell(0);
|
|
||||||
cell.setCellValue("人工肝诊疗病例征集项目专家劳务费表");
|
|
||||||
|
|
||||||
// 2. 写入数据
|
// === 设置列宽 ===
|
||||||
writer.write(processedList, writeSheet);
|
int[] columnWidths = {
|
||||||
|
6, 25, 15, 15, 25, 10, 10, 30, 8, 8, 30, 25, 30, 15
|
||||||
|
};
|
||||||
|
for (int i = 0; i < columnWidths.length; i++) {
|
||||||
|
sheet.setColumnWidth(i, columnWidths[i] * 256); // 乘 256 为 Excel 单位
|
||||||
|
}
|
||||||
|
|
||||||
|
// 写合计行
|
||||||
|
int totalRowIndex = processedList.size() + 2; // +1是数据从第3行开始,+2是表头行数
|
||||||
|
Row totalRow = sheet.createRow(totalRowIndex);
|
||||||
|
totalRow.setHeightInPoints(22);
|
||||||
|
|
||||||
|
// 合计行样式(黑底白字)
|
||||||
|
CellStyle totalStyle = workbook.createCellStyle();
|
||||||
|
Font totalFont = workbook.createFont();
|
||||||
|
totalFont.setBold(true);
|
||||||
|
totalFont.setColor(IndexedColors.WHITE.getIndex());
|
||||||
|
totalStyle.setFont(totalFont);
|
||||||
|
totalStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||||
|
totalStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
totalStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
totalStyle.setBorderTop(BorderStyle.THIN);
|
||||||
|
totalStyle.setBorderBottom(BorderStyle.THIN);
|
||||||
|
totalStyle.setBorderLeft(BorderStyle.THIN);
|
||||||
|
totalStyle.setBorderRight(BorderStyle.THIN);
|
||||||
|
|
||||||
|
// 合并前3列,写“合计”
|
||||||
|
sheet.addMergedRegion(new CellRangeAddress(totalRowIndex, totalRowIndex, 0, 5));
|
||||||
|
Cell cell0 = totalRow.createCell(0);
|
||||||
|
cell0.setCellValue("合计");
|
||||||
|
|
||||||
|
// 设置边框样式
|
||||||
|
CellStyle borderStyle = workbook.createCellStyle();
|
||||||
|
borderStyle.setBorderBottom(BorderStyle.THIN);
|
||||||
|
borderStyle.setBorderTop(BorderStyle.THIN);
|
||||||
|
borderStyle.setBorderLeft(BorderStyle.THIN);
|
||||||
|
borderStyle.setBorderRight(BorderStyle.THIN);
|
||||||
|
borderStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
|
||||||
|
// 创建合计单元格并添加边框
|
||||||
|
for (int i = 0; i < head.size(); i++) {
|
||||||
|
Cell cell = totalRow.getCell(i);
|
||||||
|
if (cell == null) {
|
||||||
|
cell = totalRow.createCell(i);
|
||||||
|
}
|
||||||
|
cell.setCellStyle(borderStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 实发(列 G = index 6)、个税(I = 8)、应发(J = 9)
|
||||||
|
totalRow.getCell(6).setCellValue(totalActual);
|
||||||
|
totalRow.getCell(8).setCellValue(totalTax);
|
||||||
|
totalRow.getCell(9).setCellValue(totalTotal);
|
||||||
|
|
||||||
writer.finish();
|
writer.finish();
|
||||||
|
outputStream.close();
|
||||||
|
|
||||||
// 6通知浏览器以附件的形式下载处理,设置返回头要注意文件名有中文
|
System.out.println("Excel 导出完成,路径: " + filePath);
|
||||||
String fileName = URLEncoder.encode("病例数据", "UTF-8").replaceAll("\\+", "%20");
|
|
||||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
||||||
response.setContentType("multipart/form-data");
|
|
||||||
response.setCharacterEncoding("utf-8");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -174,7 +249,7 @@ public class CaseplatformCaseExcelController {
|
|||||||
|
|
||||||
// 结算导出
|
// 结算导出
|
||||||
@ApiOperation("结算导出")
|
@ApiOperation("结算导出")
|
||||||
@GetMapping("/caseplatformCase/settlementExcel")
|
@GetMapping("/caseplatformCase/settlementExcel1")
|
||||||
public void exportExpertCaseExcel(HttpServletResponse response, @Valid CaseplatformCaseQueryForm queryForm) {
|
public void exportExpertCaseExcel(HttpServletResponse response, @Valid CaseplatformCaseQueryForm queryForm) {
|
||||||
try {
|
try {
|
||||||
List<ExportExpertCaseExcelVo> list = caseplatformCaseService.exportExpertCaseExcel(queryForm);
|
List<ExportExpertCaseExcelVo> list = caseplatformCaseService.exportExpertCaseExcel(queryForm);
|
||||||
@ -215,11 +290,12 @@ public class CaseplatformCaseExcelController {
|
|||||||
bodyStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
bodyStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
|
||||||
// 3设置表格sheet样式
|
// 3设置表格sheet样式
|
||||||
WriteSheet sheet = EasyExcel.writerSheet().head(head).sheetNo(1).build();
|
WriteSheet sheet = EasyExcel.writerSheet().sheetNo(1).build();
|
||||||
// 4拿到表格处理对象
|
// 4拿到表格处理对象
|
||||||
ExcelWriter writer = EasyExcel.write(response.getOutputStream()).needHead(true).excelType(ExcelTypeEnum.XLSX)
|
// ExcelWriter writer = EasyExcel.write(response.getOutputStream()).needHead(true).excelType(ExcelTypeEnum.XLSX)
|
||||||
// ExcelWriter writer = EasyExcel.write(outputStream).needHead(true).excelType(ExcelTypeEnum.XLSX)
|
ExcelWriter writer = EasyExcel.write(outputStream).needHead(true).excelType(ExcelTypeEnum.XLSX)
|
||||||
// 设置单元格的风格样式
|
// 设置单元格的风格样式
|
||||||
|
.head(head)
|
||||||
.registerWriteHandler(new HorizontalCellStyleStrategy(headStyle, bodyStyle))
|
.registerWriteHandler(new HorizontalCellStyleStrategy(headStyle, bodyStyle))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user