修改功能支持模型选择id
This commit is contained in:
parent
ac2ddb1beb
commit
8169815278
|
|
@ -19,6 +19,7 @@ type FunctionModel struct {
|
||||||
Function string `gorm:"column:function"` //功能函数,唯一标识
|
Function string `gorm:"column:function"` //功能函数,唯一标识
|
||||||
UserID uint `gorm:"column:user_id"` //用户id
|
UserID uint `gorm:"column:user_id"` //用户id
|
||||||
ModelID uint `gorm:"column:model_id"` //模型id
|
ModelID uint `gorm:"column:model_id"` //模型id
|
||||||
|
ModelIDS string `gorm:"column:model_ids"` //允许模型id,可多个
|
||||||
Info string `gorm:"column:info"` //功能信息,系统功能,对应模型系统参数
|
Info string `gorm:"column:info"` //功能信息,系统功能,对应模型系统参数
|
||||||
//System string `gorm:"column:system"` //系统功能,对应模型系统参数
|
//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) {
|
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}
|
functionModel := FunctionModel{UserID: userID, ModelID: modelID, Name: name, Info: info, Function: function, ModelIDS: modelIDs}
|
||||||
var res *gorm.DB
|
var res *gorm.DB
|
||||||
if proto.Config.SERVER_SQL_LOG {
|
if proto.Config.SERVER_SQL_LOG {
|
||||||
res = DB.Debug().Create(&functionModel)
|
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 {
|
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}
|
functionModel := FunctionModel{UserID: userID, ModelID: modelID, Name: name, Info: info, Function: function, ModelIDS: modelIDs}
|
||||||
var res *gorm.DB
|
var res *gorm.DB
|
||||||
if proto.Config.SERVER_SQL_LOG {
|
if proto.Config.SERVER_SQL_LOG {
|
||||||
res = DB.Debug().Model(&FunctionModel{}).Where("id = ?", id).Updates(&functionModel)
|
res = DB.Debug().Model(&FunctionModel{}).Where("id = ?", id).Updates(&functionModel)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package handler
|
||||||
import (
|
import (
|
||||||
"StuAcaWorksAI/proto"
|
"StuAcaWorksAI/proto"
|
||||||
"StuAcaWorksAI/service"
|
"StuAcaWorksAI/service"
|
||||||
|
"encoding/json"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
@ -21,6 +22,7 @@ type FuncModelReq struct {
|
||||||
Function string `json:"function" form:"function"`
|
Function string `json:"function" form:"function"`
|
||||||
Name string `json:"name" form:"name"`
|
Name string `json:"name" form:"name"`
|
||||||
Info string `json:"info" form:"info"`
|
Info string `json:"info" form:"info"`
|
||||||
|
ModelIDS map[int]bool `json:"model_ids" form:"model_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateFuncModel(c *gin.Context) {
|
func CreateFuncModel(c *gin.Context) {
|
||||||
|
|
@ -28,8 +30,13 @@ func CreateFuncModel(c *gin.Context) {
|
||||||
userID := int(id.(float64))
|
userID := int(id.(float64))
|
||||||
var req FuncModelReq
|
var req FuncModelReq
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
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 {
|
if err2 == nil {
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": mid})
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": mid})
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -72,8 +79,13 @@ func UpdateFuncModel(c *gin.Context) {
|
||||||
userID := int(id.(float64))
|
userID := int(id.(float64))
|
||||||
var req FuncModelReq
|
var req FuncModelReq
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
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 {
|
if err2 == nil {
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ func UpdateModelByID(id int, userID uint, modelType, url, parameter, description
|
||||||
return dao.UpdateModelByID(id, userID, 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)
|
user := GetUserByIDWithCache(userID)
|
||||||
if user.ID == 0 {
|
if user.ID == 0 {
|
||||||
|
|
@ -83,7 +83,7 @@ func CreateFuncModel(userID, modelID int, name, info, function string) (error, u
|
||||||
if user.Role != "admin" {
|
if user.Role != "admin" {
|
||||||
return errors.New("user not admin,no permission"), 0
|
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) {
|
func FindFuncModelByID(id, userID int) ([]dao.FunctionModel, error) {
|
||||||
|
|
@ -122,7 +122,7 @@ func DeleteFuncModelByID(id, userID int) error {
|
||||||
return dao.DeleteFunctionModelByID(id)
|
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))
|
user := GetUserByIDWithCache(int(userID))
|
||||||
if user.ID == 0 {
|
if user.ID == 0 {
|
||||||
return errors.New("user not exist")
|
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" {
|
if user.Role != "admin" {
|
||||||
return errors.New("user not admin,no permission")
|
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