Commit 65f697d2 authored by hanfeng's avatar hanfeng

修改新闻系列接口

parent dc5fc768
package com.xxfc.platform.uccn.comstnt;
/**
* 访问路径
* @author Administrator
*/
public enum UrlType {
OFFICIAL_WEBSITE("官网访问",1),BACKGROUND_MANAGEMENT("后台访问",2);
private String name;
private Integer code;
UrlType(String name, Integer code) {
this.name = name;
this.code = code;
}
public String getName() {
return name;
}
public Integer getCode() {
return code;
}
}
package com.xxfc.platform.uccn.vo;
import lombok.Data;
/**
* 新闻文章查询条件
* @author Administrator
*/
@Data
public class ArticleQuery {
private Integer page;
private Integer limit;
// private String newsContent;
}
......@@ -3,8 +3,10 @@ package com.xxfc.platform.uccn.biz;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.uccn.comstnt.UrlType;
import com.xxfc.platform.uccn.entity.Article;
import com.xxfc.platform.uccn.mapper.ArticleMapper;
import com.xxfc.platform.uccn.vo.ArticleQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
......@@ -21,16 +23,17 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
/**
* 随机文章条数
*/
private final Integer RANDOM_NUMBER=3;
private final Integer RANDOM_NUMBER = 3;
/**
* 首页文章条数
*/
private final Integer HOME_PAGE_NUMBER=4;
private final Integer HOME_PAGE_NUMBER = 4;
/**
* 文章列表
*
* @param page
* @param limit
* @param type
......@@ -43,24 +46,28 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
}
/**
* 获取一条数据
* 获取一条数据
*
* @param id
* @param urlType
* @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;
public Article getOne(Integer id, Integer urlType) {
Example example = new Example(Article.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("id", id);
criteria.andEqualTo("isDel", 0);
if (UrlType.OFFICIAL_WEBSITE.getCode().equals(urlType)) {
criteria.andEqualTo("status", 1);
}
return mapper.selectOneByExample(example);
}
/**
* 随机获取三条连续的文章
*
* @param type
* @return
*/
......@@ -69,14 +76,14 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
List<Article> articleList = mapper.getArticleList(type);
if (!Objects.isNull(articleList)) {
int size = articleList.size();
if (RANDOM_NUMBER>=size) {
if (RANDOM_NUMBER >= size) {
return articleList;
}else {
} else {
Random random = new Random();
int r = random.nextInt(size -RANDOM_NUMBER+1);
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;
for (int i = 0; i < RANDOM_NUMBER.intValue(); i++) {
int index = i + r;
result.add(articleList.get(index));
}
return result;
......@@ -88,17 +95,18 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
/**
* 首页文章列表
*
* @param type
* @return
*/
public List getHomePageArticle(Integer type){
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 {
} else {
if (articleList.size() > HOME_PAGE_NUMBER) {
return articleList.subList(0, HOME_PAGE_NUMBER);
} else {
return articleList;
}
}
......@@ -106,19 +114,64 @@ public class ArticleBiz extends BaseBiz<ArticleMapper, Article> {
@Transactional(rollbackFor = Exception.class)
public void add(Article article) {
if (article==null) {
if (article == null) {
return;
}
article.setIsDel(0);
if (article.getStatus()==null){
if (article.getStatus() == null) {
article.setStatus(0);
}
if (article.getType()==null){
if (article.getType() == null) {
article.setType(0);
}
article.setCreTime(new Date());
mapper.insertSelective(article);
}
public PageInfo findAll(ArticleQuery query) {
PageHelper.startPage(query.getPage(),query.getLimit());
Example exa = Example.builder(Article.class).where(
WeekendSqls.<Article>custom()
.andEqualTo(Article::getIsDel,0)
).build();
List<Article> articles = mapper.selectByExample(exa);
return PageInfo.of(articles);
}
@Override
@Transactional(rollbackFor = Exception.class)
public int updateSelectiveByIdRe(Article article){
article.setUpdTime(new Date());
return mapper.updateByPrimaryKeySelective(article);
}
public int putaway(Integer id) {
Article article = new Article();
article.setId(id);
article.setUpdTime(new Date());
article.setAddTime(new Date());
article.setStatus(1);
return mapper.updateByPrimaryKeySelective(article);
}
public int soldOut(Integer id) {
Article article = new Article();
article.setId(id);
article.setUpdTime(new Date());
article.setStatus(0);
return mapper.updateByPrimaryKeySelective(article);
}
public int remove(Integer id) {
Article article = new Article();
article.setId(id);
article.setUpdTime(new Date());
article.setIsDel(1);
return mapper.updateByPrimaryKeySelective(article);
}
}
......@@ -4,12 +4,11 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.xxfc.platform.uccn.biz.ArticleBiz;
import com.xxfc.platform.uccn.entity.Article;
import com.xxfc.platform.uccn.vo.ArticleQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 文章
......@@ -21,7 +20,7 @@ import java.util.Map;
@Api(tags = {"文章"})
public class ArticleController extends BaseController<ArticleBiz, Article> {
@GetMapping("/list")
@GetMapping("/app/unauth/list")
@ApiOperation(value = "获取文章列表")
public ObjectRestResponse getArticleList(
@RequestParam(name = "page", defaultValue = "1") Integer page,
......@@ -30,20 +29,21 @@ public class ArticleController extends BaseController<ArticleBiz, Article> {
return ObjectRestResponse.succ(baseBiz.getArticleList(page, limit, type));
}
@GetMapping("/one/{id}")
@GetMapping("/app/unauth/one")
@ApiOperation(value = "获取一条数据")
public ObjectRestResponse getOne(@PathVariable Integer id) {
return ObjectRestResponse.succ(baseBiz.getOne(id));
public ObjectRestResponse getOne(@RequestParam Integer id,
@RequestParam(required = false) Integer urlType) {
return ObjectRestResponse.succ(baseBiz.getOne(id,urlType));
}
@GetMapping("/three/{type}")
@GetMapping("/app/unauth/three/{type}")
@ApiOperation(value = "随机获取三条数据")
public ObjectRestResponse randomAccessToThreeData(@PathVariable Integer type){
return ObjectRestResponse.succ(baseBiz.getThree(type));
}
@GetMapping("/homePage/{type}")
@GetMapping("/app/unauth/homePage/{type}")
@ApiOperation(value = "获取首页文章列表")
public ObjectRestResponse getHomePageArticle(@PathVariable Integer type){
return ObjectRestResponse.succ(baseBiz.getHomePageArticle(type));
......@@ -51,11 +51,58 @@ public class ArticleController extends BaseController<ArticleBiz, Article> {
@Override
@PostMapping("/add")
@ApiOperation(value = "获取首页文章列表")
@ApiOperation(value = "添加")
public ObjectRestResponse add(@RequestBody Article article){
baseBiz.add(article);
return ObjectRestResponse.succ();
}
@PostMapping("/All")
@ApiOperation(value = "获取新闻列表")
public ObjectRestResponse<Article> findAll(@RequestBody ArticleQuery query){
return ObjectRestResponse.succ(baseBiz.findAll(query));
}
@Override
@PutMapping("/update")
@ApiOperation(value = "修改")
public ObjectRestResponse update(@RequestBody Article article){
int flag = baseBiz.updateSelectiveByIdRe(article);
if (flag==1) {
return ObjectRestResponse.succ();
}
return ObjectRestResponse.createDefaultFail();
}
@PutMapping("/putaway/{id}")
@ApiOperation(value = "上架")
public ObjectRestResponse putaway(@PathVariable Integer id){
int flag = baseBiz.putaway(id);
if (flag==1) {
return ObjectRestResponse.succ();
}
return ObjectRestResponse.createDefaultFail();
}
@PutMapping("/soldOut/{id}")
@ApiOperation(value = "下架")
public ObjectRestResponse soldOut(@PathVariable Integer id){
int flag = baseBiz.soldOut(id);
if (flag==1) {
return ObjectRestResponse.succ();
}
return ObjectRestResponse.createDefaultFail();
}
@PutMapping("/remove/{id}")
@ApiOperation(value = "删除")
public ObjectRestResponse remove(@PathVariable Integer id){
int flag = baseBiz.remove(id);
if (flag==1) {
return ObjectRestResponse.succ();
}
return ObjectRestResponse.createDefaultFail();
}
}
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