dockChat.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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 assert = require('assert');
  6. // 展会公共聊天
  7. class DockChatService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'dock_chat');
  10. this.model = this.ctx.model.Dock.DockChat;
  11. }
  12. async create(data) {
  13. const res = await this.model.create(data);
  14. if (res) {
  15. const exchange = 'dockChat';
  16. const routeKey = `${res.dock_id}`;
  17. const content = JSON.stringify(_.pick(res, [ 'sender_id', 'sender_name', 'dock_id', 'send_time', 'content' ]));
  18. const param = { durable: true };
  19. const { mq } = this.ctx;
  20. if (mq) {
  21. try {
  22. await mq.topic(exchange, routeKey, content, param);
  23. } catch (error) {
  24. this.ctx.logger.error(error);
  25. }
  26. } else {
  27. this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
  28. }
  29. }
  30. return res;
  31. }
  32. }
  33. module.exports = DockChatService;