|
@@ -1,19 +1,34 @@
|
|
|
package com.rongwei.bscommon.sys.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.aspose.cells.SaveFormat;
|
|
|
+import com.aspose.cells.Workbook;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.rongwei.bscommon.sys.service.*;
|
|
|
import com.rongwei.bsentity.domain.*;
|
|
|
import com.rongwei.bscommon.sys.dao.ZhcxItpProjectNodesDao;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.rongwei.bsentity.dto.ItpProjectNodeExtVo;
|
|
|
+import com.rongwei.bsentity.dto.ItpProjectNodeL2Vo;
|
|
|
+import com.rongwei.bsentity.dto.OutsideInspectionProjectPointDto;
|
|
|
import com.rongwei.bsentity.vo.CopyNodeVo;
|
|
|
import com.rongwei.commonservice.service.dao.CommonSqlDao;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommon.utils.JSONUtils;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.aspose.ExcelExportUtil;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.aspose.ExcelUtils;
|
|
|
+import com.rongwei.rwcommoncomponent.excel.vo.FormData;
|
|
|
+import com.rongwei.rwcommoncomponent.file.service.SysFileItemService;
|
|
|
+import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -39,6 +54,13 @@ public class ZhcxItpProjectNodesServiceImpl extends ServiceImpl<ZhcxItpProjectNo
|
|
|
@Autowired
|
|
|
private CommonSqlDao commonSqlDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExcelUtils excelUtils;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysFileItemService sysFileItemService;
|
|
|
+
|
|
|
/**
|
|
|
* 项目引用ITP模板节点
|
|
|
* @param map
|
|
@@ -378,6 +400,158 @@ public class ZhcxItpProjectNodesServiceImpl extends ServiceImpl<ZhcxItpProjectNo
|
|
|
return getProjectNodes(copyNodeVo);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出项目报验点
|
|
|
+ *
|
|
|
+ * @param excelData
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void exportProjectInspectionPoint(OutsideInspectionProjectPointDto excelData, HttpServletResponse response) {
|
|
|
+
|
|
|
+ //获取模板数据
|
|
|
+ FormData formData = getProjectFormData(excelData.getProjectId());
|
|
|
+
|
|
|
+ SysFileItemDo fileItem = sysFileItemService.getById(excelData.getFileId());
|
|
|
+
|
|
|
+ exportExcelByTemplate(formData, fileItem, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param formData
|
|
|
+ * @param fileItem
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ private void exportExcelByTemplate(FormData formData, SysFileItemDo fileItem, HttpServletResponse response) {
|
|
|
+ if(!excelUtils.GetLicense()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //excel
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcelByAsposeWithTemplate(formData, fileItem.getFullpath());
|
|
|
+ //传给前端
|
|
|
+ wookboot2Response(response, fileItem.getFilename(), workbook);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * excel填充到response中,传给前端
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param filename
|
|
|
+ * @param workbook
|
|
|
+ */
|
|
|
+ private void wookboot2Response(HttpServletResponse response,String filename, Workbook workbook) {
|
|
|
+ try {
|
|
|
+ //执行公式计算
|
|
|
+ workbook.calculateFormula();
|
|
|
+ if (filename.indexOf("直打") >= 0 || filename.toLowerCase().indexOf("pdf") >= 0) {
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+ workbook.save(response.getOutputStream(), SaveFormat.PDF);
|
|
|
+ } else {
|
|
|
+ response.setContentType("application/octet-stream;charset=ISO8859-1");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + filename);
|
|
|
+ workbook.save(response.getOutputStream(), SaveFormat.XLSX);
|
|
|
+ }
|
|
|
+ workbook.dispose();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("填充失败:{}", e);
|
|
|
+ throw new CustomException("填充失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取导出数据信息
|
|
|
+ *
|
|
|
+ * @param projectId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private FormData getProjectFormData(String projectId) {
|
|
|
+
|
|
|
+ //主表单
|
|
|
+ List<Map<String, Object>> mainList = new ArrayList<>(1);
|
|
|
+ //项目信息
|
|
|
+ Map<String, Object> project = this.getBaseMapper().getProjectByProjectId(projectId);
|
|
|
+ if(ObjectUtil.isNotNull(project)) {
|
|
|
+ mainList.add(project);
|
|
|
+ } else {
|
|
|
+ mainList.add(Collections.emptyMap());
|
|
|
+ }
|
|
|
+
|
|
|
+ //从表单
|
|
|
+ List<ZhcxItpProjectNodesDo> l3 = new ArrayList<>();
|
|
|
+ Map<String, ZhcxItpProjectNodesDo> map = new HashMap<>();
|
|
|
+ //获取项目下报验点
|
|
|
+ LambdaQueryWrapper<ZhcxItpProjectNodesDo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(ZhcxItpProjectNodesDo::getProjectid, projectId)
|
|
|
+ .eq(ZhcxItpProjectNodesDo::getDeleted, "0");
|
|
|
+ List<ZhcxItpProjectNodesDo> projectNodes = list(queryWrapper);
|
|
|
+
|
|
|
+ for(ZhcxItpProjectNodesDo node : projectNodes) {
|
|
|
+ //报验点
|
|
|
+ if("3".equals(node.getLevel()) && "true".equals(node.getIsneedout())) {
|
|
|
+ l3.add(node);
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put(node.getId(), node);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<List<Map<String, Object>>> slaveList = new ArrayList<>();
|
|
|
+ if(ObjectUtil.isEmpty(l3)) {
|
|
|
+ slaveList.add(Collections.emptyList());
|
|
|
+ return FormData.builder()
|
|
|
+ .mainDataList(mainList)
|
|
|
+ .slaveTableDataList(slaveList)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ int count = 0;
|
|
|
+ for(ZhcxItpProjectNodesDo node : l3) {
|
|
|
+
|
|
|
+ count++;
|
|
|
+
|
|
|
+ ItpProjectNodeExtVo nodeExtVo = new ItpProjectNodeExtVo();
|
|
|
+ BeanUtil.copyProperties(node, nodeExtVo);
|
|
|
+
|
|
|
+ ZhcxItpProjectNodesDo nodesDo = map.get(node.getPid());
|
|
|
+ if(ObjectUtil.isNull(nodesDo)) {
|
|
|
+ nodeExtVo.setL2NodeName("");
|
|
|
+ nodeExtVo.setL1NodeName("");
|
|
|
+ } else {
|
|
|
+ if(ObjectUtil.isEmpty(nodesDo.getPnodeid())) {
|
|
|
+ //构件
|
|
|
+ nodeExtVo.setL2NodeName(nodesDo.getNodename());
|
|
|
+ //阶段
|
|
|
+ ZhcxItpProjectNodesDo l1node = map.get(nodesDo.getPid());
|
|
|
+ nodeExtVo.setL1NodeName(l1node.getNodename());
|
|
|
+ } else {
|
|
|
+ //大小构件
|
|
|
+ ZhcxItpProjectNodesDo pnode = map.get(nodesDo.getPnodeid());
|
|
|
+ nodeExtVo.setL2NodeName(pnode.getNodename().concat("/").concat(nodesDo.getNodename()));
|
|
|
+
|
|
|
+ //阶段
|
|
|
+ ZhcxItpProjectNodesDo l1node = map.get(pnode.getPid());
|
|
|
+ nodeExtVo.setL1NodeName(l1node.getNodename());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ nodeExtVo.setIdx(count);
|
|
|
+ nodeExtVo.setTypeOfQc("H");
|
|
|
+ Map<String, Object> map1 = JSONUtils.toEntity(nodeExtVo, Map.class);
|
|
|
+ list.add(map1);
|
|
|
+ }
|
|
|
+
|
|
|
+ slaveList.add(list);
|
|
|
+
|
|
|
+
|
|
|
+ return FormData.builder()
|
|
|
+ .mainDataList(mainList)
|
|
|
+ .slaveTableDataList(slaveList)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 返回最新数据
|
|
|
* @param copyNodeVo
|