liusheng
2024-11-08 048db32d9a965f1ef398a8aa02a012e9b968a6b1
ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java
@@ -1,10 +1,12 @@
package com.ruoyi.web.component;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.ServiceFromEnum;
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;
@@ -13,10 +15,7 @@
import com.smartor.domain.*;
import com.smartor.mapper.ServiceSubtaskMapper;
import com.smartor.mapper.ServiceTaskMapper;
import com.smartor.service.IBaseSmsaccountService;
import com.smartor.service.IIvrTaskTemplateService;
import com.smartor.service.IServiceSubtaskRecordService;
import com.smartor.service.ISvyTaskTemplateService;
import com.smartor.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +25,7 @@
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
@@ -55,9 +55,7 @@
    private String thirdWXUrl;
    @Autowired
    private IIvrTaskTemplateService ivrTaskTemplateService;
    @Autowired
    private ISvyTaskTemplateService svyTaskTemplateService;
    private IServiceOutPathService iServiceOutPathService;
    @Autowired
    private ServiceSubtaskMapper ivrTaskcallMapper;
@@ -88,6 +86,9 @@
    @Autowired
    IBaseSmsaccountService baseSmsaccountService;
    @Value("${xhsmsPath}")
    private String xhsmsPath;
    // 创建固定大小的线程池
    private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
@@ -280,7 +281,6 @@
                    continue;
                } else if (descByCode.equals("短信")) {
                    //短信
//                        http://localhost:8099/followvisit/particty?param1=3&param2=348
                    //对url中两个参数加密
                    RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
                    String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key);
@@ -298,17 +298,62 @@
                            SendMagParam sendMagParam = new SendMagParam();
                            sendMagParam.setType("4");
                            if (type == 1) {
                                sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "&param2=" + patid + "&param5=false");
                            } else if (type == 1) {
                                sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false");
                                //随访
                                ServiceOutPath serviceOutPath = new ServiceOutPath();
                                serviceOutPath.setParam1(taskId);
                                serviceOutPath.setParam2(patid);
                                serviceOutPath.setCreateTime(new Date());
                                iServiceOutPathService.insertServiceOutPath(serviceOutPath);
//                                sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "&param2=" + patid + "&param5=false");
                                //转成16进制
                                String format = String.format("%03X", serviceOutPath.getId());
                                serviceOutPath.setRadix(format);
                                serviceOutPath.setUpdateTime(new Date());
                                iServiceOutPathService.updateServiceOutPath(serviceOutPath);
                                sendMagParam.setPhone(serviceSubtask.getPhone());
                                sendMagParam.setUrl(ip + ":" + req_path + "/sf?p=" + format);
                                sendMagParam.setContent("【新华医院】您好,邀请您填写出院随访调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!");
                            } else if (type == 2) {
                                //问券(问题)
                                ServiceOutPath serviceOutPath = new ServiceOutPath();
                                serviceOutPath.setParam1(taskId);
                                serviceOutPath.setParam2(patid);
//                                serviceOutPath.setParam3(URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()));
                                serviceOutPath.setParam3(ivrTask1.getTaskName());
                                serviceOutPath.setCreateTime(new Date());
                                iServiceOutPathService.insertServiceOutPath(serviceOutPath);
                                String format = String.format("%03X", serviceOutPath.getId());
                                serviceOutPath.setRadix(format);
                                serviceOutPath.setUpdateTime(new Date());
                                iServiceOutPathService.updateServiceOutPath(serviceOutPath);
//                                sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false");
                                sendMagParam.setPhone(serviceSubtask.getPhone());
                                sendMagParam.setUrl(ip + ":" + req_path + "/wt?p=" + format);
                                sendMagParam.setContent("【新华医院】您好,邀请您填写出院调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!");
                            } else if (type == 3) {
                                sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainxj?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false");
                                //宣教
                                ServiceOutPath serviceOutPath = new ServiceOutPath();
                                serviceOutPath.setParam1(taskId);
                                serviceOutPath.setParam2(patid);
//                                serviceOutPath.setParam3(URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()));
                                serviceOutPath.setParam3(ivrTask1.getTaskName());
                                serviceOutPath.setCreateTime(new Date());
                                iServiceOutPathService.insertServiceOutPath(serviceOutPath);
                                String format = String.format("%03X", serviceOutPath.getId());
                                serviceOutPath.setRadix(format);
                                serviceOutPath.setUpdateTime(new Date());
                                iServiceOutPathService.updateServiceOutPath(serviceOutPath);
//                                sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainxj?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false");
                                sendMagParam.setPhone(serviceSubtask.getPhone());
                                sendMagParam.setUrl(ip + ":" + req_path + "/xj?p=" + format);
                                sendMagParam.setContent("【新华医院】您好,邀请您填写出院宣教调查表,请点击" + sendMagParam.getUrl() + "查看。感谢您配合!");
                            }
                            //短信还需要模板
                            sendMagParam.setContent("【新华医院】+<a href="+sendMagParam.getUrl()+"链接测试</a>");
                            Boolean aBoolean = sendService.sendMsg(sendMagParam);
                            if (!aBoolean) {
                            Map<String, String> req = new HashMap<>();
                            req.put("phone", sendMagParam.getPhone());
                            req.put("content", sendMagParam.getContent());
                            String s = HttpUtil.postJsonRequest(xhsmsPath, new Gson().toJson(req));
                            if (s.equals("true")) {
                                ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
                                serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString());
                                serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId());
@@ -373,34 +418,77 @@
                    String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key);
                    for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) {
                        String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key);
//                        SendMagParam sendMagParam = new SendMagParam();
//                        sendMagParam.setType("5");
//                        sendMagParam.setUrl(ip + ":" + req_path + "/outsideChain?param1=" + taskId + "&param2=" + patid + "&param3=" + ivrTask1.getTaskName() + "&param5=false");
//                        log.info("链接完整路径:{}", ip + ":" + req_path + "/outsideChain?param1=" + taskId + "&param2=" + patid + "&param3=" + ivrTask1.getTaskName() + "&param5=false");
//                        //这个模板ID先写死,后面做成可选
//                        sendMagParam.setTmpCode("oG3pJHPVWpE81DmZsua_2tKwgJ97r0qz37z56ns7NB4");
//                        Map map = new HashMap();
//                        map.put("first", ivrTask1.getTaskName());
//                        sendMagParam.setContent(JSON.toJSONString(map));
//                        sendMagParam.setOpenid(serviceSubtask.getOpenid());
//                        Boolean aBoolean = sendService.sendMsg(sendMagParam);
                        String url = null;
                        try {
                            if (type == 1) {
                                url = ip + ":" + req_path + "/outsideChain?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false";
                            } else if (type == 2) {
                                url = ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false";
                            } else if (type == 3) {
                                url = ip + ":" + req_path + "/outsideChainxj?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false";
                            }
                        SendMagParam sendMagParam = new SendMagParam();
                        sendMagParam.setType("5");
                        sendMagParam.setUrl(ip + ":" + req_path + "/outsideChain?param1=" + taskId + "&param2=" + patid + "&param3=" + ivrTask1.getTaskName() + "&param5=false");
                        log.info("链接完整路径:{}", ip + ":" + req_path + "/outsideChain?param1=" + taskId + "&param2=" + patid + "&param3=" + ivrTask1.getTaskName() + "&param5=false");
                        //这个模板ID先写死,后面做成可选
                        sendMagParam.setTmpCode("oG3pJHPVWpE81DmZsua_2tKwgJ97r0qz37z56ns7NB4");
                        Map map = new HashMap();
                        map.put("first", ivrTask1.getTaskName());
                        sendMagParam.setContent(JSON.toJSONString(map));
                        sendMagParam.setOpenid(serviceSubtask.getOpenid());
                        Boolean aBoolean = sendService.sendMsg(sendMagParam);
                        String url = null;
                            String wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), "无");
                            Map<String, Object> map = JSONObject.parseObject(wxCode, Map.class);
                            if (!map.isEmpty()) {
////                            if (type == 1) {
////                                url = ip + ":" + req_path + "/outsideChain?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false";
////                            } else if (type == 2) {
////                                url = ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false";
////                            } else if (type == 3) {
////                                url = ip + ":" + req_path + "/outsideChainxj?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false";
////                            }
//                            if (type == 1) {
//                                //随访
//                                ServiceOutPath serviceOutPath = new ServiceOutPath();
//                                serviceOutPath.setParam1(taskId);
//                                serviceOutPath.setParam2(patid);
//                                serviceOutPath.setCreateTime(new Date());
//                                iServiceOutPathService.insertServiceOutPath(serviceOutPath);
//                                String format = String.format("%03X", serviceOutPath.getId());
//                                serviceOutPath.setRadix(format);
//                                serviceOutPath.setUpdateTime(new Date());
//                                iServiceOutPathService.updateServiceOutPath(serviceOutPath);
////                                sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "&param2=" + patid + "&param5=false");
//                                url = ip + ":" + req_path + "/sf?p=" + format;
//                            } else if (type == 2) {
//                                //问券
//                                ServiceOutPath serviceOutPath = new ServiceOutPath();
//                                serviceOutPath.setParam1(taskId);
//                                serviceOutPath.setParam2(patid);
////                                serviceOutPath.setParam3(URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()));
//                                serviceOutPath.setParam3(ivrTask1.getTaskName());
//                                serviceOutPath.setCreateTime(new Date());
//                                iServiceOutPathService.insertServiceOutPath(serviceOutPath);
//                                String format = String.format("%03X", serviceOutPath.getId());
//                                serviceOutPath.setRadix(format);
//                                serviceOutPath.setUpdateTime(new Date());
//                                iServiceOutPathService.updateServiceOutPath(serviceOutPath);
////                                sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "&param2=" + patid + "&param3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "&param5=false");
//                                url = ip + ":" + req_path + "/wt?p=" + format;
//                            } else if (type == 3) {
//                                //宣教
//                                ServiceOutPath serviceOutPath = new ServiceOutPath();
//                                serviceOutPath.setParam1(taskId);
//                                serviceOutPath.setParam2(patid);
////                                serviceOutPath.setParam3(URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()));
//                                serviceOutPath.setParam3(ivrTask1.getTaskName());
//                                serviceOutPath.setCreateTime(new Date());
//                                iServiceOutPathService.insertServiceOutPath(serviceOutPath);
//                                String format = String.format("%03X", serviceOutPath.getId());
//                                serviceOutPath.setRadix(format);
//                                serviceOutPath.setUpdateTime(new Date());
//                                iServiceOutPathService.updateServiceOutPath(serviceOutPath);
//                                url = ip + ":" + req_path + "/xj?p=" + format;
//                            }
//
//                            String wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), "无");
//                            Map<String, Object> map = JSONObject.parseObject(wxCode, Map.class);
//                            if (!map.isEmpty()) {
                                serviceSubtask.setResult("success");
                                serviceSubtask.setSendstate(3L);
                                if ((Boolean) map.get("succ") == false) {
                                if (aBoolean == false) {
                                    ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
                                    serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString());
                                    serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId());
@@ -413,7 +501,7 @@
                                    serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord);
                                    continue;
                                }
                            }
//                            }
                        } catch (Exception e) {
                            ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
                            serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString());