Procházet zdrojové kódy

feat(order-module): 订单资产查询API添加文件实体关联

- 在查询订单人员资产服务中添加文件关系加载:`leftJoinAndSelect('asset.file', 'file')`
- 创建简化的文件schema(SimpleFileSchema),避免uploadUser字段验证问题
- 更新路由定义,响应中包含文件信息
- 修复文件fullUrl字段类型,从`z.url()`改为`z.string().optional()`
- API现在返回完整的文件信息,包括文件名、类型、大小、路径、URL等

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname před 2 týdny
rodič
revize
f1bfbdf74d

+ 39 - 0
allin-packages/order-module/src/routes/order-custom.routes.ts

@@ -15,6 +15,43 @@ import {
   UpdatePersonWorkStatusSchema
 } from '../schemas/order.schema';
 import { OrderStatus, WorkStatus } from '@d8d/allin-enums';
+import { FileSchema } from '@d8d/file-module';
+
+// 简化的文件schema,用于订单资产查询
+const SimpleFileSchema = z.object({
+  id: z.number().int().positive().openapi({
+    description: '文件ID',
+    example: 1
+  }),
+  name: z.string().max(255).openapi({
+    description: '文件名称',
+    example: '项目计划书.pdf'
+  }),
+  type: z.string().max(50).nullable().openapi({
+    description: '文件类型',
+    example: 'application/pdf'
+  }),
+  size: z.number().int().positive().nullable().openapi({
+    description: '文件大小,单位字节',
+    example: 102400
+  }),
+  path: z.string().max(512).openapi({
+    description: '文件存储路径',
+    example: '/uploads/documents/2023/project-plan.pdf'
+  }),
+  fullUrl: z.string().optional().openapi({
+    description: '完整文件访问URL',
+    example: 'https://minio.example.com/d8dai/uploads/documents/2023/project-plan.pdf'
+  }),
+  description: z.string().nullable().openapi({
+    description: '文件描述',
+    example: '2023年度项目计划书'
+  }),
+  uploadTime: z.coerce.date().openapi({
+    description: '上传时间',
+    example: '2023-01-15T10:30:00Z'
+  })
+});
 
 // 创建订单路由
 const createOrderRoute = createRoute({
@@ -414,6 +451,7 @@ const queryOrderPersonAssetRoute = createRoute({
               assetType: z.string().openapi({ description: '资产类型' }),
               assetFileType: z.string().openapi({ description: '资产文件类型' }),
               fileId: z.number().int().openapi({ description: '文件ID' }),
+              file: SimpleFileSchema.optional().openapi({ description: '文件信息' }),
               relatedTime: z.coerce.date().openapi({ description: '关联时间' }),
               createTime: z.coerce.date().openapi({ description: '创建时间' }),
               updateTime: z.coerce.date().openapi({ description: '更新时间' })
@@ -846,6 +884,7 @@ const app = new OpenAPIHono<AuthContext>()
             assetType: z.string(),
             assetFileType: z.string(),
             fileId: z.number().int(),
+            file: SimpleFileSchema.optional(),
             relatedTime: z.coerce.date(),
             createTime: z.coerce.date(),
             updateTime: z.coerce.date()

+ 2 - 1
allin-packages/order-module/src/services/order.service.ts

@@ -450,8 +450,9 @@ export class OrderService extends GenericCrudService<EmploymentOrder> {
     // 获取总数
     const total = await queryBuilder.getCount();
 
-    // 获取数据
+    // 获取数据,加载文件关系
     const data = await queryBuilder
+      .leftJoinAndSelect('asset.file', 'file')
       .skip((page - 1) * limit)
       .take(limit)
       .orderBy('asset.updateTime', 'DESC')