Browse Source

♻️ refactor(solution-design): 优化SolutionDesignService依赖注入和类型处理

- 移除DocumentService构造函数的dataSource参数依赖
- 修复savedDesign.id可能为undefined的类型断言
- 为getById调用添加结果检查,防止返回undefined
- 修正SolutionChapter类型断言,确保类型一致性
- 调整fileService.createFile参数,使用name替代originalName,path替代storagePath

🐛 fix(solution-design): 修复创建方案设计后的错误处理

- 添加getById结果检查,当获取不到设计时抛出明确错误
- 修正fileService.createFile调用参数名称,匹配接口定义
yourname 2 tháng trước cách đây
mục cha
commit
625ea47abc
1 tập tin đã thay đổi với 15 bổ sung11 xóa
  1. 15 11
      src/server/modules/solution-designs/solution-design.service.ts

+ 15 - 11
src/server/modules/solution-designs/solution-design.service.ts

@@ -1,5 +1,5 @@
 import { GenericCrudService } from '@/server/utils/generic-crud.service';
-import { DataSource, Repository, In } from 'typeorm';
+import { DataSource, Repository } from 'typeorm';
 import { SolutionDesign } from './solution-design.entity';
 import { SolutionChapter } from './solution-chapter.entity';
 import { DocumentService } from '@/server/modules/documents/document.service';
@@ -27,7 +27,7 @@ export class SolutionDesignService extends GenericCrudService<SolutionDesign> {
   constructor(dataSource: DataSource) {
     super(dataSource, SolutionDesign);
     this.chapterRepository = dataSource.getRepository(SolutionChapter);
-    this.documentService = new DocumentService(dataSource);
+    this.documentService = new DocumentService();
     this.fileService = new FileService(dataSource);
     this.aiService = new AIService();
   }
@@ -54,10 +54,14 @@ export class SolutionDesignService extends GenericCrudService<SolutionDesign> {
 
     // 如果有原始文件,尝试自动提取章节
     if (originalFileId) {
-      await this.autoExtractChapters(savedDesign.id, originalFileId);
+      await this.autoExtractChapters(savedDesign.id!, originalFileId);
     }
 
-    return this.getById(savedDesign.id, ['user', 'originalFile', 'chapters']);
+    const result = await this.getById(savedDesign.id!, ['user', 'originalFile', 'chapters']);
+    if (!result) {
+      throw new Error('创建方案设计失败');
+    }
+    return result;
   }
 
   /**
@@ -151,7 +155,7 @@ export class SolutionDesignService extends GenericCrudService<SolutionDesign> {
     // 更新总章节数
     await this.repository.increment({ id: designId }, 'totalChapters', 1);
 
-    return savedChapter;
+    return savedChapter as unknown as SolutionChapter;
   }
 
   /**
@@ -318,17 +322,17 @@ export class SolutionDesignService extends GenericCrudService<SolutionDesign> {
     const downloadUrl = await this.documentService.saveToMinio(buffer, fileName);
 
     // 创建文件记录
-    const file = await this.fileService.createFile({
-      originalName: fileName,
+    const fileResult = await this.fileService.createFile({
+      name: fileName,
       size: buffer.length,
-      mimeType: design.outputFormat === 'pdf' ? 'application/pdf' : 
-               'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
-      storagePath: downloadUrl
+      type: design.outputFormat === 'pdf' ? 'application/pdf' :
+             'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+      path: downloadUrl
     });
 
     // 更新方案设计的输出文件
     await this.repository.update(designId, {
-      outputFileId: file.id,
+      outputFileId: fileResult.file.id,
       status: 'completed'
     });