|
|
@@ -1,6 +1,7 @@
|
|
|
package com.etotem.cfc.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.entity.UserNotification;
|
|
|
import com.etotem.cfc.mapper.UserNotificationMapper;
|
|
|
@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.Date;
|
|
|
@@ -28,7 +30,7 @@ public class UserNotificationController {
|
|
|
@Resource
|
|
|
private UserNotificationMapper userNotificationMapper;
|
|
|
|
|
|
- @Operation(summary = "通知列表(未读优先,倒序)")
|
|
|
+ @Operation(summary = "通知列表(未读优先,倒序,LIMIT 100 扁平)")
|
|
|
@PostMapping("/list")
|
|
|
public Result<List<UserNotification>> list(@RequestAttribute("userId") Long userId) {
|
|
|
List<UserNotification> list = userNotificationMapper.selectList(
|
|
|
@@ -40,7 +42,26 @@ public class UserNotificationController {
|
|
|
return Result.success(list);
|
|
|
}
|
|
|
|
|
|
- @Operation(summary = "标记已读(id 或 ids 数组,缺省标记全部)")
|
|
|
+ /**
|
|
|
+ * 通知列表(分页,SC-P-78「分页」)。请求带 {@code pageNum} 查询参数时命中本方法(org.springframework
|
|
|
+ * 会在同路径下选择更具体的 {@code params} 条件映射),返回含 {@code total/pageNum/pageSize} 的分页载体;
|
|
|
+ * 未带 {@code pageNum} 时走上方扁平 LIMIT 100 接口(向后兼容现有前端)。
|
|
|
+ */
|
|
|
+ @Operation(summary = "通知列表(分页,未读优先倒序;pageNum/pageSize 请求参数)")
|
|
|
+ @PostMapping(value = "/list", params = "pageNum")
|
|
|
+ public Result<Page<UserNotification>> list(@RequestAttribute("userId") Long userId,
|
|
|
+ @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
|
|
+ @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) {
|
|
|
+ Page<UserNotification> page = userNotificationMapper.selectPage(
|
|
|
+ new Page<>(pageNum, pageSize),
|
|
|
+ new LambdaQueryWrapper<UserNotification>()
|
|
|
+ .eq(UserNotification::getUserId, userId)
|
|
|
+ .orderByAsc(UserNotification::getIsRead)
|
|
|
+ .orderByDesc(UserNotification::getCreatedAt));
|
|
|
+ return Result.success(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "标记已读(id 或 ids 数组,缺省标记全部;id 不存在 → 404)")
|
|
|
@PostMapping("/read")
|
|
|
public Result<Boolean> read(@RequestAttribute("userId") Long userId,
|
|
|
@RequestBody(required = false) Map<String, Object> params) {
|
|
|
@@ -48,7 +69,11 @@ public class UserNotificationController {
|
|
|
Object idsObj = params != null ? params.get("ids") : null;
|
|
|
if (idObj != null) {
|
|
|
UserNotification n = userNotificationMapper.selectById(Long.valueOf(idObj.toString()));
|
|
|
- if (n != null && n.getUserId().equals(userId)) {
|
|
|
+ if (n == null) {
|
|
|
+ // TC-P-78-E「不存在 404」:无此消息 → 404
|
|
|
+ return Result.notFound("消息不存在");
|
|
|
+ }
|
|
|
+ if (n.getUserId().equals(userId)) {
|
|
|
n.setIsRead(1);
|
|
|
userNotificationMapper.updateById(n);
|
|
|
}
|