1234567891011121314151617181920212223242526272829303132333435 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const moment = require('moment');
- const assert = require('assert');
- // 培训问诊聊天
- class Train_chatService extends CrudService {
- constructor(ctx) {
- super(ctx, 'train_chat');
- 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 = Train_chatService;
|