ZjxlArticleContentController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package cn.stylefeng.guns.zjxl.cnotroller;
  2. import cn.stylefeng.guns.zjxl.model.ZjxlArticleContent;
  3. import cn.stylefeng.guns.zjxl.service.ZjxlArticleContentService;
  4. import cn.stylefeng.guns.zjxlUtil.BaseController;
  5. import cn.stylefeng.guns.zjxlUtil.PageUtil;
  6. import io.swagger.annotations.Api;
  7. import io.swagger.annotations.ApiOperation;
  8. import io.swagger.annotations.ApiParam;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.text.SimpleDateFormat;
  18. import java.util.Date;
  19. import java.util.List;
  20. /***
  21. * @ClassName: ZjxlArticleContentController
  22. * @Description:文章内容管理
  23. * @Auther: shi kejing
  24. * @Date: 2020/11/3 17:40
  25. */
  26. @RestController
  27. @Api(description = "文章内容管理")
  28. @RequestMapping(value = "/zjxl/zjxlArticleContent")
  29. public class ZjxlArticleContentController extends BaseController {
  30. private Logger logger = (Logger) LoggerFactory.getLogger(ZjxlArticleContentController.class);
  31. @Autowired
  32. private ZjxlArticleContentService articleContentService;
  33. @RequestMapping(value = "/findArticleContentById", method = RequestMethod.GET)
  34. @ApiOperation(value = "查询文章管理列表")
  35. public String findArticleContentById(@ApiParam(name = "id", value = "文章id", required = false) @RequestParam(value = "id", required = false)String id,
  36. @ApiParam(name = "articleContentTitle", value = "文章标题", required = false) @RequestParam(value = "articleContentTitle", required = false)String articleContentTitle,
  37. @ApiParam(name = "systemDictType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们", required = false) @RequestParam(value = "systemDictType", required = false)Integer systemDictType,
  38. @ApiParam(name = "pageNo", value = "第几页", defaultValue = "1") @RequestParam(value = "pageNo", required = false) Integer pageNo,
  39. @ApiParam(name = "pageSize", value = "分页大小", defaultValue = "10") @RequestParam(value = "pageSize", required = false) Integer pageSize){
  40. try {
  41. List<ZjxlArticleContent> articleContentList = articleContentService.findArticleContentById(id,articleContentTitle,systemDictType,pageNo-1,pageSize);
  42. return write(200,"查询成功","data", PageUtil.getPage(articleContentList,pageNo,pageSize,articleContentService.allCount()));
  43. }catch (Exception e){
  44. e.printStackTrace();
  45. return write(-1,"查询失败");
  46. }
  47. }
  48. @RequestMapping(value = "/addArticleContent", method = RequestMethod.POST)
  49. @ApiOperation(value = "添加文章")
  50. public String addArticleContent(
  51. @ApiParam(name = "articleContentTitle", value = "文章标题", required = false) @RequestParam(value = "articleContentTitle", required = false)String articleContentTitle,
  52. @ApiParam(name = "articleContentCover", value = "封面", required = false) @RequestParam(value = "articleContentCover", required = false)String articleContentCover,
  53. @ApiParam(name = "articleContentAbstract", value = "摘要", required = false) @RequestParam(value = "articleContentAbstract", required = false) String articleContentAbstract,
  54. @ApiParam(name = "articleContentContent", value = "内容", required = false) @RequestParam(value = "articleContentContent", required = false) String articleContentContent,
  55. @ApiParam(name = "articleContentType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们", required = false) @RequestParam(value = "articleContentType", required = false)Integer articleContentType,
  56. @ApiParam(name = "articleContentClassify", value = "分类", required = false) @RequestParam(value = "articleContentClassify", required = false)String articleContentClassify,
  57. @ApiParam(name = "articleContentSubclassify", value = "子分类", required = false) @RequestParam(value = "articleContentSubclassify", required = false)String articleContentSubclassify,
  58. @ApiParam(name = "articleContentSort", value = "排序", required = false) @RequestParam(value = "articleContentSort", required = false)Integer articleContentSort,
  59. @ApiParam(name = "articleContentIsLine", value = "是否上线", required = false, defaultValue = "0") @RequestParam(value = "articleContentIsLine", required = false)Integer articleContentIsLine){
  60. try {
  61. ZjxlArticleContent articleContent = new ZjxlArticleContent();
  62. articleContent.setArticleContentTitle(articleContentTitle);
  63. articleContent.setArticleContentCover(articleContentCover);
  64. articleContent.setArticleContentAbstract(articleContentAbstract);
  65. articleContent.setArticleContentType(articleContentType);
  66. articleContent.setArticleContentClassify(articleContentClassify);
  67. articleContent.setArticleContentSubclassify(articleContentSubclassify);
  68. articleContent.setArticleContentSort(articleContentSort);
  69. articleContent.setArticleContentIsLine(articleContentIsLine);
  70. articleContent.setArticleContentContent(articleContentContent);
  71. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
  72. articleContent.setArticleContentCreateTime(df.format(new Date()));// new Date()为获取当前系统时间
  73. return write(200,"添加成功","data",articleContentService.addArticleContent(articleContent));
  74. }catch (Exception e){
  75. e.printStackTrace();
  76. return write(-1,"添加失败");
  77. }
  78. }
  79. @RequestMapping(value = "/deleteArticleContent", method = RequestMethod.POST)
  80. @ApiOperation(value = "删除文章管理")
  81. public String deleteArticleContent(@ApiParam(name = "id", value = "文章id") @RequestParam(value = "id") String id){
  82. try {
  83. if (id == null){
  84. logger.info("修改是否上线:id====="+id);
  85. return write(-1,"获取参数失败");
  86. }
  87. logger.info("修改是否上线:id====="+id);
  88. return write(200,"删除成功","data",articleContentService.deleteArticleContent(id));
  89. }catch (Exception e){
  90. e.printStackTrace();
  91. return write(-1,"删除失败");
  92. }
  93. }
  94. @RequestMapping(value = "/updateArticleContent", method = RequestMethod.POST)
  95. @ApiOperation(value = "修改是否上线")
  96. public String updateArticleContent(@ApiParam(name = "id", value = "文章id") @RequestParam(value = "id") String id,
  97. @ApiParam(name = "isLine", value = "是否上线") @RequestParam(value = "isLine") Integer isLine){
  98. try {
  99. if (id == null || isLine == null){
  100. logger.info("修改是否上线:id====="+id+",isLine===="+isLine);
  101. return write(-1,"获取参数失败");
  102. }
  103. logger.info("修改是否上线:id====="+id+",isLine===="+isLine);
  104. return write(200,"修改上线成功","data",articleContentService.updateArticleContent(id,isLine));
  105. }catch (Exception e){
  106. e.printStackTrace();
  107. return write(-1,"修改上线失败");
  108. }
  109. }
  110. @RequestMapping(value = "/getLeftTabs", method = RequestMethod.GET)
  111. @ApiOperation(value = "根据每个内容类型获取对应的分类")
  112. public String getLeftTabs(@ApiParam(name = "articleContentType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们") @RequestParam(value = "articleContentType") String articleContentType){
  113. try {
  114. if (StringUtils.isEmpty(articleContentType)){
  115. logger.info("内容类型:articleContentType====="+articleContentType);
  116. return write(-1,"获取参数失败");
  117. }
  118. logger.info("内容类型:articleContentType====="+articleContentType);
  119. return write(200,"操作成功","data",articleContentService.getLeftTabs(articleContentType));
  120. }catch (Exception e){
  121. e.printStackTrace();
  122. return write(-1,"操作失败");
  123. }
  124. }
  125. @RequestMapping(value = "/getArticleContentSubclassify", method = RequestMethod.GET)
  126. @ApiOperation(value = "根据每个分类获取对应的子分类")
  127. public String getArticleContentSubclassify(@ApiParam(name = "articleContentType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们") @RequestParam(value = "articleContentType") String articleContentType,
  128. @ApiParam(name = "articleContentClassify", value = "分类") @RequestParam(value = "articleContentClassify") String articleContentClassify){
  129. try {
  130. if (StringUtils.isEmpty(articleContentType) || StringUtils.isEmpty(articleContentClassify)){
  131. logger.info("内容类型:articleContentType====="+articleContentType);
  132. logger.info("分类:articleContentClassify====="+articleContentClassify);
  133. return write(-1,"获取参数失败");
  134. }
  135. logger.info("内容类型:articleContentType====="+articleContentType);
  136. logger.info("分类:articleContentClassify====="+articleContentClassify);
  137. return write(200,"操作成功","data",articleContentService.getArticleContentSubclassify(articleContentType,articleContentClassify));
  138. }catch (Exception e){
  139. e.printStackTrace();
  140. return write(-1,"操作失败");
  141. }
  142. }
  143. @RequestMapping(value = "/getArticleContent", method = RequestMethod.GET)
  144. @ApiOperation(value = "根据子分类获取对应的文章(排序最高的文章)")
  145. public String getArticleContent(@ApiParam(name = "articleContentType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们") @RequestParam(value = "articleContentType") String articleContentType,
  146. @ApiParam(name = "articleContentClassify", value = "分类") @RequestParam(value = "articleContentClassify") String articleContentClassify,
  147. @ApiParam(name = "articleContentSubclassify", value = "子分类") @RequestParam(value = "articleContentSubclassify") String articleContentSubclassify){
  148. try {
  149. if (StringUtils.isEmpty(articleContentType) || StringUtils.isEmpty(articleContentClassify) || StringUtils.isEmpty(articleContentSubclassify)){
  150. logger.info("内容类型:articleContentType====="+articleContentType);
  151. logger.info("分类:articleContentClassify====="+articleContentClassify);
  152. logger.info("子分类:articleContentSubclassify====="+articleContentSubclassify);
  153. return write(-1,"获取参数失败");
  154. }
  155. logger.info("内容类型:articleContentType====="+articleContentType);
  156. logger.info("分类:articleContentClassify====="+articleContentClassify);
  157. logger.info("子分类:articleContentSubclassify====="+articleContentSubclassify);
  158. return write(200,"操作成功","data",articleContentService.getArticleContent(articleContentType,articleContentClassify,articleContentSubclassify));
  159. }catch (Exception e){
  160. e.printStackTrace();
  161. return write(-1,"操作失败");
  162. }
  163. }
  164. @RequestMapping(value = "/findNewsList", method = RequestMethod.GET)
  165. @ApiOperation(value = "查询新闻中心列表")
  166. public String findNewsList(@ApiParam(name = "id", value = "文章id", required = false) @RequestParam(value = "id", required = false)String id,
  167. // @ApiParam(name = "articleContentTitle", value = "文章标题", required = false) @RequestParam(value = "articleContentTitle", required = false)String articleContentTitle,
  168. // @ApiParam(name = "systemDictType", value = "内容类型 1-产品与服务 2-公司案例 3-新闻中心 4-关于我们", required = false, defaultValue = "3") @RequestParam(value = "systemDictType", required = false)Integer systemDictType,
  169. @ApiParam(name = "articleContentClassify", value = "分类: 公司动态 媒体报道 参观交流", defaultValue = "公司动态") @RequestParam(value = "articleContentClassify") String articleContentClassify,
  170. @ApiParam(name = "pageNo", value = "第几页", defaultValue = "1") @RequestParam(value = "pageNo", required = false) Integer pageNo,
  171. @ApiParam(name = "pageSize", value = "分页大小", defaultValue = "10") @RequestParam(value = "pageSize", required = false) Integer pageSize){
  172. try {
  173. List<ZjxlArticleContent> articleContentList = articleContentService.findNewsList(id,articleContentClassify,3,pageNo-1,pageSize);
  174. return write(200,"查询成功","data", PageUtil.getPage(articleContentList,pageNo,pageSize,articleContentService.allNewsCount(articleContentClassify)));
  175. }catch (Exception e){
  176. e.printStackTrace();
  177. return write(-1,"查询失败");
  178. }
  179. }
  180. }