trainChat.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const moment = require('moment');
  6. const assert = require('assert');
  7. // 培训问诊聊天
  8. class TrainChatService extends CrudService {
  9. constructor(ctx) {
  10. super(ctx, 'train_chat');
  11. this.model = this.ctx.model.Consultation.TrainChat;
  12. }
  13. async create(data) {
  14. const res = await this.model.create(data);
  15. if (res) {
  16. const exchange = "train_live";
  17. const routeKey = `${res.train_id}`;
  18. const content = JSON.stringify(_.pick(res, [ 'sender_id', 'sender_name', 'train_id', 'send_time', 'content' ]));
  19. const param = { durable: true };
  20. const { mq } = this.ctx;
  21. if (mq) {
  22. try {
  23. await mq.topic(exchange, routeKey, content, param);
  24. } catch (error) {
  25. this.ctx.logger.error(error);
  26. }
  27. } else {
  28. this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
  29. }
  30. }
  31. return res;
  32. }
  33. }
  34. module.exports = TrainChatService;