|
@@ -51,6 +51,9 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -1404,36 +1407,35 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
nodeMap.put(node.getId().toString(), node);
|
|
|
});
|
|
|
|
|
|
- String finalTabOwner1 = tabOwner;
|
|
|
- nodeChildAll.forEach(node -> {
|
|
|
+ for (WbsTreeContract nodeOld : nodeChildAll) {
|
|
|
WbsTreeContract newData = new WbsTreeContract();
|
|
|
- BeanUtils.copyProperties(node, newData);
|
|
|
+ BeanUtils.copyProperties(nodeOld, newData);
|
|
|
//重塑关键信息
|
|
|
//重塑primaryKeyId
|
|
|
newData.setPKeyId(SnowFlakeUtil.getId());
|
|
|
//设置旧ID
|
|
|
- if (StringUtils.isNotEmpty(node.getOldId())) {
|
|
|
- newData.setOldId(node.getOldId());
|
|
|
+ if (StringUtils.isNotEmpty(nodeOld.getOldId())) {
|
|
|
+ newData.setOldId(nodeOld.getOldId());
|
|
|
} else {
|
|
|
- newData.setOldId(node.getId().toString());
|
|
|
+ newData.setOldId(nodeOld.getId().toString());
|
|
|
}
|
|
|
|
|
|
//设置新ID
|
|
|
- if (new Integer("1").equals(node.getType())) {
|
|
|
+ if (new Integer("1").equals(nodeOld.getType())) {
|
|
|
//如果是节点类型才重塑ID
|
|
|
- newData.setId(oldToNewIdMap.containsKey(node.getId()) ? oldToNewIdMap.get(node.getId()) : SnowFlakeUtil.getId());
|
|
|
+ newData.setId(oldToNewIdMap.containsKey(nodeOld.getId()) ? oldToNewIdMap.get(nodeOld.getId()) : SnowFlakeUtil.getId());
|
|
|
//划分编号
|
|
|
newData.setPartitionCode(StringUtils.isNotEmpty(vo.getPartitionCode()) ? vo.getPartitionCode() : null);
|
|
|
}
|
|
|
//设置父节点ID
|
|
|
- if (vo.getNeedCopyPrimaryKeyId().equals(node.getPKeyId().toString())) {
|
|
|
+ if (vo.getNeedCopyPrimaryKeyId().equals(nodeOld.getPKeyId().toString())) {
|
|
|
//找到复制的节点,将parentId更改为 parent.getId()
|
|
|
newData.setParentId(parent.getId());
|
|
|
//设置新名称
|
|
|
newData.setNodeName(vo.getNeedCopyNodeName());
|
|
|
newData.setFullName(vo.getNeedCopyNodeName());
|
|
|
} else {
|
|
|
- newData.setParentId(oldToNewIdMap.containsKey(node.getParentId()) ? oldToNewIdMap.get(node.getParentId()) : SnowFlakeUtil.getId());
|
|
|
+ newData.setParentId(oldToNewIdMap.containsKey(nodeOld.getParentId()) ? oldToNewIdMap.get(nodeOld.getParentId()) : SnowFlakeUtil.getId());
|
|
|
}
|
|
|
newData.setCreateTime(new Date());
|
|
|
newData.setUpdateTime(new Date());
|
|
@@ -1450,13 +1452,13 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
this.restoreParent(newData, oldToNewIdMap);
|
|
|
//保存到集合中
|
|
|
saveList.add(newData);
|
|
|
- if (new Integer("6").equals(node.getNodeType())) {
|
|
|
+ if (new Integer("6").equals(nodeOld.getNodeType())) {
|
|
|
//生成施工日志
|
|
|
this.createLedger(newData, saveLedger, nodeMap, null);
|
|
|
}
|
|
|
//表单所属方,只有勾选了对应的所属方权限才复制数据;勾选了复制数据才能复制,否则只是创建节点、表
|
|
|
//组织复制值Sql
|
|
|
- if (node.getType() == 2 && StringUtils.isNotEmpty(newData.getInitTableName()) && finalTabOwner1.contains(node.getTableOwner()) && vo.getIsCopyData() == 1) {
|
|
|
+ if (nodeOld.getType() == 2 && StringUtils.isNotEmpty(newData.getInitTableName()) && tabOwner.contains(nodeOld.getTableOwner()) && vo.getIsCopyData() == 1) {
|
|
|
String tableName = newData.getInitTableName();
|
|
|
String col = nodeTabColsMap.get(tableName);
|
|
|
String colVal = nodeTabColsMap.get(tableName);
|
|
@@ -1464,25 +1466,36 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
//delete SQL (先删除旧数据,再新增)
|
|
|
String delSql = "delete from " + tableName + " where p_key_id = " + newData.getPKeyId() + " ; ";
|
|
|
//insert into SQL
|
|
|
- copeSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(node.getPKeyId()).append("' ;");
|
|
|
+ copeSql.append(delSql).append("insert into ").append(tableName).append(" (").append(col).append(") select ").append(colVal).append(" from ").append(tableName).append(" where p_key_id='").append(nodeOld.getPKeyId()).append("' ;");
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
needCopyNode.setNodeName(vo.getNeedCopyNodeName());
|
|
|
+
|
|
|
//复制保存节点、表信息
|
|
|
R<Boolean> booleanR = this.saveOrCopyNodeTree(saveList, saveLedger, 32, needCopyNode);
|
|
|
|
|
|
+ try {
|
|
|
+ //复制表单数据
|
|
|
+ if (copeSql.length() >= 10 && booleanR.getData()) {
|
|
|
+ jdbcTemplate.execute(copeSql.toString());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ //手动回滚,删除节点、表
|
|
|
+ List<String> collect = saveList.stream().map(WbsTreeContract::getPKeyId).map(String::valueOf).collect(Collectors.toList());
|
|
|
+ if (collect.size() > 0) {
|
|
|
+ jdbcTemplate.execute("delete from m_wbs_tree_contract where p_key_id in(" + StringUtils.join(collect, ",") + ")");
|
|
|
+ }
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException("保存数据异常,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
//复制元素表附件信息
|
|
|
List<WbsTreeContract> newTabs = saveList.stream().filter(f -> (new Integer(2).equals(f.getType()))).collect(Collectors.toList());
|
|
|
if (newTabs.size() > 0 && oldTabs.size() > 0 && vo.getIsCopyData() == 1) {
|
|
|
this.addCopyTabFile(new HashSet<>(newTabs), oldTabs);
|
|
|
}
|
|
|
|
|
|
- //复制表单数据
|
|
|
- if (copeSql.length() >= 10) {
|
|
|
- jdbcTemplate.execute(copeSql.toString());
|
|
|
- }
|
|
|
-
|
|
|
//更新redis缓存
|
|
|
informationQueryService.delAsyncWbsTree(needCopyNode.getContractId());
|
|
|
|
|
@@ -1651,9 +1664,21 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
|
|
|
if (resultTablesData.size() > 0 && vo.getIsCopyData() == 1) {
|
|
|
//复制新增表数据
|
|
|
- List<List<String>> partition = Lists.partition(resultTablesData, 20);
|
|
|
- for (List<String> strings : partition) {
|
|
|
- jdbcTemplate.execute(StringUtils.join(strings, ""));
|
|
|
+ try {
|
|
|
+ List<List<String>> partition = Lists.partition(resultTablesData, 20);
|
|
|
+ for (List<String> strings : partition) {
|
|
|
+ jdbcTemplate.execute(StringUtils.join(strings, ""));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ //手动回滚,删除节点、表
|
|
|
+ List<String> collect1 = nodes.stream().map(WbsTreeContract::getPKeyId).map(String::valueOf).collect(Collectors.toList());
|
|
|
+ List<String> collect2 = tabs.stream().map(WbsTreeContract::getPKeyId).map(String::valueOf).collect(Collectors.toList());
|
|
|
+ collect1.addAll(collect2);
|
|
|
+ if (collect1.size() > 0) {
|
|
|
+ jdbcTemplate.execute("delete from m_wbs_tree_contract where p_key_id in(" + StringUtils.join(collect1, ",") + ")");
|
|
|
+ }
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException("保存数据异常,请联系管理员");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1721,7 +1746,8 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
* 新增复制的表单文件
|
|
|
*/
|
|
|
@Async
|
|
|
- public void addCopyTabFile(Set<WbsTreeContract> addChildNodesTables, Set<WbsTreeContract> addChildNodesTablesOld) {
|
|
|
+ public void addCopyTabFile
|
|
|
+ (Set<WbsTreeContract> addChildNodesTables, Set<WbsTreeContract> addChildNodesTablesOld) {
|
|
|
//获取所有数据源附件文件
|
|
|
List<Long> tabFileIds = addChildNodesTablesOld.stream().distinct().map(WbsTreeContract::getPKeyId).collect(Collectors.toList());
|
|
|
Map<String, List<TableFile>> tableFileOldMap = tableFileClient.getTabFilesByTabIds(StringUtils.join(tabFileIds, ",")).stream().collect(Collectors.groupingBy(TableFile::getTabId));
|
|
@@ -1775,7 +1801,9 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
/**
|
|
|
* 新增复制的数据
|
|
|
*/
|
|
|
- private void addCopyTabData(WbsTreeContract needCopyNode, WbsTreeContract toCopyNode, String tabOwner, List<String> resultTablesData, List<WbsTreeContract> addChildNodesTablesAll, Integer isCopyData, Set<WbsTreeContract> addNewFileTabs) {
|
|
|
+ private void addCopyTabData(WbsTreeContract needCopyNode, WbsTreeContract toCopyNode, String
|
|
|
+ tabOwner, List<String> resultTablesData, List<WbsTreeContract> addChildNodesTablesAll, Integer
|
|
|
+ isCopyData, Set<WbsTreeContract> addNewFileTabs) {
|
|
|
List<WbsTreeContract> wbsTreeContractsNeed = Collections.singletonList(needCopyNode);
|
|
|
List<WbsTreeContract> wbsTreeContractsTo = Collections.singletonList(toCopyNode);
|
|
|
List<WbsTreeContract> needCopyNodeTabs = this.getChildNodesTables(wbsTreeContractsNeed, needCopyNode.getContractId());
|
|
@@ -1867,7 +1895,10 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
/**
|
|
|
* 新增复制的节点、表的数据构造
|
|
|
*/
|
|
|
- private void addCopyNodesAndTabsBuildData(List<WbsTreeContract> addNodeList, List<WbsTreeContract> addTabList, List<WbsTreeContract> needNodes, List<WbsTreeContract> needTabs, WbsTreeContract needCopyNode, WbsTreeContract toCopyNode, List<String> resultTablesData, Integer isSameNode, String tabOwner, Integer isCopyData) {
|
|
|
+ private void addCopyNodesAndTabsBuildData
|
|
|
+ (List<WbsTreeContract> addNodeList, List<WbsTreeContract> addTabList, List<WbsTreeContract> needNodes, List<WbsTreeContract> needTabs, WbsTreeContract
|
|
|
+ needCopyNode, WbsTreeContract toCopyNode, List<String> resultTablesData, Integer isSameNode, String
|
|
|
+ tabOwner, Integer isCopyData) {
|
|
|
int var = 0;
|
|
|
if (needNodes.size() == 1) {
|
|
|
//判断是否为最下级节点
|
|
@@ -2081,7 +2112,8 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
/**
|
|
|
* 递归获取所有子级节点
|
|
|
*/
|
|
|
- private void recursionGetChildNodes(List<WbsTreeContract> list, List<WbsTreeContract> result, String contractId) {
|
|
|
+ private void recursionGetChildNodes(List<WbsTreeContract> list, List<WbsTreeContract> result, String
|
|
|
+ contractId) {
|
|
|
List<Long> ids = list.stream().map(WbsTreeContract::getId).collect(Collectors.toList());
|
|
|
if (ids.size() > 0) {
|
|
|
List<WbsTreeContract> query = jdbcTemplate.query("select * from m_wbs_tree_contract where type = 1 and parent_id in(" + StringUtils.join(ids, ",") + ") and status = 1 and is_deleted = 0 and contract_id = " + contractId, new BeanPropertyRowMapper<>(WbsTreeContract.class));
|
|
@@ -2906,7 +2938,9 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<WbsTreePrivate> unifiedCode(List<AddContractTreeNodeVO.Node> allSelectedNodeList, WbsTreeContract treeContract, String saveType, List<WbsTreePrivate> queryResultP) {
|
|
|
+ private List<WbsTreePrivate> unifiedCode
|
|
|
+ (List<AddContractTreeNodeVO.Node> allSelectedNodeList, WbsTreeContract treeContract, String
|
|
|
+ saveType, List<WbsTreePrivate> queryResultP) {
|
|
|
//获取项目节点树的主键
|
|
|
List<Long> halfSelectedList = allSelectedNodeList.stream().map(AddContractTreeNodeVO.Node::getPrimaryKeyId).map(Long::parseLong).distinct().collect(Collectors.toList());
|
|
|
|
|
@@ -2931,13 +2965,10 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
}
|
|
|
|
|
|
@NotNull
|
|
|
- private R<Boolean> saveOrCopyNodeTree
|
|
|
- (List<WbsTreeContract> saveList, List<ConstructionLedger> saveLedger, Integer
|
|
|
- operationType, WbsTreeContract currentNode) {
|
|
|
-
|
|
|
+ public R<Boolean> saveOrCopyNodeTree(List<WbsTreeContract> saveList, List<ConstructionLedger> saveLedger, Integer operationType, WbsTreeContract currentNode) {
|
|
|
if (saveList.size() > 0) {
|
|
|
-// StringBuilder str = new StringBuilder();
|
|
|
-// str.append("-" + saveList.get(0).getFullName());
|
|
|
+ //StringBuilder str = new StringBuilder();
|
|
|
+ //str.append("-" + saveList.get(0).getFullName());
|
|
|
//保存施工日志
|
|
|
/*if (saveLedger.size() > 0) {
|
|
|
this.constructionLedgerService.saveBatch(saveLedger, 1000);
|
|
@@ -2978,13 +3009,10 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
}
|
|
|
|
|
|
@NotNull
|
|
|
- private R<Boolean> saveOrCopyNodeTree2
|
|
|
- (List<WbsTreeContract> saveList, List<ConstructionLedger> saveLedger, Integer
|
|
|
- operationType, WbsTreeContract currentNode) {
|
|
|
-
|
|
|
+ private R<Boolean> saveOrCopyNodeTree2(List<WbsTreeContract> saveList, List<ConstructionLedger> saveLedger, Integer operationType, WbsTreeContract currentNode) {
|
|
|
if (saveList.size() > 0) {
|
|
|
-// StringBuilder str = new StringBuilder();
|
|
|
-// str.append("-" + saveList.get(0).getFullName());
|
|
|
+ //StringBuilder str = new StringBuilder();
|
|
|
+ //str.append("-" + saveList.get(0).getFullName());
|
|
|
//保存施工日志
|
|
|
/*if (saveLedger.size() > 0) {
|
|
|
this.constructionLedgerService.saveBatch(saveLedger, 1000);
|
|
@@ -3035,7 +3063,8 @@ public class InformationWriteQueryController extends BladeController {
|
|
|
/**
|
|
|
* 处理半选集合
|
|
|
*/
|
|
|
- private void disposeHalfSelectList(@RequestBody WbsTreeContract treeContract, List<AddContractTreeNodeVO.Node> allSelectedNodeList, List<WbsTreePrivate> selectedNodeList, List<WbsTreePrivate> queryResultP) {
|
|
|
+ private void disposeHalfSelectList(@RequestBody WbsTreeContract
|
|
|
+ treeContract, List<AddContractTreeNodeVO.Node> allSelectedNodeList, List<WbsTreePrivate> selectedNodeList, List<WbsTreePrivate> queryResultP) {
|
|
|
if (allSelectedNodeList != null && allSelectedNodeList.size() > 0) {
|
|
|
//获取主键
|
|
|
List<Long> allSelectedList = allSelectedNodeList.stream().map(AddContractTreeNodeVO.Node::getPrimaryKeyId).map(Long::parseLong).distinct().collect(Collectors.toList());
|