refactor: Skill状态字段从int改为string类型

- model/skill.go: Status字段从 int 改为 string,支持 "active"/"inactive"
- handler/skill_handler.go: 适配Status字段的类型变化,处理"1"/"0"和"active"/"inactive"两种格式
- repository/skill_repo.go: 更新Status字段的空值判断逻辑
- service/skill_service.go: 同步更新

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-13 08:31:57 +08:00
parent a07cc4498d
commit 2a9326ef5f
4 changed files with 8 additions and 8 deletions

View File

@@ -245,7 +245,7 @@ func (h *SkillHandler) Create(c *gin.Context) {
SkillType: skillType,
SkillDesc: skillDesc,
Path: filepath.Join(skillPath, "SKILL.md"),
Status: 1,
Status: "active",
}
// 记录创建者
@@ -386,7 +386,7 @@ func (h *SkillHandler) Update(c *gin.Context) {
skillName := req.SkillName
skillDesc := req.SkillDesc
skillType := req.SkillType
var status int
var status string
if skillName == "" {
skillName = existingSkill.SkillName
@@ -397,15 +397,15 @@ func (h *SkillHandler) Update(c *gin.Context) {
if skillType == "" {
skillType = existingSkill.SkillType
}
// 处理 status如果是空字符串则使用现有值否则转换为整数
// 处理 status如果是空字符串则使用现有值否则使用传入的值
if req.Status == "" {
status = existingSkill.Status
} else {
// 支持传入数字或字符串
if req.Status == "1" || req.Status == "active" {
status = 1
status = "active"
} else if req.Status == "0" || req.Status == "inactive" {
status = 0
status = "inactive"
} else {
status = existingSkill.Status
}

View File

@@ -14,7 +14,7 @@ type Skill struct {
SkillType string `json:"skill_type" gorm:"size:20;not null"` // system / user
SkillDesc string `json:"skill_desc" gorm:"type:text"`
Path string `json:"path" gorm:"size:500"` // skill 文件路径
Status int `json:"status" gorm:"default:1"` // 1: active, 0: inactive
Status string `json:"status" gorm:"size:20;default:active"` // active / inactive
CreatedBy string `json:"created_by" gorm:"size:100"` // 创建者用户名
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`

View File

@@ -65,7 +65,7 @@ func (r *SkillRepository) Update(skill *model.Skill) error {
if skill.SkillType != "" {
updates["skill_type"] = skill.SkillType
}
if skill.Status != 0 {
if skill.Status != "" {
updates["status"] = skill.Status
}
if skill.Path != "" {

View File

@@ -143,7 +143,7 @@ func (s *SkillService) scanSkillsDirectory(basePath string, skillType string) ([
SkillType: skillType,
SkillDesc: skillInfo.SkillDesc,
Path: skillPath,
Status: 1,
Status: "active",
}
skills = append(skills, skill)