refactor(billing): 优化条件判断逻辑并移除未使用的常量
This commit is contained in:
+14
-16
@@ -255,27 +255,25 @@ func extractValue(source map[string]any, path string) any {
|
||||
return sum
|
||||
}
|
||||
|
||||
// 条件判断:content.#.type==xxx
|
||||
if strings.Count(path, ".#.") == 1 && strings.Contains(path, "==") {
|
||||
parts := strings.Split(path, "==")
|
||||
basePath := parts[0]
|
||||
typ := parts[1]
|
||||
arr := gjson.New(source).Get(strings.Split(basePath, ".#.")[0]).Array()
|
||||
for _, item := range arr {
|
||||
field := strings.Split(basePath, ".#.")[1]
|
||||
if gconv.String(gjson.New(item).Get(field).Val()) == typ {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 条件判断:rounds.#.content.#.type==xxx(嵌套数组)
|
||||
// 条件判断:xxx.#.type==yyy 或 rounds.#.content.#.type==yyy
|
||||
if strings.Contains(path, "==video_url") || strings.Contains(path, "==input_audio") {
|
||||
parts := strings.Split(path, "==")
|
||||
basePath := parts[0]
|
||||
typ := parts[1]
|
||||
segments := strings.Split(basePath, ".#.")
|
||||
|
||||
// 单层:content.#.type → segments = ["content", "type"]
|
||||
if len(segments) == 2 && !strings.Contains(segments[0], ".") {
|
||||
arr := gjson.New(source).Get(segments[0]).Array()
|
||||
for _, item := range arr {
|
||||
if gconv.String(gjson.New(item).Get(segments[1]).Val()) == typ {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 嵌套:rounds.#.content.#.type → segments = ["rounds", "content", "type"]
|
||||
topArr := gjson.New(source).Get(segments[0]).Array()
|
||||
for _, item := range topArr {
|
||||
subArr := gjson.New(item).Get(segments[1]).Array()
|
||||
|
||||
@@ -5,9 +5,8 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
TableNameModel = "model_gateway_models" // 模型表
|
||||
TableNameTask = "model_gateway_task" // 任务表
|
||||
TableNameUserBilling = "model_user_billing" // 用户账单表
|
||||
TableNameOpLog = "model_gateway_logs_op" // 操作日志表
|
||||
TableNameStat = "model_gateway_logs_stat" // 按天统计表
|
||||
TableNameModel = "model_gateway_models" // 模型表
|
||||
TableNameTask = "model_gateway_task" // 任务表
|
||||
TableNameOpLog = "model_gateway_logs_op" // 操作日志表
|
||||
TableNameStat = "model_gateway_logs_stat" // 按天统计表
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user