|
@@ -1,5 +1,6 @@
|
|
package org.springblade.manager.service.impl;
|
|
package org.springblade.manager.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
@@ -26,6 +27,7 @@ import org.springblade.core.tool.constant.BladeConstant;
|
|
import org.springblade.core.tool.node.ForestNodeMerger;
|
|
import org.springblade.core.tool.node.ForestNodeMerger;
|
|
import org.springblade.core.tool.utils.*;
|
|
import org.springblade.core.tool.utils.*;
|
|
import org.springblade.manager.dto.FormulaBean;
|
|
import org.springblade.manager.dto.FormulaBean;
|
|
|
|
+import org.springblade.manager.dto.ParamElements;
|
|
import org.springblade.manager.dto.WbsTreePrivateDTO2;
|
|
import org.springblade.manager.dto.WbsTreePrivateDTO2;
|
|
import org.springblade.manager.dto.WbsTreePrivateDTO3;
|
|
import org.springblade.manager.dto.WbsTreePrivateDTO3;
|
|
import org.springblade.manager.entity.*;
|
|
import org.springblade.manager.entity.*;
|
|
@@ -48,6 +50,7 @@ import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.time.LocalDateTime;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
import java.util.stream.Collector;
|
|
import java.util.stream.Collector;
|
|
@@ -695,8 +698,7 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
- public boolean syncNodeParam(String projectId, String pKeyId) {
|
|
|
|
|
|
+ public boolean syncNodeParamOld(String projectId, String pKeyId) {
|
|
if (StringUtils.isNotEmpty(projectId) && StringUtils.isNotEmpty(pKeyId)) {
|
|
if (StringUtils.isNotEmpty(projectId) && StringUtils.isNotEmpty(pKeyId)) {
|
|
ProjectInfo projectInfo = projectInfoMapper.selectById(projectId);
|
|
ProjectInfo projectInfo = projectInfoMapper.selectById(projectId);
|
|
//当前选择同步的节点信息
|
|
//当前选择同步的节点信息
|
|
@@ -891,6 +893,149 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+ @Override
|
|
|
|
+ public boolean syncNodeParam(String projectId, String pKeyId){
|
|
|
|
+ projectId=null;//暂不执行
|
|
|
|
+ if (StringUtils.isNotEmpty(projectId) && StringUtils.isNotEmpty(pKeyId)) {
|
|
|
|
+ ProjectInfo projectInfo = projectInfoMapper.selectById(projectId);
|
|
|
|
+ //当前选择同步的节点信息
|
|
|
|
+ WbsTreePrivate selectNodeNow = baseMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, pKeyId).eq(WbsTreePrivate::getStatus, 1));
|
|
|
|
+ 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)
|
|
|
|
+ .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));
|
|
|
|
+ /*比较的结果*/
|
|
|
|
+ Map<String, Map<String, Object>> updateMap = new HashMap<>();
|
|
|
|
+ Map<String, Map<String, Object>> insertMap = new HashMap<>();
|
|
|
|
+ sourceMap.forEach((k, v) -> {
|
|
|
|
+ if (distMap.containsKey(k)) {
|
|
|
|
+ String s = Func.toStr(v.get("v"));
|
|
|
|
+ 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")));
|
|
|
|
+ /*假如内容不一样,且模版最后更新时间更晚,则覆盖*/
|
|
|
|
+ if (sldt.isAfter(tldt)) {
|
|
|
|
+ u.put("v", s);
|
|
|
|
+ updateMap.put(u.get("id").toString(), u);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ /*假如对应节点不存在,则把节点内容添加到待新增列表*/
|
|
|
|
+ insertMap.put(v.get("privateId").toString(), v);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ List<WbsParam> updateList;
|
|
|
|
+ if (!updateMap.isEmpty()) {
|
|
|
|
+ updateList = Optional.ofNullable(this.wbsParamServiceImpl.list(Wrappers.<WbsParam>lambdaQuery().in(WbsParam::getId, new ArrayList<>(updateMap.keySet())))).orElse(new ArrayList<>());
|
|
|
|
+ updateList.forEach(e -> {
|
|
|
|
+ e.setV(updateMap.get(e.getId().toString()).get("v").toString());
|
|
|
|
+ });
|
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
|
+ this.wbsParamServiceImpl.saveOrUpdateBatch(updateList, 1000);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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<>());
|
|
|
|
+ targetList.forEach(e -> {
|
|
|
|
+ Map<String, Object> kmp = insertMap.get(e.getId().toString());
|
|
|
|
+ if (kmp != null) {
|
|
|
|
+ WbsParam one = BeanUtil.toBean(kmp, WbsParam.class);
|
|
|
|
+ one.setNodeId(e.getPKeyId());
|
|
|
|
+ insertList.add(one);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (!insertList.isEmpty()) {
|
|
|
|
+ insertList.forEach(i->i.setId(SnowFlakeUtil.getId()));
|
|
|
|
+ this.wbsParamServiceImpl.saveOrUpdateBatch(insertList, 1000);
|
|
|
|
+ /*生成公式,并自动绑定元素*/
|
|
|
|
+ Map<Long,Formula> insertFormulaMap = insertList.stream().map(e->{
|
|
|
|
+ Map<String, Object> tmpMap = new HashMap<>();
|
|
|
|
+ Formula formula = new Formula();
|
|
|
|
+ formula.setOutm(Formula.FULL);
|
|
|
|
+ formula.setParamId(e.getId());
|
|
|
|
+ Map<String, String> keyMap = new HashMap<>();
|
|
|
|
+ keyMap.put("name", e.getName());
|
|
|
|
+ keyMap.put("id", e.getId().toString());
|
|
|
|
+ tmpMap.put(e.getK(), keyMap);
|
|
|
|
+ if (RegexUtil.match(ParamElements.LEVEL_REG, e.getV().trim())) {
|
|
|
|
+ /*取层级*/
|
|
|
|
+ formula.setFormula("FC.tree(trees,WP[" + e.getK() + "])");
|
|
|
|
+ } else {
|
|
|
|
+ /*直接取数*/
|
|
|
|
+ formula.setFormula("WP[" + e.getK() + "]");
|
|
|
|
+ }
|
|
|
|
+ formula.setMap(JSON.toJSONString(tmpMap));
|
|
|
|
+ formula.setId(SnowFlakeUtil.getId());
|
|
|
|
+ return formula;
|
|
|
|
+ }).collect(Collectors.toMap(Formula::getParamId,f->f));
|
|
|
|
+ List<String> nodeIds= insertList.stream().map(WbsParam::getNodeId).distinct().map(Objects::toString).collect(Collectors.toList());
|
|
|
|
+ /*每道工序下包含的元素集合*/
|
|
|
|
+ List<Map<String, Object>> listMaps = this.jdbcTemplate.queryForList(
|
|
|
|
+ "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);
|
|
|
|
+
|
|
|
|
+ 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(insertFormulaMap.size()>0){
|
|
|
|
+ this.formulaService.saveBatch(insertFormulaMap.values(),1000);
|
|
|
|
+ }
|
|
|
|
+ if(insertEfm.size()>0){
|
|
|
|
+ this.elementFormulaMappingService.saveBatch(insertEfm,1000);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public R<String> syncPrivateProjectFormula(Long projectId, Long pKeyId) {
|
|
public R<String> syncPrivateProjectFormula(Long projectId, Long pKeyId) {
|