|
@@ -1,12 +1,12 @@
|
|
|
-import { Body, Controller, Del, Get, Inject, Param, Post, Query } from "@midwayjs/core";
|
|
|
-import { ApiQuery, ApiTags } from "@midwayjs/swagger";
|
|
|
-import { BaseController } from "../../frame/BaseController";
|
|
|
-import { Validate } from "@midwayjs/validate";
|
|
|
-import { omit, pick } from "lodash";
|
|
|
-import { ServiceError, ErrorCode } from "../../error/service.error";
|
|
|
-import { FVO_region, CVO_region } from "../../interface/system/region.interface";
|
|
|
-import { MessageService } from "../../service/system/message.service";
|
|
|
-
|
|
|
+import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/core';
|
|
|
+import { ApiQuery, ApiTags } from '@midwayjs/swagger';
|
|
|
+import { BaseController } from '../../frame/BaseController';
|
|
|
+import { Validate } from '@midwayjs/validate';
|
|
|
+import { get, omit, pick } from 'lodash';
|
|
|
+import { ServiceError, ErrorCode } from '../../error/service.error';
|
|
|
+import { MessageService } from '../../service/system/message.service';
|
|
|
+import { Context } from '@midwayjs/koa';
|
|
|
+import { MessageUserType } from '../../public/var';
|
|
|
|
|
|
const namePrefix = '消息';
|
|
|
@ApiTags(['消息'])
|
|
@@ -16,22 +16,28 @@ export class RegionController implements BaseController {
|
|
|
@Inject()
|
|
|
service: MessageService;
|
|
|
|
|
|
+ @Inject()
|
|
|
+ ctx: Context;
|
|
|
+
|
|
|
@Get('/')
|
|
|
@ApiTags('列表查询')
|
|
|
@ApiQuery({ name: 'query' })
|
|
|
async index(@Query() query: object) {
|
|
|
const qobj = omit(query, ['skip', 'limit']);
|
|
|
const others = pick(query, ['skip', 'limit']);
|
|
|
- const result = await this.service.query(qobj, others);
|
|
|
- return result;
|
|
|
+ let { data, total } = await this.service.query(qobj, others);
|
|
|
+ // 如果query中有'to.user',那就把to中其他的人的数据都删掉
|
|
|
+ if (qobj['to.user']) {
|
|
|
+ data = await this.service.deleteOtherUserInfo(data, qobj['to.user']);
|
|
|
+ }
|
|
|
+ return { data, total };
|
|
|
}
|
|
|
|
|
|
@Get('/:id')
|
|
|
@ApiTags('单查询')
|
|
|
async fetch(@Param('id') id: number) {
|
|
|
const data = await this.service.fetch({ id });
|
|
|
- const result = new FVO_region(data);
|
|
|
- return result;
|
|
|
+ return data;
|
|
|
}
|
|
|
|
|
|
@Post('/', { routerName: `创建${namePrefix}` })
|
|
@@ -39,8 +45,24 @@ export class RegionController implements BaseController {
|
|
|
@Validate()
|
|
|
async create(@Body() data: object) {
|
|
|
const dbData = await this.service.create(data);
|
|
|
- const result = new CVO_region(dbData);
|
|
|
- return result;
|
|
|
+ // 需要让mq发送消息,触发前端接收消息
|
|
|
+ const to = get(dbData, 'to', []);
|
|
|
+ for (const i of to) {
|
|
|
+ await this.service.toSendMq(get(i, 'user'), MessageUserType.USER, get(dbData, 'id'));
|
|
|
+ }
|
|
|
+ return dbData;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Post('/remind/:id', { routerName: `重提示${namePrefix}` })
|
|
|
+ @ApiTags('重提示')
|
|
|
+ async remind(@Param('id') id: number) {
|
|
|
+ const message = await this.service.fetch({ id });
|
|
|
+ if (!message) return;
|
|
|
+ const to = get(message, 'to', []);
|
|
|
+ for (const i of to) {
|
|
|
+ await this.service.toSendMq(get(i, 'user'), MessageUserType.USER, id);
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
@Post('/:id', { routerName: `修改${namePrefix}` })
|
|
@@ -61,4 +83,15 @@ export class RegionController implements BaseController {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+ @Get('/checkNotRead')
|
|
|
+ @ApiTags('列表查询')
|
|
|
+ @ApiQuery({ name: 'query' })
|
|
|
+ async checkNotRead() {
|
|
|
+ const qobj = { 'to.is_read': '0' };
|
|
|
+ const user = get(this.ctx, 'user');
|
|
|
+ if (!user) return 0;
|
|
|
+ qobj['to.user'] = get(user, 'id');
|
|
|
+ const result = await this.service.query(qobj, { selects: ['id'] });
|
|
|
+ return get(result, 'total');
|
|
|
+ }
|
|
|
+}
|