|
@@ -3,14 +3,26 @@ package com.dayou.service.impl;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.read.listener.PageReadListener;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.dayou.common.BaseEntity;
|
|
|
+import com.dayou.common.CalculateFormula;
|
|
|
+import com.dayou.config.FileNetConfig;
|
|
|
import com.dayou.dto.calculate.equipment.EquipmentBaseInfoDTO;
|
|
|
import com.dayou.entity.AssetsCalculate;
|
|
|
import com.dayou.entity.AssetsCalculateEqptData;
|
|
|
+import com.dayou.entity.TmplAssetCalculate;
|
|
|
+import com.dayou.entity.TmplAssetCalculateSection;
|
|
|
import com.dayou.mapper.AssetsCalculateMapper;
|
|
|
+import com.dayou.mapper.TmplAssetCalculateMapper;
|
|
|
+import com.dayou.mapper.TmplAssetCalculateSectionMapper;
|
|
|
import com.dayou.service.AssetsCalculateEqptDataService;
|
|
|
import com.dayou.service.AssetsCalculateService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.dayou.utils.EasyExcelUtil;
|
|
|
import com.dayou.vo.calculate.AssetsCalculateProgressVO;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -20,6 +32,13 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+
|
|
|
+import static com.dayou.common.CalculateFormula.EQUIPMENT_MAIN_FORMULA;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -38,6 +57,15 @@ public class AssetsCalculateServiceImpl extends ServiceImpl<AssetsCalculateMappe
|
|
|
@Autowired
|
|
|
private AssetsCalculateEqptDataService assetsCalculateEqptDataService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TmplAssetCalculateMapper tmplAssetCalculateMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TmplAssetCalculateSectionMapper calculateSectionMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileNetConfig fileNetConfig;
|
|
|
+
|
|
|
@Override
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public Page<AssetsCalculate> selectPage(Page page,AssetsCalculate assetsCalculate){
|
|
@@ -111,4 +139,105 @@ public class AssetsCalculateServiceImpl extends ServiceImpl<AssetsCalculateMappe
|
|
|
assetsCalculateMapper.updateCalculateProgress(calculateId,"GENERATE");
|
|
|
return assetsCalculateMapper.updateCalculateBaseInfo(calculateId, baseInfo);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成机器设备测算表excel文件
|
|
|
+ * @param calculateId 测算表id
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean generateEquipmentCalculate(Long calculateId) throws IOException {
|
|
|
+
|
|
|
+ // 第一步:写入数据到 机器设备-主模板-设备信息-段落模板
|
|
|
+ // 获取模板
|
|
|
+ TmplAssetCalculateSection calculateSection = calculateSectionMapper.getByTmplCode("MAIN_DETAIL");
|
|
|
+ // 生成后文件的位置
|
|
|
+ String mainDetailPath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputCalculatePath() + System.currentTimeMillis() + "_MAIN_DETAIL.xlsx";
|
|
|
+ // 模板文件的位置
|
|
|
+ String mainDetailTMplPath = fileNetConfig.getBaseDir() + calculateSection.getSectionFileUrl() + calculateSection.getSectionFileName();
|
|
|
+ // 写入
|
|
|
+ EasyExcel.write(mainDetailPath)
|
|
|
+ .withTemplate(mainDetailTMplPath)
|
|
|
+ .sheet()
|
|
|
+ .doFill(assetsCalculateEqptDataService.getAllByAssetsCalculateId(calculateId));
|
|
|
+
|
|
|
+ // 第二步:写入数据到 机器设备-主模板
|
|
|
+ // 获取模板
|
|
|
+ TmplAssetCalculate calculate = tmplAssetCalculateMapper.getCalculateTmplByCode("MAIN");
|
|
|
+ // 生成后文件的位置
|
|
|
+ String mainPath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputCalculatePath() + System.currentTimeMillis() + "_MAIN.xlsx";
|
|
|
+ // 模板文件的位置
|
|
|
+ String mainTmplPath = fileNetConfig.getBaseDir() + calculate.getFileUrl() + calculate.getFileName();
|
|
|
+ // 获取基础测算信息
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ EquipmentBaseInfoDTO baseInfoDTO = objectMapper.readValue(getCalculateBaseInfo(calculateId), EquipmentBaseInfoDTO.class);
|
|
|
+ // 利息、前期费用率、建设单位管理费率采用百分比,需要除100
|
|
|
+ baseInfoDTO.setInterest(baseInfoDTO.getInterest() / 100);
|
|
|
+ baseInfoDTO.setPreConstructionCostRatio(baseInfoDTO.getPreConstructionCostRatio() / 100);
|
|
|
+ baseInfoDTO.setManagementExpenseRatio(baseInfoDTO.getManagementExpenseRatio() / 100);
|
|
|
+ // 获取评估基准日
|
|
|
+ baseInfoDTO.setValuationBasisDate(getValuationBasisDate(calculateId));
|
|
|
+ // 写入
|
|
|
+ EasyExcel.write(mainPath)
|
|
|
+ .withTemplate(mainTmplPath)
|
|
|
+ .sheet()
|
|
|
+ .doFill(baseInfoDTO);
|
|
|
+
|
|
|
+ // 第三步:将 机器设备-主模板-设备信息-段落模板 拼接到 写入数据到 机器设备-主模板
|
|
|
+ // 合并后文件的位置
|
|
|
+ String mainMergePath = fileNetConfig.getBaseDir() + fileNetConfig.getAssetOutputCalculatePath() + System.currentTimeMillis() + "_MAIN_MERGE.xlsx";
|
|
|
+ Workbook workbook = EasyExcelUtil.mergeExcel(mainDetailPath, mainPath, 0, 4, 0);
|
|
|
+
|
|
|
+ // 第四步:主模板设置公式
|
|
|
+ // 遍历所有行,跳过前四行
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ for (int i = 4; i <= sheet.getLastRowNum(); i++) {
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ // 循环设置公式
|
|
|
+ for (CalculateFormula.EquipmentMainFormula formula: EQUIPMENT_MAIN_FORMULA) {
|
|
|
+ Cell cell = row.getCell(formula.getColumn() - 1);
|
|
|
+ // 如果该单元格不存在,则创建一个
|
|
|
+ if (cell == null) {
|
|
|
+ cell = row.createCell(formula.getColumn() - 1);
|
|
|
+ }
|
|
|
+ // 设置公式
|
|
|
+ cell.setCellFormula(MessageFormat.format(formula.getFormula(),(row.getRowNum() + 1)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 强制计算公式
|
|
|
+ workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
|
|
|
+
|
|
|
+ OutputStream outputStream = Files.newOutputStream(Paths.get(mainMergePath));
|
|
|
+ workbook.write(outputStream);
|
|
|
+ // 关闭流
|
|
|
+ workbook.close();
|
|
|
+ outputStream.close();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据测算表id获取基础测算信息
|
|
|
+ * @param calculateId 测算表id
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String getCalculateBaseInfo(Long calculateId) {
|
|
|
+ return assetsCalculateMapper.selectOne(new LambdaQueryWrapper<AssetsCalculate>()
|
|
|
+ .select(AssetsCalculate::getBaseInfo)
|
|
|
+ .eq(BaseEntity::getId, calculateId)
|
|
|
+ .eq(BaseEntity::getDeleteStatus, 0))
|
|
|
+ .getBaseInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据测算表id获取评估基准日
|
|
|
+ * @param calculateId 测算表id
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ public LocalDate getValuationBasisDate(Long calculateId) {
|
|
|
+ return assetsCalculateMapper.selectOne(new LambdaQueryWrapper<AssetsCalculate>()
|
|
|
+ .select(AssetsCalculate::getValuationBasisDate)
|
|
|
+ .eq(BaseEntity::getId, calculateId)
|
|
|
+ .eq(BaseEntity::getDeleteStatus, 0)).getValuationBasisDate();
|
|
|
+ }
|
|
|
}
|