|
@@ -31,9 +31,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
-import org.apache.poi.ss.usermodel.Row;
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
-import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.springblade.archive.dto.ArchiveWarningDTO;
|
|
|
import org.springblade.archive.dto.FindAndReplaceDto;
|
|
|
import org.springblade.archive.dto.SaveApplyDTO;
|
|
@@ -162,38 +160,56 @@ public class ArchivesAutoController extends BladeController {
|
|
|
@PostMapping ("/downloadArchiveAutoExcel")
|
|
|
@ApiOperationSupport(order = 13)
|
|
|
@ApiOperation(value = "档案下载案卷excel")
|
|
|
- public ResponseEntity<Resource> downloadArchiveAutoExcel(HttpServletResponse response,Long nodeId,Long projectId,Long contractId) throws IOException, InvalidFormatException {
|
|
|
- List<ArchiveTreeContract> archiveTreeContracts = this.archiveTreeContractClient.queryAllChildByAncestors(nodeId+"",contractId);
|
|
|
- List<String> ids=new ArrayList<>();
|
|
|
- if(archiveTreeContracts != null && archiveTreeContracts.size() > 0){
|
|
|
- ids = JSONArray.parseArray(JSONObject.toJSONString(archiveTreeContracts.stream().map(ArchiveTreeContract::getId).distinct().collect(Collectors.toList())), String.class);
|
|
|
+ public ResponseEntity<Resource> downloadArchiveAutoExcel(HttpServletResponse response, Long nodeId, Long projectId, Long contractId) throws IOException, InvalidFormatException {
|
|
|
+ // 获取数据
|
|
|
+ List<ArchiveTreeContract> archiveTreeContracts = this.archiveTreeContractClient.queryAllChildByAncestors(nodeId+"", contractId);
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ if(archiveTreeContracts != null && !archiveTreeContracts.isEmpty()) {
|
|
|
+ ids = JSONArray.parseArray(JSONObject.toJSONString(archiveTreeContracts.stream()
|
|
|
+ .map(ArchiveTreeContract::getId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList())), String.class);
|
|
|
ids.add(nodeId+"");
|
|
|
}
|
|
|
- List<ArchivesAutoVO5> list= archivesAutoService.selectArchivesAutoFileFormDownload(projectId,contractId,ids);
|
|
|
- String templatePath="/mnt/sdc/Users/hongchuangyanfa/Desktop/excel/archiveTemplate.xlsx";
|
|
|
+ List<ArchivesAutoVO5> list = archivesAutoService.selectArchivesAutoFileFormDownload(projectId, contractId, ids);
|
|
|
+
|
|
|
+ // 加载模板
|
|
|
+ String templatePath = "/mnt/sdc/Users/hongchuangyanfa/Desktop/excel/archiveTemplate.xlsx";
|
|
|
//String templatePath="C:\\Users\\hc01\\Desktop\\archiveTemplate.xlsx";
|
|
|
InputStream templateStream = new FileInputStream(new File(templatePath));
|
|
|
org.apache.poi.ss.usermodel.Workbook workbook = WorkbookFactory.create(templateStream);
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
- // 3. 填充数据(假设数据从第2行开始填充)
|
|
|
- int startRow = 1; // 第2行开始填充数据
|
|
|
+
|
|
|
+ // 创建带边框的单元格样式
|
|
|
+ CellStyle borderedCellStyle = workbook.createCellStyle();
|
|
|
+ borderedCellStyle.setBorderTop(BorderStyle.THIN); // 上边框
|
|
|
+ borderedCellStyle.setBorderBottom(BorderStyle.THIN); // 下边框
|
|
|
+ borderedCellStyle.setBorderLeft(BorderStyle.THIN); // 左边框
|
|
|
+ borderedCellStyle.setBorderRight(BorderStyle.THIN); // 右边框
|
|
|
+
|
|
|
+ // 填充数据(从第2行开始)
|
|
|
+ int startRow = 1;
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
Row row = sheet.createRow(startRow + i);
|
|
|
ArchivesAutoVO5 vo1 = list.get(i);
|
|
|
- // 填充各列数据
|
|
|
- row.createCell(0).setCellValue(i + 1); // 序号
|
|
|
- row.createCell(1).setCellValue(StringUtils.isNotEmpty(vo1.getFileNumber())?vo1.getFileNumber():""); // 档号
|
|
|
- row.createCell(2).setCellValue(StringUtils.isNotEmpty(vo1.getName())?vo1.getName():""); // 案卷题名
|
|
|
- row.createCell(3).setCellValue(StringUtils.isNotEmpty(vo1.getStorageTimeValue())?vo1.getStorageTimeValue():""); // 保管期限
|
|
|
- row.createCell(4).setCellValue(vo1.getPageN()+""); // 总页数
|
|
|
- row.createCell(5).setCellValue(StringUtils.isNotEmpty(vo1.getUnit())?vo1.getUnit():""); // 立卷单位
|
|
|
- row.createCell(6).setCellValue(StringUtils.isNotEmpty(vo1.getRemark())?vo1.getRemark():""); // 备注
|
|
|
+
|
|
|
+ // 创建单元格并设置值和样式
|
|
|
+ createCellWithBorder(row, 0, i + 1, borderedCellStyle); // 序号
|
|
|
+ createCellWithBorder(row, 1, StringUtils.isNotEmpty(vo1.getFileNumber()) ? vo1.getFileNumber() : "", borderedCellStyle); // 档号
|
|
|
+ createCellWithBorder(row, 2, StringUtils.isNotEmpty(vo1.getName()) ? vo1.getName() : "", borderedCellStyle); // 案卷题名
|
|
|
+ createCellWithBorder(row, 3, StringUtils.isNotEmpty(vo1.getStorageTimeValue()) ? vo1.getStorageTimeValue() : "", borderedCellStyle); // 保管期限
|
|
|
+ createCellWithBorder(row, 4, vo1.getPageN() + "", borderedCellStyle); // 总页数
|
|
|
+ createCellWithBorder(row, 5, StringUtils.isNotEmpty(vo1.getUnit()) ? vo1.getUnit() : "", borderedCellStyle); // 立卷单位
|
|
|
+ createCellWithBorder(row, 6, StringUtils.isNotEmpty(vo1.getRemark()) ? vo1.getRemark() : "", borderedCellStyle); // 备注
|
|
|
}
|
|
|
+
|
|
|
+ // 输出Excel文件
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
workbook.write(outputStream);
|
|
|
workbook.close();
|
|
|
ByteArrayResource resource = new ByteArrayResource(outputStream.toByteArray());
|
|
|
|
|
|
+ // 设置响应头
|
|
|
String fileName = "案卷目录.xlsx";
|
|
|
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString())
|
|
|
.replaceAll("\\+", "%20");
|
|
@@ -202,7 +218,17 @@ public class ArchivesAutoController extends BladeController {
|
|
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
|
.contentLength(resource.contentLength())
|
|
|
.body(resource);
|
|
|
+ }
|
|
|
|
|
|
+ // 辅助方法:创建带边框的单元格
|
|
|
+ private void createCellWithBorder(Row row, int columnIndex, Object value, CellStyle style) {
|
|
|
+ Cell cell = row.createCell(columnIndex);
|
|
|
+ if (value instanceof Number) {
|
|
|
+ cell.setCellValue(((Number) value).doubleValue());
|
|
|
+ } else {
|
|
|
+ cell.setCellValue(value.toString());
|
|
|
+ }
|
|
|
+ cell.setCellStyle(style);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/fileNumberFlush")
|