增加PC端文章详情接口
This commit is contained in:
parent
d6bd188203
commit
f48116e8d1
|
|
@ -30,6 +30,7 @@ public class FrontConfig {
|
||||||
"/api/article/list",
|
"/api/article/list",
|
||||||
"/api/pc/getConfig",
|
"/api/pc/getConfig",
|
||||||
"/api/pc/index",
|
"/api/pc/index",
|
||||||
|
"/api/pc/articleDetail",
|
||||||
"/api/login/getScanCode",
|
"/api/login/getScanCode",
|
||||||
"/api/login/scanLogin",
|
"/api/login/scanLogin",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
package com.mdd.front.controller;
|
package com.mdd.front.controller;
|
||||||
|
|
||||||
import com.mdd.common.core.AjaxResult;
|
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.service.IPcService;
|
||||||
|
import com.mdd.front.vo.PcArticleDetailVo;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
@ -19,9 +24,14 @@ public class PcController {
|
||||||
@Resource
|
@Resource
|
||||||
IPcService iPcService;
|
IPcService iPcService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主页
|
||||||
|
*
|
||||||
|
* @author cjh
|
||||||
|
* @return AjaxResult<Map<String, Object>>
|
||||||
|
*/
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
public AjaxResult<Map<String,Object>> index()
|
public AjaxResult<Map<String,Object>> index() {
|
||||||
{
|
|
||||||
Map<String, Object> index = iPcService.index();
|
Map<String, Object> index = iPcService.index();
|
||||||
return AjaxResult.success(index);
|
return AjaxResult.success(index);
|
||||||
}
|
}
|
||||||
|
|
@ -37,4 +47,18 @@ public class PcController {
|
||||||
return AjaxResult.success(config);
|
return AjaxResult.success(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param id 文章主键
|
||||||
|
* @return AjaxResult<PcArticleDetailVo>
|
||||||
|
*/
|
||||||
|
@GetMapping("/articleDetail")
|
||||||
|
public AjaxResult<PcArticleDetailVo> articleDetail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||||
|
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||||
|
PcArticleDetailVo vo = iPcService.articleDetail(id, userId);
|
||||||
|
return AjaxResult.success(vo);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.mdd.front.service;
|
package com.mdd.front.service;
|
||||||
|
|
||||||
|
import com.mdd.front.vo.PcArticleDetailVo;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface IPcService {
|
public interface IPcService {
|
||||||
|
|
@ -17,4 +19,14 @@ public interface IPcService {
|
||||||
* @return Map<String, Object>
|
* @return Map<String, Object>
|
||||||
*/
|
*/
|
||||||
Map<String, Object> getConfig();
|
Map<String, Object> getConfig();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param id 文章主键
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
|
PcArticleDetailVo articleDetail(Integer id, Integer userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,20 +4,21 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.mdd.common.config.GlobalConfig;
|
import com.mdd.common.config.GlobalConfig;
|
||||||
import com.mdd.common.entity.DecoratePage;
|
import com.mdd.common.entity.DecoratePage;
|
||||||
import com.mdd.common.entity.article.Article;
|
import com.mdd.common.entity.article.Article;
|
||||||
|
import com.mdd.common.entity.article.ArticleCategory;
|
||||||
|
import com.mdd.common.entity.article.ArticleCollect;
|
||||||
|
import com.mdd.common.exception.OperateException;
|
||||||
import com.mdd.common.mapper.DecoratePageMapper;
|
import com.mdd.common.mapper.DecoratePageMapper;
|
||||||
|
import com.mdd.common.mapper.article.ArticleCategoryMapper;
|
||||||
|
import com.mdd.common.mapper.article.ArticleCollectMapper;
|
||||||
import com.mdd.common.mapper.article.ArticleMapper;
|
import com.mdd.common.mapper.article.ArticleMapper;
|
||||||
import com.mdd.common.util.ArrayUtils;
|
import com.mdd.common.util.*;
|
||||||
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 com.mdd.front.service.IPcService;
|
||||||
|
import com.mdd.front.vo.PcArticleDetailVo;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PcServiceImpI implements IPcService {
|
public class PcServiceImpI implements IPcService {
|
||||||
|
|
@ -25,9 +26,20 @@ public class PcServiceImpI implements IPcService {
|
||||||
@Resource
|
@Resource
|
||||||
DecoratePageMapper decoratePageMapper;
|
DecoratePageMapper decoratePageMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ArticleCategoryMapper articleCategoryMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ArticleCollectMapper articleCollectMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
ArticleMapper articleMapper;
|
ArticleMapper articleMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置
|
||||||
|
* @author cjh
|
||||||
|
* @return Map<String, Object>
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> index() {
|
public Map<String, Object> index() {
|
||||||
Map<String,Object> indexData = new LinkedHashMap<>();
|
Map<String,Object> indexData = new LinkedHashMap<>();
|
||||||
|
|
@ -106,6 +118,11 @@ public class PcServiceImpI implements IPcService {
|
||||||
return indexData;
|
return indexData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置
|
||||||
|
* @author cjh
|
||||||
|
* @return Map<String, Object>
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getConfig() {
|
public Map<String, Object> getConfig() {
|
||||||
Map<String, Object> config = new LinkedHashMap<>();
|
Map<String, Object> config = new LinkedHashMap<>();
|
||||||
|
|
@ -146,4 +163,84 @@ public class PcServiceImpI implements IPcService {
|
||||||
config.put("qrcode",qrCodeMap);
|
config.put("qrcode",qrCodeMap);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param id 文章主键
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return PcArticleDetailVo
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PcArticleDetailVo articleDetail(Integer id, Integer userId) {
|
||||||
|
// 文章详情
|
||||||
|
Article article = articleMapper.selectOne(new QueryWrapper<Article>()
|
||||||
|
.select(Article.class, info->
|
||||||
|
!info.getColumn().equals("is_show") &&
|
||||||
|
!info.getColumn().equals("is_delete") &&
|
||||||
|
!info.getColumn().equals("delete_time"))
|
||||||
|
.eq("id", id)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
if (StringUtils.isNull(article)) {
|
||||||
|
throw new OperateException("文章数据不存在!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分类名称
|
||||||
|
ArticleCategory articleCategory = articleCategoryMapper.selectOne(
|
||||||
|
new QueryWrapper<ArticleCategory>()
|
||||||
|
.eq("id", article.getId())
|
||||||
|
.eq("is_delete", 0));
|
||||||
|
|
||||||
|
// 上一条记录
|
||||||
|
Article prev = articleMapper.selectOne(new QueryWrapper<Article>()
|
||||||
|
.select()
|
||||||
|
.lt("id", id)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.orderByDesc(Arrays.asList("sort", "id"))
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
// 下一条记录
|
||||||
|
Article next = articleMapper.selectOne(new QueryWrapper<Article>()
|
||||||
|
.select("id,title")
|
||||||
|
.gt("id", id)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.orderByDesc(Arrays.asList("sort", "id"))
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
// 是否收藏
|
||||||
|
ArticleCollect collect = articleCollectMapper.selectOne(new QueryWrapper<ArticleCollect>()
|
||||||
|
.eq("article_id", article.getId())
|
||||||
|
.eq("user_id", userId)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
// 处理数据
|
||||||
|
PcArticleDetailVo vo = new PcArticleDetailVo();
|
||||||
|
BeanUtils.copyProperties(article, vo);
|
||||||
|
vo.setCreateTime(TimeUtils.timestampToDate(vo.getCreateTime()));
|
||||||
|
vo.setUpdateTime(TimeUtils.timestampToDate(vo.getUpdateTime()));
|
||||||
|
vo.setCategory(StringUtils.isNotNull(articleCategory) ? articleCategory.getName() : "");
|
||||||
|
vo.setIsCollect(StringUtils.isNotNull(collect) ? 1 : 0);
|
||||||
|
vo.setPrev(null);
|
||||||
|
vo.setNext(null);
|
||||||
|
|
||||||
|
if (StringUtils.isNotNull(prev)) {
|
||||||
|
Map<String, Object> prevMap = new LinkedHashMap<>();
|
||||||
|
prevMap.put("id", prev.getId());
|
||||||
|
prevMap.put("title", prev.getTitle());
|
||||||
|
vo.setPrev(prevMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotNull(next)) {
|
||||||
|
Map<String, Object> nextMap = new LinkedHashMap<>();
|
||||||
|
nextMap.put("id", next.getId());
|
||||||
|
nextMap.put("title", next.getTitle());
|
||||||
|
vo.setNext(nextMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.mdd.front.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PC端文章详情
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PcArticleDetailVo implements Serializable {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private Integer cid;
|
||||||
|
private String category;
|
||||||
|
private String intro;
|
||||||
|
private String summary;
|
||||||
|
private String image;
|
||||||
|
private String content;
|
||||||
|
private String author;
|
||||||
|
private Integer visit;
|
||||||
|
private Integer sort;
|
||||||
|
private Integer isCollect;
|
||||||
|
private String createTime;
|
||||||
|
private String updateTime;
|
||||||
|
private Object prev;
|
||||||
|
private Object next;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue