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