|
|
@@ -2,12 +2,15 @@ package com.huimv.employment.service.notification;
|
|
2
|
2
|
|
|
3
|
3
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
4
|
4
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
5
|
+import com.huimv.employment.common.exception.BizException;
|
|
|
6
|
+import com.huimv.employment.common.exception.ErrorCode;
|
|
5
|
7
|
import com.huimv.employment.dao.entity.FeEmploymentOrder;
|
|
6
|
8
|
import com.huimv.employment.dao.entity.FeNotification;
|
|
7
|
9
|
import com.huimv.employment.dao.entity.FeSettlementOrder;
|
|
8
|
10
|
import com.huimv.employment.dao.mapper.FeNotificationMapper;
|
|
9
|
11
|
import com.huimv.employment.service.notification.dto.NotificationItemResponse;
|
|
10
|
12
|
import com.huimv.employment.service.notification.dto.NotificationPageResponse;
|
|
|
13
|
+import com.huimv.employment.service.notification.dto.NotificationReadResponse;
|
|
11
|
14
|
import org.slf4j.Logger;
|
|
12
|
15
|
import org.slf4j.LoggerFactory;
|
|
13
|
16
|
import org.springframework.stereotype.Service;
|
|
|
@@ -98,6 +101,42 @@ public class NotificationService {
|
|
98
|
101
|
return response;
|
|
99
|
102
|
}
|
|
100
|
103
|
|
|
|
104
|
+ /**
|
|
|
105
|
+ * 标记消息已读:更新 {@code read_flag=true}、{@code read_time}(幂等)。
|
|
|
106
|
+ */
|
|
|
107
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
108
|
+ public NotificationReadResponse markRead(Long userId, Long notificationId) {
|
|
|
109
|
+ if (userId == null) {
|
|
|
110
|
+ throw new BizException(ErrorCode.UNAUTHORIZED, "请先登录");
|
|
|
111
|
+ }
|
|
|
112
|
+ if (notificationId == null) {
|
|
|
113
|
+ throw new BizException(ErrorCode.BAD_REQUEST, "消息 ID 不能为空");
|
|
|
114
|
+ }
|
|
|
115
|
+ FeNotification existing = feNotificationMapper.selectById(notificationId);
|
|
|
116
|
+ if (existing == null) {
|
|
|
117
|
+ throw new BizException(ErrorCode.NOT_FOUND, "消息不存在");
|
|
|
118
|
+ }
|
|
|
119
|
+ if (existing.getUserId() == null || !userId.equals(existing.getUserId())) {
|
|
|
120
|
+ throw new BizException(ErrorCode.FORBIDDEN, "无权操作该消息");
|
|
|
121
|
+ }
|
|
|
122
|
+
|
|
|
123
|
+ if (!Boolean.TRUE.equals(existing.getReadFlag())) {
|
|
|
124
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
125
|
+ FeNotification update = new FeNotification();
|
|
|
126
|
+ update.setId(existing.getId());
|
|
|
127
|
+ update.setReadFlag(Boolean.TRUE);
|
|
|
128
|
+ update.setReadTime(now);
|
|
|
129
|
+ feNotificationMapper.updateById(update);
|
|
|
130
|
+ existing.setReadFlag(Boolean.TRUE);
|
|
|
131
|
+ existing.setReadTime(now);
|
|
|
132
|
+ }
|
|
|
133
|
+
|
|
|
134
|
+ NotificationReadResponse response = new NotificationReadResponse();
|
|
|
135
|
+ response.setItem(toItem(existing));
|
|
|
136
|
+ response.setUnreadCount(countUnread(userId));
|
|
|
137
|
+ return response;
|
|
|
138
|
+ }
|
|
|
139
|
+
|
|
101
|
140
|
private long countUnread(Long userId) {
|
|
102
|
141
|
Long count = feNotificationMapper.selectCount(new LambdaQueryWrapper<FeNotification>()
|
|
103
|
142
|
.eq(FeNotification::getUserId, userId)
|