Parcourir la source

试验-公式
1、switch-case公式开发

LHB il y a 1 semaine
Parent
commit
9d6a77b9e2

+ 41 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -2028,6 +2028,40 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
             FormulaUtils.write(fd, data, !fd.getIsRemoveEmpty());
         }
     }
+    //处理
+    public void write(String key, String value, TableElementConverter tec) {
+        Map<String, FormData> formDataMap = tec.getFormDataMap();
+
+        key = key.replace("E[","").replace("'","").replace("]","");
+
+        FormData formData = formDataMap.get(key);
+        formData.setFinished(true);
+        formData.setUpdate(1);
+        List<ElementData> values = formData.getValues();
+        //取的值是从其他元素获取的
+        if(value.contains("E[")){
+            value = value.replace("E[","").replace("'","").replace("]","");
+            //获取value的值
+            FormData valueFormData = formDataMap.get(value);
+            List<ElementData> values1 = valueFormData.getValues();
+            //如果是一个元素多个单元格 便利每一个单元格赋值
+            if(CollectionUtil.isNotEmpty(values) && CollectionUtil.isNotEmpty(values1)){
+                int count = values.size();
+                if(values1.size() < count){
+                    count = values1.size();
+                }
+                for (int i = 0; i < count; i++) {
+                    ElementData elementData = values.get(i);
+                    ElementData elementData1 = values1.get(i);
+                    elementData.setValue(elementData1.getValue());
+                }
+            }
+        }else{
+            if(CollectionUtil.isNotEmpty(values)){
+                values.get(0).setValue(value);
+            }
+        }
+    }
 
     /**
      * 加页增容
@@ -5724,7 +5758,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
 
                         try {
                             // 提取括号内的内容(去掉外层的ifelse())
-                            String content = el.replaceFirst("^" + FC_REG + "ifelseMulti\\(", "").replaceFirst("\\)$", "");
+                            String content = el.replaceFirst("^" + FC_REG + "switchCase\\(", "").replaceFirst("\\)$", "");
 
 
                             //
@@ -5737,7 +5771,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                             String[] ruleArray = content.trim().split(";");
                             for (String rule : ruleArray) {
                                 if (rule.startsWith("else")) {
-                                    String[] parts = rule.split(" -> ");
+                                    String[] parts = rule.split("->");
                                     String[] action = parts[1].split("=");
                                     key = action[0];
                                     value = action[1];
@@ -5753,8 +5787,11 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                                     break;
                                 }
                             }
-
-                            f = f.replace(el, putDataWithKey(value, tec));
+                            f = "";
+                            if(key != null && value != null){
+                                /*数据回写*/
+                                write(key,value,tec);
+                            }
                         } catch (Exception e) {
                             f = f.replace(el, "解析错误");
                         }