增加PC资讯中心接口
This commit is contained in:
parent
570198d9bc
commit
97518d66d3
|
|
@ -30,6 +30,7 @@ public class FrontConfig {
|
|||
"/api/article/list",
|
||||
"/api/pc/getConfig",
|
||||
"/api/pc/index",
|
||||
"/api/pc/articleCenter",
|
||||
"/api/pc/articleDetail",
|
||||
"/api/login/getScanCode",
|
||||
"/api/login/scanLogin",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.mdd.common.core.AjaxResult;
|
|||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import com.mdd.front.LikeFrontThreadLocal;
|
||||
import com.mdd.front.service.IPcService;
|
||||
import com.mdd.front.vo.PcArticleCenterVo;
|
||||
import com.mdd.front.vo.PcArticleDetailVo;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
|
@ -12,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -47,6 +49,18 @@ public class PcController {
|
|||
return AjaxResult.success(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 资讯中心
|
||||
*
|
||||
* @author fzr
|
||||
* @return AjaxResult<List<PcArticleCenterVo>>
|
||||
*/
|
||||
@GetMapping("/articleCenter")
|
||||
public AjaxResult<List<PcArticleCenterVo>> articleCenter() {
|
||||
List<PcArticleCenterVo> list = iPcService.articleCenter();
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章详情
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.mdd.front.service;
|
||||
|
||||
import com.mdd.front.vo.PcArticleCenterVo;
|
||||
import com.mdd.front.vo.PcArticleDetailVo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IPcService {
|
||||
|
|
@ -20,12 +22,20 @@ public interface IPcService {
|
|||
*/
|
||||
Map<String, Object> getConfig();
|
||||
|
||||
/**
|
||||
* 资讯中心
|
||||
*
|
||||
* @authro fzr
|
||||
* @return PcArticleCenterVo
|
||||
*/
|
||||
List<PcArticleCenterVo> articleCenter();
|
||||
|
||||
/**
|
||||
* 文章详情
|
||||
*
|
||||
* @author fzr
|
||||
* @param id 文章主键
|
||||
* @return Object
|
||||
* @return PcArticleDetailVo
|
||||
*/
|
||||
PcArticleDetailVo articleDetail(Integer id, Integer userId);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.mdd.common.mapper.article.ArticleCollectMapper;
|
|||
import com.mdd.common.mapper.article.ArticleMapper;
|
||||
import com.mdd.common.util.*;
|
||||
import com.mdd.front.service.IPcService;
|
||||
import com.mdd.front.vo.PcArticleCenterVo;
|
||||
import com.mdd.front.vo.PcArticleDetailVo;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -164,6 +165,42 @@ public class PcServiceImpI implements IPcService {
|
|||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PcArticleCenterVo> articleCenter() {
|
||||
List<ArticleCategory> articleCategoryList = articleCategoryMapper.selectList(
|
||||
new QueryWrapper<ArticleCategory>()
|
||||
.eq("is_show", 1)
|
||||
.eq("is_delete", 0)
|
||||
.orderByDesc(Arrays.asList("sort", "id")));
|
||||
|
||||
List<PcArticleCenterVo> list = new LinkedList<>();
|
||||
for (ArticleCategory articleCategory : articleCategoryList) {
|
||||
List<Article> articleList = articleMapper.selectList(new QueryWrapper<Article>()
|
||||
.eq("cid", articleCategory.getId())
|
||||
.eq("is_show", 1)
|
||||
.eq("is_delete", 0)
|
||||
.orderByDesc(Arrays.asList("sort", "id"))
|
||||
.last("limit 10"));
|
||||
|
||||
List<Map<String, Object>> articles = new LinkedList<>();
|
||||
for (Article article : articleList) {
|
||||
Map<String, Object> a = new LinkedHashMap<>();
|
||||
a.put("id", article.getId());
|
||||
a.put("title", article.getTitle());
|
||||
a.put("image", UrlUtils.toAbsoluteUrl(article.getImage()));
|
||||
articles.add(a);
|
||||
}
|
||||
|
||||
PcArticleCenterVo vo = new PcArticleCenterVo();
|
||||
vo.setId(articleCategory.getId());
|
||||
vo.setName(articleCategory.getName());
|
||||
vo.setArticle(articles);
|
||||
list.add(vo);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章详情
|
||||
*
|
||||
|
|
@ -196,7 +233,7 @@ public class PcServiceImpI implements IPcService {
|
|||
|
||||
// 上一条记录
|
||||
Article prev = articleMapper.selectOne(new QueryWrapper<Article>()
|
||||
.select()
|
||||
.select("id,title")
|
||||
.lt("id", id)
|
||||
.eq("is_delete", 0)
|
||||
.orderByDesc(Arrays.asList("sort", "id"))
|
||||
|
|
@ -217,6 +254,25 @@ public class PcServiceImpI implements IPcService {
|
|||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
// 最新资讯
|
||||
List<Article> news = articleMapper.selectList(new QueryWrapper<Article>()
|
||||
.select("id,title,image,create_time,update_time")
|
||||
.eq("cid", article.getCid())
|
||||
.eq("is_delete", 0)
|
||||
.orderByDesc("id")
|
||||
.last("limit 8"));
|
||||
|
||||
List<Map<String, Object>> newsList = new LinkedList<>();
|
||||
for (Article newArticle : news) {
|
||||
Map<String, Object> newsMap = new LinkedHashMap<>();
|
||||
newsMap.put("id", newArticle.getId());
|
||||
newsMap.put("title", newArticle.getTitle());
|
||||
newsMap.put("image", UrlUtils.toAbsoluteUrl(newArticle.getImage()));
|
||||
newsMap.put("createTime", TimeUtils.timestampToDate(newArticle.getCreateTime()));
|
||||
newsMap.put("updateTime", TimeUtils.timestampToDate(newArticle.getUpdateTime()));
|
||||
newsList.add(newsMap);
|
||||
}
|
||||
|
||||
// 处理数据
|
||||
PcArticleDetailVo vo = new PcArticleDetailVo();
|
||||
BeanUtils.copyProperties(article, vo);
|
||||
|
|
@ -224,6 +280,7 @@ public class PcServiceImpI implements IPcService {
|
|||
vo.setUpdateTime(TimeUtils.timestampToDate(vo.getUpdateTime()));
|
||||
vo.setCategory(StringUtils.isNotNull(articleCategory) ? articleCategory.getName() : "");
|
||||
vo.setIsCollect(StringUtils.isNotNull(collect) ? 1 : 0);
|
||||
vo.setNews(newsList);
|
||||
vo.setPrev(null);
|
||||
vo.setNext(null);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.mdd.front.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 资讯中心数据
|
||||
*/
|
||||
@Data
|
||||
public class PcArticleCenterVo implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Object article;
|
||||
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ public class PcArticleDetailVo implements Serializable {
|
|||
private Integer id;
|
||||
private Integer cid;
|
||||
private String category;
|
||||
private String title;
|
||||
private String intro;
|
||||
private String summary;
|
||||
private String image;
|
||||
|
|
@ -25,6 +26,6 @@ public class PcArticleDetailVo implements Serializable {
|
|||
private String updateTime;
|
||||
private Object prev;
|
||||
private Object next;
|
||||
|
||||
private Object news;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue