wlzboy
1 天以前 08f95b2f159b56fa3bd4f4b348855989de8aa456
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/NotifyDispatchServiceImpl.java
@@ -1,6 +1,7 @@
package com.ruoyi.system.service.impl;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.config.WechatConfig;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.*;
@@ -46,6 +47,16 @@
    @Autowired
    private ISmsService smsService;
    @Autowired
    private IQyWechatService qyWechatService;
    @Autowired
    private WechatConfig wechatConfig;
    @Autowired
    private ISysEmergencyTaskService sysEmergencyTaskService;
    /**
     * 获取指定通知类型启用的渠道列表
     */
@@ -75,8 +86,8 @@
            return 0;
        }
        log.info("开始分发通知任务,id={}, taskId={}, userId={}, notifyType={}",
                notifyTask.getId(), notifyTask.getTaskId(), notifyTask.getUserId(), notifyTask.getNotifyType());
//        log.info("开始分发通知任务,id={}, taskId={}, userId={}, notifyType={}",
//                notifyTask.getId(), notifyTask.getTaskId(), notifyTask.getUserId(), notifyTask.getNotifyType());
        // 更新状态为处理中
        notifyTaskService.markProcessing(notifyTask.getId());
@@ -108,6 +119,9 @@
                        break;
                    case NotifyChannelConfig.CHANNEL_SMS:
                        success = sendSmsMessage(notifyTask);
                        break;
                    case NotifyChannelConfig.CHANNEL_QY_WECHAT:
                        success = sendQyWechatMessage(notifyTask);
                        break;
                    default:
                        log.warn("不支持的渠道类型:{}", channel);
@@ -175,6 +189,7 @@
            sendLog.setChannel(channel);
            sendLog.setSendStatus(success ? NotifySendLog.SEND_STATUS_SUCCESS : NotifySendLog.SEND_STATUS_FAILED);
            sendLog.setSendTime(DateUtils.getNowDate());
            sendLog.setSendContent(notifyTask.getContent());
            sendLog.setResponseMsg(errorMsg);
            
            notifySendLogService.insertNotifySendLog(sendLog);
@@ -318,4 +333,48 @@
            return false;
        }
    }
    @Autowired
    private ISysConfigService sysConfigService;
    /**
     * 发送企业微信消息
     */
    @Override
    public boolean sendQyWechatMessage(NotifyTask notifyTask) {
        try {
            // 检查企业微信服务是否启用
            if (!qyWechatService.isEnabled()) {
                log.info("企业微信服务已关闭,跳过发送");
                return false;
            }
            Long taskId= notifyTask.getTaskId();
           SysTaskEmergency emergency = this.sysEmergencyTaskService.selectSysTaskEmergencyByTaskId(taskId);
           if(emergency==null){
               return false;
           }
//           Long dispatchOrderId = emergency.getLegacyDispatchOrdId();
//          String oldsiteUrl= sysConfigService.selectConfigByKey("oldsite.url");
//          if(oldsiteUrl==null){
//              oldsiteUrl="https://sys.966120.com.cn/m_DispatchOrder.gds?DispatchOrdID=";
//          }
            String appId=wechatConfig.getAppId();
           String pathPage="/pagesTask/detail?id="+taskId;
            // 发送企业微信消息
            boolean success = qyWechatService.sendNotifyMessage(
                    notifyTask.getUserId(),
                    notifyTask.getTitle(),
                    notifyTask.getContent(),appId,pathPage
            );
            if (success) {
                log.info("企业微信消息发送成功,userId={}", notifyTask.getUserId());
            } else {
                log.warn("企业微信消息发送失败,userId={}", notifyTask.getUserId());
            }
            return success;
        } catch (Exception e) {
            log.error("企业微信消息发送异常,taskId={}, userId={}", notifyTask.getTaskId(), notifyTask.getUserId(), e);
            return false;
        }
    }
}