123456789101112131415161718192021222324252627282930313233343536 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const moment = require('moment');
- const assert = require('assert');
- // 培训问诊聊天
- class TrainChatService extends CrudService {
- constructor(ctx) {
- super(ctx, 'train_chat');
- this.model = this.ctx.model.Consultation.TrainChat;
- }
- async create(data) {
- const res = await this.model.create(data);
- if (res) {
- const exchange = "train_live";
- const routeKey = `${res.train_id}`;
- const content = JSON.stringify(_.pick(res, [ 'sender_id', 'sender_name', 'train_id', 'send_time', 'content' ]));
- const param = { durable: true };
- const { mq } = this.ctx;
- if (mq) {
- try {
- await mq.topic(exchange, routeKey, content, param);
- } catch (error) {
- this.ctx.logger.error(error);
- }
- } else {
- this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
- }
- }
- return res;
- }
- }
- module.exports = TrainChatService;
|