|
@@ -1,15 +1,21 @@
|
|
|
package com.yaoyicloud.service.impl;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.time.LocalDate;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import com.yaoyicloud.config.FilerepoProperties;
|
|
|
+import com.yaoyicloud.config.ReportPathManager;
|
|
|
import com.yaoyicloud.constant.enums.ModuleType;
|
|
|
import com.yaoyicloud.constant.enums.ReportType;
|
|
|
+import com.yaoyicloud.entity.ReportGenerationResult;
|
|
|
import com.yaoyicloud.render.InterestConflictsRender;
|
|
|
import com.yaoyicloud.render.ProjectInfoRender;
|
|
|
import com.yaoyicloud.render.PublicRecordRender;
|
|
@@ -32,6 +38,9 @@ import com.yaoyicloud.render.platform.update.TaxNewRender;
|
|
|
|
|
|
import com.yaoyicloud.service.ReportUpdateService;
|
|
|
|
|
|
+import com.yaoyicloud.tools.DocxUtil;
|
|
|
+
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -40,22 +49,33 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import static com.yaoyicloud.config.SessionInterceptor.SESSION_MAP;
|
|
|
|
|
|
-/**
|
|
|
- * 报告服务
|
|
|
- *
|
|
|
- * @author snows
|
|
|
- * @date 2024/10/12
|
|
|
- */
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
public class ReportUpdateServiceImpl implements ReportUpdateService {
|
|
|
|
|
|
private final FilerepoProperties filerepoProperties;
|
|
|
-
|
|
|
+ private final ReportPathManager reportPathManager;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按配置项模块
|
|
|
+ *
|
|
|
+ * @param reportType
|
|
|
+ * @param data
|
|
|
+ * @param templateBytes
|
|
|
+ * @param outputBasePath
|
|
|
+ * @param relationId
|
|
|
+ * @param request
|
|
|
+ * @param moduleType
|
|
|
+ * @param name
|
|
|
+ * @param level
|
|
|
+ * @param tenantName
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
@SuppressWarnings("checkstyle:ReturnCount")
|
|
|
@Override
|
|
|
- public String createPlusVersionCheckReport(
|
|
|
+ public ReportGenerationResult createPlusVersionCheckReport(
|
|
|
ReportType reportType, String data, byte[] templateBytes, String outputBasePath, Long relationId,
|
|
|
HttpServletRequest request, ModuleType moduleType, String name, Integer level, String tenantName)
|
|
|
throws Exception {
|
|
@@ -74,105 +94,118 @@ public class ReportUpdateServiceImpl implements ReportUpdateService {
|
|
|
|
|
|
String sessionId = SESSION_MAP.get(relationId.toString());
|
|
|
|
|
|
+ // 处理指定模块
|
|
|
+ String reportPath = processModule(moduleType, data, processedData, templateBytes, sessionId, relationId);
|
|
|
+ reportPathManager.addReportPath(sessionId, reportPath);
|
|
|
+
|
|
|
+ String mergedReportPath = null;
|
|
|
+ boolean isLastModule = reportPath.contains("attachmentSection");
|
|
|
+
|
|
|
+ if (isLastModule) {
|
|
|
+ List<String> reportPaths = reportPathManager.getReportPaths(sessionId);
|
|
|
+ XWPFDocument targetDoc;
|
|
|
+ try (FileInputStream fis = new FileInputStream(reportPaths.get(0))) {
|
|
|
+ targetDoc = new XWPFDocument(fis);
|
|
|
+ }
|
|
|
+ List<XWPFDocument> sourceDocs = new ArrayList<>();
|
|
|
+ for (int i = 1; i < reportPaths.size(); i++) {
|
|
|
+ try (FileInputStream fis = new FileInputStream(reportPaths.get(i))) {
|
|
|
+ sourceDocs.add(new XWPFDocument(fis));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String label = relationId + "_" + IdUtil.fastSimpleUUID();
|
|
|
+ mergedReportPath = filerepoProperties.getBasePath() + "/" + label + ".docx";
|
|
|
+ // 调用合并方法
|
|
|
+ DocxUtil.mergeDocx(targetDoc, sourceDocs, mergedReportPath, relationId);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new ReportGenerationResult(reportPath, mergedReportPath, isLastModule);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理单个模块的报告生成
|
|
|
+ */
|
|
|
+ @SuppressWarnings("checkstyle:ParameterNumber")
|
|
|
+ private String processModule(ModuleType moduleType, String data, Map<String, Object> processedData,
|
|
|
+ byte[] templateBytes, String sessionId, Long relationId) throws Exception {
|
|
|
String reportPath;
|
|
|
switch (moduleType) {
|
|
|
case ANTIBRIBERY:
|
|
|
- reportPath =
|
|
|
- new AntiBriberyRender(sessionId, filerepoProperties).renderDocx(data, processedData, templateBytes,
|
|
|
- String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new AntiBriberyRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case ANTIBRIBERY_NEW:
|
|
|
- reportPath =
|
|
|
- new AntiBriberyNewRender(sessionId, filerepoProperties).renderDocx(data, processedData, templateBytes,
|
|
|
- String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new AntiBriberyNewRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case PLATFORM_COMPANY_BASICINFO:
|
|
|
- reportPath =
|
|
|
- new BasicInfoRender(sessionId, filerepoProperties).renderDocx(data, processedData, templateBytes,
|
|
|
- String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new BasicInfoRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case PLATFORM_COMPANY_ATTACHMENTSECTION:
|
|
|
- reportPath =
|
|
|
- new AttachmentSectionRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes, String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new AttachmentSectionRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case ASSOCIATION_ATTACHMENTSECTION:
|
|
|
- reportPath =
|
|
|
- new AssociationAttachmentSectionRender(sessionId, filerepoProperties).renderDocx(data,
|
|
|
- processedData,
|
|
|
- templateBytes, String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new AssociationAttachmentSectionRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case FOUNDATION_ATTACHMENTSECTION:
|
|
|
- reportPath =
|
|
|
- new FoundationAttachmentSectionRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes, String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new FoundationAttachmentSectionRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case COMMON:
|
|
|
- reportPath =
|
|
|
- new ServiceProviderInfoRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes, String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new ServiceProviderInfoRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case PLATFORM_COMPANY_FINANCIALINFO:
|
|
|
- reportPath = new FinancialInfoRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes, String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new FinancialInfoRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case PLATFORM_COMPANY_FINANCIALINFO_NEW:
|
|
|
- reportPath = new FinancialInfoNewRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes, String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new FinancialInfoNewRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case FOUNDATION_FINANCIALINFO:
|
|
|
- reportPath =
|
|
|
- new FoundationfinancialInfoRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes, String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new FoundationfinancialInfoRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case PUBLIC_RECORD:
|
|
|
- reportPath = new PublicRecordRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes, String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new PublicRecordRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case PUBLIC_RECORD_NEW:
|
|
|
- reportPath = new PublicRecordNewRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes, String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
-
|
|
|
+ reportPath = new PublicRecordNewRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case PLATFORM_COMPANY_BASICINFO_NEW:
|
|
|
- reportPath =
|
|
|
- new BasicInfoNewRender(sessionId, filerepoProperties).renderDocx(data, processedData, templateBytes,
|
|
|
- String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
-
|
|
|
+ reportPath = new BasicInfoNewRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case FOUNDATION_BASICINFO:
|
|
|
- reportPath =
|
|
|
- new FoundationBasicInfoRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes,
|
|
|
- String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new FoundationBasicInfoRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case ASSOCIATION_BASICINFO:
|
|
|
- reportPath =
|
|
|
- new AssociationBasicInfoRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes,
|
|
|
- String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new AssociationBasicInfoRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case PROJECT:
|
|
|
- reportPath =
|
|
|
- new ProjectInfoRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes,
|
|
|
- String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new ProjectInfoRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case INTERESTCONFLICTS:
|
|
|
- reportPath =
|
|
|
- new InterestConflictsRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes,
|
|
|
- String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
+ reportPath = new InterestConflictsRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
case TAX_NEW:
|
|
|
- reportPath = new TaxNewRender(sessionId, filerepoProperties).renderDocx(data, processedData,
|
|
|
- templateBytes, String.valueOf(relationId));
|
|
|
- return reportPath;
|
|
|
-
|
|
|
+ reportPath = new TaxNewRender(sessionId, filerepoProperties)
|
|
|
+ .renderDocx(data, processedData, templateBytes, String.valueOf(relationId));
|
|
|
+ break;
|
|
|
default:
|
|
|
throw new UnsupportedOperationException("Unsupported module type: " + moduleType);
|
|
|
-
|
|
|
}
|
|
|
+ return reportPath;
|
|
|
}
|
|
|
|
|
|
}
|