wangzhibo
6 天以前 7dcc2997614f849258091f5d66e648317a40d323
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { CoolController, BaseController } from '@cool-midway/core';
import { CsMsgEntity } from '../../entity/msg';
import { UserInfoEntity } from '../../../user/entity/info';
import { BaseSysUserEntity } from '../../../base/entity/sys/user';
import { CsMsgService } from '../../service/msg';
import { Body, Get, Inject, Post } from '@midwayjs/core';
 
/**
 * 消息
 */
@CoolController({
  api: ['page'],
  entity: CsMsgEntity,
  service: CsMsgService,
  pageQueryOp: {
    select: [
      'a.*',
      'b.nickName',
      'b.avatarUrl',
      'c.name as adminUserName',
      'c.headImg as adminUserHeadImg',
    ],
    join: [
      {
        entity: UserInfoEntity,
        alias: 'b',
        condition: 'a.userId = b.id and a.type = 0',
      },
      {
        entity: BaseSysUserEntity,
        alias: 'c',
        condition: 'a.userId = c.id and a.type = 1',
      },
    ],
    where: ctx => {
      const { sessionId } = ctx.request.body;
      return [['a.sessionId = :sessionId', { sessionId }]];
    },
  },
})
export class AdminCsMsgController extends BaseController {
  @Inject()
  ctx;
 
  @Inject()
  csMsgService: CsMsgService;
 
  @Get('/unreadCount', { summary: '未读消息数' })
  async unreadCount() {
    return this.ok(await this.csMsgService.unreadCount(null, 0));
  }
 
  @Post('/read', { summary: '标记已读' })
  async read(@Body('msgIds') msgIds: number[]) {
    this.csMsgService.read(msgIds);
    return this.ok();
  }
}