Commit bd21410b authored by hanfeng's avatar hanfeng

文章列表

parent a0363c21
......@@ -68,21 +68,21 @@ public class Article {
*/
@Column(name = "author")
@ApiModelProperty(value = "作者")
private Integer author;
private String author;
/**
* 发布人
*/
@Column(name = "publisher")
@ApiModelProperty(value = "发布人")
private Integer publisher;
private String publisher;
/**
* 封面图
*/
@Column(name = "cover_image")
@ApiModelProperty(value = "封面图")
private Integer coverImage;
private String coverImage;
/**
* 权重
......@@ -105,6 +105,11 @@ public class Article {
@ApiModelProperty(value = "是否上下架:0-否,1-是")
private Integer status;
@Column(name ="type")
@ApiModelProperty(value = "文章发布网站:0-所有,1-新欣房车官网,2-滴房车官网")
private Integer type;
/**
* 创建时间
*/
......
......@@ -12,11 +12,12 @@ import tk.mybatis.spring.annotation.MapperScan;
* @author Administrator
*/
@SpringBootApplication(scanBasePackages ={
"com.github.wxiaoqi"
"com.github.wxiaoqi",
"com.xxfc.platform"
})
@EnableDiscoveryClient
@EnableAceAuthClient
@EnableFeignClients(value = {"com.xxfc.platform","com.github.wxiaoqi.security"})
@EnableFeignClients(basePackages = {"com.xxfc.platform","com.github.wxiaoqi.security"})
@MapperScan(basePackages = "com.xxfc.platform.uccn.mapper")
public class UccnApplication {
public static void main(String[] args) {
......
......@@ -7,18 +7,101 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.uccn.entity.Article;
import com.xxfc.platform.uccn.mapper.ArticleMapper;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls;
import java.util.*;
import java.util.List;
/**
* @author Administrator
*/
@Service
public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
/**
* 随机文章条数
*/
private final Integer RANDOM_NUMBER=3;
/**
* 首页文章条数
*/
private final Integer HOME_PAGE_NUMBER=4;
public PageInfo getArticleList(Integer page, Integer limit) {
PageHelper.startPage(page,limit);
List articleList = mapper.getArticleList();
/**
* 文章列表
* @param page
* @param limit
* @param type
* @return
*/
public PageInfo getArticleList(Integer page, Integer limit, Integer type) {
PageHelper.startPage(page, limit);
List articleList = mapper.getArticleList(type);
return PageInfo.of(articleList);
}
/**
* 获取一条数据
* @param id
* @return
*/
public Article getOne(Integer id) {
Example example = Example.builder(Article.class).where(
WeekendSqls.<Article>custom()
.andEqualTo(Article::getId,id)
.andEqualTo(Article::getIsDel, 0)
.andEqualTo(Article::getStatus, 1)
).build();
Article article = mapper.selectOneByExample(example);
return article;
}
/**
* 随机获取三条连续的文章
* @param type
* @return
*/
public List getThree(Integer type) {
List<Article> articleList = mapper.getArticleList(type);
if (!Objects.isNull(articleList)) {
int size = articleList.size();
if (RANDOM_NUMBER>=size) {
return articleList;
}else {
Random random = new Random();
int r = random.nextInt(size -RANDOM_NUMBER+1);
List<Article> result = new ArrayList<>();
for (int i=0;i<RANDOM_NUMBER.intValue();i++){
int index= i+r;
result.add(articleList.get(index));
}
return result;
}
}
return new ArrayList();
}
/**
* 首页文章列表
* @param type
* @return
*/
public List getHomePageArticle(Integer type){
List<Article> articleList = mapper.getArticleList(type);
if (Objects.isNull(articleList)) {
return new ArrayList();
}else {
if (articleList.size()>HOME_PAGE_NUMBER) {
return articleList.subList(0,HOME_PAGE_NUMBER);
}else {
return articleList;
}
}
}
}
package com.xxfc.platform.uccn.mapper;
import com.xxfc.platform.uccn.entity.Article;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
......@@ -9,5 +10,10 @@ import java.util.List;
* @author Administrator
*/
public interface ArticleMapper extends Mapper<Article> {
List getArticleList();
/**
* 根据网站类型查询文章
* @param type
* @return
*/
List<Article> getArticleList(@Param("type") Integer type);
}
......@@ -5,14 +5,15 @@ import com.github.wxiaoqi.security.common.rest.BaseController;
import com.xxfc.platform.uccn.biz.ArticleBiz;
import com.xxfc.platform.uccn.entity.Article;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
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.*;
import java.util.Map;
/**
* 文章
*
* @author Administrator
*/
@RestController
......@@ -22,9 +23,29 @@ public class ArticleController extends BaseController<ArticleBiz, Article> {
@GetMapping("/list")
@ApiOperation(value = "获取文章列表")
public ObjectRestResponse getArticleList(
@RequestParam(name = "page",defaultValue = "1") Integer page,
@RequestParam(name = "limit",defaultValue = "10")Integer limit){
return ObjectRestResponse.succ(baseBiz.getArticleList(page,limit));
}
public ObjectRestResponse getArticleList(
@RequestParam(name = "page", defaultValue = "1") Integer page,
@RequestParam(name = "limit", defaultValue = "10") Integer limit,
@RequestParam(name = "type", defaultValue = "0") Integer type) {
return ObjectRestResponse.succ(baseBiz.getArticleList(page, limit, type));
}
@GetMapping("/one/{id}")
@ApiOperation(value = "获取一条数据")
public ObjectRestResponse getOne(@PathVariable Integer id) {
return ObjectRestResponse.succ(baseBiz.getOne(id));
}
@GetMapping("/three/{type}")
@ApiOperation(value = "随机获取三条数据")
public ObjectRestResponse randomAccessToThreeData(@PathVariable Integer type){
return ObjectRestResponse.succ(baseBiz.getThree(type));
}
@GetMapping("/homePage/{type}")
@ApiOperation(value = "获取首页文章列表")
public ObjectRestResponse getHomePageArticle(@PathVariable Integer type){
return ObjectRestResponse.succ(baseBiz.getHomePageArticle(type));
}
}
......@@ -4,7 +4,8 @@
<mapper namespace="com.xxfc.platform.uccn.mapper.ArticleMapper">
<select id="getArticleList" resultType="com.xxfc.platform.uccn.entity.Article">
select title,epitome,add_time,cover_image from article where is_del=0 and status=1 order by weight,add_time DESC
select title,epitome,add_time,cover_image from article
where is_del=0 and status=1 and (type=#{type} or type=0) order by weight DESC,add_time DESC
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment