From 0bbbd746e8c39d91ad7b47a4e36e29ab972dc98c Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期二, 20 十月 2026 16:56:54 +0800
Subject: [PATCH] 处理长期任务发送问题

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SmsController.java |  264 +++++++++++++++++++++++++++-------------------------
 1 files changed, 135 insertions(+), 129 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SmsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SmsController.java
index 9b3667f..b55411c 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SmsController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SmsController.java
@@ -1,23 +1,17 @@
 package com.ruoyi.web.controller.common;
 
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.Gson;
 import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.common.dx.MessageSend;
-import com.ruoyi.common.utils.HttpUtil;
 import com.ruoyi.common.utils.RSAPublicKeyExample;
 import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.http.HttpUtils;
-import com.ruoyi.common.utils.sms.smsUtils;
-import com.smartor.common.MtSubmitSmUtil;
-import com.smartor.common.ShiyiSmsUtil;
-import com.smartor.domain.ServiceOutPath;
-import com.smartor.domain.ShiyiSmsRequest;
-import com.smartor.domain.ShiyiSmsResponse;
-import com.smartor.domain.smsVO;
-import com.smartor.mapper.UtilsMapper;
-import com.smartor.service.IServiceOutPathService;
+import com.ruoyi.message.SendResult;
+import com.ruoyi.message.sms.SmsSendRequest;
+import com.ruoyi.message.sms.SmsSenderFactory;
+import com.ruoyi.message.sms.provider.shiyi.ShiyiSmsRequest;
+import com.ruoyi.message.sms.provider.shiyi.ShiyiSmsResponse;
+import com.ruoyi.message.sms.provider.shiyi.ShiyiSmsUtil;
+import com.ruoyi.message.wechat.WechatSendRequest;
+import com.ruoyi.message.wechat.WechatSenderFactory;
+import com.smartor.domain.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -30,35 +24,32 @@
 import org.springframework.web.bind.annotation.RestController;
 
 import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+import com.ruoyi.task.domain.ServiceSubtask;
+import com.ruoyi.task.domain.ServiceOutPath;
+import com.ruoyi.task.service.IServiceOutPathService;
+import com.ruoyi.task.service.IServiceSubtaskService;
 
+/**
+ * 鐭ヤ俊鎺ュ彛锛堝澶栫煭淇� / 寰俊鍏紬鍙峰彂閫佸叆鍙o級銆�
+ * <p>
+ * 璇存槑锛氱煭淇′笌鍏紬鍙风殑绔欑偣宸紓锛堟姤鏂囨牸寮忋�佺鍚嶃�乼oken銆佽繑鍥炲垽瀹氾級宸插叏閮ㄦ敹鍙e埌
+ * {@code ruoyi-message} 妯″潡锛屾湰绫诲彧璐熻矗鍙傛暟缁勮涓庢寜 {@code active} 璺敱銆�
+ */
 @RestController
 @Api(description = "鐭ヤ俊鎺ュ彛")
 @RequestMapping("/sms")
 @Slf4j
 public class SmsController {
-    @Value("${xhsmsPath}")
-    private String xhsmsPath;
 
     @Autowired
-    private MtSubmitSmUtil mtSubmitSmUtil;
+    private SmsSenderFactory smsSenderFactory;
+
+    @Autowired
+    private WechatSenderFactory wechatSenderFactory;
 
     @Autowired
     private ShiyiSmsUtil shiyiSmsUtil;
-
-    @Value("${xhsmsAccount}")
-    private String xhsmsAccount;
-
-    @Value("${xhsmsPwd}")
-    private String xhsmsPwd;
-    // 铏氭嫙鎺ュ叆鐮�
-    @Value("${xhsmsjrm}")
-    private String xhsmsjrm;
 
     @Value("${localIP}")
     private String ip;
@@ -71,19 +62,23 @@
 
     @Autowired
     private IServiceOutPathService iServiceOutPathService;
+    @Autowired
+    private IServiceSubtaskService iServiceSubtaskService;
 
     @Value("${spring.profiles.active}")
     private String active;
 
     /**
-     * @param
-     * @return
+     * 鐭俊鍙戦�侊紙娴嬭瘯锛�
      */
     @ApiOperation("鐭俊鍙戦��")
     @PostMapping("/sendTest")
     public AjaxResult send(@RequestBody smsVO vo) {
-        String sendMsg = smsUtils.sendSms(xhsmsPath, xhsmsAccount, xhsmsPwd, vo.getPhone(), vo.getContent());
-        return AjaxResult.success(sendMsg);
+        //涓庡師瀹炵幇涓�鑷达細娴嬭瘯鎺ュ彛鍥哄畾璧板競涓�锛坰msUtils.sendSms锛屽惔灞辩鍚嶏級
+        SmsSendRequest request = SmsSendRequest.of(vo.getPhone(), vo.getContent());
+        request.setCampus("2");
+        SendResult sendResult = smsSenderFactory.send("hzszlyy", request);
+        return AjaxResult.success(sendResult.getRawResponse());
     }
 
     @ApiOperation("甯備竴HIS鐭俊XML娴嬭瘯")
@@ -99,12 +94,105 @@
     }
 
     /**
-     * @param
-     * @return
+     * 鐭俊鍙戦��
      */
     @ApiOperation("鐭俊鍙戦��")
     @PostMapping("/send")
     public AjaxResult sendAsk(@RequestBody smsVO vo) throws UnsupportedEncodingException {
+        String content = "";
+        if (StringUtils.isNotEmpty(vo.getSubId())) {
+            ServiceSubtask serviceSubtask = iServiceSubtaskService.selectServiceSubtaskById(Long.valueOf(vo.getSubId()));
+            if (serviceSubtask.getSendstate() == 4L) content = "璇ヤ换鍔′笉鎵ц";
+            return AjaxResult.error(content);
+        }
+
+        if (StringUtils.isNotEmpty(vo.getTaskId()) && StringUtils.isNotEmpty(vo.getPatId()) && StringUtils.isNotEmpty(vo.getSubId())) {
+            RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
+            String taskId = rsaPublicKeyExample.encryptedData(vo.getTaskId().toString(), pub_key);
+            String patid = rsaPublicKeyExample.encryptedData(vo.getPatId().toString(), pub_key);
+            String subId = rsaPublicKeyExample.encryptedData(vo.getSubId().toString(), pub_key);
+            Integer radix = iServiceOutPathService.selectAutoId();
+            String format = String.format("%03X", radix);
+            ServiceOutPath serviceOutPath = new ServiceOutPath();
+            serviceOutPath.setParam1(taskId);
+            serviceOutPath.setParam2(patid);
+            serviceOutPath.setParam3(vo.getTaskName());
+            serviceOutPath.setParam6(subId);
+            serviceOutPath.setRadix(format);
+            serviceOutPath.setCreateTime(new Date());
+            serviceOutPath.setOrgid(vo.getOrgid());
+            String url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format;
+            content = "鎮ㄥソ锛岄個璇锋偍濉啓鍑洪櫌璋冩煡琛紝璇风偣鍑�" + url + "濉啓銆傛劅璋㈡偍閰嶅悎锛�";
+            serviceOutPath.setUrl(url);
+            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
+        }
+
+        if (ObjectUtils.isNotEmpty(vo.getContent())) content = vo.getContent();
+
+        String sendMsg = "false";
+        try {
+            if ("ls".equals(active)) {
+                //涓庡師瀹炵幇涓�鑷达細涓芥按13瀹跺尰闄㈢殑鐭俊鍔熻兘鏍囪涓烘湭寮�閫�
+                return AjaxResult.error("璇ョ煭淇″姛鑳借繕鏈紑閫�");
+            }
+            SmsSendRequest request = SmsSendRequest.of(vo.getPhone(), content, vo.getOrgid());
+            //甯備竴鍖哄垎婀栨花/鍚村北绛惧悕锛屾鎺ュ彛鏃犻櫌鍖轰俊鎭紝涓庡師瀹炵幇涓�鑷达紙闈炴箹婊ㄥ嵆鍚村北锛�
+            SendResult sendResult = smsSenderFactory.send(active, request);
+            sendMsg = sendResult.asLegacyFlag();
+            log.info(sendMsg);
+        } catch (Exception ex) {
+            log.error(ex.getMessage());
+        }
+        return AjaxResult.success(sendMsg);
+    }
+
+    /**
+     * 寰俊鍙戦��
+     */
+    @ApiOperation("寰俊鍙戦��")
+    @PostMapping("/sendChat")
+    public AjaxResult sendChat(@RequestBody smsVO vo) {
+        String sendMsg = "";
+        if (StringUtils.isNotEmpty(vo.getSubId())) {
+            ServiceSubtask serviceSubtask = iServiceSubtaskService.selectServiceSubtaskById(Long.valueOf(vo.getSubId()));
+            if (serviceSubtask.getSendstate() == 4L) sendMsg = "璇ヤ换鍔′笉鎵ц";
+            return AjaxResult.error(sendMsg);
+        }
+        if (StringUtils.isNotEmpty(vo.getTaskId()) && StringUtils.isNotEmpty(vo.getPatId()) && StringUtils.isNotEmpty(vo.getSubId())) {
+            RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
+            String taskId = rsaPublicKeyExample.encryptedData(vo.getTaskId().toString(), pub_key);
+            String patid = rsaPublicKeyExample.encryptedData(vo.getPatId().toString(), pub_key);
+            String subId = rsaPublicKeyExample.encryptedData(vo.getSubId().toString(), pub_key);
+            Integer radix = iServiceOutPathService.selectAutoId();
+            String format = String.format("%03X", radix);
+            ServiceOutPath serviceOutPath = new ServiceOutPath();
+            serviceOutPath.setParam1(taskId);
+            serviceOutPath.setParam2(patid);
+            serviceOutPath.setParam3(vo.getTaskName());
+            serviceOutPath.setParam6(subId);
+            serviceOutPath.setRadix(format);
+            serviceOutPath.setCreateTime(new Date());
+            serviceOutPath.setOrgid(vo.getOrgid());
+            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
+            String url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format;
+            //涓庡師瀹炵幇涓�鑷达細璇ユ帴鍙e浐瀹氳蛋甯備竴鍏紬鍙�
+            WechatSendRequest request = new WechatSendRequest();
+            request.setIdCard(vo.getIdCard());
+            request.setPhone(vo.getPhone());
+            request.setUrl(url);
+            request.setOrgid(vo.getOrgid());
+            SendResult sendResult = wechatSenderFactory.send("hzszlyy", request);
+            sendMsg = sendResult.getRawResponse();
+        }
+        return AjaxResult.success(sendMsg);
+    }
+
+    /**
+     * 鐢熸垚澶栭摼
+     */
+    @ApiOperation("鐢熸垚澶栭摼")
+    @PostMapping("/getUrl")
+    public AjaxResult getUrl(@RequestBody smsVO vo) throws UnsupportedEncodingException {
         String content = "";
         if (StringUtils.isNotEmpty(vo.getTaskId()) && StringUtils.isNotEmpty(vo.getPatId()) && StringUtils.isNotEmpty(vo.getSubId())) {
             RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
@@ -121,100 +209,18 @@
             serviceOutPath.setRadix(format);
             serviceOutPath.setCreateTime(new Date());
             serviceOutPath.setOrgid(vo.getOrgid());
+            String url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format;
+//            content = "鎮ㄥソ锛岄個璇锋偍濉啓鍑洪櫌璋冩煡琛紝璇风偣鍑�" + url + "濉啓銆傛劅璋㈡偍閰嶅悎锛�";
+            content = url;
+            serviceOutPath.setUrl(url);
             iServiceOutPathService.insertServiceOutPath(serviceOutPath);
-            String url = ip + ":" + req_path + "/wt?p=" + format;
-            content = "鎮ㄥソ锛岄個璇锋偍濉啓鍑洪櫌璋冩煡琛紝璇风偣鍑�" + url + "濉啓銆傛劅璋㈡偍閰嶅悎锛�";
+        }
+        if (StringUtils.isNotEmpty(vo.getSubId())) {
+            ServiceSubtask serviceSubtask = iServiceSubtaskService.selectServiceSubtaskById(Long.valueOf(vo.getSubId()));
+            if (serviceSubtask.getSendstate() == 4L) content = "璇ヤ换鍔′笉鎵ц";
         }
 
-        if (ObjectUtils.isNotEmpty(vo.getContent())) content = vo.getContent();
-
-        String sendMsg = "false";
-        try {
-            if (active.equals("hzszlyy")) {
-                sendMsg = smsUtils.sendSms(xhsmsPath, xhsmsAccount, xhsmsPwd, vo.getPhone(), content);
-            } else if (active.equals("nhfy")) {
-                Map<String, Object> smsResult = mtSubmitSmUtil.submitSm(vo.getPhone(), content);
-                if (smsResult != null && smsResult.get("result") != null && smsResult.get("result").toString().equals("0")) {
-                    sendMsg = "true";
-                }
-            } else if (active.equals("sltd")) {
-                String data = MessageSend.sendMsg(content, "6", vo.getPhone(), LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
-                if (StringUtils.isNotEmpty(data)) {
-                    ObjectMapper mapper = new ObjectMapper();
-                    JsonNode root = mapper.readTree(data);
-                    String status = root.get("result").get(0).get("status").asText();
-                    if (status.equals("00000")) {
-                        sendMsg = "true";
-                    }
-                }
-            } else if (active.equals("xh")) {
-//                Map<String, String> req = new HashMap<>();
-//                req.put("phone", vo.getPhone());
-//                req.put("content", vo.getContent());
-//                Boolean result = HttpUtil.postJsonRequest(xhsmsPath, new Gson().toJson(req));
-                Map<String, String> map2 = new HashMap<String, String>();
-                map2.put("action", "send");
-                map2.put("account", xhsmsAccount);
-                map2.put("password", xhsmsPwd);
-                map2.put("mobile", vo.getPhone());
-                map2.put("content", vo.getContent());
-                map2.put("extno", xhsmsjrm);
-                map2.put("rt", "json");
-                StringBuilder encodedParams = new StringBuilder();
-
-                for (Map.Entry<String, String> entry : map2.entrySet()) {
-                    if (encodedParams.length() > 0) {
-                        encodedParams.append("&");
-                    }
-                    // 瀵归敭鍜屽�艰繘琛孶RL缂栫爜
-                    String encodedKey = URLEncoder.encode(entry.getKey(), "UTF-8");
-                    String encodedValue = URLEncoder.encode(entry.getValue(), "UTF-8");
-                    encodedParams.append(encodedKey).append("=").append(encodedValue);
-                }
-                Boolean result = HttpUtils.sendPost(xhsmsPath, encodedParams.toString());
-                if (result) {
-                    sendMsg = "true";
-                }
-            } else if (active.equals("ls")) {
-                //涓芥按13瀹跺尰闄紝鏈夌偣涓嶆柟渚匡紝鏈夌┖鍐嶆帴
-                return AjaxResult.error("璇ョ煭淇″姛鑳借繕鏈紑閫�");
-            }
-            log.info(sendMsg);
-        } catch (Exception ex) {
-            log.error(ex.getMessage());
-        }
-        return AjaxResult.success(sendMsg);
+        return AjaxResult.success(content);
     }
-
-    /**
-     * @param
-     * @return
-     */
-    @ApiOperation("寰俊鍙戦��")
-    @PostMapping("/sendChat")
-    public AjaxResult sendChat(@RequestBody smsVO vo) throws UnsupportedEncodingException {
-        String sendMsg = "";
-        if (StringUtils.isNotEmpty(vo.getTaskId()) && StringUtils.isNotEmpty(vo.getPatId()) && StringUtils.isNotEmpty(vo.getSubId())) {
-            RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
-            String taskId = rsaPublicKeyExample.encryptedData(vo.getTaskId().toString(), pub_key);
-            String patid = rsaPublicKeyExample.encryptedData(vo.getPatId().toString(), pub_key);
-            String subId = rsaPublicKeyExample.encryptedData(vo.getSubId().toString(), pub_key);
-            Integer radix = iServiceOutPathService.selectAutoId();
-            String format = String.format("%03X", radix);
-            ServiceOutPath serviceOutPath = new ServiceOutPath();
-            serviceOutPath.setParam1(taskId);
-            serviceOutPath.setParam2(patid);
-            serviceOutPath.setParam3(vo.getTaskName());
-            serviceOutPath.setParam6(subId);
-            serviceOutPath.setRadix(format);
-            serviceOutPath.setCreateTime(new Date());
-            serviceOutPath.setOrgid(vo.getOrgid());
-            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
-            String url = ip + ":" + req_path + "/wt?p=" + format;
-            sendMsg = smsUtils.sendChat(url, vo.getPhone(), vo.getIdCard());
-        }
-        return AjaxResult.success(sendMsg);
-    }
-
 
 }

--
Gitblit v1.9.3