|
@ -2,6 +2,7 @@ package com.yihu.jw.im.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.entity.base.dict.DictHospitalDeptDO;
|
|
|
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
|
|
|
import com.yihu.jw.entity.knowledge.*;
|
|
|
import com.yihu.jw.im.util.ImUtil;
|
|
@ -126,32 +127,145 @@ public class RobotService {
|
|
|
welcome(session_id,mapSetting,map);
|
|
|
//自动匹配回复文字内容
|
|
|
replyContent(session_id,type,content,mapSetting,map);
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
//常见问题匹配
|
|
|
public void replyContent(String type,String content,String consult){
|
|
|
/**
|
|
|
*
|
|
|
* @param type 会话类型
|
|
|
* @param content 消息内容
|
|
|
* @param consult 咨询code
|
|
|
* @param contentType 消息类型 文本1 问题集3002
|
|
|
*/
|
|
|
//普通咨询常见问题匹配
|
|
|
public void replyContent(String type,String content,String consult,Integer contentType){
|
|
|
try {
|
|
|
BaseSystemDialogSetting setting = dialogSettingDao.findBySystemTypeAndFunctionType(sessionTypeToType(type),"7",1);
|
|
|
if(setting==null){
|
|
|
return;
|
|
|
}
|
|
|
//查找相似问题
|
|
|
BaseKnowledgeQuestion question = findQuestionLikeName(content);
|
|
|
BaseKnowledgeQuestion question = new BaseKnowledgeQuestion();
|
|
|
if (contentType==1){
|
|
|
question = findQuestionLikeName(content);
|
|
|
}else if ((contentType+"").equalsIgnoreCase(ImUtil.ContentType.KnowCommonQuestions+"")){
|
|
|
question = knowledgeQuestionDao.findById(content).get();
|
|
|
}
|
|
|
if(question!=null){
|
|
|
//匹配到相关问题后先推送答案
|
|
|
String answer = question.getAnswer();
|
|
|
WlyyHospitalSysDictDO dictDO = getSender();
|
|
|
imUtil.sendTopicIM(dictDO.getDictCode(), dictDO.getDictName(), consult, "1", answer,null);
|
|
|
//匹配问题是否关联其他配置;
|
|
|
if (question.getFlag()==null){
|
|
|
List<BaseKnowledgeFlowConfigurationRelation> flowConfigurationRelations = findFlowConfigurationRelationLikeName(content);
|
|
|
if (flowConfigurationRelations!=null&&flowConfigurationRelations.size()!=0){
|
|
|
BaseKnowledgeFlowConfigurationRelation flowConfigurationRelation = flowConfigurationRelations.get(0);
|
|
|
String contentTypes = "1";
|
|
|
String contentMsg = "";
|
|
|
if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("2")){
|
|
|
contentTypes = ImUtil.ContentType.KnowCommonDict+"";
|
|
|
contentMsg = selectByContentType(contentTypes,flowConfigurationRelation.getRelationCode()).toJSONString();
|
|
|
}else if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("3")){
|
|
|
contentTypes = ImUtil.ContentType.KnowCommonQuestions+"";
|
|
|
contentMsg = selectByContentType(contentTypes,flowConfigurationRelation.getRelationCode()).toJSONString();
|
|
|
}
|
|
|
imUtil.sendTopicIM(dictDO.getDictCode(), dictDO.getDictName(), consult, contentTypes, contentMsg,null);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @param senderId 发送人id
|
|
|
* @param senderName 发送人名称
|
|
|
* @param sessionId 会话id
|
|
|
* @param type 咨询类型
|
|
|
* @param content 内容
|
|
|
* @param contentType 消息类型
|
|
|
* @param businessType 业务类型
|
|
|
* @param extend 扩展
|
|
|
* 导诊咨询常见问题匹配
|
|
|
*/
|
|
|
public void replyGuaidenceContent(String sessionId,String type,String content,String contentType,String businessType, String extend){
|
|
|
try {
|
|
|
BaseSystemDialogSetting setting = dialogSettingDao.findBySystemTypeAndFunctionType(sessionTypeToType(type),"7",1);
|
|
|
if(setting==null){
|
|
|
return;
|
|
|
}
|
|
|
Boolean re = imUtil.sessionIsExist(sessionId);
|
|
|
if(re){
|
|
|
//查找相似问题
|
|
|
BaseKnowledgeQuestion question = new BaseKnowledgeQuestion();
|
|
|
if (contentType.equalsIgnoreCase("1")){
|
|
|
question = findQuestionLikeName(content);
|
|
|
}else if ((contentType+"").equalsIgnoreCase(ImUtil.ContentType.KnowCommonQuestions+"")){
|
|
|
question = knowledgeQuestionDao.findById(content).get();
|
|
|
}
|
|
|
if(question!=null){
|
|
|
//匹配到相关问题后先推送答案
|
|
|
String answer = question.getAnswer();
|
|
|
WlyyHospitalSysDictDO dictDO = getSender();
|
|
|
imService.patientGuaidenceAppend(dictDO.getDictCode(),dictDO.getDictValue(),sessionId,
|
|
|
contentType+"", answer, "1",null);
|
|
|
//匹配问题是否关联其他配置;
|
|
|
if (question.getFlag()==null){
|
|
|
List<BaseKnowledgeFlowConfigurationRelation> flowConfigurationRelations = findFlowConfigurationRelationLikeName(content);
|
|
|
if (flowConfigurationRelations!=null&&flowConfigurationRelations.size()!=0){
|
|
|
BaseKnowledgeFlowConfigurationRelation flowConfigurationRelation = flowConfigurationRelations.get(0);
|
|
|
String contentTypes = "1";
|
|
|
String contentMsg = "";
|
|
|
if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("2")){
|
|
|
contentTypes = ImUtil.ContentType.KnowCommonDict+"";
|
|
|
contentMsg = selectByContentType(contentTypes,flowConfigurationRelation.getRelationCode()).toJSONString();
|
|
|
}else if (flowConfigurationRelation.getRelationType().equalsIgnoreCase("3")){
|
|
|
contentTypes = ImUtil.ContentType.KnowCommonQuestions+"";
|
|
|
contentMsg = selectByContentType(contentTypes,flowConfigurationRelation.getRelationCode()).toJSONString();
|
|
|
}
|
|
|
imService.patientGuaidenceAppend(dictDO.getDictCode(),dictDO.getDictValue(),sessionId,
|
|
|
contentTypes+"", contentMsg, "1",null);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public JSONObject selectByContentType(String contentType,String id){
|
|
|
JSONObject object = new JSONObject();
|
|
|
if (contentType.equalsIgnoreCase(ImUtil.ContentType.KnowCommonDict+"")){
|
|
|
BaseKnowledgeDict dict = knowledgeDictDao.findById(id).get();
|
|
|
BaseKnowledgeDictRelation dictRelation = knowledgeDictRelationDao.selectByDictId(id);
|
|
|
if (dictRelation!=null){
|
|
|
String dept = dictRelation.getDept();
|
|
|
}
|
|
|
List<DictHospitalDeptDO> deptDOList = findDeptList(id);
|
|
|
object.put("content",deptDOList);
|
|
|
object.put("contentType",contentType);
|
|
|
|
|
|
}else if (contentType.equalsIgnoreCase(ImUtil.ContentType.KnowCommonQuestions+"")){
|
|
|
BaseKnowledgeQuestions questions = knowledgeQuestionsDao.findById(id).get();
|
|
|
List<BaseKnowledgeQuestionsRelation> questionsRelations = knowledgeQuestionsRelationDao.selectByQuestionsId(questions.getId());
|
|
|
object.put("content",questionsRelations);
|
|
|
object.put("contentType",contentType);
|
|
|
|
|
|
}
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void replyContent(String session_id,String type,String content,Map<String,BaseSystemDialogSetting> mapSetting,Map<String,JSONObject> map){
|
|
|
try {
|
|
|
BaseSystemDialogSetting setting = null;
|
|
@ -181,7 +295,7 @@ public class RobotService {
|
|
|
public void welcome(String session_id,Map<String,BaseSystemDialogSetting> mapSetting,Map<String,JSONObject> map){
|
|
|
try {
|
|
|
Boolean re = imUtil.sessionIsExist(session_id);
|
|
|
if(re){
|
|
|
if(!re){
|
|
|
//欢迎语
|
|
|
BaseSystemDialogSetting welcomeSetting = mapSetting.get("1");
|
|
|
if(welcomeSetting!=null){
|
|
@ -279,6 +393,17 @@ public class RobotService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
//查找常见问题关联配置
|
|
|
public List<BaseKnowledgeFlowConfigurationRelation> findFlowConfigurationRelationLikeName(String content){
|
|
|
if(StringUtils.isNotEmpty(content)){
|
|
|
return null;
|
|
|
}
|
|
|
String sql = "select p.* from base_knowledge_flow_configuration_relation p where " +
|
|
|
" p.relation_name like '%"+content+"%' order by sort asc ";
|
|
|
List<BaseKnowledgeFlowConfigurationRelation> flowConfigurationRelations = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseKnowledgeFlowConfigurationRelation.class));
|
|
|
return flowConfigurationRelations;
|
|
|
}
|
|
|
|
|
|
public List<BaseKnowledgeQuestions> findTopQuestionsList(Integer limit,String ids){
|
|
|
String sql = "select p.* from base_knowledge_questions p where p.status = 1 and p.del=1 and p.id in ('"+ids+"')" +
|
|
|
"(p.time=1 or (p.time=2 and p.date<'"+DateUtil.getStringDate()+"')) order by sort limit "+limit;
|
|
@ -293,12 +418,23 @@ public class RobotService {
|
|
|
return questionList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询相关字典
|
|
|
* @param limit
|
|
|
* @param ids
|
|
|
* @return
|
|
|
*/
|
|
|
public List<BaseKnowledgeDict> findTopDictList(Integer limit,String ids){
|
|
|
String sql = "select p.* from base_knowledge_dict p where p.del=1 and p.id in ('"+ids+"') order by sort limit "+limit;
|
|
|
List<BaseKnowledgeDict> dictList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(BaseKnowledgeDict.class));
|
|
|
return dictList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据业务不一样转换相关的会话类型
|
|
|
* @param type
|
|
|
* @return
|
|
|
*/
|
|
|
//会话类型转类型
|
|
|
private String sessionTypeToType(String type){
|
|
|
if(StringUtils.isNotEmpty(type)){
|
|
@ -319,4 +455,10 @@ public class RobotService {
|
|
|
return type;
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<DictHospitalDeptDO> findDeptList(String ids){
|
|
|
String sql = "select p.* from dict_hospital_dept p where p.consult_dept_flag=1 and p.code in ('"+ids+"') ";
|
|
|
List<DictHospitalDeptDO> deptDOList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(DictHospitalDeptDO.class));
|
|
|
return deptDOList;
|
|
|
}
|
|
|
}
|