liusheng
2025-09-29 55f5271f893a25a7be671b24938e49976936a67b
smartor/src/main/java/com/smartor/service/impl/CommonTaskServiceImpl.java
@@ -60,7 +60,6 @@
            //宣教
            return xjSend(sendTaskVO);
        }
        log.error("走到这里了嘛");
        return null;
    }
@@ -108,6 +107,8 @@
        //判断任务是否是立即发送
        if (StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("2")) {
            String content = sendMQContent(sendTaskVO, ivrTask.getTemplateid().toString(), ivrTask.getPreachform(), ivrTask.getStopState(), null);
            //先修改状态
            updateServiceSubtask(ivrTask.getTaskid(), new Date());
            //立即发送
            redisCache.setCacheObject(content, content, 1, TimeUnit.SECONDS);
            //将任务状态修改成执行中
@@ -130,23 +131,23 @@
                } catch (JsonProcessingException e) {
                    log.error("JsonProcessingException报错了:{}", e.getMessage());
                }
                Date date = new Date();
                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);
                        date = sdf.parse(begantime);
                        milliseconds = date.getTime() - System.currentTimeMillis();
                        System.out.println("日期毫秒数:" + milliseconds);
                        SendTaskVO sendTaskVO1 = DtoConversionUtils.sourceToTarget(sendTaskVO, SendTaskVO.class);
                        sendTaskVO1.setSendType("1");
                        String content = sendMQContent(sendTaskVO1, ivrTask.getTemplateid().toString(), ivrTask.getPreachform(), ivrTask.getStopState(), taskSendTimeVO);
                        //先修改状态
                        updateServiceSubtask(ivrTask.getTaskid(), date);
                        redisCache.setCacheObject(content, content, milliseconds / 1000, TimeUnit.SECONDS);
                    } catch (Exception e) {
                        e.printStackTrace();
@@ -208,6 +209,8 @@
        if (StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("2")) {
            String content = sendMQContent(sendTaskVO, serviceTask1.getTemplateid().toString(), serviceTask1.getPreachform(), serviceTask1.getStopState(), null);
            //先修改状态
            updateServiceSubtask(serviceTask1.getTaskid(), new Date());
            //立即发送
            redisCache.setCacheObject(content, content, 1, TimeUnit.SECONDS);
@@ -228,6 +231,7 @@
                } catch (JsonProcessingException e) {
                    log.error("JsonProcessingException报错了:{}", e.getMessage());
                }
                Date date = new Date();
                for (TaskSendTimeVO taskSendTimeVO : taskSendTimeVOList) {
                    //去SendTimeslot中,获取所有的时间段
//                    List<TaskSendTimeVO> list = new ArrayList<>();
@@ -239,7 +243,7 @@
                    //记录目前到发送时间的毫秒值 (发送时间的毫秒值 - 当前时间的毫秒值)
                    Long milliseconds = 1000L;
                    try {
                        Date date = sdf.parse(begantime);
                        date = sdf.parse(begantime);
                        milliseconds = date.getTime() - System.currentTimeMillis();
                        if (milliseconds < 0) {
                            milliseconds = 1000L;
@@ -252,6 +256,8 @@
                    SendTaskVO sendTaskVO1 = DtoConversionUtils.sourceToTarget(sendTaskVO, SendTaskVO.class);
                    sendTaskVO1.setSendType("1");
                    String content = sendMQContent(sendTaskVO1, serviceTask1.getTemplateid().toString(), serviceTask1.getPreachform(), serviceTask1.getStopState(), taskSendTimeVO);
                    //先修改状态
                    updateServiceSubtask(serviceTask1.getTaskid(), date);
                    redisCache.setCacheObject(content, content, milliseconds / 1000, TimeUnit.SECONDS);
                }
                //将任务状态修改成执行中
@@ -310,6 +316,8 @@
        if (StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("2")) {
            String content = sendMQContent(sendTaskVO, serviceTask1.getLibtemplateid().toString(), serviceTask1.getPreachform(), serviceTask1.getStopState(), null);
            //先修改状态
            updateServiceSubtask(serviceTask1.getTaskid(), new Date());
            //立即发送
            redisCache.setCacheObject(content, content, 1, TimeUnit.SECONDS);
@@ -323,6 +331,7 @@
        } else if (StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("1") || StringUtils.isNotEmpty(sendTaskVO.getSendType()) && sendTaskVO.getSendType().equals("3")) {
            //时间段发送
            ObjectMapper objectMapper = new ObjectMapper();
            Date date = new Date();
            if (StringUtils.isNotEmpty(serviceTask1.getSendTimeSlot())) {
                List<TaskSendTimeVO> taskSendTimeVOList = null;
                try {
@@ -342,7 +351,7 @@
                    //记录目前到发送时间的毫秒值 (发送时间的毫秒值 - 当前时间的毫秒值)
                    Long milliseconds = 1000L;
                    try {
                        Date date = sdf.parse(begantime);
                        date = sdf.parse(begantime);
                        milliseconds = date.getTime() - System.currentTimeMillis();
                        System.out.println("日期毫秒数:" + milliseconds);
                    } catch (Exception e) {
@@ -352,6 +361,8 @@
                    SendTaskVO sendTaskVO1 = DtoConversionUtils.sourceToTarget(sendTaskVO, SendTaskVO.class);
                    sendTaskVO1.setSendType("1");
                    String content = sendMQContent(sendTaskVO1, serviceTask1.getTemplateid().toString(), serviceTask1.getPreachform(), serviceTask1.getStopState(), taskSendTimeVO);
                    //先修改状态
                    updateServiceSubtask(serviceTask1.getTaskid(), date);
                    redisCache.setCacheObject(content, content, milliseconds / 1000, TimeUnit.SECONDS);
                }
                //将任务状态修改成执行中
@@ -389,4 +400,17 @@
        commonTaskcallMQJson = commonTaskcallMQJson.substring(1, commonTaskcallMQJson.length() - 1);
        return commonTaskcallMQJson;
    }
    private void updateServiceSubtask(Long taskId, Date date) {
        //只要进入队列就算待发送
        ServiceSubtaskVO serviceSubtaskVO = new ServiceSubtaskVO();
        serviceSubtaskVO.setTaskid(taskId);
        serviceSubtaskVO.setSendstate(1L);
        List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
        for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
            serviceSubtask.setSendstate(2L);
            serviceSubtask.setVisitTime(date);
            serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
        }
    }
}