|
@@ -1,15 +1,27 @@
|
|
|
package com.rongwei.bscommon.sys.service.impl;
|
|
|
|
|
|
+import com.aspose.cells.*;
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxItpProjectNodesService;
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxProjectDeviceNumberService;
|
|
|
+import com.rongwei.bscommon.sys.utils.ProjectSummaryExcelHelp;
|
|
|
import com.rongwei.bsentity.domain.ZhcxProjectManageDo;
|
|
|
import com.rongwei.bscommon.sys.dao.ZhcxProjectManageDao;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxProjectManageService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.rongwei.rwcommoncomponent.file.dto.NewFileDto;
|
|
|
+import com.rongwei.bsentity.dto.project.CellChangeInfoDto;
|
|
|
+import com.rongwei.bsentity.dto.project.ProjectSummaryParamExcelDto;
|
|
|
+import com.rongwei.bsentity.dto.project.WorksheetSummaryDto;
|
|
|
+import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.aspose.ExcelUtils;
|
|
|
+import com.rongwei.rwcommoncomponent.file.dto.SysFileItemParamDto;
|
|
|
import com.rongwei.rwcommoncomponent.file.service.SysFileItemService;
|
|
|
import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 项目管理表 服务实现类
|
|
@@ -22,8 +34,15 @@ import org.springframework.stereotype.Service;
|
|
|
public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageDao, ZhcxProjectManageDo> implements ZhcxProjectManageService {
|
|
|
|
|
|
@Autowired
|
|
|
+ @Lazy
|
|
|
private SysFileItemService fileItemService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ZhcxProjectDeviceNumberService projectDeviceNumberService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ZhcxItpProjectNodesService itpProjectNodesService;
|
|
|
+
|
|
|
/**
|
|
|
* 生成汇总文件
|
|
|
*
|
|
@@ -32,13 +51,230 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
|
@Override
|
|
|
public SysFileItemDo genSummaryFiles(String projectId) {
|
|
|
|
|
|
+ //项目信息
|
|
|
ZhcxProjectManageDo manageDo = getById(projectId);
|
|
|
+ //组装请求参数
|
|
|
+ ProjectSummaryParamExcelDto excelDto = assembleProjectSummaryParam(manageDo);
|
|
|
+ //组装文件实体
|
|
|
+ SysFileItemDo fileItemDo = assembleFileItem(manageDo, excelDto.getFileName());
|
|
|
+ excelDto.setFullPathFile(fileItemDo.getFullpath());
|
|
|
|
|
|
- NewFileDto newFileDto = NewFileDto.builder()
|
|
|
- .fileName(manageDo.getProjectCode().concat(manageDo.getProjectEname()))
|
|
|
- .suffix("xlsx")
|
|
|
- .build();
|
|
|
- SysFileItemDo fileItemDo = fileItemService.newBlankFile(newFileDto);
|
|
|
+ //生成文件
|
|
|
+ genSummaryExcel(excelDto);
|
|
|
+
|
|
|
+ fileItemService.save(fileItemDo);
|
|
|
return fileItemDo;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装整改汇总文件参数
|
|
|
+ *
|
|
|
+ * @param manageDo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ProjectSummaryParamExcelDto assembleProjectSummaryParam(ZhcxProjectManageDo manageDo) {
|
|
|
+ // 文件名
|
|
|
+ String fileName = manageDo.getProjectCode().concat(manageDo.getProjectEname());
|
|
|
+
|
|
|
+ //获取项目机号
|
|
|
+ List<String> deviceNumberList = projectDeviceNumberService.getDeviceNumberByProjectId(manageDo.getId());
|
|
|
+
|
|
|
+ //构件
|
|
|
+ List<String> structureList = itpProjectNodesService.getStructureByProjectId(manageDo.getId());
|
|
|
+
|
|
|
+ ProjectSummaryParamExcelDto excelDto = ProjectSummaryParamExcelDto.builder()
|
|
|
+ .deviceNumberList(deviceNumberList)
|
|
|
+ .fileName(fileName)
|
|
|
+ .structureList(structureList)
|
|
|
+ .build();
|
|
|
+ return excelDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装文件
|
|
|
+ *
|
|
|
+ * @param manageDo
|
|
|
+ * @param fileName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private SysFileItemDo assembleFileItem(ZhcxProjectManageDo manageDo, String fileName) {
|
|
|
+ String fileNameTemp = fileName.concat(".xlsx");
|
|
|
+ SysFileItemParamDto itemParamDto = SysFileItemParamDto.builder()
|
|
|
+ .fileName(fileNameTemp)
|
|
|
+ .build();
|
|
|
+ return fileItemService.assembleItem(itemParamDto, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成汇总文件
|
|
|
+ *
|
|
|
+ * @param excelDto
|
|
|
+ */
|
|
|
+ private void genSummaryExcel(ProjectSummaryParamExcelDto excelDto) {
|
|
|
+ ExcelUtils excelUtils = new ExcelUtils();
|
|
|
+ if(!excelUtils.GetLicense()) {
|
|
|
+ throw new CustomException("license验证失败,请联系管理员!");
|
|
|
+ }
|
|
|
+ // 创建Workbook对象
|
|
|
+ Workbook workbook = new Workbook();
|
|
|
+
|
|
|
+ WorksheetSummaryDto summaryDto = getWorksheet0Param(workbook);
|
|
|
+ int totalColumns = 0;
|
|
|
+
|
|
|
+ //普通标题
|
|
|
+ totalColumns = addNormalTitle(summaryDto, excelDto, totalColumns);
|
|
|
+ //添加机号标题
|
|
|
+ totalColumns = addMachineTitle(summaryDto, excelDto, totalColumns);
|
|
|
+ //添加主标题
|
|
|
+ addMainTitle(summaryDto, excelDto, totalColumns);
|
|
|
+
|
|
|
+ try {
|
|
|
+ workbook.save(excelDto.getFullPathFile());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("文件保存失败,{}", e);
|
|
|
+ throw new CustomException("文件保存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取第一个工作簿参数
|
|
|
+ *
|
|
|
+ * @param workbook
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private WorksheetSummaryDto getWorksheet0Param(Workbook workbook) {
|
|
|
+ //公共样式
|
|
|
+ Style commonStyle = createCommonStyle(workbook);
|
|
|
+
|
|
|
+ Worksheet worksheet = workbook.getWorksheets().get(0);
|
|
|
+
|
|
|
+ // 访问第一个工作表
|
|
|
+ Cells cells = worksheet.getCells();
|
|
|
+
|
|
|
+ return WorksheetSummaryDto.builder()
|
|
|
+ .worksheet(worksheet)
|
|
|
+ .cells(cells)
|
|
|
+ .commonStyle(commonStyle)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加主标题
|
|
|
+ *
|
|
|
+ * @param summaryDto
|
|
|
+ * @param excelDto
|
|
|
+ * @param totalColumns
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private int addMainTitle(WorksheetSummaryDto summaryDto, ProjectSummaryParamExcelDto excelDto, int totalColumns) {
|
|
|
+ Range range = summaryDto.getCells().createRange(0, 0, 1, totalColumns);
|
|
|
+ range.setStyle(summaryDto.getCommonStyle());
|
|
|
+ range.merge();
|
|
|
+ Cell cell = summaryDto.getCells().get(0, 0);
|
|
|
+ cell.setValue(excelDto.getFileName());
|
|
|
+
|
|
|
+ return totalColumns;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加正常标题
|
|
|
+ *
|
|
|
+ * @param summaryDto
|
|
|
+ * @param excelDto
|
|
|
+ * @param totalColumns
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private int addNormalTitle(WorksheetSummaryDto summaryDto, ProjectSummaryParamExcelDto excelDto, int totalColumns) {
|
|
|
+ List<CellChangeInfoDto> normalTitleCellList = ProjectSummaryExcelHelp.getNormalTitleCellList();
|
|
|
+ for (CellChangeInfoDto normal : normalTitleCellList) {
|
|
|
+ //单元格合并
|
|
|
+ Range range = summaryDto.getCells().createRange(normal.getRangeCellName());
|
|
|
+ range.setStyle(summaryDto.getCommonStyle());
|
|
|
+ range.merge();
|
|
|
+
|
|
|
+ Cell cell10 = summaryDto.getCells().get(normal.getCellName());
|
|
|
+ cell10.setValue(normal.getValue());
|
|
|
+ totalColumns++;
|
|
|
+ }
|
|
|
+
|
|
|
+ //部位添加下拉框
|
|
|
+ CellArea area = new CellArea();
|
|
|
+ area.StartRow = 3;
|
|
|
+ area.EndRow = 1000;
|
|
|
+ area.StartColumn = 2;
|
|
|
+ area.EndColumn = 1;
|
|
|
+ int validations = summaryDto.getWorksheet().getValidations().add(area);
|
|
|
+ Validation validation = summaryDto.getWorksheet().getValidations().get(validations);
|
|
|
+ // 创建一个Validation对象
|
|
|
+ // 设置Validation的类型为下拉列表
|
|
|
+ validation.setType(ValidationType.LIST);
|
|
|
+ // 设置Validation的输入消息和错误消息
|
|
|
+ // 设置Validation的有效条件,即下拉列表的选项
|
|
|
+ validation.setFormula1(String.join(",", excelDto.getStructureList()));
|
|
|
+
|
|
|
+ return totalColumns;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加机号标题
|
|
|
+ *
|
|
|
+ * @param summaryDto
|
|
|
+ * @param excelDto
|
|
|
+ * @param totalColumns
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private int addMachineTitle(WorksheetSummaryDto summaryDto, ProjectSummaryParamExcelDto excelDto, int totalColumns) {
|
|
|
+ //机号
|
|
|
+ for(String deviceNumber : excelDto.getDeviceNumberList()) {
|
|
|
+ Range range = summaryDto.getCells().createRange(1, totalColumns, 1, 4);
|
|
|
+ range.setStyle(summaryDto.getCommonStyle());
|
|
|
+ range.merge();
|
|
|
+
|
|
|
+ Cell macchineCell = summaryDto.getCells().get(1, totalColumns);
|
|
|
+ macchineCell.setValue(deviceNumber);
|
|
|
+
|
|
|
+ //机号下标题
|
|
|
+ for(String title : ProjectSummaryExcelHelp.getMachineTitles()) {
|
|
|
+ Cell macchineTitleCell = summaryDto.getCells().get(2, totalColumns);
|
|
|
+ macchineTitleCell.setStyle(summaryDto.getCommonStyle());
|
|
|
+ macchineTitleCell.setValue(title);
|
|
|
+ totalColumns++;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return totalColumns;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建公共样式
|
|
|
+ *
|
|
|
+ * @param workbook
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Style createCommonStyle(Workbook workbook) {
|
|
|
+ Style style1 = workbook.createStyle();
|
|
|
+ style1.setHorizontalAlignment(TextAlignmentType.CENTER);
|
|
|
+ style1.setVerticalAlignment(TextAlignmentType.CENTER);
|
|
|
+ style1.setLocked(true);
|
|
|
+ //上边线
|
|
|
+ Border topBorder = style1.getBorders().getByBorderType(BorderType.TOP_BORDER);
|
|
|
+ topBorder.setColor(Color.getBlack());
|
|
|
+ topBorder.setLineStyle(CellBorderType.THIN);
|
|
|
+ //下边线
|
|
|
+ Border bottomBorder = style1.getBorders().getByBorderType(BorderType.BOTTOM_BORDER);
|
|
|
+ bottomBorder.setColor(Color.getBlack());
|
|
|
+ bottomBorder.setLineStyle(CellBorderType.THIN);
|
|
|
+
|
|
|
+ //左边线
|
|
|
+ Border leftBorder = style1.getBorders().getByBorderType(BorderType.LEFT_BORDER);
|
|
|
+ leftBorder.setColor(Color.getBlack());
|
|
|
+ leftBorder.setLineStyle(CellBorderType.THIN);
|
|
|
+
|
|
|
+ //右边线
|
|
|
+ Border rightBorder = style1.getBorders().getByBorderType(BorderType.RIGHT_BORDER);
|
|
|
+ rightBorder.setColor(Color.getBlack());
|
|
|
+ rightBorder.setLineStyle(CellBorderType.THIN);
|
|
|
+ return style1;
|
|
|
+ }
|
|
|
}
|