惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
A
About on SuperTechFans
博客园 - 司徒正美
D
DataBreaches.Net
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
I
InfoQ
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
小众软件
小众软件
G
Google Developers Blog
博客园 - 【当耐特】
U
Unit 42
美团技术团队
B
Blog
D
Docker
Blog — PlanetScale
Blog — PlanetScale

博客园 - timseng

解决网卡问题,很快啊 ai辅助升级前端安全更新(贼快!hh openclaw的token又耗完了,先不冲了,记录下折腾踩坑过程 (如果需要协助安装500,帮忙卸载250[doge]) VS Code我的配置(持续更新) 推广:flowable工作流引擎就是高级版本的数据库而已(一) springboot升级3x导致邮件发送失败:错误1 jakarta.mail.NoSuchProviderException: smtp nice du更好的du分析文件占用工具ncdu 使用MITMProxy转发https请求到本地、保存鉴权给本地请求(二) 前端发布shell脚本 virtualBox环境Ubuntu升级后太卡,转debian很丝滑 收藏:加不加「/」?Nginx location 路径与 proxy_pass 的规律 使用visjs分析flowable流程数据 浏览器标签页多行显示:使用Floorp浏览器 最先进的跨平台 Firefox 衍生品 开源之光 开源WAF:ModSecurity探究与部署 mysql备份恢复云端之核心:更新扫描MySQL库里的所有表的UPDATE_TIME,若发生变动就mysqldump 使用MITMProxy转发请求到本地、保存鉴权给本地请求 这款Ubuntu的默认壁纸水母是真漂亮啊 笑死!'m not going to tell you who, but I know someone who recently locked himself out of the system he was using for an article covering iptables by forgetting the SSH rule. itext的PdfPCell中设置行间距失败的问题 Java递归函数计算递归次数出错
动态条件实现java
timseng · 2024-07-12 · via 博客园 - timseng

提交页面设计

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;
  }

  @SneakyThrows
  public 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);
  }

  @SneakyThrows
  public static <T> T toObj(String json, Class<T> tClass) {
    if (StrUtil.isBlank(json)) {
      return null;
    }
    return new Gson().fromJson(json, tClass);
  }

  @SneakyThrows
  public static String toJson(Object obj) {
    return new Gson().toJson(obj);
  }
}

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