|
@ -0,0 +1,133 @@
|
|
|
package com.yihu.jw.hospital.service.consult;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.entity.knowledge.BaseKnowledgeDict;
|
|
|
import com.yihu.jw.entity.knowledge.BaseKnowledgeQuestion;
|
|
|
import com.yihu.jw.entity.knowledge.BaseKnowledgeQuestions;
|
|
|
import com.yihu.jw.entity.knowledge.BaseSystemDialogSetting;
|
|
|
import com.yihu.jw.im.util.ImUtil;
|
|
|
import com.yihu.jw.knowledge.dao.*;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 机器人
|
|
|
* Created by yeshijie on 2023/4/12.
|
|
|
*/
|
|
|
@Service
|
|
|
public class RobotService {
|
|
|
|
|
|
@Autowired
|
|
|
private ImUtil imUtil;
|
|
|
@Autowired
|
|
|
private BaseSystemDialogSettingDao dialogSettingDao;
|
|
|
@Autowired
|
|
|
private BaseKnowledgeDictDao knowledgeDictDao;
|
|
|
@Autowired
|
|
|
private BaseKnowledgeDictRelationDao knowledgeDictRelationDao;
|
|
|
@Autowired
|
|
|
private BaseKnowledgeQuestionDao knowledgeQuestionDao;
|
|
|
@Autowired
|
|
|
private BaseKnowledgeFlowConfigurationRelationDao knowledgeFlowConfigurationRelationDao;
|
|
|
@Autowired
|
|
|
private BaseKnowledgeQuestionsDao knowledgeQuestionsDao;
|
|
|
@Autowired
|
|
|
private BaseKnowledgeQuestionsRelationDao knowledgeQuestionsRelationDao;
|
|
|
|
|
|
|
|
|
//智能导致助手回复
|
|
|
public void robotReply(String session_id,String type,String content){
|
|
|
List<BaseSystemDialogSetting> settingList = dialogSettingDao.selectBySystemTypeAndFlag(sessionTypeToType(type),1);
|
|
|
if(settingList.size()==0){
|
|
|
//未配置自动回复内容
|
|
|
return;
|
|
|
}
|
|
|
Map<String,BaseSystemDialogSetting> mapSetting = settingList.stream().collect(Collectors.toMap(BaseSystemDialogSetting::getFunctionType, v -> v,(o1,o2)->o1));
|
|
|
//欢迎语
|
|
|
welcome(session_id,mapSetting);
|
|
|
//自动匹配回复文字内容
|
|
|
replyContent(session_id,content,mapSetting);
|
|
|
}
|
|
|
|
|
|
|
|
|
public void replyContent(String session_id,String content,Map<String,BaseSystemDialogSetting> mapSetting){
|
|
|
|
|
|
}
|
|
|
|
|
|
public void welcome(String session_id,Map<String,BaseSystemDialogSetting> mapSetting){
|
|
|
Boolean re = imUtil.sessionIsExist(session_id);
|
|
|
if(re){
|
|
|
//欢迎语
|
|
|
BaseSystemDialogSetting welcomeSetting = mapSetting.get("1");
|
|
|
if(welcomeSetting!=null){
|
|
|
String welcomeContent = welcomeSetting.getContent();
|
|
|
}
|
|
|
//欢迎消息关联问题
|
|
|
BaseSystemDialogSetting welcomeQueSetting = mapSetting.get("2");
|
|
|
if(welcomeQueSetting!=null){
|
|
|
Integer relaitonCodeType = welcomeQueSetting.getRelaitonCodeType();//1常见问题2字典中心3问题集
|
|
|
relaitonCodeType = relaitonCodeType==null?-1:relaitonCodeType;
|
|
|
String relationCode = welcomeQueSetting.getRelationCode();//relationType2对应业务code,多个逗号隔开
|
|
|
if(relaitonCodeType==1){
|
|
|
//1常见问题
|
|
|
List<BaseKnowledgeQuestion> questionList = knowledgeQuestionDao.findTopList(DateUtil.getStringDate(),10);
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (BaseKnowledgeQuestion question:questionList){
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("id",question.getId());
|
|
|
json.put("questionName",question.getQuestionName());
|
|
|
jsonArray.add(jsonArray);
|
|
|
}
|
|
|
}else if(relaitonCodeType==2){
|
|
|
List<BaseKnowledgeDict> dictList = knowledgeDictDao.findTopList(10);
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (BaseKnowledgeDict dict:dictList){
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("id",dict.getId());
|
|
|
json.put("name",dict.getName());
|
|
|
jsonArray.add(jsonArray);
|
|
|
}
|
|
|
}else if(relaitonCodeType==3){
|
|
|
List<BaseKnowledgeQuestions> questionsList = knowledgeQuestionsDao.findTopList(DateUtil.getStringDate(),10);
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (BaseKnowledgeQuestions questions:questionsList){
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("id",questions.getId());
|
|
|
json.put("questionsName",questions.getQuestionsName());
|
|
|
json.put("businessType",questions.getBusinessType());
|
|
|
jsonArray.add(jsonArray);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//会话类型转类型
|
|
|
private String sessionTypeToType(String type){
|
|
|
if(StringUtils.isNotEmpty(type)){
|
|
|
return type;
|
|
|
}
|
|
|
if("18".equals(type)){
|
|
|
return "1";
|
|
|
}
|
|
|
if("26".equals(type)){
|
|
|
return "2";
|
|
|
}
|
|
|
if("27".equals(type)){
|
|
|
return "3";
|
|
|
}
|
|
|
if("28".equals(type)){
|
|
|
return "4";
|
|
|
}
|
|
|
return type;
|
|
|
}
|
|
|
|
|
|
}
|