检测报告管理
This commit is contained in:
parent
167b872ee6
commit
0032a783b7
|
|
@ -13,6 +13,7 @@ import com.bonus.aqgqj.basis.service.TestReportManageService;
|
||||||
import com.bonus.aqgqj.system.vo.EncryptedReq;
|
import com.bonus.aqgqj.system.vo.EncryptedReq;
|
||||||
import com.bonus.aqgqj.utils.DateTimeHelper;
|
import com.bonus.aqgqj.utils.DateTimeHelper;
|
||||||
import com.bonus.aqgqj.utils.ServerResponse;
|
import com.bonus.aqgqj.utils.ServerResponse;
|
||||||
|
import com.bonus.aqgqj.utils.StringHelper;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
|
|
@ -26,6 +27,10 @@ import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
@ -36,6 +41,8 @@ import java.io.*;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -156,23 +163,23 @@ public class TestReportManageController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @description 一级页面下载
|
// * @description 一级页面下载
|
||||||
*/
|
// */
|
||||||
@PostMapping("download")
|
// @PostMapping("download")
|
||||||
// @DecryptAndVerify(decryptedClass = TestReportManageDto.class)//加解密统一管理
|
//// @DecryptAndVerify(decryptedClass = TestReportManageDto.class)//加解密统一管理
|
||||||
@LogAnnotation(operModul = "检测报告管理", operation = "下载", operDesc = "业务级事件", operType = "新增")
|
// @LogAnnotation(operModul = "检测报告管理", operation = "下载", operDesc = "业务级事件", operType = "新增")
|
||||||
@PreAuthorize("@pms.hasPermission('sys:samples:dispatch')")
|
// @PreAuthorize("@pms.hasPermission('sys:samples:dispatch')")
|
||||||
public ServerResponse download(EncryptedReq<TestReportManageDto> vo) {
|
// public ServerResponse download(EncryptedReq<TestReportManageDto> vo) {
|
||||||
try {
|
// try {
|
||||||
TestReportManageDto voo=new TestReportManageDto();
|
// TestReportManageDto voo=new TestReportManageDto();
|
||||||
voo.setId(25);
|
// voo.setId(25);
|
||||||
return testReportManageService.download(voo);
|
// return testReportManageService.download(voo);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error(e.toString(), e);
|
// log.error(e.toString(), e);
|
||||||
return ServerResponse.createErroe("操作失败");
|
// return ServerResponse.createErroe("操作失败");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@PostMapping(value = "viewTestData")
|
@PostMapping(value = "viewTestData")
|
||||||
@DecryptAndVerify(decryptedClass = TestReportManageDto.class)//加解密统一管理
|
@DecryptAndVerify(decryptedClass = TestReportManageDto.class)//加解密统一管理
|
||||||
|
|
@ -289,60 +296,29 @@ public class TestReportManageController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/export", method = RequestMethod.GET)
|
@GetMapping("/download")
|
||||||
public void exportWorkerAttendance(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
public ResponseEntity<FileSystemResource> downloadFile(HttpServletRequest request) {
|
||||||
String path = "D:\\poi\\";
|
File tempZipFile = null;
|
||||||
//总列数
|
try {
|
||||||
int all = 0;
|
// Return the ZIP file
|
||||||
//动态生成列数
|
return testReportManageService.downloadFile(request, tempZipFile);
|
||||||
int col = 0;
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}finally {
|
||||||
// 1.创建一个工作簿。03
|
// Ensure the temporary file is deleted if not already done
|
||||||
Workbook workbook = new HSSFWorkbook();
|
if (tempZipFile != null && tempZipFile.exists()) {
|
||||||
// 2.创建一个工作表
|
tempZipFile.delete();
|
||||||
Sheet sheet = workbook.createSheet("统计表");
|
}
|
||||||
// 3.创建行。第一行
|
|
||||||
Row row = sheet.createRow(0);
|
|
||||||
// 4.创建列。
|
|
||||||
// (1,1) 第一行第一列的单元格
|
|
||||||
Cell cell = row.createCell(0);
|
|
||||||
cell.setCellValue("安全帽检测报告附页");
|
|
||||||
// 合并单元格:从第一个到第十个单元格
|
|
||||||
sheet.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(
|
|
||||||
0, // 起始行
|
|
||||||
0, // 结束行
|
|
||||||
0, // 起始列
|
|
||||||
all - 1 // 结束列
|
|
||||||
));
|
|
||||||
|
|
||||||
// 第二行。(1,0)
|
|
||||||
Row row1 = sheet.createRow(1);
|
|
||||||
//(2,1)第二行第一列的单元格
|
|
||||||
Cell cell1 = row1.createCell(0);
|
|
||||||
cell1.setCellValue("报告编号");
|
|
||||||
|
|
||||||
Cell cell2 = row1.createCell(1);
|
|
||||||
cell1.setCellValue("报告编号");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 判断文件是否存在,不存在就创建
|
|
||||||
if (FileUtil.isEmpty(new File(path))) {
|
|
||||||
FileUtil.mkdir(path);
|
|
||||||
}
|
}
|
||||||
// 5.生成一张表。03版本的工作簿是以.xls结尾
|
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream(path + "03.xls");
|
|
||||||
// 输出
|
|
||||||
workbook.write(fileOutputStream);
|
|
||||||
// 6.关闭流
|
|
||||||
fileOutputStream.close();
|
|
||||||
System.out.println("03表生成成功!");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private byte[] generateExcelData(String fileName) {
|
||||||
|
// Implement this method to generate Excel file data
|
||||||
|
// For now, returning empty byte array as placeholder
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,12 @@ package com.bonus.aqgqj.basis.service;
|
||||||
import com.bonus.aqgqj.basis.entity.dto.ParamsDto;
|
import com.bonus.aqgqj.basis.entity.dto.ParamsDto;
|
||||||
import com.bonus.aqgqj.basis.entity.dto.TestReportManageDto;
|
import com.bonus.aqgqj.basis.entity.dto.TestReportManageDto;
|
||||||
import com.bonus.aqgqj.utils.ServerResponse;
|
import com.bonus.aqgqj.utils.ServerResponse;
|
||||||
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -77,4 +82,12 @@ public interface TestReportManageService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerResponse download(TestReportManageDto data);
|
ServerResponse download(TestReportManageDto data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测报告下载
|
||||||
|
* @param request
|
||||||
|
* @param tempZipFile
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ResponseEntity<FileSystemResource> downloadFile(HttpServletRequest request, File tempZipFile) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,16 @@ import com.bonus.aqgqj.utils.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
import org.apache.poi.xssf.usermodel.*;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
@ -28,6 +32,9 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 工器具个体管理
|
* @description 工器具个体管理
|
||||||
|
|
@ -231,24 +238,65 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
//根据试验id、设备类型、是否合格、部门id来查询每个检测报告
|
//根据试验id、设备类型、是否合格、部门id来查询每个检测报告
|
||||||
ServerResponse serverResponse = viewTestData(dto);
|
ServerResponse serverResponse = viewTestData(dto);
|
||||||
if (serverResponse.isSuccess()){
|
if (serverResponse.isSuccess()){
|
||||||
|
File zipFile = new File("检测报告_"+DateTimeHelper.getNowDMS()+".zip");
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(zipFile);
|
||||||
|
ZipOutputStream zos = new ZipOutputStream(fos)) {
|
||||||
TestReportManageDto testVo = (TestReportManageDto) serverResponse.getData();
|
TestReportManageDto testVo = (TestReportManageDto) serverResponse.getData();
|
||||||
log.info("sj--->{}",testVo);
|
log.info("sj--->{}",testVo);
|
||||||
//将数据传给检测报告生成的方法
|
//将数据传给检测报告生成的方法
|
||||||
try {
|
try {
|
||||||
generateReport(testVo);
|
generateReport(testVo,zos);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}catch (IOException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<FileSystemResource> downloadFile(HttpServletRequest request, File tempZipFile) throws IOException {
|
||||||
|
String ids = request.getParameter("ids");
|
||||||
|
if (StringHelper.isNotEmpty(ids)) {
|
||||||
|
String fileNames="检测报告_" + DateTimeHelper.getNowDMS();
|
||||||
|
tempZipFile = File.createTempFile(fileNames, ".zip");
|
||||||
|
tempZipFile.deleteOnExit();
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(tempZipFile);
|
||||||
|
ZipOutputStream zos = new ZipOutputStream(fos)) {
|
||||||
|
//拆分用逗号分隔的数据
|
||||||
|
String[] idsArray = ids.split(",");
|
||||||
|
for (String id : idsArray) {
|
||||||
|
TestReportManageDto dto = new TestReportManageDto();
|
||||||
|
dto.setId(Integer.parseInt(id));
|
||||||
|
//查询每条数据里面的详细数据
|
||||||
|
List<TestReportManageDto> list = getDetailsList(dto);
|
||||||
|
//查询详情里所有数据的检测报告
|
||||||
|
for (TestReportManageDto dtos : list) {
|
||||||
|
//根据试验id、设备类型、是否合格、部门id来查询每个检测报告
|
||||||
|
ServerResponse serverResponse = viewTestData(dtos);
|
||||||
|
if (serverResponse.isSuccess()) {
|
||||||
|
TestReportManageDto testVo = (TestReportManageDto) serverResponse.getData();
|
||||||
|
log.info("sj--->{}", testVo);
|
||||||
|
generateReport(testVo, zos);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileNames+".zip");
|
||||||
|
return new ResponseEntity<>(new FileSystemResource(tempZipFile), headers, HttpStatus.OK);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成检测报告
|
* 生成检测报告
|
||||||
*/
|
*/
|
||||||
public void generateReport(TestReportManageDto bean) throws IOException {
|
public void generateReport(TestReportManageDto bean,ZipOutputStream zos) throws IOException {
|
||||||
String path = "D:\\poi\\";
|
String path = "D:\\poi\\";
|
||||||
//先计算出总共有多少列和动态生成的有多少列
|
//先计算出总共有多少列和动态生成的有多少列
|
||||||
//总列数
|
//总列数
|
||||||
|
|
@ -273,6 +321,26 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
|
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
Sheet sheet = workbook.createSheet("检测报告");
|
Sheet sheet = workbook.createSheet("检测报告");
|
||||||
|
|
||||||
|
|
||||||
|
// 创建样式
|
||||||
|
XSSFCellStyle style = workbook.createCellStyle();
|
||||||
|
style.setBorderTop(BorderStyle.THIN);
|
||||||
|
style.setBorderBottom(BorderStyle.THIN);
|
||||||
|
style.setBorderLeft(BorderStyle.THIN);
|
||||||
|
style.setBorderRight(BorderStyle.THIN);
|
||||||
|
style.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
|
||||||
|
// 设置每列的宽度为20个字符的宽度
|
||||||
|
int widthInCharacters = 15;
|
||||||
|
int columnCount = totalNum;
|
||||||
|
|
||||||
|
for (int i = 0; i < columnCount; i++) {
|
||||||
|
// 1/256字符的宽度单位
|
||||||
|
sheet.setColumnWidth(i, widthInCharacters * 256);
|
||||||
|
}
|
||||||
|
|
||||||
//第一行
|
//第一行
|
||||||
Row row1 = sheet.createRow(0);
|
Row row1 = sheet.createRow(0);
|
||||||
//单元格-创建第一个头
|
//单元格-创建第一个头
|
||||||
|
|
@ -280,7 +348,8 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
cell11.setCellValue(bean.getSampleTools()+"检测报告附页");
|
cell11.setCellValue(bean.getSampleTools()+"检测报告附页");
|
||||||
//合并全部列
|
//合并全部列
|
||||||
addMergedRegion(0,0,0,totalNum-1,sheet);
|
addMergedRegion(0,0,0,totalNum-1,sheet);
|
||||||
XSSFCellStyle style= centerStyle(workbook);
|
// 应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(0, 0, 0, totalNum-1), style);
|
||||||
cell11.setCellStyle(style);
|
cell11.setCellStyle(style);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -293,7 +362,10 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
int num21=(totalNum-4)/2;
|
int num21=(totalNum-4)/2;
|
||||||
Cell cell22 = row2.createCell(1);
|
Cell cell22 = row2.createCell(1);
|
||||||
addMergedRegion(1,1,1,num21,sheet);
|
addMergedRegion(1,1,1,num21,sheet);
|
||||||
|
// 应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(1, 1, 1, num21), style);
|
||||||
cell22.setCellValue(bean.getReportCode());
|
cell22.setCellValue(bean.getReportCode());
|
||||||
|
cell22.setCellStyle(style);
|
||||||
|
|
||||||
Cell cell23 = row2.createCell(num21+1);
|
Cell cell23 = row2.createCell(num21+1);
|
||||||
cell23.setCellValue("收样日期");
|
cell23.setCellValue("收样日期");
|
||||||
|
|
@ -301,8 +373,10 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
|
|
||||||
Cell cell24 = row2.createCell(num21+2);
|
Cell cell24 = row2.createCell(num21+2);
|
||||||
cell24.setCellValue(bean.getCollectSamplesTime());
|
cell24.setCellValue(bean.getCollectSamplesTime());
|
||||||
cell24.setCellStyle(style);
|
|
||||||
addMergedRegion(1,1,num21+2,totalNum-3,sheet);
|
addMergedRegion(1,1,num21+2,totalNum-3,sheet);
|
||||||
|
// 应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(1,1,num21+2,totalNum-3), style);
|
||||||
|
cell24.setCellStyle(style);
|
||||||
|
|
||||||
Cell cell25 = row2.createCell(totalNum-2);
|
Cell cell25 = row2.createCell(totalNum-2);
|
||||||
cell25.setCellValue("样品数量");
|
cell25.setCellValue("样品数量");
|
||||||
|
|
@ -323,6 +397,8 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
cell32.setCellValue(bean.getDevTypeName());
|
cell32.setCellValue(bean.getDevTypeName());
|
||||||
cell32.setCellStyle(style);
|
cell32.setCellStyle(style);
|
||||||
addMergedRegion(2,2,1,totalNum-1,sheet);
|
addMergedRegion(2,2,1,totalNum-1,sheet);
|
||||||
|
// 应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(2,2,1,totalNum-1), style);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -337,6 +413,8 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
cell42.setCellValue(yj);
|
cell42.setCellValue(yj);
|
||||||
cell42.setCellStyle(style);
|
cell42.setCellStyle(style);
|
||||||
addMergedRegion(3,3,1,totalNum-1,sheet);
|
addMergedRegion(3,3,1,totalNum-1,sheet);
|
||||||
|
// 应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(3,3,1,totalNum-1), style);
|
||||||
|
|
||||||
//第5行 //第六行
|
//第5行 //第六行
|
||||||
Row row5= sheet.createRow(4);
|
Row row5= sheet.createRow(4);
|
||||||
|
|
@ -346,16 +424,21 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
cell51.setCellValue("序号");
|
cell51.setCellValue("序号");
|
||||||
cell51.setCellStyle(style);
|
cell51.setCellStyle(style);
|
||||||
addMergedRegion(4,5,0,0,sheet);
|
addMergedRegion(4,5,0,0,sheet);
|
||||||
|
// 应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(4,5,0,0), style);
|
||||||
|
|
||||||
Cell cell52 = row5.createCell(1);
|
Cell cell52 = row5.createCell(1);
|
||||||
cell52.setCellValue("样品编号");
|
cell52.setCellValue("样品编号");
|
||||||
cell52.setCellStyle(style);
|
cell52.setCellStyle(style);
|
||||||
addMergedRegion(4,5,1,1,sheet);
|
addMergedRegion(4,5,1,1,sheet);
|
||||||
//
|
//应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(4,5,1,1), style);
|
||||||
Cell cell53 = row5.createCell(2);
|
Cell cell53 = row5.createCell(2);
|
||||||
cell53.setCellValue("样品信息");
|
cell53.setCellValue("样品信息");
|
||||||
cell53.setCellStyle(style);
|
cell53.setCellStyle(style);
|
||||||
addMergedRegion(4,4,2,5,sheet);//
|
addMergedRegion(4,4,2,5,sheet);
|
||||||
|
//应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(4,4,2,5), style);
|
||||||
//第六行固定数据
|
//第六行固定数据
|
||||||
Cell cell62= row6.createCell(2);
|
Cell cell62= row6.createCell(2);
|
||||||
cell62.setCellStyle(style);
|
cell62.setCellStyle(style);
|
||||||
|
|
@ -381,6 +464,8 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
cell54.setCellValue(vo.getExperTypeName());
|
cell54.setCellValue(vo.getExperTypeName());
|
||||||
cell54.setCellStyle(style);
|
cell54.setCellStyle(style);
|
||||||
addMergedRegion(4,4,num.get(),num.get()+rowNum-1,sheet);
|
addMergedRegion(4,4,num.get(),num.get()+rowNum-1,sheet);
|
||||||
|
//应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(4,4,num.get(),num.get()+rowNum-1), style);
|
||||||
num.addAndGet(rowNum-1);
|
num.addAndGet(rowNum-1);
|
||||||
childList.forEach(child->{
|
childList.forEach(child->{
|
||||||
rowNums.set(rowNums.get() + 1);
|
rowNums.set(rowNums.get() + 1);
|
||||||
|
|
@ -392,17 +477,25 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
|
|
||||||
AtomicInteger row = new AtomicInteger(5);
|
AtomicInteger row = new AtomicInteger(5);
|
||||||
AtomicInteger cellNum = new AtomicInteger(0);
|
AtomicInteger cellNum = new AtomicInteger(0);
|
||||||
|
AtomicInteger serialNumber = new AtomicInteger(1); // 用于追踪序号
|
||||||
|
|
||||||
if (ListHelper.isNotEmpty(devList)) {
|
if (ListHelper.isNotEmpty(devList)) {
|
||||||
devList.forEach(dev -> {
|
devList.forEach(dev -> {
|
||||||
row.set(row.get() + 1);
|
row.set(row.get() + 1);
|
||||||
|
cellNum.set(0); // 每次处理新行时重置 cellNum
|
||||||
|
|
||||||
Row row7 = sheet.createRow(row.get());
|
Row row7 = sheet.createRow(row.get());
|
||||||
|
|
||||||
|
// 创建序号列
|
||||||
Cell row71 = row7.createCell(cellNum.get());
|
Cell row71 = row7.createCell(cellNum.get());
|
||||||
cellNum.set(cellNum.get() + 1);
|
row71.setCellValue(serialNumber.get()); // 设置序号
|
||||||
row71.setCellValue(cellNum.get());
|
|
||||||
row71.setCellStyle(style);
|
row71.setCellStyle(style);
|
||||||
|
cellNum.set(cellNum.get() + 1);
|
||||||
|
|
||||||
|
// 更新序号
|
||||||
|
serialNumber.set(serialNumber.get() + 1);
|
||||||
|
|
||||||
|
// 处理其他列
|
||||||
Cell row72 = row7.createCell(cellNum.get());
|
Cell row72 = row7.createCell(cellNum.get());
|
||||||
row72.setCellValue(dev.getCustomerCode());
|
row72.setCellValue(dev.getCustomerCode());
|
||||||
row72.setCellStyle(style);
|
row72.setCellStyle(style);
|
||||||
|
|
@ -423,7 +516,6 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
row75.setCellStyle(style);
|
row75.setCellStyle(style);
|
||||||
cellNum.set(cellNum.get() + 1);
|
cellNum.set(cellNum.get() + 1);
|
||||||
|
|
||||||
|
|
||||||
Cell row76 = row7.createCell(cellNum.get());
|
Cell row76 = row7.createCell(cellNum.get());
|
||||||
row76.setCellValue(dev.getDevModule());
|
row76.setCellValue(dev.getDevModule());
|
||||||
row76.setCellStyle(style);
|
row76.setCellStyle(style);
|
||||||
|
|
@ -438,7 +530,6 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
row77.setCellStyle(style);
|
row77.setCellStyle(style);
|
||||||
cellNum.set(cellNum.get() + 1);
|
cellNum.set(cellNum.get() + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|
@ -452,6 +543,8 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
cell82.setCellValue(bean.getExperStand());
|
cell82.setCellValue(bean.getExperStand());
|
||||||
cell82.setCellStyle(style);
|
cell82.setCellStyle(style);
|
||||||
addMergedRegion(row.get(),row.get(),1,totalNum-1,sheet);
|
addMergedRegion(row.get(),row.get(),1,totalNum-1,sheet);
|
||||||
|
//应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(row.get(),row.get(),1,totalNum-1), style);
|
||||||
|
|
||||||
|
|
||||||
row.set(row.get() + 1);
|
row.set(row.get() + 1);
|
||||||
|
|
@ -465,6 +558,8 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
cell92.setCellValue(bean.getExperConclu());
|
cell92.setCellValue(bean.getExperConclu());
|
||||||
cell92.setCellStyle(style);
|
cell92.setCellStyle(style);
|
||||||
addMergedRegion(row.get(),row.get(),1,totalNum-1,sheet);
|
addMergedRegion(row.get(),row.get(),1,totalNum-1,sheet);
|
||||||
|
//应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(row.get(),row.get(),1,totalNum-1), style);
|
||||||
|
|
||||||
|
|
||||||
row.set(row.get() + 1);
|
row.set(row.get() + 1);
|
||||||
|
|
@ -478,6 +573,8 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
cell102.setCellValue(bean.getRemarks());
|
cell102.setCellValue(bean.getRemarks());
|
||||||
cell102.setCellStyle(style);
|
cell102.setCellStyle(style);
|
||||||
addMergedRegion(row.get(),row.get(),1,totalNum-1,sheet);
|
addMergedRegion(row.get(),row.get(),1,totalNum-1,sheet);
|
||||||
|
//应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(row.get(),row.get(),1,totalNum-1), style);
|
||||||
|
|
||||||
|
|
||||||
row.set(row.get() + 1);
|
row.set(row.get() + 1);
|
||||||
|
|
@ -492,6 +589,8 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
cell112.setCellStyle(style);
|
cell112.setCellStyle(style);
|
||||||
int num112=(totalNum-2)/2;
|
int num112=(totalNum-2)/2;
|
||||||
addMergedRegion(row.get(),row.get(),1,num112,sheet);
|
addMergedRegion(row.get(),row.get(),1,num112,sheet);
|
||||||
|
//应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(row.get(),row.get(),1,num112), style);
|
||||||
|
|
||||||
Cell cell113 = row11.createCell(num112+1);
|
Cell cell113 = row11.createCell(num112+1);
|
||||||
cell113.setCellValue("下次检测日期");
|
cell113.setCellValue("下次检测日期");
|
||||||
|
|
@ -501,25 +600,34 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
cell114.setCellValue(bean.getNextExperTime());
|
cell114.setCellValue(bean.getNextExperTime());
|
||||||
cell114.setCellStyle(style);
|
cell114.setCellStyle(style);
|
||||||
addMergedRegion(row.get(),row.get(),num112+2,totalNum-1,sheet);
|
addMergedRegion(row.get(),row.get(),num112+2,totalNum-1,sheet);
|
||||||
|
//应用边框到合并区域
|
||||||
|
applyBordersToMergedRegion(sheet, new CellRangeAddress(row.get(),row.get(),num112+2,totalNum-1), style);
|
||||||
|
|
||||||
|
|
||||||
// 判断文件是否存在,不存在就创建
|
// 保存到 ZIP 文件
|
||||||
if (FileUtil.isEmpty(new File(path))) {
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
FileUtil.mkdir(path);
|
workbook.write(baos);
|
||||||
|
if (StringHelper.isNotEmpty(bean.getReportCode())){
|
||||||
|
//将字符串中“ML/BG-”去除
|
||||||
|
bean.setReportCode(bean.getReportCode().replace("ML/BG-",""));
|
||||||
}
|
}
|
||||||
double math=Math.random();
|
ZipEntry entry = new ZipEntry("检测报告_" + bean.getReportCode() + "_"+DateTimeHelper.getNowDMS()+".xlsx");
|
||||||
// 5.生成一张表。03版本的工作簿是以.xls结尾
|
zos.putNextEntry(entry);
|
||||||
FileOutputStream fileOutputStream = new FileOutputStream(path + math+".xls");
|
zos.write(baos.toByteArray());
|
||||||
// 输出
|
zos.closeEntry();
|
||||||
workbook.write(fileOutputStream);
|
workbook.close();
|
||||||
// 6.关闭流
|
|
||||||
fileOutputStream.close();
|
|
||||||
System.out.println("03表生成成功!");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单元格样式--居中
|
||||||
|
*/
|
||||||
public static XSSFCellStyle centerStyle(XSSFWorkbook workbook){
|
public static XSSFCellStyle centerStyle(XSSFWorkbook workbook){
|
||||||
XSSFCellStyle commonStyle = workbook.createCellStyle();
|
XSSFCellStyle commonStyle = workbook.createCellStyle();
|
||||||
|
commonStyle.setBorderTop(BorderStyle.THIN);
|
||||||
|
commonStyle.setBorderBottom(BorderStyle.THIN);
|
||||||
|
commonStyle.setBorderLeft(BorderStyle.THIN);
|
||||||
|
commonStyle.setBorderRight(BorderStyle.THIN);
|
||||||
// 左右居中
|
// 左右居中
|
||||||
commonStyle.setAlignment(HorizontalAlignment.CENTER);
|
commonStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
// 上下居中
|
// 上下居中
|
||||||
|
|
@ -530,6 +638,35 @@ public class TestReportManageServiceImpl implements TestReportManageService {
|
||||||
return commonStyle;
|
return commonStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 应用边框到合并区域
|
||||||
|
*
|
||||||
|
* @param sheet
|
||||||
|
* @param range
|
||||||
|
* @param style
|
||||||
|
*/
|
||||||
|
// 应用边框到合并区域
|
||||||
|
private static void applyBordersToMergedRegion(Sheet sheet, CellRangeAddress range, CellStyle style) {
|
||||||
|
int firstRow = range.getFirstRow();
|
||||||
|
int lastRow = range.getLastRow();
|
||||||
|
int firstCol = range.getFirstColumn();
|
||||||
|
int lastCol = range.getLastColumn();
|
||||||
|
|
||||||
|
// 遍历合并区域的所有单元格,并设置边框
|
||||||
|
for (int row = firstRow; row <= lastRow; row++) {
|
||||||
|
Row xssfRow = sheet.getRow(row);
|
||||||
|
if (xssfRow == null) {
|
||||||
|
xssfRow = sheet.createRow(row);
|
||||||
|
}
|
||||||
|
for (int col = firstCol; col <= lastCol; col++) {
|
||||||
|
Cell cell = xssfRow.getCell(col);
|
||||||
|
if (cell == null) {
|
||||||
|
cell = xssfRow.createCell(col);
|
||||||
|
}
|
||||||
|
cell.setCellStyle(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合并单元格
|
* 合并单元格
|
||||||
* @param startRow 开始行
|
* @param startRow 开始行
|
||||||
|
|
|
||||||
|
|
@ -248,18 +248,40 @@ function downloadClick() {
|
||||||
if (ids==='') {
|
if (ids==='') {
|
||||||
return layer.msg('请选择需要下载的数据', {icon: 7})
|
return layer.msg('请选择需要下载的数据', {icon: 7})
|
||||||
}
|
}
|
||||||
let loadingMsg = layer.msg('数据下载中,请稍候...', {icon: 16, scrollbar: false, time: 0});
|
// 显示提示
|
||||||
let url = dataUrl + '/testReport/download';
|
let loadingMsg = layer.msg('数据下载中,请稍候...', {
|
||||||
let params = {
|
icon: 16,
|
||||||
'ids': ids
|
scrollbar: false,
|
||||||
}
|
time: 0, // time: 0 表示提示框不会自动关闭
|
||||||
params = {
|
offset: ['45%', '57%']
|
||||||
encryptedData: encryptCBC(JSON.stringify(params))
|
|
||||||
}
|
|
||||||
ajaxRequest(url, "POST", params, true, function () {
|
|
||||||
layer.close(loadingMsg);
|
|
||||||
window.location.href = dataUrl + '/testReport/download?ids=' + ids;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 获取 token
|
||||||
|
let tokens = localStorage.getItem("token");
|
||||||
|
|
||||||
|
// 发起下载请求
|
||||||
|
fetch(dataUrl + '/testReport/download?ids=' + ids + '&token=' + tokens)
|
||||||
|
.then(response => response.blob())
|
||||||
|
.then(blob => {
|
||||||
|
// 生成下载链接并触发下载
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = '检测报告.zip'; // 文件名
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
|
||||||
|
// 下载完成后关闭提示
|
||||||
|
layer.close(loadingMsg);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
// 处理错误并关闭提示
|
||||||
|
console.error('Error downloading file:', error);
|
||||||
|
layer.close(loadingMsg);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue