Skip to content

Commit

Permalink
Merge pull request #2880 from actiontech/2130
Browse files Browse the repository at this point in the history
add i18n words for desc of sql in global dashboard
  • Loading branch information
iwanghc authored Jan 17, 2025
2 parents cc0a70b + d62b06e commit 9a840e4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
5 changes: 5 additions & 0 deletions sqle/locale/active.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions sqle/locale/active.zh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ ParamSQLMinSecond = "SQL 最小执行时间(秒)"
ParamSlowLogCollectInput = "采集来源"
ParamTopN = "Top N"
PipelineCmdUsage = "#使用方法#\n1. 确保运行该命令的用户具有scannerd的执行权限。\n2. 在scannerd文件所在目录执行启动命令。\n#启动命令#\n"
RuleLevelError = "错误"
RuleLevelNormal = "常规"
RuleLevelNotice = "提示"
RuleLevelWarn = "警告"
RuleTemplateDesc = "规则模板描述"
RuleTemplateInstType = "数据源类型"
RuleTemplateName = "规则模板名"
Expand Down Expand Up @@ -301,6 +305,7 @@ TaskStatusExecuteFailed = "上线失败"
TaskStatusExecuteSucceeded = "上线成功"
TaskStatusExecuting = "正在上线"
TaskStatusManuallyExecuted = "手动上线"
WordIs = ""
WorkflowNotifyTypeDefault = "SQL工单未知请求"
WorkflowNotifyTypeExecuteFail = "SQL工单上线失败"
WorkflowNotifyTypeExecuteSuccess = "SQL工单上线成功"
Expand Down
9 changes: 9 additions & 0 deletions sqle/locale/message_zh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "正在上线"}
Expand Down
25 changes: 19 additions & 6 deletions sqle/server/auditplan/job_task_handler.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package auditplan

import (
"context"
"database/sql"
"errors"
"fmt"
"sync"
"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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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"
}
Expand All @@ -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 {
Expand Down

0 comments on commit 9a840e4

Please sign in to comment.