yangyj 2 rokov pred
rodič
commit
fde85a1ad3
16 zmenil súbory, kde vykonal 189 pridanie a 113 odobranie
  1. 14 6
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/dto/FormulaBean.java
  2. 2 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/ElementFormulaMapping.java
  3. 6 6
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/Formula.java
  4. 2 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/WbsFormElementVO.java
  5. 28 46
      blade-service/blade-manager/src/main/java/org/springblade/manager/controller/FormulaController.java
  6. 1 1
      blade-service/blade-manager/src/main/java/org/springblade/manager/feign/FormulaClientImpl.java
  7. 2 1
      blade-service/blade-manager/src/main/java/org/springblade/manager/formula/Container.java
  8. 9 1
      blade-service/blade-manager/src/main/java/org/springblade/manager/formula/KeyMapper.java
  9. 32 29
      blade-service/blade-manager/src/main/java/org/springblade/manager/formula/impl/TableElementConverter.java
  10. 1 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ElementFormulaMappingMapper.xml
  11. 3 3
      blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/FormulaMapper.xml
  12. 3 1
      blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeMapper.xml
  13. 4 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/IFormulaService.java
  14. 5 8
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java
  15. 75 11
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java
  16. 2 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeServiceImpl.java

+ 14 - 6
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/dto/FormulaBean.java

@@ -13,8 +13,10 @@ import javax.validation.constraints.Size;
  */
 @Data
 public class FormulaBean {
-    public static Integer GLOBAL=1;
-    public static Integer PART=10;
+    public static Integer WBS_GLOBAL=1;
+    public static Integer WBS_PART=2;
+    public static Integer PRO_GLOBAL=10;
+    public static Integer PRO_PART=20;
     private Long id;
     private String formula;
     private String remark;
@@ -32,11 +34,17 @@ public class FormulaBean {
         BeanUtils.copyProperties(this,f);
         return f;
     }
-    public Boolean isGlobal(){
-        return GLOBAL.equals(this.scope);
+    public Boolean isWbsGlobal(){
+        return WBS_GLOBAL.equals(this.scope);
     }
-    public Boolean isPart(){
-        return PART.equals(this.scope);
+    public Boolean isWbsPart(){
+        return WBS_PART.equals(this.scope);
+    }
+    public Boolean isProGlobal(){
+        return PRO_GLOBAL.equals(this.scope);
+    }
+    public Boolean isProPart(){
+        return PRO_PART.equals(this.scope);
     }
     public Boolean isNewOne(){
         return this.id==null;

+ 2 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/ElementFormulaMapping.java

@@ -23,4 +23,6 @@ public class ElementFormulaMapping extends BaseEntity {
     @Size(max = 20)
     private Long formulaId;
     private Long projectId;
+    private Integer scope;
+
 }

+ 6 - 6
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/Formula.java

@@ -29,21 +29,21 @@ public class Formula extends BaseEntity {
    private String number;
    private Integer orderNum;
    private String remark;
-   @Size(max = 20)
-   private Long nodeId;
-   @Size(max = 20)
-   private Long elementId;
+//   @Size(max = 20)
+//   private Long nodeId;
+//   @Size(max = 20)
+//   private Long elementId;
    private String map;
    private Integer scale;
    private Integer batch;
-   private Integer scope;
+//   private Integer scope;
    /**
     * 输出模式,0自动 1填充
     * */
    private Integer outm;
    /**关联的节点参数id
     * */
-   private Long paramId;
+//   private Long paramId;
 
 
    public List<String> getRelyList(){

+ 2 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/WbsFormElementVO.java

@@ -25,5 +25,7 @@ public class WbsFormElementVO extends WbsFormElement {
     private Integer isSaveFormula;
 
     private Integer globalFormula;
+    /**所属工序节点id*/
+    private Long nodeId;
 
 }

+ 28 - 46
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/FormulaController.java

@@ -83,25 +83,17 @@ public class FormulaController {
              fa.setFormula(StringUtils.escapeFormula(f.getFormula()));
              this.service.relyParse(fa);
              if(f.isNewOne()){
-                 if(f.isPart()){
-                     if(f.getNodeId()!=null){
-                         fa.setId(SnowFlakeUtil.getId());
-                         this.service.save(fa);
-                         ElementFormulaMapping efm = new ElementFormulaMapping();
-                         efm.setFormulaId(fa.getId());
-                         efm.setNodeId(f.getNodeId());
-                         efm.setElementId(f.getElementId());
-                         efm.setProjectId(f.getProjectId());
-                         this.elementFormulaMappingService.save(efm);
-                         /*假如不存在projectId则认为是系统级模版公式,必须同步给所有项目TODO*/
-                         return R.success("新增成功");
-                     }else{
-                       return   R.fail("保存不成功,请检查projectId、nodeId字段是否为空") ;
-                     }
-                 }else{
-                     /*假如不存在projectId则认为是系统级模版公式,必须同步给所有项目TODO*/
-                     return  R.status(this.service.save(fa));
-                 }
+                 fa.setId(SnowFlakeUtil.getId());
+                 this.service.save(fa);
+                 ElementFormulaMapping efm = new ElementFormulaMapping();
+                 efm.setFormulaId(fa.getId());
+                 efm.setElementId(f.getElementId());
+                 efm.setScope(f.getScope());
+                 efm.setNodeId(f.getNodeId());
+                 efm.setProjectId(f.getProjectId());
+                 this.elementFormulaMappingService.save(efm);
+                 /*假如不存在projectId则认为是系统级模版公式,必须同步给所有项目TODO*/
+                 return R.success("新增成功");
              }else{
                  return R.status(this.service.updateById(fa));
              }
@@ -132,38 +124,28 @@ public class FormulaController {
     @ApiOperation(value = "查看详情", notes = "传入id")
     @GetMapping("/detail")
     public R<FormulaBean> detail(FormulaBean f) {
-         Formula data = null;
-         if(f.isGlobal()){
-             if(f.getElementId()!=null) {
-                 data = this.service.getOne(Wrappers.<Formula>lambdaQuery().eq(Formula::getElementId, f.getElementId()).eq(Formula::getScope,FormulaBean.GLOBAL));
-             }
-         }else if(f.isPart()){
-             if(f.getElementId()!=null&&f.getNodeId()!=null) {
-                 ElementFormulaMapping efm =null;
-                 if(f.getProjectId()!=null){
-                   efm  = this.elementFormulaMappingService.getOne(Wrappers.<ElementFormulaMapping>lambdaQuery().eq(ElementFormulaMapping::getElementId, f.getElementId()).eq(ElementFormulaMapping::getNodeId, f.getNodeId()).eq(ElementFormulaMapping::getProjectId,f.getProjectId()));
-                 }else{
-                   efm  = this.elementFormulaMappingService.getOne(Wrappers.<ElementFormulaMapping>lambdaQuery().eq(ElementFormulaMapping::getElementId, f.getElementId()).eq(ElementFormulaMapping::getNodeId, f.getNodeId()));
-                 }
-                 if(efm!=null){
-                     data=this.service.getById(efm.getFormulaId());
-                 }
-             }
-         }
-         if(data!=null){
-             return R.data(BeanUtil.copy(data,FormulaBean.class));
-         }
+        if(f.getElementId()!=null){
+            StringBuilder sb = new StringBuilder("select b.* from m_element_formula_mapping a INNER JOIN m_formula b on a.formula_id=b.id where a.element_id="+f.getElementId()+" and b.is_deleted=0  and a.scope ="+f.getScope());
+            if(Func.isNotEmpty(f.getNodeId())){
+                sb.append(" and a.node_id=").append(f.getNodeId());
+            }
+            if(Func.isNotEmpty(f.getProjectId())){
+                sb.append(" and a.project_id=").append(f.getProjectId());
+            }
+            List<Map<String,Object>> maplist =    this.jdbcTemplate.queryForList("select b.* from m_element_formula_mapping a INNER JOIN m_formula b on a.formula_id=b.id where a.element_id="+f.getElementId()+" and b.is_deleted=0 and a.scope ="+f.getScope());
+            if(Func.isNotEmpty(maplist)){
+                return R.data(BeanUtil.toBean(maplist.get(0),FormulaBean.class));
+            }
+
+        }
         return R.success("无数据");
     }
 
     @ApiOperationSupport(order = 8)
     @ApiOperation(value = "公式翻页查询", notes = "公式翻页查询")
     @GetMapping("/page")
-    public IPage<FormulaBean> userSearch(@ApiIgnore FormulaBean param, @ApiIgnore Query query) {
+    public IPage<FormulaBean> pageSearch(@ApiIgnore FormulaBean param, @ApiIgnore Query query) {
         LambdaQueryWrapper<Formula> queryWrapper = Wrappers.<Formula>query().lambda();
-        if(Func.isNotEmpty(param.getNodeId())){
-            queryWrapper.eq(Formula::getNodeId,param.getNodeId());
-        }
         if(Func.isNotEmpty(param.getFormula())){
             queryWrapper.like(Formula::getFormula,param.getFormula());
         }
@@ -185,8 +167,8 @@ public class FormulaController {
                Map<String,Map> map = new HashMap<>();
                elementIds.forEach(e->{
                      Formula formula = new Formula();
-                     formula.setElementId(e);
-                     formula.setNodeId(bean.getNodeId());
+//                     formula.setElementId(e);
+//                     formula.setNodeId(bean.getNodeId());
                      formula.setOutm(Formula.FULL);
                      Map<String,String> m= new HashMap<>();
                      m.put("name",bean.getName());

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/feign/FormulaClientImpl.java

@@ -54,7 +54,7 @@ public class FormulaClientImpl implements  FormulaClient{
             Map<String, Object> queryForMap = this.jdbcTemplate.queryForMap("SELECT   a.p_key_id as nodeId,b.id as fieldId,b.e_key as field,c.init_table_name as tableName  from m_wbs_tree_contract a LEFT JOIN m_wbs_form_element b on a.id=b.f_id left JOIN m_wbs_tree c on a.id=c.id where b.e_key='"+key+"' and b.is_deleted=0 and a.p_key_id = (" + pkId + ")");
           if(Func.isNotEmpty(queryForMap)) {
               KeyMapper keyMapper = BeanUtil.toBean(queryForMap, KeyMapper.class);
-              Formula formula = this.service.getOne(Wrappers.<Formula>lambdaQuery().eq(Formula::getElementId, keyMapper.getFieldId()));
+              Formula formula = this.service.getById(keyMapper.getFormulaId());
               if(Func.isNotEmpty(formula)) {
                   formula.getRelyList().forEach(e -> {
                       sb.append(keysMap.get(e.split(StringPool.COLON)[1])).append(StringPool.COMMA);

+ 2 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/formula/Container.java

@@ -18,5 +18,6 @@ import java.util.Map;
 @Data
 public class Container {
     public   Map<String,Object> constantMap;
-    public  List<FormData> formDataList;
+    public   List<FormData> formDataList;
+    public   Map<Long,Map<String,Object>> crossDataMap;
 }

+ 9 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/formula/KeyMapper.java

@@ -10,10 +10,18 @@ import org.springblade.core.tool.utils.StringPool;
  */
 @Data
 public class KeyMapper {
-    private  Long nodeId;
+    /**pkId*/
+    private  Long pkId;
+    /**elementId*/
     private  Long fieldId;
+    /**eKey*/
     private  String field;
+    /**initTableName*/
     private  String tableName;
+    /**公式优先级*/
+    private Integer scope;
+    /**公式id*/
+    private Long formulaId;
     public String getCode(){
         return this.tableName+StringPool.COLON+this.field;
     }

+ 32 - 29
blade-service/blade-manager/src/main/java/org/springblade/manager/formula/impl/TableElementConverter.java

@@ -13,10 +13,13 @@ import org.springblade.manager.dto.ElementData;
 import org.springblade.manager.dto.FormData;
 import org.springblade.manager.entity.Formula;
 import org.springblade.manager.dto.Coords;
+import org.springblade.manager.entity.WbsTreeContract;
 import org.springblade.manager.formula.ITableElementConverter;
 import org.springblade.manager.formula.KeyMapper;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -32,6 +35,7 @@ public class TableElementConverter implements ITableElementConverter {
     private List<TableInfo> tableInfoList;
     private Long contractId;
     private Long nodeId;
+    private Long wbsTreeId;
     List<KeyMapper> keyMappers;
     List<Formula> formulas;
     /**公式执行时的元素对象*/
@@ -40,12 +44,13 @@ public class TableElementConverter implements ITableElementConverter {
     Map<String,ElementData> elementDataMap = new HashMap<>();
 
 
-    public TableElementConverter(List<TableInfo> tableInfoList, List<KeyMapper> keyMappers, List<Formula> formulas,Map<String,Map<String,String>> coordinateMap,Long nodeId) {
+    public TableElementConverter(List<TableInfo> tableInfoList, List<KeyMapper> keyMappers, List<Formula> formulas, Map<String,Map<String,String>> coordinateMap, WbsTreeContract wtc) {
         this.tableInfoList = tableInfoList;
         this.keyMappers = keyMappers;
         this.formulas = formulas;
         this.coordinateMap=coordinateMap;
-        this.nodeId=nodeId;
+        this.nodeId=wtc.getPKeyId();
+        this.wbsTreeId=Func.isNotEmpty(wtc.getOldId())? Long.valueOf(wtc.getOldId()) :wtc.getId();
         if(Func.isNotEmpty(tableInfoList)){
             this.contractId = Long.parseLong(tableInfoList.get(0).getContractId());
         }
@@ -55,6 +60,20 @@ public class TableElementConverter implements ITableElementConverter {
 
     }
 
+    public void relyParse(Formula f){
+        if(Func.isNotBlank(f.getFormula())){
+            List<String> l = new ArrayList<>();
+            Matcher m = Pattern.compile("(?<=E\\[)[^]]+(?=\\])").matcher(f.getFormula());
+            while (m.find()){
+                l.add(m.group());
+            }
+            if(l.size()>0){
+                f.setRely(String.join(",", l));
+            }else{
+                f.setRely("");
+            }
+        }
+    }
 
     public Boolean isPresent(){
         return BaseUtils.isNotNull(this.keyMappers,this.formulas,this.nodeId,this.contractId);
@@ -65,9 +84,9 @@ public class TableElementConverter implements ITableElementConverter {
     public void before() {
         if(Func.isNotEmpty(this.keyMappers)&&Func.isNotEmpty(this.formulas)){
             /*当前节点所有已经配置的公式*/
-            Map<String,Formula> formulaMap = new HashMap<>(this.formulas.size()*2);
+            Map<Long,Formula> formulaMap = new HashMap<>(this.formulas.size()*2);
             this.formulas.forEach(e->{
-                formulaMap.put(e.getElementId().toString(),e);
+                formulaMap.put(e.getId(),e);
             });
             /*根据元素id对keyMappers分组*/
             LinkedHashMap<String,List<KeyMapper>> dataMap =keyMappers.stream().collect(Collectors.groupingBy(KeyMapper::getCodeAndId,LinkedHashMap<String,List<KeyMapper>>::new,Collectors.toList()));
@@ -75,7 +94,12 @@ public class TableElementConverter implements ITableElementConverter {
                 String[] codeAndId = e.split(StringPool.AT);
                 List<KeyMapper> kms = dataMap.get(e);
                 KeyMapper one = kms.get(0);
-                FormData fd=new FormData(codeAndId[0],new ArrayList<>(),formulaMap.get(codeAndId[1]),this.coordinateMap.get(one.getTableName()).get(one.getField()));
+                Formula formula =formulaMap.get(one.getFormulaId());
+                /*过滤掉本节点的前缀信息*/
+                String sf= formula.getFormula().replace(this.wbsTreeId+StringPool.COLON,StringPool.EMPTY);
+                formula.setFormula(sf);
+                relyParse(formula);
+                FormData fd=new FormData(codeAndId[0],new ArrayList<>(),formula,this.coordinateMap.get(one.getTableName()).get(one.getField()));
                 /*初始化元素数据集*/
                 List<ElementData> eds =fd.getValues();
                 String coords = this.coordinateMap.get(fd.getTableName()).get(fd.getKey());
@@ -85,7 +109,7 @@ public class TableElementConverter implements ITableElementConverter {
                     for(int i=0;i<kms.size();i++){
                         /*每一页都有自己对立的Id*/
                         KeyMapper km=kms.get(i);
-                        TableInfo tableInfo =this.tableInfoList.stream().filter(t-> StringUtils.isEquals(t.getPkeyId(),km.getNodeId())).findFirst().orElseGet(TableInfo::new);
+                        TableInfo tableInfo =this.tableInfoList.stream().filter(t-> StringUtils.isEquals(t.getPkeyId(),km.getPkId())).findFirst().orElseGet(TableInfo::new);
                         int groupId=Integer.parseInt(tableInfo.getGroupId());
                         LinkedHashMap<String,String> pageData = tableInfo.getDataMap();
                         if(Func.isNotEmpty(pageData)){
@@ -112,27 +136,6 @@ public class TableElementConverter implements ITableElementConverter {
                 }else{
                     StaticLog.error("FORMULA_LOG@元素{}定位信息不存在,请检查配置",fd.getTableName()+StringPool.COLON+fd.getKey());
                 }
-//                AtomicInteger index= new AtomicInteger(0);
-//                kms.forEach(b->{
-//                    List<TableInfo> elements =this.tableInfoList.stream().filter(t-> StringUtils.isEquals(t.getPkeyId(),b.getNodeId())).collect(Collectors.toList());
-//                    //String coords = this.coordinateMap.get(fd.getTableName()).get(fd.getKey());
-//                    elements.forEach(k->{
-//                        /*把页面上所有的元素区映射对象*/
-//                        LinkedHashMap<String,String>   page = k.getDataMap();
-//                        String v=page.get(b.getField());
-//                        if(StringUtils.isNotEmpty(v)){
-//                            String[] values = v.split("☆");
-//                            for(String s:values){
-//                                String[] t = s.split("_\\^_");
-//                                String[] c =t[1].split("_");
-//                                ElementData ed = new ElementData(index.get(),0,t[0],Func.toInt(c[1]),Func.toInt(c[0]));
-//                                this.elementDataMap.put(StringUtils.join(b.getCode(),ed.getGroupId(),ed.getIndex(),Func.toInt(c[1]),Func.toInt(c[0]),StringPool.AT),ed);
-//                                eds.add(ed);
-//                            }
-//                        }
-//                        index.getAndIncrement();
-//                    });
-//                });
                 this.fds.add(fd);
             });
         }
@@ -151,7 +154,7 @@ public class TableElementConverter implements ITableElementConverter {
                     List<KeyMapper> kms = tabs.get(fd.getCode());
                     List<TableInfo> tables = new ArrayList<>();
                     for(TableInfo t:this.tableInfoList){
-                        if(kms.stream().anyMatch(e->StringUtils.isEquals(e.getNodeId(),t.getPkeyId()))){
+                        if(kms.stream().anyMatch(e->StringUtils.isEquals(e.getPkId(),t.getPkeyId()))){
                             /*获取将要写入的tableInfo*/
                             tables.add(t);
                         }
@@ -190,7 +193,7 @@ public class TableElementConverter implements ITableElementConverter {
             if(tableMap.containsKey(fd.getTableName())){
                 tables=tableMap.get(fd.getTableName());
             }else{
-                List<Long> tableIds=keyMappers.stream().filter(e -> StringUtils.isEquals(e.getCode(),fd.getCode())).map(KeyMapper::getNodeId).collect(Collectors.toList());
+                List<Long> tableIds=keyMappers.stream().filter(e -> StringUtils.isEquals(e.getCode(),fd.getCode())).map(KeyMapper::getPkId).collect(Collectors.toList());
                 tables = this.tableInfoList.stream().filter(e->tableIds.contains(Long.parseLong(e.getPkeyId()))).collect(Collectors.toList());
                 tableMap.put(fd.getTableName(),tables);
             }

+ 1 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ElementFormulaMappingMapper.xml

@@ -14,6 +14,7 @@
         <result column="nodeId" property="node_id"/>
         <result column="formulaId" property="formula_id"/>
         <result column="projectId" property="project_id"/>
+        <result column="scope" property="scope"/>
     </resultMap>
 
 </mapper>

+ 3 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/FormulaMapper.xml

@@ -15,10 +15,10 @@
         <result column="number" property="number"/>
         <result column="orderNum" property="order_num"/>
         <result column="remark" property="remark"/>
-        <result column="nodeId" property="node_id"/>
-        <result column="elementId" property="element_id"/>
+<!--        <result column="nodeId" property="node_id"/>-->
+<!--        <result column="elementId" property="element_id"/>-->
         <result column="map" property="map"/>
-        <result column="paramId" property="param_Id"/>
+<!--        <result column="paramId" property="param_Id"/>-->
         <result column="outm" property="outm"/>
         <result column="scale" property="scale"/>
         <result column="batch" property="batch"/>

+ 3 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/WbsTreeMapper.xml

@@ -89,6 +89,7 @@
         <result column="e_inspection_method" property="eInspectionMethod"/>
         <result column="tableElementKey" property="tableElementKey"/>
         <result column="initTableName" property="initTableName"/>
+        <result column="nodeId" property="nodeId"/>
     </resultMap>
 
     <insert id="addFormElement" parameterType="org.springblade.manager.dto.WbsFormElementDTO">
@@ -375,7 +376,8 @@
             is_deleted = 0 and f_id = #{id}
     </select>
     <select id="selectFormElements" resultMap="wbsFormElementMap">
-        select   f_id as fId,e_key,a.id,e_name,e_type,e_length,e_allow_deviation,e_Inspection_method,CONCAT(b.init_table_name,':',e_key) as tableElementKey,init_table_name as initTableName
+        select   f_id as fId,e_key,a.id,e_name,e_type,e_length,e_allow_deviation,e_Inspection_method,CONCAT(b.parent_id,':',b.init_table_name,':',e_key) as tableElementKey,init_table_name as initTableName,
+               b.parent_id as nodeId
         from m_wbs_form_element a inner join m_wbs_tree b on a.f_id=b.init_table_id
         where b.id=#{id} and a.is_deleted=0
     </select>

+ 4 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IFormulaService.java

@@ -3,6 +3,7 @@ package org.springblade.manager.service;
 import org.springblade.core.mp.base.BaseService;
 import org.springblade.manager.dto.FormData;
 import org.springblade.manager.entity.Formula;
+import org.springblade.manager.formula.KeyMapper;
 import org.springblade.manager.formula.impl.TableElementConverter;
 
 import java.util.List;
@@ -31,4 +32,7 @@ public interface IFormulaService extends BaseService<Formula> {
     IFormulaService calculate();
     /**格式化*/
     void format();
+
+    List<Formula> getFormulaList(List<KeyMapper> keyMapperList);
+    List<KeyMapper> getKeyMapperList(List<Long> ids);
 }

+ 5 - 8
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -326,26 +326,23 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         if (Func.isNotEmpty(tableInfoList)) {
             List<WbsTreeContract> tableAll = wbsTreeContractService.searchNodeAllTable(nodeId.toString(), "1", tableInfoList.get(0).getContractId(), tableInfoList.get(0).getProjectId());
             StopWatch stopWatch = new StopWatch();
-            String ids = tableInfoList.stream().map(TableInfo::getPkeyId).filter(Func::isNotEmpty).collect(Collectors.joining(","));
-            List<Map<String, Object>> list = this.jdbcTemplate.queryForList("SELECT   a.p_key_id as nodeId,b.id as fieldId,b.e_key as field,c.init_table_name as tableName  from m_wbs_tree_contract a LEFT JOIN m_wbs_form_element b on a.id=b.f_id left JOIN m_wbs_tree c on a.id=c.id where b.is_deleted=0 and a.p_key_id in (" + ids + ")");
-
-
-            List<KeyMapper> keyMappers = JSON.parseArray(JSONArray.toJSONString(list), KeyMapper.class);
+            List<KeyMapper> keyMappers = this.formulaService.getKeyMapperList(tableInfoList.stream().map(TableInfo::getPkeyId).filter(Func::isNotEmpty).map(Long::parseLong).collect(Collectors.toList()));
             if (Func.isNotEmpty(keyMappers)) {
                 Map<String, Map<String, String>> coordinateMap = new HashMap<>(keyMappers.size() * 2);
                 keyMappers.forEach(e -> {
                     try {
                         if (!coordinateMap.containsKey(e.getTableName())) {
                             /*不包含定位信息的情况执行*/
-                            coordinateMap.put(e.getTableName(), getTablbCols(e.getNodeId().toString(), null));
+                            coordinateMap.put(e.getTableName(), getTablbCols(e.getPkId().toString(), null));
                         }
                     } catch (FileNotFoundException fileNotFoundException) {
                         fileNotFoundException.printStackTrace();
                     }
                 });
                 stopWatch.start("公式处理");
-                List<Formula> formulas = this.formulaService.list(Wrappers.<Formula>lambdaQuery().in(Formula::getElementId, keyMappers.stream().map(KeyMapper::getFieldId).distinct().collect(Collectors.toList())));
-                TableElementConverter tec = new TableElementConverter(tableInfoList, keyMappers, formulas, coordinateMap, nodeId);
+                List<Formula> formulas = this.formulaService.getFormulaList(keyMappers);
+                WbsTreeContract wtc = this.wbsTreeContractService.getById(nodeId);
+                TableElementConverter tec = new TableElementConverter(tableInfoList, keyMappers, formulas, coordinateMap, wtc);
                 if (tec.isPresent()) {
                     tec.before();
                     this.formulaService.execute(tec);

+ 75 - 11
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -9,8 +9,10 @@ import com.jfireel.expression.node.CalculateNode;
 import com.mixsmart.utils.*;
 import lombok.AllArgsConstructor;
 import org.springblade.core.mp.base.BaseServiceImpl;
+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.StringPool;
 import org.springblade.manager.dto.ElementData;
 import org.springblade.manager.dto.FormData;
 import org.springblade.manager.dto.LocalVariable;
@@ -20,6 +22,7 @@ import org.springblade.manager.entity.WbsParam;
 import org.springblade.manager.entity.WbsTreeContract;
 import org.springblade.manager.formula.Container;
 import org.springblade.manager.formula.FormulaStrategyFactory;
+import org.springblade.manager.formula.KeyMapper;
 import org.springblade.manager.formula.impl.CompositeDataAccess;
 import org.springblade.manager.formula.impl.TableElementConverter;
 import org.springblade.manager.mapper.FormulaMapper;
@@ -44,7 +47,6 @@ import java.util.stream.Collectors;
 public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula> implements IFormulaService {
 
     private final IWbsParamService wpService;
-    private final IWbsTreeContractService treeContractService;
     private final FormulaStrategyFactory formulaStrategyFactory;
     private final IContractInfoService contractInfoService;
     private final IProjectInfoService projectInfoService;
@@ -67,6 +69,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
 
     public static final String ELE_CODE_REG= "(?<=E\\[)[^]]+(?=\\])";
     public static final Pattern P = Pattern.compile(ELE_CODE_REG);
+    public static final Pattern P2= Pattern.compile("(?<=E\\[)[^];]+:[^];]+:[^];]+(?=\\])");
     public static final String POLY_REG= "(checkpoints|avg|min|max|sum|join|repeat|removeEmpty|listAt)\\(([^)]+)\\)";
     public static final Pattern POLY = Pattern.compile(POLY_REG);
     public final static String CTI="ContractInfo";
@@ -96,7 +99,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
 
     @Override
     public void execute(TableElementConverter tec) {
-        WbsTreeContract one=  this.treeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId,tec.getNodeId()));
+        WbsTreeContract one=  this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId,tec.getNodeId()));
         this.execute(tec.getFds(),tec.getContractId(),Func.isNotEmpty(one.getOldId())?Long.parseLong(one.getOldId()):one.getParentId(),one.getPKeyId());
     }
 
@@ -119,20 +122,47 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
         /*表格名称*/
         List<WbsTreeContract> tableList =wbsTreeContractService.searchNodeAllTable(primaryKeyId.toString(), "1", contractId.toString(),info.getPId());
         this.env.constantMap.put(TABLE_LIST,tableList);
-//        List<String> tableNames=this.jdbcTemplate.queryForList("SELECT "+
-//                "          wt.node_name " +
-//                "          FROM m_wbs_tree_private AS wt" +
-//                "          WHERE wt.type = 2" +
-//                "          AND wt.is_deleted = 0" +
-//                "          AND wt.parent_id = "+primaryKeyId +
-//                "          AND wt.wbs_id = "+nodes.get(0).getWbsId() +
-//                "          AND wt.project_id ="+ info.getPId()+
-//                "          ORDER BY wt.sort, wt.node_name, wt.create_time",String.class);
+        /*通过判断元素名称来确定,加入汇总公式延后执行*/
         this.env.constantMap.put("tableNames",tableList.stream().map(WbsTreeContract::getFullName).collect(Collectors.toList()));
+        /*检查是否有跨节点数据*/
+        List<FormData> crossNodeFd=new ArrayList<>();
+        this.env.formDataList.forEach(fd->{
+            if(fd.executable()){
+               Matcher matcher=P2.matcher(fd.getFormula().getFormula());
+               while (matcher.find()){
+                   String[] arr = matcher.group().split(StringPool.COLON);
+                   List<WbsTreeContract> targets=this.wbsTreeContractService.list(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getContractId,info.getId()).eq(WbsTreeContract::getId,Long.parseLong(arr[0])));
+                   /*暂时先只取第一个满足条件的*/
+                   if(Func.isNotEmpty(targets)){
+                       WbsTreeContract cross = targets.get(0);
+                       Map<String,Object> dataMap= this.env.crossDataMap.computeIfAbsent(cross.getPKeyId(),(k)->this.jdbcTemplate.queryForMap("select * from " + arr[1] + " where p_key_id=" + k));
+                       if(dataMap.size()>0){
+                           String v= StringUtils.handleNull(dataMap.get(arr[2]));
+                           if(StringUtils.isNotEmpty(v)){
+                               crossNodeFd.add(new FormData(matcher.group(), Arrays.stream(v.split("☆")).map(s->{
+                                   String[] t = s.split("_\\^_");
+                                   String[] c =t[1].split("_");
+                                   return  new ElementData(0,0,t[0],Func.toInt(c[1]),Func.toInt(c[0]));
+                               }).collect(Collectors.toList()), null,StringPool.EMPTY));
+                           }else{
+                               crossNodeFd.add(new FormData(matcher.group(),new ArrayList<>(),null,StringPool.EMPTY));
+                           }
+                       }
+                   }
+
+               }
+            }
+        });
+        if(!crossNodeFd.isEmpty()){
+            System.out.println("跨节点元素:"+crossNodeFd.stream().map(FormData::getCode).collect(Collectors.joining(",")));
+           this.env.formDataList.addAll(crossNodeFd);
+        }
         /*检查项目*/
         return this;
     }
 
+
+
      /**引入关键字*/
     public void keyWord(Map<String,Object> constantMap){
            CustomFunction.KEYWORD_SET.forEach(e->{
@@ -354,6 +384,40 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
         }
     }
 
+    @Override
+    public List<KeyMapper> getKeyMapperList(List<Long> ids) {
+        List<Map<String,Object>> listMap = this.jdbcTemplate.queryForList("select b.init_table_name as tableName,c.p_key_id as pkId ,a.e_key as field,a.id  as fieldId,d.scope,d.formula_id as formulaId " +
+                "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_contract c on (c.old_id=b.id or c.id=b.id) " +
+                "INNER JOIN m_element_formula_mapping d on a.id=d.element_id  " +
+                "where c.p_key_id in("+ids.stream().map(String::valueOf).collect(Collectors.joining(","))+") " +
+                "ORDER BY b.init_table_name,d.scope");
+        if(Func.isNotEmpty(listMap)){
+            Map<Long,List<KeyMapper>> groupList= listMap.stream().map(m->BeanUtil.toBean(m, KeyMapper.class)).collect(Collectors.groupingBy(KeyMapper::getFormulaId,LinkedHashMap::new,Collectors.toList()));
+            Set<KeyMapper> set = new HashSet<>(groupList.size()*2);
+            for(Map.Entry<Long,List<KeyMapper>>entry:groupList.entrySet()){
+                entry.getValue().stream().max(Comparator.comparing(KeyMapper::getScope)).ifPresent(set::add);
+            }
+            if(set.size()>0){
+               return new ArrayList<>(set);
+            }
+        }
+        return Collections.emptyList();
+    }
+
+    @Override
+    public List<Formula> getFormulaList(List<KeyMapper> keyMapperList) {
+       if(Func.isNotEmpty(keyMapperList)){
+             List<Formula> result = this.listByIds(keyMapperList.stream().map(KeyMapper::getFormulaId).collect(Collectors.toList()));
+             if(Func.isNotEmpty(result)){
+                 return result;
+             }
+       }
+        return Collections.emptyList();
+    }
+
+
     public  Map<String,Object> getMap(Map<String,Object> main,String key){
         Map<String,Object> CNDMap = (Map<String, Object>) main.get(key);
         if(CNDMap==null){

+ 2 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeServiceImpl.java

@@ -333,6 +333,8 @@ public class WbsTreeServiceImpl extends BaseServiceImpl<WbsTreeMapper, WbsTree>
 
 
 
+
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean importWbsTree(MultipartFile excelFile, WbsTree wbsTreeFu, WbsTree wbsTree1) throws IOException {