Browse Source

fix(api): 修复残疾人聚合API文件实体关联查询

- 更新Schema:在DisabledPhotoSchema和DisabledBankCardSchema中添加file字段
- 更新服务层:在findOne和update方法中添加bankCards.file和photos.file关联查询
- 修复关联查询:确保API返回完整的文件实体信息,而不仅仅是fileId

🤖 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 1 ngày trước cách đây
mục cha
commit
c832ac5a08

+ 35 - 0
allin-packages/disability-module/src/schemas/disabled-person.schema.ts

@@ -1,4 +1,5 @@
 import { z } from '@hono/zod-openapi';
+import { FileSchema } from '@d8d/file-module/';
 
 // 基础字段定义
 const BaseDisabledPersonSchema = z.object({
@@ -326,6 +327,23 @@ export const DisabledBankCardSchema = z.object({
     description: '银行卡照片文件ID',
     example: 1
   }),
+  file: FileSchema.nullable().optional().openapi({
+    description: '银行卡照片文件实体信息',
+    example: {
+      id: 2,
+      name: '银行卡照片.jpg',
+      type: 'image/jpeg',
+      size: 102400,
+      path: '/uploads/2024/01/bank-card.jpg',
+      fullUrl: 'https://minio.example.com/d8dai/uploads/2024/01/bank-card.jpg',
+      description: '银行卡正面照片',
+      uploadUserId: 1,
+      uploadTime: '2024-01-01T10:30:00Z',
+      lastUpdated: null,
+      createdAt: '2024-01-01T10:30:00Z',
+      updatedAt: '2024-01-01T10:30:00Z'
+    }
+  }),
   isDefault: z.number().int().min(0).max(1).default(0).openapi({
     description: '是否默认:1-是,0-否',
     example: 1
@@ -350,6 +368,23 @@ export const DisabledPhotoSchema = z.object({
     description: '照片文件ID',
     example: 1
   }),
+  file: FileSchema.nullable().optional().openapi({
+    description: '文件实体信息',
+    example: {
+      id: 1,
+      name: '身份证照片.jpg',
+      type: 'image/jpeg',
+      size: 102400,
+      path: '/uploads/2024/01/id-photo.jpg',
+      fullUrl: 'https://minio.example.com/d8dai/uploads/2024/01/id-photo.jpg',
+      description: '身份证正面照片',
+      uploadUserId: 1,
+      uploadTime: '2024-01-01T10:30:00Z',
+      lastUpdated: null,
+      createdAt: '2024-01-01T10:30:00Z',
+      updatedAt: '2024-01-01T10:30:00Z'
+    }
+  }),
   uploadTime: z.coerce.date().openapi({
     description: '上传时间',
     example: '2024-01-01T00:00:00Z'

+ 2 - 2
allin-packages/disability-module/src/services/aggregated.service.ts

@@ -241,7 +241,7 @@ export class AggregatedService {
     // 检查残疾人是否存在
     const existingPerson = await this.personRepository.findOne({
       where: { id: personId },
-      relations: ['bankCards', 'photos', 'remarks', 'visits']
+      relations: ['bankCards', 'bankCards.file', 'photos', 'photos.file', 'remarks', 'visits']
     });
 
     if (!existingPerson) {
@@ -303,7 +303,7 @@ export class AggregatedService {
     // 获取更新后的完整数据
     const updatedPerson = await this.personRepository.findOne({
       where: { id: personId },
-      relations: ['bankCards', 'photos', 'remarks', 'visits']
+      relations: ['bankCards', 'bankCards.file', 'photos', 'photos.file', 'remarks', 'visits']
     });
 
     if (!updatedPerson) {

+ 1 - 1
allin-packages/disability-module/src/services/disabled-person.service.ts

@@ -91,7 +91,7 @@ export class DisabledPersonService extends GenericCrudService<DisabledPerson> {
   async findOne(id: number): Promise<DisabledPerson | null> {
     const person = await this.repository.findOne({
       where: { id },
-      relations: ['bankCards', 'photos', 'photos.file', 'remarks', 'visits']
+      relations: ['bankCards', 'bankCards.file', 'photos', 'photos.file', 'remarks', 'visits']
     });
 
     if (person && person.photos) {

+ 6 - 4
allin-packages/disability-person-management-ui/src/components/DisabilityPersonManagement.tsx

@@ -409,7 +409,7 @@ const DisabilityPersonManagement: React.FC = () => {
 
       {/* 创建/编辑模态框 */}
       <Dialog open={isModalOpen} onOpenChange={setIsModalOpen}>
-        <DialogContent className="w-[95vw] max-w-4xl max-h-[80vh] flex flex-col">
+        <DialogContent className="w-[95vw] max-w-4xl max-h-[85vh] flex flex-col overflow-hidden">
           <DialogHeader>
             <DialogTitle data-testid={isCreateForm ? 'create-disabled-person-dialog-title' : 'edit-disabled-person-dialog-title'}>
               {isCreateForm ? '新增残疾人' : '编辑残疾人信息'}
@@ -418,7 +418,7 @@ const DisabilityPersonManagement: React.FC = () => {
               {isCreateForm ? '填写残疾人基本信息,带*的为必填项' : '修改残疾人信息'}
             </DialogDescription>
           </DialogHeader>
-          <div className="flex-1 overflow-y-auto pr-2 overscroll-contain touch-auto">
+          <div className="flex-1 overflow-y-auto pr-2 overscroll-contain touch-auto py-2 scrollbar-thin scrollbar-thumb-gray-300 scrollbar-track-gray-100 hover:scrollbar-thumb-gray-400">
             {isCreateForm ? (
               <Form {...createForm}>
                 <form id="create-form" onSubmit={createForm.handleSubmit(onSubmitCreate, (errors) => console.debug('创建表单验证错误:', errors))} className="space-y-4">
@@ -895,14 +895,15 @@ const DisabilityPersonManagement: React.FC = () => {
 
       {/* 查看详情模态框 */}
       <Dialog open={viewDialogOpen} onOpenChange={setViewDialogOpen}>
-        <DialogContent className="max-w-4xl">
+        <DialogContent className="max-w-4xl max-h-[85vh] flex flex-col overflow-hidden">
           <DialogHeader>
             <DialogTitle>残疾人详情</DialogTitle>
             <DialogDescription>查看残疾人详细信息</DialogDescription>
           </DialogHeader>
 
           {viewData && (
-            <div className="space-y-4">
+            <div className="flex-1 overflow-y-auto pr-2 overscroll-contain touch-auto py-2">
+              <div className="space-y-4">
               <div className="grid grid-cols-2 gap-4">
                 <div>
                   <label className="text-sm font-medium">姓名</label>
@@ -985,6 +986,7 @@ const DisabilityPersonManagement: React.FC = () => {
                 </div>
               )}
             </div>
+            </div>
           )}
 
           <DialogFooter>