From 22979810e50236a6763ff57514e88457ce5048e8 Mon Sep 17 00:00:00 2001 From: x ronger Date: Mon, 3 Aug 2020 21:28:47 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E6=B6=88=E6=81=AF=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E4=B8=BA=E5=B7=B2=E8=AF=BB=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/vertical/service/NotificationService.java | 2 +- .../vertical/service/impl/NotificationServiceImpl.java | 7 +++++-- .../web/api/notification/NotificationController.java | 8 ++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/service/NotificationService.java b/src/main/java/com/rymcu/vertical/service/NotificationService.java index df1c26f..4342adf 100644 --- a/src/main/java/com/rymcu/vertical/service/NotificationService.java +++ b/src/main/java/com/rymcu/vertical/service/NotificationService.java @@ -48,5 +48,5 @@ public interface NotificationService extends Service { * 标记消息已读 * @param id */ - void readNotification(Integer id); + Integer readNotification(Integer id); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java index 564b17b..38d2593 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/NotificationServiceImpl.java @@ -5,6 +5,7 @@ import com.rymcu.vertical.entity.Notification; import com.rymcu.vertical.mapper.NotificationMapper; import com.rymcu.vertical.service.NotificationService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -36,12 +37,14 @@ public class NotificationServiceImpl extends AbstractService imple } @Override + @Transactional(rollbackFor = Exception.class) public Integer save(Integer idUser, Integer dataId, String dataType, String dataSummary) { return notificationMapper.insertNotification(idUser,dataId,dataType,dataSummary); } @Override - public void readNotification(Integer id) { - notificationMapper.readNotification(id); + @Transactional(rollbackFor = Exception.class) + public Integer readNotification(Integer id) { + return notificationMapper.readNotification(id); } } diff --git a/src/main/java/com/rymcu/vertical/web/api/notification/NotificationController.java b/src/main/java/com/rymcu/vertical/web/api/notification/NotificationController.java index 3186585..b613e98 100644 --- a/src/main/java/com/rymcu/vertical/web/api/notification/NotificationController.java +++ b/src/main/java/com/rymcu/vertical/web/api/notification/NotificationController.java @@ -48,8 +48,12 @@ public class NotificationController { } @PutMapping("/read/{id}") - public void read(@PathVariable Integer id) { - notificationService.readNotification(id); + public GlobalResult read(@PathVariable Integer id) { + Integer result = notificationService.readNotification(id); + if (result == 0) { + return GlobalResultGenerator.genErrorResult("标记已读失败"); + } + return GlobalResultGenerator.genSuccessResult("标记已读成功"); } }