feat: 优化任务模型与权限控制
This commit is contained in:
parent
2c46dcacaa
commit
33965dae47
|
|
@ -1,6 +1,7 @@
|
|||
package biz
|
||||
|
||||
import (
|
||||
"ai_scheduler/internal/data/constants"
|
||||
errors "ai_scheduler/internal/data/error"
|
||||
"ai_scheduler/internal/data/impl"
|
||||
"ai_scheduler/internal/data/model"
|
||||
|
|
@ -8,10 +9,11 @@ import (
|
|||
"ai_scheduler/internal/pkg/l_request"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"gorm.io/gorm/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"gorm.io/gorm/utils"
|
||||
|
||||
"xorm.io/builder"
|
||||
|
||||
"ai_scheduler/internal/config"
|
||||
|
|
@ -33,9 +35,9 @@ func NewTaskBiz(conf *config.Config, taskRepo *impl.TaskImpl) *TaskBiz {
|
|||
func (t *TaskBiz) TaskList(ctx context.Context, req *entitys.TaskRequest, auth string) (list []model.AiTask, err error) {
|
||||
tasks := make([]model.AiTask, 0)
|
||||
cond := builder.NewCond()
|
||||
cond = cond.And(builder.Eq{"status": 1})
|
||||
|
||||
cond = cond.And(builder.Eq{"status": constants.Enable})
|
||||
cond = cond.And(builder.Eq{"sys_id": req.SysId})
|
||||
cond = cond.And(builder.Eq{"is_show": constants.IsSHOW})
|
||||
err = t.taskRepo.GetRangeToMapStruct(&cond, &tasks)
|
||||
|
||||
codes, err := t.GetUserPermission(req, auth)
|
||||
|
|
@ -55,20 +57,16 @@ func (t *TaskBiz) TaskList(ctx context.Context, req *entitys.TaskRequest, auth s
|
|||
|
||||
// 从统一登录平台获取用户权限
|
||||
func (t *TaskBiz) GetUserPermission(req *entitys.TaskRequest, auth string) (codes []string, err error) {
|
||||
var (
|
||||
request l_request.Request
|
||||
)
|
||||
|
||||
// 构建请求URL
|
||||
request.Url = t.conf.PermissionConfig.PermissionURL + strconv.Itoa(int(req.SysId))
|
||||
|
||||
request.Method = "GET"
|
||||
request.Headers = map[string]string{
|
||||
request := l_request.Request{
|
||||
Method: "GET",
|
||||
Url: t.conf.PermissionConfig.PermissionURL + strconv.Itoa(int(req.SysId)),
|
||||
Headers: map[string]string{
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
"Authorization": auth,
|
||||
},
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
res, err := request.Send()
|
||||
if err != nil {
|
||||
|
|
@ -84,7 +82,7 @@ func (t *TaskBiz) GetUserPermission(req *entitys.TaskRequest, auth string) (code
|
|||
type resp struct {
|
||||
Codes []string `json:"codes"`
|
||||
}
|
||||
// 解析响应体
|
||||
// 解析响应体s
|
||||
var respBody resp
|
||||
err = json.Unmarshal([]byte(res.Text), &respBody)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package constants
|
||||
|
||||
const (
|
||||
IsSHOW = 1
|
||||
NotShow = 2
|
||||
)
|
||||
|
||||
const (
|
||||
Enable = 1
|
||||
Disable = 2
|
||||
)
|
||||
|
|
@ -12,19 +12,21 @@ const TableNameAiTask = "ai_task"
|
|||
|
||||
// AiTask mapped from table <ai_task>
|
||||
type AiTask struct {
|
||||
TaskID int32 `gorm:"column:task_id;primaryKey" json:"task_id"`
|
||||
TaskID int32 `gorm:"column:task_id;primaryKey;autoIncrement:true" json:"task_id"`
|
||||
SysID int32 `gorm:"column:sys_id;not null" json:"sys_id"`
|
||||
Name string `gorm:"column:name;not null" json:"name"`
|
||||
Index string `gorm:"column:index;not null" json:"index"`
|
||||
Desc string `gorm:"column:desc;not null" json:"desc"`
|
||||
Type int32 `gorm:"column:type;not null;comment:类型,1:api,2:知识库" json:"type"` // 类型,1:api,2:知识库
|
||||
UseCase string `gorm:"column:use_case;not null;comment:适用场景" json:"use_case"` // 适用场景
|
||||
TempPrompt string `gorm:"column:temp_prompt;not null;comment:提示词模板" json:"temp_prompt"` // 提示词模板
|
||||
Type int32 `gorm:"column:type;not null;default:1;comment:类型,1:api,2:知识库" json:"type"` // 类型,1:api,2:知识库
|
||||
Config string `gorm:"column:config" json:"config"`
|
||||
TagType int32 `gorm:"column:tag_type;comment:标签类型:1.AI日常 2.AI查询 3.AI执行" json:"tag_type"` // 标签类型:1.AI日常 2.AI查询 3.AI执行
|
||||
CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"`
|
||||
UpdateAt time.Time `gorm:"column:update_at;default:CURRENT_TIMESTAMP" json:"update_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||
IsShow int32 `gorm:"column:is_show;not null;default:1;comment:是否展示,1为展示,2为不展示" json:"is_show"` // 是否展示,1为展示,2为不展示
|
||||
Status int32 `gorm:"column:status;not null;default:1" json:"status"`
|
||||
DeleteAt time.Time `gorm:"column:delete_at" json:"delete_at"`
|
||||
UseCase string `gorm:"column:use_case;not null" json:"use_case"` // 适用场景
|
||||
TagType int32 `gorm:"column:tag_type;not null;default:1" json:"tag_type"` // 标签类型 1.AI日常 2.AI查询 3.AI执行
|
||||
}
|
||||
|
||||
// TableName AiTask's table name
|
||||
|
|
|
|||
Loading…
Reference in New Issue