|
@@ -41,6 +41,8 @@ import org.springblade.system.cache.ParamCache;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.core.SqlParameterValue;
|
|
|
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -50,9 +52,12 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.sql.Types;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.io.*;
|
|
|
import java.util.*;
|
|
|
+import java.util.function.BinaryOperator;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -897,7 +902,7 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
|
|
|
@Override
|
|
|
public boolean syncNodeParam(String projectId, String pKeyId) {
|
|
|
- projectId = null;//暂不执行
|
|
|
+ // projectId = null;//暂不执行
|
|
|
if (StringUtils.isNotEmpty(projectId) && StringUtils.isNotEmpty(pKeyId)) {
|
|
|
ProjectInfo projectInfo = projectInfoMapper.selectById(projectId);
|
|
|
//当前选择同步的节点信息
|
|
@@ -905,26 +910,31 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
if (selectNodeNow == null) {
|
|
|
throw new ServiceException("未获取到当前选择同步的节点信息,请联系管理员");
|
|
|
}
|
|
|
-
|
|
|
- //获取当前选择的节点与它所有子节点
|
|
|
- List<WbsTreePrivate> selectNodeAndChildNodes = Optional.ofNullable(this.getChildNodes(selectNodeNow)).orElse(new ArrayList<>());
|
|
|
- selectNodeAndChildNodes.add(selectNodeNow);
|
|
|
- List<Long> privateNodeIds = selectNodeAndChildNodes.stream().map(WbsTreePrivate::getId).collect(Collectors.toList());
|
|
|
- List<Long> privateNodePKeyIds = selectNodeAndChildNodes.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
|
|
|
if (("private").equals(projectInfo.getReferenceWbsTemplateType())) {
|
|
|
// ---------私有才需要引用同步---------节点参数nodeId绑定的是m_wbs_private 的p_key_id ;同节点下mapping scope=35 共用一个formula;也就是说同一个节点下的同一个element都指向同一个公式
|
|
|
/*全部查出来,pkeyId-id-paramId source:key 最后比较;同节点相同k的参数都指向同一个公式,mapping 对象除了elementId不一样其它都一样*/
|
|
|
/*同步的范围不一定是整棵树,可以是局部分支*/
|
|
|
//获取当前私有引用模板的根节点信息
|
|
|
- WbsTreePrivate treePrivateRootNode = baseMapper.selectOne(Wrappers.<WbsTreePrivate>query().lambda()
|
|
|
- .select(WbsTreePrivate::getWbsId, WbsTreePrivate::getProjectId)
|
|
|
+ WbsTreePrivate sourceRootNode = baseMapper.selectOne(Wrappers.<WbsTreePrivate>query().lambda().select(WbsTreePrivate::getWbsId, WbsTreePrivate::getProjectId)
|
|
|
.eq(WbsTreePrivate::getPKeyId, selectNodeNow.getWbsId()).eq(WbsTreePrivate::getParentId, 0L).eq(WbsTreePrivate::getStatus, 1).eq(WbsTreePrivate::getType, 1));
|
|
|
- List<Map<String, Object>> sourceListMap = this.jdbcTemplate.queryForList("select a.id,a.k,a.v,a.remark,a.node_id nodeId ,b.id privateId,a.update_time updateTime " +
|
|
|
- "from m_wbs_param a join m_wbs_tree_private b on a.node_id = b.p_key_id where b.project_id in(?) and b.id in(?) and a.is_deleted=0 and a.type=1 ", treePrivateRootNode.getProjectId(), privateNodeIds.stream().map(Object::toString).collect(Collectors.joining(",")));
|
|
|
- List<Map<String, Object>> distListMap = this.jdbcTemplate.queryForList("select a.id,a.k,a.v,a.remark,a.node_id nodeId ,b.id privateId,a.update_time updateTime " +
|
|
|
- "from m_wbs_param a join m_wbs_tree_private b on a.node_id = b.p_key_id where b.project_id in(?) and b.p_key_id in(?) and a.is_deleted=0 and a.type=1 ", projectId, privateNodePKeyIds.stream().map(Object::toString).collect(Collectors.joining(",")));
|
|
|
- Map<String, Map<String, Object>> sourceMap = sourceListMap.stream().collect(Collectors.toMap(m -> m.get("privateId").toString() + m.get("k"), m -> m));
|
|
|
- Map<String, Map<String, Object>> distMap = distListMap.stream().collect(Collectors.toMap(m -> m.get("privateId").toString() + m.get("k"), m -> m));
|
|
|
+
|
|
|
+ List<WbsTreePrivate> selectNodeAndChildNodes = Optional.ofNullable(this.getChildNodes(selectNodeNow)).orElse(new ArrayList<>());
|
|
|
+ selectNodeAndChildNodes.add(selectNodeNow);
|
|
|
+ List<Long> sourceNodeIds = jdbcTemplate.queryForList("select p_key_id from m_wbs_tree_private where id in("+selectNodeAndChildNodes.stream().map(WbsTreePrivate::getId).map(Object::toString).collect(Collectors.joining(","))+") and is_deleted=0 and project_id ="+sourceRootNode.getProjectId(),Long.class);
|
|
|
+ List<Long> distNodeIds = selectNodeAndChildNodes.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
|
|
|
+ List<Map<String, Object>> sourceListMap = this.jdbcTemplate.queryForList("select a.id,a.name ,a.k,a.v,a.remark,a.node_id nodeId ,b.id privateId,a.update_time updateTime " +
|
|
|
+ "from m_wbs_param a join m_wbs_tree_private b on a.node_id = b.p_key_id where b.project_id in(?) and b.p_key_id in("+sourceNodeIds.stream().map(Object::toString).collect(Collectors.joining(","))+") and a.is_deleted=0 and a.type=1 ", Long.parseLong(sourceRootNode.getProjectId()));
|
|
|
+ List<Map<String, Object>> distListMap = this.jdbcTemplate.queryForList("select a.id,a.name,a.k,a.v,a.remark,a.node_id nodeId ,b.id privateId,a.update_time updateTime " +
|
|
|
+ "from m_wbs_param a join m_wbs_tree_private b on a.node_id = b.p_key_id where b.project_id in(?) and b.p_key_id in("+distNodeIds.stream().map(Object::toString).collect(Collectors.joining(","))+") and a.is_deleted=0 and a.type=1 ", Long.parseLong(projectId));
|
|
|
+
|
|
|
+ /*存在多个同名参数;保留日期最新那个参数*/
|
|
|
+ BinaryOperator<Map<String,Object>> mapBinaryOperator= (m1, m2) -> {
|
|
|
+ LocalDateTime sldt = ((Timestamp)m1.get("updateTime")).toLocalDateTime();
|
|
|
+ LocalDateTime tldt = ((Timestamp)m2.get("updateTime")).toLocalDateTime();
|
|
|
+ return sldt.isAfter(tldt)?m1:m2;
|
|
|
+ };
|
|
|
+ Map<String, Map<String, Object>> sourceMap = sourceListMap.stream().collect(Collectors.toMap(m -> m.get("privateId").toString() + m.get("k"), m -> m,mapBinaryOperator));
|
|
|
+ Map<String, Map<String, Object>> distMap = distListMap.stream().collect(Collectors.toMap(m -> m.get("privateId").toString() + m.get("k"), m -> m,mapBinaryOperator));
|
|
|
/*比较的结果*/
|
|
|
Map<String, Map<String, Object>> updateMap = new HashMap<>();
|
|
|
Map<String, Map<String, Object>> insertMap = new HashMap<>();
|
|
@@ -934,8 +944,8 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
Map<String, Object> u = distMap.get(k);
|
|
|
String t = Func.toStr(u.get("v"));
|
|
|
if (!s.equals(t)) {
|
|
|
- LocalDateTime sldt = LocalDateTime.parse(Func.toStr(v.get("updateTime")));
|
|
|
- LocalDateTime tldt = LocalDateTime.parse(Func.toStr(u.get("updateTime")));
|
|
|
+ LocalDateTime sldt = ((Timestamp)v.get("updateTime")).toLocalDateTime();
|
|
|
+ LocalDateTime tldt = ((Timestamp)u.get("updateTime")).toLocalDateTime();
|
|
|
/*假如内容不一样,且模版最后更新时间更晚,则覆盖*/
|
|
|
if (sldt.isAfter(tldt)) {
|
|
|
u.put("v", s);
|
|
@@ -959,7 +969,7 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
}
|
|
|
List<WbsParam> insertList = new ArrayList<>();
|
|
|
if (!insertMap.isEmpty()) {
|
|
|
- List<WbsTreePrivate> targetList = Optional.ofNullable(this.list(Wrappers.<WbsTreePrivate>lambdaQuery().in(WbsTreePrivate::getId, insertMap.values().stream().map(m -> m.get("privateId")).collect(Collectors.toList())))).orElse(new ArrayList<>());
|
|
|
+ List<WbsTreePrivate> targetList = Optional.ofNullable(this.list(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getProjectId,projectId).in(WbsTreePrivate::getId, insertMap.values().stream().map(m -> m.get("privateId")).collect(Collectors.toList())))).orElse(new ArrayList<>());
|
|
|
targetList.forEach(e -> {
|
|
|
Map<String, Object> kmp = insertMap.get(e.getId().toString());
|
|
|
if (kmp != null) {
|
|
@@ -998,32 +1008,26 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
"select c.e_name as name ,c.id,a.p_key_id pKeyId from m_wbs_tree_private a " +
|
|
|
"inner join m_wbs_tree_private b on (a.id=b.parent_id and a.wbs_id=b.wbs_id) " +
|
|
|
"inner join m_wbs_form_element c on b.init_table_id=c.f_id " +
|
|
|
- "where b.project_id=" + projectId + " and a.p_key_id in(?) and b.is_deleted=0 and c.is_deleted=0 ", nodeIds);
|
|
|
+ "where b.project_id=" + projectId + " and a.p_key_id in("+String.join(",",nodeIds)+") and b.is_deleted=0 and c.is_deleted=0 ");
|
|
|
|
|
|
Map<String, List<Map<String, Object>>> groupElementNode = listMaps.stream().collect(Collectors.groupingBy(e -> Func.toStr(e.get("pKeyId"))));
|
|
|
List<ElementFormulaMapping> insertEfm = new ArrayList<>();
|
|
|
insertList.forEach(p -> {
|
|
|
List<Map<String, Object>> elementMap = groupElementNode.get(p.getNodeId().toString());
|
|
|
Formula formula = insertFormulaMap.get(p.getId());
|
|
|
- elementMap.forEach(m -> {
|
|
|
- if (com.mixsmart.utils.StringUtils.handleNull(m.get("name")).contains(p.getName())) {
|
|
|
- /*匹配名称,且该元素没有绑定任何节点参数公式*/
|
|
|
-// if (longList.stream().noneMatch(k -> com.mixsmart.utils.StringUtils.isEquals(k, m.get("id")))) {
|
|
|
-// ElementFormulaMapping efm = new ElementFormulaMapping();
|
|
|
-// efm.setScope(FormulaBean.PARAM);
|
|
|
-// efm.setParamId(e.getId());
|
|
|
-// efm.setElementId(Long.parseLong(m.get("id").toString()));
|
|
|
-// efm.setFormulaId(finalFormula.getId());
|
|
|
-// this.elementFormulaMappingService.save(efm);
|
|
|
-// }
|
|
|
- ElementFormulaMapping efm = new ElementFormulaMapping();
|
|
|
- efm.setScope(FormulaBean.PARAM);
|
|
|
- efm.setParamId(p.getId());
|
|
|
- efm.setElementId(Long.parseLong(m.get("id").toString()));
|
|
|
- efm.setFormulaId(formula.getId());
|
|
|
- insertEfm.add(efm);
|
|
|
- }
|
|
|
- });
|
|
|
+ if(Func.isNotEmpty(elementMap)) {
|
|
|
+ elementMap.forEach(m -> {
|
|
|
+ if (com.mixsmart.utils.StringUtils.handleNull(m.get("name")).contains(p.getName())) {
|
|
|
+ /*匹配名称,且该元素没有绑定任何节点参数公式*/
|
|
|
+ ElementFormulaMapping efm = new ElementFormulaMapping();
|
|
|
+ efm.setScope(FormulaBean.PARAM);
|
|
|
+ efm.setParamId(p.getId());
|
|
|
+ efm.setElementId(Long.parseLong(m.get("id").toString()));
|
|
|
+ efm.setFormulaId(formula.getId());
|
|
|
+ insertEfm.add(efm);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
if (insertFormulaMap.size() > 0) {
|
|
|
this.formulaService.saveBatch(insertFormulaMap.values(), 1000);
|
|
@@ -1039,6 +1043,9 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public R<String> syncPrivateProjectFormula(Long projectId, Long pKeyId) {
|
|
|
if (projectId != null && pKeyId != null) {
|