|
@@ -1,6 +1,7 @@
|
|
|
package org.springblade.meter.controller;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.aspose.cells.SaveFormat;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -69,6 +70,8 @@ import java.time.LocalDate;
|
|
|
import java.time.Month;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -2594,8 +2597,9 @@ public class TaskController extends BladeController {
|
|
|
public String generateReportsPdf(Report report){
|
|
|
/*报表记录新增或者重算的时候会调用当前方法,生成PDF*/
|
|
|
/*保存两类PDF,一每种表独立一份用于浏览,二合成表用于电签*/
|
|
|
- /*数据完全独立互不影响,可以并发生成,预估PDF的总大小来绝对是否全部在内存中生成PDF*/
|
|
|
+ /*数据完全独立互不影响,可以并发生成,预估PDF的总大小来决定是否全部在内存中生成PDF*/
|
|
|
/*分为新增和更新*/
|
|
|
+ /*如果数据没有变化,则各表的PDF可以不用更新*/
|
|
|
List<ReportResult> reportResults = formulaClient.formulaExecute3(report.getContractId(), report.getId(), report.getType());
|
|
|
String fileUrl = null;
|
|
|
if(Func.isNotEmpty(reportResults)){
|
|
@@ -2667,17 +2671,15 @@ public class TaskController extends BladeController {
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
workbook.write(out);
|
|
|
// workbook.write(new FileOutputStream(rs.getExcelPath()));
|
|
|
- // ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(out.toByteArray());
|
|
|
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()));
|
|
|
reader = new PdfReader(new ByteArrayInputStream(out.toByteArray()));
|
|
|
pageCount = reader.getNumberOfPages();
|
|
|
- for (int i = 0; i < pageCount; ++i) {
|
|
|
- int is = i + 1;
|
|
|
- pdfCopy.addPage(pdfCopy.getImportedPage(reader, is));
|
|
|
+ for (int i = 1; i <= pageCount; ++i) {
|
|
|
+ pdfCopy.addPage(pdfCopy.getImportedPage(reader, i));
|
|
|
}
|
|
|
+ out.close();
|
|
|
workbook.close();
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
@@ -2688,28 +2690,30 @@ public class TaskController extends BladeController {
|
|
|
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){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
/*合并所有表*/
|
|
|
- Long dataId = SnowFlakeUtil.getId();
|
|
|
- String lasPdf = file_path + "/pdf//" + dataId + "_last.pdf";
|
|
|
- CollectionUtils.mergePdfPublicMethods(reportResults.stream().map(ReportResult::getPdfPath).collect(Collectors.toList()), lasPdf);
|
|
|
- BladeFile bladeFile = newIOSSClient.uploadFile(dataId + "_last.pdf", lasPdf);
|
|
|
- fileUrl=bladeFile.getLink();
|
|
|
- String upSql = "update "+Report.REPORT_TYPE[report.getType()]+" set raw_url='" + fileUrl + "' where id="+report.getId();
|
|
|
- jdbcTemplate.execute(upSql);
|
|
|
+ fileUrl=report.getReportPdf(file_path,reportResults);
|
|
|
}
|
|
|
}
|
|
|
return fileUrl;
|
|
|
}
|
|
|
|
|
|
@Data
|
|
|
- static class Report{
|
|
|
- public static final String[] REPORT_TYPE=new String[]{"s_interim_pay_certificate","s_material_start_statement","s_material_start_statement"};
|
|
|
- public static final String[] PERIOD_TYPE=new String[]{"s_contract_meter_period","s_meter_period","s_meter_period"};
|
|
|
+ class Report{
|
|
|
+ public final String[] REPORT_TYPE=new String[]{"s_interim_pay_certificate","s_material_start_statement","s_material_start_statement"};
|
|
|
+ public final String[] PERIOD_TYPE=new String[]{"s_contract_meter_period","s_meter_period","s_meter_period"};
|
|
|
/**报表记录id*/
|
|
|
private Long id;
|
|
|
/**报表PDF地址*/
|
|
@@ -2721,6 +2725,26 @@ public class TaskController extends BladeController {
|
|
|
/**计量类型,0中间计量 1材料,2开工动员*/
|
|
|
private Integer type;
|
|
|
|
|
|
+ /*上传并关联PDF,然后返回合并后的PDF链接*/
|
|
|
+ public String getReportPdf(String file_path,List<ReportResult> reportResults){
|
|
|
+ Long dataId = SnowFlakeUtil.getId();
|
|
|
+ String lasPdf = file_path + "/pdf//" + dataId + "_last.pdf";
|
|
|
+ CollectionUtils.mergePdfPublicMethods(reportResults.stream().map(ReportResult::getPdfPath).collect(Collectors.toList()), lasPdf);
|
|
|
+ BladeFile bladeFile = newIOSSClient.uploadFile(dataId + "_last.pdf", lasPdf);
|
|
|
+ this.pdfUrl=bladeFile.getLink();
|
|
|
+ Map<String,String> fileListMap = reportResults.stream().collect(Collectors.toMap(ReportResult::getName, rs-> {
|
|
|
+ try {
|
|
|
+ return rs.getPdfOssPath().get();
|
|
|
+ } catch (InterruptedException | ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "无效地址";
|
|
|
+ }
|
|
|
+ },(v1,v2)->v1,LinkedHashMap::new));
|
|
|
+ String upSql = "update "+REPORT_TYPE[this.type]+" set raw_url=?,file_url_list=? where id="+this.id;
|
|
|
+ jdbcTemplate.update(upSql,this.pdfUrl ,JSON.toJSONString(fileListMap));
|
|
|
+ return this.pdfUrl;
|
|
|
+ }
|
|
|
+
|
|
|
public Report(Long id, Integer type) {
|
|
|
this.id = id;
|
|
|
this.type = type;
|