yangyj hace 2 años
padre
commit
4cebdc3ee7

+ 3 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/ParamBean.java

@@ -19,4 +19,7 @@ public class ParamBean {
    private Long   nodeId;
    private Integer type;
    private List<Long> delIds;
+   public Boolean isCommon(){
+      return type.equals(0);
+   }
 }

+ 78 - 19
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsParamController.java

@@ -1,5 +1,6 @@
 package org.springblade.manager.controller;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -14,7 +15,9 @@ import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.core.tool.utils.CollectionUtil;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.RegexUtil;
 import org.springblade.manager.dto.FormulaBean;
+import org.springblade.manager.dto.ParamElements;
 import org.springblade.manager.dto.WbsParamBean;
 import org.springblade.manager.entity.ElementFormulaMapping;
 import org.springblade.manager.entity.Formula;
@@ -30,10 +33,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.bind.annotation.*;
 import springfox.documentation.annotations.ApiIgnore;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -84,8 +84,13 @@ public class WbsParamController {
             List<WbsParamBean> wps =pb.getWps();
             /*执行顺序,删>增>改*/
             if(Func.isNotEmpty(pb.getDelIds())){
-                this.service.deleteLogic(pb.getDelIds());
-                this.elementFormulaMappingService.update(Wrappers.<ElementFormulaMapping>lambdaUpdate().set(ElementFormulaMapping::getIsDeleted,1).in(ElementFormulaMapping::getParamId,pb.getDelIds()));
+                List<Long> delIds = pb.getDelIds().stream().filter(Func::isNotEmpty).collect(Collectors.toList());
+                if(Func.isNotEmpty(delIds)){
+                    this.service.deleteLogic(pb.getDelIds());
+                    if(!pb.isCommon()){
+                        this.elementFormulaMappingService.update(Wrappers.<ElementFormulaMapping>lambdaUpdate().set(ElementFormulaMapping::getIsDeleted,1).in(ElementFormulaMapping::getParamId,pb.getDelIds()));
+                    }
+                }
                 /*应该检查接触关联的参数公式还是否存在引用,不存在的情况也要删去*/
             }
             if(CollectionUtil.isNotEmpty(wps)){
@@ -93,29 +98,83 @@ public class WbsParamController {
                 List<WbsParamBean> saveList = map.get(false);
                 List<WbsParamBean> updateList = map.get(true);
                 if(CollectionUtil.isNotEmpty(saveList)){
-                    this.service.saveBatch(BeanUtil.copy(saveList,WbsParam.class));
-                    /*新建的时候需要初始化绑定表单元素*/
-                   List<Map<String,Object>> elementMap= this.jdbcTemplate.queryForList(
-                           "select a.e_name as name ,a.id " +
-                           "from m_wbs_form_element a " +
-                           "inner join m_wbs_tree b on a.f_id=b.init_table_id " +
-                           "inner join m_wbs_tree c on b.parent_id=c.id " +
-                           "where a.is_deleted=0 and c.id="+pb.getNodeId()
-                   );
+                    List<WbsParam>entityList=BeanUtil.copy(saveList,WbsParam.class);
+                    this.service.saveBatch(entityList);
+                    if(!pb.isCommon()){
+                        /*新建的时候需要初始化绑定表单元素*/
+                        List<Map<String,Object>> elementMap= this.jdbcTemplate.queryForList(
+                                "select a.e_name as name ,a.id " +
+                                        "from m_wbs_form_element a " +
+                                        "inner join m_wbs_tree b on a.f_id=b.init_table_id " +
+                                        "inner join m_wbs_tree c on b.parent_id=c.id " +
+                                        "where a.is_deleted=0 and c.id="+pb.getNodeId()
+                        );
+                        if(!elementMap.isEmpty()){
+                            Map<String,Object> tmpMap=new HashMap<>();
+                            entityList.forEach(e->{
+                                Formula formula = new Formula();
+                                formula.setOutm(Formula.FULL);
+                                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())){
+                                    /*取层级*/
+                                    formula.setFormula("FC.tree(trees,WP["+e.getK()+"])");
+                                }else{
+                                    /*直接取数*/
+                                    formula.setFormula("WP["+e.getK()+"]");
+                                }
+                                formula.setMap(JSON.toJSONString(tmpMap));
+                                this.formulaService.save(formula);
+                                tmpMap.clear();
+                                elementMap.forEach(m->{
+                                    if(m.get("name").toString().contains(e.getName())){
+                                        ElementFormulaMapping efm = new ElementFormulaMapping();
+                                        efm.setScope(20);
+                                        efm.setParamId(e.getId());
+                                        efm.setElementId(Long.parseLong(m.get("id").toString()));
+                                        if(pb.getProjectId()!=null){
+                                            efm.setProjectId(Long.parseLong(pb.getProjectId()));
+                                        }
+                                        efm.setNodeId(pb.getNodeId());
+                                        efm.setFormulaId(formula.getId());
+                                        this.elementFormulaMappingService.save(efm);
+                                    }
+                                });
+                            });
+                        }
+                    }
                 }
                 if(CollectionUtil.isNotEmpty(updateList)){
                     List<WbsParam> ul = new ArrayList<>();
                     for(WbsParamBean b:updateList){
                         WbsParam old = this.service.getById(b.getId());
-                        old.setIsDeleted(0);
-                        BeanUtils.copyProperties(b,old);
-                        ul.add(old);
+                        if(pb.isCommon()){
+                            if(old!=null&&!old.getK().equals(b.getK())){
+                                /*只有公式内容变化的时候才需要更新*/
+                                old.setIsDeleted(0);
+                                BeanUtils.copyProperties(b,old);
+                                ul.add(old);
+                            }
+                        }else{
+                            if(old!=null&&!old.getV().equals(b.getV())){
+                                /*只有公式内容变化的时候才需要更新*/
+                                old.setIsDeleted(0);
+                                BeanUtils.copyProperties(b,old);
+                                ul.add(old);
+                            }
+                        }
+
+                    }
+                    if(Func.isNotEmpty(ul)){
+                        this.service.saveOrUpdateBatch(ul);
                     }
-                    this.service.saveOrUpdateBatch(ul);
                 }
             }
             return R.success("操作成功");
         }catch (Exception e){
+            e.printStackTrace();
             return R.fail("操作失败");
         }