From 10e8df04766a00ed372ac40e71b8c06f287b2a95 Mon Sep 17 00:00:00 2001 From: linhaojun Date: Thu, 6 Oct 2022 18:10:16 +0800 Subject: [PATCH 1/6] =?UTF-8?q?:art:=20=E4=BF=AE=E6=94=B9=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=91=BD=E5=90=8D=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/aurora/service/impl/ArticleServiceImpl.java | 12 ++++++------ .../com/aurora/service/impl/TalkServiceImpl.java | 6 +++--- .../com/aurora/service/impl/UserAuthServiceImpl.java | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/aurora-springboot/src/main/java/com/aurora/service/impl/ArticleServiceImpl.java b/aurora-springboot/src/main/java/com/aurora/service/impl/ArticleServiceImpl.java index 796121f..f77d4be 100644 --- a/aurora-springboot/src/main/java/com/aurora/service/impl/ArticleServiceImpl.java +++ b/aurora-springboot/src/main/java/com/aurora/service/impl/ArticleServiceImpl.java @@ -343,23 +343,23 @@ public class ArticleServiceImpl extends ServiceImpl impl if (CollectionUtils.isNotEmpty(tagNames)) { List existTags = tagService.list(new LambdaQueryWrapper() .in(Tag::getTagName, tagNames)); - List existTagNameList = existTags.stream() + List existTagNames = existTags.stream() .map(Tag::getTagName) .collect(Collectors.toList()); List existTagIds = existTags.stream() .map(Tag::getId) .collect(Collectors.toList()); - tagNames.removeAll(existTagNameList); + tagNames.removeAll(existTagNames); if (CollectionUtils.isNotEmpty(tagNames)) { - List tagList = tagNames.stream().map(item -> Tag.builder() + List tags = tagNames.stream().map(item -> Tag.builder() .tagName(item) .build()) .collect(Collectors.toList()); - tagService.saveBatch(tagList); - List tagIdList = tagList.stream() + tagService.saveBatch(tags); + List tagIds = tags.stream() .map(Tag::getId) .collect(Collectors.toList()); - existTagIds.addAll(tagIdList); + existTagIds.addAll(tagIds); } List articleTags = existTagIds.stream().map(item -> ArticleTag.builder() .articleId(articleId) diff --git a/aurora-springboot/src/main/java/com/aurora/service/impl/TalkServiceImpl.java b/aurora-springboot/src/main/java/com/aurora/service/impl/TalkServiceImpl.java index 2099dfa..b5c36a2 100644 --- a/aurora-springboot/src/main/java/com/aurora/service/impl/TalkServiceImpl.java +++ b/aurora-springboot/src/main/java/com/aurora/service/impl/TalkServiceImpl.java @@ -94,13 +94,13 @@ public class TalkServiceImpl extends ServiceImpl implements Ta if (count == 0) { return new PageResultDTO<>(); } - List talkDTOList = talkMapper.listTalksAdmin(PageUtil.getLimitCurrent(), PageUtil.getSize(), conditionVO); - talkDTOList.forEach(item -> { + List talkDTOs = talkMapper.listTalksAdmin(PageUtil.getLimitCurrent(), PageUtil.getSize(), conditionVO); + talkDTOs.forEach(item -> { if (Objects.nonNull(item.getImages())) { item.setImgs(CommonUtil.castList(JSON.parseObject(item.getImages(), List.class), String.class)); } }); - return new PageResultDTO<>(talkDTOList, count); + return new PageResultDTO<>(talkDTOs, count); } @Override diff --git a/aurora-springboot/src/main/java/com/aurora/service/impl/UserAuthServiceImpl.java b/aurora-springboot/src/main/java/com/aurora/service/impl/UserAuthServiceImpl.java index 029186e..97b184b 100644 --- a/aurora-springboot/src/main/java/com/aurora/service/impl/UserAuthServiceImpl.java +++ b/aurora-springboot/src/main/java/com/aurora/service/impl/UserAuthServiceImpl.java @@ -88,6 +88,7 @@ public class UserAuthServiceImpl implements UserAuthService { } @Override + @SuppressWarnings("unchecked") public List listUserAreas(ConditionVO conditionVO) { List userAreaDTOs = new ArrayList<>(); switch (Objects.requireNonNull(getUserAreaType(conditionVO.getType()))) { From 3e191b7ad920cd9ace76cfa280c410f7307395e6 Mon Sep 17 00:00:00 2001 From: linhaojun Date: Sat, 8 Oct 2022 16:23:36 +0800 Subject: [PATCH 2/6] =?UTF-8?q?:art:=20=E8=A7=84=E8=8C=83=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/aurora/util/IpUtil.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/aurora-springboot/src/main/java/com/aurora/util/IpUtil.java b/aurora-springboot/src/main/java/com/aurora/util/IpUtil.java index b7a0194..78c7b3e 100644 --- a/aurora-springboot/src/main/java/com/aurora/util/IpUtil.java +++ b/aurora-springboot/src/main/java/com/aurora/util/IpUtil.java @@ -22,6 +22,10 @@ import java.net.UnknownHostException; @Component public class IpUtil { + private static DbSearcher searcher; + + private static Method method; + public static String getIpAddress(HttpServletRequest request) { String ipAddress = request.getHeader("X-Real-IP"); if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { @@ -56,26 +60,15 @@ public class IpUtil { return StringUtils.substringBefore(ipAddress, ","); } - private static DbSearcher searcher; - private static Method method; - - /** - * 在服务启动时加载 ip2region.db 到内存中 - */ @PostConstruct private void initIp2regionResource() throws Exception { InputStream inputStream = new ClassPathResource("/ip/ip2region.db").getInputStream(); - //将 ip2region.db 转为 ByteArray byte[] dbBinStr = FileCopyUtils.copyToByteArray(inputStream); DbConfig dbConfig = new DbConfig(); searcher = new DbSearcher(dbConfig, dbBinStr); - //二进制方式初始化 DBSearcher,需要使用基于内存的查找算法 memorySearch method = searcher.getClass().getMethod("memorySearch", String.class); } - /** - * 获取ip地址的归属地 - */ public static String getIpSource(String ipAddress) { if (ipAddress == null || !Util.isIpAddress(ipAddress)) { log.error("Error: Invalid ip address"); @@ -103,9 +96,6 @@ public class IpUtil { return strings[1]; } - /** - * 获取访问设备 - */ public static UserAgent getUserAgent(HttpServletRequest request) { return UserAgent.parseUserAgentString(request.getHeader("User-Agent")); } From 65c2515315a7ede139320972d41d14b91f1c4e11 Mon Sep 17 00:00:00 2001 From: linhaojun Date: Sat, 8 Oct 2022 18:16:56 +0800 Subject: [PATCH 3/6] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E5=90=8E?= =?UTF-8?q?=E7=AB=AFlistener=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...onLogListener.java => AuroraListener.java} | 15 ++++++++++++- .../aurora/listener/OperationLogListener.java | 22 ------------------- 2 files changed, 14 insertions(+), 23 deletions(-) rename aurora-springboot/src/main/java/com/aurora/listener/{ExceptionLogListener.java => AuroraListener.java} (60%) delete mode 100644 aurora-springboot/src/main/java/com/aurora/listener/OperationLogListener.java diff --git a/aurora-springboot/src/main/java/com/aurora/listener/ExceptionLogListener.java b/aurora-springboot/src/main/java/com/aurora/listener/AuroraListener.java similarity index 60% rename from aurora-springboot/src/main/java/com/aurora/listener/ExceptionLogListener.java rename to aurora-springboot/src/main/java/com/aurora/listener/AuroraListener.java index 2c9466c..2f3d016 100644 --- a/aurora-springboot/src/main/java/com/aurora/listener/ExceptionLogListener.java +++ b/aurora-springboot/src/main/java/com/aurora/listener/AuroraListener.java @@ -1,22 +1,35 @@ package com.aurora.listener; import com.aurora.entity.ExceptionLog; +import com.aurora.entity.OperationLog; import com.aurora.event.ExceptionLogEvent; +import com.aurora.event.OperationLogEvent; import com.aurora.mapper.ExceptionLogMapper; +import com.aurora.mapper.OperationLogMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @Component -public class ExceptionLogListener { +public class AuroraListener { + + @Autowired + private OperationLogMapper operationLogMapper; @Autowired private ExceptionLogMapper exceptionLogMapper; + @Async + @EventListener(OperationLogEvent.class) + public void saveOperationLog(OperationLogEvent operationLogEvent) { + operationLogMapper.insert((OperationLog) operationLogEvent.getSource()); + } + @Async @EventListener(ExceptionLogEvent.class) public void saveExceptionLog(ExceptionLogEvent exceptionLogEvent) { exceptionLogMapper.insert((ExceptionLog) exceptionLogEvent.getSource()); } + } diff --git a/aurora-springboot/src/main/java/com/aurora/listener/OperationLogListener.java b/aurora-springboot/src/main/java/com/aurora/listener/OperationLogListener.java deleted file mode 100644 index 84deb72..0000000 --- a/aurora-springboot/src/main/java/com/aurora/listener/OperationLogListener.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aurora.listener; - -import com.aurora.entity.OperationLog; -import com.aurora.event.OperationLogEvent; -import com.aurora.mapper.OperationLogMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; - -@Component -public class OperationLogListener { - - @Autowired - private OperationLogMapper operationLogMapper; - - @Async - @EventListener(OperationLogEvent.class) - public void saveOperationLog(OperationLogEvent operationLogEvent) { - operationLogMapper.insert((OperationLog) operationLogEvent.getSource()); - } -} From 136265193ed0c838d2f0055a83ae2f9b9d0f1d27 Mon Sep 17 00:00:00 2001 From: linhaojun Date: Sat, 8 Oct 2022 18:24:13 +0800 Subject: [PATCH 4/6] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/aurora/exception/BizException.java | 2 -- .../main/java/com/aurora/exception/TaskException.java | 5 +++-- .../com/aurora/interceptor/AccessLimitInterceptor.java | 10 ---------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/aurora-springboot/src/main/java/com/aurora/exception/BizException.java b/aurora-springboot/src/main/java/com/aurora/exception/BizException.java index e91208c..d19fbd9 100644 --- a/aurora-springboot/src/main/java/com/aurora/exception/BizException.java +++ b/aurora-springboot/src/main/java/com/aurora/exception/BizException.java @@ -17,11 +17,9 @@ public class BizException extends RuntimeException { this.message = message; } - public BizException(StatusCodeEnum statusCodeEnum) { this.code = statusCodeEnum.getCode(); this.message = statusCodeEnum.getDesc(); } - } diff --git a/aurora-springboot/src/main/java/com/aurora/exception/TaskException.java b/aurora-springboot/src/main/java/com/aurora/exception/TaskException.java index 319b434..3022b06 100644 --- a/aurora-springboot/src/main/java/com/aurora/exception/TaskException.java +++ b/aurora-springboot/src/main/java/com/aurora/exception/TaskException.java @@ -1,6 +1,7 @@ package com.aurora.exception; public class TaskException extends Exception { + private static final long serialVersionUID = 1L; private final Code code; @@ -9,8 +10,8 @@ public class TaskException extends Exception { this(msg, code, null); } - public TaskException(String msg, Code code, Exception nestedEx) { - super(msg, nestedEx); + public TaskException(String msg, Code code, Exception exception) { + super(msg, exception); this.code = code; } diff --git a/aurora-springboot/src/main/java/com/aurora/interceptor/AccessLimitInterceptor.java b/aurora-springboot/src/main/java/com/aurora/interceptor/AccessLimitInterceptor.java index 492ab2a..576a914 100644 --- a/aurora-springboot/src/main/java/com/aurora/interceptor/AccessLimitInterceptor.java +++ b/aurora-springboot/src/main/java/com/aurora/interceptor/AccessLimitInterceptor.java @@ -20,11 +20,6 @@ import java.nio.charset.StandardCharsets; import static com.aurora.constant.CommonConstant.APPLICATION_JSON; - -/** - * @author 花未眠 - * 限流逻辑 - */ @Log4j2 @Component @SuppressWarnings("all") @@ -35,19 +30,14 @@ public class AccessLimitInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler) throws Exception { - // 如果请求输入方法 if (handler instanceof HandlerMethod) { HandlerMethod hm = (HandlerMethod) handler; - // 获取方法中的注解,看是否有该注解 AccessLimit accessLimit = hm.getMethodAnnotation(AccessLimit.class); if (accessLimit != null) { long seconds = accessLimit.seconds(); int maxCount = accessLimit.maxCount(); - // 关于key的生成规则可以自己定义 本项目需求是对每个方法都加上限流功能,如果你只是针对ip地址限流,那么key只需要只用ip就好 String key = IpUtil.getIpAddress(httpServletRequest) + hm.getMethod().getName(); - // 从redis中获取用户访问的次数 try { - // 此操作代表获取该key对应的值自增1后的结果 long q = redisService.incrExpire(key, seconds); if (q > maxCount) { render(httpServletResponse, ResultVO.fail("请求过于频繁," + seconds + "秒后再试")); From 8d3685bb22e52540dd8a0dcbb1e06f2c6dd89baa Mon Sep 17 00:00:00 2001 From: linhaojun Date: Sat, 8 Oct 2022 19:07:31 +0800 Subject: [PATCH 5/6] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/aurora/constant/RedisPrefixConstant.java | 2 +- .../main/java/com/aurora/controller/ArticleController.java | 4 ++-- .../main/java/com/aurora/service/impl/ArticleServiceImpl.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/aurora-springboot/src/main/java/com/aurora/constant/RedisPrefixConstant.java b/aurora-springboot/src/main/java/com/aurora/constant/RedisPrefixConstant.java index 90b5d68..3ef9db8 100644 --- a/aurora-springboot/src/main/java/com/aurora/constant/RedisPrefixConstant.java +++ b/aurora-springboot/src/main/java/com/aurora/constant/RedisPrefixConstant.java @@ -22,6 +22,6 @@ public class RedisPrefixConstant { public static final String LOGIN_USER = "login_user"; - public static final String USER_ARTICLE_ACCESS = "article_access"; + public static final String ARTICLE_ACCESS = "article_access"; } diff --git a/aurora-springboot/src/main/java/com/aurora/controller/ArticleController.java b/aurora-springboot/src/main/java/com/aurora/controller/ArticleController.java index f002e80..f79ea68 100644 --- a/aurora-springboot/src/main/java/com/aurora/controller/ArticleController.java +++ b/aurora-springboot/src/main/java/com/aurora/controller/ArticleController.java @@ -52,8 +52,8 @@ public class ArticleController { } @ApiOperation("根据id获取文章") - @GetMapping("/articles/{id}") - public ResultVO getArticleById(@PathVariable("id") Integer articleId) { + @GetMapping("/articles/{articleId}") + public ResultVO getArticleById(@PathVariable("articleId") Integer articleId) { return ResultVO.ok(articleService.getArticleById(articleId)); } diff --git a/aurora-springboot/src/main/java/com/aurora/service/impl/ArticleServiceImpl.java b/aurora-springboot/src/main/java/com/aurora/service/impl/ArticleServiceImpl.java index f77d4be..1672820 100644 --- a/aurora-springboot/src/main/java/com/aurora/service/impl/ArticleServiceImpl.java +++ b/aurora-springboot/src/main/java/com/aurora/service/impl/ArticleServiceImpl.java @@ -123,7 +123,7 @@ public class ArticleServiceImpl extends ServiceImpl impl if (articleForCheck.getStatus().equals(2)) { Boolean isAccess; try { - isAccess = redisService.sIsMember(USER_ARTICLE_ACCESS + ":" + UserUtil.getUserDetailsDTO().getId(), articleId); + isAccess = redisService.sIsMember(ARTICLE_ACCESS + ":" + UserUtil.getUserDetailsDTO().getId(), articleId); } catch (Exception exception) { throw new BizException(ARTICLE_ACCESS_FAIL); } @@ -167,7 +167,7 @@ public class ArticleServiceImpl extends ServiceImpl impl throw new BizException("文章不存在"); } if (article.getPassword().equals(articlePasswordVO.getArticlePassword())) { - redisService.sAdd(USER_ARTICLE_ACCESS + ":" + UserUtil.getUserDetailsDTO().getId(), articlePasswordVO.getArticleId()); + redisService.sAdd(ARTICLE_ACCESS + ":" + UserUtil.getUserDetailsDTO().getId(), articlePasswordVO.getArticleId()); } else { throw new BizException("密码错误"); } From 6c77c4bc7a857cd2db954b4616a378caf169eb7d Mon Sep 17 00:00:00 2001 From: linhaojun Date: Sat, 8 Oct 2022 19:43:12 +0800 Subject: [PATCH 6/6] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E5=89=8D?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/ArticleCard/src/ArticleCard.vue | 2 +- .../components/ArticleCard/src/HorizontalArticle.vue | 5 +---- .../src/components/Sidebar/src/Profile.vue | 12 +++--------- .../src/components/Sidebar/src/TagBox.vue | 11 +---------- .../src/components/Sidebar/src/WebsiteInfo.vue | 3 +++ aurora-vue/aurora-blog/src/stores/tag.ts | 4 ++-- 6 files changed, 11 insertions(+), 26 deletions(-) diff --git a/aurora-vue/aurora-blog/src/components/ArticleCard/src/ArticleCard.vue b/aurora-vue/aurora-blog/src/components/ArticleCard/src/ArticleCard.vue index f321020..5138c09 100644 --- a/aurora-vue/aurora-blog/src/components/ArticleCard/src/ArticleCard.vue +++ b/aurora-vue/aurora-blog/src/components/ArticleCard/src/ArticleCard.vue @@ -46,7 +46,7 @@

{{ article.articleContent }}

- +