liusheng
2024-07-02 0b02577ab12ac83a0530b7e0495b513dd0cdabca
ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java
@@ -10,11 +10,12 @@
import com.smartor.common.SendService;
import com.smartor.config.RobotPhoneUtils;
import com.smartor.domain.*;
import com.smartor.mapper.IvrTaskMapper;
import com.smartor.mapper.IvrTaskSingleMapper;
import com.smartor.mapper.ServiceSubtaskMapper;
import com.smartor.mapper.ServiceTaskMapper;
import com.smartor.mapper.SvyTaskMapper;
import com.smartor.mapper.SvyTaskSingleMapper;
import com.smartor.service.IIvrTaskTemplateService;
import com.smartor.service.IServiceSubtaskRecordService;
import com.smartor.service.ISvyTaskTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,9 +25,7 @@
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -46,9 +45,9 @@
    private static IIvrTaskTemplateService ivrTaskTemplateService;
    private static IvrTaskSingleMapper ivrTaskcallMapper;
    private static ServiceSubtaskMapper ivrTaskcallMapper;
    private static IvrTaskMapper ivrTaskMapper;
    private static ServiceTaskMapper ivrTaskMapper;
    private static SendService sendService;
@@ -64,6 +63,9 @@
    @Autowired
    private ISvyTaskTemplateService iSvyTaskTemplateService;
    @Autowired
    private IServiceSubtaskRecordService serviceSubtaskRecordService;
    // 创建固定大小的线程池
    private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
@@ -89,12 +91,12 @@
    }
    @Autowired
    public void setIvrTaskcallMapper(IvrTaskSingleMapper ivrTaskcallMapper) {
    public void setIvrTaskcallMapper(ServiceSubtaskMapper ivrTaskcallMapper) {
        RedisMqReceiver.ivrTaskcallMapper = ivrTaskcallMapper;
    }
    @Autowired
    public void setIvrTaskMapper(IvrTaskMapper ivrTaskMapper) {
    public void setIvrTaskMapper(ServiceTaskMapper ivrTaskMapper) {
        RedisMqReceiver.ivrTaskMapper = ivrTaskMapper;
    }
@@ -155,7 +157,7 @@
     */
    private void sfHandle(CommonTaskcallMQ commonTaskcallMQ) {
        //判断一下commonTaskcallMQ中的stopstate是否与ivr_task中的一致,不一致,则说明是暂停了
        IvrTask ivrTask1 = ivrTaskMapper.selectIvrTaskByTaskid(commonTaskcallMQ.getTaskid());
        ServiceTask ivrTask1 = ivrTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid());
        if (ivrTask1.getStopState() != commonTaskcallMQ.getStopState()) {
            //将消息从队列中剔除
            return;
@@ -175,16 +177,26 @@
                IvrTaskTemplateVO ivrTaskTemplateVO1 = ivrTaskTemplateService.selectInfoByCondition(ivrTaskTemplateVO);
                //通过任务ID拿到患者信息
                IvrTaskSingle ivrTaskcall = new IvrTaskSingle();
                ServiceSubtask ivrTaskcall = new ServiceSubtask();
                ivrTaskcall.setTaskid(commonTaskcallMQ.getTaskid());
                List<IvrTaskSingle> ivrTaskcalls = ivrTaskcallMapper.selectIvrTaskcallList(ivrTaskcall);
                List<ServiceSubtask> ivrTaskcalls = ivrTaskcallMapper.selectServiceSubtaskList(ivrTaskcall);
                if (descByCode.equals("电话")) {
                    for (IvrTaskSingle ivrTaskcall1 : ivrTaskcalls) {
                        IvrTask ivrTask = ivrTaskMapper.selectIvrTaskByTaskid(ivrTaskcall1.getTaskid());
                    for (ServiceSubtask ivrTaskcall1 : ivrTaskcalls) {
                        ServiceTask ivrTask = ivrTaskMapper.selectServiceTaskByTaskid(ivrTaskcall1.getTaskid());
                        if (ivrTask.getSendState() != null && ivrTask.getSendState() == 3 || ivrTask.getSendState() != null && ivrTask.getSendState() == 4) {
                            //如何任务被“暂停”或“终止”
                            break;
                        }
                        //任务发送记录(这个代码应该写在phoneTask中,先写在这,后面再改)
                        ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
                        serviceSubtaskRecord.setTaskid(ivrTaskcall1.getTaskid().toString());
                        serviceSubtaskRecord.setUuid(UUID.randomUUID().toString());
                        serviceSubtaskRecord.setTasktype(ivrTaskcall1.getType());
                        serviceSubtaskRecord.setPreachform("3");
                        serviceSubtaskRecord.setStartTime(System.currentTimeMillis());
                        serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord);
                        //通过多线程的方式去打电话
                        executorService.submit(new PhoneTask(ivrTaskcall1, ivrTaskTemplateVO1, redisCache, sendService, phonePath, robotPhoneUtils));
                    }
@@ -200,18 +212,28 @@
                    String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key);
                    for (IvrTaskSingle ivrTaskSingle : ivrTaskcalls) {
                    for (ServiceSubtask ivrTaskSingle : ivrTaskcalls) {
                        String patid = rsaPublicKeyExample.encryptedData(ivrTaskSingle.getPatid().toString(), pub_key);
                        SendMagParam sendMagParam = new SendMagParam();
                        sendMagParam.setType("4");
                        sendMagParam.setUrl(req_path + "/followvisit/particty?param1=" + taskId + "&param2=" + patid);
                        sendService.sendMsg(sendMagParam);
                        Boolean aBoolean = sendService.sendMsg(sendMagParam);
                        //任务发送记录
                        ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
                        serviceSubtaskRecord.setTaskid(ivrTaskSingle.getTaskid().toString());
                        serviceSubtaskRecord.setUuid(UUID.randomUUID().toString());
                        serviceSubtaskRecord.setTasktype(ivrTaskSingle.getType());
                        serviceSubtaskRecord.setPreachform("4");
                        serviceSubtaskRecord.setStartTime(System.currentTimeMillis());
                        serviceSubtaskRecord.setResult(aBoolean == true ? "成功" : "失败");
                        serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord);
                    }
                } else if (descByCode.equals("公众号")) {
                    //公众号
                    RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
                    String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key);
                    for (IvrTaskSingle ivrTaskSingle : ivrTaskcalls) {
                    for (ServiceSubtask ivrTaskSingle : ivrTaskcalls) {
                        String patid = rsaPublicKeyExample.encryptedData(ivrTaskSingle.getPatid().toString(), pub_key);
                        SendMagParam sendMagParam = new SendMagParam();
                        sendMagParam.setType("5");
@@ -222,7 +244,17 @@
                        Map map = new HashMap();
                        map.put("first", ivrTask1.getTaskName());
                        sendMagParam.setContent(JSON.toJSONString(map));
                        sendService.sendMsg(sendMagParam);
                        Boolean aBoolean = sendService.sendMsg(sendMagParam);
                        //任务发送记录
                        ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
                        serviceSubtaskRecord.setTaskid(ivrTaskSingle.getTaskid().toString());
                        serviceSubtaskRecord.setUuid(UUID.randomUUID().toString());
                        serviceSubtaskRecord.setTasktype(ivrTaskSingle.getType());
                        serviceSubtaskRecord.setPreachform("4");
                        serviceSubtaskRecord.setStartTime(System.currentTimeMillis());
                        serviceSubtaskRecord.setResult(aBoolean == true ? "成功" : "失败");
                        serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord);
                    }
                }
                //通知 MQ 消息已被接收,可以ACK(从队列中删除)了   (这个需要根据业务再去处理ACK)
@@ -267,6 +299,15 @@
                            //如何任务被“暂停”或“终止”
                            break;
                        }
                        //任务发送记录(这个代码应该写在phoneTask中,先写在这,后面再改)
                        ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
                        serviceSubtaskRecord.setTaskid(svyTaskSingle1.getTaskid().toString());
                        serviceSubtaskRecord.setUuid(UUID.randomUUID().toString());
                        serviceSubtaskRecord.setTasktype(svyTaskSingle1.getType());
                        serviceSubtaskRecord.setPreachform("3");
                        serviceSubtaskRecord.setStartTime(System.currentTimeMillis());
                        serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord);
                        //通过多线程的方式去打电话
//                        executorService.submit(new PhoneTask(ivrTaskcall1, ivrTaskTemplateVO1, redisCache, sendService, phonePath, robotPhoneUtils));
                    }
@@ -291,7 +332,17 @@
                        Map map = new HashMap();
                        map.put("first", svyTask.getTaskName());
                        sendMagParam.setContent(JSON.toJSONString(map));
                        sendService.sendMsg(sendMagParam);
                        Boolean aBoolean = sendService.sendMsg(sendMagParam);
                        //任务发送记录
                        ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord();
                        serviceSubtaskRecord.setTaskid(svyTaskSingle1.getTaskid().toString());
                        serviceSubtaskRecord.setUuid(UUID.randomUUID().toString());
                        serviceSubtaskRecord.setTasktype(svyTaskSingle1.getType());
                        serviceSubtaskRecord.setPreachform("4");
                        serviceSubtaskRecord.setStartTime(System.currentTimeMillis());
                        serviceSubtaskRecord.setResult(aBoolean == true ? "成功" : "失败");
                        serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord);
                    }
                }
                //通知 MQ 消息已被接收,可以ACK(从队列中删除)了   (这个需要根据业务再去处理ACK)