2024-08-21 17:58:34 +08:00
|
|
|
|
package com.xinelu.quartz.task;
|
|
|
|
|
|
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import com.xinelu.common.enums.NodeExecuteStatusEnum;
|
|
|
|
|
|
import com.xinelu.common.enums.PhoneDialMethodEnum;
|
|
|
|
|
|
import com.xinelu.common.enums.TaskNodeTypeEnum;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import com.xinelu.common.utils.StringUtils;
|
|
|
|
|
|
import com.xinelu.manage.domain.patientinfo.PatientInfo;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import com.xinelu.manage.domain.patientvisitrecord.PatientVisitRecord;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import com.xinelu.manage.domain.scriptInfo.ScriptInfo;
|
|
|
|
|
|
import com.xinelu.manage.domain.scriptinfotaskinfo.ScriptInfoTaskInfo;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import com.xinelu.manage.domain.signpatientmanageroute.SignPatientManageRoute;
|
|
|
|
|
|
import com.xinelu.manage.domain.signpatientmanageroutenode.SignPatientManageRouteNode;
|
|
|
|
|
|
import com.xinelu.manage.domain.signpatientrecord.SignPatientRecord;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import com.xinelu.manage.dto.aibo.CreateTaskDto;
|
|
|
|
|
|
import com.xinelu.manage.dto.aibo.CustomerInfoDto;
|
|
|
|
|
|
import com.xinelu.manage.dto.aibo.ImportTaskDto;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import com.xinelu.manage.dto.signpatientmanageroutenode.SignPatientManageRouteNodeDto;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import com.xinelu.manage.mapper.labelfieldcontent.LabelFieldContentMapper;
|
|
|
|
|
|
import com.xinelu.manage.mapper.patientinfo.PatientInfoMapper;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import com.xinelu.manage.mapper.patientvisitrecord.PatientVisitRecordMapper;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import com.xinelu.manage.mapper.scriptInfo.ScriptInfoMapper;
|
|
|
|
|
|
import com.xinelu.manage.mapper.scriptinfotaskinfo.ScriptInfoTaskInfoMapper;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import com.xinelu.manage.mapper.signpatientmanageroute.SignPatientManageRouteMapper;
|
|
|
|
|
|
import com.xinelu.manage.mapper.signpatientmanageroutenode.SignPatientManageRouteNodeMapper;
|
|
|
|
|
|
import com.xinelu.manage.mapper.signpatientrecord.SignPatientRecordMapper;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import com.xinelu.manage.service.aibo.IAIOBService;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import com.xinelu.manage.service.signpatientmanageroutenode.ISignPatientManageRouteNodeService;
|
2024-09-05 13:58:57 +08:00
|
|
|
|
import com.xinelu.manage.vo.aibo.ImportTaskVo;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import com.xinelu.manage.vo.labelfieldcontent.LabelFieldInfoContentVo;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import java.time.format.DateTimeFormatter;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import java.util.ArrayList;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import java.util.Arrays;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import java.util.List;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2024-08-30 17:11:03 +08:00
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
2024-09-05 13:58:57 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2024-09-05 13:58:57 +08:00
|
|
|
|
* @description: 百度智能外呼上传任务定时任务
|
2024-08-21 17:58:34 +08:00
|
|
|
|
* @author: haown
|
|
|
|
|
|
* @create: 2024-08-19 13:58
|
|
|
|
|
|
**/
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
|
@Component("UploadRobotPublishTask")
|
|
|
|
|
|
public class UploadRobotPublishTask {
|
|
|
|
|
|
|
2024-09-05 13:58:57 +08:00
|
|
|
|
@Value("${aiob.callBackUrl}")
|
|
|
|
|
|
private String callBackUrl;
|
2024-08-21 17:58:34 +08:00
|
|
|
|
@Resource
|
|
|
|
|
|
private SignPatientManageRouteNodeMapper signPatientManageRouteNodeMapper;
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private ISignPatientManageRouteNodeService signPatientManageRouteNodeService;
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private SignPatientManageRouteMapper signPatientManageRouteMapper;
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private SignPatientRecordMapper signPatientRecordMapper;
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private PatientVisitRecordMapper patientVisitRecordMapper;
|
|
|
|
|
|
@Resource
|
2024-08-30 17:11:03 +08:00
|
|
|
|
private ScriptInfoTaskInfoMapper scriptInfoTaskInfoMapper;
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private IAIOBService aiobService;
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private ScriptInfoMapper scriptInfoMapper;
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private PatientInfoMapper patientInfoMapper;
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
private LabelFieldContentMapper labelFieldContentMapper;
|
|
|
|
|
|
|
2024-09-05 13:58:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @description 创建百度智能外呼任务并导入客户名单
|
|
|
|
|
|
* @Author haown
|
|
|
|
|
|
* @Date 2024-9-5 13:55
|
|
|
|
|
|
*/
|
2024-08-21 17:58:34 +08:00
|
|
|
|
public void uploadRobotPublishTask() {
|
2024-08-30 17:11:03 +08:00
|
|
|
|
log.info("开始执行百度智能外呼创建任务定时任务......");
|
2024-09-06 17:05:46 +08:00
|
|
|
|
// 查找需要当天执行的AI打电话任务(问卷或电话外呼类型)
|
2024-08-21 17:58:34 +08:00
|
|
|
|
SignPatientManageRouteNodeDto signPatientManageRouteNodeDto = new SignPatientManageRouteNodeDto();
|
|
|
|
|
|
signPatientManageRouteNodeDto.setTaskNodeType(TaskNodeTypeEnum.PHONE_OUTBOUND.getInfo());
|
|
|
|
|
|
signPatientManageRouteNodeDto.setNodeExecuteStatus(NodeExecuteStatusEnum.UNEXECUTED.getInfo());
|
|
|
|
|
|
signPatientManageRouteNodeDto.setPhoneDialMethod(PhoneDialMethodEnum.AI.getInfo());
|
|
|
|
|
|
List<SignPatientManageRouteNode> nodeList = signPatientManageRouteNodeMapper.selectSignPatientManageRouteNodeList(signPatientManageRouteNodeDto);
|
|
|
|
|
|
|
|
|
|
|
|
List<SignPatientManageRouteNode> 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);
|
2024-09-05 13:58:57 +08:00
|
|
|
|
if (executeTime.toLocalDate().isBefore(LocalDate.now())|| executeTime.toLocalDate().isEqual(LocalDate.now())) {
|
2024-08-21 17:58:34 +08:00
|
|
|
|
executeNodeList.add(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-09-05 13:58:57 +08:00
|
|
|
|
|
2024-08-21 17:58:34 +08:00
|
|
|
|
if (CollectionUtils.isNotEmpty(executeNodeList)) {
|
2024-08-30 17:11:03 +08:00
|
|
|
|
// 按照话术id分组,每个话术id对应不同的机器人id, 每个机器人每天创建一条任务
|
2024-09-05 13:58:57 +08:00
|
|
|
|
Map<Long, List<SignPatientManageRouteNode>> groupByScriptInfo = executeNodeList.stream().filter(node -> node.getScriptInfoId() != null).collect(Collectors.groupingBy(SignPatientManageRouteNode::getScriptInfoId));
|
2024-08-30 17:11:03 +08:00
|
|
|
|
// 根据机器人id查询智能外呼系统的任务id
|
|
|
|
|
|
for (Long scriptInfoId : groupByScriptInfo.keySet()) {
|
|
|
|
|
|
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(scriptInfoId);
|
|
|
|
|
|
String taskId = scriptInfoTaskInfoMapper.getByScriptInfoId(scriptInfoId);
|
|
|
|
|
|
if (StringUtils.isBlank(taskId)) {
|
|
|
|
|
|
// 没有任务则创建任务
|
|
|
|
|
|
if (ObjectUtils.isNotEmpty(scriptInfo)) {
|
2024-09-05 13:58:57 +08:00
|
|
|
|
log.info("创建任务......");
|
2024-08-30 17:11:03 +08:00
|
|
|
|
CreateTaskDto createTaskDto = new CreateTaskDto();
|
|
|
|
|
|
createTaskDto.setTaskName(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + scriptInfo.getScriptName());
|
|
|
|
|
|
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.setNumTypeFilterList(Arrays.asList(1,2));
|
2024-09-05 13:58:57 +08:00
|
|
|
|
createTaskDto.setTaskDataCallback(true);
|
|
|
|
|
|
createTaskDto.setCallBackUrl(callBackUrl);
|
2024-08-30 17:11:03 +08:00
|
|
|
|
taskId = aiobService.createTask(createTaskDto);
|
2024-09-05 13:58:57 +08:00
|
|
|
|
// 开启任务
|
|
|
|
|
|
log.info("开启任务......");
|
|
|
|
|
|
aiobService.updateTaskStatus(taskId, 2);
|
2024-08-30 17:11:03 +08:00
|
|
|
|
|
|
|
|
|
|
ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo();
|
|
|
|
|
|
scriptInfoTaskInfo.setScriptInfoId(scriptInfoId);
|
|
|
|
|
|
scriptInfoTaskInfo.setTaskId(taskId);
|
|
|
|
|
|
scriptInfoTaskInfo.setRobotId(scriptInfo.getRobotPublishId());
|
|
|
|
|
|
scriptInfoTaskInfo.setCreateTime(LocalDateTime.now());
|
|
|
|
|
|
scriptInfoTaskInfoMapper.insertScriptInfoTaskInfo(scriptInfoTaskInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 客户名单list
|
|
|
|
|
|
List<SignPatientManageRouteNode> scriptNodeList = groupByScriptInfo.get(scriptInfoId);
|
|
|
|
|
|
List<CustomerInfoDto> customerInfoList = new ArrayList<>();
|
|
|
|
|
|
scriptNodeList.forEach(node -> {
|
|
|
|
|
|
CustomerInfoDto customerInfoDto = new CustomerInfoDto();
|
|
|
|
|
|
customerInfoDto.setExtJson(node.getId() + "");
|
|
|
|
|
|
SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper.selectSignPatientManageRouteById(node.getManageRouteId());
|
|
|
|
|
|
PatientInfo patientInfo = patientInfoMapper.selectPatientInfoById(signPatientManageRoute.getPatientId());
|
|
|
|
|
|
customerInfoDto.setMobile(patientInfo.getPatientPhone());
|
|
|
|
|
|
// 查询患者画像信息
|
|
|
|
|
|
List<LabelFieldInfoContentVo> labelFieldContentList = labelFieldContentMapper.selectByPatientId(patientInfo.getId());
|
|
|
|
|
|
// 处理变量
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
|
if (StringUtils.isNotBlank(scriptInfo.getVariables())) {
|
2024-09-05 13:58:57 +08:00
|
|
|
|
List<String> variables = Arrays.asList(scriptInfo.getVariables().split("\\|"));
|
2024-08-30 17:11:03 +08:00
|
|
|
|
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());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
customerInfoDto.setVar(jsonObject);
|
|
|
|
|
|
customerInfoList.add(customerInfoDto);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 上传名单
|
2024-09-05 13:58:57 +08:00
|
|
|
|
log.info("任务导入客户名单......");
|
2024-08-30 17:11:03 +08:00
|
|
|
|
ImportTaskDto importTaskDto = new ImportTaskDto();
|
|
|
|
|
|
importTaskDto.setTaskId(taskId);
|
|
|
|
|
|
importTaskDto.setSecretType(2);
|
|
|
|
|
|
importTaskDto.setCustomerInfoList(customerInfoList);
|
2024-09-05 13:58:57 +08:00
|
|
|
|
List<ImportTaskVo> importTaskList = aiobService.importTask(importTaskDto);
|
|
|
|
|
|
String finalTaskId = taskId;
|
|
|
|
|
|
importTaskList.forEach(importTaskVo -> {
|
|
|
|
|
|
// 名单导入成功后,sign_patient_manage_route_node表中设置taskId
|
|
|
|
|
|
if (importTaskVo.getStatus()) {
|
|
|
|
|
|
SignPatientManageRouteNode node = new SignPatientManageRouteNode();
|
|
|
|
|
|
node.setTaskIdExt(finalTaskId);
|
|
|
|
|
|
node.setId(Long.valueOf(importTaskVo.getExtJson()));
|
|
|
|
|
|
signPatientManageRouteNodeMapper.updateSignPatientManageRouteNode(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-08-30 17:11:03 +08:00
|
|
|
|
}
|
2024-08-21 17:58:34 +08:00
|
|
|
|
}
|
2024-09-05 13:58:57 +08:00
|
|
|
|
log.info("百度智能外呼创建任务定时任务执行完成......");
|
2024-08-21 17:58:34 +08:00
|
|
|
|
}
|
2024-09-05 13:58:57 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @description 删除话术任务记录表信息,每天晚上执行一次
|
|
|
|
|
|
* @Author haown
|
|
|
|
|
|
* @Date 2024-9-5 13:54
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void deleteScriptTask() {
|
|
|
|
|
|
log.info("删除话术任务记录表信息任务开始执行......");
|
|
|
|
|
|
scriptInfoTaskInfoMapper.deleteScriptInfoTaskInfo();
|
|
|
|
|
|
log.info("删除话术任务记录表信息任务执行完成......");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-21 17:58:34 +08:00
|
|
|
|
}
|