瀏覽代碼

患者查群组,附带未读信息数量

lrf 1 年之前
父節點
當前提交
1880987070
共有 3 個文件被更改,包括 19 次插入2 次删除
  1. 2 1
      src/controller/group.controller.ts
  2. 1 1
      src/interface/group.interface.ts
  3. 16 0
      src/service/group.service.ts

+ 2 - 1
src/controller/group.controller.ts

@@ -46,11 +46,12 @@ export class GroupController extends BaseController {
   @ApiResponse({ type: QVO_group })
   async query(@Query() filter: QDTO_group, @Query('skip') skip: number, @Query('limit') limit: number) {
     const list = await this.service.query(filter, { skip, limit });
-    const data = [];
+    let data = [];
     for (const i of list) {
       const newData = new QVO_group(i);
       data.push(newData);
     }
+    if (filter.patients) data = await this.service.checkNotRead(data, filter.patients);
     const total = await this.service.count(filter);
     return { data, total };
   }

+ 1 - 1
src/interface/group.interface.ts

@@ -36,7 +36,7 @@ export class QDTO_group extends SearchBase {
   @ApiProperty({ description: '管理医生' })
   'doctor': string = undefined;
   @ApiProperty({ description: '群组病人' })
-  'patients': Array<any> = undefined;
+  'patients': string = undefined;
 }
 
 export class QVO_group extends FVO_group {

+ 16 - 0
src/service/group.service.ts

@@ -5,12 +5,15 @@ import { BaseService } from 'free-midway-component';
 import { Group } from '../entity/group.entity';
 import { Types } from 'mongoose';
 import { get, isNumber, omit } from 'lodash';
+import { Chat } from '../entity/chat.entity';
 const ObjectId = Types.ObjectId;
 type modelType = ReturnModelType<typeof Group>;
 @Provide()
 export class GroupService extends BaseService<modelType> {
   @InjectEntityModel(Group)
   model: modelType;
+  @InjectEntityModel(Chat)
+  chatModel: ReturnModelType<typeof Chat>;
 
   /**
    * 根据群组id,分页查询病人(只有名字)
@@ -57,4 +60,17 @@ export class GroupService extends BaseService<modelType> {
     });
     return afterDealList;
   }
+  /**
+   * 患者查群组列表时,返回患者的每个群组未读信息数量
+   * @param groupList 群组列表
+   * @param paitentId 患者id
+   */
+  async checkNotRead(groupList: Array<object>, paitentId: string) {
+    for (const g of groupList) {
+      const group = get(g, '_id');
+      const notRead = await this.chatModel.count({ group, speaker: { $ne: paitentId }, not_read: 1 });
+      g['notRead'] = notRead;
+    }
+    return groupList;
+  }
 }