Compare commits

..

No commits in common. "v4" and "master" have entirely different histories.
v4 ... master

5 changed files with 1 additions and 91 deletions

View File

@ -6,7 +6,6 @@ import (
"ai_scheduler/internal/data/impl"
"ai_scheduler/internal/data/model"
"ai_scheduler/internal/entitys"
"ai_scheduler/internal/pkg/util"
"context"
"time"
@ -152,38 +151,9 @@ 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
}

View File

@ -4,9 +4,8 @@ import (
"ai_scheduler/internal/data/model"
"ai_scheduler/tmpl/dataTemp"
"ai_scheduler/utils"
"time"
"gorm.io/gorm"
"time"
)
type SessionImpl struct {
@ -47,10 +46,3 @@ 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")
}
}

View File

@ -28,12 +28,3 @@ 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"`
}

View File

@ -59,8 +59,6 @@ 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)
// 评价

View File

@ -2,9 +2,7 @@ package services
import (
"ai_scheduler/internal/biz"
errorcode "ai_scheduler/internal/data/error"
"ai_scheduler/internal/entitys"
"net/http"
"github.com/gofiber/fiber/v2"
)
@ -71,42 +69,3 @@ 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",
})
}