第一次提交
This commit is contained in:
		| @@ -0,0 +1,129 @@ | ||||
| package com.fastbee.notify.controller; | ||||
|  | ||||
| import com.fastbee.common.annotation.Log; | ||||
| import com.fastbee.common.core.controller.BaseController; | ||||
| import com.fastbee.common.core.domain.AjaxResult; | ||||
| import com.fastbee.common.core.page.TableDataInfo; | ||||
| import com.fastbee.common.enums.BusinessType; | ||||
| import com.fastbee.common.utils.poi.ExcelUtil; | ||||
| import com.fastbee.notify.domain.NotifyChannel; | ||||
| import com.fastbee.notify.service.INotifyChannelService; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| 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 kerwincui | ||||
|  * @date 2023-12-01 | ||||
|  */ | ||||
| @RestController | ||||
| @RequestMapping("/notify/channel") | ||||
| @Api(tags = "通知渠道") | ||||
| public class NotifyChannelController extends BaseController | ||||
| { | ||||
|     @Resource | ||||
|     private INotifyChannelService notifyChannelService; | ||||
|  | ||||
|     /** | ||||
|      * 查询通知渠道列表 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:channel:list')") | ||||
|     @GetMapping("/list") | ||||
|     @ApiOperation(value = "查询通知渠道列表") | ||||
|     public TableDataInfo list(NotifyChannel notifyChannel) | ||||
|     { | ||||
|         startPage(); | ||||
|         List<NotifyChannel> list = notifyChannelService.selectNotifyChannelList(notifyChannel); | ||||
|         return getDataTable(list); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 导出通知渠道列表 | ||||
|      */ | ||||
|     @ApiOperation(value = "导出通知渠道列表") | ||||
|     @PreAuthorize("@ss.hasPermi('notify:channel:export')") | ||||
|     @Log(title = "通知渠道", businessType = BusinessType.EXPORT) | ||||
|     @PostMapping("/export") | ||||
|     public void export(HttpServletResponse response, NotifyChannel notifyChannel) | ||||
|     { | ||||
|         List<NotifyChannel> list = notifyChannelService.selectNotifyChannelList(notifyChannel); | ||||
|         ExcelUtil<NotifyChannel> util = new ExcelUtil<NotifyChannel>(NotifyChannel.class); | ||||
|         util.exportExcel(response, list, "通知渠道数据"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取通知渠道详细信息 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:channel:query')") | ||||
|     @GetMapping(value = "/{id}") | ||||
|     @ApiOperation(value = "获取通知渠道详细信息") | ||||
|     public AjaxResult getInfo(@PathVariable("id") Long id) | ||||
|     { | ||||
|         return success(notifyChannelService.selectNotifyChannelById(id)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 新增通知渠道 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:channel:add')") | ||||
|     @Log(title = "通知渠道", businessType = BusinessType.INSERT) | ||||
|     @PostMapping | ||||
|     @ApiOperation(value = "新增通知渠道") | ||||
|     public AjaxResult add(@RequestBody NotifyChannel notifyChannel) | ||||
|     { | ||||
|         return toAjax(notifyChannelService.insertNotifyChannel(notifyChannel)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改通知渠道 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:channel:edit')") | ||||
|     @Log(title = "通知渠道", businessType = BusinessType.UPDATE) | ||||
|     @PutMapping | ||||
|     @ApiOperation(value = "修改通知渠道") | ||||
|     public AjaxResult edit(@RequestBody NotifyChannel notifyChannel) | ||||
|     { | ||||
|         return toAjax(notifyChannelService.updateNotifyChannel(notifyChannel)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除通知渠道 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:channel:remove')") | ||||
|     @Log(title = "通知渠道", businessType = BusinessType.DELETE) | ||||
| 	@DeleteMapping("/{ids}") | ||||
|     @ApiOperation(value = "删除通知渠道") | ||||
|     public AjaxResult remove(@PathVariable Long[] ids) | ||||
|     { | ||||
|         return toAjax(notifyChannelService.deleteNotifyChannelByIds(ids)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询通知渠道和服务商 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @GetMapping("/listChannel") | ||||
|     @ApiOperation(value = "查询通知渠道和服务商") | ||||
|     public AjaxResult listChannel() { | ||||
|         return AjaxResult.success(notifyChannelService.listChannel()); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取消息通知渠道参数信息 | ||||
|      * @param channelType 渠道类型 | ||||
|      * @param: provider 服务商 | ||||
|      * @return com.fastbee.common.core.domain.AjaxResult | ||||
|      */ | ||||
|     @GetMapping(value = "/getConfigContent") | ||||
|     @ApiOperation("获取渠道参数配置") | ||||
|     public AjaxResult msgParams(String channelType, String provider) { | ||||
|         return success(notifyChannelService.getConfigContent(channelType, provider)); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,105 @@ | ||||
| package com.fastbee.notify.controller; | ||||
|  | ||||
| import com.fastbee.common.annotation.Log; | ||||
| import com.fastbee.common.core.controller.BaseController; | ||||
| import com.fastbee.common.core.domain.AjaxResult; | ||||
| import com.fastbee.common.core.page.TableDataInfo; | ||||
| import com.fastbee.common.enums.BusinessType; | ||||
| import com.fastbee.common.utils.poi.ExcelUtil; | ||||
| import com.fastbee.notify.domain.NotifyLog; | ||||
| import com.fastbee.notify.service.INotifyLogService; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| 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 fastbee | ||||
|  * @date 2023-12-16 | ||||
|  */ | ||||
| @Api(tags = "通知日志") | ||||
| @RestController | ||||
| @RequestMapping("/notify/log") | ||||
| public class NotifyLogController extends BaseController | ||||
| { | ||||
|     @Resource | ||||
|     private INotifyLogService notifyLogService; | ||||
|  | ||||
|     /** | ||||
|      * 查询通知日志列表 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:log:list')") | ||||
|     @ApiOperation(value = "查询通知日志列表") | ||||
|     @GetMapping("/list") | ||||
|     public TableDataInfo list(NotifyLog notifyLog) | ||||
|     { | ||||
|         startPage(); | ||||
|         List<NotifyLog> list = notifyLogService.selectNotifyLogList(notifyLog); | ||||
|         return getDataTable(list); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 导出通知日志列表 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:log:export')") | ||||
|     @Log(title = "通知日志", businessType = BusinessType.EXPORT) | ||||
|     @ApiOperation(value = "导出通知日志列表") | ||||
|     @PostMapping("/export") | ||||
|     public void export(HttpServletResponse response, NotifyLog notifyLog) | ||||
|     { | ||||
|         List<NotifyLog> list = notifyLogService.selectNotifyLogList(notifyLog); | ||||
|         ExcelUtil<NotifyLog> util = new ExcelUtil<NotifyLog>(NotifyLog.class); | ||||
|         util.exportExcel(response, list, "通知日志数据"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取通知日志详细信息 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:log:query')") | ||||
|     @ApiOperation(value = "获取通知日志详细信息") | ||||
|     @GetMapping(value = "/{id}") | ||||
|     public AjaxResult getInfo(@PathVariable("id") Long id) | ||||
|     { | ||||
|         return success(notifyLogService.selectNotifyLogById(id)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 新增通知日志 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:log:add')") | ||||
|     @Log(title = "通知日志", businessType = BusinessType.INSERT) | ||||
|     @PostMapping | ||||
|     public AjaxResult add(@RequestBody NotifyLog notifyLog) | ||||
|     { | ||||
|         return toAjax(notifyLogService.insertNotifyLog(notifyLog)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改通知日志 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:log:edit')") | ||||
|     @Log(title = "通知日志", businessType = BusinessType.UPDATE) | ||||
|     @PutMapping | ||||
|     public AjaxResult edit(@RequestBody NotifyLog notifyLog) | ||||
|     { | ||||
|         return toAjax(notifyLogService.updateNotifyLog(notifyLog)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除通知日志 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:log:remove')") | ||||
|     @Log(title = "通知日志", businessType = BusinessType.DELETE) | ||||
|     @ApiOperation(value = "批量删除通知日志") | ||||
| 	@DeleteMapping("/{ids}") | ||||
|     public AjaxResult remove(@PathVariable Long[] ids) | ||||
|     { | ||||
|         return toAjax(notifyLogService.deleteNotifyLogByIds(ids)); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,187 @@ | ||||
| package com.fastbee.notify.controller; | ||||
|  | ||||
| import com.alibaba.fastjson2.JSON; | ||||
| import com.alibaba.fastjson2.JSONObject; | ||||
| import com.fastbee.common.annotation.Log; | ||||
| import com.fastbee.common.core.controller.BaseController; | ||||
| import com.fastbee.common.core.domain.AjaxResult; | ||||
| import com.fastbee.common.core.domain.entity.SysUser; | ||||
| import com.fastbee.common.core.page.TableDataInfo; | ||||
| import com.fastbee.common.enums.BusinessType; | ||||
| import com.fastbee.common.enums.NotifyChannelProviderEnum; | ||||
| import com.fastbee.common.utils.MessageUtils; | ||||
| import com.fastbee.common.utils.poi.ExcelUtil; | ||||
| import com.fastbee.notify.domain.NotifyTemplate; | ||||
| import com.fastbee.notify.service.INotifyTemplateService; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | ||||
| import org.apache.commons.collections4.MapUtils; | ||||
| 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.LinkedHashMap; | ||||
| import java.util.List; | ||||
| import java.util.Objects; | ||||
|  | ||||
| /** | ||||
|  * 通知模版Controller | ||||
|  * | ||||
|  * @author kerwincui | ||||
|  * @date 2023-12-01 | ||||
|  */ | ||||
| @RestController | ||||
| @RequestMapping("/notify/template") | ||||
| @Api(tags = "通知模板配置") | ||||
| public class NotifyTemplateController extends BaseController { | ||||
|  | ||||
|     @Resource | ||||
|     private INotifyTemplateService notifyTemplateService; | ||||
|  | ||||
|     /** | ||||
|      * 查询通知模版列表 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:template:list')") | ||||
|     @GetMapping("/list") | ||||
|     @ApiOperation("查询通知模版列表") | ||||
|     public TableDataInfo list(NotifyTemplate notifyTemplate) { | ||||
|         startPage(); | ||||
|         List<NotifyTemplate> list = notifyTemplateService.selectNotifyTemplateList(notifyTemplate); | ||||
|         return getDataTable(list); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 导出通知模版列表 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:template:export')") | ||||
|     @Log(title = "通知模版", businessType = BusinessType.EXPORT) | ||||
|     @PostMapping("/export") | ||||
|     @ApiOperation("导出通知模版列表") | ||||
|     public void export(HttpServletResponse response, NotifyTemplate notifyTemplate) { | ||||
|         List<NotifyTemplate> list = notifyTemplateService.selectNotifyTemplateList(notifyTemplate); | ||||
|         ExcelUtil<NotifyTemplate> util = new ExcelUtil<NotifyTemplate>(NotifyTemplate.class); | ||||
|         util.exportExcel(response, list, "通知模版数据"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取通知模版详细信息 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:template:query')") | ||||
|     @GetMapping(value = "/{id}") | ||||
|     @ApiOperation("获取通知模版详细信息") | ||||
|     public AjaxResult getInfo(@PathVariable("id") Long id) { | ||||
|         return success(notifyTemplateService.selectNotifyTemplateById(id)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 新增通知模版 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:template:add')") | ||||
|     @Log(title = "通知模版", businessType = BusinessType.INSERT) | ||||
|     @PostMapping | ||||
|     @ApiOperation("新增通知模版") | ||||
|     public AjaxResult add(@RequestBody NotifyTemplate notifyTemplate) { | ||||
|         return notifyTemplateService.insertNotifyTemplate(notifyTemplate); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改通知模版 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:template:edit')") | ||||
|     @Log(title = "通知模版", businessType = BusinessType.UPDATE) | ||||
|     @PutMapping | ||||
|     @ApiOperation("修改通知模版") | ||||
|     public AjaxResult edit(@RequestBody NotifyTemplate notifyTemplate) { | ||||
|         return notifyTemplateService.updateNotifyTemplate(notifyTemplate); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除通知模版 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:template:remove')") | ||||
|     @Log(title = "通知模版", businessType = BusinessType.DELETE) | ||||
|     @DeleteMapping("/{ids}") | ||||
|     @ApiOperation("删除通知模版") | ||||
|     public AjaxResult remove(@PathVariable Long[] ids) { | ||||
|         return toAjax(notifyTemplateService.deleteNotifyTemplateByIds(ids)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取消息通知模版参数信息 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:template:query')") | ||||
|     @GetMapping(value = "/msgParams") | ||||
|     @ApiOperation("获取模板参数配置") | ||||
|     public AjaxResult msgParams(Long channelId, String msgType) { | ||||
|         return success(notifyTemplateService.getNotifyMsgParams(channelId, msgType)); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * 获取通知模版详细信息 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:template:query')") | ||||
|     @GetMapping(value = "/getUsable") | ||||
|     @ApiOperation("获取同一业务的模板是否有可用的") | ||||
|     public AjaxResult getUsable(NotifyTemplate notifyTemplate) { | ||||
|         return success(notifyTemplateService.countNormalTemplate(notifyTemplate)); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * 修改通知模版-更新选择的为可用,其他为不可用 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:template:edit')") | ||||
|     @PostMapping("/updateState") | ||||
|     @ApiOperation("修改模版启用状态") | ||||
|     public AjaxResult updateState(@RequestBody NotifyTemplate notifyTemplate) { | ||||
|         notifyTemplateService.updateTemplateStatus(notifyTemplate); | ||||
|         return AjaxResult.success(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取消息通知模版参数变量 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('notify:template:query')") | ||||
|     @GetMapping(value = "/listVariables") | ||||
|     @ApiOperation("获取模板内容变量") | ||||
|     public AjaxResult listVariables(Long id, String channelType, String provider) { | ||||
|         NotifyTemplate notifyTemplate = notifyTemplateService.selectNotifyTemplateById(id); | ||||
|         if (Objects.isNull(notifyTemplate)) { | ||||
|             return success(); | ||||
|         } | ||||
|         String content = JSONObject.parseObject(notifyTemplate.getMsgParams()).get("content").toString(); | ||||
|         Object account = JSONObject.parseObject(notifyTemplate.getMsgParams()).get("sendAccount"); | ||||
|         NotifyChannelProviderEnum notifyChannelProviderEnum = NotifyChannelProviderEnum.getByChannelTypeAndProvider(channelType, provider); | ||||
|         List<String> variables = notifyTemplateService.listVariables(content, notifyChannelProviderEnum); | ||||
|         LinkedHashMap<String, String> map = new LinkedHashMap<>(); | ||||
|         for (String variable : variables) { | ||||
|             map.put(variable, ""); | ||||
|         } | ||||
|         JSONObject resultData = new JSONObject(); | ||||
|         // 企业微信、钉钉机器人没有发送账号 | ||||
|         if (NotifyChannelProviderEnum.WECHAT_WECOM_ROBOT == notifyChannelProviderEnum || | ||||
|                 NotifyChannelProviderEnum.DING_TALK_GROUP_ROBOT == notifyChannelProviderEnum) { | ||||
|             if (MapUtils.isEmpty(map)) { | ||||
|                 return AjaxResult.success(MessageUtils.message("operate.success"), ""); | ||||
|             } else { | ||||
|                 resultData.put("variables", JSON.toJSONString(map)); | ||||
|                 return success(resultData); | ||||
|             } | ||||
|         } | ||||
|         resultData.put("sendAccount", Objects.isNull(account) ? "" : account.toString()); | ||||
|         resultData.put("variables", MapUtils.isNotEmpty(map) ? JSON.toJSONString(map) : ""); | ||||
|         return success(resultData); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取告警微信小程序模板id | ||||
|      */ | ||||
|     @GetMapping(value = "/getAlertWechatMini") | ||||
|     @ApiOperation("获取告警微信小程序模板id") | ||||
|     public AjaxResult getAlertWechatMini() { | ||||
|         return success(notifyTemplateService.getAlertWechatMini()); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,50 @@ | ||||
| package com.fastbee.notify.domain; | ||||
|  | ||||
| import com.fastbee.common.annotation.Excel; | ||||
| import com.fastbee.common.core.domain.BaseEntity; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import lombok.experimental.Accessors; | ||||
|  | ||||
| /** | ||||
|  * 通知渠道对象 notify_channel | ||||
|  * | ||||
|  * @author kerwincui | ||||
|  * @date 2023-12-01 | ||||
|  */ | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @Data | ||||
| @Accessors(chain = true) | ||||
| public class NotifyChannel extends BaseEntity | ||||
| { | ||||
|     private static final long serialVersionUID = 1L; | ||||
|  | ||||
|     /** 编号 */ | ||||
|     private Long id; | ||||
|  | ||||
|     /** 通知名称 */ | ||||
|     @Excel(name = "通知名称") | ||||
|     private String name; | ||||
|  | ||||
|     /** 发送渠道类型 */ | ||||
|     @Excel(name = "发送渠道类型") | ||||
|     private String channelType; | ||||
|  | ||||
|     /** 服务商 */ | ||||
|     @Excel(name = "服务商") | ||||
|     private String provider; | ||||
|  | ||||
|     /** 配置内容 */ | ||||
|     @Excel(name = "配置内容") | ||||
|     private String configContent; | ||||
|  | ||||
|     /** 租户id */ | ||||
|     private Long tenantId; | ||||
|  | ||||
|     /** 租户名称 */ | ||||
|     private String tenantName; | ||||
|  | ||||
|     /** 逻辑删除标识 */ | ||||
|     private Integer delFlag; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,67 @@ | ||||
| package com.fastbee.notify.domain; | ||||
|  | ||||
| import com.fastbee.common.annotation.Excel; | ||||
| import com.fastbee.common.core.domain.BaseEntity; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import lombok.experimental.Accessors; | ||||
|  | ||||
| /** | ||||
|  * 通知日志对象 notify_log | ||||
|  *  | ||||
|  * @author fastbee | ||||
|  * @date 2023-12-16 | ||||
|  */ | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @Data | ||||
| @Accessors(chain = true) | ||||
| public class NotifyLog extends BaseEntity | ||||
| { | ||||
|     private static final long serialVersionUID = 1L; | ||||
|  | ||||
|     /** 编号 */ | ||||
|     private Long id; | ||||
|  | ||||
|     /** 通知模版编号 */ | ||||
|     @Excel(name = "通知模版编号") | ||||
|     private Long notifyTemplateId; | ||||
|  | ||||
|     /** 渠道编号 */ | ||||
|     @Excel(name = "渠道编号") | ||||
|     private Long channelId; | ||||
|  | ||||
|     /** 消息内容 */ | ||||
|     @Excel(name = "消息内容") | ||||
|     private String msgContent; | ||||
|  | ||||
|     /** 发送账号 */ | ||||
|     @Excel(name = "发送账号") | ||||
|     private String sendAccount; | ||||
|  | ||||
|     /** 发送状态 */ | ||||
|     @Excel(name = "发送状态") | ||||
|     private Integer sendStatus; | ||||
|  | ||||
|     /** 返回内容 */ | ||||
|     @Excel(name = "返回内容") | ||||
|     private String resultContent; | ||||
|  | ||||
|     /** 逻辑删除标识 */ | ||||
|     private Integer delFlag; | ||||
|  | ||||
|     /** 渠道名称 */ | ||||
|     private String channelName; | ||||
|  | ||||
|     /** 模板名称 */ | ||||
|     private String templateName; | ||||
|  | ||||
|     /** 租户id */ | ||||
|     private Long tenantId; | ||||
|  | ||||
|     /** 租户名称 */ | ||||
|     private String tenantName; | ||||
|     /** 业务编码 */ | ||||
|     @Excel(name = "业务编码") | ||||
|     private String serviceCode; | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,65 @@ | ||||
| package com.fastbee.notify.domain; | ||||
|  | ||||
| import com.fastbee.common.annotation.Excel; | ||||
| import com.fastbee.common.core.domain.BaseEntity; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| import lombok.Data; | ||||
| import lombok.EqualsAndHashCode; | ||||
| import lombok.experimental.Accessors; | ||||
|  | ||||
| /** | ||||
|  * 通知模版对象 notify_template | ||||
|  * | ||||
|  * @author kerwincui | ||||
|  * @date 2023-12-01 | ||||
|  */ | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @Data | ||||
| @Accessors(chain = true) | ||||
| public class NotifyTemplate extends BaseEntity | ||||
| { | ||||
|     private static final long serialVersionUID = 1L; | ||||
|  | ||||
|     /** 编号 */ | ||||
|     private Long id; | ||||
|  | ||||
|     /** 模版名称 */ | ||||
|     @Excel(name = "模版名称") | ||||
|     private String name; | ||||
|  | ||||
|     /** 通知渠道 */ | ||||
|     @Excel(name = "通知渠道") | ||||
|     private Long channelId; | ||||
|  | ||||
|     /** 业务编码 */ | ||||
|     @Excel(name = "业务编码") | ||||
|     private String serviceCode; | ||||
|  | ||||
|     @ApiModelProperty("模版配置参数") | ||||
|     private String msgParams; | ||||
|  | ||||
|     /** 发送账号 */ | ||||
|     @Excel(name = "是否启用,0-否 1-是") | ||||
|     private Integer status; | ||||
|  | ||||
|     /** 逻辑删除标识 */ | ||||
|     private Integer delFlag; | ||||
|  | ||||
|     private String channelName; | ||||
|  | ||||
|     /** 发送渠道类型 */ | ||||
|     @Excel(name = "发送渠道类型") | ||||
|     private String channelType; | ||||
|  | ||||
|     /** 服务商 */ | ||||
|     @Excel(name = "服务商") | ||||
|     private String provider; | ||||
|  | ||||
|     /** 租户id */ | ||||
|     private Long tenantId; | ||||
|  | ||||
|     /** 租户名称 */ | ||||
|     private String tenantName; | ||||
|  | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,70 @@ | ||||
| package com.fastbee.notify.mapper; | ||||
|  | ||||
| import com.fastbee.notify.domain.NotifyChannel; | ||||
| import org.apache.ibatis.annotations.Param; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 通知渠道Mapper接口 | ||||
|  * | ||||
|  * @author kerwincui | ||||
|  * @date 2023-12-01 | ||||
|  */ | ||||
| public interface NotifyChannelMapper | ||||
| { | ||||
|     /** | ||||
|      * 查询通知渠道 | ||||
|      * | ||||
|      * @param id 通知渠道主键 | ||||
|      * @return 通知渠道 | ||||
|      */ | ||||
|     public NotifyChannel selectNotifyChannelById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询通知渠道列表 | ||||
|      * | ||||
|      * @param notifyChannel 通知渠道 | ||||
|      * @return 通知渠道集合 | ||||
|      */ | ||||
|     public List<NotifyChannel> selectNotifyChannelList(NotifyChannel notifyChannel); | ||||
|  | ||||
|     /** | ||||
|      * 新增通知渠道 | ||||
|      * | ||||
|      * @param notifyChannel 通知渠道 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int insertNotifyChannel(NotifyChannel notifyChannel); | ||||
|  | ||||
|     /** | ||||
|      * 修改通知渠道 | ||||
|      * | ||||
|      * @param notifyChannel 通知渠道 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int updateNotifyChannel(NotifyChannel notifyChannel); | ||||
|  | ||||
|     /** | ||||
|      * 删除通知渠道 | ||||
|      * | ||||
|      * @param id 通知渠道主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyChannelById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 批量删除通知渠道 | ||||
|      * | ||||
|      * @param ids 需要删除的数据主键集合 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyChannelByIds(Long[] ids); | ||||
|  | ||||
|     /** | ||||
|      * 批量查询通知渠道 | ||||
|      * @param idList  主键id集合 | ||||
|      * @return java.util.List<com.fastbee.notify.domain.NotifyChannel> | ||||
|      */ | ||||
|     List<NotifyChannel> selectNotifyChannelByIds(@Param("idList") List<Long> idList); | ||||
| } | ||||
| @@ -0,0 +1,62 @@ | ||||
| package com.fastbee.notify.mapper; | ||||
|  | ||||
| import com.fastbee.notify.domain.NotifyLog; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 通知日志Mapper接口 | ||||
|  *  | ||||
|  * @author fastbee | ||||
|  * @date 2023-12-16 | ||||
|  */ | ||||
| public interface NotifyLogMapper  | ||||
| { | ||||
|     /** | ||||
|      * 查询通知日志 | ||||
|      *  | ||||
|      * @param id 通知日志主键 | ||||
|      * @return 通知日志 | ||||
|      */ | ||||
|     public NotifyLog selectNotifyLogById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询通知日志列表 | ||||
|      *  | ||||
|      * @param notifyLog 通知日志 | ||||
|      * @return 通知日志集合 | ||||
|      */ | ||||
|     public List<NotifyLog> selectNotifyLogList(NotifyLog notifyLog); | ||||
|  | ||||
|     /** | ||||
|      * 新增通知日志 | ||||
|      *  | ||||
|      * @param notifyLog 通知日志 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int insertNotifyLog(NotifyLog notifyLog); | ||||
|  | ||||
|     /** | ||||
|      * 修改通知日志 | ||||
|      *  | ||||
|      * @param notifyLog 通知日志 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int updateNotifyLog(NotifyLog notifyLog); | ||||
|  | ||||
|     /** | ||||
|      * 删除通知日志 | ||||
|      *  | ||||
|      * @param id 通知日志主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyLogById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 批量删除通知日志 | ||||
|      *  | ||||
|      * @param ids 需要删除的数据主键集合 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyLogByIds(Long[] ids); | ||||
| } | ||||
| @@ -0,0 +1,112 @@ | ||||
| package com.fastbee.notify.mapper; | ||||
|  | ||||
| import com.fastbee.notify.domain.NotifyTemplate; | ||||
| import org.apache.ibatis.annotations.Param; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 通知模版Mapper接口 | ||||
|  * | ||||
|  * @author kerwincui | ||||
|  * @date 2023-12-01 | ||||
|  */ | ||||
| public interface NotifyTemplateMapper | ||||
| { | ||||
|     /** | ||||
|      * 查询通知模版 | ||||
|      * | ||||
|      * @param id 通知模版主键 | ||||
|      * @return 通知模版 | ||||
|      */ | ||||
|     public NotifyTemplate selectNotifyTemplateById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询通知模版列表 | ||||
|      * | ||||
|      * @param notifyTemplate 通知模版 | ||||
|      * @return 通知模版集合 | ||||
|      */ | ||||
|     public List<NotifyTemplate> selectNotifyTemplateList(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * 查询同一业务已启用的模板 | ||||
|      * @param notifyTemplate | ||||
|      * @return | ||||
|      */ | ||||
|     public Integer selectEnableNotifyTemplateCount(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * 新增通知模版 | ||||
|      * | ||||
|      * @param notifyTemplate 通知模版 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int insertNotifyTemplate(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * 修改通知模版 | ||||
|      * | ||||
|      * @param notifyTemplate 通知模版 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int updateNotifyTemplate(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * 批量更新渠道状态 | ||||
|      * @param ids ids | ||||
|      * @return | ||||
|      */ | ||||
|     public int updateNotifyBatch(@Param("ids") List<Long> ids, @Param("status") Integer status); | ||||
|  | ||||
|     /** | ||||
|      * 删除通知模版 | ||||
|      * | ||||
|      * @param id 通知模版主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyTemplateById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 批量删除通知模版 | ||||
|      * | ||||
|      * @param ids 需要删除的数据主键集合 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyTemplateByIds(Long[] ids); | ||||
|  | ||||
|     /** | ||||
|      * 根据业务编码查询启用模板 | ||||
|      * @param notifyTemplate 通知模板 | ||||
|      * @return com.fastbee.notify.domain.NotifyTemplate | ||||
|      */ | ||||
|     NotifyTemplate selectOnlyEnable(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * @description: 批量删除通知模板 | ||||
|      * @param: ids 渠道id数组 | ||||
|      * @return: void | ||||
|      */ | ||||
|     void deleteNotifyTemplateByChannelIds(Long[] channelIds); | ||||
|  | ||||
|     /** | ||||
|      * @description: 查询通知模板 | ||||
|      * @param: templateIdList | ||||
|      * @return: java.util.List<com.fastbee.notify.domain.NotifyTemplate> | ||||
|      */ | ||||
|     List<NotifyTemplate> selectNotifyTemplateByIds(@Param("idList") List<Long> idList); | ||||
|  | ||||
|     /** | ||||
|      * 根据渠道id查询模板 | ||||
|      * @param channelId 渠道id | ||||
|      * @return java.util.List<com.fastbee.notify.domain.NotifyTemplate> | ||||
|      */ | ||||
|     List<NotifyTemplate> selectNotifyTemplateByChannelId(Long channelId); | ||||
|  | ||||
|     /** | ||||
|      * 根据场景ID批量删除告警场景 | ||||
|      * @param notifyTemplateIds | ||||
|      * @return | ||||
|      */ | ||||
|     public int deleteAlertNotifyTemplateByNotifyTemplateIds(Long[] notifyTemplateIds); | ||||
| } | ||||
| @@ -0,0 +1,78 @@ | ||||
| package com.fastbee.notify.service; | ||||
|  | ||||
| import com.fastbee.common.core.notify.NotifyConfigVO; | ||||
| import com.fastbee.notify.domain.NotifyChannel; | ||||
| import com.fastbee.notify.vo.ChannelProviderVO; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 通知渠道Service接口 | ||||
|  * | ||||
|  * @author kerwincui | ||||
|  * @date 2023-12-01 | ||||
|  */ | ||||
| public interface INotifyChannelService | ||||
| { | ||||
|     /** | ||||
|      * 查询通知渠道 | ||||
|      * | ||||
|      * @param id 通知渠道主键 | ||||
|      * @return 通知渠道 | ||||
|      */ | ||||
|     public NotifyChannel selectNotifyChannelById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询通知渠道列表 | ||||
|      * | ||||
|      * @param notifyChannel 通知渠道 | ||||
|      * @return 通知渠道集合 | ||||
|      */ | ||||
|     public List<NotifyChannel> selectNotifyChannelList(NotifyChannel notifyChannel); | ||||
|  | ||||
|     /** | ||||
|      * 新增通知渠道 | ||||
|      * | ||||
|      * @param notifyChannel 通知渠道 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int insertNotifyChannel(NotifyChannel notifyChannel); | ||||
|  | ||||
|     /** | ||||
|      * 修改通知渠道 | ||||
|      * | ||||
|      * @param notifyChannel 通知渠道 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int updateNotifyChannel(NotifyChannel notifyChannel); | ||||
|  | ||||
|     /** | ||||
|      * 批量删除通知渠道 | ||||
|      * | ||||
|      * @param ids 需要删除的通知渠道主键集合 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyChannelByIds(Long[] ids); | ||||
|  | ||||
|     /** | ||||
|      * 删除通知渠道信息 | ||||
|      * | ||||
|      * @param id 通知渠道主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyChannelById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询通知渠道和服务商 | ||||
|      * @return | ||||
|      */ | ||||
|     List<ChannelProviderVO> listChannel(); | ||||
|  | ||||
|     /** | ||||
|      * 获取消息通知渠道参数信息 | ||||
|      * @param channelType 渠道类型 | ||||
|      * @param: provider 服务商 | ||||
|      * @return 结果集 | ||||
|      */ | ||||
|     List<NotifyConfigVO> getConfigContent(String channelType, String provider); | ||||
| } | ||||
| @@ -0,0 +1,62 @@ | ||||
| package com.fastbee.notify.service; | ||||
|  | ||||
| import com.fastbee.notify.domain.NotifyLog; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 通知日志Service接口 | ||||
|  *  | ||||
|  * @author kerwincui | ||||
|  * @date 2023-12-16 | ||||
|  */ | ||||
| public interface INotifyLogService  | ||||
| { | ||||
|     /** | ||||
|      * 查询通知日志 | ||||
|      *  | ||||
|      * @param id 通知日志主键 | ||||
|      * @return 通知日志 | ||||
|      */ | ||||
|     public NotifyLog selectNotifyLogById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询通知日志列表 | ||||
|      *  | ||||
|      * @param notifyLog 通知日志 | ||||
|      * @return 通知日志集合 | ||||
|      */ | ||||
|     public List<NotifyLog> selectNotifyLogList(NotifyLog notifyLog); | ||||
|  | ||||
|     /** | ||||
|      * 新增通知日志 | ||||
|      *  | ||||
|      * @param notifyLog 通知日志 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int insertNotifyLog(NotifyLog notifyLog); | ||||
|  | ||||
|     /** | ||||
|      * 修改通知日志 | ||||
|      *  | ||||
|      * @param notifyLog 通知日志 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int updateNotifyLog(NotifyLog notifyLog); | ||||
|  | ||||
|     /** | ||||
|      * 批量删除通知日志 | ||||
|      *  | ||||
|      * @param ids 需要删除的通知日志主键集合 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyLogByIds(Long[] ids); | ||||
|  | ||||
|     /** | ||||
|      * 删除通知日志信息 | ||||
|      *  | ||||
|      * @param id 通知日志主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyLogById(Long id); | ||||
| } | ||||
| @@ -0,0 +1,117 @@ | ||||
| package com.fastbee.notify.service; | ||||
|  | ||||
| import com.fastbee.common.core.domain.AjaxResult; | ||||
| import com.fastbee.common.core.notify.NotifyConfigVO; | ||||
| import com.fastbee.common.enums.NotifyChannelProviderEnum; | ||||
| import com.fastbee.notify.domain.NotifyTemplate; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 通知模版Service接口 | ||||
|  * | ||||
|  * @author kerwincui | ||||
|  * @date 2023-12-01 | ||||
|  */ | ||||
| public interface INotifyTemplateService | ||||
| { | ||||
|     /** | ||||
|      * 查询通知模版 | ||||
|      * | ||||
|      * @param id 通知模版主键 | ||||
|      * @return 通知模版 | ||||
|      */ | ||||
|     public NotifyTemplate selectNotifyTemplateById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询通知模版列表 | ||||
|      * | ||||
|      * @param notifyTemplate 通知模版 | ||||
|      * @return 通知模版集合 | ||||
|      */ | ||||
|     public List<NotifyTemplate> selectNotifyTemplateList(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * 新增通知模版 | ||||
|      * | ||||
|      * @param notifyTemplate 通知模版 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public AjaxResult insertNotifyTemplate(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * 修改通知模版 | ||||
|      * | ||||
|      * @param notifyTemplate 通知模版 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public AjaxResult updateNotifyTemplate(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * 批量删除通知模版 | ||||
|      * | ||||
|      * @param ids 需要删除的通知模版主键集合 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyTemplateByIds(Long[] ids); | ||||
|  | ||||
|     /** | ||||
|      * 删除通知模版信息 | ||||
|      * | ||||
|      * @param id 通知模版主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteNotifyTemplateById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询某一业务通知通道是否有启动的(业务编码唯一启用一个模板) | ||||
|      * @param notifyTemplate 通知模板 | ||||
|      */ | ||||
|     public Integer countNormalTemplate(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * 更新某一类型为不可用状态,选中的为可用状态 | ||||
|      * @param notifyTemplate 通知模板 | ||||
|      */ | ||||
|     public void updateTemplateStatus(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * @description: 查询启用通知模板 | ||||
|      * @param: serviceCode  业务编码 | ||||
|      * @return: com.fastbee.notify.domain.NotifyTemplate | ||||
|      */ | ||||
|     NotifyTemplate selectOnlyEnable(NotifyTemplate notifyTemplate); | ||||
|  | ||||
|     /** | ||||
|      * @description: 获取消息通知模版参数信息 | ||||
|      * @author fastb | ||||
|      * @date 2023-12-22 11:01 | ||||
|      * @version 1.0 | ||||
|      */ | ||||
|     List<NotifyConfigVO> getNotifyMsgParams(Long channelId, String msgType); | ||||
|  | ||||
|     /** | ||||
|      * @description: 统一获取模板参数内容变量,调用这个方法 | ||||
|      * @param: channelId | ||||
|      * @return: java.lang.String | ||||
|      */ | ||||
|     List<String> listVariables(String content, NotifyChannelProviderEnum notifyChannelProviderEnum); | ||||
|  | ||||
|     /** | ||||
|      * @description: 获取告警微信小程序模板id | ||||
|      * @param: | ||||
|      * @return: java.lang.String | ||||
|      */ | ||||
|     String getAlertWechatMini(); | ||||
|  | ||||
|     /** | ||||
|      * 获取唯一启用模版查询条件 | ||||
|      * 短信、语音、邮箱以业务编码+渠道保证唯一启用,微信、钉钉以业务编码+渠道+服务商保证唯一启用 | ||||
|      * @param: serviceCode | ||||
|      * @param: channelType | ||||
|      * @param: provider | ||||
|      * @return com.fastbee.notify.domain.NotifyTemplate | ||||
|      */ | ||||
|     NotifyTemplate getEnableQueryCondition(String serviceCode, String channelType, String provider, Long tenantId); | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,196 @@ | ||||
| package com.fastbee.notify.service.impl; | ||||
|  | ||||
| import com.fastbee.common.core.domain.entity.SysDictData; | ||||
| import com.fastbee.common.core.domain.entity.SysRole; | ||||
| import com.fastbee.common.core.domain.entity.SysUser; | ||||
| import com.fastbee.common.core.notify.NotifyConfigVO; | ||||
| import com.fastbee.common.enums.NotifyChannelProviderEnum; | ||||
| import com.fastbee.common.exception.ServiceException; | ||||
| import com.fastbee.common.utils.DateUtils; | ||||
| import com.fastbee.notify.domain.NotifyChannel; | ||||
| import com.fastbee.notify.domain.NotifyTemplate; | ||||
| import com.fastbee.notify.mapper.NotifyChannelMapper; | ||||
| import com.fastbee.notify.mapper.NotifyTemplateMapper; | ||||
| import com.fastbee.notify.service.INotifyChannelService; | ||||
| import com.fastbee.notify.vo.ChannelProviderVO; | ||||
| import com.fastbee.system.service.ISysDictDataService; | ||||
| import org.apache.commons.collections4.CollectionUtils; | ||||
| import org.dromara.sms4j.core.factory.SmsFactory; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Objects; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| import static com.fastbee.common.utils.SecurityUtils.getLoginUser; | ||||
|  | ||||
| /** | ||||
|  * 通知渠道Service业务层处理 | ||||
|  * | ||||
|  * @author kerwincui | ||||
|  * @date 2023-12-01 | ||||
|  */ | ||||
| @Service | ||||
| public class NotifyChannelServiceImpl implements INotifyChannelService | ||||
| { | ||||
|     @Resource | ||||
|     private NotifyChannelMapper notifyChannelMapper; | ||||
|     @Resource | ||||
|     private ISysDictDataService sysDictDataService; | ||||
|     @Resource | ||||
|     private NotifyTemplateMapper notifyTemplateMapper; | ||||
|  | ||||
|     /** | ||||
|      * 查询通知渠道 | ||||
|      * | ||||
|      * @param id 通知渠道主键 | ||||
|      * @return 通知渠道 | ||||
|      */ | ||||
|     @Override | ||||
|     public NotifyChannel selectNotifyChannelById(Long id) | ||||
|     { | ||||
|         return notifyChannelMapper.selectNotifyChannelById(id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询通知渠道列表 | ||||
|      * | ||||
|      * @param notifyChannel 通知渠道 | ||||
|      * @return 通知渠道 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<NotifyChannel> selectNotifyChannelList(NotifyChannel notifyChannel) | ||||
|     { | ||||
|         SysUser user = getLoginUser().getUser(); | ||||
| //        List<SysRole> roles=user.getRoles(); | ||||
| //        // 租户 | ||||
| //        if(roles.stream().anyMatch(a-> "tenant".equals(a.getRoleKey()))){ | ||||
| //            notifyChannel.setTenantId(user.getUserId()); | ||||
| //        } | ||||
|         // 查询所属机构 | ||||
|         if (null != user.getDeptId()) { | ||||
|             notifyChannel.setTenantId(user.getDept().getDeptUserId()); | ||||
|         } else { | ||||
|             notifyChannel.setTenantId(user.getUserId()); | ||||
|         } | ||||
|         return notifyChannelMapper.selectNotifyChannelList(notifyChannel); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 新增通知渠道 | ||||
|      * | ||||
|      * @param notifyChannel 通知渠道 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int insertNotifyChannel(NotifyChannel notifyChannel) | ||||
|     { | ||||
|         SysUser user = getLoginUser().getUser(); | ||||
|         if (null == user.getDeptId()) { | ||||
|             throw new ServiceException("只允许租户配置"); | ||||
|         } | ||||
|         notifyChannel.setTenantId(user.getDept().getDeptUserId()); | ||||
|         notifyChannel.setTenantName(user.getDept().getDeptUserName()); | ||||
|         return notifyChannelMapper.insertNotifyChannel(notifyChannel); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改通知渠道 | ||||
|      * | ||||
|      * @param notifyChannel 通知渠道 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int updateNotifyChannel(NotifyChannel notifyChannel) | ||||
|     { | ||||
|         notifyChannel.setUpdateTime(DateUtils.getNowDate()); | ||||
|         List<NotifyTemplate> notifyTemplateList = notifyTemplateMapper.selectNotifyTemplateByChannelId(notifyChannel.getId()); | ||||
|         for (NotifyTemplate notifyTemplate : notifyTemplateList) { | ||||
|             SmsFactory.unregister(notifyTemplate.getId().toString()); | ||||
|         } | ||||
|         return notifyChannelMapper.updateNotifyChannel(notifyChannel); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 批量删除通知渠道 | ||||
|      * | ||||
|      * @param ids 需要删除的通知渠道主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteNotifyChannelByIds(Long[] ids) | ||||
|     { | ||||
|         int result = notifyChannelMapper.deleteNotifyChannelByIds(ids); | ||||
|         // 删除渠道下的模板 | ||||
|         if (result > 0) { | ||||
|             notifyTemplateMapper.deleteNotifyTemplateByChannelIds(ids); | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除通知渠道信息 | ||||
|      * | ||||
|      * @param id 通知渠道主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteNotifyChannelById(Long id) | ||||
|     { | ||||
|         int result = notifyChannelMapper.deleteNotifyChannelById(id); | ||||
|         // 删除渠道下的模板 | ||||
|         if (result > 0) { | ||||
|             notifyTemplateMapper.deleteNotifyTemplateByChannelIds(new Long[]{id}); | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<ChannelProviderVO> listChannel() { | ||||
|         SysDictData sysDictData = new SysDictData(); | ||||
|         sysDictData.setDictType("notify_channel_type"); | ||||
|         sysDictData.setStatus("0"); | ||||
|         List<SysDictData> parentDataList = sysDictDataService.selectDictDataList(sysDictData); | ||||
|         if (CollectionUtils.isEmpty(parentDataList)) { | ||||
|             return new ArrayList<>(); | ||||
|         } | ||||
|         List<String> dictValueList = parentDataList.stream().map(SysDictData::getDictValue).collect(Collectors.toList()); | ||||
|         List<String> dictTypeList = new ArrayList<>(); | ||||
|         for (String s : dictValueList) { | ||||
|             dictTypeList.add("notify_channel_" + s + "_provider"); | ||||
|         } | ||||
|         List<SysDictData> childerDataList = sysDictDataService.selectDictDataListByDictTypes(dictTypeList); | ||||
|         Map<String, List<SysDictData>> map = childerDataList.stream().collect(Collectors.groupingBy(SysDictData::getDictType)); | ||||
|         List<ChannelProviderVO> result = new ArrayList<>(); | ||||
|         for (SysDictData dictData : parentDataList) { | ||||
|             ChannelProviderVO channelProviderVO = new ChannelProviderVO(); | ||||
|             channelProviderVO.setChannelType(dictData.getDictValue()); | ||||
|             channelProviderVO.setChannelName(dictData.getDictLabel()); | ||||
|             String key = "notify_channel_" + dictData.getDictValue() + "_provider"; | ||||
|             if (!map.containsKey(key)) { | ||||
|                 result.add(channelProviderVO); | ||||
|                 continue; | ||||
|             } | ||||
|             List<SysDictData> dataList = map.get(key); | ||||
|             List<ChannelProviderVO.Provider> providerList = new ArrayList<>(); | ||||
|             for (SysDictData data : dataList) { | ||||
|                 ChannelProviderVO.Provider provider = new ChannelProviderVO.Provider(); | ||||
|                 provider.setProvider(data.getDictValue()); | ||||
|                 provider.setProviderName(data.getDictLabel()); | ||||
|                 provider.setCategory(dictData.getDictValue()); | ||||
|                 providerList.add(provider); | ||||
|             } | ||||
|             channelProviderVO.setProviderList(providerList); | ||||
|             result.add(channelProviderVO); | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<NotifyConfigVO> getConfigContent(String channelType, String provider) { | ||||
|         return NotifyChannelProviderEnum.getConfigContent(Objects.requireNonNull(NotifyChannelProviderEnum.getByChannelTypeAndProvider(channelType, provider))); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,143 @@ | ||||
| package com.fastbee.notify.service.impl; | ||||
|  | ||||
| import com.fastbee.common.core.domain.entity.SysRole; | ||||
| import com.fastbee.common.core.domain.entity.SysUser; | ||||
| import com.fastbee.common.utils.DateUtils; | ||||
| import com.fastbee.notify.domain.NotifyChannel; | ||||
| import com.fastbee.notify.domain.NotifyLog; | ||||
| import com.fastbee.notify.domain.NotifyTemplate; | ||||
| import com.fastbee.notify.mapper.NotifyChannelMapper; | ||||
| import com.fastbee.notify.mapper.NotifyLogMapper; | ||||
| import com.fastbee.notify.mapper.NotifyTemplateMapper; | ||||
| import com.fastbee.notify.service.INotifyLogService; | ||||
| import org.apache.commons.collections4.CollectionUtils; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.function.Function; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| import static com.fastbee.common.utils.SecurityUtils.getLoginUser; | ||||
|  | ||||
| /** | ||||
|  * 通知日志Service业务层处理 | ||||
|  * | ||||
|  * @author fastbee | ||||
|  * @date 2023-12-16 | ||||
|  */ | ||||
| @Service | ||||
| public class NotifyLogServiceImpl implements INotifyLogService | ||||
| { | ||||
|     @Resource | ||||
|     private NotifyLogMapper notifyLogMapper; | ||||
|     @Resource | ||||
|     private NotifyChannelMapper notifyChannelMapper; | ||||
|     @Resource | ||||
|     private NotifyTemplateMapper notifyTemplateMapper; | ||||
|  | ||||
|     /** | ||||
|      * 查询通知日志 | ||||
|      * | ||||
|      * @param id 通知日志主键 | ||||
|      * @return 通知日志 | ||||
|      */ | ||||
|     @Override | ||||
|     public NotifyLog selectNotifyLogById(Long id) | ||||
|     { | ||||
|         return notifyLogMapper.selectNotifyLogById(id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询通知日志列表 | ||||
|      * | ||||
|      * @param notifyLog 通知日志 | ||||
|      * @return 通知日志 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<NotifyLog> selectNotifyLogList(NotifyLog notifyLog) | ||||
|     { | ||||
|         SysUser user = getLoginUser().getUser(); | ||||
| //        List<SysRole> roles=user.getRoles(); | ||||
| //        // 租户 | ||||
| //        if(roles.stream().anyMatch(a->a.getRoleKey().equals("tenant"))){ | ||||
| //            notifyLog.setTenantId(user.getUserId()); | ||||
| //        } | ||||
|         // 查询所属机构 | ||||
|         if (null != user.getDeptId()) { | ||||
|             notifyLog.setTenantId(user.getDept().getDeptUserId()); | ||||
|         } else { | ||||
|             notifyLog.setTenantId(user.getUserId()); | ||||
|         } | ||||
|         List<NotifyLog> notifyLogs = notifyLogMapper.selectNotifyLogList(notifyLog); | ||||
|         if (CollectionUtils.isEmpty(notifyLogs)) { | ||||
|             return notifyLogs; | ||||
|         } | ||||
|         List<Long> channelIdList = notifyLogs.stream().map(NotifyLog::getChannelId).collect(Collectors.toList()); | ||||
|         List<NotifyChannel> notifyChannelList = notifyChannelMapper.selectNotifyChannelByIds(channelIdList); | ||||
|         Map<Long, NotifyChannel> notifyChannelMap = notifyChannelList.stream().collect(Collectors.toMap(NotifyChannel::getId, Function.identity())); | ||||
|         List<Long> templateIdList = notifyLogs.stream().map(NotifyLog::getNotifyTemplateId).collect(Collectors.toList()); | ||||
|         List<NotifyTemplate> notifyTemplateList = notifyTemplateMapper.selectNotifyTemplateByIds(templateIdList); | ||||
|         Map<Long, NotifyTemplate> notifyTemplateMap = notifyTemplateList.stream().collect(Collectors.toMap(NotifyTemplate::getId, Function.identity())); | ||||
|         for (NotifyLog log : notifyLogs) { | ||||
|             if (notifyChannelMap.containsKey(log.getChannelId())) { | ||||
|                 log.setChannelName(notifyChannelMap.get(log.getChannelId()).getName()); | ||||
|             } | ||||
|             if (notifyTemplateMap.containsKey(log.getNotifyTemplateId())) { | ||||
|                 log.setTemplateName(notifyTemplateMap.get(log.getNotifyTemplateId()).getName()); | ||||
|             } | ||||
|         } | ||||
|         return notifyLogs; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 新增通知日志 | ||||
|      * | ||||
|      * @param notifyLog 通知日志 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int insertNotifyLog(NotifyLog notifyLog) | ||||
|     { | ||||
|         notifyLog.setCreateTime(DateUtils.getNowDate()); | ||||
|         return notifyLogMapper.insertNotifyLog(notifyLog); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改通知日志 | ||||
|      * | ||||
|      * @param notifyLog 通知日志 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int updateNotifyLog(NotifyLog notifyLog) | ||||
|     { | ||||
|         notifyLog.setUpdateTime(DateUtils.getNowDate()); | ||||
|         return notifyLogMapper.updateNotifyLog(notifyLog); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 批量删除通知日志 | ||||
|      * | ||||
|      * @param ids 需要删除的通知日志主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteNotifyLogByIds(Long[] ids) | ||||
|     { | ||||
|         return notifyLogMapper.deleteNotifyLogByIds(ids); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除通知日志信息 | ||||
|      * | ||||
|      * @param id 通知日志主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteNotifyLogById(Long id) | ||||
|     { | ||||
|         return notifyLogMapper.deleteNotifyLogById(id); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,288 @@ | ||||
| package com.fastbee.notify.service.impl; | ||||
|  | ||||
| import com.alibaba.fastjson2.JSONObject; | ||||
| import com.fastbee.common.core.domain.AjaxResult; | ||||
| import com.fastbee.common.core.domain.entity.SysRole; | ||||
| import com.fastbee.common.core.domain.entity.SysUser; | ||||
| import com.fastbee.common.core.domain.model.LoginUser; | ||||
| import com.fastbee.common.core.notify.NotifyConfigVO; | ||||
| import com.fastbee.common.enums.NotifyChannelEnum; | ||||
| import com.fastbee.common.enums.NotifyChannelProviderEnum; | ||||
| import com.fastbee.common.enums.NotifyServiceCodeEnum; | ||||
| import com.fastbee.common.exception.ServiceException; | ||||
| import com.fastbee.common.utils.DateUtils; | ||||
| import com.fastbee.common.utils.StringUtils; | ||||
| import com.fastbee.notify.domain.NotifyChannel; | ||||
| import com.fastbee.notify.domain.NotifyTemplate; | ||||
| import com.fastbee.notify.mapper.NotifyChannelMapper; | ||||
| import com.fastbee.notify.mapper.NotifyTemplateMapper; | ||||
| import com.fastbee.notify.service.INotifyTemplateService; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.dromara.sms4j.core.factory.SmsFactory; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
| import org.springframework.util.CollectionUtils; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Objects; | ||||
| import java.util.function.Function; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| import static com.fastbee.common.utils.SecurityUtils.getLoginUser; | ||||
|  | ||||
| /** | ||||
|  * 通知模版Service业务层处理 | ||||
|  * | ||||
|  * @author kerwincui | ||||
|  * @date 2023-12-01 | ||||
|  */ | ||||
| @Service | ||||
| @Slf4j | ||||
| public class NotifyTemplateServiceImpl implements INotifyTemplateService { | ||||
|     @Resource | ||||
|     private NotifyTemplateMapper notifyTemplateMapper; | ||||
|     @Resource | ||||
|     private NotifyChannelMapper notifyChannelMapper; | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * 查询通知模版 | ||||
|      * | ||||
|      * @param id 通知模版主键 | ||||
|      * @return 通知模版 | ||||
|      */ | ||||
|     @Override | ||||
|     public NotifyTemplate selectNotifyTemplateById(Long id) { | ||||
|         return notifyTemplateMapper.selectNotifyTemplateById(id); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询通知模版列表 | ||||
|      * | ||||
|      * @param notifyTemplate 通知模版 | ||||
|      * @return 通知模版 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<NotifyTemplate> selectNotifyTemplateList(NotifyTemplate notifyTemplate) { | ||||
|         SysUser user = getLoginUser().getUser(); | ||||
| //        List<SysRole> roles=user.getRoles(); | ||||
| //        // 租户 | ||||
| //        if(roles.stream().anyMatch(a-> "tenant".equals(a.getRoleKey()))){ | ||||
| //            notifyTemplate.setTenantId(user.getUserId()); | ||||
| //        } | ||||
|         // 查询所属机构 | ||||
|         if (null != user.getDeptId()) { | ||||
|             notifyTemplate.setTenantId(user.getDept().getDeptUserId()); | ||||
|         } else { | ||||
|             notifyTemplate.setTenantId(user.getUserId()); | ||||
|         } | ||||
|         List<NotifyTemplate> notifyTemplates = notifyTemplateMapper.selectNotifyTemplateList(notifyTemplate); | ||||
|         if (org.apache.commons.collections4.CollectionUtils.isEmpty(notifyTemplates)) { | ||||
|             return notifyTemplates; | ||||
|         } | ||||
|         List<Long> collect = notifyTemplates.stream().map(NotifyTemplate::getChannelId).collect(Collectors.toList()); | ||||
|         List<NotifyChannel> notifyChannelList = notifyChannelMapper.selectNotifyChannelByIds(collect); | ||||
|         Map<Long, NotifyChannel> notifyChannelMap = notifyChannelList.stream().collect(Collectors.toMap(NotifyChannel::getId, Function.identity())); | ||||
|         for (NotifyTemplate template : notifyTemplates) { | ||||
|             if (notifyChannelMap.containsKey(template.getChannelId())) { | ||||
|                 NotifyChannel notifyChannel = notifyChannelMap.get(template.getChannelId()); | ||||
|                 template.setChannelName(notifyChannel.getName()); | ||||
|             } | ||||
|         } | ||||
|         return notifyTemplates; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 新增通知模版 | ||||
|      * | ||||
|      * @param notifyTemplate 通知模版 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public AjaxResult insertNotifyTemplate(NotifyTemplate notifyTemplate) { | ||||
|         SysUser user = getLoginUser().getUser(); | ||||
|         if (null == user.getDeptId()) { | ||||
|             throw new ServiceException("只允许租户配置"); | ||||
|         } | ||||
|         notifyTemplate.setTenantId(user.getDept().getDeptUserId()); | ||||
|         notifyTemplate.setTenantName(user.getDept().getDeptUserName()); | ||||
|         notifyTemplate.setCreateTime(DateUtils.getNowDate()); | ||||
|         return notifyTemplateMapper.insertNotifyTemplate(notifyTemplate) > 0 ? AjaxResult.success() : AjaxResult.error(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改通知模版 | ||||
|      * | ||||
|      * @param notifyTemplate 通知模版 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public AjaxResult updateNotifyTemplate(NotifyTemplate notifyTemplate) { | ||||
|         notifyTemplate.setUpdateTime(DateUtils.getNowDate()); | ||||
|         if (NotifyChannelEnum.SMS.getType().equals(notifyTemplate.getChannelType())) { | ||||
|             SmsFactory.unregister(notifyTemplate.getId().toString()); | ||||
|         } | ||||
|         return notifyTemplateMapper.updateNotifyTemplate(notifyTemplate) > 0 ? AjaxResult.success() : AjaxResult.error(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 批量删除通知模版 | ||||
|      * | ||||
|      * @param ids 需要删除的通知模版主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteNotifyTemplateByIds(Long[] ids) { | ||||
|         int i = notifyTemplateMapper.deleteNotifyTemplateByIds(ids); | ||||
|         if (i > 0) { | ||||
|             notifyTemplateMapper.deleteAlertNotifyTemplateByNotifyTemplateIds(ids); | ||||
|         } | ||||
|         return i; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除通知模版信息 | ||||
|      * | ||||
|      * @param id 通知模版主键 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     public int deleteNotifyTemplateById(Long id) { | ||||
|         int i = notifyTemplateMapper.deleteNotifyTemplateById(id); | ||||
|         if (i > 0) { | ||||
|             notifyTemplateMapper.deleteAlertNotifyTemplateByNotifyTemplateIds(new Long[]{id}); | ||||
|         } | ||||
|         return i; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询某一业务通知通道是否有启动的(业务编码唯一启用一个模板) | ||||
|      * @param notifyTemplate 通知模板 | ||||
|      */ | ||||
|     @Override | ||||
|     public Integer countNormalTemplate(NotifyTemplate notifyTemplate){ | ||||
|         LoginUser loginUser = getLoginUser(); | ||||
|         assert !Objects.isNull(notifyTemplate.getServiceCode()) : "业务编码不能为空"; | ||||
|         NotifyTemplate selectOne = this.getEnableQueryCondition(notifyTemplate.getServiceCode(), notifyTemplate.getChannelType(), notifyTemplate.getProvider(), loginUser.getUser().getDept().getDeptUserId()); | ||||
|         selectOne.setId(notifyTemplate.getId()); | ||||
|         return notifyTemplateMapper.selectEnableNotifyTemplateCount(selectOne); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取唯一启用模版查询条件 | ||||
|      * 唯一启用条件:同一业务编码的模板短信、语音、邮箱渠道分别可以启用一个,微信、钉钉渠道下不同服务商分别可以启用一个 | ||||
|      * @param: serviceCode | ||||
|      * @param: channelType | ||||
|      * @param: provider | ||||
|      * @return com.fastbee.notify.domain.NotifyTemplate | ||||
|      */ | ||||
|     @Override | ||||
|     public NotifyTemplate getEnableQueryCondition(String serviceCode, String channelType, String provider, Long tenantId) { | ||||
|         NotifyTemplate notifyTemplate = new NotifyTemplate(); | ||||
|         notifyTemplate.setServiceCode(serviceCode); | ||||
|         notifyTemplate.setStatus(1); | ||||
|         notifyTemplate.setTenantId(tenantId); | ||||
|         NotifyChannelEnum notifyChannelEnum = NotifyChannelEnum.getNotifyChannelEnum(channelType); | ||||
|         switch (Objects.requireNonNull(notifyChannelEnum)) { | ||||
|             case SMS: | ||||
|             case VOICE: | ||||
|             case EMAIL: | ||||
|                 notifyTemplate.setChannelType(channelType); | ||||
|                 break; | ||||
|             case WECHAT: | ||||
|             case DING_TALK: | ||||
|                 notifyTemplate.setChannelType(channelType); | ||||
|                 notifyTemplate.setProvider(provider); | ||||
|                 break; | ||||
|             default: | ||||
|                 break; | ||||
|         } | ||||
|         return notifyTemplate; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 更新某一类型为不可用状态,选中的为可用状态 | ||||
|      * @param notifyTemplate 通知模板 | ||||
|      */ | ||||
|     @Override | ||||
|     @Transactional(rollbackFor = Exception.class) | ||||
|     public void updateTemplateStatus(NotifyTemplate notifyTemplate){ | ||||
|         LoginUser loginUser = getLoginUser(); | ||||
|         // 查询所有统一类型可用的渠道 | ||||
|         NotifyTemplate selectEnable = this.getEnableQueryCondition(notifyTemplate.getServiceCode(), notifyTemplate.getChannelType(), notifyTemplate.getProvider(), loginUser.getUser().getDept().getDeptUserId()); | ||||
|         selectEnable.setId(notifyTemplate.getId()); | ||||
|         List<NotifyTemplate> notifyTemplateList = this.selectNotifyTemplateList(selectEnable); | ||||
|         if (!CollectionUtils.isEmpty(notifyTemplateList)){ | ||||
|             //如果有同一类型的渠道为可用,要先将更新为不可用 | ||||
|             List<Long> ids = notifyTemplateList.stream().map(NotifyTemplate::getId).filter(id -> !Objects.equals(id, notifyTemplate.getId())).collect(Collectors.toList()); | ||||
|             if (!CollectionUtils.isEmpty(ids)) { | ||||
|                 notifyTemplateMapper.updateNotifyBatch(ids, 0); | ||||
|             } | ||||
|         } | ||||
|         //更新选中的为可用状态 | ||||
|         NotifyTemplate updateBo = new NotifyTemplate(); | ||||
|         updateBo.setStatus(1); | ||||
|         updateBo.setId(notifyTemplate.getId()); | ||||
|         notifyTemplateMapper.updateNotifyTemplate(updateBo); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public NotifyTemplate selectOnlyEnable(NotifyTemplate notifyTemplate) { | ||||
|         return notifyTemplateMapper.selectOnlyEnable(notifyTemplate); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<NotifyConfigVO> getNotifyMsgParams(Long channelId, String msgType) { | ||||
|         NotifyChannel notifyChannel = notifyChannelMapper.selectNotifyChannelById(channelId); | ||||
|         if (Objects.isNull(notifyChannel)) { | ||||
|             return new ArrayList<>(); | ||||
|         } | ||||
|         NotifyChannelProviderEnum notifyChannelProviderEnum = NotifyChannelProviderEnum.getByChannelTypeAndProvider(notifyChannel.getChannelType(), notifyChannel.getProvider()); | ||||
|         return NotifyChannelProviderEnum.getMsgParams(notifyChannelProviderEnum, msgType); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<String> listVariables(String content, NotifyChannelProviderEnum notifyChannelProviderEnum) { | ||||
|         List<String> variables; | ||||
|         switch (Objects.requireNonNull(notifyChannelProviderEnum)) { | ||||
|             case WECHAT_MINI_PROGRAM: | ||||
|             case WECHAT_PUBLIC_ACCOUNT: | ||||
|                 variables = StringUtils.getWeChatMiniVariables(content); | ||||
|                 break; | ||||
|             case SMS_TENCENT: | ||||
|             case VOICE_TENCENT: | ||||
|                 variables = StringUtils.getVariables("{}", content); | ||||
|                 break; | ||||
|             case EMAIL_QQ: | ||||
|             case EMAIL_163: | ||||
|                 variables = StringUtils.getVariables("#{}", content); | ||||
|                 break; | ||||
|             default: | ||||
|                 variables = StringUtils.getVariables("${}", content); | ||||
|                 break; | ||||
|         } | ||||
|         return variables; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getAlertWechatMini() { | ||||
|         NotifyTemplate selectOne = new NotifyTemplate(); | ||||
|         selectOne.setServiceCode(NotifyServiceCodeEnum.ALERT.getServiceCode()).setChannelType(NotifyChannelProviderEnum.WECHAT_MINI_PROGRAM.getChannelType()).setProvider(NotifyChannelProviderEnum.WECHAT_MINI_PROGRAM.getProvider()).setStatus(1); | ||||
|         SysUser user = getLoginUser().getUser(); | ||||
|         if (null != user.getDeptId()) { | ||||
|             selectOne.setTenantId(user.getDept().getDeptUserId()); | ||||
|         } else { | ||||
|             selectOne.setTenantId(1L); | ||||
|         } | ||||
|         NotifyTemplate notifyTemplate = notifyTemplateMapper.selectOnlyEnable(selectOne); | ||||
|         if (notifyTemplate == null || StringUtils.isEmpty(notifyTemplate.getMsgParams())) { | ||||
|             return ""; | ||||
|         } | ||||
|         JSONObject jsonObject = JSONObject.parseObject(notifyTemplate.getMsgParams()); | ||||
|         return jsonObject.get("templateId").toString(); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,54 @@ | ||||
| package com.fastbee.notify.vo; | ||||
|  | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 渠道服务商VO类 | ||||
|  * @author fastb | ||||
|  * @date 2023-12-01 14:06 | ||||
|  */ | ||||
| @Data | ||||
| public class ChannelProviderVO { | ||||
|  | ||||
|     /** | ||||
|      * 渠道类型 | ||||
|      */ | ||||
|     private String channelType; | ||||
|  | ||||
|     /** | ||||
|      * 渠道名称 | ||||
|      */ | ||||
|     private String channelName; | ||||
|  | ||||
|     /** | ||||
|      * 服务商集合 | ||||
|      */ | ||||
|     private List<Provider> providerList; | ||||
|  | ||||
|     /** | ||||
|      * 服务商 | ||||
|      */ | ||||
|     @Data | ||||
|     public static class Provider{ | ||||
|  | ||||
|         /** | ||||
|          * 服务商英文标识 | ||||
|          */ | ||||
|         private String provider; | ||||
|  | ||||
|         /** | ||||
|          * 服务商名称 | ||||
|          */ | ||||
|         private String providerName; | ||||
|  | ||||
|         /** | ||||
|          * 所属渠道标识 | ||||
|          */ | ||||
|         private String category; | ||||
|  | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -0,0 +1,33 @@ | ||||
| package com.fastbee.notify.vo; | ||||
|  | ||||
| import com.fastbee.common.enums.NotifyChannelProviderEnum; | ||||
| import com.fastbee.notify.domain.NotifyChannel; | ||||
| import com.fastbee.notify.domain.NotifyTemplate; | ||||
| import lombok.Data; | ||||
| import lombok.experimental.Accessors; | ||||
|  | ||||
| import java.util.LinkedHashMap; | ||||
|  | ||||
| /** | ||||
|  * @author fastb | ||||
|  * @version 1.0 | ||||
|  * @description: 通知发送参数 | ||||
|  * @date 2024-01-02 11:10 | ||||
|  */ | ||||
| @Data | ||||
| @Accessors(chain = true) | ||||
| public class NotifyVO { | ||||
|  | ||||
|     private NotifyChannel notifyChannel; | ||||
|  | ||||
|     private NotifyTemplate notifyTemplate; | ||||
|  | ||||
|     /** | ||||
|      * 多个账号用英文逗号隔开 例如:21,51 | ||||
|      */ | ||||
|     private String sendAccount; | ||||
|  | ||||
|     private LinkedHashMap<String,String> map; | ||||
|  | ||||
|     private NotifyChannelProviderEnum notifyChannelProviderEnum; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 wyw
					wyw