package system import ( "github.com/gin-gonic/gin" "go.uber.org/zap" "sundynix-go/global" "sundynix-go/model/commom/response" "sundynix-go/model/system" ) type SysAiConfigApi struct{} // CreateAiConfig 创建 AI 配置 // @Summary 创建 AI 配置 // @Tags System-SysAiConfig // @accept json // @Produce json // @Param data body system.SysAiConfig true "配置模型" // @Success 200 {object} response.Response // @Router /aiConfig/create [post] func (a *SysAiConfigApi) CreateAiConfig(c *gin.Context) { var cfg system.SysAiConfig if err := c.ShouldBindJSON(&cfg); err != nil { response.FailWithMsg("参数错误:"+err.Error(), c) return } if err := sysAiConfigService.Create(&cfg); err != nil { global.Logger.Error("创建AI配置失败", zap.Error(err)) response.FailWithMsg("创建失败:"+err.Error(), c) return } response.OkWithMsg("创建成功", c) } // UpdateAiConfig 更新 AI 配置 // @Summary 更新 AI 配置 // @Tags System-SysAiConfig // @accept json // @Produce json // @Param data body system.SysAiConfig true "配置模型" // @Success 200 {object} response.Response // @Router /aiConfig/update [put] func (a *SysAiConfigApi) UpdateAiConfig(c *gin.Context) { var cfg system.SysAiConfig if err := c.ShouldBindJSON(&cfg); err != nil { response.FailWithMsg("参数错误:"+err.Error(), c) return } if err := sysAiConfigService.Update(&cfg); err != nil { global.Logger.Error("更新AI配置失败", zap.Error(err)) response.FailWithMsg("更新失败:"+err.Error(), c) return } response.OkWithMsg("更新成功", c) } // SetActive 设置激活配置 // @Summary 设置激活配置(同一时间只有一条激活) // @Tags System-SysAiConfig // @accept json // @Produce json // @Param data body object true "{ \"id\": \"xxx\" }" // @Success 200 {object} response.Response // @Router /aiConfig/setActive [post] func (a *SysAiConfigApi) SetActive(c *gin.Context) { var body struct { Id string `json:"id" binding:"required"` } if err := c.ShouldBindJSON(&body); err != nil { response.FailWithMsg("参数错误:"+err.Error(), c) return } if err := sysAiConfigService.SetActive(body.Id); err != nil { global.Logger.Error("设置激活AI配置失败", zap.Error(err)) response.FailWithMsg("设置失败:"+err.Error(), c) return } response.OkWithMsg("设置成功", c) } // GetList 获取配置列表 // @Summary 获取 AI 配置列表 // @Tags System-SysAiConfig // @Produce json // @Success 200 {object} response.Response // @Router /aiConfig/list [get] func (a *SysAiConfigApi) GetList(c *gin.Context) { list, err := sysAiConfigService.GetList() if err != nil { global.Logger.Error("获取AI配置列表失败", zap.Error(err)) response.FailWithMsg("获取失败:"+err.Error(), c) return } response.OkWithData(response.PageResult{ List: list, Total: int64(len(list)), }, c) }