新增步骤类型与Activity函数名映射工具,更新复合案例模型字段以支持ActivityName,并调整服务层逻辑适配映射功能
This commit is contained in:
parent
bc52b82b93
commit
6b4350b915
@ -27,6 +27,7 @@ type CompositeCaseStep struct {
|
|||||||
StepName string `json:"step_name" gorm:"not null;size:255"`
|
StepName string `json:"step_name" gorm:"not null;size:255"`
|
||||||
StepDescription string `json:"step_description" gorm:"type:text"`
|
StepDescription string `json:"step_description" gorm:"type:text"`
|
||||||
StepType string `json:"step_type" gorm:"not null;size:100"`
|
StepType string `json:"step_type" gorm:"not null;size:100"`
|
||||||
|
ActivityName string `json:"activity_name" gorm:"not null;size:255"`
|
||||||
ParametersJson string `json:"parameters_json" gorm:"type:json"`
|
ParametersJson string `json:"parameters_json" gorm:"type:json"`
|
||||||
IsRequired bool `json:"is_required" gorm:"default:true"`
|
IsRequired bool `json:"is_required" gorm:"default:true"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
@ -47,6 +48,7 @@ type CreateCompositeCaseStepRequest struct {
|
|||||||
StepName string `json:"step_name" binding:"required"`
|
StepName string `json:"step_name" binding:"required"`
|
||||||
StepDescription string `json:"step_description"`
|
StepDescription string `json:"step_description"`
|
||||||
StepType string `json:"step_type" binding:"required"`
|
StepType string `json:"step_type" binding:"required"`
|
||||||
|
ActivityName string `json:"activity_name"`
|
||||||
ParametersJson string `json:"parameters_json"`
|
ParametersJson string `json:"parameters_json"`
|
||||||
IsRequired bool `json:"is_required"`
|
IsRequired bool `json:"is_required"`
|
||||||
}
|
}
|
||||||
@ -66,6 +68,7 @@ type UpdateCompositeCaseStepRequest struct {
|
|||||||
StepName string `json:"step_name"`
|
StepName string `json:"step_name"`
|
||||||
StepDescription string `json:"step_description"`
|
StepDescription string `json:"step_description"`
|
||||||
StepType string `json:"step_type"`
|
StepType string `json:"step_type"`
|
||||||
|
ActivityName string `json:"activity_name"`
|
||||||
ParametersJson string `json:"parameters_json"`
|
ParametersJson string `json:"parameters_json"`
|
||||||
IsRequired bool `json:"is_required"`
|
IsRequired bool `json:"is_required"`
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package services
|
|||||||
import (
|
import (
|
||||||
"beacon/models"
|
"beacon/models"
|
||||||
"beacon/pkg/dao/mysql"
|
"beacon/pkg/dao/mysql"
|
||||||
|
"beacon/utils"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@ -60,13 +61,15 @@ func (s *CompositeCaseService) CreateCompositeCase(req *models.CreateCompositeCa
|
|||||||
zap.L().Info("开始创建步骤", zap.Int("steps_count", len(req.Steps)))
|
zap.L().Info("开始创建步骤", zap.Int("steps_count", len(req.Steps)))
|
||||||
var steps []models.CompositeCaseStep
|
var steps []models.CompositeCaseStep
|
||||||
for _, stepReq := range req.Steps {
|
for _, stepReq := range req.Steps {
|
||||||
|
activityName, _ := utils.GetActivityName(stepReq.StepType)
|
||||||
step := models.CompositeCaseStep{
|
step := models.CompositeCaseStep{
|
||||||
CompositeCaseID: compositeCase.ID,
|
CompositeCaseID: compositeCase.ID,
|
||||||
StepOrder: stepReq.StepOrder,
|
StepOrder: stepReq.StepOrder,
|
||||||
StepName: stepReq.StepName,
|
StepName: stepReq.StepName,
|
||||||
StepDescription: stepReq.StepDescription,
|
StepDescription: stepReq.StepDescription,
|
||||||
StepType: stepReq.StepType,
|
StepType: stepReq.StepType,
|
||||||
StepConfig: stepReq.StepConfig,
|
ActivityName: activityName,
|
||||||
|
ParametersJson: stepReq.ParametersJson,
|
||||||
IsRequired: stepReq.IsRequired,
|
IsRequired: stepReq.IsRequired,
|
||||||
}
|
}
|
||||||
steps = append(steps, step)
|
steps = append(steps, step)
|
||||||
@ -198,13 +201,15 @@ func (s *CompositeCaseService) UpdateCompositeCase(id uint, req *models.UpdateCo
|
|||||||
if len(req.Steps) > 0 {
|
if len(req.Steps) > 0 {
|
||||||
var steps []models.CompositeCaseStep
|
var steps []models.CompositeCaseStep
|
||||||
for _, stepReq := range req.Steps {
|
for _, stepReq := range req.Steps {
|
||||||
|
activityName, _ := utils.GetActivityName(stepReq.StepType)
|
||||||
step := models.CompositeCaseStep{
|
step := models.CompositeCaseStep{
|
||||||
CompositeCaseID: id,
|
CompositeCaseID: id,
|
||||||
StepOrder: stepReq.StepOrder,
|
StepOrder: stepReq.StepOrder,
|
||||||
StepName: stepReq.StepName,
|
StepName: stepReq.StepName,
|
||||||
StepDescription: stepReq.StepDescription,
|
StepDescription: stepReq.StepDescription,
|
||||||
StepType: stepReq.StepType,
|
StepType: stepReq.StepType,
|
||||||
StepConfig: stepReq.StepConfig,
|
ActivityName: activityName,
|
||||||
|
ParametersJson: stepReq.ParametersJson,
|
||||||
IsRequired: stepReq.IsRequired,
|
IsRequired: stepReq.IsRequired,
|
||||||
}
|
}
|
||||||
steps = append(steps, step)
|
steps = append(steps, step)
|
||||||
|
42
utils/step_type_activity_mapper.go
Normal file
42
utils/step_type_activity_mapper.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetActivityName 根据步骤类型获取对应的 Activity 函数名
|
||||||
|
// 参数:
|
||||||
|
// - stepType: 数据库中的步骤类型,如 "api", "ui" 等
|
||||||
|
//
|
||||||
|
// 返回值:
|
||||||
|
// - activityName: 对应的 Temporal Activity 函数名
|
||||||
|
// - error: 如果步骤类型不支持则返回错误
|
||||||
|
func GetActivityName(stepType string) (string, error) {
|
||||||
|
// 标准化输入:转为大写并去除空格
|
||||||
|
normalizedStepType := strings.ToUpper(strings.TrimSpace(stepType))
|
||||||
|
|
||||||
|
// 步骤类型到 Activity 名称的映射表
|
||||||
|
stepTypeToActivity := map[string]string{
|
||||||
|
// ================== 测试类型 Activity ==================
|
||||||
|
"API": "RunApiTest", // API 接口测试
|
||||||
|
"UI": "RunUiTest", // UI 自动化测试
|
||||||
|
"SQL": "RunSqlTest", // SQL 执行sql语句
|
||||||
|
"PYTHON": "RunPythonTest", // PYTHON 执行python脚本处理数据
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找对应的 Activity 名称
|
||||||
|
activityName, exists := stepTypeToActivity[normalizedStepType]
|
||||||
|
if !exists {
|
||||||
|
// 返回详细的错误信息,包含支持的类型列表
|
||||||
|
supportedTypes := make([]string, 0, len(stepTypeToActivity))
|
||||||
|
for stepType := range stepTypeToActivity {
|
||||||
|
supportedTypes = append(supportedTypes, stepType)
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", fmt.Errorf("unsupported step type '%s'. Supported types: %v",
|
||||||
|
stepType, supportedTypes)
|
||||||
|
}
|
||||||
|
|
||||||
|
return activityName, nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user