2025-03-21 14:44:40 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"StuAcaWorksAI/dao"
|
|
|
|
|
"errors"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 创建模型信息
|
2025-03-21 16:20:24 +08:00
|
|
|
func CreateModel(userID uint, modelType, url, parameter, description string) (error, uint) {
|
2025-03-21 14:44:40 +08:00
|
|
|
//查看用户是否有权限创建模型
|
|
|
|
|
user := GetUserByIDWithCache(int(userID))
|
|
|
|
|
if user.ID == 0 {
|
|
|
|
|
return errors.New("user not exist"), 0
|
|
|
|
|
}
|
|
|
|
|
if user.Role != "admin" {
|
|
|
|
|
return errors.New("user not admin,no permission"), 0
|
|
|
|
|
}
|
2025-03-21 16:20:24 +08:00
|
|
|
return dao.CreateModel(userID, modelType, url, parameter, description)
|
2025-03-21 14:44:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据id查找模型
|
|
|
|
|
func FindModelByID(id, userID int) []dao.Model {
|
|
|
|
|
return dao.FindModelByID(id, userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据用户id查找模型
|
|
|
|
|
func FindModelByUserID(userID int) []dao.Model {
|
|
|
|
|
return dao.FindModelByUserID(userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据id删除模型
|
|
|
|
|
func DeleteModelByID(id, userID int) error {
|
|
|
|
|
//查看用户是否有权限删除模型
|
|
|
|
|
user := GetUserByIDWithCache(userID)
|
|
|
|
|
model := dao.FindModelByID(id, userID)
|
|
|
|
|
if user.ID == 0 {
|
|
|
|
|
return errors.New("user not exist")
|
|
|
|
|
}
|
|
|
|
|
if len(model) == 0 && user.Role != "admin" {
|
|
|
|
|
return errors.New("model not exist or no permission")
|
|
|
|
|
}
|
|
|
|
|
return dao.DeleteModelByID(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新模型信息
|
2025-03-21 16:20:24 +08:00
|
|
|
func UpdateModelByID(id int, userID uint, modelType, url, parameter, description string) error {
|
2025-03-21 14:44:40 +08:00
|
|
|
|
2025-03-21 16:20:24 +08:00
|
|
|
return dao.UpdateModelByID(id, userID, modelType, url, parameter, description)
|
2025-03-21 14:44:40 +08:00
|
|
|
}
|