'use strict'; const assert = require('assert'); const { CrudService } = require('naf-framework-mongoose/lib/service'); const moment = require('moment'); // 培训问诊聊天 class TrainchatService extends CrudService { constructor(ctx) { super(ctx, 'trainchat'); this.model = this.ctx.model.Trainchat; } async create(query, { unit_id, sender_id, sender_name, content, role }) { assert(sender_name, '缺少发言人信息'); assert(unit_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, unit_id }); // TODO MQ const { mq } = this.ctx; if (mq) { const exchange = 'train_live'; const parm = { durable: true, headers: { userid: 1, } }; await mq.fanout(exchange, unit_id, JSON.stringify(res), parm); } return res; } } module.exports = TrainchatService;