|
@@ -5,48 +5,41 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.aspose.words.Document;
|
|
|
import com.aspose.words.DocumentBuilder;
|
|
|
import com.aspose.words.ImportFormatMode;
|
|
|
-import com.aspose.words.Paragraph;
|
|
|
import com.dayou.bo.EqptReportFillBO;
|
|
|
import com.dayou.config.FileNetConfig;
|
|
|
import com.dayou.dto.report.ReportBaseInfoDTO;
|
|
|
import com.dayou.dto.report.equipment.EqptReportBaseInfoDTO;
|
|
|
import com.dayou.entity.AssetsReport;
|
|
|
+import com.dayou.entity.DocumentProduction;
|
|
|
import com.dayou.entity.TmplAssetReport;
|
|
|
import com.dayou.entity.TmplAssetReportSection;
|
|
|
-import com.dayou.enums.EqptReportTmplCode;
|
|
|
import com.dayou.mapper.AssetsReportMapper;
|
|
|
import com.dayou.mapper.TmplAssetReportMapper;
|
|
|
import com.dayou.mapper.TmplAssetReportSectionMapper;
|
|
|
import com.dayou.service.AssetsReportService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.dayou.service.DocumentProductionService;
|
|
|
import com.dayou.utils.ArabicToChineseUtil;
|
|
|
import com.dayou.utils.AsposeWordUtil;
|
|
|
import com.dayou.utils.DataUtil;
|
|
|
import com.dayou.utils.DateToChinese;
|
|
|
import com.dayou.vo.AssetsReportVO;
|
|
|
import com.dayou.vo.report.AssetsReportProgressVO;
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.util.List;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import static com.dayou.enums.DocumentType.EQPT_CALCULATE;
|
|
|
+import static com.dayou.enums.DocumentType.EQPT_REPORT;
|
|
|
import static com.dayou.enums.EqptReportTmplCode.*;
|
|
|
|
|
|
/**
|
|
@@ -70,6 +63,9 @@ public class AssetsReportServiceImpl extends ServiceImpl<AssetsReportMapper, Ass
|
|
|
private TmplAssetReportSectionMapper reportSectionMapper;
|
|
|
|
|
|
@Autowired
|
|
|
+ private DocumentProductionService documentProductionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private FileNetConfig fileNetConfig;
|
|
|
|
|
|
/**
|
|
@@ -151,9 +147,10 @@ public class AssetsReportServiceImpl extends ServiceImpl<AssetsReportMapper, Ass
|
|
|
* @return Boolean
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean generateEquipmentReport(Long reportId) throws Exception {
|
|
|
|
|
|
- // 获取基础报告信息
|
|
|
+ // 获取与设置基础报告信息
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
EqptReportFillBO eqptReportFillBO = assetsReportMapper.geteqptReportFillBO(reportId);
|
|
|
// 设置增值率(评估净值 - 账面净值) / 账面净值,保留两位小数
|
|
@@ -174,75 +171,58 @@ public class AssetsReportServiceImpl extends ServiceImpl<AssetsReportMapper, Ass
|
|
|
// 将评估报告日转换为中文并设置到中文评估报告日中
|
|
|
eqptReportFillBO.setChineseReportDate(DateToChinese.dateStrConvertChinese(eqptReportFillBO.getEqptReportBaseInfo().getReportDate()));
|
|
|
|
|
|
+
|
|
|
// 第一步:设置封面
|
|
|
// 获取封面模板
|
|
|
TmplAssetReportSection coverTmpl = reportSectionMapper.getTmplByCode(COVER.getCode());
|
|
|
- // 封面生成后文件位置
|
|
|
- String coverPath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputReportPath() + System.currentTimeMillis() + "_COVER.docx";
|
|
|
// 封面模板文件位置
|
|
|
String coverTmplPath = fileNetConfig.getBaseDir() + coverTmpl.getSectionFileUrl() + coverTmpl.getSectionFileName();
|
|
|
-
|
|
|
// 读取模板文件
|
|
|
byte[] coverTmplByte = Files.readAllBytes(Paths.get(coverTmplPath));
|
|
|
// 获取填充数据后的文件
|
|
|
byte[] resultCoverByte = AsposeWordUtil.fillWordDataByMap(coverTmplByte, DataUtil.objToMap(eqptReportFillBO));
|
|
|
+ // 将封面的字节流转成输入流以供后续使用
|
|
|
+ InputStream coverIs = new ByteArrayInputStream(resultCoverByte);
|
|
|
|
|
|
- // 处理该二进制文件并保存
|
|
|
- File resultFile = new File(coverPath);
|
|
|
- FileOutputStream fos = new FileOutputStream(resultFile);
|
|
|
- fos.write(resultCoverByte);
|
|
|
- fos.close();
|
|
|
|
|
|
// 第二步:设置摘要内容
|
|
|
// 获取正文
|
|
|
TmplAssetReportSection digestTmpl = reportSectionMapper.getTmplByCode(DIGEST.getCode());
|
|
|
- // 封面生成后文件位置
|
|
|
- String digestPath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputReportPath() + System.currentTimeMillis() + "_DIGEST.docx";
|
|
|
// 封面模板文件位置
|
|
|
String digestTmplPath = fileNetConfig.getBaseDir() + digestTmpl.getSectionFileUrl() + digestTmpl.getSectionFileName();
|
|
|
-
|
|
|
// 读取模板文件
|
|
|
byte[] digestTmplByte = Files.readAllBytes(Paths.get(digestTmplPath));
|
|
|
// 获取填充数据后的文件
|
|
|
byte[] resultdigestByte = AsposeWordUtil.fillWordDataByMap(digestTmplByte, DataUtil.objToMap(eqptReportFillBO));
|
|
|
-
|
|
|
- // 处理该二进制文件并保存
|
|
|
- File digestFile = new File(digestPath);
|
|
|
- FileOutputStream digestOs = new FileOutputStream(digestFile);
|
|
|
- digestOs.write(resultdigestByte);
|
|
|
- digestOs.close();
|
|
|
- Document digestDoc = new Document(digestPath);
|
|
|
+ // 将摘要的字节流转成输入流以供后续使用
|
|
|
+ InputStream digestIs = new ByteArrayInputStream(resultdigestByte);
|
|
|
|
|
|
// 第三步:设置正文内容
|
|
|
// 获取正文
|
|
|
TmplAssetReportSection detailTmpl = reportSectionMapper.getTmplByCode(DETAIL.getCode());
|
|
|
- // 封面生成后文件位置
|
|
|
- String detailPath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputReportPath() + System.currentTimeMillis() + "_DETAIL.docx";
|
|
|
// 封面模板文件位置
|
|
|
String detailTmplPath = fileNetConfig.getBaseDir() + detailTmpl.getSectionFileUrl() + detailTmpl.getSectionFileName();
|
|
|
-
|
|
|
// 读取模板文件
|
|
|
byte[] detailTmplByte = Files.readAllBytes(Paths.get(detailTmplPath));
|
|
|
// 获取填充数据后的文件
|
|
|
byte[] resultDetailByte = AsposeWordUtil.fillWordDataByMap(detailTmplByte, DataUtil.objToMap(eqptReportFillBO));
|
|
|
-
|
|
|
- // 处理该二进制文件并保存
|
|
|
- File detailFile = new File(detailPath);
|
|
|
- FileOutputStream detailOs = new FileOutputStream(detailFile);
|
|
|
- detailOs.write(resultDetailByte);
|
|
|
- detailOs.close();
|
|
|
-
|
|
|
+ // 将正文的字节流转成输入流以供后续使用
|
|
|
+ InputStream detailIs = new ByteArrayInputStream(resultDetailByte);
|
|
|
// 将正文读取出来
|
|
|
- Document detailDoc = new Document(detailPath);
|
|
|
+ Document detailDoc = new Document(detailIs);
|
|
|
+ // 判断是否需要 质保期 注意事项段落,不需要就通过提前设置的书签移除掉
|
|
|
+ DocumentBuilder detailBuilder = new DocumentBuilder(detailDoc);
|
|
|
+ if (!eqptReportFillBO.getEqptReportBaseInfo().getAssetsInfo().getUnderWarranty()) {
|
|
|
+ detailBuilder.moveToBookmark("underWarranty");
|
|
|
+ detailBuilder.getCurrentParagraph().remove();
|
|
|
+ }
|
|
|
|
|
|
- // 第四步:设置委托人概况
|
|
|
+ // 第四步:设置委托人概况到正文
|
|
|
// 获取委托人概况模板
|
|
|
TmplAssetReportSection consignorTmpl = reportSectionMapper.getTmplByCode(CONSIGNOR.getCode());
|
|
|
- // 委托人概况生成后文件位置
|
|
|
- String consignorPath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputReportPath() + System.currentTimeMillis() + "_CONSIGNOR.docx";
|
|
|
// 委托人概况模板文件位置
|
|
|
String consignorTmplPath = fileNetConfig.getBaseDir() + consignorTmpl.getSectionFileUrl() + consignorTmpl.getSectionFileName();
|
|
|
-
|
|
|
+ // 插入时会导致先插入的排在后插入的后面,所以把顺序反转一下
|
|
|
for (int i = eqptReportFillBO.getEqptReportBaseInfo().getConsignorInfos().size(); i > 0; i--) {
|
|
|
EqptReportBaseInfoDTO.ConsignorInfo consignorInfo = eqptReportFillBO.getEqptReportBaseInfo().getConsignorInfos().get(i -1);
|
|
|
consignorInfo.setSort(i);
|
|
@@ -251,61 +231,34 @@ public class AssetsReportServiceImpl extends ServiceImpl<AssetsReportMapper, Ass
|
|
|
byte[] consignorTmplByte = Files.readAllBytes(Paths.get(consignorTmplPath));
|
|
|
// 获取填充数据后的文件
|
|
|
byte[] resultConsignorByte = AsposeWordUtil.fillWordDataByDomain(consignorTmplByte, consignorInfo);
|
|
|
- // 处理该二进制文件并保存
|
|
|
- File consignorFile = new File(consignorPath);
|
|
|
- FileOutputStream consignorOs = new FileOutputStream(consignorFile);
|
|
|
- consignorOs.write(resultConsignorByte);
|
|
|
- consignorOs.close();
|
|
|
-
|
|
|
- Document consignorDoc = new Document(consignorPath);
|
|
|
- detailDoc = AsposeWordUtil.insertDocumentAfterBookMark(detailDoc, consignorDoc, "insertConsignor", false, false);
|
|
|
+ InputStream consignorIs = new ByteArrayInputStream(resultConsignorByte);
|
|
|
+ detailDoc = AsposeWordUtil.insertDocumentAfterBookMark(detailDoc, new Document(consignorIs), "insertConsignor", false, false);
|
|
|
+ consignorIs.close();
|
|
|
}
|
|
|
|
|
|
- // 第五步:设置产权持有人概况
|
|
|
+ // 第五步:设置产权持有人概况到正文
|
|
|
// 获取产权持有人概况模板
|
|
|
TmplAssetReportSection ownerTmpl = reportSectionMapper.getTmplByCode(PROPERTY_OWNER.getCode());
|
|
|
- // 产权持有人概况生成后文件位置
|
|
|
- String ownerPath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputReportPath() + System.currentTimeMillis() + "_PROPERTY_OWNER.docx";
|
|
|
// 产权持有人概况模板文件位置
|
|
|
String ownerTmplPath = fileNetConfig.getBaseDir() + ownerTmpl.getSectionFileUrl() + ownerTmpl.getSectionFileName();
|
|
|
-
|
|
|
for (int i = eqptReportFillBO.getEqptReportBaseInfo().getPropertyOwnerInfos().size(); i > 0; i--) {
|
|
|
EqptReportBaseInfoDTO.PropertyOwnerInfo propertyOwnerInfo = eqptReportFillBO.getEqptReportBaseInfo().getPropertyOwnerInfos().get(i - 1);
|
|
|
propertyOwnerInfo.setSort(i);
|
|
|
propertyOwnerInfo.setSortUppercase(ArabicToChineseUtil.int2chineseNum(i));
|
|
|
// 读取模板文件
|
|
|
- byte[] consignorTmplByte = Files.readAllBytes(Paths.get(ownerTmplPath));
|
|
|
+ byte[] propertyOwnerTmplByte = Files.readAllBytes(Paths.get(ownerTmplPath));
|
|
|
// 获取填充数据后的文件
|
|
|
- byte[] resultConsignorByte = AsposeWordUtil.fillWordDataByDomain(consignorTmplByte, propertyOwnerInfo);
|
|
|
- // 处理该二进制文件并保存
|
|
|
- File ownerFile = new File(ownerPath);
|
|
|
- FileOutputStream consignorOs = new FileOutputStream(ownerFile);
|
|
|
- consignorOs.write(resultConsignorByte);
|
|
|
- consignorOs.close();
|
|
|
-
|
|
|
- Document ownerDoc = new Document(ownerPath);
|
|
|
- detailDoc = AsposeWordUtil.insertDocumentAfterBookMark(detailDoc, ownerDoc, "insertPropertyOwner", false, false);
|
|
|
+ byte[] propertyOwnerByte = AsposeWordUtil.fillWordDataByDomain(propertyOwnerTmplByte, propertyOwnerInfo);
|
|
|
+ InputStream propertyOwnerIs = new ByteArrayInputStream(propertyOwnerByte);
|
|
|
+ detailDoc = AsposeWordUtil.insertDocumentAfterBookMark(detailDoc, new Document(propertyOwnerIs), "insertPropertyOwner", false, false);
|
|
|
+ propertyOwnerIs.close();
|
|
|
}
|
|
|
|
|
|
- // 删除两个书签所在的空白行
|
|
|
- DocumentBuilder builder = new DocumentBuilder(detailDoc);
|
|
|
- builder.moveToBookmark("insertConsignor");
|
|
|
- // 获取当前光标所在的段落
|
|
|
- Paragraph currentParagraph1 = builder.getCurrentParagraph();
|
|
|
- currentParagraph1.remove();
|
|
|
- builder.moveToBookmark("insertPropertyOwner");
|
|
|
- // 获取当前光标所在的段落
|
|
|
- Paragraph currentParagraph2 = builder.getCurrentParagraph();
|
|
|
- currentParagraph2.remove();
|
|
|
-
|
|
|
- // 保存正文文件
|
|
|
- detailDoc.save(detailPath);
|
|
|
-
|
|
|
// 第六步:设置主体框架
|
|
|
// 获取框架模板
|
|
|
TmplAssetReport mainTmpl = tmplAssetReportMapper.getTmplByCode(MAIN.getCode());
|
|
|
// 框架生成后文件位置
|
|
|
- String mainPath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputReportPath() + System.currentTimeMillis() + "_MAIN.docx";
|
|
|
+ String mainPath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputReportPath() + System.currentTimeMillis() + "_设备融资报告.docx";
|
|
|
// 框架模板文件位置
|
|
|
String mainTmplPath = fileNetConfig.getBaseDir() + mainTmpl.getFileUrl() + mainTmpl.getFileName();
|
|
|
|
|
@@ -317,7 +270,7 @@ public class AssetsReportServiceImpl extends ServiceImpl<AssetsReportMapper, Ass
|
|
|
// 将框架读取出来
|
|
|
Document mainDoc = new Document(mainIs);
|
|
|
// 将摘要插入到框架
|
|
|
- AsposeWordUtil.insertDocumentAfterBookMark(mainDoc, digestDoc, "insertDigest", false, false);
|
|
|
+ AsposeWordUtil.insertDocumentAfterBookMark(mainDoc, new Document(digestIs), "insertDigest", false, false);
|
|
|
// 将正文插入到框架
|
|
|
AsposeWordUtil.insertDocumentAfterBookMark(mainDoc, detailDoc, "insertDetail", false, false);
|
|
|
|
|
@@ -345,36 +298,66 @@ public class AssetsReportServiceImpl extends ServiceImpl<AssetsReportMapper, Ass
|
|
|
// 将目录插入到框架
|
|
|
AsposeWordUtil.insertDocumentAfterBookMark(mainDoc, catalogueDoc, "insertCatalogue", false, false);
|
|
|
|
|
|
- // 删除书签所在的空白行
|
|
|
+ // 第七步:删除预留书签插入位置的空白行
|
|
|
DocumentBuilder mainBuilder = new DocumentBuilder(mainDoc);
|
|
|
-
|
|
|
+ // 移除正文的书签所在段落
|
|
|
mainBuilder.moveToBookmark("insertDetail");
|
|
|
- // 获取当前光标所在的段落
|
|
|
- Paragraph mainCurrentParagraph1 = mainBuilder.getCurrentParagraph();
|
|
|
- mainCurrentParagraph1.remove();
|
|
|
-
|
|
|
+ mainBuilder.getCurrentParagraph().remove();
|
|
|
+ // 移除摘要的书签所在段落
|
|
|
mainBuilder.moveToBookmark("insertDigest");
|
|
|
- // 获取当前光标所在的段落
|
|
|
- Paragraph mainCurrentParagraph2 = mainBuilder.getCurrentParagraph();
|
|
|
- mainCurrentParagraph2.remove();
|
|
|
-
|
|
|
+ mainBuilder.getCurrentParagraph().remove();
|
|
|
+ // 移除目录的书签所在段落
|
|
|
mainBuilder.moveToBookmark("insertCatalogue");
|
|
|
- // 获取当前光标所在的段落
|
|
|
- Paragraph mainCurrentParagraph3 = mainBuilder.getCurrentParagraph();
|
|
|
- mainCurrentParagraph3.remove();
|
|
|
-
|
|
|
+ mainBuilder.getCurrentParagraph().remove();
|
|
|
+ // 移除附件的书签所在段落
|
|
|
mainBuilder.moveToBookmark("insertAttachments");
|
|
|
- // 获取当前光标所在的段落
|
|
|
- Paragraph mainCurrentParagraph4 = mainBuilder.getCurrentParagraph();
|
|
|
- mainCurrentParagraph4.remove();
|
|
|
-
|
|
|
+ mainBuilder.getCurrentParagraph().remove();
|
|
|
+ // 移除委托人概况的书签所在段落
|
|
|
+ mainBuilder.moveToBookmark("insertConsignor");
|
|
|
+ mainBuilder.getCurrentParagraph().remove();
|
|
|
+ // 移除产权持有人概况的书签所在段落
|
|
|
+ mainBuilder.moveToBookmark("insertPropertyOwner");
|
|
|
+ mainBuilder.getCurrentParagraph().remove();
|
|
|
+
|
|
|
+ // 第八步:生成并保存文档
|
|
|
// 将封面和文档进行拼接
|
|
|
- Document coverDoc = new Document(coverPath);
|
|
|
+ Document coverDoc = new Document(coverIs);
|
|
|
coverDoc.appendDocument(mainDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
|
|
|
// 更新目录页码
|
|
|
AsposeWordUtil.updateCatalogueLink(coverDoc);
|
|
|
coverDoc.save(mainPath);
|
|
|
|
|
|
- return null;
|
|
|
+ // 关闭各个段落的流
|
|
|
+ coverIs.close();
|
|
|
+ digestIs.close();
|
|
|
+ detailIs.close();
|
|
|
+ mainIs.close();
|
|
|
+ attachmentsIs.close();
|
|
|
+
|
|
|
+ // 更新报告进度
|
|
|
+ assetsReportMapper.updateReportProgress(reportId,"FINISHED");
|
|
|
+
|
|
|
+ // 保存文档信息到数据库
|
|
|
+ // 设置文档信息
|
|
|
+ AssetsReportVO assetsReportVO = assetsReportMapper.getReportInfoForDoc(reportId);
|
|
|
+ DocumentProduction documentProduction = documentProductionService.getDocProdByBusinessId(assetsReportVO.getProjectId(), reportId);
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotNull(documentProduction)) { // 判断文档信息是否为空,不为空说明以前生成过文档,则更新文档版本号
|
|
|
+ documentProduction.setDocVersion(documentProduction.getDocVersion() + 1);
|
|
|
+ } else { // 为空重新new对象
|
|
|
+ documentProduction = new DocumentProduction();
|
|
|
+ }
|
|
|
+ // 设置文档信息
|
|
|
+ documentProduction.setBusinessType("ASSETS")
|
|
|
+ .setBusinessId(assetsReportVO.getProjectId())
|
|
|
+ .setDocType(EQPT_REPORT.getName())
|
|
|
+ .setDocName(assetsReportVO.getReportName() + ".docx")
|
|
|
+ .setConsignor(assetsReportVO.getPrincipal())
|
|
|
+ .setDocUrl(mainPath)
|
|
|
+ .setCreateUserId(StpUtil.getLoginIdAsLong())
|
|
|
+ .setBusinessCate(assetsReportVO.getProjectTypeName())
|
|
|
+ .setDocNo(eqptReportFillBO.getProductionNo())
|
|
|
+ .setBusinessSubId(reportId);
|
|
|
+ return documentProductionService.saveDocumentProduction(documentProduction);
|
|
|
}
|
|
|
}
|