| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| package controller |
|
|
| import ( |
| "encoding/json" |
| "net/http" |
| "veloera/model" |
| "veloera/service" |
|
|
| "github.com/gin-gonic/gin" |
| ) |
|
|
| |
| func GetGlobalModelMapping(c *gin.Context) { |
| mapping := service.GetGlobalModelMapping() |
| |
| c.JSON(http.StatusOK, gin.H{ |
| "success": true, |
| "message": "", |
| "data": mapping, |
| }) |
| } |
|
|
| |
| func UpdateGlobalModelMapping(c *gin.Context) { |
| var mapping model.GlobalModelMapping |
| |
| if err := c.ShouldBindJSON(&mapping); err != nil { |
| c.JSON(http.StatusBadRequest, gin.H{ |
| "success": false, |
| "message": "请求参数解析失败: " + err.Error(), |
| }) |
| return |
| } |
| |
| if err := service.UpdateGlobalModelMapping(&mapping); err != nil { |
| c.JSON(http.StatusInternalServerError, gin.H{ |
| "success": false, |
| "message": "更新全局模型映射配置失败: " + err.Error(), |
| }) |
| return |
| } |
| |
| c.JSON(http.StatusOK, gin.H{ |
| "success": true, |
| "message": "全局模型映射配置更新成功", |
| }) |
| } |
|
|
|
|
|
|
| |
| func GetModelMappingConfig(c *gin.Context) { |
| configStr := service.GlobalModelMappingToJSONString() |
| |
| |
| var config map[string]interface{} |
| if err := json.Unmarshal([]byte(configStr), &config); err != nil { |
| c.JSON(http.StatusInternalServerError, gin.H{ |
| "success": false, |
| "message": "配置格式错误: " + err.Error(), |
| }) |
| return |
| } |
| |
| c.JSON(http.StatusOK, gin.H{ |
| "success": true, |
| "message": "", |
| "data": config, |
| }) |
| } |
|
|
| |
| func UpdateModelMappingConfig(c *gin.Context) { |
| |
| jsonStr, err := c.GetRawData() |
| if err != nil { |
| c.JSON(http.StatusBadRequest, gin.H{ |
| "success": false, |
| "message": "读取请求体失败: " + err.Error(), |
| }) |
| return |
| } |
| |
| |
| if len(jsonStr) == 0 { |
| jsonStr = []byte("{}") |
| } |
| |
| |
| if err := service.UpdateGlobalModelMappingFromJSONString(string(jsonStr)); err != nil { |
| c.JSON(http.StatusInternalServerError, gin.H{ |
| "success": false, |
| "message": "更新全局模型映射配置失败: " + err.Error(), |
| }) |
| return |
| } |
| |
| c.JSON(http.StatusOK, gin.H{ |
| "success": true, |
| "message": "全局模型映射配置更新成功", |
| }) |
| } |
|
|
|
|
| |
| func ReloadModelMapping(c *gin.Context) { |
| if err := service.ReloadModelMapping(); err != nil { |
| c.JSON(http.StatusInternalServerError, gin.H{ |
| "success": false, |
| "message": "重新加载模型映射配置失败: " + err.Error(), |
| }) |
| return |
| } |
| |
| c.JSON(http.StatusOK, gin.H{ |
| "success": true, |
| "message": "模型映射配置重新加载成功", |
| }) |
| } |