ZjxlArticleContentController.java 14 KB

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