fix: 1. session列表移除删除记录 2. 新增删除session记录接口
This commit is contained in:
parent
5d1649de96
commit
d3fe7ded1a
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"ai_scheduler/internal/data/impl"
|
"ai_scheduler/internal/data/impl"
|
||||||
"ai_scheduler/internal/data/model"
|
"ai_scheduler/internal/data/model"
|
||||||
"ai_scheduler/internal/entitys"
|
"ai_scheduler/internal/entitys"
|
||||||
|
"ai_scheduler/internal/pkg/util"
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -151,9 +152,24 @@ func (s *SessionBiz) SessionList(ctx context.Context, req *entitys.SessionListRe
|
||||||
list, err = s.sessionRepo.FindAll(
|
list, err = s.sessionRepo.FindAll(
|
||||||
s.sessionRepo.WithUserId(req.UserId), // 条件:用户ID
|
s.sessionRepo.WithUserId(req.UserId), // 条件:用户ID
|
||||||
s.sessionRepo.WithSysId(req.SysId), // 条件:系统ID
|
s.sessionRepo.WithSysId(req.SysId), // 条件:系统ID
|
||||||
|
s.sessionRepo.WithDeleteAt(), // 条件:未删除
|
||||||
s.sessionRepo.PaginateScope(req.Page, req.PageSize), // 分页
|
s.sessionRepo.PaginateScope(req.Page, req.PageSize), // 分页
|
||||||
s.sessionRepo.OrderByDesc("create_at"), // 排序:按创建时间降序
|
s.sessionRepo.OrderByDesc("create_at"), // 排序:按创建时间降序
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,9 @@ import (
|
||||||
"ai_scheduler/internal/data/model"
|
"ai_scheduler/internal/data/model"
|
||||||
"ai_scheduler/tmpl/dataTemp"
|
"ai_scheduler/tmpl/dataTemp"
|
||||||
"ai_scheduler/utils"
|
"ai_scheduler/utils"
|
||||||
"gorm.io/gorm"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SessionImpl struct {
|
type SessionImpl struct {
|
||||||
|
|
@ -46,3 +47,10 @@ func (impl *SessionImpl) WithSessionId(sessionId interface{}) CondFunc {
|
||||||
return db.Where("session_id = ?", sessionId)
|
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,7 @@ type UseFulRequest struct {
|
||||||
HisId int64 `json:"his_id"`
|
HisId int64 `json:"his_id"`
|
||||||
Useful int32 `json:"useful"`
|
Useful int32 `json:"useful"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SessionDeleteRequest struct {
|
||||||
|
SessionId string `json:"session_id"`
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ func SetupRoutes(app *fiber.App, ChatService *services.ChatService, sessionServi
|
||||||
r.Post("/session/new", sessionService.NewSession)
|
r.Post("/session/new", sessionService.NewSession)
|
||||||
r.Post("/session/init", sessionService.SessionInit) // 会话初始化,不存在则创建,存在则返回会话ID和默认条数会话历史
|
r.Post("/session/init", sessionService.SessionInit) // 会话初始化,不存在则创建,存在则返回会话ID和默认条数会话历史
|
||||||
r.Post("/session/list", sessionService.SessionList)
|
r.Post("/session/list", sessionService.SessionList)
|
||||||
|
r.Post("/session/delete", sessionService.DeleteSession) // 删除会话
|
||||||
|
|
||||||
r.Post("/sys/tasks", task.Tasks)
|
r.Post("/sys/tasks", task.Tasks)
|
||||||
// 评价
|
// 评价
|
||||||
|
|
|
||||||
|
|
@ -69,3 +69,21 @@ func (s *SessionService) SessionList(c *fiber.Ctx) error {
|
||||||
"session_list": sessionList,
|
"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",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue