|
@@ -30,6 +30,7 @@ import java.io.FileInputStream;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -56,13 +57,10 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
URL_MAP.put("r_Archives_back", "https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230413/31081917b41e12b9b0359f6a9c1755bd.xlsx");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
public static final String LocalPath = "/www/wwwroot/Users/hongchuangyanfa/Desktop/";
|
|
|
|
|
|
|
|
|
-
|
|
|
+ //测试数据
|
|
|
public void test1() {
|
|
|
|
|
|
Long pkeyId = SnowFlakeUtil.getId();
|
|
@@ -90,6 +88,7 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //测试
|
|
|
public void test() {
|
|
|
|
|
|
Long projectId = 1578599210897772545L;
|
|
@@ -169,17 +168,14 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
for (int i = 0; i < 20;i++) {
|
|
|
archiveFiles.add(archiveFile);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
buildArchiveFrontPdfs(projectId,archivesAuto,archiveFiles);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ * 生成四要素
|
|
|
* @param projectId
|
|
|
- * @param archivesAuto
|
|
|
+ * @param archivesAuto, 会更新起始时间和结束时间,所以调用后要更新
|
|
|
* @param archiveFileList
|
|
|
*/
|
|
|
public void buildArchiveFrontPdfs(Long projectId, ArchivesAuto archivesAuto,List<ArchiveFile> archiveFileList) {
|
|
@@ -218,6 +214,12 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param number 四要素的表名
|
|
|
+ * @param variables 参数集
|
|
|
+ * @param urls 返回的url
|
|
|
+ */
|
|
|
public void buildFrontPdf(String number, Map<String,Object> variables,List<String> urls) {
|
|
|
// Step 1: Get the list of formulas using archiveFormulaConfigService
|
|
|
List<ArchiveFormulaConfig> formulaConfigs = archiveFormulaConfigService.getByNumber(number);
|
|
@@ -228,7 +230,6 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
|
|
|
ArchiveFormulaConfig multiLineconfig = null;
|
|
|
|
|
|
-
|
|
|
for (ArchiveFormulaConfig config : formulaConfigs) {
|
|
|
String coords = config.getCoords();
|
|
|
String formula = config.getFormula();
|
|
@@ -261,6 +262,16 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成 卷内目录
|
|
|
+ * @param coords
|
|
|
+ * @param formula
|
|
|
+ * @param variables
|
|
|
+ * @param file_path
|
|
|
+ * @param excelUrl
|
|
|
+ * @param dataInfo
|
|
|
+ * @param urls
|
|
|
+ */
|
|
|
private void handleArchiveFile(String coords, String formula,
|
|
|
Map<String,Object> variables,String file_path,
|
|
|
String excelUrl, Map<String, Object> dataInfo,List<String> urls){
|
|
@@ -318,6 +329,16 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成 封面,备考表,脊背
|
|
|
+ * @param config
|
|
|
+ * @param coords
|
|
|
+ * @param formula
|
|
|
+ * @param variables 参数集
|
|
|
+ * @param file_path 本地路径
|
|
|
+ * @param excelUrl
|
|
|
+ * @param dataInfo 结果集
|
|
|
+ */
|
|
|
private void handleNonArchiveFile(ArchiveFormulaConfig config, String coords, String formula,
|
|
|
Map<String,Object> variables,String file_path,
|
|
|
String excelUrl, Map<String, Object> dataInfo) {
|
|
@@ -344,6 +365,15 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
return filePath.contains("https") || filePath.contains("aliyun");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成单张pdf
|
|
|
+ * @param pkeyId 生成pdf的id
|
|
|
+ * @param DataInfo excel和数据
|
|
|
+ * @param excelUrl excel模板
|
|
|
+ * @param filePath 本地路径
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
public String getBussPdfInfo(Long pkeyId,Map<String, Object> DataInfo,String excelUrl,String filePath) throws Exception{
|
|
|
|
|
|
if (pkeyId == null) {
|
|
@@ -444,6 +474,12 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
return pdfLink;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成四要素的数据源
|
|
|
+ * @param archive
|
|
|
+ * @param datas
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public static Map<String,Object> dataSourceBuilder(ArchivesAuto archive, List<ArchiveFile> datas){
|
|
|
|
|
|
//预处理
|
|
@@ -456,12 +492,16 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
List<Map<String, Object>> fileMapList = new ArrayList<>();
|
|
|
for (ArchiveFile file: datas) {
|
|
|
idx++;
|
|
|
+ //设置序号
|
|
|
file.setId(idx.longValue());
|
|
|
+ //设置文件编号
|
|
|
if (StringUtil.isEmpty(file.getFileNumber())) {
|
|
|
file.setFileNumber("\\");
|
|
|
}
|
|
|
+ //设置页数
|
|
|
file.setPageNum(iStartPage.toString());
|
|
|
|
|
|
+ //最后一页
|
|
|
iStartPage += file.getFilePage();
|
|
|
if (idx >= datas.size() ) {
|
|
|
String lastPageNum = file.getPageNum() + "~" + iStartPage;
|
|
@@ -471,8 +511,31 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
Map<String, Object> fileMap = new ObjectMapper().convertValue(file, Map.class);
|
|
|
fileMapList.add(fileMap);
|
|
|
}
|
|
|
+ //设置总页数
|
|
|
archive.setPageN(iStartPage - 1);
|
|
|
|
|
|
+ // 找出最小和最大日期
|
|
|
+ String minDate = "";
|
|
|
+ String maxDate = "";
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
+
|
|
|
+ for (ArchiveFile file : datas) {
|
|
|
+ String fileTime = file.getFileTime();
|
|
|
+ if (minDate.isEmpty() || fileTime.compareTo(minDate) < 0) {
|
|
|
+ minDate = fileTime;
|
|
|
+ }
|
|
|
+ if (maxDate.isEmpty() || fileTime.compareTo(maxDate) > 0) {
|
|
|
+ maxDate = fileTime;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将日期赋值给startDate和endDate
|
|
|
+ if (!minDate.isEmpty()) {
|
|
|
+ archive.setStartDate(LocalDateTime.parse(minDate, formatter));
|
|
|
+ }
|
|
|
+ if (!maxDate.isEmpty()) {
|
|
|
+ archive.setEndDate(LocalDateTime.parse(maxDate, formatter));
|
|
|
+ }
|
|
|
|
|
|
Map<String, Object> archivesAutoMap = new ObjectMapper().convertValue(archive, Map.class);
|
|
|
if (archive.getRollDate()!= null) {
|
|
@@ -491,19 +554,18 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
archivesAutoMap.put("endDate",FormulaUtil.formatLocalDateTime(archive.getEndDate(),"yyyyMMdd"));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
Map<String,Object> variables = new HashMap<>();
|
|
|
variables.put("Archive",archivesAutoMap);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
variables.put("ArchiveFile",fileMapList);
|
|
|
return variables;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 获取四要素模板的url,这里写死,后续可以从清表的 ”归档“模板树下获取
|
|
|
+ * @param number
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public String getUrlByNumber(String number) {
|
|
|
// Get the URL from the static map using the number as key
|
|
|
String url = URL_MAP.get(number);
|