外呼批量执行代码重构
This commit is contained in:
parent
528dbcfe65
commit
254839b2fd
@ -0,0 +1,24 @@
|
||||
package com.xinelu.common.enums;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum DialStatusEnum {
|
||||
/**
|
||||
* 未拨打
|
||||
*/
|
||||
NODIALED("NODIALED"),
|
||||
/**
|
||||
* 已拨打
|
||||
*/
|
||||
DIALED("DIALED"),
|
||||
;
|
||||
final private String info;
|
||||
|
||||
DialStatusEnum(String info) {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -81,6 +81,11 @@ public class SignPatientManageRouteNodeDto {
|
||||
*/
|
||||
@ApiModelProperty(value = "任务执行类型(批量还是单个执行,'批量任务:BATCH_TASK,单个实时拔打任务:ACTUAL_TIME_TASK')")
|
||||
private String taskExcuteType;
|
||||
/**
|
||||
* 拨打状态:DIALED,已拨打:NODIALED:未拨打;默认NULL表示未拨打
|
||||
*/
|
||||
@ApiModelProperty(value = "拨打状态:DIALED,已拨打:NODIALED:未拨打;默认NULL表示未拨打")
|
||||
private String dialStaus;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ import java.util.List;
|
||||
*/
|
||||
public interface ScriptInfoTaskInfoMapper {
|
||||
|
||||
String getByNodeId(Long signPatientManageRouteNodeId, String aiobTaskType);
|
||||
String getByNodeId(String signPatientManageRouteNodeId, String aiobTaskType);
|
||||
|
||||
List<ScriptInfoTaskInfo> selectList(ScriptInfoTaskInfo scriptInfoTaskInfo);
|
||||
|
||||
|
||||
@ -453,10 +453,6 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
|
||||
patientInfoImportVO.setDeptAliasVOS(deptAliasVOS);
|
||||
}
|
||||
|
||||
//科室名称全符合新增患者表,否则返回数据
|
||||
if (CollectionUtils.isNotEmpty(deptAliasVOS)) {
|
||||
return AjaxResult.error("科室名称不存在", patientInfoImportVO);
|
||||
} else {
|
||||
//新增缓存表
|
||||
int insertCount = patientInfoImportMapper.insertPatientInfoImportList(patientInfoImportList);
|
||||
if (insertCount <= 0) {
|
||||
@ -475,6 +471,10 @@ public class PatientInfoServiceImpl implements IPatientInfoService {
|
||||
patientInfoImportMainMapper.insertPatientInfoImportMain(patientInfoImportMain);
|
||||
//endregion
|
||||
|
||||
//科室名称全符合新增患者表,否则返回数据
|
||||
if (CollectionUtils.isNotEmpty(deptAliasVOS)) {
|
||||
return AjaxResult.error("科室名称不存在", patientInfoImportVO);
|
||||
} else {
|
||||
//新增居民表
|
||||
//region 新增居民表
|
||||
patientInfoImportList.forEach(item ->
|
||||
|
||||
@ -230,7 +230,7 @@ public class SignPatientManageRouteServiceImpl implements ISignPatientManageRout
|
||||
signPatientManageRoute.setCreateBy(SecurityUtils.getUsername());
|
||||
signPatientManageRoute.setCreateTime(LocalDateTime.now());
|
||||
//任务执行类型,批量执行
|
||||
if(StringUtils.isNotBlank(signPatientManageRoute.getImportMainId()))
|
||||
if(StringUtils.isNotBlank(signPatientManageRoute.getSn()))
|
||||
{ signPatientManageRoute.setTaskExcuteType(TaskExcuteTypeEnum.BATCH_TASK.getInfo());}
|
||||
|
||||
//任务路由主表 新增
|
||||
@ -247,7 +247,7 @@ public class SignPatientManageRouteServiceImpl implements ISignPatientManageRout
|
||||
continue;
|
||||
}
|
||||
//任务执行类型,批量执行
|
||||
if(StringUtils.isNotBlank(signPatientManageRoute.getImportMainId()))
|
||||
if(StringUtils.isNotBlank(signPatientManageRoute.getSn()))
|
||||
{ routeNode.setTaskExcuteType(TaskExcuteTypeEnum.BATCH_TASK.getInfo());}
|
||||
if(Objects.isNull(signPatientManageRoute.getSignPatientRecordId())) {
|
||||
//更新 审核状态为 已审核,适用场景:对未签约患者 手动创建任务 zyk 20241204
|
||||
@ -1095,7 +1095,7 @@ public class SignPatientManageRouteServiceImpl implements ISignPatientManageRout
|
||||
private void extracted(SignPatientManageRouteVO signPatientManageRoute, List<SignPatientManageRouteNode> signPatientManageRouteNodes, SignPatientManageRouteNode routeNode) {
|
||||
SignPatientManageRouteNode signPatientManageRouteNode = new SignPatientManageRouteNode();
|
||||
//如果 导入患者主表id不为空,则认为此任务是批量执行类型
|
||||
if(StringUtils.isNotBlank(signPatientManageRoute.getImportMainId()))
|
||||
if(StringUtils.isNotBlank(signPatientManageRoute.getSn()))
|
||||
signPatientManageRouteNode.setTaskExcuteType(TaskExcuteTypeEnum.BATCH_TASK.getInfo());
|
||||
else
|
||||
signPatientManageRouteNode.setTaskExcuteType(TaskExcuteTypeEnum.ACTUAL_TIME_TASK.getInfo());
|
||||
|
||||
@ -83,6 +83,7 @@
|
||||
<result property="appletNodeExecuteResultStatus" column="applet_node_execute_result_status"/>
|
||||
<result property="nodeFinishDate" column="node_finish_date"/>
|
||||
<result property="taskIdExt" column="task_id_ext"/>
|
||||
<result property="dialStatus" column="dial_status"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSignPatientManageRouteNodeVo">
|
||||
@ -143,6 +144,12 @@
|
||||
<if test="taskExcuteType != null and taskExcuteType = 'BATCH_TASK'">
|
||||
and task_excute_type = #{taskExcuteType}
|
||||
</if>
|
||||
<if test="dialStatus !=null and dialStatus = 'NODIALED'">
|
||||
and (dial_status is null or dial_status = 'NODIALED')
|
||||
</if>
|
||||
<if test="dialStatus !=null and dialStatus = 'DIALED'">
|
||||
and dial_status = 'DIALED'
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
@ -2,10 +2,7 @@ package com.xinelu.quartz.task;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.xinelu.common.constant.AiobTaskTypeContant;
|
||||
import com.xinelu.common.enums.NodeExecuteStatusEnum;
|
||||
import com.xinelu.common.enums.PhoneDialMethodEnum;
|
||||
import com.xinelu.common.enums.PhoneRedialTimesEnum;
|
||||
import com.xinelu.common.enums.TaskExcuteTypeEnum;
|
||||
import com.xinelu.common.enums.*;
|
||||
import com.xinelu.common.utils.StringUtils;
|
||||
import com.xinelu.manage.domain.patientinfo.PatientInfo;
|
||||
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.vo.aiob.ImportTaskVo;
|
||||
import com.xinelu.manage.vo.labelfieldcontent.LabelFieldInfoContentVo;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -81,6 +79,7 @@ public class UploadRobotPublishTask {
|
||||
* @description 创建百度智能外呼任务并导入客户名单
|
||||
* @Author haown
|
||||
* @Date 2024-9-5 13:55
|
||||
* @Date 2024-12-11 重构批量执行
|
||||
*/
|
||||
public void uploadRobotPublishTask() {
|
||||
log.info("开始执行百度智能外呼创建任务定时任务......");
|
||||
@ -89,6 +88,11 @@ public class UploadRobotPublishTask {
|
||||
//signPatientManageRouteNodeDto.setTaskNodeType(TaskNodeTypeEnum.PHONE_OUTBOUND.getInfo());
|
||||
signPatientManageRouteNodeDto.setNodeExecuteStatus(NodeExecuteStatusEnum.UNEXECUTED.getInfo());
|
||||
signPatientManageRouteNodeDto.setPhoneDialMethod(PhoneDialMethodEnum.AI.getInfo());
|
||||
//只获取 任务执行类型为 批量执行的
|
||||
signPatientManageRouteNodeDto.setTaskExcuteType(TaskExcuteTypeEnum.BATCH_TASK.getInfo());
|
||||
//查询未拨打的
|
||||
signPatientManageRouteNodeDto.setDialStaus(DialStatusEnum.NODIALED.getInfo());
|
||||
|
||||
List<SignPatientManageRouteNode> nodeList = signPatientManageRouteNodeMapper.selectSignPatientManageRouteNodeList(signPatientManageRouteNodeDto);
|
||||
|
||||
List<SignPatientManageRouteNode> executeNodeList = new ArrayList<>();
|
||||
@ -101,24 +105,39 @@ public class UploadRobotPublishTask {
|
||||
executeNodeList.add(node);
|
||||
}
|
||||
});
|
||||
if (executeNodeList.isEmpty()) return;
|
||||
|
||||
if (CollectionUtils.isNotEmpty(executeNodeList)) {
|
||||
// 根据机器人id查询智能外呼系统的任务id
|
||||
executeNodeList.forEach(node -> {
|
||||
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(node.getScriptInfoId());
|
||||
String taskId = scriptInfoTaskInfoMapper.getByNodeId(node.getId(), AiobTaskTypeContant.BATCHTASK);
|
||||
//1、最外层,按照路径ID分组
|
||||
Map<Long, List<SignPatientManageRouteNode>> routeNodeGroupListByRouteId =
|
||||
executeNodeList.stream().collect(Collectors.groupingBy(SignPatientManageRouteNode::getManageRouteId));
|
||||
|
||||
//开始遍历
|
||||
routeNodeGroupListByRouteId.keySet().forEach(routeId -> {
|
||||
//2、次外层,按照话术ID分组
|
||||
Map<Long, List<SignPatientManageRouteNode>> routeNodeGroupListByScriptInfoId =
|
||||
executeNodeList.stream().collect(Collectors.groupingBy(SignPatientManageRouteNode::getScriptInfoId));
|
||||
//开始遍历,生成任务
|
||||
routeNodeGroupListByScriptInfoId.keySet().forEach(scriptInfoId -> {
|
||||
// 同已分组下的任务节点,配置属性 应该是 是相同的,所以取第0项节点 来使用
|
||||
SignPatientManageRouteNode nodeTemp = routeNodeGroupListByScriptInfoId.get(scriptInfoId).get(0);
|
||||
//话术
|
||||
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(scriptInfoId);
|
||||
//拼接一个taskId,格式:NodeId_ScriptInfoId_ManageRouteId
|
||||
String taskId = scriptInfoTaskInfoMapper.getByNodeId(Long.toString(nodeTemp.getId()).concat("_")
|
||||
.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() + "(" +node.getId()+ ")");
|
||||
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(node.getPhoneRedialTimes()) ? 0 : PhoneRedialTimesEnum.getValueByInfo(node.getPhoneRedialTimes()).getValue());
|
||||
createTaskDto.setRetryInterval(node.getPhoneTimeInterval());
|
||||
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);
|
||||
@ -128,18 +147,20 @@ public class UploadRobotPublishTask {
|
||||
aiobService.updateTaskStatus(taskId, 2);
|
||||
|
||||
ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo();
|
||||
scriptInfoTaskInfo.setScriptInfoId(node.getScriptInfoId());
|
||||
scriptInfoTaskInfo.setScriptInfoId(nodeTemp.getScriptInfoId());
|
||||
scriptInfoTaskInfo.setTaskId(taskId);
|
||||
scriptInfoTaskInfo.setRobotId(scriptInfo.getRobotPublishId());
|
||||
scriptInfoTaskInfo.setCreateTime(LocalDateTime.now());
|
||||
scriptInfoTaskInfo.setSignPatientManageRouteNodeId(node.getId());
|
||||
scriptInfoTaskInfo.setSignPatientManageRouteNodeId(nodeTemp.getId());
|
||||
scriptInfoTaskInfo.setAiobTaskType(AiobTaskTypeContant.BATCHTASK);
|
||||
//进入拔打记录表(用于后续重拨处理等判断)
|
||||
scriptInfoTaskInfoMapper.insertScriptInfoTaskInfo(scriptInfoTaskInfo);
|
||||
}
|
||||
}
|
||||
|
||||
//3、开始组装本任务下的客户变量
|
||||
// 客户名单list
|
||||
List<CustomerInfoDto> customerInfoList = new ArrayList<>();
|
||||
|
||||
//遍历最内层任务节点
|
||||
routeNodeGroupListByScriptInfoId.get(scriptInfoId).forEach(node->{
|
||||
CustomerInfoDto customerInfoDto = new CustomerInfoDto();
|
||||
customerInfoDto.setExtJson(node.getId() + "");
|
||||
SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper.selectSignPatientManageRouteById(node.getManageRouteId());
|
||||
@ -156,10 +177,10 @@ public class UploadRobotPublishTask {
|
||||
jsonObject.fluentPut(variable, ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
|
||||
});
|
||||
}
|
||||
|
||||
customerInfoDto.setVar(jsonObject);
|
||||
customerInfoList.add(customerInfoDto);
|
||||
|
||||
});
|
||||
// 上传名单
|
||||
log.info("任务导入客户名单......");
|
||||
ImportTaskDto importTaskDto = new ImportTaskDto();
|
||||
@ -169,21 +190,29 @@ public class UploadRobotPublishTask {
|
||||
List<ImportTaskVo> importTaskList = aiobService.importTask(importTaskDto);
|
||||
String finalTaskId = taskId;
|
||||
importTaskList.forEach(importTaskVo -> {
|
||||
SignPatientManageRouteNode signPatientManageRouteNode = new SignPatientManageRouteNode();
|
||||
// 名单导入成功后,sign_patient_manage_route_node表中设置taskId
|
||||
if (importTaskVo.getStatus()) {
|
||||
node.setTaskIdExt(finalTaskId);
|
||||
node.setId(Long.valueOf(importTaskVo.getExtJson()));
|
||||
signPatientManageRouteNodeMapper.updateSignPatientManageRouteNode(node);
|
||||
signPatientManageRouteNode.setTaskIdExt(finalTaskId);
|
||||
signPatientManageRouteNode.setId(Long.valueOf(importTaskVo.getExtJson()));
|
||||
|
||||
signPatientManageRouteNodeMapper.updateSignPatientManageRouteNode(signPatientManageRouteNode);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
// 根据机器人id查询智能外呼系统的任务id
|
||||
log.info("百度智能外呼创建任务定时任务执行完成......");
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 创建实时任务
|
||||
* @return null
|
||||
* @description 创建实时任务
|
||||
* @Author haown
|
||||
* @Date 2024-9-23 10:41
|
||||
*/
|
||||
@ -195,13 +224,17 @@ public class UploadRobotPublishTask {
|
||||
signPatientManageRouteNodeDto.setPhoneDialMethod(PhoneDialMethodEnum.AI.getInfo());
|
||||
//只获取 任务执行类型为 单个执行的
|
||||
signPatientManageRouteNodeDto.setTaskExcuteType(TaskExcuteTypeEnum.ACTUAL_TIME_TASK.getInfo());
|
||||
//查询未拨打的
|
||||
signPatientManageRouteNodeDto.setDialStaus(DialStatusEnum.NODIALED.getInfo());
|
||||
|
||||
List<SignPatientManageRouteNode> nodeList = signPatientManageRouteNodeMapper.selectSignPatientManageRouteNodeList(signPatientManageRouteNodeDto);
|
||||
List<SignPatientManageRouteNode> executeNodeList = new ArrayList<>();
|
||||
nodeList.forEach(node -> {
|
||||
LocalDateTime executeTime;
|
||||
//如果有计划执行时间,则直接获取
|
||||
if(node.getNodePlanTime()!=null)
|
||||
{ executeTime = node.getNodePlanTime(); }
|
||||
if (node.getNodePlanTime() != null) {
|
||||
executeTime = node.getNodePlanTime();
|
||||
}
|
||||
// 否则 ,则根据诊后/院后 第几天 计算
|
||||
else {
|
||||
SignPatientManageRoute signPatientManageRoute = signPatientManageRouteMapper.selectSignPatientManageRouteById(node.getManageRouteId());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user