package org.springblade.modules.article.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import lombok.AllArgsConstructor;
|
import org.springblade.core.cache.utils.CacheUtil;
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.mp.support.Query;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.modules.article.entity.Article;
|
import org.springblade.modules.article.service.ArticleService;
|
import org.springblade.modules.article.vo.ArticleVO;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.validation.Valid;
|
import java.util.Date;
|
import java.util.List;
|
|
import static org.springblade.common.cache.CacheNames.ARTICLE_KEY;
|
|
/**
|
* @author zhongrj
|
* @title 资讯控制层
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/blade-article/article")
|
@Api(value = "通知", tags = "通知")
|
public class ArticleController {
|
|
private final ArticleService articleService;
|
|
/**
|
* 查询资讯分页信息
|
*
|
* @param article 资讯对象
|
* @param query 查询参数
|
* @return
|
*/
|
@GetMapping("/pageWeb")
|
public R<IPage<Article>> pageWeb(ArticleVO article, Query query) {
|
return R.data(articleService.selectArticlePage(Condition.getPage(query), article));
|
}
|
|
@GetMapping("/getArticleByDistrictId")
|
public R<List<ArticleVO>> getArticleByDistrictId(ArticleVO article) {
|
return R.data(articleService.getArticleByDistrictId(article));
|
}
|
|
/**
|
* 查询资讯分页信息-app
|
*
|
* @param article 资讯对象
|
* @param query 查询参数
|
* @return
|
*/
|
@GetMapping("/page")
|
public R<IPage<ArticleVO>> page(ArticleVO article, Query query) {
|
return R.data(articleService.selectArticlePageByApp(Condition.getPage(query), article));
|
}
|
|
/**
|
* 敏感词预警
|
*
|
* @param article 资讯对象
|
* @param query 查询参数
|
* @return
|
*/
|
@GetMapping("/pageWords")
|
public R<IPage<Article>> pageWords(ArticleVO article, Query query) {
|
return R.data(articleService.pageWords(Condition.getPage(query), article));
|
}
|
|
/**
|
* 查询资讯分页信息(角色权限)
|
*
|
* @param article 资讯对象
|
* @param query 查询参数
|
* @return
|
*/
|
@GetMapping("/pageDate")
|
public R<IPage<Article>> pageDate(ArticleVO article, Query query) {
|
return R.data(articleService.pageDate(Condition.getPage(query), article));
|
}
|
|
@GetMapping("/pageCollectList")
|
public R<IPage<Article>> pageCollectList(ArticleVO article, Query query) {
|
return R.data(articleService.pageCollectList(Condition.getPage(query), article));
|
}
|
|
/**
|
* 查询资讯分页信息(角色权限)附带点赞评论数
|
*
|
* @param article 资讯对象
|
* @param query 查询参数
|
* @return
|
*/
|
@GetMapping("/pageLikes")
|
public R<IPage<Article>> pageLikes(ArticleVO article, Query query) {
|
return R.data(articleService.pageLikes(Condition.getPage(query), article));
|
}
|
|
/**
|
* 查询已收藏的资讯
|
*/
|
@GetMapping("/pageCollect")
|
public R<IPage<Article>> pageCollect(ArticleVO article, Query query) {
|
return R.data(articleService.pageCollect(Condition.getPage(query), article));
|
}
|
|
|
/**
|
* 资讯详情
|
*
|
* @param article 资讯查询对象
|
*/
|
@GetMapping("/detail")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入articleoy")
|
public R<Article> detail(ArticleVO article) {
|
ArticleVO detail = articleService.getArticleOne(article);
|
UpdateWrapper<Article> objectUpdateWrapper = new UpdateWrapper<>();
|
objectUpdateWrapper.setSql("view_number = view_number + 1");
|
objectUpdateWrapper.eq("id", article.getId());
|
articleService.update(null, objectUpdateWrapper);
|
// List<List<String>> lists = new ArrayList<>();
|
// if (StringUtils.isNotBlank(detail.getArticleRange())) {
|
// lists = (List<List<String>>) JSON.parse(detail.getArticleRange());
|
// }
|
// detail.setArticleList(lists);
|
return R.data(detail);
|
}
|
|
/**
|
* 新增资讯信息
|
*
|
* @param article 资讯对象
|
*/
|
@PostMapping("/save")
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "新增", notes = "传入article")
|
public R save(@Valid Article article) {
|
return R.status(articleService.save(article));
|
}
|
|
/**
|
* 修改资讯信息
|
*
|
* @param article 资讯对象
|
*/
|
@PostMapping("/update")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "修改", notes = "传入article")
|
public R update(@Valid @RequestBody Article article) {
|
return R.status(articleService.updateById(article));
|
}
|
|
/**
|
* 新增或修改资讯信息
|
*
|
* @param article 资讯对象信息
|
*/
|
@PostMapping("/submit")
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "新增或修改资讯信息", notes = "传入article")
|
public R submit(@RequestBody Article article) {
|
CacheUtil.clear(ARTICLE_KEY);
|
boolean flag = false;
|
if (null == article.getId()) {
|
flag = true;
|
if (null == article.getCreateTime()) {
|
article.setCreateTime(new Date());
|
}
|
}
|
article.setUpdateTime(new Date());
|
boolean saveOrUpdate = articleService.saveOrUpdate(article);
|
return R.status(saveOrUpdate);
|
}
|
|
|
/**
|
* 删除资讯信息
|
*
|
* @param ids 资讯主键id,id集合
|
*/
|
@PostMapping("/remove")
|
@ApiOperationSupport(order = 8)
|
@ApiOperation(value = "删除", notes = "传入ids")
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
List<Long> longs = Func.toLongList(ids);
|
boolean removeByIds = articleService.removeByIds(longs);
|
return R.status(removeByIds);
|
}
|
|
/**
|
* 批量修改评论区状态
|
*/
|
@PostMapping("/upcomment")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "批量修改评论区状态", notes = "传入article")
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids, String type) {
|
String[] split = ids.split(",");
|
String strArrays = "";
|
for (int i = 0; i < split.length; i++) {
|
strArrays += "'" + split[i] + "',";
|
}
|
String code = strArrays.substring(0, strArrays.length() - 1);
|
return R.status(articleService.upcomment(code, type));
|
}
|
|
/**
|
* 查询个人资讯
|
*
|
* @param article
|
* @param query
|
* @return
|
*/
|
@GetMapping("/selectArticleG")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "查询个人资讯", notes = "传入article")
|
public R<IPage<Article>> selectArticleG(ArticleVO article, Query query) {
|
return R.data(articleService.selectArticleG(Condition.getPage(query), article));
|
}
|
|
/**
|
* 通知公告表浏览数量加一(反诈的居民查看会得积分)
|
*/
|
@PostMapping("/addNumber")
|
@ApiOperationSupport(order = 8)
|
@ApiOperation(value = "添加浏览数量", notes = "传入notice")
|
public R addNumber(@Valid @RequestBody ArticleVO notice) {
|
UpdateWrapper<Article> objectUpdateWrapper = new UpdateWrapper<>();
|
objectUpdateWrapper.setSql("view_number = view_number + 1");
|
objectUpdateWrapper.eq("id", notice.getId());
|
return R.status(articleService.updateArticle(objectUpdateWrapper,notice.getId(),notice.getHouseCode()));
|
}
|
}
|