| | |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.smartor.config.RabbitMqCallPhoneConfig; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | private IvrLibaTemplateTargetoptionMapper ivrLibaTemplateTargetOptionMapper; |
| | | |
| | | @Autowired |
| | | private RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig; |
| | | private RedisCache redisCache; |
| | | |
| | | /** |
| | | * 查询语音任务 |
| | |
| | | return ivrLibaTemplateScriptVOS; |
| | | } |
| | | |
| | | /** |
| | | * 任务发送 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int taskSend(SendTaskVO sendTaskVO) { |
| | | if (sendTaskVO.getTaskId() == null) throw new BaseException("任务ID不能为空,请检查后,再进行执行"); |
| | | IvrTask ivrTask = 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()); |
| | | updateIvrTask(ivrTask3); |
| | | return 0; |
| | | } |
| | | |
| | | //判断发送状态是否为空 |
| | | if (org.apache.commons.lang3.StringUtils.isEmpty(sendTaskVO.getSendType())) { |
| | | sendTaskVO.setSendType(ivrTask.getSendType().toString()); |
| | | } |
| | | Long ss = ivrTask.getStopState() + 1; |
| | | //判断任务是否是立即发送 |
| | | if (org.apache.commons.lang3.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); |
| | | updateIvrTask(ivrTask2); |
| | | } else if (org.apache.commons.lang3.StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("1")) { |
| | | //时间段发送 |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | if (org.apache.commons.lang3.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); |
| | | updateIvrTask(ivrTask2); |
| | | } |
| | | } |
| | | return 1; |
| | | } |
| | | } |