Compare commits
No commits in common. "c96ee6cc38f470627c00616a24d7f838111a8f8b" and "5d1649de96da2f52c8ee1d31b18f6a0dd877aa1a" have entirely different histories.
c96ee6cc38
...
5d1649de96
|
|
@ -6,7 +6,6 @@ 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"
|
||||||
|
|
||||||
|
|
@ -152,38 +151,9 @@ 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
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@ 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"
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SessionImpl struct {
|
type SessionImpl struct {
|
||||||
|
|
@ -47,10 +46,3 @@ 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,12 +28,3 @@ 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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SessionRenameRequest struct {
|
|
||||||
SessionId string `json:"session_id"`
|
|
||||||
NewName string `json:"new_name"`
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,6 @@ 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("/session/rename", sessionService.RenameSession) // 会话重命名
|
|
||||||
|
|
||||||
r.Post("/sys/tasks", task.Tasks)
|
r.Post("/sys/tasks", task.Tasks)
|
||||||
// 评价
|
// 评价
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"ai_scheduler/internal/biz"
|
"ai_scheduler/internal/biz"
|
||||||
errorcode "ai_scheduler/internal/data/error"
|
|
||||||
"ai_scheduler/internal/entitys"
|
"ai_scheduler/internal/entitys"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
@ -71,42 +69,3 @@ 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",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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