Compare commits

..

No commits in common. "4626efe7b2ddfc714546ebd53ae625fa588d5bb8" and "c086e9ba15b951b025fa689338bba3b86cdd59c3" have entirely different histories.

3 changed files with 29 additions and 40 deletions

View File

@ -1,7 +1,6 @@
package biz
import (
"ai_scheduler/internal/data/constants"
errors "ai_scheduler/internal/data/error"
"ai_scheduler/internal/data/impl"
"ai_scheduler/internal/data/model"
@ -9,11 +8,10 @@ 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"
@ -35,9 +33,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": constants.Enable})
cond = cond.And(builder.Eq{"status": 1})
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)
@ -57,16 +55,20 @@ 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
)
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,
},
// 构建请求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,
}
// 发送请求
res, err := request.Send()
if err != nil {
@ -82,7 +84,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 {

View File

@ -1,11 +0,0 @@
package constants
const (
IsSHOW = 1
NotShow = 2
)
const (
Enable = 1
Disable = 2
)

View File

@ -12,21 +12,19 @@ const TableNameAiTask = "ai_task"
// AiTask mapped from table <ai_task>
type AiTask struct {
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:类型1api,2:知识库" json:"type"` // 类型1api,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"`
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:类型1api,2:知识库" json:"type"` // 类型1api,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执行
}
// TableName AiTask's table name