liujie
2026-06-09 c96fbe6b0aeb413a17c429133ee6d81d138144b9
xp-robotaxi-account-boot/src/main/java/com/xiaopeng/account/controller/XpOperationsUserNotificationController.java
@@ -1,9 +1,20 @@
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.log.annotation.AdminOperationLog;
import com.xiaopeng.common.log.enums.AdminBusinessType;
import com.xiaopeng.common.log.enums.AdminOperationType;
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 org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import java.util.List;
/**
 * <p>
@@ -13,8 +24,74 @@
 * @author mitao
 * @since 2026-02-03
 */
@Controller
@RequestMapping("/xp-operations-user-notification")
@Slf4j
@RestController
public class XpOperationsUserNotificationController {
    @Autowired
    private IXpOperationsUserNotificationService notificationService;
    @Autowired
    private TokenService tokenService;
    /**
     * 根据当前登录用户获取通知分页列表(运维APP接口)
     */
    @PostMapping("/maintenance-app/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("/maintenance-app/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("/maintenance-app/api/v1/notification/read")
    @ApiOperation(value = "操作已读", tags = "运维APP-消息通知")
    @AdminOperationLog(
            businessType = AdminBusinessType.OPERATIONS_USER_NOTIFICATION_MANAGEMENT,
            operationType = AdminOperationType.EDIT,
            contentExpression = "'操作通知已读,notificationId=' + #p0",
            appendRequestData = false
    )
    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 = {"内部接口"})
    @AdminOperationLog(
            businessType = AdminBusinessType.OPERATIONS_USER_NOTIFICATION_MANAGEMENT,
            operationType = AdminOperationType.ADD,
            content = "批量添加运维人员消息通知",
            appendRequestData = true
    )
    public R<?> addNotificationBatch(@RequestBody List<XpOperationsUserNotification> notifications) {
        notificationService.addNotificationBatch(notifications);
        return R.ok();
    }
}