|
@@ -44,12 +44,10 @@ import org.springblade.core.tool.utils.DateUtil;
|
|
|
import org.springblade.feign.ArchiveFileTaskClient;
|
|
|
import org.springblade.manager.entity.ContractInfo;
|
|
|
import org.springblade.manager.entity.ContractRelationJlyz;
|
|
|
-import org.springblade.manager.entity.WbsTreePrivate;
|
|
|
import org.springblade.manager.feign.FormulaClient;
|
|
|
import org.springblade.manager.vo.ReportResult;
|
|
|
import org.springblade.meter.dto.*;
|
|
|
import org.springblade.meter.entity.*;
|
|
|
-import org.springblade.meter.mapper.MaterialStartStatementMapper;
|
|
|
import org.springblade.meter.mapper.MiddleMeterApplyMapper;
|
|
|
import org.springblade.meter.service.IMaterialStartStatementService;
|
|
|
import org.springblade.meter.service.impl.*;
|
|
@@ -74,6 +72,7 @@ import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -2674,13 +2673,13 @@ public class TaskController extends BladeController {
|
|
|
public R<String> calculate(String reportId, Integer type){
|
|
|
if(BaseUtils.isNumber(reportId)&& BaseUtils.isNumber(type)) {
|
|
|
Report report = generateReport(Long.parseLong(reportId), type);
|
|
|
- return R.data(generateReportsPdf(report));
|
|
|
+ return generateReportsPdf(report);
|
|
|
}
|
|
|
return R.fail("计算失败");
|
|
|
}
|
|
|
|
|
|
/*中期支付证书报表、开工、材料手册报表*/
|
|
|
- public String generateReportsPdf(Report report){
|
|
|
+ public R<String> generateReportsPdf(Report report){
|
|
|
/*报表记录新增或者重算的时候会调用当前方法,生成PDF*/
|
|
|
/*保存两类PDF,一每种表独立一份用于浏览,二合成表用于电签*/
|
|
|
/*数据完全独立互不影响,可以并发生成,预估PDF的总大小来决定是否全部在内存中生成PDF*/
|
|
@@ -2719,83 +2718,89 @@ public class TaskController extends BladeController {
|
|
|
}
|
|
|
});
|
|
|
/*每种表生成一份pdf*/
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
reportResults.parallelStream().forEach(rs->{
|
|
|
try {
|
|
|
byte[] excelByte = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(rs.getExcelUrl()));
|
|
|
- if(Func.isNotEmpty(rs.getData())){
|
|
|
- PdfReader reader = null;
|
|
|
- Document doc = new Document();
|
|
|
- PdfCopy pdfCopy = new PdfCopy(doc, new FileOutputStream(rs.getPdfPath()));
|
|
|
- int pageCount;
|
|
|
- doc.open();
|
|
|
- String tile=rs.getName().contains("封面")?projectName:projectName+StringPool.DASH+rs.getName();
|
|
|
- for(Map<String,Object> dataMap:rs.getData()){
|
|
|
- try {
|
|
|
- Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(excelByte));
|
|
|
- //获取工作表
|
|
|
- Sheet sheet = workbook.getSheetAt(0);
|
|
|
- sheet.setForceFormulaRecalculation(true);
|
|
|
- if(Func.isNotEmpty(dataMap)) {
|
|
|
- for (String keys : dataMap.keySet()) {
|
|
|
- int y1 = Func.toInt(keys.split("_")[0]);
|
|
|
- int x1 = Func.toInt(keys.split("_")[1]);
|
|
|
- Row row = sheet.getRow(y1 - 1);
|
|
|
- if (row != null) {
|
|
|
- Cell cell = row.getCell(x1 - 1);
|
|
|
- if (cell != null) {
|
|
|
- cell.setCellValue(dataMap.getOrDefault(keys, StringPool.EMPTY).toString());
|
|
|
- } else {
|
|
|
- System.out.println(keys + "不存在");
|
|
|
- }
|
|
|
+ PdfReader reader = null;
|
|
|
+ Document doc = new Document();
|
|
|
+ PdfCopy pdfCopy = new PdfCopy(doc, new FileOutputStream(rs.getPdfPath()));
|
|
|
+ int pageCount;
|
|
|
+ doc.open();
|
|
|
+ String tile=rs.getName().contains("封面")?projectName:projectName+StringPool.DASH+rs.getName();
|
|
|
+ /*把公共部分内容释放到每一页*/
|
|
|
+ rs.putCommon();
|
|
|
+ for(Map<String,Object> dataMap:rs.getData()){
|
|
|
+ try {
|
|
|
+ Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(excelByte));
|
|
|
+ //获取工作表
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ sheet.setForceFormulaRecalculation(true);
|
|
|
+ if(Func.isNotEmpty(dataMap)) {
|
|
|
+ for (String keys : dataMap.keySet()) {
|
|
|
+ int y1 = Func.toInt(keys.split("_")[0]);
|
|
|
+ int x1 = Func.toInt(keys.split("_")[1]);
|
|
|
+ Row row = sheet.getRow(y1 - 1);
|
|
|
+ if (row != null) {
|
|
|
+ Cell cell = row.getCell(x1 - 1);
|
|
|
+ if (cell != null) {
|
|
|
+ cell.setCellValue(dataMap.getOrDefault(keys, StringPool.EMPTY).toString());
|
|
|
+ } else {
|
|
|
+ System.out.println(keys + "不存在");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- /*设置表头*/
|
|
|
- setTitle(sheet,tile);
|
|
|
- //去掉表格虚线
|
|
|
- sheet.setPrintGridlines(false);
|
|
|
- //设置 整个工作表为一页
|
|
|
- sheet.setFitToPage(true);
|
|
|
- sheet.getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE);
|
|
|
- ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
- workbook.write(out);
|
|
|
- workbook.write(new FileOutputStream(rs.getExcelPath()));
|
|
|
- com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook( new ByteArrayInputStream(out.toByteArray()));
|
|
|
- out.reset();
|
|
|
- wb.save(out, SaveFormat.PDF);
|
|
|
- reader = new PdfReader(new ByteArrayInputStream(out.toByteArray()));
|
|
|
- pageCount = reader.getNumberOfPages();
|
|
|
- for (int i = 1; i <= pageCount; ++i) {
|
|
|
- pdfCopy.addPage(pdfCopy.getImportedPage(reader, i));
|
|
|
- }
|
|
|
- out.close();
|
|
|
- workbook.close();
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
}
|
|
|
- }
|
|
|
- pdfCopy.flush();
|
|
|
- pdfCopy.close();
|
|
|
- if(reader!=null)reader.close();
|
|
|
- doc.close();
|
|
|
- rs.setPdfOssPath(CompletableFuture.supplyAsync(()->{
|
|
|
- BladeFile bladeFile = newIOSSClient.uploadFile(rs.getName()+SnowFlakeUtil.getId() + ".pdf", rs.getPdfPath());
|
|
|
- String url=bladeFile.getLink();
|
|
|
- if(Func.isEmpty(url)){
|
|
|
- url="无效链接";
|
|
|
+ /*设置表头*/
|
|
|
+ setTitle(sheet,tile);
|
|
|
+ //去掉表格虚线
|
|
|
+ sheet.setPrintGridlines(false);
|
|
|
+ //设置 整个工作表为一页
|
|
|
+ sheet.setFitToPage(true);
|
|
|
+ sheet.getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE);
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
+ workbook.write(out);
|
|
|
+ workbook.write(new FileOutputStream(rs.getExcelPath()));
|
|
|
+ com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook( new ByteArrayInputStream(out.toByteArray()));
|
|
|
+ out.reset();
|
|
|
+ wb.save(out, SaveFormat.PDF);
|
|
|
+ reader = new PdfReader(new ByteArrayInputStream(out.toByteArray()));
|
|
|
+ pageCount = reader.getNumberOfPages();
|
|
|
+ for (int i = 1; i <= pageCount; ++i) {
|
|
|
+ pdfCopy.addPage(pdfCopy.getImportedPage(reader, i));
|
|
|
}
|
|
|
- return url;
|
|
|
- }));
|
|
|
+ out.close();
|
|
|
+ workbook.close();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
+ pdfCopy.flush();
|
|
|
+ pdfCopy.close();
|
|
|
+ if(reader!=null)reader.close();
|
|
|
+ doc.close();
|
|
|
+ rs.setPdfOssPath(CompletableFuture.supplyAsync(()->{
|
|
|
+ BladeFile bladeFile = newIOSSClient.uploadFile(rs.getName()+SnowFlakeUtil.getId() + ".pdf", rs.getPdfPath());
|
|
|
+ String url=bladeFile.getLink();
|
|
|
+ if(Func.isEmpty(url)){
|
|
|
+ url="无效链接";
|
|
|
+ }
|
|
|
+ return url;
|
|
|
+ }));
|
|
|
}catch (Exception e){
|
|
|
+ sb.append("【").append(rs.getName()).append("】");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
+ if(sb.length()>0){
|
|
|
+ sb.append("生成异常");
|
|
|
+ return R.fail(sb.toString());
|
|
|
+ }
|
|
|
/*合并所有表*/
|
|
|
fileUrl=report.getReportPdf(file_path,reportResults);
|
|
|
}
|
|
|
}
|
|
|
- return fileUrl;
|
|
|
+ return R.data(fileUrl);
|
|
|
}
|
|
|
|
|
|
|