PushConfigController.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package com.jjt.push.controller;
  2. import com.jjt.common.annotation.Log;
  3. import com.jjt.common.core.controller.BaseController;
  4. import com.jjt.common.core.domain.AjaxResult;
  5. import com.jjt.common.core.page.TableDataInfo;
  6. import com.jjt.common.enums.BusinessType;
  7. import com.jjt.common.utils.poi.ExcelUtil;
  8. import com.jjt.push.domain.PushConfig;
  9. import com.jjt.push.service.IMailService;
  10. import com.jjt.push.service.IPushConfigService;
  11. import com.jjt.push.service.ISmsService;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import io.swagger.annotations.ApiParam;
  15. import org.springframework.security.access.prepost.PreAuthorize;
  16. import org.springframework.web.bind.annotation.*;
  17. import javax.annotation.Resource;
  18. import javax.servlet.http.HttpServletResponse;
  19. import java.util.List;
  20. /**
  21. * 推送配置Controller
  22. *
  23. * @author jjt
  24. * @date 2024-10-08
  25. */
  26. @Api(tags = "推送配置")
  27. @RestController
  28. @RequestMapping("/push/pushConfig")
  29. public class PushConfigController extends BaseController {
  30. @Resource
  31. private IPushConfigService pushConfigService;
  32. /**
  33. * 查询推送配置列表
  34. */
  35. @ApiOperation("查询推送配置列表")
  36. @PreAuthorize("@ss.hasPermi('push:pushConfig:list')")
  37. @GetMapping("/list")
  38. public TableDataInfo list(PushConfig pushConfig) {
  39. startPage();
  40. List<PushConfig> list = pushConfigService.selectPushConfigList(pushConfig);
  41. return getDataTable(list);
  42. }
  43. @ApiOperation("短信发送")
  44. @GetMapping("/sms")
  45. public AjaxResult sms(@ApiParam(value = "手机号") String phone, @ApiParam(value = "短信内容") String content) {
  46. try {
  47. pushConfigService.sendSms(phone, content);
  48. } catch (Exception e) {
  49. return AjaxResult.error(e.getMessage());
  50. }
  51. return AjaxResult.success();
  52. }
  53. @ApiOperation("邮件发送")
  54. @GetMapping("/mail")
  55. public AjaxResult mail(@ApiParam(value = "邮箱") String mail, @ApiParam(value = "邮件标题") String title, @ApiParam(value = "邮件内容") String content) {
  56. try {
  57. pushConfigService.sendMail(mail, title, content);
  58. } catch (Exception e) {
  59. return AjaxResult.error(e.getMessage());
  60. }
  61. return AjaxResult.success();
  62. }
  63. /**
  64. * 导出推送配置列表
  65. */
  66. @ApiOperation("导出推送配置列表")
  67. @PreAuthorize("@ss.hasPermi('push:pushConfig:export')")
  68. @Log(title = "推送配置", businessType = BusinessType.EXPORT)
  69. @PostMapping("/export")
  70. public void export(HttpServletResponse response, PushConfig pushConfig) {
  71. List<PushConfig> list = pushConfigService.selectPushConfigList(pushConfig);
  72. ExcelUtil<PushConfig> util = new ExcelUtil<PushConfig>(PushConfig.class);
  73. util.exportExcel(response, list, "推送配置数据");
  74. }
  75. /**
  76. * 获取推送配置详细信息
  77. */
  78. @ApiOperation("获取推送配置详细信息")
  79. @PreAuthorize("@ss.hasPermi('push:pushConfig:query')")
  80. @GetMapping(value = "/{pcId}")
  81. public AjaxResult getInfo(@PathVariable("pcId") Long pcId) {
  82. return success(pushConfigService.selectPushConfigByPcId(pcId));
  83. }
  84. /**
  85. * 新增推送配置
  86. */
  87. @ApiOperation("新增推送配置")
  88. @PreAuthorize("@ss.hasPermi('push:pushConfig:add')")
  89. @Log(title = "推送配置", businessType = BusinessType.INSERT)
  90. @PostMapping
  91. public AjaxResult add(@RequestBody PushConfig pushConfig) {
  92. return toAjax(pushConfigService.insertPushConfig(pushConfig));
  93. }
  94. /**
  95. * 修改推送配置
  96. */
  97. @ApiOperation("修改推送配置")
  98. @PreAuthorize("@ss.hasPermi('push:pushConfig:edit')")
  99. @Log(title = "推送配置", businessType = BusinessType.UPDATE)
  100. @PutMapping
  101. public AjaxResult edit(@RequestBody PushConfig pushConfig) {
  102. if (pushConfigService.selectPushConfigByPcId(1L) == null) {
  103. PushConfig config = new PushConfig();
  104. config.setPcId(1L);
  105. pushConfigService.insertPushConfig(config);
  106. }
  107. return toAjax(pushConfigService.updatePushConfig(pushConfig));
  108. }
  109. /**
  110. * 删除推送配置
  111. */
  112. @ApiOperation("删除推送配置")
  113. @PreAuthorize("@ss.hasPermi('push:pushConfig:remove')")
  114. @Log(title = "推送配置", businessType = BusinessType.DELETE)
  115. @DeleteMapping("/{pcIds}")
  116. public AjaxResult remove(@PathVariable Long[] pcIds) {
  117. return toAjax(pushConfigService.deletePushConfigByPcIds(pcIds));
  118. }
  119. }