|
@@ -14,14 +14,14 @@ export class MessageService extends BaseServiceV2 {
|
|
|
@Config('modulesConfig.mq')
|
|
|
mqServiceHttpPrefix: any;
|
|
|
getQueryColumnsOpera() {
|
|
|
- return { 'to.user': this.Opera.JsonArrayObject, 'to.is_read': this.Opera.JsonArrayObject };
|
|
|
+ return { 'to.user': this.Opera.JsonArrayObject, 'to.is_read': this.Opera.JsonArrayObject, 'to.user_type': this.Opera.JsonArrayObject };
|
|
|
}
|
|
|
|
|
|
|
|
|
- async read({ id }) {
|
|
|
+ async read({ id, user_type }) {
|
|
|
const list = await this.model
|
|
|
.createQueryBuilder()
|
|
|
- .where('"to" @> :member', { member: JSON.stringify([{ user: parseInt(id) }]) })
|
|
|
+ .where('"to" @> :member', { member: JSON.stringify([{ user: parseInt(id), user_type }]) })
|
|
|
.getMany();
|
|
|
for (const tag of list) {
|
|
|
const to = get(tag, 'to', []);
|
|
@@ -31,15 +31,35 @@ export class MessageService extends BaseServiceV2 {
|
|
|
await this.model.update({ id: tag.id }, { to: to });
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ * 发送消息
|
|
|
+ * @param id 消息数据id
|
|
|
+ */
|
|
|
+ async toSendMsg(id) {
|
|
|
+ const data = await this.model.createQueryBuilder().where(`id =:id`, { id }).getOne();
|
|
|
+ if (!data) return;
|
|
|
+ const data_content = get(data, 'content');
|
|
|
+ const to = get(data, 'to', []);
|
|
|
+ for (const i of to) {
|
|
|
+ const target = get(i, 'user');
|
|
|
+ const userType = get(i, 'user_type');
|
|
|
+ const content = {
|
|
|
+ data_id: id,
|
|
|
+ content: data_content,
|
|
|
+ };
|
|
|
+ this.toSendMq(target, userType, content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 发送mq消息
|
|
|
* @param target mq接收人
|
|
|
* @param userType 用户类型
|
|
|
- * @param data_id 消息数据id
|
|
|
+ * @param content 消息对象
|
|
|
*/
|
|
|
- async toSendMq(target, userType: MessageUserType, data_id) {
|
|
|
+ async toSendMq(target, userType: MessageUserType, content) {
|
|
|
const url = `${this.mqServiceHttpPrefix}/send`;
|
|
|
- const body = { target, userType, data_id };
|
|
|
+ const body = { target, userType, content };
|
|
|
try {
|
|
|
await Axios.post(url, body, { responseType: 'json' });
|
|
|
} catch (error) {
|