编辑代码

//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。


/**
 * 
 * @param verifyActionConf 验证动作配置
 * @param defaultVerifyAction 默认的验证动作
 * @param verifyActionMap 规则命中验证动作
 * @param strategy 最终策略结果
 * @return
 */
def visual_verifyActionSummary(verifyActionConf, defaultVerifyAction, verifyActionMap, strategy) {
    // 如果策略不是 'verify',则返回 null
    if (strategy != 'verify') {
        return null
    }

    // 默认的最终验证动作
    String finalVerifyAction = defaultVerifyAction

    // 如果有验证动作映射,则进行计算
    if (verifyActionMap) {
        // 用于记录最大的分数
        Integer maxScore = 0

        // 遍历验证动作映射
        verifyActionMap.each { key, value ->
            // 解析动作字符串
            def actions = value as String
            def actionGroups = actions.split("\\|")

            // 计算每个分组的总分,取最小的分数
            Integer minGroupScore = actionGroups.collect { group ->
                group.split("&").sum { action ->
                    verifyActionConf.get(action) as Integer
                }
            }.min() as Integer

            // 更新最大分数和最终验证动作
            if (minGroupScore > maxScore) {
                maxScore = minGroupScore
                finalVerifyAction = value
            }
        }
    }

    // 格式化最终验证动作为要求的格式
    def formattedActions = finalVerifyAction.split("\\|").collect { group ->
        "(" + group.replaceAll("&", " and ") + ")"
    }

    // 返回格式化后的验证动作字符串
    return formattedActions.join(" or ")
  }

def verifyActionConf = ['phone':1,'2fa':3,'email':2]
def defaultVerifyAction =''
def inner_verifyActionMap = [:]
inner_verifyActionMap.put("node_e6933e0c.emptyNode","email&phone|phone&email")
def strategy='verify'

def ss=visual_verifyActionSummary(verifyActionConf,defaultVerifyAction,inner_verifyActionMap,strategy)
println(ss)