From cc23959133af0496ed8b12e46556ba70956c9cd8 Mon Sep 17 00:00:00 2001 From: ronger Date: Thu, 26 May 2022 15:43:53 +0800 Subject: [PATCH 1/4] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E8=A2=AB=E5=88=A0=E9=99=A4=EF=BC=8C=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E6=AE=8B=E7=95=99=E6=9C=AA=E8=AF=BB=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E9=97=AE=E9=A2=98=EF=BC=88=E5=A6=82=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E8=A2=AB=E5=88=A0=E9=99=A4=E5=88=99=E6=B8=85=E9=99=A4=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=9C=AA=E8=AF=BB=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/mapper/NotificationMapper.java | 8 ++++++++ .../com/rymcu/forest/service/NotificationService.java | 8 ++++++++ .../com/rymcu/forest/service/impl/ArticleServiceImpl.java | 5 +++++ .../forest/service/impl/NotificationServiceImpl.java | 5 +++++ src/main/java/mapper/NotificationMapper.xml | 3 +++ 5 files changed, 29 insertions(+) diff --git a/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java b/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java index fee64a9..d0257eb 100644 --- a/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/NotificationMapper.java @@ -58,4 +58,12 @@ public interface NotificationMapper extends Mapper { * @return */ Integer readAllNotification(@Param("idUser") Integer idUser); + + /** + * 删除相关未读消息 + * @param dataId + * @param dataType + * @return + */ + Integer deleteUnreadNotification(@Param("dataId") Integer dataId, @Param("dataType") String dataType); } diff --git a/src/main/java/com/rymcu/forest/service/NotificationService.java b/src/main/java/com/rymcu/forest/service/NotificationService.java index da7109b..1b3e461 100644 --- a/src/main/java/com/rymcu/forest/service/NotificationService.java +++ b/src/main/java/com/rymcu/forest/service/NotificationService.java @@ -58,4 +58,12 @@ public interface NotificationService extends Service { * @throws BaseApiException */ Integer readAllNotification() throws BaseApiException; + + /** + * 删除相关未读消息 + * @param dataId + * @param dataType + * @return + */ + Integer deleteUnreadNotification(Integer dataId, String dataType); } 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 2fc19f9..f0bc2f2 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java @@ -10,6 +10,7 @@ import com.rymcu.forest.entity.User; import com.rymcu.forest.lucene.service.LuceneService; import com.rymcu.forest.mapper.ArticleMapper; import com.rymcu.forest.service.ArticleService; +import com.rymcu.forest.service.NotificationService; import com.rymcu.forest.service.TagService; import com.rymcu.forest.service.UserService; import com.rymcu.forest.util.*; @@ -43,6 +44,8 @@ public class ArticleServiceImpl extends AbstractService
implements Arti private UserService userService; @Resource private LuceneService luceneService; + @Resource + private NotificationService notificationService; @Value("${resource.domain}") private String domain; @@ -257,6 +260,8 @@ public class ArticleServiceImpl extends AbstractService
implements Arti articleMapper.deleteTagArticle(id); // 删除文章内容表 articleMapper.deleteArticleContent(id); + // 删除相关未读消息 + notificationService.deleteUnreadNotification(id, NotificationConstant.PostArticle); } @Override 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 c409d8e..18143ea 100644 --- a/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/NotificationServiceImpl.java @@ -77,4 +77,9 @@ public class NotificationServiceImpl extends AbstractService imple public Integer readAllNotification() throws BaseApiException { return notificationMapper.readAllNotification(Objects.requireNonNull(UserUtils.getCurrentUserByToken()).getIdUser()); } + + @Override + public Integer deleteUnreadNotification(Integer dataId, String dataType) { + return notificationMapper.deleteUnreadNotification(dataId, dataType); + } } diff --git a/src/main/java/mapper/NotificationMapper.xml b/src/main/java/mapper/NotificationMapper.xml index 3e68965..bcbbfd2 100644 --- a/src/main/java/mapper/NotificationMapper.xml +++ b/src/main/java/mapper/NotificationMapper.xml @@ -28,6 +28,9 @@ update forest_notification set has_read = '1' where id_user = #{idUser} and has_read = '0' + + delete from forest_notification where has_read = '0' and data_id = #{dataId} and data_type = #{dataType} + From b281703bac452ccf119a7715dbf91f6c54878a3e Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 27 May 2022 14:40:08 +0800 Subject: [PATCH 2/4] =?UTF-8?q?:bug:=20can=20not=20cast=20to=20JSONObject?= =?UTF-8?q?=20=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 --- .../core/service/security/AuthorshipAspect.java | 14 ++++++++++++-- .../core/service/security/SecurityAspect.java | 11 ++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/rymcu/forest/core/service/security/AuthorshipAspect.java b/src/main/java/com/rymcu/forest/core/service/security/AuthorshipAspect.java index 093b48d..92fd989 100644 --- a/src/main/java/com/rymcu/forest/core/service/security/AuthorshipAspect.java +++ b/src/main/java/com/rymcu/forest/core/service/security/AuthorshipAspect.java @@ -75,11 +75,21 @@ public class AuthorshipAspect { isArticle = false; } HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); - String idArticle = ""; + String idArticle; Integer idAuthor = 0; if (isAjax(request)) { Object[] objects = joinPoint.getArgs(); - JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(objects[0])); + JSONObject jsonObject; + if (objects[0] instanceof Integer) { + jsonObject = new JSONObject(); + if (isArticle) { + jsonObject.put("idArticle", objects[0].toString()); + } else { + jsonObject.put("idPortfolio", objects[0].toString()); + } + } else { + jsonObject = JSONObject.parseObject(JSON.toJSONString(objects[0])); + } if (Objects.nonNull(jsonObject)) { if (isArticle) { idArticle = jsonObject.getString("idArticle"); diff --git a/src/main/java/com/rymcu/forest/core/service/security/SecurityAspect.java b/src/main/java/com/rymcu/forest/core/service/security/SecurityAspect.java index f6ba82c..453d5eb 100644 --- a/src/main/java/com/rymcu/forest/core/service/security/SecurityAspect.java +++ b/src/main/java/com/rymcu/forest/core/service/security/SecurityAspect.java @@ -54,9 +54,14 @@ public class SecurityAspect { String idUser = ""; if (isAjax(request)) { Object[] objects = joinPoint.getArgs(); - JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(objects[0])); - if (Objects.nonNull(jsonObject)) { - idUser = jsonObject.getString("idUser"); + JSONObject jsonObject; + if (objects[0] instanceof Integer) { + idUser = objects[0].toString(); + } else { + jsonObject = JSONObject.parseObject(JSON.toJSONString(objects[0])); + if (Objects.nonNull(jsonObject)) { + idUser = jsonObject.getString("idUser"); + } } } else { Map params = getParams(request); From ef22670d1a0770d2c6dddcf92f09a5158d039863 Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 1 Jun 2022 16:18:41 +0800 Subject: [PATCH 3/4] :arrow_down: fastjson --- pom.xml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index ea0eb05..03da05b 100644 --- a/pom.xml +++ b/pom.xml @@ -101,7 +101,7 @@ com.alibaba fastjson - 2.0.3 + 1.2.83 @@ -241,10 +241,6 @@ com.google.guava guava - - org.json - json - From 8cdcdfeff09078676aff66ea3d342785f25fafb7 Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 6 Jun 2022 11:55:31 +0800 Subject: [PATCH 4/4] =?UTF-8?q?:art:=20=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/entity/Sponsor.java | 2 +- .../forest/enumerate/TransactionEnum.java | 21 +++++++------------ .../impl/TransactionRecordServiceImpl.java | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/rymcu/forest/entity/Sponsor.java b/src/main/java/com/rymcu/forest/entity/Sponsor.java index 46ad4b3..a9eeaef 100644 --- a/src/main/java/com/rymcu/forest/entity/Sponsor.java +++ b/src/main/java/com/rymcu/forest/entity/Sponsor.java @@ -24,7 +24,7 @@ public class Sponsor implements Serializable, Cloneable { /** * 数据类型 */ - private String dataType; + private Integer dataType; /** * 数据主键 */ diff --git a/src/main/java/com/rymcu/forest/enumerate/TransactionEnum.java b/src/main/java/com/rymcu/forest/enumerate/TransactionEnum.java index 6b6c8de..fec7f07 100644 --- a/src/main/java/com/rymcu/forest/enumerate/TransactionEnum.java +++ b/src/main/java/com/rymcu/forest/enumerate/TransactionEnum.java @@ -7,29 +7,22 @@ import java.util.Arrays; */ public enum TransactionEnum { - ArticleSponsor("0", 20, "文章赞赏"), - Answer("1", 30, "答题奖励"), - CorrectAnswer("2", 50, "答题奖励"), - NewbieRewards("3", 200, "新手奖励"); - - private String dataType; + ArticleSponsor(20, "文章赞赏"), + Answer(30, "答题奖励"), + CorrectAnswer(50, "答题奖励"), + NewbieRewards(200, "新手奖励"); private Integer money; private String description; - TransactionEnum(String dataType, Integer money, String description) { - this.dataType = dataType; + TransactionEnum(Integer money, String description) { this.money = money; this.description = description; } - public static TransactionEnum findTransactionEnum(String dataType) { - return Arrays.stream(TransactionEnum.values()).filter(transactionEnum -> transactionEnum.getDataType().equals(dataType)).findFirst().orElse(TransactionEnum.ArticleSponsor); - } - - public String getDataType() { - return this.dataType; + public static TransactionEnum findTransactionEnum(int dataType) { + return Arrays.stream(TransactionEnum.values()).filter(transactionEnum -> transactionEnum.ordinal() == dataType).findFirst().orElse(TransactionEnum.ArticleSponsor); } public Integer getMoney() { diff --git a/src/main/java/com/rymcu/forest/service/impl/TransactionRecordServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/TransactionRecordServiceImpl.java index af8856f..4a2f7cb 100644 --- a/src/main/java/com/rymcu/forest/service/impl/TransactionRecordServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/TransactionRecordServiceImpl.java @@ -57,7 +57,7 @@ public class TransactionRecordServiceImpl extends AbstractService findTransactionRecords(String bankAccount, String startDate, String endDate) { List list = transactionRecordMapper.selectTransactionRecords(bankAccount, startDate, endDate); - list.forEach(transactionRecordDTO -> genTransactionRecord(transactionRecordDTO)); + list.forEach(this::genTransactionRecord); return list; }