feiyu02
2024-08-15 196bb14112448857a885e32dc4149e308e00b01a
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cn.flightfeather.supervision.lightshare.web
 
import cn.flightfeather.supervision.domain.entity.NoticeConfig
import cn.flightfeather.supervision.lightshare.service.NotificationService
import cn.flightfeather.supervision.lightshare.vo.NoticeReadStateVo
import cn.flightfeather.supervision.lightshare.vo.NotificationVo
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import org.springframework.web.bind.annotation.*
import javax.servlet.http.HttpServletResponse
 
@Api(tags = ["通知API接口"])
@RestController
@RequestMapping("/notifications")
class NotificationController(val notificationService: NotificationService) {
 
    @ApiOperation(value = "按查询条件获取通知")
    @PostMapping("/history")
    fun getAllNotices(
        @ApiParam("用户id") @RequestParam(value = "userId") userId: String,
        @ApiParam("通知查询条件") @RequestBody noticeConfig: NoticeConfig,
        @ApiParam("页码") @RequestParam(value = "page") page: Int,
        @ApiParam("单页数据量") @RequestParam(value = "per_page") perPage: Int,
    ) = notificationService.getAllNotices(userId, noticeConfig, page, perPage)
 
    @ApiOperation(value = "获取用户未读通知")
    @GetMapping
    fun getNotificationUnRead(
        @ApiParam("用户id") @RequestParam(value = "userId") userId: String,
        @ApiParam("页码") @RequestParam(value = "page") page: Int,
        @ApiParam("单页数据量") @RequestParam(value = "per_page") perPage: Int,
        response: HttpServletResponse
    ) = notificationService.getNotificationUnRead(userId, page, perPage, response)
 
    @ApiOperation(value = "更新通知读取状态")
    @PostMapping("/{userId}/readState")
    fun updateReadState(
        @ApiParam("用户id") @PathVariable("userId") userId: String,
        @ApiParam("通知读取状态") @RequestBody readStates: List<NoticeReadStateVo>
    ) = notificationService.updateReadState(userId, readStates)
 
    @ApiOperation(value = "获取通知长文本内容")
    @GetMapping("/text")
    fun getNotificationText(
        @ApiParam("通知id") @RequestParam(value = "id") notificationId: String
    ) = notificationService.getNotificationText(notificationId)
 
    @ApiOperation(value = "获取总未读通知数量")
    @GetMapping("/{userId}/unread")
    fun getUnReadNoticeNum(
        @ApiParam("用户id") @PathVariable("userId") userId: String
    ) = notificationService.getUnReadNoticeNum(userId)
 
    @ApiOperation(value = "发布通知")
    @PostMapping("/{userId}/release")
    fun releaseNotice(
        @ApiParam("用户id") @PathVariable("userId") userId: String,
        @ApiParam("通知") @RequestBody notice: NotificationVo
    ) = notificationService.releaseNotice(userId, notice)
 
    @ApiOperation(value = "发布通知")
    @PostMapping("/{userId}/release2")
    fun releaseNotice2(
        @ApiParam("用户id") @PathVariable("userId") userId: String,
        @ApiParam("通知") @RequestBody notice: NotificationVo
    ) = notificationService.releaseNotice2(userId, notice)
 
    @ApiOperation(value = "推送一条微信订阅消息")
    @GetMapping("/wx/message/subscribe/send")
    fun pushMsgWx(
        @ApiParam("模板id") @RequestParam("templateId") templateId: Int
    ) = notificationService.pushMsgWx(templateId)
 
    @ApiOperation(value = "获取通知模板")
    @GetMapping("/template")
    fun getTemplate(
        @ApiParam("通知类型") @RequestParam("typeId") typeId: Int,
        @ApiParam("通知子类型") @RequestParam("subTypeId") subTypeId: Int,
    ) = notificationService.getTemplate(typeId, subTypeId)
}