diff --git a/server/like-front/src/main/java/com/mdd/front/config/FrontConfig.java b/server/like-front/src/main/java/com/mdd/front/config/FrontConfig.java index b41f6602..4d9e3e6a 100644 --- a/server/like-front/src/main/java/com/mdd/front/config/FrontConfig.java +++ b/server/like-front/src/main/java/com/mdd/front/config/FrontConfig.java @@ -29,6 +29,7 @@ public class FrontConfig { "/api/article/detail", "/api/article/list", "/api/pc/getConfig", + "/api/pc/index", }; } diff --git a/server/like-front/src/main/java/com/mdd/front/controller/PcController.java b/server/like-front/src/main/java/com/mdd/front/controller/PcController.java index 4e08508a..301554f5 100644 --- a/server/like-front/src/main/java/com/mdd/front/controller/PcController.java +++ b/server/like-front/src/main/java/com/mdd/front/controller/PcController.java @@ -19,6 +19,13 @@ public class PcController { @Resource IPcService iPcService; + @GetMapping("/index") + public AjaxResult> index() + { + Map index = iPcService.index(); + return AjaxResult.success(index); + } + /** * 配置 * @author cjh diff --git a/server/like-front/src/main/java/com/mdd/front/service/IPcService.java b/server/like-front/src/main/java/com/mdd/front/service/IPcService.java index b2542ef0..dbaa5371 100644 --- a/server/like-front/src/main/java/com/mdd/front/service/IPcService.java +++ b/server/like-front/src/main/java/com/mdd/front/service/IPcService.java @@ -1,9 +1,19 @@ package com.mdd.front.service; +import com.mdd.common.mapper.DecoratePageMapper; +import com.mdd.common.mapper.DecorateTabbarMapper; +import com.mdd.common.mapper.article.ArticleMapper; +import com.mdd.common.mapper.setting.HotSearchMapper; + +import javax.annotation.Resource; import java.util.Map; public interface IPcService { + + + + Map index(); /** * 配置 * @author cjh diff --git a/server/like-front/src/main/java/com/mdd/front/service/impl/PcServiceImpI.java b/server/like-front/src/main/java/com/mdd/front/service/impl/PcServiceImpI.java index df98dfea..3d7d457b 100644 --- a/server/like-front/src/main/java/com/mdd/front/service/impl/PcServiceImpI.java +++ b/server/like-front/src/main/java/com/mdd/front/service/impl/PcServiceImpI.java @@ -1,17 +1,109 @@ package com.mdd.front.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.mdd.common.config.GlobalConfig; +import com.mdd.common.entity.DecoratePage; +import com.mdd.common.entity.article.Article; +import com.mdd.common.mapper.DecoratePageMapper; +import com.mdd.common.mapper.article.ArticleMapper; import com.mdd.common.util.ArrayUtils; import com.mdd.common.util.ConfigUtils; +import com.mdd.common.util.TimeUtils; import com.mdd.common.util.UrlUtils; import com.mdd.front.service.IPcService; import org.springframework.stereotype.Service; + +import javax.annotation.Resource; import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; @Service public class PcServiceImpI implements IPcService { + @Resource + DecoratePageMapper decoratePageMapper; + + @Resource + ArticleMapper articleMapper; + + @Override + public Map index() { + Map indexData = new LinkedHashMap<>(); + DecoratePage decoratePage = decoratePageMapper.selectOne( + new QueryWrapper() + .eq("id", 1) + .last("limit 1")); + //全部资讯 + List
articlesAll = articleMapper.selectList(new QueryWrapper
() + .eq("is_show", 1) + .eq("is_delete", 0) + .orderByDesc("sort") + .orderByDesc("id") + .last("limit 5")); + List> articlesAllList = new LinkedList<>(); + for (Article article : articlesAll) { + Map map = new LinkedHashMap<>(); + map.put("id", article.getId()); + map.put("title", article.getTitle()); + map.put("intro", article.getIntro()); + map.put("summary", article.getSummary()); + map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); + map.put("author", article.getAuthor()); + map.put("visit", article.getVisit()); + map.put("sort", article.getSort()); + map.put("createTime", TimeUtils.timestampToDate(article.getCreateTime())); + articlesAllList.add(map); + } + + //最新资讯 + List
articlesNew = articleMapper.selectList(new QueryWrapper
() + .eq("is_show", 1) + .eq("is_delete", 0) + .orderByDesc("id") + .last("limit 7")); + List> articlesNewList = new LinkedList<>(); + for (Article article : articlesNew) { + Map map = new LinkedHashMap<>(); + map.put("id", article.getId()); + map.put("title", article.getTitle()); + map.put("intro", article.getIntro()); + map.put("summary", article.getSummary()); + map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); + map.put("author", article.getAuthor()); + map.put("visit", article.getVisit()); + map.put("sort", article.getSort()); + map.put("createTime", TimeUtils.timestampToDate(article.getCreateTime())); + articlesNewList.add(map); + } + //热门资讯 + List
articlesHot = articleMapper.selectList(new QueryWrapper
() + .eq("is_show", 1) + .eq("is_delete", 0) + .orderByDesc("visit") + .last("limit 7")); + List> articlesHostList = new LinkedList<>(); + for (Article article : articlesHot) { + Map map = new LinkedHashMap<>(); + map.put("id", article.getId()); + map.put("title", article.getTitle()); + map.put("intro", article.getIntro()); + map.put("summary", article.getSummary()); + map.put("image", UrlUtils.toAbsoluteUrl(article.getImage())); + map.put("author", article.getAuthor()); + map.put("visit", article.getVisit()); + map.put("sort", article.getSort()); + map.put("createTime", TimeUtils.timestampToDate(article.getCreateTime())); + articlesHostList.add(map); + } + + indexData.put("pages", decoratePage.getPageData()); + indexData.put("all", articlesAllList); + indexData.put("new", articlesNewList); + indexData.put("hot", articlesHostList); + return indexData; + } @Override public Map getConfig() {