| | |
| | | package com.ruoyi.system.listener; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.config.WechatConfig; |
| | | import com.ruoyi.common.utils.DeptUtil; |
| | | import com.ruoyi.common.utils.LongUtil; |
| | | import com.ruoyi.system.domain.*; |
| | |
| | | |
| | | @Autowired |
| | | private INotifyDispatchService notifyDispatchService; |
| | | |
| | | @Autowired |
| | | private IQyWechatService qyWechatService; |
| | | |
| | | @Autowired |
| | | private WechatConfig wechatConfig; |
| | | |
| | | /** 待准备状态 - 可以发送短信通知 */ |
| | | private static final String TASK_STATUS_PENDING = "PENDING"; |
| | |
| | | /** |
| | | * 监听任务分配事件 |
| | | * 创建通知任务,由通知分发服务决定发送渠道 |
| | | * 同时直接发送企业微信通知 |
| | | * |
| | | * @param event 任务分配事件 |
| | | */ |
| | |
| | | Long creatorId = task.getCreatorId(); |
| | | String taskStatus = task.getTaskStatus(); |
| | | task.setEmergencyInfo(emergency); |
| | | // 仅在待准备状态下发送通知 |
| | | if (!TASK_STATUS_PENDING.equals(taskStatus) && !TASK_STATUS_PREPARING.equals(taskStatus)) { |
| | | log.info("任务状态({})非待准备状态,跳过通知,taskId={}", taskStatus, event.getTaskId()); |
| | | return; |
| | | } |
| | | |
| | | |
| | | // 构建通知内容 |
| | | String notifyContent = buildNotifyContent(task, emergency); |
| | | this.sendDispatchNotify(event.getAssigneeIds(), creatorId, event.getTaskId(),task.getShowTaskCode(), notifyContent); |
| | | |
| | | // 直接发送企业微信通知给执行人员 |
| | | sendQyWechatNotifyToAssignees(event.getAssigneeIds(), creatorId, event.getTaskId(), notifyContent); |
| | | |
| | | // 同时走原有通知分发流程(站内消息等) |
| | | // 仅在待准备状态下发送其他通知 |
| | | if (TASK_STATUS_PENDING.equals(taskStatus) || TASK_STATUS_PREPARING.equals(taskStatus)) { |
| | | this.sendDispatchNotify(event.getAssigneeIds(), creatorId, event.getTaskId(), task.getShowTaskCode(), notifyContent); |
| | | } |
| | | |
| | | |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 直接发送企业微信通知给执行人员 |
| | | */ |
| | | private void sendQyWechatNotifyToAssignees(List<Long> assigneeIds, Long creatorId, Long taskId, String content) { |
| | | String appId = wechatConfig.getAppId(); |
| | | String pathPage = "/pagesTask/detail?id=" + taskId; |
| | | int successCount = 0; |
| | | |
| | | for (Long assigneeId : assigneeIds) { |
| | | // 排除创建人 |
| | | if (creatorId != null && creatorId.equals(assigneeId)) { |
| | | log.debug("跳过创建人,不发送企业微信通知,userId={}", assigneeId); |
| | | continue; |
| | | } |
| | | |
| | | try { |
| | | boolean success = qyWechatService.sendNotifyMessage( |
| | | assigneeId, |
| | | "转运单任务派单通知", |
| | | content, |
| | | appId, |
| | | pathPage |
| | | ); |
| | | |
| | | if (success) { |
| | | successCount++; |
| | | log.info("企业微信派单通知发送成功,taskId={}, userId={}", taskId, assigneeId); |
| | | } else { |
| | | log.warn("企业微信派单通知发送失败,taskId={}, userId={}", taskId, assigneeId); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("企业微信派单通知发送异常,taskId={}, userId={}", taskId, assigneeId, e); |
| | | } |
| | | } |
| | | |
| | | log.info("企业微信派单通知发送完成,taskId={}, 成功数量={}/{}", taskId, successCount, assigneeIds.size()); |
| | | } |
| | | |
| | | /** |
| | | * 向执行人发送任务分配通知 |
| | | * @param assigneeIds |
| | | * @param creatorId |