From f54ec4e100973d0914082b00cc4fbfb7ec6b129a Mon Sep 17 00:00:00 2001 From: haown <454902499@qq.com> Date: Tue, 24 Sep 2024 17:10:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BE=E5=BA=A6=E5=AE=9E=E6=97=B6=E5=A4=96?= =?UTF-8?q?=E5=91=BC=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/AiboTaskTypeContant.java | 19 ++++ .../ScriptInfoTaskInfo.java | 15 +++ .../ScriptInfoTaskInfoMapper.java | 7 +- .../service/aibo/impl/AIOBServiceImpl.java | 71 +++++++++++-- ...SignPatientManageRouteNodeServiceImpl.java | 7 +- .../ScriptInfoTaskInfoMapper.xml | 44 ++++++++- .../quartz/task/UploadRobotPublishTask.java | 99 ++++++++++++++++++- 7 files changed, 249 insertions(+), 13 deletions(-) create mode 100644 postdischarge-common/src/main/java/com/xinelu/common/constant/AiboTaskTypeContant.java diff --git a/postdischarge-common/src/main/java/com/xinelu/common/constant/AiboTaskTypeContant.java b/postdischarge-common/src/main/java/com/xinelu/common/constant/AiboTaskTypeContant.java new file mode 100644 index 00000000..762ca1b1 --- /dev/null +++ b/postdischarge-common/src/main/java/com/xinelu/common/constant/AiboTaskTypeContant.java @@ -0,0 +1,19 @@ +package com.xinelu.common.constant; + +/** + * @description: 百度外呼任务类型常量 + * @author: haown + * @create: 2024-09-24 14:38 + **/ +public class AiboTaskTypeContant { + + /** + * 批量任务 + */ + public static final String BATCHTASK = "BATCH_TASK"; + + /** + * 实时任务 + */ + public static final String ACTUALTIMETASK = "ACTUAL_TIME_TASK"; +} diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/domain/scriptinfotaskinfo/ScriptInfoTaskInfo.java b/postdischarge-manage/src/main/java/com/xinelu/manage/domain/scriptinfotaskinfo/ScriptInfoTaskInfo.java index 0fc28d6e..e0083327 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/domain/scriptinfotaskinfo/ScriptInfoTaskInfo.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/domain/scriptinfotaskinfo/ScriptInfoTaskInfo.java @@ -2,6 +2,7 @@ package com.xinelu.manage.domain.scriptinfotaskinfo; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Data; @@ -43,6 +44,20 @@ public class ScriptInfoTaskInfo { */ private Long signPatientManageRouteNodeId; + /** + * 执行时间 + */ + private LocalDateTime executeTime; + + /** + * 百度外呼任务类型,BATCH_TASK:批量任务,ACTUAL_TIME_TASK:实时任务 + */ + private String aiobTaskType; + + /** 任务执行状态,已执行:EXECUTED,未执行:UNEXECUTED */ + @ApiModelProperty(value = "任务执行状态,已执行:EXECUTED,未执行:UNEXECUTED") + private String executeStatus; + /** * 创建时间 */ diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/scriptinfotaskinfo/ScriptInfoTaskInfoMapper.java b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/scriptinfotaskinfo/ScriptInfoTaskInfoMapper.java index 07a1d394..4868c43f 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/scriptinfotaskinfo/ScriptInfoTaskInfoMapper.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/mapper/scriptinfotaskinfo/ScriptInfoTaskInfoMapper.java @@ -1,6 +1,7 @@ package com.xinelu.manage.mapper.scriptinfotaskinfo; import com.xinelu.manage.domain.scriptinfotaskinfo.ScriptInfoTaskInfo; +import java.util.List; /** * 百度外呼话术任务临时表Mapper接口 @@ -10,7 +11,9 @@ import com.xinelu.manage.domain.scriptinfotaskinfo.ScriptInfoTaskInfo; */ public interface ScriptInfoTaskInfoMapper { - String getByNodeId(Long signPatientManageRouteNodeId); + String getByNodeId(Long signPatientManageRouteNodeId, String aiobTaskType); + + List selectList(ScriptInfoTaskInfo scriptInfoTaskInfo); /** * 新增百度外呼话术任务临时表 @@ -20,6 +23,8 @@ public interface ScriptInfoTaskInfoMapper { */ int insertScriptInfoTaskInfo(ScriptInfoTaskInfo scriptInfoTaskInfo); + int updateExecuteStatusByNodeId(Long signPatientManageRouteNodeId); + int deleteScriptInfoTaskInfo(); } diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/aibo/impl/AIOBServiceImpl.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/aibo/impl/AIOBServiceImpl.java index 72e7cbc7..c0953bc4 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/aibo/impl/AIOBServiceImpl.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/aibo/impl/AIOBServiceImpl.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.aliyuncs.exceptions.ClientException; import com.xinelu.common.config.AliYunSmsTwoConfig; +import com.xinelu.common.constant.AiboTaskTypeContant; import com.xinelu.common.constant.PhoneMessageRemindConstants; import com.xinelu.common.constant.TaskCreateTypeConstant; import com.xinelu.common.constant.TaskStatisticsTypeConstants; @@ -14,6 +15,7 @@ import com.xinelu.common.enums.ErrorStatusEnum; import com.xinelu.common.enums.NodeExecuteResultStatusEnum; import com.xinelu.common.enums.NodeExecuteStatusEnum; import com.xinelu.common.enums.PhoneDialMethodEnum; +import com.xinelu.common.enums.PhoneRedialTimesEnum; import com.xinelu.common.enums.TaskNodeTypeEnum; import com.xinelu.common.exception.ServiceException; import com.xinelu.common.utils.StringUtils; @@ -22,10 +24,12 @@ import com.xinelu.manage.domain.patientquestionoptionresult.PatientQuestionOptio import com.xinelu.manage.domain.patientquestionsubjectresult.PatientQuestionSubjectResult; import com.xinelu.manage.domain.patientquestionsubmitresult.PatientQuestionSubmitResult; import com.xinelu.manage.domain.patienttaskexecuterecord.PatientTaskExecuteRecord; +import com.xinelu.manage.domain.patientvisitrecord.PatientVisitRecord; import com.xinelu.manage.domain.phonedialrecord.PhoneDialRecord; import com.xinelu.manage.domain.questioninfo.QuestionInfo; import com.xinelu.manage.domain.questionsubjectoption.QuestionSubjectOption; import com.xinelu.manage.domain.scriptInfo.ScriptInfo; +import com.xinelu.manage.domain.scriptinfotaskinfo.ScriptInfoTaskInfo; import com.xinelu.manage.domain.signpatientmanageroute.SignPatientManageRoute; import com.xinelu.manage.domain.signpatientmanageroutenode.SignPatientManageRouteNode; import com.xinelu.manage.domain.signpatientrecord.SignPatientRecord; @@ -44,11 +48,13 @@ import com.xinelu.manage.mapper.patientquestionoptionresult.PatientQuestionOptio import com.xinelu.manage.mapper.patientquestionsubjectresult.PatientQuestionSubjectResultMapper; import com.xinelu.manage.mapper.patientquestionsubmitresult.PatientQuestionSubmitResultMapper; import com.xinelu.manage.mapper.patienttaskexecuterecord.PatientTaskExecuteRecordMapper; +import com.xinelu.manage.mapper.patientvisitrecord.PatientVisitRecordMapper; import com.xinelu.manage.mapper.phonedialrecord.PhoneDialRecordMapper; import com.xinelu.manage.mapper.questioninfo.QuestionInfoMapper; import com.xinelu.manage.mapper.questionsubject.QuestionSubjectMapper; import com.xinelu.manage.mapper.questionsubjectoption.QuestionSubjectOptionMapper; import com.xinelu.manage.mapper.scriptInfo.ScriptInfoMapper; +import com.xinelu.manage.mapper.scriptinfotaskinfo.ScriptInfoTaskInfoMapper; import com.xinelu.manage.mapper.signpatientmanageroute.SignPatientManageRouteMapper; import com.xinelu.manage.mapper.signpatientmanageroutenode.SignPatientManageRouteNodeMapper; import com.xinelu.manage.mapper.signpatientrecord.SignPatientRecordMapper; @@ -56,6 +62,7 @@ import com.xinelu.manage.mapper.textmessage.TextMessageMapper; import com.xinelu.manage.service.aibo.IAIOBService; import com.xinelu.manage.service.patienttaskstatistics.IPatientTaskStatisticsService; import com.xinelu.manage.service.signpatientmanageroute.ISignPatientManageRouteService; +import com.xinelu.manage.service.signpatientmanageroutenode.ISignPatientManageRouteNodeService; import com.xinelu.manage.vo.aibo.ImportTaskVo; import com.xinelu.manage.vo.labelfieldcontent.LabelFieldInfoContentVo; import com.xinelu.manage.vo.questionsubject.QuestionSubjectVO; @@ -73,6 +80,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; @@ -117,6 +125,8 @@ public class AIOBServiceImpl implements IAIOBService { @Resource private ISignPatientManageRouteService signPatientManageRouteService; @Resource + private ISignPatientManageRouteNodeService signPatientManageRouteNodeService; + @Resource private TextMessageMapper textMessageMapper; @Resource private PatientTaskExecuteRecordMapper patientTaskExecuteRecordMapper; @@ -130,7 +140,6 @@ public class AIOBServiceImpl implements IAIOBService { private ScriptInfoMapper scriptInfoMapper; @Resource private QuestionInfoMapper questionInfoMapper; - @Resource private PatientQuestionSubmitResultMapper questionSubmitResultMapper; @Resource @@ -141,6 +150,10 @@ public class AIOBServiceImpl implements IAIOBService { private QuestionSubjectOptionMapper questionSubjectOptionMapper; @Resource private PatientQuestionOptionResultMapper patientQuestionOptionResultMapper; + @Resource + private ScriptInfoTaskInfoMapper scriptInfoTaskInfoMapper; + @Resource + private PatientVisitRecordMapper patientVisitRecordMapper; /** * @description 获取外呼平台accessToken @@ -344,23 +357,35 @@ public class AIOBServiceImpl implements IAIOBService { if (callbackType == 0 || callbackType == 3) { // 是否发送短信标识 boolean needSendSms = false; + // 是否重拨 + boolean needRedial = false; // 根据id查询任务 SignPatientManageRouteNode signPatientManageRouteNode = signPatientManageRouteNodeMapper.selectSignPatientManageRouteNodeById(Long.valueOf(data.getExtJson())); if (ObjectUtils.isNotEmpty(signPatientManageRouteNode)) { // 标记任务执行状态 signPatientManageRouteNode.setNodeExecuteStatus(NodeExecuteStatusEnum.EXECUTED.getInfo()); - // 获取电话已拨打次数 - PhoneDialRecord phoneDialRecordQuery = new PhoneDialRecord(); - phoneDialRecordQuery.setManageRouteNodeId(signPatientManageRouteNode.getId()); - // 电话拨打未成功,判断是否需要重拨;电话拨打成功,设置电话拨通情况为成功 - if (data.getEndType() != null && data.getEndType() == 0) {//接通状态,1-已接通 0-未接通 - // 不需要重拨,设置电话拨通情况 + //接通状态,1-已接通 0-未接通 + if (data.getEndType() != null && data.getEndType() == 0) { + // 设置电话拨通情况 signPatientManageRouteNode.setPhoneNodeExecuteResultStatus(NodeExecuteResultStatusEnum.FAILURE.getInfo()); // 电话短信提醒 if (StringUtils.equals(PhoneMessageRemindConstants.NOT_CONNECTED_SEND_MESSAGE, signPatientManageRouteNode.getPhoneMessageRemind())) { // 发送短信 needSendSms = true; } + + // 实时任务设置电话重拨 + if (callbackType == 3) { + // 查询拨打次数 + PhoneDialRecord phoneDialRecordQuery = new PhoneDialRecord(); + phoneDialRecordQuery.setManageRouteNodeId(signPatientManageRouteNode.getId()); + List phoneDialRecordList = phoneDialRecordMapper.selectPhoneDialRecordList(phoneDialRecordQuery); + if (CollectionUtils.isEmpty(phoneDialRecordList) || phoneDialRecordList.size() + 1 < PhoneRedialTimesEnum.getValueByInfo(signPatientManageRouteNode.getPhoneRedialTimes()).getValue()) { + // 重拨 + needRedial = true; + } + + } } else { signPatientManageRouteNode.setPhoneNodeExecuteResultStatus(NodeExecuteResultStatusEnum.SUCCESS.getInfo()); if (StringUtils.equals(PhoneMessageRemindConstants.CONNECTED_SEND_MESSAGE, signPatientManageRouteNode.getPhoneMessageRemind())) { @@ -373,9 +398,15 @@ public class AIOBServiceImpl implements IAIOBService { signPatientManageRouteNodeMapper.updateSignPatientManageRouteNode(signPatientManageRouteNode); + // 重拨表任务执行状态修改 + ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo(); + scriptInfoTaskInfo.setSignPatientManageRouteNodeId(signPatientManageRouteNode.getRouteNodeId()); + scriptInfoTaskInfo.setAiobTaskType(AiboTaskTypeContant.ACTUALTIMETASK); + scriptInfoTaskInfoMapper.updateExecuteStatusByNodeId(signPatientManageRouteNode.getRouteNodeId()); + + // 任务执行记录 PatientTaskExecuteRecord patientTaskExecuteRecord = new PatientTaskExecuteRecord(); BeanUtils.copyProperties(signPatientManageRouteNode, patientTaskExecuteRecord); - SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper.selectSignPatientManageRouteById(signPatientManageRouteNode.getManageRouteId()); if (ObjectUtils.isNotEmpty(signPatientManageRoute)) { patientTaskExecuteRecord.setPatientId(signPatientManageRoute.getPatientId()); @@ -390,6 +421,11 @@ public class AIOBServiceImpl implements IAIOBService { if (needSendSms) { sendSms(signPatientManageRoute.getPatientId(), signPatientManageRouteNode); } + // 重拨 + if (needRedial) { + PatientVisitRecord patientVisitRecord = patientVisitRecordMapper.selectPatientVisitRecordById(signPatientRecord.getPatientVisitRecordId()); + redialInfoSave(signPatientManageRouteNode, patientVisitRecord); + } } // 增加任务执行记录 patientTaskExecuteRecord.setManageRouteNodeId(signPatientManageRouteNode.getId()); @@ -422,6 +458,7 @@ public class AIOBServiceImpl implements IAIOBService { if (StringUtils.equals(signPatientManageRouteNode.getTaskNodeType(), TaskNodeTypeEnum.QUESTIONNAIRE_SCALE.getInfo())) { parseQuestionInfo(data.getRecord(), signPatientManageRouteNode, signPatientManageRoute.getPatientId(), patientTaskExecuteRecord.getId()); } + } } return retObj; @@ -610,4 +647,22 @@ public class AIOBServiceImpl implements IAIOBService { return questionName; } + /** + * @description 重拨信息保存 + * @param signPatientManageRouteNode 任务信息 + * @param patientVisitRecord 就诊记录信息 + * @Author haown + * @Date 2024-9-24 15:08 + */ + private void redialInfoSave(SignPatientManageRouteNode signPatientManageRouteNode, PatientVisitRecord patientVisitRecord) { + ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo(); + scriptInfoTaskInfo.setScriptInfoId(signPatientManageRouteNode.getScriptInfoId()); + scriptInfoTaskInfo.setRobotId(signPatientManageRouteNode.getRobotPublishId()); + scriptInfoTaskInfo.setCreateTime(LocalDateTime.now()); + scriptInfoTaskInfo.setSignPatientManageRouteNodeId(signPatientManageRouteNode.getId()); + scriptInfoTaskInfo.setAiobTaskType(AiboTaskTypeContant.ACTUALTIMETASK); + LocalDateTime executeTime = signPatientManageRouteNodeService.getExecuteTime(signPatientManageRouteNode.getExecuteTime(), signPatientManageRouteNode.getRouteNodeName(), signPatientManageRouteNode.getRouteNodeDay(), patientVisitRecord); + scriptInfoTaskInfo.setExecuteTime(executeTime.minusMinutes(signPatientManageRouteNode.getPhoneTimeInterval())); + scriptInfoTaskInfoMapper.insertScriptInfoTaskInfo(scriptInfoTaskInfo); + } } diff --git a/postdischarge-manage/src/main/java/com/xinelu/manage/service/signpatientmanageroutenode/impl/SignPatientManageRouteNodeServiceImpl.java b/postdischarge-manage/src/main/java/com/xinelu/manage/service/signpatientmanageroutenode/impl/SignPatientManageRouteNodeServiceImpl.java index 145e9292..419a84dd 100644 --- a/postdischarge-manage/src/main/java/com/xinelu/manage/service/signpatientmanageroutenode/impl/SignPatientManageRouteNodeServiceImpl.java +++ b/postdischarge-manage/src/main/java/com/xinelu/manage/service/signpatientmanageroutenode/impl/SignPatientManageRouteNodeServiceImpl.java @@ -722,6 +722,10 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage generateByManageRoute(signPatientManageRoute, signPatientRecord.getPatientId()); } + /** + * 手动创建的任务标签替换 + * @param signRecordId 签约记录主键 + */ @Override @Transactional(rollbackFor = Exception.class) public void manualCreateTaskLabelReplace(Long signRecordId) { @@ -1232,9 +1236,8 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage .taskExecuteNum(BigDecimal.ZERO) .taskFinishNum(BigDecimal.ZERO) .build()); - } - // 任务上传至爱医生 + } } private String replaceNodeContent(String nodeContent, List paramsList) { diff --git a/postdischarge-manage/src/main/resources/mapper/manage/scriptinfotaskinfo/ScriptInfoTaskInfoMapper.xml b/postdischarge-manage/src/main/resources/mapper/manage/scriptinfotaskinfo/ScriptInfoTaskInfoMapper.xml index 4ac9a008..49c8e665 100644 --- a/postdischarge-manage/src/main/resources/mapper/manage/scriptinfotaskinfo/ScriptInfoTaskInfoMapper.xml +++ b/postdischarge-manage/src/main/resources/mapper/manage/scriptinfotaskinfo/ScriptInfoTaskInfoMapper.xml @@ -9,6 +9,10 @@ + + + + @@ -17,6 +21,10 @@ script_info_id, robot_id, task_id, + sign_patient_manage_route_node_id, + execute_time, + aiob_task_type, + execute_status, create_time, from script_info_task_info @@ -24,7 +32,24 @@ + + sign_patient_manage_route_node_id, + execute_time, + + aiob_task_type, + + execute_status, + create_time, @@ -51,11 +82,22 @@ #{signPatientManageRouteNodeId}, + #{executeTime}, + + #{aiobTaskType}, + + #{executeStatus}, + #{createTime}, + + update script_info_task_info set execute_status = 'EXECUTED' + where signPatientManageRouteNodeId = #{signPatientManageRouteNodeId} + + update script_info_task_info set del_flag = 1 where del_flag = 0 diff --git a/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/UploadRobotPublishTask.java b/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/UploadRobotPublishTask.java index 289af93b..bc9032cb 100644 --- a/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/UploadRobotPublishTask.java +++ b/postdischarge-quartz/src/main/java/com/xinelu/quartz/task/UploadRobotPublishTask.java @@ -1,6 +1,7 @@ package com.xinelu.quartz.task; import com.alibaba.fastjson2.JSONObject; +import com.xinelu.common.constant.AiboTaskTypeContant; import com.xinelu.common.enums.NodeExecuteStatusEnum; import com.xinelu.common.enums.PhoneDialMethodEnum; import com.xinelu.common.enums.PhoneRedialTimesEnum; @@ -12,6 +13,7 @@ import com.xinelu.manage.domain.scriptinfotaskinfo.ScriptInfoTaskInfo; import com.xinelu.manage.domain.signpatientmanageroute.SignPatientManageRoute; import com.xinelu.manage.domain.signpatientmanageroutenode.SignPatientManageRouteNode; import com.xinelu.manage.domain.signpatientrecord.SignPatientRecord; +import com.xinelu.manage.dto.aibo.ActualTimeTaskDto; import com.xinelu.manage.dto.aibo.CreateTaskDto; import com.xinelu.manage.dto.aibo.CustomerInfoDto; import com.xinelu.manage.dto.aibo.ImportTaskDto; @@ -103,7 +105,7 @@ public class UploadRobotPublishTask { // 根据机器人id查询智能外呼系统的任务id executeNodeList.forEach(node -> { ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(node.getScriptInfoId()); - String taskId = scriptInfoTaskInfoMapper.getByNodeId(node.getId()); + String taskId = scriptInfoTaskInfoMapper.getByNodeId(node.getId(), AiboTaskTypeContant.BATCHTASK); if (StringUtils.isBlank(taskId)) { // 没有任务则创建任务 if (ObjectUtils.isNotEmpty(scriptInfo)) { @@ -130,6 +132,7 @@ public class UploadRobotPublishTask { scriptInfoTaskInfo.setRobotId(scriptInfo.getRobotPublishId()); scriptInfoTaskInfo.setCreateTime(LocalDateTime.now()); scriptInfoTaskInfo.setSignPatientManageRouteNodeId(node.getId()); + scriptInfoTaskInfo.setAiobTaskType(AiboTaskTypeContant.BATCHTASK); scriptInfoTaskInfoMapper.insertScriptInfoTaskInfo(scriptInfoTaskInfo); } } @@ -177,6 +180,100 @@ public class UploadRobotPublishTask { log.info("百度智能外呼创建任务定时任务执行完成......"); } + /** + * @description 创建实时任务 + * @return null + * @Author haown + * @Date 2024-9-23 10:41 + */ + public void actualTimeTask() { + log.info("开始执行百度智能外呼创建实时任务定时任务......"); + // 查找需要当天执行的AI打电话任务(问卷或电话外呼类型) + SignPatientManageRouteNodeDto signPatientManageRouteNodeDto = new SignPatientManageRouteNodeDto(); + signPatientManageRouteNodeDto.setNodeExecuteStatus(NodeExecuteStatusEnum.UNEXECUTED.getInfo()); + signPatientManageRouteNodeDto.setPhoneDialMethod(PhoneDialMethodEnum.AI.getInfo()); + List nodeList = signPatientManageRouteNodeMapper.selectSignPatientManageRouteNodeList(signPatientManageRouteNodeDto); + List executeNodeList = new ArrayList<>(); + nodeList.forEach(node -> { + SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper.selectSignPatientManageRouteById(node.getManageRouteId()); + SignPatientRecord signPatientRecord = signPatientRecordMapper.selectByPrimaryKey(signPatientManageRoute.getSignPatientRecordId()); + PatientVisitRecord patientVisitRecord = patientVisitRecordMapper.selectPatientVisitRecordById(signPatientRecord.getPatientVisitRecordId()); + LocalDateTime executeTime = signPatientManageRouteNodeService.getExecuteTime(node.getExecuteTime(), node.getRouteNodeName(), node.getRouteNodeDay(), patientVisitRecord); + if (node.getScriptInfoId() != null && (executeTime.toLocalDate().isBefore(LocalDate.now()) || executeTime.toLocalDate().isEqual(LocalDate.now()))) { + executeNodeList.add(node); + } + }); + + // 查询需要重拨的任务 + ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo(); + List scriptInfoTaskInfoList = scriptInfoTaskInfoMapper.selectList(scriptInfoTaskInfo); + scriptInfoTaskInfoList.forEach(taskInfo -> { + SignPatientManageRouteNode node = signPatientManageRouteNodeMapper.selectSignPatientManageRouteNodeById(taskInfo.getSignPatientManageRouteNodeId()); + if (taskInfo.getExecuteTime().isBefore(LocalDateTime.now()) || taskInfo.getExecuteTime().isEqual(LocalDateTime.now())) { + executeNodeList.add(node); + } + }); + if (CollectionUtils.isNotEmpty(executeNodeList)) { + // 根据机器人id查询智能外呼系统的任务id + executeNodeList.forEach(node -> { + createTask(node); + }); + } + log.info("百度智能外呼创建实时任务定时任务执行完成......"); + } + + /** + * @description 创建重拨任务 + * @return null + * @Author haown + * @Date 2024-9-24 16:10 + */ + //public void redialTask() { + // log.info("开始执行重拨任务定时任务......"); + // List executeNodeList = new ArrayList<>(); + // // 查询需要重拨的任务 + // ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo(); + // List scriptInfoTaskInfoList = scriptInfoTaskInfoMapper.selectList(scriptInfoTaskInfo); + // scriptInfoTaskInfoList.forEach(taskInfo -> { + // SignPatientManageRouteNode node = signPatientManageRouteNodeMapper.selectSignPatientManageRouteNodeById(taskInfo.getSignPatientManageRouteNodeId()); + // if (taskInfo.getExecuteTime().isBefore(LocalDateTime.now()) || taskInfo.getExecuteTime().isEqual(LocalDateTime.now())) { + // createTask(node); + // } + // }); + // log.info("重拨任务定时任务执行完成......"); + //} + + private void createTask(SignPatientManageRouteNode node) { + ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(node.getScriptInfoId()); + SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper.selectSignPatientManageRouteById(node.getManageRouteId()); + PatientInfo patientInfo = patientInfoMapper.selectPatientInfoById(signPatientManageRoute.getPatientId()); + // 没有任务则创建任务 + if (ObjectUtils.isNotEmpty(scriptInfo)) { + log.info("创建任务......"); + ActualTimeTaskDto actualTimeTaskDto = new ActualTimeTaskDto(); + actualTimeTaskDto.setRobotId(scriptInfo.getRobotPublishId()); + actualTimeTaskDto.setMobile(patientInfo.getPatientPhone()); + actualTimeTaskDto.setSecretType(2); + actualTimeTaskDto.setStopDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + // 查询患者画像信息 + List labelFieldContentList = labelFieldContentMapper.selectByPatientId(patientInfo.getId()); + // 处理变量 + JSONObject jsonObject = new JSONObject(); + if (StringUtils.isNotBlank(scriptInfo.getVariables())) { + List variables = Arrays.asList(scriptInfo.getVariables().split("\\|")); + variables.forEach(variable -> { + LabelFieldInfoContentVo labelFieldContent = labelFieldContentList.stream().filter(s -> Objects.equals(s.getFieldCode(), variable.replaceAll("_", "").toUpperCase())).findFirst().orElse(null); + jsonObject.fluentPut(variable, ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue()); + }); + } + actualTimeTaskDto.setDialogVar(jsonObject); + actualTimeTaskDto.setCallBackUrl(callBackUrl); + actualTimeTaskDto.setExtJson(node.getId()+ ""); + aiobService.createActualTimeTask(actualTimeTaskDto); + log.info("创建任务完成......"); + } + } + /** * @description 删除话术任务记录表信息,每天晚上执行一次 * @Author haown