feat(documents): rebuild project document workbench
This commit is contained in:
@@ -174,19 +174,14 @@ func seedProjectA1(tx *gorm.DB, userID uint, projectID uint) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, note := range []models.SaNote{
|
||||
{ProjectID: projectID, CreatedBy: userID, Title: "用户权限体系设计文档 v2.1", Markdown: "# 权限体系\n\n围绕项目、任务和资料分享做保守授权。"},
|
||||
{ProjectID: projectID, CreatedBy: userID, Title: "导出功能技术方案评审", Markdown: "# 导出功能\n\n记录权限校验和任务队列方案。"},
|
||||
for _, document := range []struct {
|
||||
name string
|
||||
markdown string
|
||||
}{
|
||||
{name: "用户权限体系设计文档 v2.1.md", markdown: "# 权限体系\n\n围绕项目、任务和资料分享做保守授权。"},
|
||||
{name: "导出功能技术方案评审.md", markdown: "# 导出功能\n\n记录权限校验和任务队列方案。"},
|
||||
} {
|
||||
if err := firstOrCreateNote(tx, note); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, source := range []models.SaSource{
|
||||
{ProjectID: projectID, CreatedBy: userID, Kind: "file", Title: "2026 Q3 竞品功能对比表", FilePath: "projects/a1/competitors.xlsx", ContentText: "竞品功能矩阵和价格摘要"},
|
||||
{ProjectID: projectID, CreatedBy: userID, Kind: "link", Title: "客户访谈记录索引", URL: "https://example.com/interviews", ContentText: "客户访谈和问题归类"},
|
||||
} {
|
||||
if err := firstOrCreateSource(tx, source); err != nil {
|
||||
if err := firstOrCreateDocument(tx, projectID, userID, document.name, document.markdown); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -261,12 +256,25 @@ func firstOrCreateAISession(tx *gorm.DB, session models.SaAISession) error {
|
||||
return firstOrCreate(tx, &models.SaAISession{}, "project_id = ? AND title = ?", []any{session.ProjectID, session.Title}, session)
|
||||
}
|
||||
|
||||
func firstOrCreateNote(tx *gorm.DB, note models.SaNote) error {
|
||||
return firstOrCreate(tx, &models.SaNote{}, "project_id = ? AND title = ?", []any{note.ProjectID, note.Title}, note)
|
||||
}
|
||||
|
||||
func firstOrCreateSource(tx *gorm.DB, source models.SaSource) error {
|
||||
return firstOrCreate(tx, &models.SaSource{}, "project_id = ? AND title = ?", []any{source.ProjectID, source.Title}, source)
|
||||
func firstOrCreateDocument(tx *gorm.DB, projectID, userID uint, name, markdown string) error {
|
||||
var document models.SaDocument
|
||||
err := tx.Where("project_id = ? AND normalized_name = ?", projectID, strings.ToLower(name)).First(&document).Error
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
return err
|
||||
}
|
||||
document = models.SaDocument{
|
||||
ProjectID: projectID, CreatedBy: userID, Kind: models.DocumentKindFile,
|
||||
Name: name, NormalizedName: strings.ToLower(name), Extension: ".md",
|
||||
MimeType: "text/markdown; charset=utf-8", Size: int64(len([]byte(markdown))),
|
||||
Revision: 1, ScanStatus: "not_scanned",
|
||||
}
|
||||
if err := tx.Create(&document).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Create(&models.SaDocumentContent{DocumentID: document.ID, Markdown: markdown}).Error
|
||||
}
|
||||
|
||||
func firstOrCreateCronPlan(tx *gorm.DB, plan models.SaCronPlan) error {
|
||||
|
||||
@@ -147,8 +147,7 @@ func TestPostgresDemoSeedSerializesConcurrentRunsForSameOwner(t *testing.T) {
|
||||
assertPostgresDemoCount(t, database, &models.SaTask{}, "project_id IN ?", []any{projectIDs}, 6)
|
||||
assertPostgresDemoCount(t, database, &models.SaInboxItem{}, "project_id IN ?", []any{projectIDs}, 7)
|
||||
assertPostgresDemoCount(t, database, &models.SaAISession{}, "project_id = ?", []any{projects[0].ID}, 4)
|
||||
assertPostgresDemoCount(t, database, &models.SaNote{}, "project_id = ?", []any{projects[0].ID}, 2)
|
||||
assertPostgresDemoCount(t, database, &models.SaSource{}, "project_id = ?", []any{projects[0].ID}, 2)
|
||||
assertPostgresDemoCount(t, database, &models.SaDocument{}, "project_id = ?", []any{projects[0].ID}, 2)
|
||||
assertPostgresDemoCount(t, database, &models.SaCronPlan{}, "project_id = ?", []any{projects[0].ID}, 3)
|
||||
assertPostgresDemoCount(t, database, &models.SaProjectChannel{}, "project_id = ?", []any{projects[0].ID}, 2)
|
||||
}
|
||||
@@ -217,8 +216,7 @@ func cleanupPostgresDemoSeed(database *gorm.DB, userID uint) {
|
||||
}
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaProjectEvent{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaTask{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaNote{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaSource{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaDocument{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaAISession{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaTag{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaProjectChannel{})
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestDemoSeedCreatesFrontendWorkspaceData(t *testing.T) {
|
||||
require.GreaterOrEqual(t, len(workspace.Inbox), 4)
|
||||
require.GreaterOrEqual(t, len(workspace.Tasks), 3)
|
||||
require.GreaterOrEqual(t, len(workspace.AISessions), 4)
|
||||
require.GreaterOrEqual(t, len(workspace.NotesSources), 3)
|
||||
require.GreaterOrEqual(t, len(workspace.Documents), 2)
|
||||
require.GreaterOrEqual(t, len(workspace.CronPlans), 3)
|
||||
for _, plan := range workspace.CronPlans {
|
||||
require.Empty(t, plan.LastResult, "演示数据不得声称计划已执行")
|
||||
|
||||
Reference in New Issue
Block a user