From 5d479dc2a55fe70f51ef8e19359eab9f001f85a3 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 3 Sep 2024 19:00:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?= =?UTF-8?q?=E7=BB=84=E5=90=88=E8=BF=87=E6=BB=A4=E6=9D=A1=E4=BB=B6=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1237746444632064]后端-组合过滤条件代码优化 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1237746444632064 --- .../condition/dto/ConditionConfigVo.java | 175 ++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 src/main/java/neatlogic/framework/process/condition/dto/ConditionConfigVo.java diff --git a/src/main/java/neatlogic/framework/process/condition/dto/ConditionConfigVo.java b/src/main/java/neatlogic/framework/process/condition/dto/ConditionConfigVo.java new file mode 100644 index 00000000..da5ae59a --- /dev/null +++ b/src/main/java/neatlogic/framework/process/condition/dto/ConditionConfigVo.java @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.framework.process.condition.dto; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.asynchronization.threadlocal.ConditionParamContext; +import neatlogic.framework.common.constvalue.GroupSearch; +import neatlogic.framework.condition.dto.ConditionBaseVo; +import neatlogic.framework.condition.dto.ConditionConfigBaseVo; +import neatlogic.framework.condition.dto.ConditionGroupBaseVo; +import neatlogic.framework.condition.dto.RelVo; +import neatlogic.framework.util.ConditionUtil; +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class ConditionConfigVo extends ConditionConfigBaseVo> { + private static final Logger logger = LoggerFactory.getLogger(ConditionConfigVo.class); + + public String buildScript() { + if (CollectionUtils.isNotEmpty(conditionGroupRelList)) { + StringBuilder script = new StringBuilder(); + script.append("("); + String toUuid = null; + for (RelVo conditionGroupRelVo : conditionGroupRelList) { + script.append(getConditionGroupByUuid(conditionGroupRelVo.getFrom()).buildScript()); + script.append("and".equals(conditionGroupRelVo.getJoinType()) ? " && " : " || "); + toUuid = conditionGroupRelVo.getTo(); + } + script.append(getConditionGroupByUuid(toUuid).buildScript()); + script.append(")"); + return script.toString(); + } else { + ConditionGroupVo conditionGroupVo = conditionGroupList.get(0); + return conditionGroupVo.buildScript(); + } + } + public static class ConditionGroupVo extends ConditionGroupBaseVo { + + public String buildScript() { + if (!CollectionUtils.isEmpty(conditionRelList)) { + StringBuilder script = new StringBuilder(); + script.append("("); + String toUuid = null; + for (RelVo conditionRelVo : conditionRelList) { + script.append(getConditionByUuid(conditionRelVo.getFrom()).predicate()); + script.append("and".equals(conditionRelVo.getJoinType()) ? " && " : " || "); + toUuid = conditionRelVo.getTo(); + } + script.append(getConditionByUuid(toUuid).predicate()); + script.append(")"); + return script.toString(); + } else { + ConditionVo conditionVo = conditionList.get(0); + return String.valueOf(conditionVo.predicate()); + } + } + } + + public static class ConditionVo extends ConditionBaseVo { + private String type; + private Boolean result; + private String error; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Boolean getResult() { + return result; + } + + public void setResult(Boolean result) { + this.result = result; + } + + public String getError() { + return error; + } + + public void setError(String error) { + this.error = error; + } + + public boolean predicate() { + result = false; + ConditionParamContext context = ConditionParamContext.get(); + if (context != null) { + List currentValueList = new ArrayList<>(); + JSONObject paramData = context.getParamData(); + Object paramValue = paramData.get(this.name); + if (paramValue != null) { + if (paramValue instanceof String) { + currentValueList.add(GroupSearch.removePrefix((String) paramValue)); + } else if (paramValue instanceof List) { + List values = JSON.parseArray(JSON.toJSONString(paramValue), String.class); + for (String value : values) { + currentValueList.add(GroupSearch.removePrefix(value)); + } + } else { + currentValueList.add(GroupSearch.removePrefix(paramValue.toString())); + } + } + + List targetValueList = new ArrayList<>(); + if (valueList != null) { + if (valueList instanceof String) { + targetValueList.add(GroupSearch.removePrefix((String) valueList)); + } else if (valueList instanceof List) { + List values = JSON.parseArray(JSON.toJSONString(valueList), String.class); + for (String value : values) { + targetValueList.add(GroupSearch.removePrefix(value)); + } + } else { + targetValueList.add(GroupSearch.removePrefix(valueList.toString())); + } + } + try { + result = ConditionUtil.predicate(currentValueList, this.expression, targetValueList); + } catch (Exception e) { + error = e.getMessage(); + logger.warn(e.getMessage(), e); + } + /* 将参数名称、表达式、值的value翻译成对应text,目前条件步骤生成活动时用到**/ +// if (context.isTranslate()) { +// if ("common".equals(type)) { +// IConditionHandler conditionHandler = ConditionHandlerFactory.getHandler(name); +// if (conditionHandler != null) { +// valueList = conditionHandler.valueConversionText(valueList, null); +// name = conditionHandler.getDisplayName(); +// } +// } else if ("form".equals(type)) { +// IConditionHandler conditionHandler = ConditionHandlerFactory.getHandler("form"); +// if (conditionHandler != null) { +// JSONObject formConfig = context.getFormConfig(); +// if (MapUtils.isNotEmpty(formConfig)) { +// JSONObject configObj = new JSONObject(); +// configObj.put("attributeUuid", name); +// configObj.put("formConfig", formConfig); +// valueList = conditionHandler.valueConversionText(valueList, configObj); +// name = configObj.getString("name"); +// } +// } +// } +// this.expression = Expression.getExpressionName(this.expression); +// } + } + + return result; + } + } +} -- Gitee From 3e4898f3a470398e44b2817b75e68ef02a6aba18 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 3 Sep 2024 19:01:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-?= =?UTF-8?q?=E7=BB=84=E5=90=88=E8=BF=87=E6=BB=A4=E6=9D=A1=E4=BB=B6=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1237746444632064]后端-组合过滤条件代码优化 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1237746444632064 --- .../framework/process/condition/dto/ConditionConfigVo.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/neatlogic/framework/process/condition/dto/ConditionConfigVo.java b/src/main/java/neatlogic/framework/process/condition/dto/ConditionConfigVo.java index da5ae59a..f08538fb 100644 --- a/src/main/java/neatlogic/framework/process/condition/dto/ConditionConfigVo.java +++ b/src/main/java/neatlogic/framework/process/condition/dto/ConditionConfigVo.java @@ -54,6 +54,7 @@ public class ConditionConfigVo extends ConditionConfigBaseVo extends ConditionGroupBaseVo { public String buildScript() { -- Gitee