yangyj 2 жил өмнө
parent
commit
c093215f9f

+ 1 - 1
blade-service/blade-manager/src/main/java/com/mixsmart/utils/CustomFunction.java

@@ -3335,7 +3335,7 @@ public class CustomFunction {
 		StringBuilder r = new StringBuilder();
 		if(o instanceof  List){
 			if(null==separator){
-				separator=space(1);
+				separator="、";
 			}
 			for(Object e:(List<Object>)o){
 				if(StringUtils.isNotEmpty(e)){

+ 24 - 0
blade-service/blade-manager/src/main/java/com/mixsmart/utils/StringUtils.java

@@ -6,6 +6,8 @@ import com.bstek.ureport.console.designer.ReportUtils;
 import com.jfirer.baseutil.encrypt.Md5Util;
 import com.mixsmart.constant.IMixConstant;
 import com.mixsmart.exception.NullArgumentException;
+import org.springblade.core.tool.utils.StringPool;
+
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
@@ -1467,6 +1469,28 @@ public class StringUtils {
 		return max;
 	}
 
+	/**
+	 * @Description 公式脚本转义
+	 * @Param [f]
+	 * @return java.lang.String
+	 * @Author yangyj
+	 * @Date 2022.10.13 21:25
+	 **/
+	public static String escapeFormula(String f){
+		if(isNotEmpty(f)) {
+			if (f.contains("&gt;") || f.contains("&lt;")) {
+				f = f.replace("&lt;", "<").replace("&gt;", ">");
+			}
+			if (f.contains(StringPool.QUOTE)) {
+				f = f.replaceAll(StringPool.QUOTE, StringPool.SINGLE_QUOTE);
+			}
+		}
+		return f;
+	}
 
+	public static void main(String[] args) {
+		String f= "FC.join(E['m_20220922155211_1572856268366807040:key_3'],\"\")";
+		System.out.println(escapeFormula(f));
+	}
 
 }

+ 2 - 6
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/FormulaController.java

@@ -53,9 +53,7 @@ public class FormulaController {
     @ApiOperationSupport(order = 4)
     @ApiOperation(value = "新增或修改", notes = "传入")
     public R save(@RequestBody Formula f) {
-        if(f.getFormula().contains("&gt;")||f.getFormula().contains("&lt;")){
-            f.setFormula(f.getFormula().replace("&lt;","<").replace("&gt;",">"));
-        }
+        f.setFormula(StringUtils.escapeFormula(f.getFormula()));
         if(this.service.count(Wrappers.<Formula>query().lambda().eq(Formula::getElementId,f.getElementId()))>0){
             return R.status(false);
         }
@@ -71,9 +69,7 @@ public class FormulaController {
     @ApiOperationSupport(order = 5)
     @ApiOperation(value = "修改", notes = "传入脚本")
     public R update( @RequestBody FormulaBean f) {
-        if(f.getFormula().contains("&gt;")||f.getFormula().contains("&lt;")){
-            f.setFormula(f.getFormula().replace("&lt;","<").replace("&gt;",">"));
-        }
+        f.setFormula(StringUtils.escapeFormula(f.getFormula()));
         if(f.getId()!=null){
             Formula old = this.service.getById(f.getId());
             if(old!=null){

+ 31 - 26
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -202,8 +202,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                 fd.getFormula().setFormula(tmp);
             }
         }
-        /*聚合运算*/
-        polymerization();
+
         return this;
     }
 
@@ -229,6 +228,8 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                 Formula formula =fd.getFormula();
                 String f=formula.getFormula();
                 if(Func.isNotBlank(f)){
+                    /*聚合运算*/
+                    polymerization();
                     Map<String, Object> currentMap = new HashMap<>(this.env.constantMap);
                     List<String>  relyList = fd.getFormula().getRelyList();
                     if(CollectionUtil.isNotEmpty(relyList)){
@@ -481,33 +482,37 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
             Formula formula = fd.getFormula();
             if(Func.isNotEmpty(formula)){
                 String f=formula.getFormula();
-                if(Func.isNotBlank(f)) {
-                    if (f.contains(CustomFunction.CLASS_CALL + "checkpoints(") ||f.contains(CustomFunction.CLASS_CALL + "avg(") || f.contains(CustomFunction.CLASS_CALL + "min(") || f.contains(CustomFunction.CLASS_CALL + "max(") || f.contains(CustomFunction.CLASS_CALL + "sum(")
-                      ||f.contains(CustomFunction.CLASS_CALL+"listAt(")||f.contains(CustomFunction.CLASS_CALL+"join(")||f.contains(CustomFunction.CLASS_CALL+"repeat(")||f.contains(CustomFunction.CLASS_CALL+"removeEmpty(")
-                    ) {
-                        /*聚合*/
-                        Matcher m = POLY.matcher(f);
-                        while (m.find()) {
-                            //List<String> elementCodes = CustomFunction.parseElementCode(m.group(2));
-                            Map<String, Object> currentMap = new HashMap<>(this.env.constantMap);
-                            List<String> relyList = fd.getFormula().getRelyList();
-                            List<FormData> tmp = this.env.formDataList.stream().filter(e -> relyList.contains(e.getCode())).collect(Collectors.toList());
-                            Map<String, Object> E = getMap(currentMap, "E");
-                            tmp.forEach(e -> E.put(e.getCode(), e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList())));
-                            Object data = Expression.parse(CustomFunction.CLASS_CALL + m.group()).calculate(currentMap);
-                            if(StringUtils.isNotEmpty(data)) {
-                                data = CustomFunction.setScale(data, StringUtils.getScale(data));
+                try {
+                    if(Func.isNotBlank(f)) {
+                        if (f.contains(CustomFunction.CLASS_CALL + "checkpoints(") ||f.contains(CustomFunction.CLASS_CALL + "avg(") || f.contains(CustomFunction.CLASS_CALL + "min(") || f.contains(CustomFunction.CLASS_CALL + "max(") || f.contains(CustomFunction.CLASS_CALL + "sum(")
+                                ||f.contains(CustomFunction.CLASS_CALL+"listAt(")||f.contains(CustomFunction.CLASS_CALL+"join(")||f.contains(CustomFunction.CLASS_CALL+"repeat(")||f.contains(CustomFunction.CLASS_CALL+"removeEmpty(")
+                        ) {
+                            /*聚合*/
+                            Matcher m = POLY.matcher(f);
+                            while (m.find()) {
+                                //List<String> elementCodes = CustomFunction.parseElementCode(m.group(2));
+                                Map<String, Object> currentMap = new HashMap<>(this.env.constantMap);
+                                List<String> relyList = fd.getFormula().getRelyList();
+                                List<FormData> tmp = this.env.formDataList.stream().filter(e -> relyList.contains(e.getCode())).collect(Collectors.toList());
+                                Map<String, Object> E = getMap(currentMap, "E");
+                                tmp.forEach(e -> E.put(e.getCode(), e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList())));
+                                Object data = Expression.parse(CustomFunction.CLASS_CALL + m.group()).calculate(currentMap);
+                                if(StringUtils.isNotEmpty(data)) {
+                                    data = CustomFunction.setScale(data, StringUtils.getScale(data));
+                                }
+                                /*必须要用括号套壳,不然无法处理负数*/
+                                String key ="HA"+HashUtil.identityHashCode(data);
+                                this.env.constantMap.put(key,data);
+                                f = f.replace(CustomFunction.CLASS_CALL + m.group(), key);
+                                fd.getFormula().setFormula(f);
+                                /*更新依赖*/
+                                relyParse(fd.getFormula());
                             }
-                            /*必须要用括号套壳,不然无法处理负数*/
-                            String key ="HA"+HashUtil.identityHashCode(data);
-                            this.env.constantMap.put(key,data);
-                            f = f.replace(CustomFunction.CLASS_CALL + m.group(), key);
-                            fd.getFormula().setFormula(f);
-                            /*更新依赖*/
-                            relyParse(fd.getFormula());
                         }
+                        System.out.println("聚合处理");
                     }
-                    System.out.println("聚合处理");
+                }catch (Exception e){
+                    e.printStackTrace();
                 }
             }
         }