|
|
@@ -10,6 +10,8 @@ import com.yimeng.okr.mapper.NotificationMapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import com.yimeng.okr.exception.BusinessException;
|
|
|
+
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
|
|
|
@@ -39,11 +41,15 @@ public class NotificationService {
|
|
|
|
|
|
public void markRead(Long id, Long userId) {
|
|
|
Notification n = notificationMapper.selectById(id);
|
|
|
- if (n != null && n.getUserId().equals(userId)) {
|
|
|
- n.setIsRead(1);
|
|
|
- n.setReadAt(LocalDateTime.now());
|
|
|
- notificationMapper.updateById(n);
|
|
|
+ if (n == null) {
|
|
|
+ throw new BusinessException(404, "通知不存在");
|
|
|
+ }
|
|
|
+ if (!n.getUserId().equals(userId)) {
|
|
|
+ throw new BusinessException(403, "无权操作此通知");
|
|
|
}
|
|
|
+ n.setIsRead(1);
|
|
|
+ n.setReadAt(LocalDateTime.now());
|
|
|
+ notificationMapper.updateById(n);
|
|
|
}
|
|
|
|
|
|
public void markAllRead(Long userId) {
|