动态条件实现java

news/2024/9/21 1:22:17/文章来源:https://www.cnblogs.com/timseng/p/18282112

提交页面设计

 

json数据格式

[{"name": "规则1","action": {"with": [{"type": "SHOW","targets": ["xd_hh_158444776217"]},{"type": "HIDE","targets": ["xd_hh_158772314112"]}],"other": [{"type": "HIDE","targets": ["xd_hh_158444776217"]},{"type": "SHOW","targets": ["xd_hh_158772314112"]}]},"condition": {"groupMode": true,"conditionList": [{"mode": true,"conditionList": [{"key": "xd_hh_162172344044","value": [{"key": "16","value": "16"}],"expression": "in"}]}]}}
]

java解析

  public Set<String> getRuleHideShowList(String rule,Map<String, Object> variables,Boolean returnHide)throws ErrorResponseException {Set<String> showIds = new HashSet<>();Set<String> hideIds = new HashSet<>();if(StrUtil.isNotBlank(rule)){List<FormRuleDto> formRuleDtoList = CommonUtil.toArray(rule, FormRuleDto.class);// 遍历每个规则for (FormRuleDto formRuleDto : formRuleDtoList) {Boolean with=null;FormRuleConditionDto formRuleConditionDto=formRuleDto.getCondition();for (FormRuleConditionItemDto formRuleConditionItemDto : formRuleConditionDto.getConditionList()) {Boolean getConditionListExpressionValue=null;for (FormRuleConditionItemItemDto formRuleConditionItemItemDto : formRuleConditionItemDto.getConditionList()) {boolean expressionValue=false;String key = formRuleConditionItemItemDto.getKey();Object value = formRuleConditionItemItemDto.getValue();String expression = formRuleConditionItemItemDto.getExpression();if(Objects.equals(expression, "in")){Object keyValue =variables.get(key);expressionValue=Objects.equals(value,keyValue);}else if(Objects.equals(expression, "notin"))
{ Object keyValue =variables.get(key);
expressionValue=!Objects.equals(value,keyValue);
}else
{log.error("该动态表单表达式暂未支持,请联系管理员:{}", new Gson().toJson(rule));ErrorResponseException exception = new ErrorResponseException(HttpStatus.NOT_FOUND);exception.setDetail("该动态表单表达式暂未支持,请联系管理员:" + expression);throw exception;}//if(formRuleConditionItemDto.getMode()){if(getConditionListExpressionValue==null){getConditionListExpressionValue=expressionValue;}else{getConditionListExpressionValue=getConditionListExpressionValue && expressionValue;}}else{//if(getConditionListExpressionValue==null){getConditionListExpressionValue=expressionValue;}else{getConditionListExpressionValue=getConditionListExpressionValue || expressionValue;}}}//if(formRuleConditionDto.getGroupMode()){if(with==null){with=getConditionListExpressionValue;}else{with=with && getConditionListExpressionValue;}}else{//if(with==null){with=getConditionListExpressionValue;}else{with=with || getConditionListExpressionValue;}}}// 获取所有action子节点FormRuleActionDto action=formRuleDto.getAction();if(with!=null && action!=null){if(with){List<FormRuleActionItemDto> actionWith= action.getWith();for (FormRuleActionItemDto actionItemDto : actionWith) {if(Objects.equals(actionItemDto.getType(), "SHOW")){showIds.addAll(actionItemDto.getTargets());}if(Objects.equals(actionItemDto.getType(), "HIDE")){hideIds.addAll(actionItemDto.getTargets());}}}else{List<FormRuleActionItemDto> actionOther= action.getOther();for (FormRuleActionItemDto actionItemDto : actionOther) {if(Objects.equals(actionItemDto.getType(), "SHOW")){showIds.addAll(actionItemDto.getTargets());}if(Objects.equals(actionItemDto.getType(), "HIDE")){hideIds.addAll(actionItemDto.getTargets());}}}}}}if(returnHide){return hideIds;}else{return showIds;}}

支撑pdo

import lombok.Data;@Data
public class FormRuleDto {String name;FormRuleActionDto action;FormRuleConditionDto condition;
}import lombok.Data;@Data
public class FormRuleConditionItemItemDto {String key;Object value;String expression;}
import java.util.List;
import lombok.Data;@Data
public class FormRuleConditionItemDto {Boolean mode;List<FormRuleConditionItemItemDto> conditionList;}
import java.util.List;
import lombok.Data;@Data
public class FormRuleConditionDto {Boolean groupMode;List<FormRuleConditionItemDto> conditionList;}
import java.util.List;
import lombok.Data;@Data
public class FormRuleActionItemDto {//  SHOW HIDE
  String type;List<String> targets;}
import java.util.List;
import lombok.Data;@Data
public class FormRuleActionDto {List<FormRuleActionItemDto> with;List<FormRuleActionItemDto> other;}import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xd.flow.engine.bo.flow.NodeUser;
import lombok.SneakyThrows;import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
public class CommonUtil {/*** 1-26* 数字转大写英文字符** @param num* @return*/public static String numberToLetter(int num) {if (num <= 0) {return null;}String letter = "";num--;do {if (letter.length() > 0) {num--;}letter = ((char) (num % 26 + (int) 'A')) + letter;num = (int) ((num - num % 26) / 26);} while (num > 0);return letter;}@SneakyThrowspublic static <T> List<T> toArray(String json, Class<T> tClass) {Type type = TypeToken.getParameterized(ArrayList.class, tClass).getType();return new Gson().fromJson(json, type);
//    return JSON.parseArray(json, tClass);
  }@SneakyThrowspublic static <T> T toObj(String json, Class<T> tClass) {if (StrUtil.isBlank(json)) {return null;}return new Gson().fromJson(json, tClass);}@SneakyThrowspublic static String toJson(Object obj) {return new Gson().toJson(obj);}
}

该版本只支持in表达式可拓展startWith endWith contains等,动作支持hide show可拓展为其他动作

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/742682.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

玩一玩yolov5 自己训练模型识别马克杯

python 虚拟环境搭建 conda create -n yolo python==3.8yolov5下载 git clone https://github.com/ultralytics/yolov5 cd yolov5 activate yolo pip install -r requirements.txt准备数据集 官方介绍:https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data 建立文件…

web渗透——信息收集

切记:未经授权,禁止对任何网站进行渗透测试whois查询 常用网址: 爱站:https://www.aizhan.com/ 站长之家:https://whois.chinaz.com/ bugscaner:http://whois.bugscaner.com/ 端口扫描 常用工具: Nmap工具Masscan CMS识别 常用网址: TideFinger潮汐:http://finger.tides…

记一次处理挖矿程序xmrig的过程

现象 挖矿xmrig占用100%CPU处理过程 kill掉进程,后会立即启动# kill pid # kill 14527通过pid找到病毒文件地址 # ls -l /proc/PID/exe找到病毒文件夹目录为 /root/c3pool使用rm删除文件会报权限错误 使用lsattr查看隐藏权限为e表示可以追加 # lsattr miner.sh -------------…

Algorithm notes and references

Algorithm notes and references Version:2024/02/03 Data Structure 1. Segment Tree Beats (segb) from 题解 P4314 【CPU监控】 - He_Ren 的博客 - 洛谷博客 (luogu.com.cn) lazy tag 实际上可以看作是对于该节点表示的区间的操作序列,这也是线段树的精髓所在 push_down 操…

浅谈HTTP中Get与Post的区别

Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE。URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP中的GET,POST,PUT,DELETE就对应着对这个资源的查,改,增,删4个操作。到这里,大家应该有…

ExtJS中layout的12种布局风格

extjs的容器组件都可以设置它的显示风格,它的有效值有 absolute, accordion, anchor, border, card, column, fit, form and table. 一共9种。 另外几种见: http://www.sencha.com/deploy/dev/examples/layout-browser/layout-browser.html 里面有详细的例子。 absolute …

extjs中treepanel例子

:TreePanel继承自Panel,在ExtJS中使用树控件含有丰富的属性和方法实现复杂的功能。其中Ext.tree.TreeNode代表一个树节点,比较常用的属性包括text、id、icon、checked等、异步树Ext.tree.AsyncTreeNode、树加载器Ext.tree.TreeLoader。下面介绍几个extjs中treepanel例子一、…

全球单体容量最大漂浮式风电平台“明阳天成号”正式亮相

7月12日,全球单体容量最大的16.6MW漂浮式风电平台“明阳天成号”启航仪式在中船黄埔文冲造船厂举办,中山市委书记、市人大常委会主任郭文海主礼启航仪式。“明阳天成号”于7月3日完成吊装,经过各项调试准备工作后正式亮相,并将择日拖航至广东阳江海域。据测算,“明阳天成号…

从程序员的角度来看为什么我们需要工作流

每一个程序员,在接触到工作流的时候,都会有这么一个疑问——我用一般的方法可以实现,为什么还要用工作流?我曾经也问过这个问题,不过现在稍微有点明白了。别着急要答案,看过下面的例子,或许你也就明白一些了。这是一个简单的业务——订货流程:客户提交采购订单 业务员执…

003_python3 解释器 注释 运算符

Python3 解释器 1.Linux设置环境变量 $ PATH=$PATH:/usr/local/python3/bin/python3 # 设置环境变量 2.交互式编程 $ python # 启动Python解释器 3.脚本式编程 Windows中写入脚本xx.py文件,执行 python xx.py # cmd 当中直接执行 Linux中文件顶部写入 #! /usr/bin/env py…

2024暑假集训测试4

前言比赛链接这次和高中一起打的,排名一次比一次低了,差点出前一半了…… 主要是 T1 \(dijkstra\) 唐氏复杂度打假了,T2 挂分,T3 没想出来压位,T4 题都没看。 T1 最短路原题:luogu P2966 [USACO09DEC] Cow Toll Paths G。本题考察对 \(Floyed\) 的理解,\(Floyed\) 数组在…

Bootstrap图片样式使用方法

在Bootstrap中自带了几种图片样式,能够让你很快地对其进行使用,这几种样式使用起来相当简单,让我们一起来看看怎么快速调用Bootstrap图片样式。Bootstrap图片圆角样式 在现今的网站建设中,由于扁平化设计的趋势,我们经常会用用到一些CSS3的特性,例如圆角、渐变、阴影等。…