修改功能支持模型选择id
This commit is contained in:
parent
ac2ddb1beb
commit
8169815278
19
dao/model.go
19
dao/model.go
|
|
@ -15,11 +15,12 @@ type Model struct {
|
|||
}
|
||||
type FunctionModel struct {
|
||||
gorm.Model
|
||||
Name string `gorm:"column:name"` //功能名称
|
||||
Function string `gorm:"column:function"` //功能函数,唯一标识
|
||||
UserID uint `gorm:"column:user_id"` //用户id
|
||||
ModelID uint `gorm:"column:model_id"` //模型id
|
||||
Info string `gorm:"column:info"` //功能信息,系统功能,对应模型系统参数
|
||||
Name string `gorm:"column:name"` //功能名称
|
||||
Function string `gorm:"column:function"` //功能函数,唯一标识
|
||||
UserID uint `gorm:"column:user_id"` //用户id
|
||||
ModelID uint `gorm:"column:model_id"` //模型id
|
||||
ModelIDS string `gorm:"column:model_ids"` //允许模型id,可多个
|
||||
Info string `gorm:"column:info"` //功能信息,系统功能,对应模型系统参数
|
||||
//System string `gorm:"column:system"` //系统功能,对应模型系统参数
|
||||
}
|
||||
|
||||
|
|
@ -105,8 +106,8 @@ func UpdateModelByID(id int, userID uint, modelType, url, parameter, description
|
|||
}
|
||||
|
||||
// 创建功能模型
|
||||
func CreateFunctionModel(userID uint, modelID uint, name, info, function string) (error, uint) {
|
||||
functionModel := FunctionModel{UserID: userID, ModelID: modelID, Name: name, Info: info, Function: function}
|
||||
func CreateFunctionModel(userID uint, modelID uint, name, info, function, modelIDs string) (error, uint) {
|
||||
functionModel := FunctionModel{UserID: userID, ModelID: modelID, Name: name, Info: info, Function: function, ModelIDS: modelIDs}
|
||||
var res *gorm.DB
|
||||
if proto.Config.SERVER_SQL_LOG {
|
||||
res = DB.Debug().Create(&functionModel)
|
||||
|
|
@ -139,8 +140,8 @@ func FindFunctionModelByUserID(userID int) []FunctionModel {
|
|||
}
|
||||
|
||||
// 修改功能模型
|
||||
func UpdateFunctionModelByID(id int, userID uint, modelID uint, name, info, function string) error {
|
||||
functionModel := FunctionModel{UserID: userID, ModelID: modelID, Name: name, Info: info, Function: function}
|
||||
func UpdateFunctionModelByID(id int, userID uint, modelID uint, name, info, function, modelIDs string) error {
|
||||
functionModel := FunctionModel{UserID: userID, ModelID: modelID, Name: name, Info: info, Function: function, ModelIDS: modelIDs}
|
||||
var res *gorm.DB
|
||||
if proto.Config.SERVER_SQL_LOG {
|
||||
res = DB.Debug().Model(&FunctionModel{}).Where("id = ?", id).Updates(&functionModel)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package handler
|
|||
import (
|
||||
"StuAcaWorksAI/proto"
|
||||
"StuAcaWorksAI/service"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
|
@ -16,11 +17,12 @@ func SetUpFuncModelGroup(router *gin.Engine) {
|
|||
}
|
||||
|
||||
type FuncModelReq struct {
|
||||
ID int `json:"id" form:"id"`
|
||||
ModelID int `json:"model_id" form:"model_id"`
|
||||
Function string `json:"function" form:"function"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Info string `json:"info" form:"info"`
|
||||
ID int `json:"id" form:"id"`
|
||||
ModelID int `json:"model_id" form:"model_id"`
|
||||
Function string `json:"function" form:"function"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Info string `json:"info" form:"info"`
|
||||
ModelIDS map[int]bool `json:"model_ids" form:"model_ids"`
|
||||
}
|
||||
|
||||
func CreateFuncModel(c *gin.Context) {
|
||||
|
|
@ -28,8 +30,13 @@ func CreateFuncModel(c *gin.Context) {
|
|||
userID := int(id.(float64))
|
||||
var req FuncModelReq
|
||||
if err := c.ShouldBind(&req); err == nil {
|
||||
modelIDs, err3 := json.Marshal(req.ModelIDS)
|
||||
if err3 != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.FuncModelCreateFailed, "message": "failed"})
|
||||
return
|
||||
}
|
||||
// 创建功能模型
|
||||
err2, mid := service.CreateFuncModel(int(uint(userID)), req.ModelID, req.Name, req.Info, req.Function)
|
||||
err2, mid := service.CreateFuncModel(int(uint(userID)), req.ModelID, req.Name, req.Info, req.Function, string(modelIDs))
|
||||
if err2 == nil {
|
||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": mid})
|
||||
} else {
|
||||
|
|
@ -72,8 +79,13 @@ func UpdateFuncModel(c *gin.Context) {
|
|||
userID := int(id.(float64))
|
||||
var req FuncModelReq
|
||||
if err := c.ShouldBind(&req); err == nil {
|
||||
modelIDs, err3 := json.Marshal(req.ModelIDS)
|
||||
if err3 != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"error": err3.Error(), "code": proto.FuncModelCreateFailed, "message": "failed"})
|
||||
return
|
||||
}
|
||||
// 修改功能模型
|
||||
err2 := service.UpdateFuncModelByID(req.ID, uint(userID), uint(req.ModelID), req.Name, req.Info, req.Function)
|
||||
err2 := service.UpdateFuncModelByID(req.ID, uint(userID), uint(req.ModelID), req.Name, req.Info, req.Function, string(modelIDs))
|
||||
if err2 == nil {
|
||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func UpdateModelByID(id int, userID uint, modelType, url, parameter, description
|
|||
return dao.UpdateModelByID(id, userID, modelType, url, parameter, description)
|
||||
}
|
||||
|
||||
func CreateFuncModel(userID, modelID int, name, info, function string) (error, uint) {
|
||||
func CreateFuncModel(userID, modelID int, name, info, function, modelIDs string) (error, uint) {
|
||||
//查看用户是否有权限创建模型
|
||||
user := GetUserByIDWithCache(userID)
|
||||
if user.ID == 0 {
|
||||
|
|
@ -83,7 +83,7 @@ func CreateFuncModel(userID, modelID int, name, info, function string) (error, u
|
|||
if user.Role != "admin" {
|
||||
return errors.New("user not admin,no permission"), 0
|
||||
}
|
||||
return dao.CreateFunctionModel(uint(userID), uint(modelID), name, info, function)
|
||||
return dao.CreateFunctionModel(uint(userID), uint(modelID), name, info, function, modelIDs)
|
||||
}
|
||||
|
||||
func FindFuncModelByID(id, userID int) ([]dao.FunctionModel, error) {
|
||||
|
|
@ -122,7 +122,7 @@ func DeleteFuncModelByID(id, userID int) error {
|
|||
return dao.DeleteFunctionModelByID(id)
|
||||
}
|
||||
|
||||
func UpdateFuncModelByID(id int, userID, modelID uint, name, info, function string) error {
|
||||
func UpdateFuncModelByID(id int, userID, modelID uint, name, info, function, modelIDs string) error {
|
||||
user := GetUserByIDWithCache(int(userID))
|
||||
if user.ID == 0 {
|
||||
return errors.New("user not exist")
|
||||
|
|
@ -130,7 +130,7 @@ func UpdateFuncModelByID(id int, userID, modelID uint, name, info, function stri
|
|||
if user.Role != "admin" {
|
||||
return errors.New("user not admin,no permission")
|
||||
}
|
||||
return dao.UpdateFunctionModelByID(id, userID, modelID, name, info, function)
|
||||
return dao.UpdateFunctionModelByID(id, userID, modelID, name, info, function, modelIDs)
|
||||
}
|
||||
|
||||
// 根据功能查找对应功能
|
||||
|
|
|
|||
Loading…
Reference in New Issue