Browse Source

Merge branch 'main' of http://git.cc-lotus.info/follow-up/follow_server into main

zs 1 year ago
parent
commit
78d00dba50

+ 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 {

+ 3 - 2
src/service/chat.service.ts

@@ -15,11 +15,12 @@ export class ChatService extends BaseService<modelType> {
 
   async sendMq(data) {
     // 队列: /${群组id}/${患者id}
-    const { group, patient } = data;
+    const { group, patient, _id } = data;
     // 没有群组&患者id直接返回,无法构成队列
     if (!(group && patient)) return;
     const routingKey = `${group}_${patient}`;
-    await this.chatMqService.sendExMsg(routingKey, JSON.stringify(data));
+    const nd = await this.fetch(_id);
+    await this.chatMqService.sendExMsg(routingKey, JSON.stringify(nd));
   }
 
   async query(filter: SearchBase, pageOptions: PageOptions = {}): Promise<Array<any>> {

+ 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;
+  }
 }