From a6f90b8aeea0f675440295b52dcf9fc265c51044 Mon Sep 17 00:00:00 2001 From: WinfredLIN Date: Thu, 16 Jan 2025 18:41:02 +0800 Subject: [PATCH 1/2] new word set in i18n package #2130 --- sqle/locale/active.en.toml | 5 +++++ sqle/locale/active.zh.toml | 5 +++++ sqle/locale/message_zh.go | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/sqle/locale/active.en.toml b/sqle/locale/active.en.toml index 3b559b8b0..7226fe38e 100644 --- a/sqle/locale/active.en.toml +++ b/sqle/locale/active.en.toml @@ -244,6 +244,10 @@ ParamSQLMinSecond = "SQL Minimum Execution Time (Second)" ParamSlowLogCollectInput = "Collect Source" ParamTopN = "Top N" PipelineCmdUsage = "#Usage#\n1. Ensure the user running this command has execution permission for scannerd.\n2. Execute the start command in the directory where the scannerd file is located.\n#Start Command#\n" +RuleLevelError = "Error" +RuleLevelNormal = "Normal" +RuleLevelNotice = "Notice" +RuleLevelWarn = "Warn" RuleTemplateDesc = "Rule template description" RuleTemplateInstType = "instance type" RuleTemplateName = "Rule template name" @@ -301,6 +305,7 @@ TaskStatusExecuteFailed = "Execution failed" TaskStatusExecuteSucceeded = "Execution succeeded" TaskStatusExecuting = "Executing" TaskStatusManuallyExecuted = "Manually executed" +WordIs = "is" WorkflowNotifyTypeDefault = "SQL Workflow Unknown Requests" WorkflowNotifyTypeExecuteFail = "SQL Workflow Execute Failed" WorkflowNotifyTypeExecuteSuccess = "SQL Workflow Execute Succeeded" diff --git a/sqle/locale/active.zh.toml b/sqle/locale/active.zh.toml index c01fbd8c8..a3ab86137 100644 --- a/sqle/locale/active.zh.toml +++ b/sqle/locale/active.zh.toml @@ -244,6 +244,10 @@ ParamSQLMinSecond = "SQL 最小执行时间(秒)" ParamSlowLogCollectInput = "采集来源" ParamTopN = "Top N" PipelineCmdUsage = "#使用方法#\n1. 确保运行该命令的用户具有scannerd的执行权限。\n2. 在scannerd文件所在目录执行启动命令。\n#启动命令#\n" +RuleLevelError = "错误" +RuleLevelNormal = "常规" +RuleLevelNotice = "提示" +RuleLevelWarn = "警告" RuleTemplateDesc = "规则模板描述" RuleTemplateInstType = "数据源类型" RuleTemplateName = "规则模板名" @@ -301,6 +305,7 @@ TaskStatusExecuteFailed = "上线失败" TaskStatusExecuteSucceeded = "上线成功" TaskStatusExecuting = "正在上线" TaskStatusManuallyExecuted = "手动上线" +WordIs = "为" WorkflowNotifyTypeDefault = "SQL工单未知请求" WorkflowNotifyTypeExecuteFail = "SQL工单上线失败" WorkflowNotifyTypeExecuteSuccess = "SQL工单上线成功" diff --git a/sqle/locale/message_zh.go b/sqle/locale/message_zh.go index 74ed4e2d2..49b2c7692 100644 --- a/sqle/locale/message_zh.go +++ b/sqle/locale/message_zh.go @@ -31,6 +31,15 @@ var ( RuleTemplateRuleErr = &i18n.Message{ID: "RuleTemplateRuleErr", Other: "问题"} ) +// rule +var ( + RuleLevelError = &i18n.Message{ID: "RuleLevelError", Other: "错误"} + RuleLevelWarn = &i18n.Message{ID: "RuleLevelWarn", Other: "警告"} + RuleLevelNotice = &i18n.Message{ID: "RuleLevelNotice", Other: "提示"} + RuleLevelNormal = &i18n.Message{ID: "RuleLevelNormal", Other: "常规"} + WordIs = &i18n.Message{ID: "WordIs", Other: "为"} +) + // task var ( TaskStatusExecuting = &i18n.Message{ID: "TaskStatusExecuting", Other: "正在上线"} From d62b06e72f2563edcf79058d4d63bee0efa789c5 Mon Sep 17 00:00:00 2001 From: WinfredLIN Date: Thu, 16 Jan 2025 18:41:40 +0800 Subject: [PATCH 2/2] convert number string to audit level string #2130 --- sqle/server/auditplan/job_task_handler.go | 25 +++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/sqle/server/auditplan/job_task_handler.go b/sqle/server/auditplan/job_task_handler.go index 32b41599c..f47d59bfb 100644 --- a/sqle/server/auditplan/job_task_handler.go +++ b/sqle/server/auditplan/job_task_handler.go @@ -1,6 +1,7 @@ package auditplan import ( + "context" "database/sql" "errors" "fmt" @@ -8,6 +9,7 @@ import ( "time" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" + "github.com/actiontech/sqle/sqle/locale" "github.com/actiontech/sqle/sqle/model" "github.com/actiontech/sqle/sqle/server" "github.com/sirupsen/logrus" @@ -141,7 +143,7 @@ func SetSQLPriority(sqlList []*model.SQLManageRecord) ([]*model.SQLManageRecord, } auditPlanMap[sourceId] = auditPlan } - priority, _, err := GetSingleSQLPriorityWithReasons(auditPlan, sql_) + priority, _, err := GetSingleSQLPriorityWithReasons(context.TODO(), auditPlan, sql_) if err != nil { return nil, err } @@ -156,7 +158,7 @@ func SetSQLPriority(sqlList []*model.SQLManageRecord) ([]*model.SQLManageRecord, } // 获取SQL的优先级以及优先级触发的原因,只有高优先级或者无优先级,若是高优先级,则返回model.PriorityHigh=high,如果无优先级则返回空字符串 -func GetSingleSQLPriorityWithReasons(auditPlan *model.AuditPlanV2, sql *model.SQLManageRecord) (priority string, reasons []string, err error) { +func GetSingleSQLPriorityWithReasons(ctx context.Context, auditPlan *model.AuditPlanV2, sql *model.SQLManageRecord) (priority string, reasons []string, err error) { if auditPlan == nil || sql == nil { return "", reasons, nil } @@ -166,12 +168,14 @@ func GetSingleSQLPriorityWithReasons(auditPlan *model.AuditPlanV2, sql *model.SQ } toAuditLevel := func(valueToBeCompared string) string { switch valueToBeCompared { + case "0": + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.RuleLevelNormal) case "1": - return "提示" + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.RuleLevelNotice) case "2": - return "警告" + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.RuleLevelWarn) case "3": - return "错误" + return locale.Bundle.LocalizeMsgByCtx(ctx, locale.RuleLevelError) default: return valueToBeCompared } @@ -189,6 +193,8 @@ func GetSingleSQLPriorityWithReasons(auditPlan *model.AuditPlanV2, sql *model.SQ valueToBeCompared = "2" case string(driverV2.RuleLevelError): valueToBeCompared = "3" + case string(driverV2.RuleLevelNormal): + valueToBeCompared = "0" default: valueToBeCompared = "0" } @@ -203,10 +209,17 @@ func GetSingleSQLPriorityWithReasons(auditPlan *model.AuditPlanV2, sql *model.SQ // 检查是否为高优先级条件 if high, err := highPriorityConditions.CompareParamValue(highPriorityCondition.Key, valueToBeCompared); err == nil && high { // 添加匹配的条件作为原因 + comparedValue := highPriorityCondition.Param.Value if highPriorityCondition.Key == OperationParamAuditLevel { valueToBeCompared = toAuditLevel(valueToBeCompared) + comparedValue = toAuditLevel(comparedValue) } - reasons = append(reasons, fmt.Sprintf("【%v %v %v,为:%s】", highPriorityCondition.Desc, highPriorityCondition.Operator.Value, highPriorityCondition.Param.Value, valueToBeCompared)) + reasons = append(reasons, fmt.Sprintf("【%v %v %v,%s %s】", + highPriorityCondition.I18nDesc.GetStrInLang(locale.Bundle.GetLangTagFromCtx(ctx)), + highPriorityCondition.Operator.Value, + comparedValue, + locale.Bundle.LocalizeMsgByCtx(ctx, locale.WordIs), valueToBeCompared), + ) } } if len(reasons) > 0 {