package com.jjt.push.controller; import com.jjt.common.annotation.Log; import com.jjt.common.core.controller.BaseController; import com.jjt.common.core.domain.AjaxResult; import com.jjt.common.core.page.TableDataInfo; import com.jjt.common.enums.BusinessType; import com.jjt.common.utils.poi.ExcelUtil; import com.jjt.push.domain.PushConfig; import com.jjt.push.service.IMailService; import com.jjt.push.service.IPushConfigService; import com.jjt.push.service.ISmsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.List; /** * 推送配置Controller * * @author jjt * @date 2024-10-08 */ @Api(tags = "推送配置") @RestController @RequestMapping("/push/pushConfig") public class PushConfigController extends BaseController { @Resource private IPushConfigService pushConfigService; /** * 查询推送配置列表 */ @ApiOperation("查询推送配置列表") @PreAuthorize("@ss.hasPermi('push:pushConfig:list')") @GetMapping("/list") public TableDataInfo list(PushConfig pushConfig) { startPage(); List list = pushConfigService.selectPushConfigList(pushConfig); return getDataTable(list); } @ApiOperation("短信发送") @GetMapping("/sms") public AjaxResult sms(@ApiParam(value = "手机号") String phone, @ApiParam(value = "短信内容") String content) { try { pushConfigService.sendSms(phone, content); } catch (Exception e) { return AjaxResult.error(e.getMessage()); } return AjaxResult.success(); } @ApiOperation("邮件发送") @GetMapping("/mail") public AjaxResult mail(@ApiParam(value = "邮箱") String mail, @ApiParam(value = "邮件标题") String title, @ApiParam(value = "邮件内容") String content) { try { pushConfigService.sendMail(mail, title, content); } catch (Exception e) { return AjaxResult.error(e.getMessage()); } return AjaxResult.success(); } /** * 导出推送配置列表 */ @ApiOperation("导出推送配置列表") @PreAuthorize("@ss.hasPermi('push:pushConfig:export')") @Log(title = "推送配置", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, PushConfig pushConfig) { List list = pushConfigService.selectPushConfigList(pushConfig); ExcelUtil util = new ExcelUtil(PushConfig.class); util.exportExcel(response, list, "推送配置数据"); } /** * 获取推送配置详细信息 */ @ApiOperation("获取推送配置详细信息") @PreAuthorize("@ss.hasPermi('push:pushConfig:query')") @GetMapping(value = "/{pcId}") public AjaxResult getInfo(@PathVariable("pcId") Long pcId) { return success(pushConfigService.selectPushConfigByPcId(pcId)); } /** * 新增推送配置 */ @ApiOperation("新增推送配置") @PreAuthorize("@ss.hasPermi('push:pushConfig:add')") @Log(title = "推送配置", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody PushConfig pushConfig) { return toAjax(pushConfigService.insertPushConfig(pushConfig)); } /** * 修改推送配置 */ @ApiOperation("修改推送配置") @PreAuthorize("@ss.hasPermi('push:pushConfig:edit')") @Log(title = "推送配置", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody PushConfig pushConfig) { if (pushConfigService.selectPushConfigByPcId(1L) == null) { PushConfig config = new PushConfig(); config.setPcId(1L); pushConfigService.insertPushConfig(config); } return toAjax(pushConfigService.updatePushConfig(pushConfig)); } /** * 删除推送配置 */ @ApiOperation("删除推送配置") @PreAuthorize("@ss.hasPermi('push:pushConfig:remove')") @Log(title = "推送配置", businessType = BusinessType.DELETE) @DeleteMapping("/{pcIds}") public AjaxResult remove(@PathVariable Long[] pcIds) { return toAjax(pushConfigService.deletePushConfigByPcIds(pcIds)); } }