1234567891011121314151617181920212223242526272829303132333435 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const assert = require('assert');
- // 展会公共聊天
- class DockChatService extends CrudService {
- constructor(ctx) {
- super(ctx, 'dock_chat');
- this.model = this.ctx.model.Dock.DockChat;
- }
- async create(data) {
- const res = await this.model.create(data);
- if (res) {
- const exchange = 'dockChat';
- const routeKey = `${res.dock_id}`;
- const content = JSON.stringify(_.pick(res, [ 'sender_id', 'sender_name', 'dock_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 = DockChatService;
|