liusheng
2024-06-27 afb277a81e060c6275f11e9f9f102b5dcfd80a72
smartor/src/main/java/com/smartor/service/impl/IvrTaskSingleServiceImpl.java
@@ -9,7 +9,6 @@
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.smartor.config.PhoneUtils;
import com.smartor.config.RabbitMqCallPhoneConfig;
import com.smartor.domain.*;
import com.smartor.mapper.*;
import com.smartor.service.IIvrTaskService;
@@ -21,7 +20,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.fasterxml.jackson.core.type.TypeReference;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -58,9 +56,6 @@
    @Autowired
    private IvrLibaExtemplatescriptMapper ivrLibaExtemplatescriptMapper;
    @Autowired
    private RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig;
    /**
@@ -100,6 +95,7 @@
        ivrTaskVO.setShowTimeMorn(ivrTask.getShowTimeMorn());
        ivrTaskVO.setShowTimeNoon(ivrTask.getShowTimeNoon());
        ivrTaskVO.setShowTimeNight(ivrTask.getShowTimeNight());
        ivrTaskVO.setPreachform(ivrTask.getPreachform());
        String sendTimeSlot = ivrTask.getSendTimeSlot();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
@@ -233,7 +229,7 @@
                    ivrTaskcall.setAddr(patTaskRelevance.getAddr());
                    ivrTaskcall.setPatid(patTaskRelevance.getPatid());
                    ivrTaskcall.setCreateTime(DateUtils.getNowDate());
                    ivrTaskcall.setCreateTime(DateUtils.getNowDate());
                    ivrTaskcall.setSendstate(1L);
                    ivrTaskcall.setType(ivrTaskVO.getHospType());
                    ivrTaskSingleMapper.insertIvrTaskcall(ivrTaskcall);
                    integer = ivrTaskcall.getId().intValue();
@@ -244,7 +240,9 @@
            //任务修改
            if (ObjectUtils.isNotEmpty(ivrTaskVO.getSendTimeslot()))
                ivrTask.setSendTimeSlot(JSON.toJSONString(ivrTaskVO.getSendTimeslot()));
            //修改操作,需要将stopState状态+1
            IvrTask ivrTask1 = ivrTaskService.selectIvrTaskByTaskid(ivrTask.getTaskid());
            ivrTask.setStopState(ivrTask1.getStopState() + 1);
            ivrTask.setTemplateid(ivrTaskVO.getLibtemplateid());
            ivrTaskService.updateIvrTask(ivrTask);
@@ -260,11 +258,15 @@
                    ivrTaskcall.setPatid(patTaskRelevance.getPatid());
                    ivrTaskcall.setType(ivrTaskVO.getHospType());
                    ivrTaskcall.setCreateTime(DateUtils.getNowDate());
                    ivrTaskcall.setTextParam(new Gson().toJson(ivrTaskVO.getTextParam()));
                    if (patTaskRelevance.getIsoperation() != null) {
                        if (patTaskRelevance.getIsoperation() == 2)
                            ivrTaskSingleMapper.updateIvrTaskcallByCondition(ivrTaskcall);
                        if (patTaskRelevance.getIsoperation() == 1) ivrTaskSingleMapper.insertIvrTaskcall(ivrTaskcall);
                        if (patTaskRelevance.getIsoperation() == 1) {
                            ivrTaskcall.setSendstate(1L);
                            ivrTaskSingleMapper.insertIvrTaskcall(ivrTaskcall);
                        }
                        if (patTaskRelevance.getIsoperation() == 3)
                            //  通过taskid和patid去删除该条数据
                            ivrTaskSingleMapper.deleteIvrTaskcallByCondition(ivrTaskVO.getTaskid(), patTaskRelevance.getPatid());
@@ -278,100 +280,6 @@
        return integer;
    }
    /**
     * 任务发送
     *
     * @return
     */
    @Override
    public int heTaskSend(SendTaskVO sendTaskVO) {
        if (sendTaskVO.getTaskId() == null) throw new BaseException("任务ID不能为空,请检查后,再进行执行");
        IvrTask ivrTask = ivrTaskService.selectIvrTaskByTaskid(sendTaskVO.getTaskId());
        if (sendTaskVO.getSendState() != null && sendTaskVO.getSendState() == 3 || sendTaskVO.getSendState() != null && sendTaskVO.getSendState() == 4) {
            //任务暂停或终止
            IvrTask ivrTask3 = new IvrTask();
            ivrTask3.setTaskid(sendTaskVO.getTaskId());
            ivrTask3.setStopState(ivrTask.getStopState() + 1);
            ivrTask3.setSendState(sendTaskVO.getSendState());
            ivrTaskService.updateIvrTask(ivrTask3);
            return 0;
        }
        //判断发送状态是否为空
        if (StringUtils.isEmpty(sendTaskVO.getSendType())) {
            sendTaskVO.setSendType(ivrTask.getSendType().toString());
        }
        Long ss = ivrTask.getStopState() + 1;
        //判断任务是否是立即发送
        if (StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("2")) {
            IvrTaskcallMQ ivrTaskcallMQ = new IvrTaskcallMQ();
            ivrTaskcallMQ.setTaskid(sendTaskVO.getTaskId());
            ivrTaskcallMQ.setSendType(sendTaskVO.getSendType());
            ivrTaskcallMQ.setTemplateid(ivrTask.getTemplateid().toString());
            ivrTaskcallMQ.setStopState(ss);
            ivrTaskcallMQ.setPreachform(ivrTask.getPreachform());
            String ivrTaskcallMQJson = JSON.toJSONString(ivrTaskcallMQ);
            ivrTaskcallMQJson = ivrTaskcallMQJson.substring(1, ivrTaskcallMQJson.length() - 1);
            //立即发送
            rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.123", ivrTaskcallMQJson, 0L);
            //将任务状态修改成执行中
            IvrTask ivrTask2 = new IvrTask();
            ivrTask2.setTaskid(ivrTask.getTaskid());
            ivrTask2.setSendState(2);
            ivrTask2.setStopState(ss);
            ivrTaskService.updateIvrTask(ivrTask2);
        } else if (StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("1")) {
            //时间段发送
            ObjectMapper objectMapper = new ObjectMapper();
            if (StringUtils.isNotEmpty(ivrTask.getSendTimeSlot())) {
                List<TaskSendTimeVO> taskSendTimeVOList = null;
                try {
                    taskSendTimeVOList = objectMapper.readValue(ivrTask.getSendTimeSlot(), new TypeReference<List<TaskSendTimeVO>>() {
                    });
                } catch (JsonProcessingException e) {
                    log.error("JsonProcessingException报错了:{}", e.getMessage());
                }
                for (TaskSendTimeVO taskSendTimeVO : taskSendTimeVOList) {
                    //去SendTimeslot中,获取所有的时间段
                    List<TaskSendTimeVO> list = new ArrayList<>();
                    list.add(taskSendTimeVO);
                    //获取开始发送时间
                    String begantime = taskSendTimeVO.getBegantime();
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    //记录目前到发送时间的毫秒值 (发送时间的毫秒值 - 当前时间的毫秒值)
                    Long milliseconds = 1000L;
                    try {
                        Date date = sdf.parse(begantime);
                        milliseconds = date.getTime() - System.currentTimeMillis();
                        System.out.println("日期毫秒数:" + milliseconds);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    IvrTaskcallMQ ivrTaskcallMQ = new IvrTaskcallMQ();
                    ivrTaskcallMQ.setTaskid(sendTaskVO.getTaskId());
                    ivrTaskcallMQ.setSendType("1");
                    ivrTaskcallMQ.setTemplateid(ivrTask.getTemplateid().toString());
                    ivrTaskcallMQ.setSendTimeslot(list);
                    ivrTaskcallMQ.setStopState(ivrTask.getStopState());
                    Long finalMilliseconds = milliseconds;
                    String ivrTaskcallMQJson = JSON.toJSONString(ivrTaskcallMQ);
                    ivrTaskcallMQJson = ivrTaskcallMQJson.substring(1, ivrTaskcallMQJson.length() - 1);
                    rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.123", ivrTaskcallMQJson, milliseconds);
                }
                //将任务状态修改成执行中
                IvrTask ivrTask2 = new IvrTask();
                ivrTask2.setTaskid(ivrTask.getTaskid());
                ivrTask2.setSendState(2);
                ivrTask2.setStopState(ss);
                ivrTaskService.updateIvrTask(ivrTask2);
            }
        }
        return 1;
    }
    @Override
    public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) {