Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
e1581b2d6f
|
|
@ -6,6 +6,7 @@ import (
|
|||
"ai_scheduler/internal/data/impl"
|
||||
"ai_scheduler/internal/data/model"
|
||||
"ai_scheduler/internal/entitys"
|
||||
"ai_scheduler/internal/pkg/util"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
|
|
@ -151,9 +152,38 @@ func (s *SessionBiz) SessionList(ctx context.Context, req *entitys.SessionListRe
|
|||
list, err = s.sessionRepo.FindAll(
|
||||
s.sessionRepo.WithUserId(req.UserId), // 条件:用户ID
|
||||
s.sessionRepo.WithSysId(req.SysId), // 条件:系统ID
|
||||
s.sessionRepo.WithDeleteAt(), // 条件:未删除
|
||||
s.sessionRepo.PaginateScope(req.Page, req.PageSize), // 分页
|
||||
s.sessionRepo.OrderByDesc("create_at"), // 排序:按创建时间降序
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteSession 删除会话
|
||||
func (s *SessionBiz) DeleteSession(ctx context.Context, req *entitys.SessionDeleteRequest) error {
|
||||
err := s.sessionRepo.Update(
|
||||
&model.AiSession{
|
||||
DeleteAt: util.AnyToPoint(time.Now()), // 设置删除时间
|
||||
},
|
||||
s.sessionRepo.WithSessionId(req.SessionId), // 条件:会话ID
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RenameSession 会话重命名
|
||||
func (s *SessionBiz) RenameSession(ctx context.Context, req *entitys.SessionRenameRequest) error {
|
||||
err := s.sessionRepo.Update(
|
||||
&model.AiSession{
|
||||
Title: req.NewName, // 设置会话名称
|
||||
},
|
||||
s.sessionRepo.WithSessionId(req.SessionId), // 条件:会话ID
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ var IrregularTaskToolIndexMap = map[string]string{
|
|||
"knowledgeBase": "knowledge_qa",
|
||||
"zltxOrderStatistics": "account_statistics",
|
||||
"normalChat": "chat",
|
||||
"zltxOrderAfterSaleSupplier": "after_sale_supplier",
|
||||
"zltxOrderAfterSaleReseller": "after_sale_reseller",
|
||||
"zltxOrderAfterSaleResellerBatch": "after_sale_reseller_batch",
|
||||
"zltxLossRiskSearch": "loss_order_direct",
|
||||
"zltxOrderAfterSaleSupplier": "after_sales_supplier",
|
||||
"zltxOrderAfterSaleReseller": "after_sales_reseller",
|
||||
"zltxOrderAfterSaleResellerBatch": "after_sales_reseller_batch",
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ import (
|
|||
"ai_scheduler/internal/data/model"
|
||||
"ai_scheduler/tmpl/dataTemp"
|
||||
"ai_scheduler/utils"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type SessionImpl struct {
|
||||
|
|
@ -46,3 +47,10 @@ func (impl *SessionImpl) WithSessionId(sessionId interface{}) CondFunc {
|
|||
return db.Where("session_id = ?", sessionId)
|
||||
}
|
||||
}
|
||||
|
||||
// WithDeletedAt 条件:是否删除
|
||||
func (impl *SessionImpl) WithDeleteAt() CondFunc {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
return db.Where("delete_at IS NULL")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,3 +28,12 @@ type UseFulRequest struct {
|
|||
HisId int64 `json:"his_id"`
|
||||
Useful int32 `json:"useful"`
|
||||
}
|
||||
|
||||
type SessionDeleteRequest struct {
|
||||
SessionId string `json:"session_id"`
|
||||
}
|
||||
|
||||
type SessionRenameRequest struct {
|
||||
SessionId string `json:"session_id"`
|
||||
NewName string `json:"new_name"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ func SetupRoutes(app *fiber.App, ChatService *services.ChatService, sessionServi
|
|||
r.Post("/session/new", sessionService.NewSession)
|
||||
r.Post("/session/init", sessionService.SessionInit) // 会话初始化,不存在则创建,存在则返回会话ID和默认条数会话历史
|
||||
r.Post("/session/list", sessionService.SessionList)
|
||||
r.Post("/session/delete", sessionService.DeleteSession) // 删除会话
|
||||
r.Post("/session/rename", sessionService.RenameSession) // 会话重命名
|
||||
|
||||
r.Post("/sys/tasks", task.Tasks)
|
||||
// 评价
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package services
|
|||
|
||||
import (
|
||||
"ai_scheduler/internal/biz"
|
||||
errorcode "ai_scheduler/internal/data/error"
|
||||
"ai_scheduler/internal/entitys"
|
||||
"net/http"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
|
@ -69,3 +71,42 @@ func (s *SessionService) SessionList(c *fiber.Ctx) error {
|
|||
"session_list": sessionList,
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteSession 删除会话
|
||||
func (s *SessionService) DeleteSession(c *fiber.Ctx) error {
|
||||
req := &entitys.SessionDeleteRequest{}
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := s.sessionBiz.DeleteSession(c.Context(), req)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"message": "success",
|
||||
})
|
||||
}
|
||||
|
||||
// RenameSession 会话重命名
|
||||
func (s *SessionService) RenameSession(c *fiber.Ctx) error {
|
||||
req := &entitys.SessionRenameRequest{}
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return err
|
||||
}
|
||||
if req.SessionId == "" || req.NewName == "" {
|
||||
return errorcode.NewBusinessErr(http.StatusBadRequest, "新会话名称不能为空")
|
||||
}
|
||||
|
||||
err := s.sessionBiz.RenameSession(c.Context(), req)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"message": "success",
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue