From 116132a15008b12a4fe92fec2015481f1193e582 Mon Sep 17 00:00:00 2001 From: ronger Date: Tue, 24 May 2022 15:20:59 +0800 Subject: [PATCH 1/4] :art: update forest.sql test data --- src/main/resources/static/forest.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/static/forest.sql b/src/main/resources/static/forest.sql index 707eb4b..86a58df 100644 --- a/src/main/resources/static/forest.sql +++ b/src/main/resources/static/forest.sql @@ -339,7 +339,7 @@ values (4, '普通用户', 'user', '0', '2019-12-05 03:10:59', '2020-03-12 15:13 insert into forest.forest_user (id, account, password, nickname, real_name, sex, avatar_type, avatar_url, email, phone, status, created_time, updated_time, last_login_time, signature) -values (1, 'admin', '8ce2dd866238958ac4f07870766813cdaa39a9b83a8c75e26aa50f23', 'admin', 'admin', '0', '0', null, null, +values (1, 'admin', '8ce2dd866238958ac4f07870766813cdaa39a9b83a8c75e26aa50f23', 'admin', 'admin', '0', '0', null, 'admin@rymcu.com', null, '0', '2021-01-25 18:21:51', '2021-01-25 18:21:54', null, null); insert into forest.forest_user_role (id_user, id_role, created_time) From 2ac72ab28a2f92801cde52ddae3f5ebba7648708 Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 25 May 2022 10:24:43 +0800 Subject: [PATCH 2/4] =?UTF-8?q?:bug:=20=E5=88=86=E4=BA=AB=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E6=95=B0=E6=8D=AE=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/service/impl/ArticleServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java index 68f919d..6a8789f 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java @@ -277,7 +277,7 @@ public class ArticleServiceImpl extends AbstractService
implements Arti StringBuilder shareUrl = new StringBuilder(article.getArticlePermalink()); shareUrl.append("?s=").append(user.getAccount()); Map map = new HashMap(1); - map.put("shareUrl", shareUrl); + map.put("shareUrl", shareUrl.toString()); return map; } From 843b8b723a3e7338c07cb9564aa58a07d9763a48 Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 25 May 2022 10:33:45 +0800 Subject: [PATCH 3/4] =?UTF-8?q?:bug:=20=E5=88=86=E4=BA=AB=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E6=95=B0=E6=8D=AE=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/forest/service/impl/ArticleServiceImpl.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java index 6a8789f..2fc19f9 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java @@ -274,10 +274,8 @@ public class ArticleServiceImpl extends AbstractService
implements Arti if (Objects.isNull(user)) { throw new BaseApiException(ErrorCode.INVALID_TOKEN); } - StringBuilder shareUrl = new StringBuilder(article.getArticlePermalink()); - shareUrl.append("?s=").append(user.getAccount()); - Map map = new HashMap(1); - map.put("shareUrl", shareUrl.toString()); + Map map = new HashMap(2); + map.put("shareUrl", article.getArticlePermalink() + "?s=" + user.getAccount()); return map; } From 930dca3b59f5f3dfbe6b8d9884af42e41292cc3b Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 25 May 2022 21:36:53 +0800 Subject: [PATCH 4/4] =?UTF-8?q?:sparkles:=20=E6=B6=88=E6=81=AF=E4=B8=AD?= =?UTF-8?q?=E5=BF=83-=E4=B8=80=E9=94=AE=E6=A0=87=E8=AE=B0=E5=B7=B2?= =?UTF-8?q?=E8=AF=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/mapper/NotificationMapper.java | 7 +++++++ .../com/rymcu/forest/service/NotificationService.java | 9 +++++++++ .../forest/service/impl/NotificationServiceImpl.java | 7 +++++++ .../web/api/notification/NotificationController.java | 9 +++++++++ src/main/java/mapper/NotificationMapper.xml | 3 +++ 5 files changed, 35 insertions(+) diff --git a/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java b/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java index 2ae27ad..fee64a9 100644 --- a/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java @@ -51,4 +51,11 @@ public interface NotificationMapper extends Mapper { * @return */ Integer readNotification(@Param("id") Integer id); + + /** + * 标记所有消息已读 + * @param idUser + * @return + */ + Integer readAllNotification(@Param("idUser") Integer idUser); } diff --git a/src/main/java/com/rymcu/forest/service/NotificationService.java b/src/main/java/com/rymcu/forest/service/NotificationService.java index 4cf634b..da7109b 100644 --- a/src/main/java/com/rymcu/forest/service/NotificationService.java +++ b/src/main/java/com/rymcu/forest/service/NotificationService.java @@ -3,6 +3,7 @@ package com.rymcu.forest.service; import com.rymcu.forest.core.service.Service; import com.rymcu.forest.dto.NotificationDTO; import com.rymcu.forest.entity.Notification; +import com.rymcu.forest.web.api.exception.BaseApiException; import java.util.List; @@ -47,6 +48,14 @@ public interface NotificationService extends Service { /** * 标记消息已读 * @param id + * @return */ Integer readNotification(Integer id); + + /** + * 标记所有消息已读 + * @return + * @throws BaseApiException + */ + Integer readAllNotification() throws BaseApiException; } diff --git a/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java index b571e6f..c409d8e 100644 --- a/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java @@ -7,6 +7,8 @@ import com.rymcu.forest.mapper.NotificationMapper; import com.rymcu.forest.service.NotificationService; import com.rymcu.forest.util.BeanCopierUtil; import com.rymcu.forest.util.NotificationUtils; +import com.rymcu.forest.util.UserUtils; +import com.rymcu.forest.web.api.exception.BaseApiException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -70,4 +72,9 @@ public class NotificationServiceImpl extends AbstractService imple public Integer readNotification(Integer id) { return notificationMapper.readNotification(id); } + + @Override + public Integer readAllNotification() throws BaseApiException { + return notificationMapper.readAllNotification(Objects.requireNonNull(UserUtils.getCurrentUserByToken()).getIdUser()); + } } diff --git a/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java b/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java index 42c5072..ac8e403 100644 --- a/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java +++ b/src/main/java/com/rymcu/forest/web/api/notification/NotificationController.java @@ -65,4 +65,13 @@ public class NotificationController { return GlobalResultGenerator.genSuccessResult("标记已读成功"); } + @PutMapping("/read-all") + public GlobalResult readAll() throws BaseApiException { + Integer result = notificationService.readAllNotification(); + if (result == 0) { + return GlobalResultGenerator.genErrorResult("标记已读失败"); + } + return GlobalResultGenerator.genSuccessResult("标记已读成功"); + } + } diff --git a/src/main/java/mapper/NotificationMapper.xml b/src/main/java/mapper/NotificationMapper.xml index 144d4ca..3e68965 100644 --- a/src/main/java/mapper/NotificationMapper.xml +++ b/src/main/java/mapper/NotificationMapper.xml @@ -25,6 +25,9 @@ update forest_notification set has_read = '1' where id = #{id} + + update forest_notification set has_read = '1' where id_user = #{idUser} and has_read = '0' +