puzhibing
2026-04-10 ed838e62602c0a63a64ff4bd144a0d16cc9a7cf8
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
82
83
package com.xiaopeng.account.controller;
 
import com.xiaopeng.account.model.query.XpOperationsUserNotificationPageQuery;
import com.xiaopeng.account.service.IXpOperationsUserNotificationService;
import com.xiaopeng.api.model.account.XpOperationsUserNotification;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.web.page.PageInfo;
import com.xiaopeng.common.security.service.TokenService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * <p>
 * 运维人员消息通知表 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2026-02-03
 */
@Slf4j
@RestController
@RequestMapping("maintenance-app")
public class XpOperationsUserNotificationAPPController {
 
    @Autowired
    private IXpOperationsUserNotificationService notificationService;
 
    @Autowired
    private TokenService tokenService;
 
    /**
     * 根据当前登录用户获取通知分页列表(运维APP接口)
     */
    @PostMapping("/api/v1/notification/list")
    @ApiOperation(value = "获取通知分页列表", tags = {"运维APP-消息通知"})
    public R<PageInfo<XpOperationsUserNotification>> getNotificationList(
            @RequestBody XpOperationsUserNotificationPageQuery query) {
 
        log.info("查询通知分页列表, pageNum={}, pageSize={}",
            query.getPageNum(), query.getPageSize());
 
        // 从Token中获取当前登录用户ID
        Long currentUserId = tokenService.getLoginOperationUser().getId();
        query.setOperationsUserId(currentUserId);
 
        // 查询分页列表
        PageInfo<XpOperationsUserNotification> pageInfo =
            notificationService.selectNotificationPageByUserId(query);
 
        log.info("查询通知分页列表成功, userId={}, total={}",
            currentUserId, pageInfo.getTotal());
 
        return R.ok(pageInfo);
    }
 
    @GetMapping("/api/v1/notification/unreadCount")
    @ApiOperation(value = "获取未读通知数量", tags = {"运维APP-消息通知"})
    public R<Long> getUnreadNotificationCount() {
        // 从Token中获取当前登录用户ID
        Long currentUserId = tokenService.getLoginOperationUser().getId();
        Long count = notificationService.lambdaQuery().eq(XpOperationsUserNotification::getOperationsUserId, currentUserId)
                .eq(XpOperationsUserNotification::getReadStatus, 0).count();
        return R.ok(count);
    }
 
    @GetMapping("/api/v1/notification/read")
    @ApiOperation(value = "操作已读", tags = "运维APP-消息通知")
    public R<?> readNotification(@RequestParam Long notificationId){
        notificationService.lambdaUpdate().set(XpOperationsUserNotification::getReadStatus, 1).eq(XpOperationsUserNotification::getId, notificationId).update();
        return R.ok();
    }
 
    @PostMapping(value = "/logan/inner/v1/notification/addBatch")
    @ApiOperation(value = "批量添加通知", tags = {"内部接口"})
    public R<?> addNotificationBatch(@RequestBody List<XpOperationsUserNotification> notifications) {
        notificationService.addNotificationBatch(notifications);
        return R.ok();
    }
}