@ -2,10 +2,7 @@ package com.xinelu.quartz.task;
import com.alibaba.fastjson2.JSONObject ;
import com.alibaba.fastjson2.JSONObject ;
import com.xinelu.common.constant.AiobTaskTypeContant ;
import com.xinelu.common.constant.AiobTaskTypeContant ;
import com.xinelu.common.enums.NodeExecuteStatusEnum ;
import com.xinelu.common.enums.* ;
import com.xinelu.common.enums.PhoneDialMethodEnum ;
import com.xinelu.common.enums.PhoneRedialTimesEnum ;
import com.xinelu.common.enums.TaskExcuteTypeEnum ;
import com.xinelu.common.utils.StringUtils ;
import com.xinelu.common.utils.StringUtils ;
import com.xinelu.manage.domain.patientinfo.PatientInfo ;
import com.xinelu.manage.domain.patientinfo.PatientInfo ;
import com.xinelu.manage.domain.patientvisitrecord.PatientVisitRecord ;
import com.xinelu.manage.domain.patientvisitrecord.PatientVisitRecord ;
@ -31,16 +28,17 @@ import com.xinelu.manage.service.aiob.IAIOBService;
import com.xinelu.manage.service.signpatientmanageroutenode.ISignPatientManageRouteNodeService ;
import com.xinelu.manage.service.signpatientmanageroutenode.ISignPatientManageRouteNodeService ;
import com.xinelu.manage.vo.aiob.ImportTaskVo ;
import com.xinelu.manage.vo.aiob.ImportTaskVo ;
import com.xinelu.manage.vo.labelfieldcontent.LabelFieldInfoContentVo ;
import com.xinelu.manage.vo.labelfieldcontent.LabelFieldInfoContentVo ;
import java.time.LocalDate ;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.time.LocalDateTime ;
import java.time.format.DateTimeFormatter ;
import java.time.format.DateTimeFormatter ;
import java.util.ArrayList ;
import java.util.* ;
import java.util.Arrays ;
import java.util.stream.Collectors ;
import java.util.List ;
import java.util.Objects ;
import javax.annotation.Resource ;
import javax.annotation.Resource ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.collections4.CollectionUtils ;
import org.apache.commons.collections4.CollectionUtils ;
import org.apache.commons.collections4.MapUtils ;
import org.apache.commons.lang3.ObjectUtils ;
import org.apache.commons.lang3.ObjectUtils ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.stereotype.Component ;
import org.springframework.stereotype.Component ;
@ -54,215 +52,250 @@ import org.springframework.stereotype.Component;
@Component ( " UploadRobotPublishTask " )
@Component ( " UploadRobotPublishTask " )
public class UploadRobotPublishTask {
public class UploadRobotPublishTask {
@Value ( " ${aiob.callBackUrl} " )
@Value ( " ${aiob.callBackUrl} " )
private String callBackUrl ;
private String callBackUrl ;
@Resource
@Resource
private SignPatientManageRouteNodeMapper signPatientManageRouteNodeMapper ;
private SignPatientManageRouteNodeMapper signPatientManageRouteNodeMapper ;
@Resource
@Resource
private ISignPatientManageRouteNodeService signPatientManageRouteNodeService ;
private ISignPatientManageRouteNodeService signPatientManageRouteNodeService ;
@Resource
@Resource
private SignPatientManageRouteMapper signPatientManageRouteMapper ;
private SignPatientManageRouteMapper signPatientManageRouteMapper ;
@Resource
@Resource
private SignPatientRecordMapper signPatientRecordMapper ;
private SignPatientRecordMapper signPatientRecordMapper ;
@Resource
@Resource
private PatientVisitRecordMapper patientVisitRecordMapper ;
private PatientVisitRecordMapper patientVisitRecordMapper ;
@Resource
@Resource
private ScriptInfoTaskInfoMapper scriptInfoTaskInfoMapper ;
private ScriptInfoTaskInfoMapper scriptInfoTaskInfoMapper ;
@Resource
@Resource
private IAIOBService aiobService ;
private IAIOBService aiobService ;
@Resource
@Resource
private ScriptInfoMapper scriptInfoMapper ;
private ScriptInfoMapper scriptInfoMapper ;
@Resource
@Resource
private PatientInfoMapper patientInfoMapper ;
private PatientInfoMapper patientInfoMapper ;
@Resource
@Resource
private LabelFieldContentMapper labelFieldContentMapper ;
private LabelFieldContentMapper labelFieldContentMapper ;
/ * *
/ * *
* @description 创建百度智能外呼任务并导入客户名单
* @description 创建百度智能外呼任务并导入客户名单
* @Author haown
* @Author haown
* @Date 2024 - 9 - 5 13 : 55
* @Date 2024 - 9 - 5 13 : 55
* /
* @Date 2024 - 12 - 11 重构批量执行
public void uploadRobotPublishTask ( ) {
* /
log . info ( " 开始执行百度智能外呼创建任务定时任务...... " ) ;
public void uploadRobotPublishTask ( ) {
/ / 查找需要当天执行的AI打电话任务 ( 问卷或电话外呼类型 )
log . info ( " 开始执行百度智能外呼创建任务定时任务...... " ) ;
SignPatientManageRouteNodeDto signPatientManageRouteNodeDto = new SignPatientManageRouteNodeDto ( ) ;
/ / 查找需要当天执行的AI打电话任务 ( 问卷或电话外呼类型 )
/ / signPatientManageRouteNodeDto . setTaskNodeType ( TaskNodeTypeEnum . PHONE_OUTBOUND . getInfo ( ) ) ;
SignPatientManageRouteNodeDto signPatientManageRouteNodeDto = new SignPatientManageRouteNodeDto ( ) ;
signPatientManageRouteNodeDto . setNodeExecuteStatus ( NodeExecuteStatusEnum . UNEXECUTED . getInfo ( ) ) ;
/ / signPatientManageRouteNodeDto . setTaskNodeType ( TaskNodeTypeEnum . PHONE_OUTBOUND . getInfo ( ) ) ;
signPatientManageRouteNodeDto . setPhoneDialMethod ( PhoneDialMethodEnum . AI . getInfo ( ) ) ;
signPatientManageRouteNodeDto . setNodeExecuteStatus ( NodeExecuteStatusEnum . UNEXECUTED . getInfo ( ) ) ;
List < SignPatientManageRouteNode > nodeList = signPatientManageRouteNodeMapper . selectSignPatientManageRouteNodeList ( signPatientManageRouteNodeDto ) ;
signPatientManageRouteNodeDto . setPhoneDialMethod ( PhoneDialMethodEnum . AI . getInfo ( ) ) ;
/ / 只获取 任务执行类型为 批量执行的
signPatientManageRouteNodeDto . setTaskExcuteType ( TaskExcuteTypeEnum . BATCH_TASK . getInfo ( ) ) ;
/ / 查询未拨打的
signPatientManageRouteNodeDto . setDialStaus ( DialStatusEnum . NODIALED . getInfo ( ) ) ;
List < SignPatientManageRouteNode > executeNodeList = new ArrayList < > ( ) ;
List < SignPatientManageRouteNode > nodeList = signPatientManageRouteNodeMapper . selectSignPatientManageRouteNodeList ( signPatientManageRouteNodeDto ) ;
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 ) ;
}
} ) ;
if ( CollectionUtils . isNotEmpty ( executeNodeList ) ) {
List < SignPatientManageRouteNode > executeNodeList = new ArrayList < > ( ) ;
/ / 根据机器人id查询智能外呼系统的任务id
nodeList . forEach ( node - > {
executeNodeList . forEach ( node - > {
SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper . selectSignPatientManageRouteById ( node . getManageRouteId ( ) ) ;
ScriptInfo scriptInfo = scriptInfoMapper . selectScriptInfoById ( node . getScriptInfoId ( ) ) ;
SignPatientRecord signPatientRecord = signPatientRecordMapper . selectByPrimaryKey ( signPatientManageRoute . getSignPatientRecordId ( ) ) ;
String taskId = scriptInfoTaskInfoMapper . getByNodeId ( node . getId ( ) , AiobTaskTypeContant . BATCHTASK ) ;
PatientVisitRecord patientVisitRecord = patientVisitRecordMapper . selectPatientVisitRecordById ( signPatientRecord . getPatientVisitRecordId ( ) ) ;
if ( StringUtils . isBlank ( taskId ) ) {
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 ( ) ) ) ) {
if ( ObjectUtils . isNotEmpty ( scriptInfo ) ) {
executeNodeList . add ( node ) ;
log . info ( " 创建任务...... " ) ;
}
CreateTaskDto createTaskDto = new CreateTaskDto ( ) ;
} ) ;
createTaskDto . setTaskName ( LocalDate . now ( ) . format ( DateTimeFormatter . ofPattern ( " yyyy-MM-dd " ) ) + scriptInfo . getScriptName ( ) + " ( " + node . getId ( ) + " ) " ) ;
if ( executeNodeList . isEmpty ( ) ) return ;
createTaskDto . setRobotId ( scriptInfo . getRobotPublishId ( ) ) ;
createTaskDto . setDialStartDate ( LocalDate . now ( ) . format ( DateTimeFormatter . ofPattern ( " yyyy-MM-dd " ) ) ) ;
createTaskDto . setDialEndDate ( LocalDate . now ( ) . format ( DateTimeFormatter . ofPattern ( " yyyy-MM-dd " ) ) ) ;
createTaskDto . setForbidDialDate ( Arrays . asList ( 99 ) ) ;
createTaskDto . setRetryTimes ( StringUtils . isBlank ( node . getPhoneRedialTimes ( ) ) ? 0 : PhoneRedialTimesEnum . getValueByInfo ( node . getPhoneRedialTimes ( ) ) . getValue ( ) ) ;
createTaskDto . setRetryInterval ( node . getPhoneTimeInterval ( ) ) ;
createTaskDto . setNumTypeFilterList ( Arrays . asList ( 1 , 2 ) ) ;
createTaskDto . setTaskDataCallback ( true ) ;
createTaskDto . setCallBackUrl ( callBackUrl ) ;
taskId = aiobService . createTask ( createTaskDto ) ;
/ / 开启任务
log . info ( " 开启任务...... " ) ;
aiobService . updateTaskStatus ( taskId , 2 ) ;
ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo ( ) ;
/ / 1 、 最外层 , 按照路径ID分组
scriptInfoTaskInfo . setScriptInfoId ( node . getScriptInfoId ( ) ) ;
Map < Long , List < SignPatientManageRouteNode > > routeNodeGroupListByRouteId =
scriptInfoTaskInfo . setTaskId ( taskId ) ;
executeNodeList . stream ( ) . collect ( Collectors . groupingBy ( SignPatientManageRouteNode : : getManageRouteId ) ) ;
scriptInfoTaskInfo . setRobotId ( scriptInfo . getRobotPublishId ( ) ) ;
scriptInfoTaskInfo . setCreateTime ( LocalDateTime . now ( ) ) ;
scriptInfoTaskInfo . setSignPatientManageRouteNodeId ( node . getId ( ) ) ;
scriptInfoTaskInfo . setAiobTaskType ( AiobTaskTypeContant . BATCHTASK ) ;
scriptInfoTaskInfoMapper . insertScriptInfoTaskInfo ( scriptInfoTaskInfo ) ;
}
}
/ / 客户名单list
List < CustomerInfoDto > customerInfoList = new ArrayList < > ( ) ;
CustomerInfoDto customerInfoDto = new CustomerInfoDto ( ) ;
/ / 开始遍历
customerInfoDto . setExtJson ( node . getId ( ) + " " ) ;
routeNodeGroupListByRouteId . keySet ( ) . forEach ( routeId - > {
SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper . selectSignPatientManageRouteById ( node . getManageRouteId ( ) ) ;
/ / 2 、 次外层 , 按照话术ID分组
PatientInfo patientInfo = patientInfoMapper . selectPatientInfoById ( signPatientManageRoute . getPatientId ( ) ) ;
Map < Long , List < SignPatientManageRouteNode > > routeNodeGroupListByScriptInfoId =
customerInfoDto . setMobile ( patientInfo . getPatientPhone ( ) ) ;
executeNodeList . stream ( ) . collect ( Collectors . groupingBy ( SignPatientManageRouteNode : : getScriptInfoId ) ) ;
/ / 查询患者画像信息
/ / 开始遍历 , 生成任务
List < LabelFieldInfoContentVo > labelFieldContentList = labelFieldContentMapper . selectByPatientId ( patientInfo . getId ( ) ) ;
routeNodeGroupListByScriptInfoId . keySet ( ) . forEach ( scriptInfoId - > {
/ / 处理变量
/ / 同已分组下的任务节点 , 配置属性 应该是 是相同的 , 所以取第0项节点 来使用
JSONObject jsonObject = new JSONObject ( ) ;
SignPatientManageRouteNode nodeTemp = routeNodeGroupListByScriptInfoId . get ( scriptInfoId ) . get ( 0 ) ;
if ( StringUtils . isNotBlank ( scriptInfo . getVariables ( ) ) ) {
/ / 话术
List < String > variables = Arrays . asList ( scriptInfo . getVariables ( ) . split ( " \\ | " ) ) ;
ScriptInfo scriptInfo = scriptInfoMapper . selectScriptInfoById ( scriptInfoId ) ;
variables . forEach ( variable - > {
/ / 拼接一个taskId , 格式 : NodeId_ScriptInfoId_ManageRouteId
LabelFieldInfoContentVo labelFieldContent = labelFieldContentList . stream ( ) . filter ( s - > Objects . equals ( s . getFieldCode ( ) , variable . replaceAll ( " _ " , " " ) . toUpperCase ( ) ) ) . findFirst ( ) . orElse ( null ) ;
String taskId = scriptInfoTaskInfoMapper . getByNodeId ( Long . toString ( nodeTemp . getId ( ) ) . concat ( " _ " )
jsonObject . fluentPut ( variable , ObjectUtils . isEmpty ( labelFieldContent ) ? " " : labelFieldContent . getFieldValue ( ) ) ;
. concat ( Long . toString ( nodeTemp . getManageRouteId ( ) ) . concat ( " _ " ) . concat ( String . valueOf ( nodeTemp . getScriptInfoId ( ) ) ) ) ,
} ) ;
AiobTaskTypeContant . BATCHTASK ) ;
}
if ( StringUtils . isBlank ( taskId ) ) {
/ / 没有任务则创建任务
if ( ObjectUtils . isNotEmpty ( scriptInfo ) ) {
log . info ( " 创建任务...... " ) ;
CreateTaskDto createTaskDto = new CreateTaskDto ( ) ;
createTaskDto . setTaskName ( LocalDate . now ( ) . format ( DateTimeFormatter . ofPattern ( " yyyy-MM-dd " ) ) + scriptInfo . getScriptName ( ) + " ( " + nodeTemp . getId ( ) + " ) " ) ;
createTaskDto . setRobotId ( scriptInfo . getRobotPublishId ( ) ) ;
createTaskDto . setDialStartDate ( LocalDate . now ( ) . format ( DateTimeFormatter . ofPattern ( " yyyy-MM-dd " ) ) ) ;
createTaskDto . setDialEndDate ( LocalDate . now ( ) . format ( DateTimeFormatter . ofPattern ( " yyyy-MM-dd " ) ) ) ;
createTaskDto . setForbidDialDate ( Arrays . asList ( 99 ) ) ;
createTaskDto . setRetryTimes ( StringUtils . isBlank ( nodeTemp . getPhoneRedialTimes ( ) ) ? 0 : PhoneRedialTimesEnum . getValueByInfo ( nodeTemp . getPhoneRedialTimes ( ) ) . getValue ( ) ) ;
createTaskDto . setRetryInterval ( nodeTemp . getPhoneTimeInterval ( ) ) ;
createTaskDto . setNumTypeFilterList ( Arrays . asList ( 1 , 2 ) ) ;
createTaskDto . setTaskDataCallback ( true ) ;
createTaskDto . setCallBackUrl ( callBackUrl ) ;
taskId = aiobService . createTask ( createTaskDto ) ;
/ / 开启任务
log . info ( " 开启任务...... " ) ;
aiobService . updateTaskStatus ( taskId , 2 ) ;
customerInfoDto . setVar ( jsonObject ) ;
ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo ( ) ;
customerInfoList . add ( customerInfoDto ) ;
scriptInfoTaskInfo . setScriptInfoId ( nodeTemp . getScriptInfoId ( ) ) ;
scriptInfoTaskInfo . setTaskId ( taskId ) ;
scriptInfoTaskInfo . setRobotId ( scriptInfo . getRobotPublishId ( ) ) ;
scriptInfoTaskInfo . setCreateTime ( LocalDateTime . now ( ) ) ;
scriptInfoTaskInfo . setSignPatientManageRouteNodeId ( nodeTemp . getId ( ) ) ;
scriptInfoTaskInfo . setAiobTaskType ( AiobTaskTypeContant . BATCHTASK ) ;
/ / 进入拔打记录表 ( 用于后续重拨处理等判断 )
scriptInfoTaskInfoMapper . insertScriptInfoTaskInfo ( scriptInfoTaskInfo ) ;
/ / 上传名单
/ / 3 、 开始组装本任务下的客户变量
log . info ( " 任务导入客户名单...... " ) ;
/ / 客户名单list
ImportTaskDto importTaskDto = new ImportTaskDto ( ) ;
List < CustomerInfoDto > customerInfoList = new ArrayList < > ( ) ;
importTaskDto . setTaskId ( taskId ) ;
/ / 遍历最内层任务节点
importTaskDto . setSecretType ( 2 ) ;
routeNodeGroupListByScriptInfoId . get ( scriptInfoId ) . forEach ( node - > {
importTaskDto . setCustomerInfoList ( customerInfoList ) ;
CustomerInfoDto customerInfoDto = new CustomerInfoDto ( ) ;
List < ImportTaskVo > importTaskList = aiobService . importTask ( importTaskDto ) ;
customerInfoDto . setExtJson ( node . getId ( ) + " " ) ;
String finalTaskId = taskId ;
SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper . selectSignPatientManageRouteById ( node . getManageRouteId ( ) ) ;
importTaskList . forEach ( importTaskVo - > {
PatientInfo patientInfo = patientInfoMapper . selectPatientInfoById ( signPatientManageRoute . getPatientId ( ) ) ;
/ / 名单导入成功后 , sign_patient_manage_route_node表中设置taskId
customerInfoDto . setMobile ( patientInfo . getPatientPhone ( ) ) ;
if ( importTaskVo . getStatus ( ) ) {
/ / 查询患者画像信息
node . setTaskIdExt ( finalTaskId ) ;
List < LabelFieldInfoContentVo > labelFieldContentList = labelFieldContentMapper . selectByPatientId ( patientInfo . getId ( ) ) ;
node . setId ( Long . valueOf ( importTaskVo . getExtJson ( ) ) ) ;
/ / 处理变量
signPatientManageRouteNodeMapper . updateSignPatientManageRouteNode ( node ) ;
JSONObject jsonObject = new JSONObject ( ) ;
}
if ( StringUtils . isNotBlank ( scriptInfo . getVariables ( ) ) ) {
} ) ;
List < String > 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 ) ;
log . info ( " 百度智能外呼创建任务定时任务执行完成...... " ) ;
jsonObject . fluentPut ( variable , ObjectUtils . isEmpty ( labelFieldContent ) ? " " : labelFieldContent . getFieldValue ( ) ) ;
}
} ) ;
}
customerInfoDto . setVar ( jsonObject ) ;
customerInfoList . add ( customerInfoDto ) ;
/ * *
} ) ;
* @description 创建实时任务
/ / 上传名单
* @return null
log . info ( " 任务导入客户名单...... " ) ;
* @Author haown
ImportTaskDto importTaskDto = new ImportTaskDto ( ) ;
* @Date 2024 - 9 - 23 10 : 41
importTaskDto . setTaskId ( taskId ) ;
* /
importTaskDto . setSecretType ( 2 ) ;
public void actualTimeTask ( ) {
importTaskDto . setCustomerInfoList ( customerInfoList ) ;
log . info ( " 开始执行百度智能外呼创建实时任务定时任务...... " ) ;
List < ImportTaskVo > importTaskList = aiobService . importTask ( importTaskDto ) ;
/ / 查找需要当天执行的AI打电话任务 ( 问卷或电话外呼类型 )
String finalTaskId = taskId ;
SignPatientManageRouteNodeDto signPatientManageRouteNodeDto = new SignPatientManageRouteNodeDto ( ) ;
importTaskList . forEach ( importTaskVo - > {
signPatientManageRouteNodeDto . setNodeExecuteStatus ( NodeExecuteStatusEnum . UNEXECUTED . getInfo ( ) ) ;
SignPatientManageRouteNode signPatientManageRouteNode = new SignPatientManageRouteNode ( ) ;
signPatientManageRouteNodeDto . setPhoneDialMethod ( PhoneDialMethodEnum . AI . getInfo ( ) ) ;
/ / 名单导入成功后 , sign_patient_manage_route_node表中设置taskId
/ / 只获取 任务执行类型为 单个执行的
if ( importTaskVo . getStatus ( ) ) {
signPatientManageRouteNodeDto . setTaskExcuteType ( TaskExcuteTypeEnum . ACTUAL_TIME_TASK . getInfo ( ) ) ;
signPatientManageRouteNode . setTaskIdExt ( finalTaskId ) ;
List < SignPatientManageRouteNode > nodeList = signPatientManageRouteNodeMapper . selectSignPatientManageRouteNodeList ( signPatientManageRouteNodeDto ) ;
signPatientManageRouteNode . setId ( Long . valueOf ( importTaskVo . getExtJson ( ) ) ) ;
List < SignPatientManageRouteNode > executeNodeList = new ArrayList < > ( ) ;
nodeList . forEach ( node - > {
LocalDateTime executeTime ;
/ / 如果有计划执行时间 , 则直接获取
if ( node . getNodePlanTime ( ) ! = null )
{ executeTime = node . getNodePlanTime ( ) ; }
/ / 否则 , 则根据诊后 / 院后 第几天 计算
else {
SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper . selectSignPatientManageRouteById ( node . getManageRouteId ( ) ) ;
SignPatientRecord signPatientRecord = signPatientRecordMapper . selectByPrimaryKey ( signPatientManageRoute . getSignPatientRecordId ( ) ) ;
PatientVisitRecord patientVisitRecord = patientVisitRecordMapper . selectPatientVisitRecordById ( signPatientRecord . getPatientVisitRecordId ( ) ) ;
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 ) ;
}
} ) ;
/ / 查询需要重拨的任务
signPatientManageRouteNodeMapper . updateSignPatientManageRouteNode ( signPatientManageRouteNode ) ;
ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo ( ) ;
}
scriptInfoTaskInfo . setExecuteStatus ( NodeExecuteStatusEnum . UNEXECUTED . getInfo ( ) ) ;
} ) ;
scriptInfoTaskInfo . setAiobTaskType ( AiobTaskTypeContant . ACTUALTIMETASK ) ;
}
List < ScriptInfoTaskInfo > 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 ( " 百度智能外呼创建实时任务定时任务执行完成...... " ) ;
}
private void createTask ( SignPatientManageRouteNode node ) {
} ) ;
ScriptInfo scriptInfo = scriptInfoMapper . selectScriptInfoById ( node . getScriptInfoId ( ) ) ;
SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper . selectSignPatientManageRouteById ( node . getManageRouteId ( ) ) ;
PatientInfo patientInfo = patientInfoMapper . selectPatientInfoById ( signPatientManageRoute . getPatientId ( ) ) ;
} ) ;
/ / 没有任务则创建任务
/ / 根据机器人id查询智能外呼系统的任务id
if ( ObjectUtils . isNotEmpty ( scriptInfo ) ) {
log . info ( " 百度智能外呼创建任务定时任务执行完成...... " ) ;
log . info ( " 创建任务...... " ) ;
}
ActualTimeTaskDto actualTimeTaskDto = new ActualTimeTaskDto ( ) ;
actualTimeTaskDto . setRobotId ( scriptInfo . getRobotPublishId ( ) ) ;
/ * *
actualTimeTaskDto . setMobile ( patientInfo . getPatientPhone ( ) ) ;
* @return null
actualTimeTaskDto . setSecretType ( 2 ) ;
* @description 创建实时任务
actualTimeTaskDto . setStopDate ( LocalDate . now ( ) . format ( DateTimeFormatter . ofPattern ( " yyyy-MM-dd " ) ) + " 20:00:00 " ) ;
* @Author haown
/ / 查询患者画像信息
* @Date 2024 - 9 - 23 10 : 41
List < LabelFieldInfoContentVo > labelFieldContentList = labelFieldContentMapper . selectByPatientId ( patientInfo . getId ( ) ) ;
* /
/ / 处理变量
public void actualTimeTask ( ) {
JSONObject jsonObject = new JSONObject ( ) ;
log . info ( " 开始执行百度智能外呼创建实时任务定时任务...... " ) ;
if ( StringUtils . isNotBlank ( scriptInfo . getVariables ( ) ) ) {
/ / 查找需要当天执行的AI打电话任务 ( 问卷或电话外呼类型 )
List < String > variables = Arrays . asList ( scriptInfo . getVariables ( ) . split ( " \\ | " ) ) ;
SignPatientManageRouteNodeDto signPatientManageRouteNodeDto = new SignPatientManageRouteNodeDto ( ) ;
variables . forEach ( variable - > {
signPatientManageRouteNodeDto . setNodeExecuteStatus ( NodeExecuteStatusEnum . UNEXECUTED . getInfo ( ) ) ;
LabelFieldInfoContentVo labelFieldContent = labelFieldContentList . stream ( ) . filter ( s - > Objects . equals ( s . getFieldCode ( ) , variable . replaceAll ( " _ " , " " ) . toUpperCase ( ) ) ) . findFirst ( ) . orElse ( null ) ;
signPatientManageRouteNodeDto . setPhoneDialMethod ( PhoneDialMethodEnum . AI . getInfo ( ) ) ;
jsonObject . fluentPut ( variable , ObjectUtils . isEmpty ( labelFieldContent ) ? " " : labelFieldContent . getFieldValue ( ) ) ;
/ / 只获取 任务执行类型为 单个执行的
} ) ;
signPatientManageRouteNodeDto . setTaskExcuteType ( TaskExcuteTypeEnum . ACTUAL_TIME_TASK . getInfo ( ) ) ;
}
/ / 查询未拨打的
actualTimeTaskDto . setDialogVar ( jsonObject ) ;
signPatientManageRouteNodeDto . setDialStaus ( DialStatusEnum . NODIALED . getInfo ( ) ) ;
actualTimeTaskDto . setCallBackUrl ( callBackUrl ) ;
actualTimeTaskDto . setExtJson ( node . getId ( ) + " " ) ;
List < SignPatientManageRouteNode > nodeList = signPatientManageRouteNodeMapper . selectSignPatientManageRouteNodeList ( signPatientManageRouteNodeDto ) ;
aiobService . createActualTimeTask ( actualTimeTaskDto ) ;
List < SignPatientManageRouteNode > executeNodeList = new ArrayList < > ( ) ;
log . info ( " 创建任务完成...... " ) ;
nodeList . forEach ( node - > {
}
LocalDateTime executeTime ;
}
/ / 如果有计划执行时间 , 则直接获取
if ( node . getNodePlanTime ( ) ! = null ) {
executeTime = node . getNodePlanTime ( ) ;
}
/ / 否则 , 则根据诊后 / 院后 第几天 计算
else {
SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper . selectSignPatientManageRouteById ( node . getManageRouteId ( ) ) ;
SignPatientRecord signPatientRecord = signPatientRecordMapper . selectByPrimaryKey ( signPatientManageRoute . getSignPatientRecordId ( ) ) ;
PatientVisitRecord patientVisitRecord = patientVisitRecordMapper . selectPatientVisitRecordById ( signPatientRecord . getPatientVisitRecordId ( ) ) ;
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 ( ) ;
scriptInfoTaskInfo . setExecuteStatus ( NodeExecuteStatusEnum . UNEXECUTED . getInfo ( ) ) ;
scriptInfoTaskInfo . setAiobTaskType ( AiobTaskTypeContant . ACTUALTIMETASK ) ;
List < ScriptInfoTaskInfo > 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 ( " 百度智能外呼创建实时任务定时任务执行完成...... " ) ;
}
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 " ) ) + " 20:00:00 " ) ;
/ / 查询患者画像信息
List < LabelFieldInfoContentVo > labelFieldContentList = labelFieldContentMapper . selectByPatientId ( patientInfo . getId ( ) ) ;
/ / 处理变量
JSONObject jsonObject = new JSONObject ( ) ;
if ( StringUtils . isNotBlank ( scriptInfo . getVariables ( ) ) ) {
List < String > 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 ( " 创建任务完成...... " ) ;
}
}
}
}