refactor: simplify model selection and attribute handling

- fix ShortAttrInfo.GetAttrValue receiver naming
- replace conditional branches with switch statements
- log test task parameters during validation
This commit is contained in:
douxu 2026-07-14 17:07:06 +08:00
parent 9c9e652765
commit 61e5f9bf39
4 changed files with 12 additions and 7 deletions

View File

@ -2,6 +2,8 @@
package handler package handler
import ( import (
"fmt"
"modelRT/constants" "modelRT/constants"
"modelRT/database" "modelRT/database"
"modelRT/logger" "modelRT/logger"
@ -152,6 +154,7 @@ func validateBatchImportParams(params map[string]any) bool {
func validateTestTaskParams(params map[string]any) bool { func validateTestTaskParams(params map[string]any) bool {
// Test task has optional parameters, all are valid // Test task has optional parameters, all are valid
// sleep_duration defaults to 60 seconds if not provided // sleep_duration defaults to 60 seconds if not provided
fmt.Println("Test task parameters:", params)
return true return true
} }

View File

@ -90,6 +90,6 @@ func (s *ShortAttrInfo) IsLocal() bool {
} }
// GetAttrValue define return the attribute value // GetAttrValue define return the attribute value
func (l *ShortAttrInfo) GetAttrValue() any { func (s *ShortAttrInfo) GetAttrValue() any {
return l.AttrValue return s.AttrValue
} }

View File

@ -7,11 +7,12 @@ import (
// SelectModelByType define select the data structure for parsing based on the input model type // SelectModelByType define select the data structure for parsing based on the input model type
func SelectModelByType(modelType int) BasicModelInterface { func SelectModelByType(modelType int) BasicModelInterface {
if modelType == constants.BusbarType { switch modelType {
case constants.BusbarType:
return &orm.BusbarSection{} return &orm.BusbarSection{}
} else if modelType == constants.AsyncMotorType { case constants.AsyncMotorType:
return &orm.AsyncMotor{} return &orm.AsyncMotor{}
} else if modelType == constants.DemoType { case constants.DemoType:
return &orm.Demo{} return &orm.Demo{}
} }
return nil return nil

View File

@ -618,13 +618,14 @@ func runFuzzySearch(ctx context.Context, rdb *redis.Client, searchInput string,
} }
} }
if recommendLenType == constants.FullRecommendLength { switch recommendLenType {
case constants.FullRecommendLength:
if result.Term == "" { if result.Term == "" {
termHierarchyLen = 1 termHierarchyLen = 1
} else { } else {
termHierarchyLen = strings.Count(result.Term, ".") + 1 termHierarchyLen = strings.Count(result.Term, ".") + 1
} }
} else if recommendLenType == constants.IsLocalRecommendLength { case constants.IsLocalRecommendLength:
if result.Term == "" { if result.Term == "" {
termHierarchyLen = 4 termHierarchyLen = 4
} else { } else {