CmsNewsController.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. if(StringUtils.isNotEmpty(cmsNews.getTitle())){
  116. cmsNews.setTitle(HtmlUtils.htmlUnescape(cmsNews.getTitle()));
  117. }
  118. cmsNews.setCreateBy(getNickName());
  119. return resultByRows(cmsNewsService.insertCmsNews(cmsNews));
  120. }
  121. /**
  122. * 修改信息
  123. */
  124. @ApiOperation("修改信息")
  125. @PreAuthorize("@ss.hasPermi('business:cmsNews:edit')")
  126. @Log(title = "信息管理", businessType = BusinessType.UPDATE)
  127. @PutMapping
  128. public ResultUtil edit(@RequestBody CmsNews cmsNews)
  129. {
  130. if(StringUtils.isNotEmpty(cmsNews.getContent())){
  131. cmsNews.setContent(HtmlUtils.htmlUnescape(cmsNews.getContent()));
  132. }
  133. if(StringUtils.isNotEmpty(cmsNews.getTitle())){
  134. cmsNews.setTitle(HtmlUtils.htmlUnescape(cmsNews.getTitle()));
  135. }
  136. cmsNews.setUpdateBy(getNickName());
  137. return resultByRows(cmsNewsService.updateCmsNews(cmsNews));
  138. }
  139. /**
  140. * 置顶操作
  141. */
  142. @ApiOperation("置顶状态")
  143. @PreAuthorize("@ss.hasPermi('business:cmsNews:edit')")
  144. @Log(title = "信息管理", businessType = BusinessType.UPDATE)
  145. @PutMapping("/updateTopStatus")
  146. public ResultUtil updateTopStatus(@RequestBody CmsNews cmsNews){
  147. return resultByRows(cmsNewsService.updateTopStatus(cmsNews));
  148. }
  149. /**
  150. * 轮播操作
  151. */
  152. @ApiOperation("轮播状态")
  153. @PreAuthorize("@ss.hasPermi('business:cmsNews:edit')")
  154. @Log(title = "信息管理", businessType = BusinessType.UPDATE)
  155. @PutMapping("/updateCarouselStatus")
  156. public ResultUtil updateCarouselStatus(@RequestBody CmsNews cmsNews){
  157. return resultByRows(cmsNewsService.updateCarouselStatus(cmsNews));
  158. }
  159. /**
  160. * 删除信息
  161. */
  162. @ApiOperation("删除信息")
  163. @PreAuthorize("@ss.hasPermi('business:cmsNews:remove')")
  164. @Log(title = "信息管理", businessType = BusinessType.DELETE)
  165. @DeleteMapping("/{newsIds}")
  166. public ResultUtil remove(@PathVariable String[] newsIds)
  167. {
  168. return resultByRows(cmsNewsService.deleteCmsNewsByNewsIds(newsIds));
  169. }
  170. }