Compare commits
3 Commits
c086e9ba15
...
4626efe7b2
| Author | SHA1 | Date |
|---|---|---|
|
|
4626efe7b2 | |
|
|
4619389f4f | |
|
|
33965dae47 |
|
|
@ -1,6 +1,7 @@
|
||||||
package biz
|
package biz
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"ai_scheduler/internal/data/constants"
|
||||||
errors "ai_scheduler/internal/data/error"
|
errors "ai_scheduler/internal/data/error"
|
||||||
"ai_scheduler/internal/data/impl"
|
"ai_scheduler/internal/data/impl"
|
||||||
"ai_scheduler/internal/data/model"
|
"ai_scheduler/internal/data/model"
|
||||||
|
|
@ -8,10 +9,11 @@ import (
|
||||||
"ai_scheduler/internal/pkg/l_request"
|
"ai_scheduler/internal/pkg/l_request"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"gorm.io/gorm/utils"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"gorm.io/gorm/utils"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
|
|
||||||
"ai_scheduler/internal/config"
|
"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) {
|
func (t *TaskBiz) TaskList(ctx context.Context, req *entitys.TaskRequest, auth string) (list []model.AiTask, err error) {
|
||||||
tasks := make([]model.AiTask, 0)
|
tasks := make([]model.AiTask, 0)
|
||||||
cond := builder.NewCond()
|
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{"sys_id": req.SysId})
|
||||||
|
cond = cond.And(builder.Eq{"is_show": constants.IsSHOW})
|
||||||
err = t.taskRepo.GetRangeToMapStruct(&cond, &tasks)
|
err = t.taskRepo.GetRangeToMapStruct(&cond, &tasks)
|
||||||
|
|
||||||
codes, err := t.GetUserPermission(req, auth)
|
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) {
|
func (t *TaskBiz) GetUserPermission(req *entitys.TaskRequest, auth string) (codes []string, err error) {
|
||||||
var (
|
|
||||||
request l_request.Request
|
|
||||||
)
|
|
||||||
|
|
||||||
// 构建请求URL
|
request := l_request.Request{
|
||||||
request.Url = t.conf.PermissionConfig.PermissionURL + strconv.Itoa(int(req.SysId))
|
Method: "GET",
|
||||||
|
Url: t.conf.PermissionConfig.PermissionURL + strconv.Itoa(int(req.SysId)),
|
||||||
request.Method = "GET"
|
Headers: map[string]string{
|
||||||
request.Headers = map[string]string{
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
|
"Accept": "application/json, text/plain, */*",
|
||||||
"Accept": "application/json, text/plain, */*",
|
"Authorization": auth,
|
||||||
"Authorization": auth,
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送请求
|
// 发送请求
|
||||||
res, err := request.Send()
|
res, err := request.Send()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -84,7 +82,7 @@ func (t *TaskBiz) GetUserPermission(req *entitys.TaskRequest, auth string) (code
|
||||||
type resp struct {
|
type resp struct {
|
||||||
Codes []string `json:"codes"`
|
Codes []string `json:"codes"`
|
||||||
}
|
}
|
||||||
// 解析响应体
|
// 解析响应体s
|
||||||
var respBody resp
|
var respBody resp
|
||||||
err = json.Unmarshal([]byte(res.Text), &respBody)
|
err = json.Unmarshal([]byte(res.Text), &respBody)
|
||||||
if err != nil {
|
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>
|
// AiTask mapped from table <ai_task>
|
||||||
type AiTask struct {
|
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"`
|
SysID int32 `gorm:"column:sys_id;not null" json:"sys_id"`
|
||||||
Name string `gorm:"column:name;not null" json:"name"`
|
Name string `gorm:"column:name;not null" json:"name"`
|
||||||
Index string `gorm:"column:index;not null" json:"index"`
|
Index string `gorm:"column:index;not null" json:"index"`
|
||||||
Desc string `gorm:"column:desc;not null" json:"desc"`
|
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"` // 适用场景
|
||||||
Config string `gorm:"column:config" json:"config"`
|
TempPrompt string `gorm:"column:temp_prompt;not null;comment:提示词模板" json:"temp_prompt"` // 提示词模板
|
||||||
CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"`
|
Type int32 `gorm:"column:type;not null;default:1;comment:类型,1:api,2:知识库" json:"type"` // 类型,1:api,2:知识库
|
||||||
UpdateAt time.Time `gorm:"column:update_at;default:CURRENT_TIMESTAMP" json:"update_at"`
|
Config string `gorm:"column:config" json:"config"`
|
||||||
Status int32 `gorm:"column:status;not null;default:1" json:"status"`
|
TagType int32 `gorm:"column:tag_type;comment:标签类型:1.AI日常 2.AI查询 3.AI执行" json:"tag_type"` // 标签类型:1.AI日常 2.AI查询 3.AI执行
|
||||||
DeleteAt time.Time `gorm:"column:delete_at" json:"delete_at"`
|
CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"`
|
||||||
UseCase string `gorm:"column:use_case;not null" json:"use_case"` // 适用场景
|
UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"`
|
||||||
TagType int32 `gorm:"column:tag_type;not null;default:1" json:"tag_type"` // 标签类型 1.AI日常 2.AI查询 3.AI执行
|
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
|
// TableName AiTask's table name
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue