PoNewsController.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package com.ruoyi.web.controller.system;
  2. import com.ruoyi.common.annotation.Log;
  3. import com.ruoyi.common.constant.UserConstants;
  4. import com.ruoyi.common.core.controller.BaseController;
  5. import com.ruoyi.common.core.domain.AjaxResult;
  6. import com.ruoyi.common.core.domain.entity.SysUser;
  7. import com.ruoyi.common.core.page.TableDataInfo;
  8. import com.ruoyi.common.enums.BusinessType;
  9. import com.ruoyi.common.utils.poi.ExcelUtil;
  10. import com.ruoyi.system.domain.PoNews;
  11. import com.ruoyi.system.domain.PoUser;
  12. import com.ruoyi.system.service.IPoNewsService;
  13. import com.ruoyi.system.service.impl.PoUserServiceImpl;
  14. import io.swagger.annotations.ApiOperation;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.data.repository.query.Param;
  17. import org.springframework.security.access.prepost.PreAuthorize;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.multipart.MultipartFile;
  20. import javax.servlet.http.HttpServletResponse;
  21. import java.util.Date;
  22. import java.util.List;
  23. /**
  24. * 消息模块Controller
  25. *
  26. * @date 2023-01-15
  27. */
  28. @RestController
  29. @RequestMapping("/system/news")
  30. public class PoNewsController extends BaseController
  31. {
  32. @Autowired
  33. private IPoNewsService poNewsService;
  34. @Autowired
  35. private PoUserServiceImpl poUserService;
  36. /**
  37. * 导入用户手机号
  38. */
  39. @Log(title = "用户手机导入", businessType = BusinessType.IMPORT)
  40. @PreAuthorize("@ss.hasPermi('system:news:import')")
  41. @PostMapping("/importData")
  42. public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
  43. {
  44. ExcelUtil<PoNews> util = new ExcelUtil<PoNews>(PoNews.class);
  45. List<PoNews> phoneList = util.importExcel(file.getInputStream());
  46. String userName = getUsername();
  47. String message = poNewsService.importPhone(phoneList, updateSupport, userName);
  48. return success(message);
  49. }
  50. /**
  51. * 对list数据源将其里面的数据导入到excel表单
  52. * @param response
  53. */
  54. @PostMapping("/importTemplate")
  55. public void importTemplate(HttpServletResponse response)
  56. {
  57. ExcelUtil<PoNews> util = new ExcelUtil<PoNews>(PoNews.class);
  58. util.importTemplateExcel(response, "消息数据");
  59. }
  60. /**
  61. * 查看详情
  62. * 点击详情获取一个消息详细内容根据newsId
  63. */
  64. @ApiOperation("点击详情获取一个消息详细内容根据newsId")
  65. @Log(title = "获取一个消息详细内容")
  66. @PreAuthorize("@ss.hasPermi('system:news:querycontent')")
  67. @GetMapping("/content/{newsId}")
  68. public AjaxResult getContent(@PathVariable("newsId")String newsId){
  69. return success(poNewsService.selectContentByNewsId(newsId));
  70. }
  71. /**
  72. * 标题和时间搜索消息列表
  73. */
  74. @ApiOperation("标题和时间搜索消息列表")
  75. @Log(title = "标题和时间搜索")
  76. @PreAuthorize("@ss.hasPermi('system:news:querynews')")
  77. @GetMapping("/queryNews")
  78. public TableDataInfo list(@RequestParam(value="title",required = false)String title,
  79. @RequestParam(value="newsTimeStart",required = false)Date newsTimeStart,
  80. @RequestParam(value="newsTimeEnd",required = false) Date newsTimeEnd)
  81. {
  82. startPage();
  83. List<PoNews> list= poNewsService.selectListByTitleAndTime(title,newsTimeStart,newsTimeEnd);
  84. return getDataTable(list);
  85. }
  86. /**
  87. * 查询消息列表
  88. */
  89. @ApiOperation("查询消息列表")
  90. @Log(title = "分页查询消息列表")
  91. @PreAuthorize("@ss.hasPermi('system:news:list')")
  92. @GetMapping("/list")
  93. public TableDataInfo list(PoNews poNews)
  94. {
  95. startPage();
  96. List<PoNews> list = poNewsService.selectPoNewsList(poNews);
  97. return getDataTable(list);
  98. }
  99. /**
  100. * 导出消息列表
  101. */
  102. @ApiOperation("导出消息列表")
  103. @PreAuthorize("@ss.hasPermi('system:news:export')")
  104. @Log(title = "导出消息列表", businessType = BusinessType.EXPORT)
  105. @PostMapping("/export")
  106. public void export(HttpServletResponse response, PoNews poNews)
  107. {
  108. List<PoNews> list = poNewsService.selectPoNewsList(poNews);
  109. ExcelUtil<PoNews> util = new ExcelUtil<PoNews>(PoNews.class);
  110. util.exportExcel(response, list, "消息数据");
  111. }
  112. /**
  113. * 获取消息详细信息
  114. */
  115. @ApiOperation("获取消息详细内容")
  116. @Log(title = "获取所有消息详情")
  117. @PreAuthorize("@ss.hasPermi('system:news:query')")
  118. @GetMapping(value = "/{newsId}")
  119. public AjaxResult getInfo(@PathVariable("newsId") String newsId)
  120. {
  121. return success(poNewsService.selectPoNewsByNewsId(newsId));
  122. }
  123. /**
  124. * 新增消息
  125. */
  126. @ApiOperation("新增消息")
  127. @PreAuthorize("@ss.hasPermi('system:news:add')")
  128. @Log(title = "新增消息", businessType = BusinessType.INSERT)
  129. @PostMapping("/add")
  130. public AjaxResult add(@RequestBody @Param("poNews") PoNews poNews, @RequestBody @Param("poUser") PoUser poUser)
  131. {
  132. //判断当前用户是否有操作的权限
  133. poUserService.checkUserAllowed(poUser);
  134. if (UserConstants.NOT_UNIQUE.equals(poNewsService.checkPostNewsTitleUnique(poNews))){
  135. return AjaxResult.error("新增失败"+poNews.getNewsTitle()+"已经存在");
  136. }
  137. if(UserConstants.NOT_UNIQUE.equals(poNewsService.checkPostNewsImageUnique(poNews))){
  138. return AjaxResult.error("新增失败"+poNews.getImage()+"已经存在");
  139. }
  140. return toAjax(poNewsService.insertPoNews(poNews));
  141. }
  142. /**
  143. * 修改消息
  144. */
  145. @ApiOperation("修改消息")
  146. @PreAuthorize("@ss.hasPermi('system:news:edit')")
  147. @Log(title = "修改消息", businessType = BusinessType.UPDATE)
  148. @PutMapping("/edit")
  149. public AjaxResult edit(@RequestBody PoNews poNews ,@RequestBody PoUser poUser)
  150. {
  151. //校验是否有操作的权限
  152. poUserService.checkUserAllowed(poUser);
  153. //校验是否可以访问到数据
  154. poUserService.checkUserDataScope(poUser.getUserId());
  155. if (UserConstants.NOT_UNIQUE.equals(poNewsService.checkPostNewsTitleUnique(poNews))
  156. ){
  157. return AjaxResult.error("修改失败"+poNews.getNewsTitle()+"已经存在");
  158. }
  159. return toAjax(poNewsService.updatePoNews(poNews));
  160. }
  161. /**
  162. * 删除消息
  163. */
  164. @ApiOperation("删除消息")
  165. @PreAuthorize("@ss.hasPermi('system:news:remove')")
  166. @Log(title = "删除消息", businessType = BusinessType.DELETE)
  167. @DeleteMapping("/remove/{newsIds}")
  168. public AjaxResult remove(@PathVariable String[] newsIds)
  169. {
  170. if (!getUsername().equals("admin")){
  171. return AjaxResult.error("删除消息失败当前用户不是管理员");
  172. }
  173. return toAjax(poNewsService.deletePoNewsByNewsIds(newsIds));
  174. }
  175. }