|
@@ -2,13 +2,27 @@ package com.dayou.service.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.aspose.words.Document;
|
|
|
+import com.aspose.words.DocumentBuilder;
|
|
|
+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.TmplAssetReportSection;
|
|
|
+import com.dayou.enums.EqptReportTmplCode;
|
|
|
import com.dayou.mapper.AssetsReportMapper;
|
|
|
+import com.dayou.mapper.TmplAssetReportSectionMapper;
|
|
|
import com.dayou.service.AssetsReportService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.dayou.utils.ArabicToChineseUtil;
|
|
|
+import com.dayou.utils.AsposeWordUtil;
|
|
|
+import com.dayou.utils.DataUtil;
|
|
|
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;
|
|
@@ -19,11 +33,20 @@ 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.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+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.EqptReportTmplCode.*;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 资产项目报告信息表 服务实现类
|
|
@@ -38,6 +61,12 @@ public class AssetsReportServiceImpl extends ServiceImpl<AssetsReportMapper, Ass
|
|
|
@Autowired
|
|
|
private AssetsReportMapper assetsReportMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TmplAssetReportSectionMapper reportSectionMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileNetConfig fileNetConfig;
|
|
|
+
|
|
|
/**
|
|
|
* 根据项目id查询所有报告信息
|
|
|
*
|
|
@@ -110,4 +139,106 @@ public class AssetsReportServiceImpl extends ServiceImpl<AssetsReportMapper, Ass
|
|
|
public String getReportBaseInfo(Long reportId) {
|
|
|
return assetsReportMapper.getReportBaseInfo(reportId);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成机器设备报告word文件
|
|
|
+ * @param reportId 报告id
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean generateEquipmentReport(Long reportId) throws Exception {
|
|
|
+
|
|
|
+ // 获取基础报告信息
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ EqptReportFillBO eqptReportFillBO = assetsReportMapper.geteqptReportFillBO(reportId);
|
|
|
+ // 设置增值率(评估净值 - 账面净值) / 账面净值,保留两位小数
|
|
|
+ eqptReportFillBO.setValueAddedRate(((eqptReportFillBO.getEvaluateNetValue().subtract(eqptReportFillBO.getBookNetValue())).divide(eqptReportFillBO.getBookNetValue(), 2, RoundingMode.HALF_UP)).doubleValue() * 100);
|
|
|
+ // 设置其他的信息
|
|
|
+ eqptReportFillBO.setEqptReportBaseInfo(objectMapper.readValue(getReportBaseInfo(reportId), EqptReportBaseInfoDTO.class));
|
|
|
+ // 设置委托人和产权持有人的名字
|
|
|
+ eqptReportFillBO.setConsignorCompanyName(eqptReportFillBO.getEqptReportBaseInfo().getConsignorInfos().stream() // 将集合转换为流
|
|
|
+ .map(EqptReportBaseInfoDTO.ConsignorInfo::getConsignorCompanyName) // 提取每个对象的consignorCompanyName属性
|
|
|
+ .collect(Collectors.joining("、")));
|
|
|
+ eqptReportFillBO.setOwnerCompanyName(eqptReportFillBO.getEqptReportBaseInfo().getPropertyOwnerInfos().stream() // 将集合转换为流
|
|
|
+ .map(EqptReportBaseInfoDTO.PropertyOwnerInfo::getOwnerCompanyName) // 提取每个对象的ownerCompanyName属性
|
|
|
+ .collect(Collectors.joining("、")));
|
|
|
+
|
|
|
+ // 第一步:设置封面
|
|
|
+ // 获取封面模板
|
|
|
+ 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.fillWordDataByDomain(coverTmplByte, eqptReportFillBO);
|
|
|
+
|
|
|
+ // 处理该二进制文件并保存
|
|
|
+ File resultFile = new File(coverPath);
|
|
|
+ FileOutputStream fos = new FileOutputStream(resultFile);
|
|
|
+ fos.write(resultCoverByte);
|
|
|
+ fos.close();
|
|
|
+
|
|
|
+ // 第二步:设置正文内容
|
|
|
+ // 获取正文
|
|
|
+ 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[] mainTmplByte = Files.readAllBytes(Paths.get(detailTmplPath));
|
|
|
+ // 获取填充数据后的文件
|
|
|
+ byte[] resultMainByte = AsposeWordUtil.fillWordDataByMap(mainTmplByte, DataUtil.objToMap(eqptReportFillBO));
|
|
|
+
|
|
|
+ // 处理该二进制文件并保存
|
|
|
+ File detailFile = new File(detailPath);
|
|
|
+ FileOutputStream detailOs = new FileOutputStream(detailFile);
|
|
|
+ detailOs.write(resultMainByte);
|
|
|
+ detailOs.close();
|
|
|
+
|
|
|
+ // 第三步:设置委托人概况
|
|
|
+ // 获取委托人概况模板
|
|
|
+ TmplAssetReportSection consignorTmpl = reportSectionMapper.getTmplByCode(CONSIGNOR.getCode());
|
|
|
+ // 委托人概况生成后文件位置
|
|
|
+ String consignorPath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputReportPath() + System.currentTimeMillis() + "_CONSIGNOR.docx";
|
|
|
+ // 委托人概况模板文件位置
|
|
|
+ String consignorTmplPath = fileNetConfig.getBaseDir() + consignorTmpl.getSectionFileUrl() + consignorTmpl.getSectionFileName();
|
|
|
+
|
|
|
+ Document detailDoc = new Document(detailPath);
|
|
|
+ for (int i = 0; i < eqptReportFillBO.getEqptReportBaseInfo().getConsignorInfos().size() ; i++) {
|
|
|
+ EqptReportBaseInfoDTO.ConsignorInfo consignorInfo = eqptReportFillBO.getEqptReportBaseInfo().getConsignorInfos().get(i);
|
|
|
+ consignorInfo.setSort(i + 1);
|
|
|
+ consignorInfo.setSortUppercase(ArabicToChineseUtil.int2chineseNum(i + 1));
|
|
|
+ // 读取模板文件
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ DocumentBuilder builder = new DocumentBuilder(detailDoc);
|
|
|
+
|
|
|
+ builder.moveToBookmark("insertConsignor");
|
|
|
+
|
|
|
+ // 获取当前光标所在的段落
|
|
|
+ Paragraph currentParagraph = builder.getCurrentParagraph();
|
|
|
+
|
|
|
+ currentParagraph.remove();
|
|
|
+
|
|
|
+ detailDoc.save(detailPath);
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|