Browse Source

公共聊天需要区分对接会

lrf402788946 4 years ago
parent
commit
a116733c1d
2 changed files with 6 additions and 4 deletions
  1. 2 1
      app/model/chat.js
  2. 4 3
      app/service/chat.js

+ 2 - 1
app/model/chat.js

@@ -3,11 +3,12 @@ const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 
 const Chat = {
+  dock_id: { type: String, maxLength: 200 }, // 对接会id,公共聊天区分对接会
   sender_id: { type: String, maxLength: 200 }, // 发言人id
   sender_name: { type: String, required: true, maxLength: 200 }, // 发言人名称
   content: { type: String, required: true, maxLength: 1000 }, // 发言内容
   send_time: { type: String, required: true, maxLength: 100 }, // 发言时间:年月日时分秒
-  role: { type: String, maxLength: 200 }, //用户身份
+  role: { type: String, maxLength: 200 }, // 用户身份
 };
 const schema = new Schema(Chat, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });

+ 4 - 3
app/service/chat.js

@@ -11,11 +11,12 @@ class ChatService extends CrudService {
     super(ctx, 'chat');
     this.model = this.ctx.model.Chat;
   }
-  async create(query, { sender_id, sender_name, content, role }) {
+  async create(query, { dock_id, sender_id, sender_name, content, role }) {
     assert(sender_name, '缺少发言人信息');
+    assert(dock_id, '缺少对接会id');
     assert(content, '缺少发言内容');
     const send_time = moment().format('YYYY-MM-DD HH:mm:ss');
-    const res = await this.model.create({ sender_id, sender_name, content, send_time, role });
+    const res = await this.model.create({ sender_id, sender_name, content, send_time, role, dock_id });
     // TODO MQ
     const { mq } = this.ctx;
     if (mq) {
@@ -25,7 +26,7 @@ class ChatService extends CrudService {
         headers: {
           userid: 1,
         } };
-      await mq.fanout(exchange, '1', JSON.stringify(res), parm);
+      await mq.fanout(exchange, dock_id, JSON.stringify(res), parm);
     }
     return res;
   }