百度智能外呼对接。
This commit is contained in:
parent
bfe64372fc
commit
2b7afe7d52
@ -38,6 +38,11 @@ public class ScriptInfoTaskInfo {
|
|||||||
*/
|
*/
|
||||||
private String taskId;
|
private String taskId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务Id
|
||||||
|
*/
|
||||||
|
private Long signPatientManageRouteNodeId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -44,6 +44,16 @@ public class CreateTaskDto {
|
|||||||
*/
|
*/
|
||||||
private List<Integer> forbidDialDate;
|
private List<Integer> forbidDialDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重试次数,整数,且 N ≤ 3,默认为空,表示不重试
|
||||||
|
*/
|
||||||
|
private Integer retryTimes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重试间隔时间,单位min,0≤ N ≤720
|
||||||
|
*/
|
||||||
|
private Integer retryInterval;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否开启24小时空号检测
|
* 是否开启24小时空号检测
|
||||||
*/
|
*/
|
||||||
@ -70,4 +80,6 @@ public class CreateTaskDto {
|
|||||||
*/
|
*/
|
||||||
private Integer callFinishTaskEnd = 0;
|
private Integer callFinishTaskEnd = 0;
|
||||||
|
|
||||||
|
private Integer callOnePhoneTimeLimit = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import com.xinelu.manage.domain.scriptinfotaskinfo.ScriptInfoTaskInfo;
|
|||||||
*/
|
*/
|
||||||
public interface ScriptInfoTaskInfoMapper {
|
public interface ScriptInfoTaskInfoMapper {
|
||||||
|
|
||||||
String getByScriptInfoId(Long scriptInfoId);
|
String getByNodeId(Long signPatientManageRouteNodeId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增百度外呼话术任务临时表
|
* 新增百度外呼话术任务临时表
|
||||||
|
|||||||
@ -14,7 +14,6 @@ import com.xinelu.common.enums.ErrorStatusEnum;
|
|||||||
import com.xinelu.common.enums.NodeExecuteResultStatusEnum;
|
import com.xinelu.common.enums.NodeExecuteResultStatusEnum;
|
||||||
import com.xinelu.common.enums.NodeExecuteStatusEnum;
|
import com.xinelu.common.enums.NodeExecuteStatusEnum;
|
||||||
import com.xinelu.common.enums.PhoneDialMethodEnum;
|
import com.xinelu.common.enums.PhoneDialMethodEnum;
|
||||||
import com.xinelu.common.enums.PhoneRedialTimesEnum;
|
|
||||||
import com.xinelu.common.enums.TaskNodeTypeEnum;
|
import com.xinelu.common.enums.TaskNodeTypeEnum;
|
||||||
import com.xinelu.common.exception.ServiceException;
|
import com.xinelu.common.exception.ServiceException;
|
||||||
import com.xinelu.common.utils.StringUtils;
|
import com.xinelu.common.utils.StringUtils;
|
||||||
@ -73,7 +72,6 @@ import java.util.regex.Pattern;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
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.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@ -332,15 +330,8 @@ public class AIOBServiceImpl implements IAIOBService {
|
|||||||
List<PhoneDialRecord> phoneDialRecordList = phoneDialRecordMapper.selectPhoneDialRecordList(phoneDialRecordQuery);
|
List<PhoneDialRecord> phoneDialRecordList = phoneDialRecordMapper.selectPhoneDialRecordList(phoneDialRecordQuery);
|
||||||
// 电话拨打未成功,判断是否需要重拨;电话拨打成功,设置电话拨通情况为成功
|
// 电话拨打未成功,判断是否需要重拨;电话拨打成功,设置电话拨通情况为成功
|
||||||
if (data.getEndType() != null && data.getEndType() == 0) {//接通状态,1-已接通 0-未接通
|
if (data.getEndType() != null && data.getEndType() == 0) {//接通状态,1-已接通 0-未接通
|
||||||
// 已经拨打的次数
|
// 不需要重拨,设置电话拨通情况
|
||||||
int dialCount = CollectionUtils.isEmpty(phoneDialRecordList) ? 0 : phoneDialRecordList.size() + 1;
|
signPatientManageRouteNode.setPhoneNodeExecuteResultStatus(NodeExecuteResultStatusEnum.FAILURE.getInfo());
|
||||||
if (PhoneRedialTimesEnum.getValueByInfo(signPatientManageRouteNode.getPhoneRedialTimes()).getValue() + 1 > dialCount) {
|
|
||||||
// 需要重拨-导入名单
|
|
||||||
uploadCustomerInfoList(signPatientManageRouteNode, data.getTaskId());
|
|
||||||
} else {
|
|
||||||
// 不需要重拨,设置电话拨通情况
|
|
||||||
signPatientManageRouteNode.setPhoneNodeExecuteResultStatus(NodeExecuteResultStatusEnum.FAILURE.getInfo());
|
|
||||||
}
|
|
||||||
// 电话短信提醒
|
// 电话短信提醒
|
||||||
if (StringUtils.equals(PhoneMessageRemindConstants.NOT_CONNECTED_SEND_MESSAGE, signPatientManageRouteNode.getPhoneMessageRemind())) {
|
if (StringUtils.equals(PhoneMessageRemindConstants.NOT_CONNECTED_SEND_MESSAGE, signPatientManageRouteNode.getPhoneMessageRemind())) {
|
||||||
// 发送短信
|
// 发送短信
|
||||||
@ -373,6 +364,7 @@ public class AIOBServiceImpl implements IAIOBService {
|
|||||||
|
|
||||||
// 发送短信
|
// 发送短信
|
||||||
if (needSendSms) {
|
if (needSendSms) {
|
||||||
|
System.out.println("发送短信");
|
||||||
//sendSms(signPatientManageRoute.getPatientId(), signPatientManageRouteNode);
|
//sendSms(signPatientManageRoute.getPatientId(), signPatientManageRouteNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -478,20 +470,12 @@ public class AIOBServiceImpl implements IAIOBService {
|
|||||||
* @Date 2024-9-6 14:30
|
* @Date 2024-9-6 14:30
|
||||||
*/
|
*/
|
||||||
private void parseQuestionInfo(JSONArray records, SignPatientManageRouteNode node, Long patientInfoId, Long taskExecuteRecordId) {
|
private void parseQuestionInfo(JSONArray records, SignPatientManageRouteNode node, Long patientInfoId, Long taskExecuteRecordId) {
|
||||||
// record=[{"role":"speech","timestamp":1724917698521,"contextText":"您好,我是山东省立医院的电话客服,请问您是李四本人或家属吗?", "sn":"19a09431-1ac6-43a1-8f9f-4b6f617bed73","intent":"NOINTENT","start":"00:00.033","stop":"00:06.974","timeLen":6941,"interrupted":false,"silent":false,"nodeInfo":"eyJwcm9jZXNzTmFtZSI6IuaFoueXheeUqOiNr+Wbnuiuv+ivneacryIsIm5vZGVOYW1lIjoi5byA5Zy655m96IqC54K5X3RwcnZtc2g4IiwiaW50ZW50IjoiIiwiZW50aXR5IjpbXSwic3lzdGVtRXZlbnQiOiIiLCJmYXEiOiIifQ=="},
|
|
||||||
// {"role":"voice","timestamp":1724917707542,"content":"是的","contextText":"是的","sn":"0e5c9c4e65db11ef_2_1","start":"00:06.930","stop":"00:08.330","timeLen":1400,"interrupted":false,"silent":false},
|
|
||||||
// {"role":"speech","timestamp":1724917708359,"content":"是的","contextText":"好的,您之前在我们医院住过院,想了解一下您近期的健康状况。","sn":"0e5c9c4e65db11ef_2_1","intent":"patient_self","start":"00:09.871","stop":"00:15.793","timeLen":5922,"interrupted":false,"silent":false,"nodeInfo":"eyJwcm9jZXNzTmFtZSI6IuaFoueXheeUqOiNr+Wbnuiuv+ivneacryIsIm5vZGVOYW1lIjoi5pys5Lq66IqC54K5X3Nyd2Q5MTR3IiwiaW50ZW50Ijoi5piv5pys5Lq6IiwiZW50aXR5IjpbXSwic3lzdGVtRXZlbnQiOiIiLCJmYXEiOiIifQ=="},
|
|
||||||
// {"role":"voice","timestamp":1724917718191,"content":"好的嗯","contextText":"好的嗯","sn":"0e5c9c4e65db11ef_4_1","start":"00:16.650","stop":"00:18.970","timeLen":2320,"interrupted":false,"silent":false},
|
|
||||||
// {"role":"speech","timestamp":1724917718873,"content":"好的嗯","contextText":"您是否正常按时服药呢?","sn":"0e5c9c4e65db11ef_4_1","intent":"NOINTENT","start":"00:20.385","stop":"00:22.917","timeLen":2532,"interrupted":false,"silent":false,"nodeInfo":"eyJwcm9jZXNzTmFtZSI6IuaFoueXheeUqOiNr+Wbnuiuv+ivneacryIsIm5vZGVOYW1lIjoi6IKv5a6a6IqC54K5X3F6aWpzb2g2IiwiaW50ZW50IjoiIiwiZW50aXR5IjpbXSwic3lzdGVtRXZlbnQiOiIiLCJmYXEiOiIifQ=="},
|
|
||||||
// {"role":"voice","timestamp":1724917725425,"content":"是的","contextText":"是的","sn":"0e5c9c4e65db11ef_6_1","start":"00:24.810","stop":"00:26.210","timeLen":1400,"interrupted":false,"silent":false},
|
|
||||||
// {"role":"speech","timestamp":1724917725993,"content":"是的","contextText":"祝您早日康复。","sn":"0e5c9c4e65db11ef_6_1","intent":"sys_yes","start":"00:27.505","stop":"00:29.637","timeLen":2132,"interrupted":false,"silent":false,"nodeInfo":"eyJwcm9jZXNzTmFtZSI6IuaFoueXheeUqOiNr+Wbnuiuv+ivneacryIsIm5vZGVOYW1lIjoi5oyJ5pe25pyN6I2v6IqC54K5X3Bxd2RkcDBpIiwiaW50ZW50Ijoi6IKv5a6a5oSP5Zu+IiwiZW50aXR5IjpbXSwic3lzdGVtRXZlbnQiOiIiLCJmYXEiOiIifQ=="}],
|
|
||||||
|
|
||||||
List<AiboRecord> aiboRecords = records.toList(AiboRecord.class);
|
List<AiboRecord> aiboRecords = records.toList(AiboRecord.class);
|
||||||
List<AiboRecord> speechList = aiboRecords.stream().filter(record -> StringUtils.equals("speech", record.getRole()))
|
List<AiboRecord> speechList = aiboRecords.stream().filter(record -> StringUtils.equals("speech", record.getRole()))
|
||||||
.sorted(Comparator.comparing(AiboRecord::getSn))
|
|
||||||
.collect(Collectors.toMap(AiboRecord::getContextText, p -> p, (p1, p2) -> p2))
|
.collect(Collectors.toMap(AiboRecord::getContextText, p -> p, (p1, p2) -> p2))
|
||||||
.values()
|
.values()
|
||||||
.stream()
|
.stream()
|
||||||
|
.sorted(Comparator.comparing(AiboRecord::getTimestamp))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 查询患者画像信息
|
// 查询患者画像信息
|
||||||
@ -522,17 +506,28 @@ public class AIOBServiceImpl implements IAIOBService {
|
|||||||
patientQuestionSubmitResult.setQuestionCount(questionInfo.getQuestionCount());
|
patientQuestionSubmitResult.setQuestionCount(questionInfo.getQuestionCount());
|
||||||
patientQuestionSubmitResult.setResidentId(patientInfo.getResidentId());
|
patientQuestionSubmitResult.setResidentId(patientInfo.getResidentId());
|
||||||
questionSubmitResultMapper.insertPatientQuestionSubmitResult(patientQuestionSubmitResult);
|
questionSubmitResultMapper.insertPatientQuestionSubmitResult(patientQuestionSubmitResult);
|
||||||
// 2、保存patient_question_subject_result,计算总得分
|
// 2、保存patient_question_subject_result
|
||||||
BigDecimal totalScore = BigDecimal.ZERO;
|
BigDecimal totalScore = BigDecimal.ZERO;
|
||||||
List<QuestionSubjectVO> questionSubjectList = questionSubjectMapper.selectQuestionSubjectBy(node.getQuestionInfoId());
|
List<QuestionSubjectVO> questionSubjectList = questionSubjectMapper.selectQuestionSubjectBy(node.getQuestionInfoId());
|
||||||
questionSubjectList.forEach(questionSubjectVO -> {
|
questionSubjectList.forEach(questionSubjectVO -> {
|
||||||
// 判断问题中有无变量,有变量替换变量
|
// 判断问题中有无变量,有变量替换变量
|
||||||
String questionName = replaceQuestionName(questionSubjectVO.getQuestionName(), labelFieldContentList);
|
String questionName = replaceQuestionName(questionSubjectVO.getQuestionName(), labelFieldContentList);
|
||||||
// 根据通话记录筛查问题
|
// 根据通话记录筛查是否询问该问题
|
||||||
if (contextMap.containsKey(questionName)) {
|
boolean hasQuestion = false;
|
||||||
|
String aiobQuestionName = "";
|
||||||
|
for (String questionContent : contextMap.keySet()) {
|
||||||
|
if (questionContent.replaceAll("\\p{P}", "").contains(questionName.replaceAll("\\p{P}", ""))) {
|
||||||
|
hasQuestion = true;
|
||||||
|
aiobQuestionName = questionContent;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasQuestion) {
|
||||||
PatientQuestionSubjectResult patientQuestionSubjectResult = new PatientQuestionSubjectResult();
|
PatientQuestionSubjectResult patientQuestionSubjectResult = new PatientQuestionSubjectResult();
|
||||||
BeanUtils.copyProperties(questionSubjectVO, patientQuestionSubjectResult);
|
BeanUtils.copyProperties(questionSubjectVO, patientQuestionSubjectResult);
|
||||||
|
patientQuestionSubjectResult.setId(null);
|
||||||
patientQuestionSubjectResult.setQuestionSubmitResultId(patientQuestionSubmitResult.getId());
|
patientQuestionSubjectResult.setQuestionSubmitResultId(patientQuestionSubmitResult.getId());
|
||||||
|
patientQuestionSubjectResult.setCreateTime(LocalDateTime.now());
|
||||||
patientQuestionSubjectResultMapper.insertPatientQuestionSubjectResult(patientQuestionSubjectResult);
|
patientQuestionSubjectResultMapper.insertPatientQuestionSubjectResult(patientQuestionSubjectResult);
|
||||||
|
|
||||||
// 3、保存patient_question_option_result
|
// 3、保存patient_question_option_result
|
||||||
@ -540,29 +535,20 @@ public class AIOBServiceImpl implements IAIOBService {
|
|||||||
questionSubjectOptionQuery.setQuestionnaireSubjectId(questionSubjectVO.getId());
|
questionSubjectOptionQuery.setQuestionnaireSubjectId(questionSubjectVO.getId());
|
||||||
List<QuestionSubjectOption> questionSubjectOptions = questionSubjectOptionMapper.selectQuestionSubjectOptionList(questionSubjectOptionQuery);
|
List<QuestionSubjectOption> questionSubjectOptions = questionSubjectOptionMapper.selectQuestionSubjectOptionList(questionSubjectOptionQuery);
|
||||||
List<PatientQuestionOptionResult> patientQuestionOptionResults = new ArrayList<>();
|
List<PatientQuestionOptionResult> patientQuestionOptionResults = new ArrayList<>();
|
||||||
|
String finalAiobQuestionName = aiobQuestionName;
|
||||||
questionSubjectOptions.forEach(questionSubjectOption -> {
|
questionSubjectOptions.forEach(questionSubjectOption -> {
|
||||||
PatientQuestionOptionResult patientQuestionOptionResult = new PatientQuestionOptionResult();
|
PatientQuestionOptionResult patientQuestionOptionResult = new PatientQuestionOptionResult();
|
||||||
BeanUtils.copyProperties(questionSubjectOptions, patientQuestionOptionResult);
|
BeanUtils.copyProperties(questionSubjectOption, patientQuestionOptionResult);
|
||||||
// 设置是否选中, 通过通话记录中下一个问题的intent字段查询QuestionSubjectOption,
|
// 设置是否选中, 通过通话记录中下一个问题的intent字段查询QuestionSubjectOption,
|
||||||
// speech_context_text中的字段需要替换为文本,竖线分隔的分段都要匹配 input.replaceAll("[\\p{Punct}]", "")
|
List<String> intents = Arrays.asList(questionSubjectOption.getIntent().split("\\|"));
|
||||||
//{% &department_name %} /.*{% & %}.*/ #\{([^\}]*)\}
|
AiboRecord nextRecord = getNextQuestion(speechList, finalAiobQuestionName);
|
||||||
//Pattern pattern = Pattern.compile("\\{%\\s*&[\\s\\S]*?\\s*%}");
|
|
||||||
//Matcher matcher = pattern.matcher(questionSubjectOption.getSpeechContextText());
|
|
||||||
//while (matcher.find()) {
|
|
||||||
// LabelFieldInfoContentVo labelFieldContent = labelFieldContentList.stream().filter(s -> Objects.equals(s.getFieldCode(), matcher.group(1).replaceAll("_", "").toUpperCase())).findFirst().orElse(null);
|
|
||||||
// if (ObjectUtils.isNotEmpty(labelFieldContent)) {
|
|
||||||
// String speechContextText = questionSubjectOption.getSpeechContextText().replaceAll("\\{%\\s*&[\\s\\S]*?\\s*%}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue())
|
|
||||||
// .replaceAll("[\\p{Punct}]", "")
|
|
||||||
// .replaceAll("|", "");
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
List<String> intents = Arrays.asList(questionSubjectOption.getIntent().split("|"));
|
|
||||||
AiboRecord nextRecord = getNextQuestion(speechList, questionName);
|
|
||||||
if (ObjectUtils.isNotEmpty(nextRecord) && intents.contains(nextRecord.getIntent())) {
|
if (ObjectUtils.isNotEmpty(nextRecord) && intents.contains(nextRecord.getIntent())) {
|
||||||
patientQuestionOptionResult.setOptionChooseSign(0);
|
patientQuestionOptionResult.setOptionChooseSign(0);
|
||||||
} else {
|
} else {
|
||||||
patientQuestionOptionResult.setOptionChooseSign(1);
|
patientQuestionOptionResult.setOptionChooseSign(1);
|
||||||
}
|
}
|
||||||
|
patientQuestionOptionResult.setId(null);
|
||||||
|
patientQuestionOptionResult.setCreateTime(LocalDateTime.now());
|
||||||
patientQuestionOptionResult.setQuestionSubjectResultId(patientQuestionSubjectResult.getId());
|
patientQuestionOptionResult.setQuestionSubjectResultId(patientQuestionSubjectResult.getId());
|
||||||
patientQuestionOptionResults.add(patientQuestionOptionResult);
|
patientQuestionOptionResults.add(patientQuestionOptionResult);
|
||||||
});
|
});
|
||||||
@ -577,9 +563,11 @@ public class AIOBServiceImpl implements IAIOBService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private AiboRecord getNextQuestion(List<AiboRecord> speechList, String currentQuestion) {
|
private AiboRecord getNextQuestion(List<AiboRecord> speechList, String currentQuestion) {
|
||||||
for (int i = 0; i < speechList.size(); i++) {
|
if (StringUtils.isNotBlank(currentQuestion)) {
|
||||||
if (StringUtils.equals(speechList.get(i).getContextText(), currentQuestion)) {
|
for (int i = 0; i < speechList.size(); i++) {
|
||||||
return speechList.get(i+1);
|
if (StringUtils.equals(speechList.get(i).getContextText(), currentQuestion)) {
|
||||||
|
return speechList.get(i+1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -596,4 +584,5 @@ public class AIOBServiceImpl implements IAIOBService {
|
|||||||
}
|
}
|
||||||
return questionName;
|
return questionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,10 +21,10 @@
|
|||||||
from script_info_task_info
|
from script_info_task_info
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="getByScriptInfoId" resultType="java.lang.String">
|
<select id="getByNodeId" resultType="java.lang.String">
|
||||||
select task_id
|
select task_id
|
||||||
from script_info_task_info
|
from script_info_task_info
|
||||||
where script_info_id = #{scriptInfoId} and del_flag = 0
|
where sign_patient_manage_route_node_id = #{signPatientManageRouteNodeId} and del_flag = 0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="insertScriptInfoTaskInfo" parameterType="ScriptInfoTaskInfo" useGeneratedKeys="true"
|
<insert id="insertScriptInfoTaskInfo" parameterType="ScriptInfoTaskInfo" useGeneratedKeys="true"
|
||||||
@ -37,6 +37,8 @@
|
|||||||
</if>
|
</if>
|
||||||
<if test="taskId != null">task_id,
|
<if test="taskId != null">task_id,
|
||||||
</if>
|
</if>
|
||||||
|
<if test="signPatientManageRouteNodeId != null">sign_patient_manage_route_node_id,
|
||||||
|
</if>
|
||||||
<if test="createTime != null">create_time,
|
<if test="createTime != null">create_time,
|
||||||
</if>
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
@ -47,6 +49,8 @@
|
|||||||
</if>
|
</if>
|
||||||
<if test="taskId != null">#{taskId},
|
<if test="taskId != null">#{taskId},
|
||||||
</if>
|
</if>
|
||||||
|
<if test="signPatientManageRouteNodeId != null">#{signPatientManageRouteNodeId},
|
||||||
|
</if>
|
||||||
<if test="createTime != null">#{createTime},
|
<if test="createTime != null">#{createTime},
|
||||||
</if>
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.xinelu.quartz.task;
|
|||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.xinelu.common.enums.NodeExecuteStatusEnum;
|
import com.xinelu.common.enums.NodeExecuteStatusEnum;
|
||||||
import com.xinelu.common.enums.PhoneDialMethodEnum;
|
import com.xinelu.common.enums.PhoneDialMethodEnum;
|
||||||
|
import com.xinelu.common.enums.PhoneRedialTimesEnum;
|
||||||
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;
|
||||||
@ -33,9 +34,7 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
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;
|
||||||
@ -95,28 +94,28 @@ public class UploadRobotPublishTask {
|
|||||||
SignPatientRecord signPatientRecord = signPatientRecordMapper.selectByPrimaryKey(signPatientManageRoute.getSignPatientRecordId());
|
SignPatientRecord signPatientRecord = signPatientRecordMapper.selectByPrimaryKey(signPatientManageRoute.getSignPatientRecordId());
|
||||||
PatientVisitRecord patientVisitRecord = patientVisitRecordMapper.selectPatientVisitRecordById(signPatientRecord.getPatientVisitRecordId());
|
PatientVisitRecord patientVisitRecord = patientVisitRecordMapper.selectPatientVisitRecordById(signPatientRecord.getPatientVisitRecordId());
|
||||||
LocalDateTime executeTime = signPatientManageRouteNodeService.getExecuteTime(node.getExecuteTime(), node.getRouteNodeName(), node.getRouteNodeDay(), patientVisitRecord);
|
LocalDateTime executeTime = signPatientManageRouteNodeService.getExecuteTime(node.getExecuteTime(), node.getRouteNodeName(), node.getRouteNodeDay(), patientVisitRecord);
|
||||||
if (executeTime.toLocalDate().isBefore(LocalDate.now())|| executeTime.toLocalDate().isEqual(LocalDate.now())) {
|
if (node.getScriptInfoId() != null && (executeTime.toLocalDate().isBefore(LocalDate.now()) || executeTime.toLocalDate().isEqual(LocalDate.now()))) {
|
||||||
executeNodeList.add(node);
|
executeNodeList.add(node);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(executeNodeList)) {
|
if (CollectionUtils.isNotEmpty(executeNodeList)) {
|
||||||
// 按照话术id分组,每个话术id对应不同的机器人id, 每个机器人每天创建一条任务
|
|
||||||
Map<Long, List<SignPatientManageRouteNode>> groupByScriptInfo = executeNodeList.stream().filter(node -> node.getScriptInfoId() != null).collect(Collectors.groupingBy(SignPatientManageRouteNode::getScriptInfoId));
|
|
||||||
// 根据机器人id查询智能外呼系统的任务id
|
// 根据机器人id查询智能外呼系统的任务id
|
||||||
for (Long scriptInfoId : groupByScriptInfo.keySet()) {
|
executeNodeList.forEach(node -> {
|
||||||
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(scriptInfoId);
|
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(node.getScriptInfoId());
|
||||||
String taskId = scriptInfoTaskInfoMapper.getByScriptInfoId(scriptInfoId);
|
String taskId = scriptInfoTaskInfoMapper.getByNodeId(node.getId());
|
||||||
if (StringUtils.isBlank(taskId)) {
|
if (StringUtils.isBlank(taskId)) {
|
||||||
// 没有任务则创建任务
|
// 没有任务则创建任务
|
||||||
if (ObjectUtils.isNotEmpty(scriptInfo)) {
|
if (ObjectUtils.isNotEmpty(scriptInfo)) {
|
||||||
log.info("创建任务......");
|
log.info("创建任务......");
|
||||||
CreateTaskDto createTaskDto = new CreateTaskDto();
|
CreateTaskDto createTaskDto = new CreateTaskDto();
|
||||||
createTaskDto.setTaskName(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + scriptInfo.getScriptName());
|
createTaskDto.setTaskName(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + scriptInfo.getScriptName() + "(" +node.getId()+ ")");
|
||||||
createTaskDto.setRobotId(scriptInfo.getRobotPublishId());
|
createTaskDto.setRobotId(scriptInfo.getRobotPublishId());
|
||||||
createTaskDto.setDialStartDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
createTaskDto.setDialStartDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||||
createTaskDto.setDialEndDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
createTaskDto.setDialEndDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||||
createTaskDto.setForbidDialDate(Arrays.asList(99));
|
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.setNumTypeFilterList(Arrays.asList(1,2));
|
||||||
createTaskDto.setTaskDataCallback(true);
|
createTaskDto.setTaskDataCallback(true);
|
||||||
createTaskDto.setCallBackUrl(callBackUrl);
|
createTaskDto.setCallBackUrl(callBackUrl);
|
||||||
@ -126,37 +125,36 @@ public class UploadRobotPublishTask {
|
|||||||
aiobService.updateTaskStatus(taskId, 2);
|
aiobService.updateTaskStatus(taskId, 2);
|
||||||
|
|
||||||
ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo();
|
ScriptInfoTaskInfo scriptInfoTaskInfo = new ScriptInfoTaskInfo();
|
||||||
scriptInfoTaskInfo.setScriptInfoId(scriptInfoId);
|
scriptInfoTaskInfo.setScriptInfoId(node.getScriptInfoId());
|
||||||
scriptInfoTaskInfo.setTaskId(taskId);
|
scriptInfoTaskInfo.setTaskId(taskId);
|
||||||
scriptInfoTaskInfo.setRobotId(scriptInfo.getRobotPublishId());
|
scriptInfoTaskInfo.setRobotId(scriptInfo.getRobotPublishId());
|
||||||
scriptInfoTaskInfo.setCreateTime(LocalDateTime.now());
|
scriptInfoTaskInfo.setCreateTime(LocalDateTime.now());
|
||||||
|
scriptInfoTaskInfo.setSignPatientManageRouteNodeId(node.getId());
|
||||||
scriptInfoTaskInfoMapper.insertScriptInfoTaskInfo(scriptInfoTaskInfo);
|
scriptInfoTaskInfoMapper.insertScriptInfoTaskInfo(scriptInfoTaskInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 客户名单list
|
// 客户名单list
|
||||||
List<SignPatientManageRouteNode> scriptNodeList = groupByScriptInfo.get(scriptInfoId);
|
|
||||||
List<CustomerInfoDto> customerInfoList = new ArrayList<>();
|
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())) {
|
|
||||||
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());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
customerInfoDto.setVar(jsonObject);
|
CustomerInfoDto customerInfoDto = new CustomerInfoDto();
|
||||||
customerInfoList.add(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())) {
|
||||||
|
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());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
customerInfoDto.setVar(jsonObject);
|
||||||
|
customerInfoList.add(customerInfoDto);
|
||||||
|
|
||||||
// 上传名单
|
// 上传名单
|
||||||
log.info("任务导入客户名单......");
|
log.info("任务导入客户名单......");
|
||||||
@ -169,13 +167,12 @@ public class UploadRobotPublishTask {
|
|||||||
importTaskList.forEach(importTaskVo -> {
|
importTaskList.forEach(importTaskVo -> {
|
||||||
// 名单导入成功后,sign_patient_manage_route_node表中设置taskId
|
// 名单导入成功后,sign_patient_manage_route_node表中设置taskId
|
||||||
if (importTaskVo.getStatus()) {
|
if (importTaskVo.getStatus()) {
|
||||||
SignPatientManageRouteNode node = new SignPatientManageRouteNode();
|
|
||||||
node.setTaskIdExt(finalTaskId);
|
node.setTaskIdExt(finalTaskId);
|
||||||
node.setId(Long.valueOf(importTaskVo.getExtJson()));
|
node.setId(Long.valueOf(importTaskVo.getExtJson()));
|
||||||
signPatientManageRouteNodeMapper.updateSignPatientManageRouteNode(node);
|
signPatientManageRouteNodeMapper.updateSignPatientManageRouteNode(node);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
log.info("百度智能外呼创建任务定时任务执行完成......");
|
log.info("百度智能外呼创建任务定时任务执行完成......");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user