From a8c27e29fd6155f826209d83ecad87eec5ca23d8 Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 30 Nov 2020 23:56:34 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E4=B8=80=E4=B8=AA=E7=AE=80?= =?UTF-8?q?=E6=98=93=E7=9A=84=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/forest/dto/SearchModel.java | 17 ++++++++ .../com/rymcu/forest/mapper/SearchMapper.java | 28 ++++++++++++ .../rymcu/forest/service/SearchService.java | 16 +++++++ .../service/impl/SearchServiceImpl.java | 43 +++++++++++++++++++ .../web/api/common/CommonApiController.java | 13 ++++-- src/main/java/mapper/SearchMapper.xml | 18 ++++++++ 6 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/rymcu/forest/dto/SearchModel.java create mode 100644 src/main/java/com/rymcu/forest/mapper/SearchMapper.java create mode 100644 src/main/java/com/rymcu/forest/service/SearchService.java create mode 100644 src/main/java/com/rymcu/forest/service/impl/SearchServiceImpl.java create mode 100644 src/main/java/mapper/SearchMapper.xml diff --git a/src/main/java/com/rymcu/forest/dto/SearchModel.java b/src/main/java/com/rymcu/forest/dto/SearchModel.java new file mode 100644 index 0000000..5a44e51 --- /dev/null +++ b/src/main/java/com/rymcu/forest/dto/SearchModel.java @@ -0,0 +1,17 @@ +package com.rymcu.forest.dto; + +import lombok.Data; + +/** + * @author ronger + */ +@Data +public class SearchModel { + + private String label; + + private String value; + + private String type; + +} diff --git a/src/main/java/com/rymcu/forest/mapper/SearchMapper.java b/src/main/java/com/rymcu/forest/mapper/SearchMapper.java new file mode 100644 index 0000000..b6a8a3f --- /dev/null +++ b/src/main/java/com/rymcu/forest/mapper/SearchMapper.java @@ -0,0 +1,28 @@ +package com.rymcu.forest.mapper; + +import com.rymcu.forest.dto.SearchModel; + +import java.util.List; + +/** + * @author ronger + */ +public interface SearchMapper { + /** + * 初始化文章搜索数据 + * @return + */ + List searchInitialArticleSearch(); + + /** + * 初始化作品集搜索数据 + * @return + */ + List searchInitialPortfolioSearch(); + + /** + * 初始化用户搜索数据 + * @return + */ + List searchInitialUserSearch(); +} diff --git a/src/main/java/com/rymcu/forest/service/SearchService.java b/src/main/java/com/rymcu/forest/service/SearchService.java new file mode 100644 index 0000000..7485bf0 --- /dev/null +++ b/src/main/java/com/rymcu/forest/service/SearchService.java @@ -0,0 +1,16 @@ +package com.rymcu.forest.service; + +import com.rymcu.forest.dto.SearchModel; + +import java.util.List; + +/** + * @author ronger + */ +public interface SearchService { + /** + * 初始化搜索数据 + * @return + */ + List initialSearch(); +} diff --git a/src/main/java/com/rymcu/forest/service/impl/SearchServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/SearchServiceImpl.java new file mode 100644 index 0000000..2f583b0 --- /dev/null +++ b/src/main/java/com/rymcu/forest/service/impl/SearchServiceImpl.java @@ -0,0 +1,43 @@ +package com.rymcu.forest.service.impl; + +import com.rymcu.forest.core.service.redis.RedisResult; +import com.rymcu.forest.core.service.redis.RedisService; +import com.rymcu.forest.dto.SearchModel; +import com.rymcu.forest.mapper.SearchMapper; +import com.rymcu.forest.service.SearchService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * @author ronger + */ +@Service +public class SearchServiceImpl implements SearchService { + + @Resource + private SearchMapper searchMapper; + @Resource + private RedisService redisService; + + @Override + public List initialSearch() { + String searchKey = "initialSearch"; + RedisResult result = redisService.getListResult(searchKey, SearchModel.class); + if (Objects.nonNull(result.getListResult())) { + return result.getListResult(); + } + List list = new ArrayList<>(); + List articleSearchModels = searchMapper.searchInitialArticleSearch(); + List portfolioSearchModels = searchMapper.searchInitialPortfolioSearch(); + List userSearchModels = searchMapper.searchInitialUserSearch(); + list.addAll(articleSearchModels); + list.addAll(portfolioSearchModels); + list.addAll(userSearchModels); + redisService.set(searchKey, list, 24 * 60 * 60); + return list; + } +} diff --git a/src/main/java/com/rymcu/forest/web/api/common/CommonApiController.java b/src/main/java/com/rymcu/forest/web/api/common/CommonApiController.java index 715f8de..d9e330a 100644 --- a/src/main/java/com/rymcu/forest/web/api/common/CommonApiController.java +++ b/src/main/java/com/rymcu/forest/web/api/common/CommonApiController.java @@ -8,10 +8,7 @@ import com.rymcu.forest.core.result.GlobalResultMessage; import com.rymcu.forest.core.service.log.annotation.VisitLogger; import com.rymcu.forest.dto.*; import com.rymcu.forest.entity.User; -import com.rymcu.forest.service.ArticleService; -import com.rymcu.forest.service.JavaMailService; -import com.rymcu.forest.service.PortfolioService; -import com.rymcu.forest.service.UserService; +import com.rymcu.forest.service.*; import com.rymcu.forest.util.UserUtils; import com.rymcu.forest.util.Utils; import org.springframework.web.bind.annotation.*; @@ -37,6 +34,8 @@ public class CommonApiController { private ArticleService articleService; @Resource private PortfolioService portfolioService; + @Resource + private SearchService SearchService; @GetMapping("/get-email-code") public GlobalResult> getEmailCode(@RequestParam("email") String email) throws MessagingException { @@ -135,4 +134,10 @@ public class CommonApiController { Map map = Utils.getArticlesGlobalResult(pageInfo); return GlobalResultGenerator.genSuccessResult(map); } + + @GetMapping("/initial-search") + public GlobalResult initialSearch() { + List list = SearchService.initialSearch(); + return GlobalResultGenerator.genSuccessResult(list); + } } diff --git a/src/main/java/mapper/SearchMapper.xml b/src/main/java/mapper/SearchMapper.xml new file mode 100644 index 0000000..44047d0 --- /dev/null +++ b/src/main/java/mapper/SearchMapper.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + \ No newline at end of file