增加文章资讯接口
This commit is contained in:
parent
746236e545
commit
15c0cc66b9
|
|
@ -1,10 +1,17 @@
|
||||||
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.core.PageResult;
|
||||||
|
import com.mdd.common.validator.annotation.IDMust;
|
||||||
import com.mdd.front.service.IArticleService;
|
import com.mdd.front.service.IArticleService;
|
||||||
|
import com.mdd.front.validate.PageParam;
|
||||||
import com.mdd.front.vo.article.ArticleCateVo;
|
import com.mdd.front.vo.article.ArticleCateVo;
|
||||||
|
import com.mdd.front.vo.article.ArticleDetailVo;
|
||||||
|
import com.mdd.front.vo.article.ArticleListVo;
|
||||||
|
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;
|
||||||
|
|
@ -36,8 +43,10 @@ public class ArticleController {
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public Object list() {
|
public Object list(@Validated PageParam pageParam,
|
||||||
return AjaxResult.success();
|
@RequestParam(value = "cid", defaultValue = "0") Integer cid) {
|
||||||
|
PageResult<ArticleListVo> list = iArticleService.list(pageParam, cid);
|
||||||
|
return AjaxResult.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,8 +56,9 @@ public class ArticleController {
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
@GetMapping("/detail")
|
@GetMapping("/detail")
|
||||||
public Object detail() {
|
public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||||
return AjaxResult.success();
|
ArticleDetailVo vo = iArticleService.detail(id);
|
||||||
|
return AjaxResult.success(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
package com.mdd.front.service;
|
package com.mdd.front.service;
|
||||||
|
|
||||||
|
import com.mdd.common.core.PageResult;
|
||||||
|
import com.mdd.front.validate.PageParam;
|
||||||
import com.mdd.front.vo.article.ArticleCateVo;
|
import com.mdd.front.vo.article.ArticleCateVo;
|
||||||
|
import com.mdd.front.vo.article.ArticleDetailVo;
|
||||||
|
import com.mdd.front.vo.article.ArticleListVo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -9,10 +13,31 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public interface IArticleService {
|
public interface IArticleService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章分类
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return List<ArticleCateVo>
|
||||||
|
*/
|
||||||
List<ArticleCateVo> category();
|
List<ArticleCateVo> category();
|
||||||
|
|
||||||
Object list();
|
/**
|
||||||
|
* 文章分类
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param pageParam 分页参数
|
||||||
|
* @param cid 分类ID
|
||||||
|
* @return PageResult<ArticleListVo>
|
||||||
|
*/
|
||||||
|
PageResult<ArticleListVo> list(PageParam pageParam, Integer cid);
|
||||||
|
|
||||||
Object detail();
|
/**
|
||||||
|
* 文章详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param id 文章主键
|
||||||
|
* @return ArticleDetailVo
|
||||||
|
*/
|
||||||
|
ArticleDetailVo detail(Integer id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,32 @@
|
||||||
package com.mdd.front.service.impl;
|
package com.mdd.front.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.mdd.common.core.PageResult;
|
||||||
|
import com.mdd.common.entity.article.Article;
|
||||||
|
import com.mdd.common.entity.article.ArticleCategory;
|
||||||
import com.mdd.common.mapper.article.ArticleCategoryMapper;
|
import com.mdd.common.mapper.article.ArticleCategoryMapper;
|
||||||
import com.mdd.common.mapper.article.ArticleMapper;
|
import com.mdd.common.mapper.article.ArticleMapper;
|
||||||
|
import com.mdd.common.utils.TimeUtil;
|
||||||
|
import com.mdd.common.utils.UrlUtil;
|
||||||
import com.mdd.front.service.IArticleService;
|
import com.mdd.front.service.IArticleService;
|
||||||
|
import com.mdd.front.validate.PageParam;
|
||||||
import com.mdd.front.vo.article.ArticleCateVo;
|
import com.mdd.front.vo.article.ArticleCateVo;
|
||||||
|
import com.mdd.front.vo.article.ArticleDetailVo;
|
||||||
|
import com.mdd.front.vo.article.ArticleListVo;
|
||||||
|
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.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章服务实现类
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ArticleServiceImpl implements IArticleService {
|
public class ArticleServiceImpl implements IArticleService {
|
||||||
|
|
||||||
|
|
@ -18,19 +36,87 @@ public class ArticleServiceImpl implements IArticleService {
|
||||||
@Resource
|
@Resource
|
||||||
ArticleCategoryMapper articleCategoryMapper;
|
ArticleCategoryMapper articleCategoryMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章分类
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return List<ArticleCateVo>
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<ArticleCateVo> category() {
|
public List<ArticleCateVo> category() {
|
||||||
return null;
|
List<ArticleCategory> articleCateVos = articleCategoryMapper.selectList(
|
||||||
|
new QueryWrapper<ArticleCategory>()
|
||||||
|
.select("id,name")
|
||||||
|
.eq("is_show", 1)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.orderByDesc(Arrays.asList("sort", "id")));
|
||||||
|
|
||||||
|
List<ArticleCateVo> list = new LinkedList<>();
|
||||||
|
for (ArticleCategory category: articleCateVos) {
|
||||||
|
ArticleCateVo vo = new ArticleCateVo();
|
||||||
|
BeanUtils.copyProperties(category, vo);
|
||||||
|
list.add(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章列表
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param pageParam 分页参数
|
||||||
|
* @param cid 分类ID
|
||||||
|
* @return PageResult<ArticleListVo>
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object list() {
|
public PageResult<ArticleListVo> list(PageParam pageParam, Integer cid) {
|
||||||
return null;
|
Integer pageNo = pageParam.getPageNo();
|
||||||
|
Integer pageSize = pageParam.getPageSize();
|
||||||
|
|
||||||
|
QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.select("id,title,image,intro,visit,create_time");
|
||||||
|
if (cid > 0) {
|
||||||
|
queryWrapper.eq("cid", cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPage<Article> iPage = articleMapper.selectPage(new Page<>(pageNo, pageSize), queryWrapper);
|
||||||
|
|
||||||
|
List<ArticleListVo> list = new LinkedList<>();
|
||||||
|
for (Article article : iPage.getRecords()) {
|
||||||
|
ArticleListVo vo = new ArticleListVo();
|
||||||
|
BeanUtils.copyProperties(article, vo);
|
||||||
|
vo.setImage(UrlUtil.toAbsoluteUrl(article.getImage()));
|
||||||
|
vo.setCreateTime(TimeUtil.timestampToDate(article.getCreateTime()));
|
||||||
|
list.add(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return PageResult.iPageHandle(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param id 文章主键
|
||||||
|
* @return ArticleDetailVo
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object detail() {
|
public ArticleDetailVo detail(Integer id) {
|
||||||
return null;
|
Article article = articleMapper.selectOne(new QueryWrapper<Article>()
|
||||||
|
.select("id,title,image,intro,visit,author,content,create_time")
|
||||||
|
.eq("id", id)
|
||||||
|
.eq("is_show", 1)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
Assert.notNull(article, "数据不存在!");
|
||||||
|
|
||||||
|
ArticleDetailVo vo = new ArticleDetailVo();
|
||||||
|
BeanUtils.copyProperties(article, vo);
|
||||||
|
vo.setImage(UrlUtil.toAbsoluteUrl(article.getImage()));
|
||||||
|
vo.setCreateTime(TimeUtil.timestampToDate(article.getCreateTime()));
|
||||||
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.mdd.front.validate;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.DecimalMax;
|
||||||
|
import javax.validation.constraints.DecimalMin;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class PageParam implements Serializable {
|
||||||
|
|
||||||
|
// 当前分页
|
||||||
|
@DecimalMin(value = "1", message = "pageNo参数必须大于0的数字")
|
||||||
|
public Integer pageNo = 1;
|
||||||
|
|
||||||
|
// 每页条数
|
||||||
|
@DecimalMin(value = "1", message = "pageSize参数必须是大于0的数字")
|
||||||
|
@DecimalMax(value = "60", message = "pageSize参数必须是小于60的数字")
|
||||||
|
private Integer pageSize = 20;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -9,5 +9,13 @@ public class ArticleDetailVo implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private String title;
|
||||||
|
private String image;
|
||||||
|
private String intro;
|
||||||
|
private Integer visit;
|
||||||
|
private String author;
|
||||||
|
private String content;
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,12 @@ import java.io.Serializable;
|
||||||
public class ArticleListVo implements Serializable {
|
public class ArticleListVo implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private String title;
|
||||||
|
private String image;
|
||||||
|
private String intro;
|
||||||
|
private Integer visit;
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue