| | |
| | | sendLog.setSendTime(DateUtils.getNowDate()); |
| | | sendLog.setSendContent(notifyTask.getContent()); |
| | | sendLog.setResponseMsg(errorMsg); |
| | | sendLog.setSendResult(success ? "发送成功" : ("发送失败: " + (errorMsg != null ? errorMsg : "未知原因"))); |
| | | |
| | | notifySendLogService.insertNotifySendLog(sendLog); |
| | | } catch (Exception e) { |
| | |
| | | */ |
| | | @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; |
| | | // 检查企业微信服务是否启用 |
| | | if (!qyWechatService.isEnabled()) { |
| | | throw new RuntimeException("企业微信服务未启用"); |
| | | } |
| | | Long taskId = notifyTask.getTaskId(); |
| | | SysTaskEmergency emergency = this.sysEmergencyTaskService.selectSysTaskEmergencyByTaskId(taskId); |
| | | if (emergency == null) { |
| | | throw new RuntimeException("找不到对应的急救任务信息,taskId=" + taskId); |
| | | } |
| | | // 检查用户是否绑定企业微信 |
| | | Long userId = notifyTask.getUserId(); |
| | | String qyUserId = qyWechatService.getQyUserIdByUserId(userId); |
| | | if (qyUserId == null || qyUserId.isEmpty()) { |
| | | throw new RuntimeException("用户未绑定企业微信ID,userId=" + userId); |
| | | } |
| | | String appId = wechatConfig.getAppId(); |
| | | String pathPage = "/pagesTask/detail?id=" + taskId; |
| | | // 发送企业微信消息 |
| | | boolean success = qyWechatService.sendNotifyMessage( |
| | | userId, |
| | | notifyTask.getTitle(), |
| | | notifyTask.getContent(), appId, pathPage |
| | | ); |
| | | if (success) { |
| | | log.info("企业微信消息发送成功,userId={}", userId); |
| | | } else { |
| | | throw new RuntimeException("企业微信API返回失败,userId=" + userId); |
| | | } |
| | | return true; |
| | | } |
| | | } |