后端:
1.阶段 6 CP4/CP5 目录收口与共享边界纯化
- 将 backend 根目录收口为 services、client、gateway、cmd、shared 五个一级目录
- 收拢 bootstrap、inits、infra/kafka、infra/outbox、conv、respond、pkg、middleware,移除根目录旧实现与空目录
- 将 utils 下沉到 services/userauth/internal/auth,将 logic 下沉到 services/schedule/core/planning
- 将迁移期 runtime 桥接实现统一收拢到 services/runtime/{conv,dao,eventsvc,model},删除 shared/legacy 与未再被 import 的旧 service 实现
- 将 gateway/shared/respond 收口为 HTTP/Gin 错误写回适配,shared/respond 仅保留共享错误语义与状态映射
- 将 HTTP IdempotencyMiddleware 与 RateLimitMiddleware 收口到 gateway/middleware
- 将 GormCachePlugin 下沉到 shared/infra/gormcache,将共享 RateLimiter 下沉到 shared/infra/ratelimit,将 agent token budget 下沉到 services/agent/shared
- 删除 InitEino 兼容壳,收缩 cmd/internal/coreinit 仅保留旧组合壳残留域初始化语义
- 更新微服务迁移计划与桌面 checklist,补齐 CP4/CP5 当前切流点、目录终态与验证结果
- 完成 go test ./...、git diff --check 与最终真实 smoke;health、register/login、task/create+get、schedule/today、task-class/list、memory/items、agent chat/meta/timeline/context-stats 全部 200,SSE 合并结果为 CP5_OK 且 [DONE] 只有 1 个
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package dao
|
||
|
||
import (
|
||
"context"
|
||
|
||
"github.com/LoveLosita/smartflow/backend/services/runtime/model"
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
type CourseDAO struct {
|
||
db *gorm.DB
|
||
}
|
||
|
||
// NewCourseDAO 创建ScheduleDAO实例
|
||
func NewCourseDAO(db *gorm.DB) *CourseDAO {
|
||
return &CourseDAO{
|
||
db: db,
|
||
}
|
||
}
|
||
|
||
func (r *CourseDAO) WithTx(tx *gorm.DB) *CourseDAO {
|
||
return &CourseDAO{db: tx}
|
||
}
|
||
|
||
func (r *CourseDAO) AddUserCoursesIntoSchedule(ctx context.Context, courses []model.Schedule) error {
|
||
if err := r.db.WithContext(ctx).Create(&courses).Error; err != nil {
|
||
return err
|
||
}
|
||
return nil
|
||
}
|
||
|
||
func (r *CourseDAO) AddUserCoursesIntoScheduleEvents(ctx context.Context, events []model.ScheduleEvent) ([]int, error) {
|
||
if err := r.db.WithContext(ctx).Create(&events).Error; err != nil {
|
||
return nil, err
|
||
}
|
||
ids := make([]int, 0, len(events))
|
||
for i := range events {
|
||
ids = append(ids, events[i].ID)
|
||
}
|
||
return ids, nil
|
||
}
|
||
|
||
// Transaction 在同一个数据库事务中执行传入的函数,供 service 层复用(自动提交/回滚)
|
||
// 规则:fn 返回 nil \-\> 提交;fn 返回 error 或发生 panic \-\> 回滚
|
||
// 说明:gorm\.\(\\\*DB\)\.Transaction 会在 fn 返回 error 时回滚,并在发生 panic 时自动回滚后继续向上抛出 panic
|
||
func (r *CourseDAO) Transaction(fn func(txDAO *CourseDAO) error) error {
|
||
return r.db.Transaction(func(tx *gorm.DB) error {
|
||
return fn(NewCourseDAO(tx))
|
||
})
|
||
}
|