修改模板替换正则表达式。

This commit is contained in:
haown 2024-07-01 14:08:26 +08:00
parent 5a6d7e73eb
commit fe4c9382c9
2 changed files with 68 additions and 53 deletions

View File

@ -505,21 +505,20 @@ public class SignPatientManageRouteServiceImpl implements ISignPatientManageRout
break;
// 话术
case TemplateTypeConstants.SCRIPT:
manageRouteNode.setPhoneId(node.getTemplateId());
manageRouteNode.setPhoneId(node.getPhoneTemplateId());
// 查询话术
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(node.getTemplateId());
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(node.getPhoneTemplateId());
if (ObjectUtils.isNotEmpty(scriptInfo)) {
// 话术库json内容替换
manageRouteNode.setPhoneNodeContent(getFlowScheme(scriptInfo.getFlowScheme(), labelFieldContentList));
templateDetail = JSONObject.parseObject(JSONObject.toJSONString(scriptInfo));
manageRouteNode.setTemplateType(TemplateTypeConstants.SCRIPT);
manageRouteNode.setTemplateDetail(templateDetail);
// 电话短信内容
if (node.getPhoneMessageTemplateId() != null) {
// 查询短信库
manageRouteNode.setPhoneMessageTemplateContent(replaceMessageInfo(node.getPhoneMessageTemplateId(), labelFieldContentList));
}
}
// 电话短信内容
if (node.getPhoneMessageTemplateId() != null) {
// 查询短信库
manageRouteNode.setPhoneMessageTemplateContent(replaceMessageInfo(node.getPhoneMessageTemplateId(), labelFieldContentList));
}
break;
}
@ -546,21 +545,31 @@ public class SignPatientManageRouteServiceImpl implements ISignPatientManageRout
manageNode.setRouteNodeNameCN(RouteNodeNameEnum.getNameByInfo(manageNode.getRouteNodeName()).getName());
JSONObject templateDetail = new JSONObject();
switch(manageNode.getTaskType()) {
// 电话外呼--话术
// 电话外呼
case TaskContentConstants.PHONE_OUTBOUND:
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(manageNode.getPhoneId());
if (ObjectUtils.isNotEmpty(scriptInfo)) {
// 话术库json内容替换
manageNode.setPhoneNodeContent(getFlowScheme(scriptInfo.getFlowScheme(), labelFieldContentList));
templateDetail = JSONObject.parseObject(JSONObject.toJSONString(scriptInfo));
manageNode.setTemplateType(TemplateTypeConstants.SCRIPT);
manageNode.setTemplateDetail(templateDetail);
// 电话短信内容
if (manageNode.getPhoneMessageTemplateId() != null) {
// 查询短信库
manageNode.setPhoneMessageTemplateContent(replaceMessageInfo(manageNode.getPhoneMessageTemplateId(), labelFieldContentList));
// 电话外呼分为话术和问卷两种根据模板id判断选择的哪种模板
if (manageNode.getPhoneId() != null) { // 话术
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(manageNode.getPhoneId());
if (ObjectUtils.isNotEmpty(scriptInfo)) {
// 话术库json内容替换
manageNode.setPhoneNodeContent(getFlowScheme(scriptInfo.getFlowScheme(), labelFieldContentList));
templateDetail = JSONObject.parseObject(JSONObject.toJSONString(scriptInfo));
manageNode.setTemplateType(TemplateTypeConstants.SCRIPT);
manageNode.setTemplateDetail(templateDetail);
}
} else if (manageNode.getQuestionInfoId() != null) { // 问卷
// 查询问卷详情
QuestionVO questionVO = questionInfoService.selectQuestionInfoById(manageNode.getQuestionInfoId());
if (ObjectUtils.isNotEmpty(questionVO)) {
templateDetail = JSONObject.parseObject(JSONObject.toJSONString(questionVO));
manageNode.setTemplateType(TemplateTypeConstants.QUESTIONNAIRE);
manageNode.setTemplateDetail(templateDetail);
}
}
// 电话短信内容
if (manageNode.getPhoneMessageTemplateId() != null) {
// 查询短信库
manageNode.setPhoneMessageTemplateContent(replaceMessageInfo(manageNode.getPhoneMessageTemplateId(), labelFieldContentList));
}
break;
// 问卷
@ -713,15 +722,15 @@ public class SignPatientManageRouteServiceImpl implements ISignPatientManageRout
*/
private String getFlowScheme(String flowScheme, List<LabelFieldInfoContentVo> labelFieldContentList) {
// 话术库json内容替换
if (StringUtils.isNotBlank(flowScheme) && StringUtils.contains(flowScheme, "{{") && StringUtils.contains(flowScheme, "}}")) {
if (StringUtils.isNotBlank(flowScheme)) {
// 替换{{}}中的内容
Pattern pattern = Pattern.compile("\\{\\{([^\\{\\}}]+)\\}\\}");
Pattern pattern = Pattern.compile("#\\{([^\\}]*)\\}");
Matcher matcher = pattern.matcher(flowScheme);
while (matcher.find()) {
//过滤出符合条件的对象不匹配返回null
LabelFieldInfoContentVo labelFieldContent = labelFieldContentList.stream().filter(s -> Objects.equals(s.getFieldCode(), matcher.group(1))).findFirst().orElse(null);
if (ObjectUtils.isNotEmpty(labelFieldContent)) {
flowScheme = flowScheme.replaceAll("\\{\\{([^\\{\\}}]+)\\}\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
flowScheme = flowScheme.replaceAll("#\\{([^\\}]*)\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
}
}
}
@ -739,13 +748,13 @@ public class SignPatientManageRouteServiceImpl implements ISignPatientManageRout
TextMessage textMessage = textMessageMapper.selectTextMessageById(messageTemplateId);
String textMessageContent = textMessage.getTextMessageContent();
// 替换{{}}中的内容
Pattern pattern = Pattern.compile("\\{\\{([^\\{\\}}]+)\\}\\}");
Pattern pattern = Pattern.compile("#\\{([^\\}]*)\\}");
Matcher matcher = pattern.matcher(textMessage.getTextMessageContent());
while (matcher.find()) {
// 过滤出符合条件的对象不匹配返回null
LabelFieldInfoContentVo labelFieldContent = labelFieldContentList.stream().filter(s -> Objects.equals(s.getFieldCode(), matcher.group(1))).findFirst().orElse(null);
if (ObjectUtils.isNotEmpty(labelFieldContent)) {
textMessageContent = textMessageContent.replaceAll("\\{\\{([^\\{\\}}]+)\\}\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
textMessageContent = textMessageContent.replaceAll("#\\{([^\\}]*)\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
}
}
return textMessageContent;
@ -777,13 +786,13 @@ public class SignPatientManageRouteServiceImpl implements ISignPatientManageRout
return null;
}
String templateContent = wechatTemplate.getTemplateContent();
Pattern pattern = Pattern.compile("\\{\\{([^\\{\\}}]+)\\}\\}");
Pattern pattern = Pattern.compile("#\\{([^\\}]*)\\}");
Matcher matcher = pattern.matcher(templateContent);
while (matcher.find()) {
// 过滤出符合条件的对象不匹配返回null
LabelFieldInfoContentVo labelFieldContent = labelFieldContentList.stream().filter(s -> Objects.equals(s.getFieldCode(), matcher.group(1))).findFirst().orElse(null);
if (ObjectUtils.isNotEmpty(labelFieldContent)) {
templateContent = templateContent.replaceAll("\\{\\{([^\\{\\}}]+)\\}\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
templateContent = templateContent.replaceAll("#\\{([^\\}]*)\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
}
}
return templateContent;

View File

@ -237,6 +237,12 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
if (node.getPhoneId() != null) {
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(node.getPhoneId());
detailInfo = JSONObject.parseObject(JSONObject.toJSONString(scriptInfo));
} else if (node.getQuestionInfoId() != null) { // 问卷
// 查询问卷详情
QuestionVO questionVO = questionInfoService.selectQuestionInfoById(node.getQuestionInfoId());
if (ObjectUtils.isNotEmpty(questionVO)) {
detailInfo = JSONObject.parseObject(JSONObject.toJSONString(questionVO));
}
}
break;
case (TaskContentConstants.QUESTIONNAIRE_SCALE): // 问卷量表-返回问卷信息
@ -644,19 +650,20 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
// 根据node去替换模板信息
manageNodeList.forEach(manageNode -> {
switch(manageNode.getTaskType()) {
// 电话外呼--话术
// 电话外呼--话术/问卷只替换话术
case TaskContentConstants.PHONE_OUTBOUND:
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(manageNode.getPhoneId());
if (ObjectUtils.isNotEmpty(scriptInfo)) {
// 话术库json内容替换
manageNode.setPhoneNodeContent(getFlowScheme(scriptInfo.getFlowScheme(), labelFieldContentList));
// 电话短信内容
if (manageNode.getPhoneMessageTemplateId() != null) {
// 查询短信库
manageNode.setPhoneMessageTemplateContent(replaceMessageInfo(manageNode.getPhoneMessageTemplateId(), labelFieldContentList));
if (manageNode.getPhoneId() != null) {
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(manageNode.getPhoneId());
if (ObjectUtils.isNotEmpty(scriptInfo)) {
// 话术库json内容替换
manageNode.setPhoneNodeContent(getFlowScheme(scriptInfo.getFlowScheme(), labelFieldContentList));
}
}
// 电话短信内容
if (manageNode.getPhoneMessageTemplateId() != null) {
// 查询短信库
manageNode.setPhoneMessageTemplateContent(replaceMessageInfo(manageNode.getPhoneMessageTemplateId(), labelFieldContentList));
}
break;
// 问卷
case TaskContentConstants.QUESTIONNAIRE_SCALE:
@ -796,16 +803,15 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
case TemplateTypeConstants.SCRIPT:
manageRouteNode.setPhoneId(node.getTemplateId());
// 查询话术
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(node.getTemplateId());
ScriptInfo scriptInfo = scriptInfoMapper.selectScriptInfoById(node.getPhoneTemplateId());
if (ObjectUtils.isNotEmpty(scriptInfo)) {
// 话术库json内容替换
manageRouteNode.setPhoneNodeContent(getFlowScheme(scriptInfo.getFlowScheme(), labelFieldContentList));
// 电话短信内容
if (node.getPhoneMessageTemplateId() != null) {
// 查询短信库
manageRouteNode.setPhoneMessageTemplateContent(replaceMessageInfo(node.getPhoneMessageTemplateId(), labelFieldContentList));
}
}
// 电话短信内容
if (node.getPhoneMessageTemplateId() != null) {
// 查询短信库
manageRouteNode.setPhoneMessageTemplateContent(replaceMessageInfo(node.getPhoneMessageTemplateId(), labelFieldContentList));
}
break;
}
@ -846,15 +852,15 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
*/
private String getFlowScheme(String flowScheme, List<LabelFieldInfoContentVo> labelFieldContentList) {
// 话术库json内容替换
if (org.apache.commons.lang3.StringUtils.isNotBlank(flowScheme) && org.apache.commons.lang3.StringUtils.contains(flowScheme, "{{") && org.apache.commons.lang3.StringUtils.contains(flowScheme, "}}")) {
// 替换{{}}中的内容
Pattern pattern = Pattern.compile("\\{\\{([^\\{\\}}]+)\\}\\}");
if (StringUtils.isNotBlank(flowScheme) && org.apache.commons.lang3.StringUtils.contains(flowScheme, "{{") && org.apache.commons.lang3.StringUtils.contains(flowScheme, "}}")) {
// 替换#{}中的内容
Pattern pattern = Pattern.compile("#\\{([^\\}]*)\\}");
Matcher matcher = pattern.matcher(flowScheme);
while (matcher.find()) {
//过滤出符合条件的对象不匹配返回null
LabelFieldInfoContentVo labelFieldContent = labelFieldContentList.stream().filter(s -> Objects.equals(s.getFieldCode(), matcher.group(1))).findFirst().orElse(null);
if (ObjectUtils.isNotEmpty(labelFieldContent)) {
flowScheme = flowScheme.replaceAll("\\{\\{([^\\{\\}}]+)\\}\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
flowScheme = flowScheme.replaceAll("#\\{([^\\}]*)\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
}
}
}
@ -872,13 +878,13 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
TextMessage textMessage = textMessageMapper.selectTextMessageById(messageTemplateId);
String textMessageContent = textMessage.getTextMessageContent();
// 替换{{}}中的内容
Pattern pattern = Pattern.compile("\\{\\{([^\\{\\}}]+)\\}\\}");
Pattern pattern = Pattern.compile("#\\{([^\\}]*)\\}");
Matcher matcher = pattern.matcher(textMessage.getTextMessageContent());
while (matcher.find()) {
// 过滤出符合条件的对象不匹配返回null
LabelFieldInfoContentVo labelFieldContent = labelFieldContentList.stream().filter(s -> Objects.equals(s.getFieldCode(), matcher.group(1))).findFirst().orElse(null);
if (ObjectUtils.isNotEmpty(labelFieldContent)) {
textMessageContent = textMessageContent.replaceAll("\\{\\{([^\\{\\}}]+)\\}\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
textMessageContent = textMessageContent.replaceAll("#\\{([^\\}]*)\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
}
}
return textMessageContent;
@ -916,13 +922,13 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
return null;
}
String templateContent = wechatTemplate.getTemplateContent();
Pattern pattern = Pattern.compile("\\{\\{([^\\{\\}}]+)\\}\\}");
Pattern pattern = Pattern.compile("#\\{([^\\}]*)\\}");
Matcher matcher = pattern.matcher(templateContent);
while (matcher.find()) {
// 过滤出符合条件的对象不匹配返回null
LabelFieldInfoContentVo labelFieldContent = labelFieldContentList.stream().filter(s -> Objects.equals(s.getFieldCode(), matcher.group(1))).findFirst().orElse(null);
if (ObjectUtils.isNotEmpty(labelFieldContent)) {
templateContent = templateContent.replaceAll("\\{\\{([^\\{\\}}]+)\\}\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
templateContent = templateContent.replaceAll("#\\{([^\\}]*)\\}", ObjectUtils.isEmpty(labelFieldContent) ? "" : labelFieldContent.getFieldValue());
}
}
return templateContent;