|
@@ -0,0 +1,1276 @@
|
|
|
+package org.springblade.manager.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import org.apache.commons.lang.ObjectUtils;
|
|
|
+import org.springblade.business.entity.InformationQuery;
|
|
|
+import org.springblade.common.constant.CommonConstant;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.log.publisher.ErrorLogPublisher;
|
|
|
+import org.springblade.core.tool.utils.*;
|
|
|
+import org.springblade.manager.entity.*;
|
|
|
+import org.springblade.manager.enums.WbsSyncTypeEnum;
|
|
|
+import org.springblade.manager.mapper.*;
|
|
|
+import org.springblade.system.cache.ParamCache;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.rmi.ServerException;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Wbs 同步功能Service
|
|
|
+ *
|
|
|
+ * @author LHB
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class WbsSynchronousServiceImpl {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+ //实体表
|
|
|
+ @Autowired
|
|
|
+ private TableInfoMapper tableInfoMapper;
|
|
|
+ //清表
|
|
|
+ @Autowired
|
|
|
+ private ExcelTabMapper excelTabMapper;
|
|
|
+
|
|
|
+ //电签同步事务类
|
|
|
+ @Autowired
|
|
|
+ private WbsSynchronousEViSaServiceImpl wbsSynchronousEViSaService;
|
|
|
+ //电签
|
|
|
+ @Autowired
|
|
|
+ private TextdictInfoMapper textdictInfoMapper;
|
|
|
+ //合同wbs
|
|
|
+ @Autowired
|
|
|
+ private WbsTreeContractMapper wbsTreeContractMapper;
|
|
|
+ //合同
|
|
|
+ @Autowired
|
|
|
+ private ContractInfoMapper contractInfoMapper;
|
|
|
+ //项目wbs
|
|
|
+ @Autowired
|
|
|
+ private WbsTreePrivateMapper wbsTreePrivateMapper;
|
|
|
+ //系统wbs
|
|
|
+ @Autowired
|
|
|
+ private WbsTreeMapper wbsTreeMapper;
|
|
|
+ //项目
|
|
|
+ @Autowired
|
|
|
+ private ProjectInfoMapper projectInfoMapper;
|
|
|
+ //同步信息
|
|
|
+ @Autowired
|
|
|
+ private WbsTreeSynchronousRecordMapper synchronousRecordMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @Async("taskExecutor1")
|
|
|
+ public void syncExecute(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) {
|
|
|
+ // 类型枚举 WbsSyncTypeEnum.ALREADY_FILLED_IN_NOT_REPORTED
|
|
|
+ //范围 1.项目,2.合同
|
|
|
+ //
|
|
|
+ try {
|
|
|
+ Integer range = wbsTreeSynchronousRecord.getRange();
|
|
|
+ switch (range) {
|
|
|
+ case 1:
|
|
|
+ //同步项目
|
|
|
+ insertPrivateNode(wbsTreeSynchronousRecord);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ //同步合同段
|
|
|
+ insertContractNode(wbsTreeSynchronousRecord);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ //同步元素相同的所有表单
|
|
|
+ syncPrivateAllForm(wbsTreeSynchronousRecord);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ //强制同步表单
|
|
|
+ syncPrivateForceForm(wbsTreeSynchronousRecord);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new ServiceException("同步类型错误");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
|
|
|
+ .set(WbsTreeSynchronousRecord::getStatus, 3)
|
|
|
+ .set(WbsTreeSynchronousRecord::getErrorMsg, e.getMessage())
|
|
|
+ .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
|
|
|
+ .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
|
|
|
+ ErrorLogPublisher.publishEvent(e, null);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步所有相同元素的表单
|
|
|
+ *
|
|
|
+ * @param wbsTreeSynchronousRecord
|
|
|
+ */
|
|
|
+ private void syncPrivateAllForm(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) {
|
|
|
+ String nodeId = wbsTreeSynchronousRecord.getNodeId();
|
|
|
+ WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectById(nodeId);
|
|
|
+ if (wbsTreePrivate == null) {
|
|
|
+ throw new ServiceException("节点/表单 不存在");
|
|
|
+ }
|
|
|
+ String initTableName = wbsTreePrivate.getInitTableName();
|
|
|
+ if (StringUtil.isBlank(initTableName)) {
|
|
|
+ throw new ServiceException("表单未绑定实体表");
|
|
|
+ }
|
|
|
+ //在指定项目下指定实体表相同的数据
|
|
|
+ List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .eq(WbsTreePrivate::getProjectId, wbsTreePrivate.getProjectId())
|
|
|
+ .ne(WbsTreePrivate::getPKeyId, nodeId)
|
|
|
+ .eq(WbsTreePrivate::getInitTableName, initTableName)
|
|
|
+ );
|
|
|
+ if (CollectionUtil.isEmpty(wbsTreePrivates)) {
|
|
|
+ throw new ServiceException("当前项目没有相同实体表的其他表单");
|
|
|
+ }
|
|
|
+ //清表也相同的数据
|
|
|
+ List<WbsTreePrivate> collect = wbsTreePrivates.stream().filter(f ->
|
|
|
+ Objects.equals(f.getExcelId(), wbsTreePrivate.getExcelId())
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ //清表不同的数据
|
|
|
+ List<WbsTreePrivate> noExcelIdEq = wbsTreePrivates.stream().filter(f -> !Objects.equals(f.getExcelId(), wbsTreePrivate.getExcelId())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isNotEmpty(noExcelIdEq)) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (WbsTreePrivate treePrivate : noExcelIdEq) {
|
|
|
+ List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery().in(WbsTreePrivate::getPKeyId, Func.toLongList(treePrivate.getAncestorsPId())));
|
|
|
+ List<String> nodeNames = list.stream().map(WbsTreePrivate::getNodeName).collect(Collectors.toList());
|
|
|
+
|
|
|
+ sb.append(StringUtil.join(nodeNames, "/")).append(";");
|
|
|
+ }
|
|
|
+ throw new ServiceException("清表绑定错误:" + sb);
|
|
|
+ }
|
|
|
+ List<Long> ids = collect.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
|
|
|
+ //修改数据
|
|
|
+ wbsSynchronousEViSaService.updateSyncPrivateForm(wbsTreePrivate.getHtmlUrl(), ids, wbsTreeSynchronousRecord.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 强制同步表单
|
|
|
+ *
|
|
|
+ * @param wbsTreeSynchronousRecord
|
|
|
+ */
|
|
|
+ private void syncPrivateForceForm(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) {
|
|
|
+ String nodeId = wbsTreeSynchronousRecord.getNodeId();
|
|
|
+ if (nodeId.contains(",")) {
|
|
|
+ throw new ServiceException("不能选中多个节点");
|
|
|
+ }
|
|
|
+ String formIds = wbsTreeSynchronousRecord.getFormIds();
|
|
|
+ //选中的表单
|
|
|
+ WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectById(formIds);
|
|
|
+ if (wbsTreePrivate == null) {
|
|
|
+ throw new ServiceException("表单不存在");
|
|
|
+ }
|
|
|
+ wbsSynchronousEViSaService.syncPrivateForceForm(wbsTreePrivate, nodeId, wbsTreeSynchronousRecord.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目同步 获取源节点数据和当前节点数据
|
|
|
+ *
|
|
|
+ * @param wbsTreeSynchronousRecord
|
|
|
+ */
|
|
|
+ public void insertPrivateNode(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) throws IOException {
|
|
|
+ String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
|
|
|
+ //同步类型 1.新增表单,2.新增节点,3.删除节点,4.删除表单,5.修改节点,6.修改表单,7.修改节点表单
|
|
|
+ String type = wbsTreeSynchronousRecord.getType();
|
|
|
+ Set<Integer> collect = Arrays.stream(type.split(","))
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 选中节点
|
|
|
+ String nodeId = wbsTreeSynchronousRecord.getNodeId();
|
|
|
+ if (StringUtil.isBlank(nodeId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String[] nodeIds = nodeId.split(",");
|
|
|
+ //选中表单
|
|
|
+ String formIds = wbsTreeSynchronousRecord.getFormIds();
|
|
|
+ Set<Long> formList = StringUtil.isNotBlank(formIds)
|
|
|
+ ? Arrays.stream(formIds.split(",")).map(Long::parseLong).collect(Collectors.toSet())
|
|
|
+ : Collections.emptySet();
|
|
|
+
|
|
|
+ //获取项目信息
|
|
|
+ ProjectInfo projectInfo = projectInfoMapper.selectOne(Wrappers.<ProjectInfo>lambdaQuery()
|
|
|
+ .eq(ProjectInfo::getId, wbsTreeSynchronousRecord.getProjectId()));
|
|
|
+ //模板项目信息
|
|
|
+ ProjectInfo tempProject = projectInfoMapper.selectOne(Wrappers.<ProjectInfo>lambdaQuery()
|
|
|
+ .eq(ProjectInfo::getId, wbsTreeSynchronousRecord.getTemplateId()));
|
|
|
+
|
|
|
+ List<WbsTreePrivate> editData = new ArrayList<>();
|
|
|
+
|
|
|
+ for (String primaryKeyId : nodeIds) {
|
|
|
+ if (StringUtils.isNotEmpty(primaryKeyId)) {
|
|
|
+ //获取当前节点对应节点信息
|
|
|
+ WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .eq(WbsTreePrivate::getPKeyId, primaryKeyId));
|
|
|
+ if (wbsTreePrivate == null) {
|
|
|
+ throw new ServiceException("当前节点不存在");
|
|
|
+ }
|
|
|
+ //当前项目绑定的是公有模板还是私有项目
|
|
|
+ Boolean isPublic = false;
|
|
|
+
|
|
|
+ if (tempProject == null) {
|
|
|
+ isPublic = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //当前项目模板对应的节点信息
|
|
|
+ List<WbsTreePrivate> templateNodes = new ArrayList<>();
|
|
|
+ //质检
|
|
|
+ //当前节点引用的模板为公有模板
|
|
|
+
|
|
|
+ if (isPublic) {
|
|
|
+ //获取模板中当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
|
|
|
+ LambdaQueryWrapper<WbsTree> wrapperTree = Wrappers.lambdaQuery();
|
|
|
+ wrapperTree
|
|
|
+ .eq(WbsTree::getIsDeleted, 0)
|
|
|
+ .eq(WbsTree::getType, 2)
|
|
|
+ .apply("FIND_IN_SET({0},ancestors)", wbsTreePrivate.getTreePId());
|
|
|
+ //模板节点的所有子节点信息
|
|
|
+ List<WbsTree> wbsTrees = wbsTreeMapper.selectList(wrapperTree);
|
|
|
+ //3、获取需要新增的节点或者表单节点信息 以及他们对应的父级节点信息--------------------------------------------------------------------------------------------
|
|
|
+ if (CollectionUtil.isEmpty(wbsTrees)) {
|
|
|
+ throw new ServiceException("模板节点未找到");
|
|
|
+ }
|
|
|
+ templateNodes = BeanUtil.copyProperties(wbsTrees, WbsTreePrivate.class);
|
|
|
+ templateNodes.forEach(f -> {
|
|
|
+ f.setPKeyId(f.getId());
|
|
|
+ f.setTreePId(f.getId());
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //获取当前选中节点与私有模板对应的节点信息 父级模板项目的当前选中节点
|
|
|
+ WbsTreePrivate wbsTreePrivateRoot = wbsTreePrivateMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .eq(WbsTreePrivate::getProjectId, wbsTreeSynchronousRecord.getTemplateId())
|
|
|
+ .eq(WbsTreePrivate::getTreePId, wbsTreePrivate.getTreePId()));
|
|
|
+
|
|
|
+ //获取模板中当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
|
|
|
+ LambdaQueryWrapper<WbsTreePrivate> wrapperPrivate = Wrappers.lambdaQuery();
|
|
|
+ wrapperPrivate
|
|
|
+ .eq(WbsTreePrivate::getProjectId, wbsTreePrivateRoot.getProjectId())
|
|
|
+ .eq(WbsTreePrivate::getType, 2)
|
|
|
+ .eq(WbsTreePrivate::getIsDeleted, 0);
|
|
|
+ //判断如果为顶级顶级节点
|
|
|
+ if (wbsTreePrivate.getTreePId() != 0) {
|
|
|
+ wrapperPrivate.apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivateRoot.getPKeyId());
|
|
|
+ }
|
|
|
+ templateNodes = wbsTreePrivateMapper.selectList(wrapperPrivate);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtil.isEmpty(templateNodes)) {
|
|
|
+ throw new ServiceException("模板节点未找到");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //2、获取当前节点的子节点的数据------------------------------------------------------------------------------------------------------------------------
|
|
|
+ LambdaQueryWrapper<WbsTreePrivate> wrapperPrivate = Wrappers.lambdaQuery();
|
|
|
+ wrapperPrivate
|
|
|
+ .eq(WbsTreePrivate::getWbsId, wbsTreePrivate.getWbsId())
|
|
|
+ .eq(WbsTreePrivate::getIsDeleted, 0);
|
|
|
+ //判断如果为顶级顶级节点
|
|
|
+ if (wbsTreePrivate.getTreePId() != 0) {
|
|
|
+ wrapperPrivate.apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivate.getPKeyId());
|
|
|
+ }
|
|
|
+
|
|
|
+ //当前表节点下的节点信息
|
|
|
+ List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(wrapperPrivate);
|
|
|
+ //把选中节点也加进去 方便后面使用
|
|
|
+ wbsTreePrivates.add(wbsTreePrivate);
|
|
|
+
|
|
|
+ if (wbsTreePrivates.isEmpty()) {
|
|
|
+ throw new ServiceException("项目节点未找到");
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取id 和 tree_p_id 组成的集合
|
|
|
+ Set<Long> ids = wbsTreePrivates.stream().map(WbsTreePrivate::getTreePId).collect(Collectors.toSet());
|
|
|
+ //3.1筛选出需要新增的节点
|
|
|
+ List<WbsTreePrivate> addPrivateNodes = templateNodes.stream()
|
|
|
+ .filter(f -> !ids.contains(f.getTreePId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //新增数据二次筛选 只保留任务选中的表单 但可能新增的数据包含新节点
|
|
|
+ if (CollectionUtil.isNotEmpty(formList)) {
|
|
|
+ addPrivateNodes = addPrivateNodes.stream().filter(f -> f.getType() == 1 || formList.contains(f.getPKeyId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ //筛选出需要更新的节点 同时做数据隔离
|
|
|
+ List<WbsTreePrivate> editPrivateNodes = new ArrayList<>();
|
|
|
+ for (WbsTreePrivate templateNode : templateNodes) {
|
|
|
+ //数据修复-----------------------------------------------------------------------------------------------------------------------------------开始
|
|
|
+ if (!isPublic && templateNode.getType() == 2 && collect.contains(2)) {
|
|
|
+ boolean isUpdate = false;
|
|
|
+ if (templateNode.getExcelId() != null) {
|
|
|
+ ExcelTab excelTab = excelTabMapper.selectOne(Wrappers.<ExcelTab>lambdaQuery()
|
|
|
+ .select(ExcelTab::getTabId)
|
|
|
+ .eq(ExcelTab::getId, templateNode.getExcelId()));
|
|
|
+ if (excelTab == null) {
|
|
|
+ throw new ServerException(templateNode.getNodeName() + " excel未知");
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(templateNode.getInitTableName())) {
|
|
|
+ TableInfo tableInfo = tableInfoMapper.selectOne(Wrappers.<TableInfo>lambdaQuery()
|
|
|
+ .select(TableInfo::getId)
|
|
|
+ .eq(TableInfo::getId, excelTab.getTabId()));
|
|
|
+ if (tableInfo == null) {
|
|
|
+ throw new ServerException(templateNode.getNodeName() + " 实体表未知");
|
|
|
+ }
|
|
|
+ templateNode.setInitTableName(tableInfo.getTabEnName());
|
|
|
+ isUpdate = true;
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(templateNode.getHtmlUrl())) {
|
|
|
+ List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .eq(WbsTreePrivate::getExcelId, templateNode.getExcelId())
|
|
|
+ .eq(WbsTreePrivate::getInitTableName, templateNode.getInitTableName())
|
|
|
+ .eq(WbsTreePrivate::getProjectId, templateNode.getProjectId()));
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ templateNode.setHtmlUrl(list.get(0).getHtmlUrl());
|
|
|
+ isUpdate = true;
|
|
|
+ } else {
|
|
|
+ throw new ServerException(templateNode.getNodeName() + " html不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (StringUtil.isNotBlank(templateNode.getInitTableName())) {
|
|
|
+ TableInfo tableInfo = tableInfoMapper.selectOne(Wrappers.<TableInfo>lambdaQuery()
|
|
|
+ .select(TableInfo::getId)
|
|
|
+ .eq(TableInfo::getTabEnName, templateNode.getInitTableName()));
|
|
|
+ if (tableInfo == null) {
|
|
|
+ throw new ServerException(templateNode.getNodeName() + " 实体表未知");
|
|
|
+ }
|
|
|
+ if (templateNode.getExcelId() == null) {
|
|
|
+ ExcelTab excelTab = excelTabMapper.selectOne(Wrappers.<ExcelTab>lambdaQuery()
|
|
|
+ .select(ExcelTab::getId)
|
|
|
+ .eq(ExcelTab::getTabId, tableInfo.getId()));
|
|
|
+ if (excelTab == null) {
|
|
|
+ throw new ServerException(templateNode.getNodeName() + " excel未知");
|
|
|
+ }
|
|
|
+ templateNode.setExcelId(excelTab.getId());
|
|
|
+ isUpdate = true;
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(templateNode.getHtmlUrl())) {
|
|
|
+ List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .eq(WbsTreePrivate::getInitTableName, templateNode.getInitTableName())
|
|
|
+ .eq(WbsTreePrivate::getExcelId, templateNode.getExcelId())
|
|
|
+ .eq(WbsTreePrivate::getProjectId, templateNode.getProjectId()));
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ templateNode.setHtmlUrl(list.get(0).getHtmlUrl());
|
|
|
+ isUpdate = true;
|
|
|
+ } else {
|
|
|
+ throw new ServerException(templateNode.getNodeName() + " html不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (StringUtil.isNotBlank(templateNode.getHtmlUrl())) {
|
|
|
+ List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .eq(WbsTreePrivate::getInitTableName, templateNode.getInitTableName())
|
|
|
+ .eq(WbsTreePrivate::getExcelId, templateNode.getExcelId())
|
|
|
+ .eq(WbsTreePrivate::getProjectId, templateNode.getProjectId()));
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ templateNode.setExcelId(templateNode.getExcelId() == null ? list.get(0).getExcelId() : templateNode.getExcelId());
|
|
|
+ templateNode.setInitTableName(templateNode.getInitTableName() == null ? list.get(0).getInitTableName() : templateNode.getInitTableName());
|
|
|
+ isUpdate = true;
|
|
|
+ } else {
|
|
|
+ throw new ServerException(templateNode.getNodeName() + " html不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isUpdate) {
|
|
|
+ wbsTreePrivateMapper.update(templateNode, Wrappers.<WbsTreePrivate>lambdaUpdate()
|
|
|
+ .eq(WbsTreePrivate::getPKeyId, templateNode.getPKeyId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //数据修复-----------------------------------------------------------------------------------------------------------------------------------完成
|
|
|
+ //更新只跟新表单
|
|
|
+ for (WbsTreePrivate editPrivateNode : wbsTreePrivates) {
|
|
|
+ // 判断模板表与项目表 html是否一致
|
|
|
+ if (ObjectUtils.equals(templateNode.getTreePId(), editPrivateNode.getTreePId()) && templateNode.getType() == 2) {
|
|
|
+ //清表
|
|
|
+ if (collect.contains(2)) {
|
|
|
+ //绑定清表
|
|
|
+ editPrivateNode.setExcelId(templateNode.getExcelId());
|
|
|
+ //绑定实体表
|
|
|
+ editPrivateNode.setInitTableName(templateNode.getInitTableName());
|
|
|
+
|
|
|
+ if (StringUtil.isBlank(templateNode.getHtmlUrl())) {
|
|
|
+ throw new ServiceException(templateNode.getNodeName() + "HTML文件不存在");
|
|
|
+ }
|
|
|
+ //封装Html路径 根据模板html copy一份到自己项目节点上
|
|
|
+ String[] split = templateNode.getHtmlUrl().split("/");
|
|
|
+ String htmlUrl = file_path + "privateUrlCopy/" + projectInfo.getId() + "/" + split[split.length - 1];
|
|
|
+ File file_in = ResourceUtil.getFile(templateNode.getHtmlUrl());
|
|
|
+ if (!file_in.exists() || file_in.length() == 0) {
|
|
|
+ //如果本地服务器上没有
|
|
|
+ throw new ServiceException(templateNode.getNodeName() + "HTML文件不存在");
|
|
|
+ }
|
|
|
+ File file_out = ResourceUtil.getFile(htmlUrl);
|
|
|
+ //查询父级文件夹
|
|
|
+ File fileParent = file_out.getParentFile();
|
|
|
+ if (!fileParent.exists()) {
|
|
|
+ fileParent.mkdirs();
|
|
|
+ }
|
|
|
+ file_out.createNewFile();
|
|
|
+ FileUtil.copy(file_in, file_out);
|
|
|
+ editPrivateNode.setHtmlUrl(htmlUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (templateNode.getExcelId() != null) {
|
|
|
+ editPrivateNode.setIsLinkTable(2);
|
|
|
+ }
|
|
|
+
|
|
|
+ //元素 是与表绑定的
|
|
|
+ if (collect.contains(3)) {
|
|
|
+ editPrivateNode.setInitTableName(templateNode.getInitTableName());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //排序
|
|
|
+ if (collect.contains(7)) {
|
|
|
+ editPrivateNode.setSort(templateNode.getSort());
|
|
|
+ }
|
|
|
+
|
|
|
+ //手动选中的表单 进行筛选
|
|
|
+ if (CollectionUtil.isNotEmpty(formList)) {
|
|
|
+ if (formList.contains(templateNode.getPKeyId())) {
|
|
|
+ if (collect.contains(2) || collect.contains(3) || collect.contains(4) || collect.contains(5) || collect.contains(6) || collect.contains(7)) {
|
|
|
+ editPrivateNodes.add(editPrivateNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (collect.contains(2) || collect.contains(3) || collect.contains(4) || collect.contains(5) || collect.contains(6) || collect.contains(7)) {
|
|
|
+ editPrivateNodes.add(editPrivateNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //转List做排序
|
|
|
+ List<Integer> arrayList = new ArrayList<>(collect);
|
|
|
+ Collections.sort(arrayList);
|
|
|
+ for (Integer i : arrayList) {
|
|
|
+ switch (i) {
|
|
|
+ //添加表单
|
|
|
+ case 1:
|
|
|
+ insertPrivateForm(wbsTreeSynchronousRecord, wbsTreePrivates, addPrivateNodes);
|
|
|
+ break;
|
|
|
+ //清表
|
|
|
+ case 2:
|
|
|
+ //元素
|
|
|
+ case 3:
|
|
|
+ //公式配置
|
|
|
+ case 5:
|
|
|
+ //排序
|
|
|
+ case 7:
|
|
|
+ //元素配置
|
|
|
+ editData.addAll(editPrivateNodes);
|
|
|
+ break;
|
|
|
+ //电签 如果有数据 与节点绑定
|
|
|
+ case 4:
|
|
|
+ //默认值 如果有数据 与节点绑定
|
|
|
+ case 6:
|
|
|
+ //现在电签使用的是模糊匹配 如果电签匹配方式改为精确匹配 则需要使用该功能
|
|
|
+// updateEViSa(collect, wbsTreeSynchronousRecord.getTemplateId(), projectInfo.getId(), templateNodes, editPrivateNodes);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //更新数据的同时统计最小节点数量
|
|
|
+ Map<Long, List<WbsTreePrivate>> collect1 = editData.stream().collect(Collectors.groupingBy(WbsTreePrivate::getPId));
|
|
|
+ Set<Long> pIds = collect1.keySet();
|
|
|
+ Integer nodeNumEnd = 0;
|
|
|
+ for (Long pId : pIds) {
|
|
|
+ nodeNumEnd++;
|
|
|
+ //更新最新节点
|
|
|
+ wbsSynchronousEViSaService.updatePrivate(wbsTreeSynchronousRecord.getCreateUserId(), collect1.get(pId));
|
|
|
+
|
|
|
+ synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
|
|
|
+ .set(WbsTreeSynchronousRecord::getNodeNumEnd, nodeNumEnd)
|
|
|
+ .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
|
|
|
+ .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
|
|
|
+ }
|
|
|
+ synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
|
|
|
+ .set(WbsTreeSynchronousRecord::getStatus, 2)
|
|
|
+ .set(WbsTreeSynchronousRecord::getErrorMsg, null)
|
|
|
+ .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
|
|
|
+ .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同段同步 获取源节点数据和当前节点数据
|
|
|
+ */
|
|
|
+ public void insertContractNode(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) {
|
|
|
+ //同步类型 1.新增表单,2.新增节点,3.删除节点,4.删除表单,5.修改节点,6.修改表单,7.修改节点表单
|
|
|
+ String type = wbsTreeSynchronousRecord.getType();
|
|
|
+ Set<Integer> collect = Arrays.stream(type.split(","))
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 选中节点
|
|
|
+ String nodeId = wbsTreeSynchronousRecord.getNodeId();
|
|
|
+ if (StringUtil.isBlank(nodeId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String[] nodeIds = nodeId.split(",");
|
|
|
+ //选中表单
|
|
|
+ String formIds = wbsTreeSynchronousRecord.getFormIds();
|
|
|
+ Set<Long> formList = StringUtil.isNotBlank(formIds)
|
|
|
+ ? Arrays.stream(formIds.split(",")).map(Long::parseLong).collect(Collectors.toSet())
|
|
|
+ : Collections.emptySet();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同段选择的类型
|
|
|
+ * 质检系统 101.未填报 102.已填报-未上报 104.待审批 105.已审批
|
|
|
+ * 试验系统 103.未上报 104.待审批 105.已审批
|
|
|
+ * 计量系统 103.未上报 104.待审批 105.已审批
|
|
|
+ */
|
|
|
+ String contractRange = wbsTreeSynchronousRecord.getContractRange();
|
|
|
+ Set<Integer> contractRanges = StringUtil.isNotBlank(contractRange)
|
|
|
+ ? Arrays.stream(contractRange.split(",")).map(Integer::parseInt).collect(Collectors.toSet())
|
|
|
+ : Collections.emptySet();
|
|
|
+
|
|
|
+
|
|
|
+ //获取当前项目所有合同---------------------------------------------------------------------------------------------------
|
|
|
+ List<ContractInfo> contractInfos = contractInfoMapper.selectContractIdByProjectId(String.valueOf(wbsTreeSynchronousRecord.getProjectId()));
|
|
|
+
|
|
|
+ List<WbsTreeContract> editData = new ArrayList<>();
|
|
|
+ for (String primaryKeyId : nodeIds) {
|
|
|
+
|
|
|
+ //获取当前节点对应节点信息
|
|
|
+ WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .eq(WbsTreePrivate::getPKeyId, primaryKeyId));
|
|
|
+ //如果wbs类型为空 则放弃该同步
|
|
|
+ if (StringUtil.isBlank(wbsTreePrivate.getWbsType())) {
|
|
|
+ throw new ServiceException("系统类型未知");
|
|
|
+ }
|
|
|
+
|
|
|
+ //当前项目选中的节点 获取当前节点的所有子节点数据
|
|
|
+ //1、获取当前节点的子节点 表单的数据------------------------------------------------------------------------------------------------------------------------
|
|
|
+ LambdaQueryWrapper<WbsTreePrivate> wrapperPrivate = Wrappers.lambdaQuery();
|
|
|
+ wrapperPrivate
|
|
|
+ .eq(WbsTreePrivate::getWbsId, wbsTreePrivate.getWbsId())
|
|
|
+ .eq(WbsTreePrivate::getType, 2)
|
|
|
+ .eq(WbsTreePrivate::getIsDeleted, 0)
|
|
|
+ .apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreePrivate.getPKeyId());
|
|
|
+ //当前项目的子节点数据
|
|
|
+ List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(wrapperPrivate);
|
|
|
+ wbsTreePrivates.add(wbsTreePrivate);
|
|
|
+
|
|
|
+ if (wbsTreePrivates.isEmpty()) {
|
|
|
+ throw new ServiceException("无法找到模板对应节点,请检查模板节点");
|
|
|
+ }
|
|
|
+
|
|
|
+ //合同同步
|
|
|
+ for (ContractInfo contractInfo : contractInfos) {
|
|
|
+ //获取合同下当前节点的数据
|
|
|
+ List<WbsTreeContract> startContacts = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
|
|
|
+ .eq(WbsTreeContract::getContractId, contractInfo.getId())
|
|
|
+ .eq(WbsTreeContract::getIsTypePrivatePid, primaryKeyId));
|
|
|
+ //如果没有查询到,表示该合同下不存在该节点
|
|
|
+ if (CollectionUtil.isEmpty(startContacts)) {
|
|
|
+ //不能抛异常 不然就会中止程序 开发阶段先抛异常,后续统一处理
|
|
|
+ throw new ServiceException("当前节点不存在");
|
|
|
+ }
|
|
|
+ for (WbsTreeContract wbsTreeContract : startContacts) {
|
|
|
+ //获取合同 当前节点的所有子节点数据
|
|
|
+ LambdaQueryWrapper<WbsTreeContract> wrapperContract = Wrappers.lambdaQuery();
|
|
|
+ wrapperContract
|
|
|
+ .eq(WbsTreeContract::getContractId, contractInfo.getId())
|
|
|
+ .eq(WbsTreeContract::getIsDeleted, 0)
|
|
|
+ .apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreeContract.getPKeyId());
|
|
|
+ wrapperContract.apply("FIND_IN_SET({0},ancestors_p_id)", wbsTreeContract.getPKeyId());
|
|
|
+
|
|
|
+ //当前合同的子节点数据
|
|
|
+ List<WbsTreeContract> wbsTreeContracts = wbsTreeContractMapper.selectList(wrapperContract);
|
|
|
+ wbsTreeContracts.add(wbsTreeContract);
|
|
|
+
|
|
|
+ HashMap<Long, Integer> informationQueryMap = new HashMap<>();
|
|
|
+ //查询质检合同节点填表信息
|
|
|
+ String sql = "SELECT b.wbs_id, b.STATUS FROM" +
|
|
|
+ "( SELECT p_key_id FROM m_wbs_tree_contract WHERE is_deleted = 0 AND contract_id = " + contractInfo.getId() + " AND FIND_IN_SET( " + wbsTreeContract.getPKeyId() + ", ancestors_p_id ) ) a" +
|
|
|
+ " INNER JOIN ( SELECT c.wbs_id, c.STATUS FROM u_information_query c" +
|
|
|
+ " JOIN ( SELECT wbs_id, MAX( update_time ) AS max_update_time FROM u_information_query WHERE contract_id = " + contractInfo.getId() + " GROUP BY wbs_id ) subquery ON c.wbs_id = subquery.wbs_id " +
|
|
|
+ " AND c.update_time = subquery.max_update_time WHERE c.contract_id = " + contractInfo.getId() + " and c.is_deleted = 0 ) b ON a.p_key_id = b.wbs_id";
|
|
|
+
|
|
|
+ List<InformationQuery> informationQueries = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(InformationQuery.class));
|
|
|
+ //质检节点填报信息
|
|
|
+
|
|
|
+ for (InformationQuery informationQuery : informationQueries) {
|
|
|
+ informationQueryMap.put(informationQuery.getWbsId(), informationQuery.getStatus());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //合同段节点对应的项目id
|
|
|
+ List<Long> typePrivateIds = wbsTreeContracts.stream().map(WbsTreeContract::getIsTypePrivatePid).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //需要新增的表单
|
|
|
+ List<WbsTreePrivate> addPrivateNodes = wbsTreePrivates.stream().filter(f -> !typePrivateIds.contains(f.getPKeyId())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //如果没有选中 则默认同步所有
|
|
|
+ if (CollectionUtil.isNotEmpty(formList)) {
|
|
|
+ //二次筛选 只保留任务选中的表单 但可能新增的数据包含新节点
|
|
|
+ addPrivateNodes = addPrivateNodes.stream().filter(f -> formList.contains(f.getPKeyId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ //筛选出需要更新的节点 同时做数据隔离
|
|
|
+ List<WbsTreeContract> editContractNodes = new ArrayList<>();
|
|
|
+ for (WbsTreePrivate templateNode : wbsTreePrivates) {
|
|
|
+ //更新只跟新表单
|
|
|
+ for (WbsTreeContract editContractNode : wbsTreeContracts) {
|
|
|
+
|
|
|
+ // 判断模板表与项目表 html是否一致
|
|
|
+ if (ObjectUtils.equals(templateNode.getPKeyId(), editContractNode.getIsTypePrivatePid())) {
|
|
|
+ if (templateNode.getType() == 2) {
|
|
|
+ //同步范围 当前节点是否允许修改
|
|
|
+ Boolean isSync = false;
|
|
|
+ if (CollectionUtil.isNotEmpty(contractRanges)) {
|
|
|
+ switch (Integer.valueOf(wbsTreePrivate.getWbsType())) {
|
|
|
+ //质检
|
|
|
+ case 1:
|
|
|
+ Integer submit = informationQueryMap.get(editContractNode.getPKeyId());
|
|
|
+
|
|
|
+ if (submit == null && contractRanges.contains(WbsSyncTypeEnum.NOT_FILLED_IN.code)) {
|
|
|
+ //未审批 101
|
|
|
+ isSync = true;
|
|
|
+ } else {
|
|
|
+ if (submit == null) {
|
|
|
+ throw new ServiceException(wbsTreeContract.getNodeName() + "--下表单未查到填报信息");
|
|
|
+ }
|
|
|
+ if (submit == 0 && contractRanges.contains(WbsSyncTypeEnum.ALREADY_FILLED_IN_NOT_REPORTED.code)) {
|
|
|
+ //已填报-未上报 102
|
|
|
+ isSync = true;
|
|
|
+ } else if (submit == 1 && contractRanges.contains(WbsSyncTypeEnum.PENDING_APPROVAL.code)) {
|
|
|
+ //待审批 104
|
|
|
+ isSync = true;
|
|
|
+ } else if (submit == 2 && contractRanges.contains(WbsSyncTypeEnum.APPROVED.code)) {
|
|
|
+ //已审批 105
|
|
|
+ isSync = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ //试验
|
|
|
+ case 2:
|
|
|
+ break;
|
|
|
+ //计量
|
|
|
+ case 3:
|
|
|
+ break;
|
|
|
+ //日志
|
|
|
+ case 4:
|
|
|
+ break;
|
|
|
+ //征地拆迁
|
|
|
+ case 5:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isSync = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //清表 公式 元素
|
|
|
+ if (collect.contains(2) || collect.contains(3) || collect.contains(5)) {
|
|
|
+ editContractNode.setExcelId(templateNode.getExcelId());
|
|
|
+ editContractNode.setInitTableName(templateNode.getInitTableName());
|
|
|
+ editContractNode.setHtmlUrl(templateNode.getHtmlUrl());
|
|
|
+ if (templateNode.getExcelId() != null) {
|
|
|
+ editContractNode.setIsLinkTable(2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //排序
|
|
|
+ if (collect.contains(7)) {
|
|
|
+ editContractNode.setSort(templateNode.getSort());
|
|
|
+ }
|
|
|
+
|
|
|
+ //手动选中的表单 进行筛选
|
|
|
+ if (CollectionUtil.isNotEmpty(formList)) {
|
|
|
+ if (formList.contains(templateNode.getPKeyId())) {
|
|
|
+ if (collect.contains(2) || collect.contains(3) || collect.contains(4) || collect.contains(5) || collect.contains(6) || collect.contains(7)) {
|
|
|
+ if (isSync) {
|
|
|
+ editContractNodes.add(editContractNode);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (collect.contains(2) || collect.contains(3) || collect.contains(4) || collect.contains(5) || collect.contains(6) || collect.contains(7)) {
|
|
|
+ if (isSync) {
|
|
|
+ editContractNodes.add(editContractNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //找到了某个选中节点下与项目节点想同的节点了 提前结束循环,节省资源
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //修改数据二次筛选 只保留任务选中的表单 但可能新增的数据包含新节点
|
|
|
+ if (CollectionUtil.isNotEmpty(formList)) {
|
|
|
+ editContractNodes = editContractNodes.stream().filter(f -> formList.contains(f.getPKeyId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ //合同段新增节点
|
|
|
+ List<WbsTreeContract> addContractNode = null;
|
|
|
+ if (addPrivateNodes != null) {
|
|
|
+ addContractNode = BeanUtil.copyProperties(addPrivateNodes, WbsTreeContract.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ //转类型排序
|
|
|
+ List<Integer> integers = new ArrayList<>(collect);
|
|
|
+ Collections.sort(integers);
|
|
|
+ for (Integer i : integers) {
|
|
|
+ switch (i) {
|
|
|
+ //添加表单
|
|
|
+ case 1:
|
|
|
+ insertContractForm(wbsTreeSynchronousRecord, contractInfo, wbsTreeContracts, addContractNode);
|
|
|
+ //如果同时选择新增表单和其他的同步类型 在操作其他类型的时候需要添加新的表单
|
|
|
+// if (CollectionUtil.isNotEmpty(addContractNode)) {
|
|
|
+// editContractNodes.addAll(addContractNode.stream().filter(f -> f.getType() == 2).collect(Collectors.toList()));
|
|
|
+// }
|
|
|
+ break;
|
|
|
+ //清表配置
|
|
|
+ case 2:
|
|
|
+ //元素配置
|
|
|
+ case 3:
|
|
|
+ //公式配置
|
|
|
+ case 5:
|
|
|
+ //排序
|
|
|
+ case 7:
|
|
|
+ editData.addAll(editContractNodes);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //合同段同步同时记录数量
|
|
|
+ Map<Long, List<WbsTreeContract>> collect1 = editData.stream().collect(Collectors.groupingBy(WbsTreeContract::getPId));
|
|
|
+ Set<Long> pIds = collect1.keySet();
|
|
|
+ Integer nodeNumEnd = 0;
|
|
|
+
|
|
|
+ for (Long pId : pIds) {
|
|
|
+ nodeNumEnd++;
|
|
|
+ wbsSynchronousEViSaService.updateContract(wbsTreeSynchronousRecord.getCreateUserId(), collect1.get(pId));
|
|
|
+ synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
|
|
|
+ .set(WbsTreeSynchronousRecord::getNodeNumEnd, nodeNumEnd)
|
|
|
+ .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
|
|
|
+ .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
|
|
|
+ .set(WbsTreeSynchronousRecord::getStatus, 2)
|
|
|
+ .set(WbsTreeSynchronousRecord::getErrorMsg, null)
|
|
|
+ .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
|
|
|
+ .eq(WbsTreeSynchronousRecord::getId, wbsTreeSynchronousRecord.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目
|
|
|
+ * 类型 1 添加表单
|
|
|
+ *
|
|
|
+ * @param wbsTreeSynchronousRecord 同步任务
|
|
|
+ * @param wbsTreePrivates 当前项目对应节点的子节点
|
|
|
+ * @param addPrivateNodes 需要新增的节点
|
|
|
+ */
|
|
|
+ public void insertPrivateForm(WbsTreeSynchronousRecord wbsTreeSynchronousRecord, List<WbsTreePrivate> wbsTreePrivates, List<WbsTreePrivate> addPrivateNodes) {
|
|
|
+ List<WbsTreePrivate> addData = new ArrayList<>();
|
|
|
+
|
|
|
+ //------------------------------------------------新增-------------------------------------------------------------------------
|
|
|
+ if (CollectionUtil.isNotEmpty(addPrivateNodes)) {
|
|
|
+ //先给每个新增节点赋唯一id,项目id,父级id
|
|
|
+ addPrivateNodes.forEach(f -> f.setPKeyId(SnowFlakeUtil.getId()));
|
|
|
+
|
|
|
+ //给每一个节点的父级id
|
|
|
+ for (WbsTreePrivate addPrivateNode : addPrivateNodes) {
|
|
|
+ if (addPrivateNode.getParentId() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询出当前模板节点的父节点 去获取对应项目节点 如果父节点为0就跳过
|
|
|
+ List<WbsTreePrivate> addPrivateParentNodes = wbsTreePrivates.stream().filter(f -> f.getTreePId().equals(addPrivateNode.getParentId())).collect(Collectors.toList());
|
|
|
+ //如果没有数据 就表示这条数据的父节点也时新增节点 就需要从新增节点集合中找父级节点
|
|
|
+ if (addPrivateParentNodes.isEmpty()) {
|
|
|
+ addPrivateParentNodes = addPrivateNodes.stream().filter(f -> f.getTreePId().equals(addPrivateNode.getParentId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ //如果现在还找不到当前节点的父节点就表示数据有问题
|
|
|
+ if (addPrivateParentNodes.isEmpty()) {
|
|
|
+ throw new ServiceException(addPrivateNode.getNodeName() + "-找不到父节点");
|
|
|
+ }
|
|
|
+ //当前新增节点的父节点
|
|
|
+ WbsTreePrivate parent = addPrivateParentNodes.get(0);
|
|
|
+
|
|
|
+ addPrivateNode.setPId(parent.getPKeyId());
|
|
|
+ addPrivateNode.setWbsId(parent.getWbsId());
|
|
|
+ addPrivateNode.setWbsType(parent.getWbsType());
|
|
|
+ addPrivateNode.setIsAddConceal(0);
|
|
|
+ addPrivateNode.setProjectId(wbsTreePrivates.get(0).getProjectId());
|
|
|
+ //TODO 后续如果把p_key_id改成了id做 唯一id
|
|
|
+ addPrivateNode.setTreePId(addPrivateNode.getTreePId());
|
|
|
+ //后续如果使用id做当前表主键 则先在赋值treePid之后再去赋值id addPrivateNode.setId(SnowFlakeUtil.getId());
|
|
|
+ //更新创建时间
|
|
|
+ addPrivateNode.setCreateTime(DateTime.now());
|
|
|
+ addPrivateNode.setCreateUser(wbsTreeSynchronousRecord.getCreateUserId());
|
|
|
+ addData.add(addPrivateNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //设置html_url----------------------------------------------------------------------------------------------------------
|
|
|
+ //如果有新增的数据 旧设置html_url
|
|
|
+ if (CollectionUtil.isNotEmpty(addData)) {
|
|
|
+ try {
|
|
|
+ String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
|
|
|
+ Set<String> urls = new HashSet<>();
|
|
|
+ for (WbsTreePrivate tree : addData) {
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(tree.getHtmlUrl())) {
|
|
|
+ String[] split = tree.getHtmlUrl().split("/");
|
|
|
+ String htmlUrl = file_path + "privateUrlCopy/" + wbsTreePrivates.get(0).getProjectId() + "/" + split[split.length - 1];
|
|
|
+ if (!urls.contains(tree.getHtmlUrl())) {
|
|
|
+ urls.add(tree.getHtmlUrl());
|
|
|
+ File file_in = ResourceUtil.getFile(tree.getHtmlUrl());
|
|
|
+ if (!file_in.exists() || file_in.length() == 0) {
|
|
|
+ //如果本地服务器上没有
|
|
|
+ throw new ServiceException(tree.getNodeName() + "HTML文件不存在");
|
|
|
+ }
|
|
|
+ File file_out = ResourceUtil.getFile(htmlUrl);
|
|
|
+ //查询父级文件夹
|
|
|
+ File fileParent = file_out.getParentFile();
|
|
|
+ if (!fileParent.exists()) {
|
|
|
+ fileParent.mkdirs();
|
|
|
+ }
|
|
|
+ file_out.createNewFile();
|
|
|
+ FileUtil.copy(file_in, file_out);
|
|
|
+ }
|
|
|
+ tree.setHtmlUrl(htmlUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ throw new ServiceException(e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException("重置表单路径错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询出当前项目所有节点---------------------------------------------------------------------------------------------------
|
|
|
+ List<WbsTreePrivate> addList = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .select(WbsTreePrivate::getPKeyId, WbsTreePrivate::getPId)
|
|
|
+ .eq(WbsTreePrivate::getIsDeleted, 0)
|
|
|
+ .eq(WbsTreePrivate::getProjectId, addData.get(0).getProjectId()));
|
|
|
+
|
|
|
+ addList.addAll(addData);
|
|
|
+ //组合祖级路径 根据当前选中节点为开始
|
|
|
+ Map<Long, WbsTreePrivate> collect = addList.stream().collect(Collectors.toMap(WbsTreePrivate::getPKeyId, Function.identity()));
|
|
|
+
|
|
|
+ addData.forEach(node -> {
|
|
|
+ String correctAncestors = createAncestorsPId(node, collect);
|
|
|
+ node.setAncestorsPId(correctAncestors);
|
|
|
+ });
|
|
|
+
|
|
|
+ //新增-----------------------------------------------------------------------------------------------------------------
|
|
|
+ List<List<WbsTreePrivate>> partition = Lists.partition(addData, 1000);
|
|
|
+ Integer count = 0;
|
|
|
+ for (List<WbsTreePrivate> data : partition) {
|
|
|
+ //单个批次一个事务,只会回滚当前批次数据
|
|
|
+ Integer i = wbsTreePrivateMapper.insertBatchSomeColumn(data);
|
|
|
+ //如果失败 -- - - - - 继续执行 或者把当前节点的p_key_id 记录到某个地方 方便后续处理
|
|
|
+ if (i == 0) {
|
|
|
+ List<Long> collect1 = addData.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
|
|
|
+ //这里可以保存到数据库指定错误日志表
|
|
|
+ throw new ServiceException("重置表单路径错误:" + StringUtil.join(collect1, ","));
|
|
|
+ }
|
|
|
+
|
|
|
+ count += i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同段添加表单
|
|
|
+ * 合同段添加表单
|
|
|
+ *
|
|
|
+ * @param wbsTreeSynchronousRecord 同步任务
|
|
|
+ * @param contractInfo 合同段信息
|
|
|
+ * @param wbsTreeContracts 当前合同节点数据
|
|
|
+ * @param addContractNodes 新增节点数据
|
|
|
+ */
|
|
|
+ public void insertContractForm(WbsTreeSynchronousRecord wbsTreeSynchronousRecord, ContractInfo contractInfo, List<WbsTreeContract> wbsTreeContracts, List<WbsTreeContract> addContractNodes) {
|
|
|
+ List<WbsTreeContract> addData = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(addContractNodes)) {
|
|
|
+
|
|
|
+ //选给新增的节点赋值
|
|
|
+ addContractNodes.forEach(f -> {
|
|
|
+ f.setIsTypePrivatePid(f.getPKeyId());
|
|
|
+ f.setPKeyId(SnowFlakeUtil.getId());
|
|
|
+ });
|
|
|
+
|
|
|
+ for (WbsTreeContract addContractNode : addContractNodes) {
|
|
|
+ if (addContractNode.getParentId() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询出当前模板节点的父节点 去获取对应项目节点 如果父节点为0就跳过
|
|
|
+ List<WbsTreeContract> addContractParentNodes = wbsTreeContracts.stream().filter(f -> Objects.equals(f.getTreePId(), addContractNode.getParentId())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //如果没有数据 就表示这条数据的父节点也时新增节点 就需要从新增节点集合中找父级节点
|
|
|
+ if (addContractParentNodes.isEmpty()) {
|
|
|
+ addContractParentNodes = addContractNodes.stream().filter(f -> f.getTreePId().equals(addContractNode.getParentId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ //如果现在还找不到当前节点的父节点就表示数据有问题
|
|
|
+ if (addContractParentNodes.isEmpty()) {
|
|
|
+ //TODO
|
|
|
+ throw new ServiceException(addContractNode.getNodeName() + "-找不到父节点");
|
|
|
+ }
|
|
|
+ //当前新增节点的父节点
|
|
|
+ WbsTreeContract parent = addContractParentNodes.get(0);
|
|
|
+
|
|
|
+ addContractNode.setIsBussShow(1);
|
|
|
+ addContractNode.setIsDeleted(0);
|
|
|
+ addContractNode.setStatus(1);
|
|
|
+ addContractNode.setParentId(parent.getId());
|
|
|
+ addContractNode.setAncestors(parent.getAncestors() + "," + parent.getId());
|
|
|
+ //TODO
|
|
|
+ addContractNode.setTreePId(addContractNode.getTreePId());
|
|
|
+ //TODO
|
|
|
+ addContractNode.setPId(parent.getPKeyId());
|
|
|
+ //TODO
|
|
|
+ addContractNode.setContractId(parent.getContractId());
|
|
|
+ addContractNode.setContractId(String.valueOf(contractInfo.getId()));
|
|
|
+ //更新创建时间
|
|
|
+ addContractNode.setCreateTime(DateTime.now());
|
|
|
+ addContractNode.setCreateUser(wbsTreeSynchronousRecord.getCreateUserId());
|
|
|
+ }
|
|
|
+ addData.addAll(addContractNodes);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //查询出当前项目所有节点---------------------------------------------------------------------------------------------------
|
|
|
+ List<WbsTreeContract> addList = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
|
|
|
+ .select(WbsTreeContract::getPKeyId, WbsTreeContract::getPId)
|
|
|
+ .eq(WbsTreeContract::getIsDeleted, 0)
|
|
|
+ .eq(WbsTreeContract::getContractId, contractInfo.getId()));
|
|
|
+
|
|
|
+ addList.addAll(addData);
|
|
|
+
|
|
|
+
|
|
|
+ //组合祖级路径 根据当前选中节点为开始
|
|
|
+ Map<Long, WbsTreeContract> collect = addList.stream().collect(Collectors.toMap(WbsTreeContract::getPKeyId, Function.identity()));
|
|
|
+
|
|
|
+ addData.forEach(node -> {
|
|
|
+ //通过转换为WbsTreePrivate的方式 去获取祖级节点
|
|
|
+ String correctAncestors = createAncestorsPId(node, collect);
|
|
|
+ node.setAncestorsPId(correctAncestors);
|
|
|
+ });
|
|
|
+
|
|
|
+ //新增-----------------------------------------------------------------------------------------------------------------
|
|
|
+ List<List<WbsTreeContract>> partition = Lists.partition(addData, 1000);
|
|
|
+ for (List<WbsTreeContract> data : partition) {
|
|
|
+ //单个批次一个事务,只会回滚当前批次数据
|
|
|
+ Integer i = wbsTreeContractMapper.insertBatchSomeColumn(data);
|
|
|
+ //如果失败 -- - - - - 继续执行 或者把当前节点的p_key_id 记录到某个地方 方便后续处理
|
|
|
+ if (i == 0) {
|
|
|
+ List<Long> collect1 = addData.stream().map(WbsTreeContract::getPKeyId).collect(Collectors.toList());
|
|
|
+ //这里可以保存到数据库指定错误日志表
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目同步电签
|
|
|
+ *
|
|
|
+ * @param collect 需要修改的节点
|
|
|
+ * @param templateId 同步源项目ID
|
|
|
+ * @param projectId 当前项目ID
|
|
|
+ * @param editPrivateNodes 模板对应的节点
|
|
|
+ * @param editPrivateNodes 需要修改的节点
|
|
|
+ */
|
|
|
+ private void updateEViSa(Set<Integer> collect, Long templateId, Long projectId, List<WbsTreePrivate> treePrivates, List<WbsTreePrivate> editPrivateNodes) {
|
|
|
+
|
|
|
+ //判断 如果模板项目为公共项目 则无法同步电签
|
|
|
+ ProjectInfo projectInfo = projectInfoMapper.selectById(projectId);
|
|
|
+
|
|
|
+ if (projectInfo != null && ("private").equals(projectInfo.getReferenceWbsTemplateType()) && projectInfo.getReferenceWbsTemplateId() != null) {
|
|
|
+
|
|
|
+
|
|
|
+ //封装 源Pkeyid 修改pKeyId
|
|
|
+ Map<Long, Long> tempMap = new HashMap<>();
|
|
|
+
|
|
|
+ //模板的主键ids
|
|
|
+ List<Long> tempPKeyIds = new ArrayList<>();
|
|
|
+ List<Long> editPKeyIds = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ for (WbsTreePrivate tempPrivate : treePrivates) {
|
|
|
+ for (WbsTreePrivate editPrivate : editPrivateNodes) {
|
|
|
+ if (Objects.equals(tempPrivate.getTreePId(), editPrivate.getTreePId())) {
|
|
|
+ //封装 源Pkeyid 修改pKeyId
|
|
|
+ tempMap.put(tempPrivate.getPKeyId(), editPrivate.getPKeyId());
|
|
|
+ //记录
|
|
|
+ tempPKeyIds.add(tempPrivate.getPKeyId());
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //源项目电签和默认值信息
|
|
|
+ List<TextdictInfo> tempTextDictInfo = textdictInfoMapper.selectList(Wrappers.<TextdictInfo>lambdaQuery()
|
|
|
+ .eq(TextdictInfo::getProjectId, templateId)
|
|
|
+ .eq(TextdictInfo::getIsDeleted, 0)
|
|
|
+ .in(TextdictInfo::getTabId, tempPKeyIds)
|
|
|
+ .in(TextdictInfo::getType, 2, 4, 6));
|
|
|
+ if (CollectionUtil.isEmpty(tempTextDictInfo)) {
|
|
|
+ throw new ServiceException("源数据无电签及默认值配置");
|
|
|
+ }
|
|
|
+ Map<Integer, List<TextdictInfo>> tempTextDictInfoMap = tempTextDictInfo.stream().collect(Collectors.groupingBy(TextdictInfo::getType));
|
|
|
+
|
|
|
+
|
|
|
+ List<TextdictInfo> tempViSa = new ArrayList<>();
|
|
|
+ //电签
|
|
|
+ if (collect.contains(3)) {
|
|
|
+ //个人电签
|
|
|
+ List<TextdictInfo> tempMyViSa = tempTextDictInfoMap.get(2);
|
|
|
+ if (CollectionUtil.isNotEmpty(tempMyViSa)) {
|
|
|
+ tempViSa.addAll(tempMyViSa);
|
|
|
+
|
|
|
+ }
|
|
|
+ //企业电签
|
|
|
+ List<TextdictInfo> tempEnterViSa = tempTextDictInfoMap.get(6);
|
|
|
+ if (CollectionUtil.isNotEmpty(tempEnterViSa)) {
|
|
|
+ tempViSa.addAll(tempEnterViSa);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //默认值
|
|
|
+ if (collect.contains(5)) {
|
|
|
+ List<TextdictInfo> tempDefault = tempTextDictInfoMap.get(4);
|
|
|
+ if (CollectionUtil.isNotEmpty(tempDefault)) {
|
|
|
+ tempViSa.addAll(tempDefault);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<TextdictInfo> addData = new ArrayList<>();
|
|
|
+ //新增电签
|
|
|
+ if (CollectionUtil.isNotEmpty(tempViSa)) {
|
|
|
+ for (TextdictInfo textdictInfo : tempViSa) {
|
|
|
+ textdictInfo.setId(SnowFlakeUtil.getId());
|
|
|
+ textdictInfo.setProjectId(String.valueOf(projectId));
|
|
|
+
|
|
|
+ //根据源id找对应的修改pKid
|
|
|
+ Long tabId = Long.valueOf(textdictInfo.getTabId());
|
|
|
+ Long editId = tempMap.get(tabId);
|
|
|
+ if (editId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ textdictInfo.setTabId(String.valueOf(editId));
|
|
|
+
|
|
|
+ addData.add(textdictInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(addData)) {
|
|
|
+ //删除 需要新增的节点的电签和默认值
|
|
|
+ List<Long> editPrivateIds = editPrivateNodes.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
|
|
|
+ //调用其他类使事务生效
|
|
|
+ wbsSynchronousEViSaService.updateTextDictInfo(projectId, editPrivateIds, addData);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("模板为公共项目,无法同步电签");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 20250414-lhb-新增
|
|
|
+ * 创建祖级路径
|
|
|
+ * <p>
|
|
|
+ * 该方法用于构建给定节点的祖先路径标识符(PId)字符串
|
|
|
+ * 它通过追溯节点的父节点,直到达到根节点或满足特定条件为止
|
|
|
+ *
|
|
|
+ * @param node WbsTreeContract类型的节点,表示需要构建路径的起始节点
|
|
|
+ * @param nodeMap 一个映射,其键为节点ID,值为WbsTreeContract类型的节点对象,用于快速查找节点
|
|
|
+ * @return 返回一个字符串,表示构建的祖先路径标识符序列,以逗号分隔
|
|
|
+ */
|
|
|
+ private String createAncestorsPId(WbsTreePrivate node, Map<Long, WbsTreePrivate> nodeMap) {
|
|
|
+ // 初始化路径列表,用于存储祖先节点的ID
|
|
|
+ List<Long> path = new ArrayList<>();
|
|
|
+ // 从给定的节点开始
|
|
|
+ WbsTreePrivate current = node;
|
|
|
+ // 初始化访问集合,用于检测循环引用
|
|
|
+ Set<Long> visited = new HashSet<>();
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ // 检查当前节点是否为根节点或无效节点
|
|
|
+ if (current == null || current.getPId() == null ||
|
|
|
+ current.getPId() == 0 || current.getPId().equals(current.getPKeyId())) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检测循环引用
|
|
|
+ if (visited.contains(current.getPId())) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // 将当前节点的ID添加到已访问集合中
|
|
|
+ visited.add(current.getPKeyId());
|
|
|
+
|
|
|
+ // 从映射中获取当前节点的父节点
|
|
|
+ current = nodeMap.get(current.getPId());
|
|
|
+ // 如果父节点存在,则将其ID添加到路径列表的开头
|
|
|
+ if (current != null) {
|
|
|
+ path.add(0, current.getPKeyId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 安全限制,防止路径过长导致性能问题
|
|
|
+ if (path.size() > 50) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 将根节点ID(0)添加到路径的最前面,表示路径的起点
|
|
|
+ path.add(0, 0L);
|
|
|
+ // 将路径列表转换为字符串并返回
|
|
|
+ return String.join(",", path.stream().map(String::valueOf).toArray(String[]::new));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 20250414-lhb-新增
|
|
|
+ * 创建祖级路径
|
|
|
+ * <p>
|
|
|
+ * 该方法用于构建给定节点的祖先路径标识符(PId)字符串
|
|
|
+ * 它通过追溯节点的父节点,直到达到根节点或满足特定条件为止
|
|
|
+ *
|
|
|
+ * @param node WbsTreeContract类型的节点,表示需要构建路径的起始节点
|
|
|
+ * @param nodeMap 一个映射,其键为节点ID,值为WbsTreeContract类型的节点对象,用于快速查找节点
|
|
|
+ * @return 返回一个字符串,表示构建的祖先路径标识符序列,以逗号分隔
|
|
|
+ */
|
|
|
+ private String createAncestorsPId(WbsTreeContract node, Map<Long, WbsTreeContract> nodeMap) {
|
|
|
+ // 初始化路径列表,用于存储祖先节点的ID
|
|
|
+ List<Long> path = new ArrayList<>();
|
|
|
+ // 从给定的节点开始
|
|
|
+ WbsTreeContract current = node;
|
|
|
+ // 初始化访问集合,用于检测循环引用
|
|
|
+ Set<Long> visited = new HashSet<>();
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ // 检查当前节点是否为根节点或无效节点
|
|
|
+ if (current == null || current.getPId() == null ||
|
|
|
+ current.getPId() == 0 || current.getPId().equals(current.getPKeyId())) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检测循环引用
|
|
|
+ if (visited.contains(current.getPId())) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // 将当前节点的ID添加到已访问集合中
|
|
|
+ visited.add(current.getPKeyId());
|
|
|
+
|
|
|
+ // 从映射中获取当前节点的父节点
|
|
|
+ current = nodeMap.get(current.getPId());
|
|
|
+ // 如果父节点存在,则将其ID添加到路径列表的开头
|
|
|
+ if (current != null) {
|
|
|
+ path.add(0, current.getPKeyId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 安全限制,防止路径过长导致性能问题
|
|
|
+ if (path.size() > 50) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 将根节点ID(0)添加到路径的最前面,表示路径的起点
|
|
|
+ path.add(0, 0L);
|
|
|
+ // 将路径列表转换为字符串并返回
|
|
|
+ return String.join(",", path.stream().map(String::valueOf).toArray(String[]::new));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定节点的所有最新节点
|
|
|
+ */
|
|
|
+ public Set<Long> getMinNodes(WbsTreeSynchronousRecord record) {
|
|
|
+
|
|
|
+ Set<Long> collect = null;
|
|
|
+ try {
|
|
|
+
|
|
|
+
|
|
|
+ collect = new HashSet<>();
|
|
|
+ Integer range = record.getRange();
|
|
|
+ String nodeId = record.getNodeId();
|
|
|
+ if (range == 1) {
|
|
|
+ if (StringUtil.isNotBlank(record.getFormIds())) {
|
|
|
+ List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .select(WbsTreePrivate::getPKeyId, WbsTreePrivate::getPId)
|
|
|
+ .eq(WbsTreePrivate::getIsDeleted, 0)
|
|
|
+ .eq(WbsTreePrivate::getType, 2)
|
|
|
+ .eq(WbsTreePrivate::getProjectId, record.getProjectId())
|
|
|
+ .in(WbsTreePrivate::getPKeyId, Func.toLongList(record.getFormIds())));
|
|
|
+ collect = list.stream().map(WbsTreePrivate::getPId).collect(Collectors.toSet());
|
|
|
+ } else {
|
|
|
+
|
|
|
+ Set<Long> split = Arrays.stream(nodeId.split(","))
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ for (Long id : split) {
|
|
|
+ List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
|
|
|
+ .select(WbsTreePrivate::getPKeyId, WbsTreePrivate::getPId)
|
|
|
+ .eq(WbsTreePrivate::getIsDeleted, 0)
|
|
|
+ .eq(WbsTreePrivate::getType, 2)
|
|
|
+ .apply("find_in_set({0},ancestors_p_id)", id));
|
|
|
+ collect.addAll(wbsTreePrivates.stream().map(WbsTreePrivate::getPId).collect(Collectors.toSet()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
+ if (range == 2) {
|
|
|
+ if (StringUtil.isNotBlank(record.getFormIds())) {
|
|
|
+ List<WbsTreeContract> list = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
|
|
|
+ .select(WbsTreeContract::getPKeyId, WbsTreeContract::getPId)
|
|
|
+ .eq(WbsTreeContract::getIsDeleted, 0)
|
|
|
+ .eq(WbsTreeContract::getProjectId, record.getProjectId())
|
|
|
+ .in(WbsTreeContract::getIsTypePrivatePid, Func.toLongList(record.getFormIds())));
|
|
|
+ collect = list.stream().map(WbsTreeContract::getPId).collect(Collectors.toSet());
|
|
|
+ } else {
|
|
|
+
|
|
|
+ List<WbsTreeContract> initNode = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
|
|
|
+ .select(WbsTreeContract::getPKeyId, WbsTreeContract::getPId)
|
|
|
+ .eq(WbsTreeContract::getIsDeleted, 0)
|
|
|
+ .eq(WbsTreeContract::getProjectId, record.getProjectId())
|
|
|
+ .in(WbsTreeContract::getIsTypePrivatePid, Func.toLongList(record.getNodeId())));
|
|
|
+
|
|
|
+ for (WbsTreeContract wbsTreeContract : initNode) {
|
|
|
+ List<WbsTreeContract> wbsTreeContracts = wbsTreeContractMapper.selectList(Wrappers.<WbsTreeContract>lambdaQuery()
|
|
|
+ .select(WbsTreeContract::getPKeyId, WbsTreeContract::getPId)
|
|
|
+ .eq(WbsTreeContract::getIsDeleted, 0)
|
|
|
+ .eq(WbsTreeContract::getType, 2)
|
|
|
+ .eq(WbsTreeContract::getProjectId, record.getProjectId())
|
|
|
+ .apply("find_in_set({0},ancestors_p_id)", wbsTreeContract.getPKeyId()));
|
|
|
+ collect.addAll(wbsTreeContracts.stream().map(WbsTreeContract::getPId).collect(Collectors.toSet()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ throw new ServiceException(e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException("系统错误");
|
|
|
+ }
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
+}
|