From 33965dae4785b5023d65c0a3965b6f7e5538b55d Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Wed, 26 Nov 2025 10:51:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E4=B8=8E=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/task.go | 30 ++++++++++++++---------------- internal/data/constants/task.go | 11 +++++++++++ internal/data/model/ai_task.gen.go | 28 +++++++++++++++------------- 3 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 internal/data/constants/task.go diff --git a/internal/biz/task.go b/internal/biz/task.go index e1a8689..1c9a39f 100644 --- a/internal/biz/task.go +++ b/internal/biz/task.go @@ -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{ - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", - "Accept": "application/json, text/plain, */*", - "Authorization": auth, + 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 { diff --git a/internal/data/constants/task.go b/internal/data/constants/task.go new file mode 100644 index 0000000..8ba18a9 --- /dev/null +++ b/internal/data/constants/task.go @@ -0,0 +1,11 @@ +package constants + +const ( + IsSHOW = 1 + NotShow = 2 +) + +const ( + Enable = 1 + Disable = 2 +) diff --git a/internal/data/model/ai_task.gen.go b/internal/data/model/ai_task.gen.go index 5599d78..e45f408 100644 --- a/internal/data/model/ai_task.gen.go +++ b/internal/data/model/ai_task.gen.go @@ -12,19 +12,21 @@ const TableNameAiTask = "ai_task" // AiTask mapped from table type AiTask struct { - TaskID int32 `gorm:"column:task_id;primaryKey" 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:知识库 - Config string `gorm:"column:config" json:"config"` - 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"` - 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执行 + 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"` + 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"` + 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"` } // TableName AiTask's table name