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("标记已读成功"); } }