Compare commits

..

No commits in common. "6b4350b915fcbe4255c0ad6186adb2f2d5d360e8" and "71eb131e581ec511cbd0e544427c60d8429f10c5" have entirely different histories.

3 changed files with 5 additions and 55 deletions

View File

@ -27,8 +27,7 @@ type CompositeCaseStep struct {
StepName string `json:"step_name" gorm:"not null;size:255"`
StepDescription string `json:"step_description" gorm:"type:text"`
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"`
StepConfig string `json:"step_config" gorm:"type:json"`
IsRequired bool `json:"is_required" gorm:"default:true"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
@ -48,8 +47,7 @@ type CreateCompositeCaseStepRequest struct {
StepName string `json:"step_name" binding:"required"`
StepDescription string `json:"step_description"`
StepType string `json:"step_type" binding:"required"`
ActivityName string `json:"activity_name"`
ParametersJson string `json:"parameters_json"`
StepConfig string `json:"step_config"`
IsRequired bool `json:"is_required"`
}
@ -68,7 +66,6 @@ type UpdateCompositeCaseStepRequest struct {
StepName string `json:"step_name"`
StepDescription string `json:"step_description"`
StepType string `json:"step_type"`
ActivityName string `json:"activity_name"`
ParametersJson string `json:"parameters_json"`
StepConfig string `json:"step_config"`
IsRequired bool `json:"is_required"`
}

View File

@ -3,7 +3,6 @@ package services
import (
"beacon/models"
"beacon/pkg/dao/mysql"
"beacon/utils"
"errors"
"fmt"
"go.uber.org/zap"
@ -61,15 +60,13 @@ func (s *CompositeCaseService) CreateCompositeCase(req *models.CreateCompositeCa
zap.L().Info("开始创建步骤", zap.Int("steps_count", len(req.Steps)))
var steps []models.CompositeCaseStep
for _, stepReq := range req.Steps {
activityName, _ := utils.GetActivityName(stepReq.StepType)
step := models.CompositeCaseStep{
CompositeCaseID: compositeCase.ID,
StepOrder: stepReq.StepOrder,
StepName: stepReq.StepName,
StepDescription: stepReq.StepDescription,
StepType: stepReq.StepType,
ActivityName: activityName,
ParametersJson: stepReq.ParametersJson,
StepConfig: stepReq.StepConfig,
IsRequired: stepReq.IsRequired,
}
steps = append(steps, step)
@ -201,15 +198,13 @@ func (s *CompositeCaseService) UpdateCompositeCase(id uint, req *models.UpdateCo
if len(req.Steps) > 0 {
var steps []models.CompositeCaseStep
for _, stepReq := range req.Steps {
activityName, _ := utils.GetActivityName(stepReq.StepType)
step := models.CompositeCaseStep{
CompositeCaseID: id,
StepOrder: stepReq.StepOrder,
StepName: stepReq.StepName,
StepDescription: stepReq.StepDescription,
StepType: stepReq.StepType,
ActivityName: activityName,
ParametersJson: stepReq.ParametersJson,
StepConfig: stepReq.StepConfig,
IsRequired: stepReq.IsRequired,
}
steps = append(steps, step)

View File

@ -1,42 +0,0 @@
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
}