CmsNewsController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package com.lqkj.business.controller;
  2. import java.util.List;
  3. import com.lqkj.common.utils.StringUtils;
  4. import org.springframework.security.access.prepost.PreAuthorize;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.PutMapping;
  9. import org.springframework.web.bind.annotation.DeleteMapping;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import com.lqkj.common.annotation.Log;
  15. import com.lqkj.common.core.controller.BaseController;
  16. import com.lqkj.common.core.model.ResultUtil;
  17. import com.lqkj.common.enums.BusinessType;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiOperation;
  20. import com.lqkj.business.entity.CmsNews;
  21. import com.lqkj.business.service.CmsNewsService;
  22. import com.lqkj.common.utils.poi.ExcelUtil;
  23. import com.github.pagehelper.PageInfo;
  24. import org.springframework.web.util.HtmlUtils;
  25. /**
  26. * 信息管理Controller
  27. *
  28. * @author lqkj
  29. * @date 2023-02-16
  30. */
  31. @Api(tags = {"信息管理"})
  32. @RestController
  33. @RequestMapping("/business/cmsNews")
  34. public class CmsNewsController extends BaseController
  35. {
  36. @Autowired
  37. private CmsNewsService cmsNewsService;
  38. /**
  39. * 查询信息管理列表
  40. */
  41. @ApiOperation("查询信息列表")
  42. @PreAuthorize("@ss.hasPermi('business:cmsNews:list')")
  43. @GetMapping("/list")
  44. public ResultUtil list(CmsNews cmsNews)
  45. {
  46. startPage( cmsNews);
  47. PageInfo<CmsNews> pageInfo = new PageInfo<>(cmsNewsService.selectCmsNewsList(cmsNews));
  48. return ResultUtil.success(pageInfo);
  49. }
  50. @ApiOperation("按分类查询列表(前端用)")
  51. @GetMapping("/front/list")
  52. public ResultUtil listByCategory(CmsNews cmsNews){
  53. startPage( cmsNews);
  54. PageInfo<CmsNews> pageInfo = new PageInfo<>(cmsNewsService.selectCmsNewsList(cmsNews));
  55. return ResultUtil.success(pageInfo);
  56. }
  57. @ApiOperation("查看详情信息(前端用)")
  58. @GetMapping(value = "/front/{newsId}")
  59. public ResultUtil view(@PathVariable("newsId") String newsId)
  60. {
  61. cmsNewsService.plusViewCount(newsId);
  62. return ResultUtil.success(cmsNewsService.selectCmsNewsByNewsId(newsId));
  63. }
  64. @ApiOperation("根据分类ID查看详情信息(前端用)")
  65. @GetMapping(value = "/front/category/{categoryId}")
  66. public ResultUtil viewByCategoryId(@PathVariable("categoryId") Long categoryId)
  67. {
  68. return ResultUtil.success(cmsNewsService.selectCmsNewsByCategoryId(categoryId));
  69. }
  70. /**
  71. * 导出信息列表
  72. */
  73. @ApiOperation("导出信息列表")
  74. @PreAuthorize("@ss.hasPermi('business:cmsNews:export')")
  75. @Log(title = "信息管理", businessType = BusinessType.EXPORT)
  76. @GetMapping("/export")
  77. public ResultUtil export(CmsNews cmsNews)
  78. {
  79. List<CmsNews> list = cmsNewsService.selectCmsNewsList(cmsNews);
  80. ExcelUtil<CmsNews> util = new ExcelUtil<CmsNews>(CmsNews.class);
  81. return util.exportExcel(list, "信息数据");
  82. }
  83. /**
  84. * 获取信息详细信息
  85. */
  86. @ApiOperation("获取信息详细信息")
  87. @PreAuthorize("@ss.hasPermi('business:cmsNews:query')")
  88. @GetMapping(value = "/{newsId}")
  89. public ResultUtil getInfo(@PathVariable("newsId") String newsId)
  90. {
  91. return ResultUtil.success(cmsNewsService.selectCmsNewsByNewsId(newsId));
  92. }
  93. /**
  94. * 获取信息详细信息
  95. */
  96. @ApiOperation("根据分类编号获取信息详细信息")
  97. @PreAuthorize("@ss.hasPermi('business:cmsNews:query')")
  98. @GetMapping(value = "/getInfoByCategoryId/{categoryId}")
  99. public ResultUtil getInfoByCategoryId(@PathVariable("categoryId") Long categoryId)
  100. {
  101. return ResultUtil.success(cmsNewsService.selectCmsNewsByCategoryId(categoryId));
  102. }
  103. /**
  104. * 新增信息
  105. */
  106. @ApiOperation("新增信息")
  107. @PreAuthorize("@ss.hasPermi('business:cmsNews:add')")
  108. @Log(title = "信息管理", businessType = BusinessType.INSERT)
  109. @PostMapping
  110. public ResultUtil add(@RequestBody CmsNews cmsNews)
  111. {
  112. if(StringUtils.isNotEmpty(cmsNews.getContent())){
  113. cmsNews.setContent(HtmlUtils.htmlUnescape(cmsNews.getContent()));
  114. }
  115. cmsNews.setCreateBy(getNickName());
  116. return resultByRows(cmsNewsService.insertCmsNews(cmsNews));
  117. }
  118. /**
  119. * 修改信息
  120. */
  121. @ApiOperation("修改信息")
  122. @PreAuthorize("@ss.hasPermi('business:cmsNews:edit')")
  123. @Log(title = "信息管理", businessType = BusinessType.UPDATE)
  124. @PutMapping
  125. public ResultUtil edit(@RequestBody CmsNews cmsNews)
  126. {
  127. if(StringUtils.isNotEmpty(cmsNews.getContent())){
  128. cmsNews.setContent(HtmlUtils.htmlUnescape(cmsNews.getContent()));
  129. }
  130. cmsNews.setUpdateBy(getNickName());
  131. return resultByRows(cmsNewsService.updateCmsNews(cmsNews));
  132. }
  133. /**
  134. * 置顶操作
  135. */
  136. @ApiOperation("置顶状态")
  137. @PreAuthorize("@ss.hasPermi('business:cmsNews:edit')")
  138. @Log(title = "信息管理", businessType = BusinessType.UPDATE)
  139. @PutMapping("/updateTopStatus")
  140. public ResultUtil updateTopStatus(@RequestBody CmsNews cmsNews){
  141. return resultByRows(cmsNewsService.updateTopStatus(cmsNews));
  142. }
  143. /**
  144. * 删除信息
  145. */
  146. @ApiOperation("删除信息")
  147. @PreAuthorize("@ss.hasPermi('business:cmsNews:remove')")
  148. @Log(title = "信息管理", businessType = BusinessType.DELETE)
  149. @DeleteMapping("/{newsIds}")
  150. public ResultUtil remove(@PathVariable String[] newsIds)
  151. {
  152. return resultByRows(cmsNewsService.deleteCmsNewsByNewsIds(newsIds));
  153. }
  154. }