| | |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.IvrLibaExtemplatescriptMapper; |
| | | import com.smartor.service.IIvrLibaTemplateService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | import com.ruoyi.template.domain.IvrLibaExtemplatescript; |
| | | import com.ruoyi.template.domain.IvrLibaTemplateScriptVO; |
| | | import com.ruoyi.template.domain.IvrLibaTemplateVO; |
| | | import com.ruoyi.template.api.TemplateFacade; |
| | | @Slf4j |
| | | @Component |
| | | public class ChatWebSocketHandler extends AbstractWebSocketHandler { |
| | | |
| | | private static RedisCache redisCache; |
| | | |
| | | private static IIvrLibaTemplateService ivrLibaTemplateService; |
| | | /** |
| | | * 模板数据一律经 ruoyi-template 的门面取用(跨模块数据访问原则)。 |
| | | * <p> |
| | | * 沿用本类原有的「static 字段 + @Autowired setter」装配风格, |
| | | * 不改造成构造注入 —— 避免影响这条已有的装配路径。 |
| | | */ |
| | | private static TemplateFacade templateFacade; |
| | | |
| | | private static IvrLibaExtemplatescriptMapper ivrLibaExtemplatescriptMapper; |
| | | @Autowired |
| | | public void setTemplateFacade(TemplateFacade templateFacade) { |
| | | ChatWebSocketHandler.templateFacade = templateFacade; |
| | | } |
| | | |
| | | // 用于存储用户ID和WebSocketSession的映射关系 |
| | | private static Map<String, WebSocketSession> sessions = new ConcurrentHashMap<>(); |
| | | |
| | | @Autowired |
| | | public void setIEMapper(IvrLibaExtemplatescriptMapper ivrLibaExtemplatescriptMapper) { |
| | | ChatWebSocketHandler.ivrLibaExtemplatescriptMapper = ivrLibaExtemplatescriptMapper; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setTodayReaderService(IIvrLibaTemplateService ivrLibaTemplateService) { |
| | | ChatWebSocketHandler.ivrLibaTemplateService = ivrLibaTemplateService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setRedisCache(RedisCache redisCache) { |
| | |
| | | //通过模板ID获取模板问题 |
| | | IvrLibaTemplateVO ivrLibaTemplateVO = new IvrLibaTemplateVO(); |
| | | ivrLibaTemplateVO.setId(socketMessage.getTemplateId()); |
| | | IvrLibaTemplateVO ivrLibaTemplateVO1 = ivrLibaTemplateService.selectInfoByCondition(ivrLibaTemplateVO); |
| | | // ⚠️ 这里**刻意不**为 TemplateModuleDisabledException 降级: |
| | | // 语音问卷本身就是模板驱动的 —— 模板模块关闭(sys_config: template.enabled=false)时 |
| | | // 这次对话没有任何问题可问,继续走下去只会拿到 null 然后在下一行 NPE。 |
| | | // 抛出明确异常(提示"模板功能未启用…")远好于一个看不懂的空指针, |
| | | // 且异常会由 handleTextMessage 抛出、由 WebSocket 容器收口。 |
| | | IvrLibaTemplateVO ivrLibaTemplateVO1 = templateFacade.findIvrLibaTemplateInfoByCondition(ivrLibaTemplateVO); |
| | | redisCache.setCacheObject(userId + "ivrLibaTemplateVO1", ivrLibaTemplateVO1, 120, TimeUnit.MINUTES); |
| | | //将查出来的问题,放到全局变量中去 |
| | | List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOList = ivrLibaTemplateVO1.getIvrLibaTemplateScriptVOList(); |
| | |
| | | } |
| | | //获取模板信息 |
| | | IvrLibaTemplateVO ivrLibaTemplateVO1 = redisCache.getCacheObject(userId + "ivrLibaTemplateVO1"); |
| | | |
| | | |
| | | if (StringUtils.isEmpty(questionMessage.getContent())) { |
| | | //调用ivrTaskTemplateScriptVO中的slienceText(静默话术) |
| | |
| | | for (String str : list) { |
| | | list1.add(Long.valueOf(str)); |
| | | } |
| | | List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = ivrLibaExtemplatescriptMapper.queryIvrLibaExtemplatescriptList(list1); |
| | | // ⚠️ 与上面那处不同:本方法返回的是**列表**,空列表天然可容错 |
| | | // (下面的 for 循环一次都不进),所以模板模块关闭时不需要额外降级分支。 |
| | | List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = templateFacade.findIvrLibaExtemplatescriptsByIds(list1); |
| | | IvrLibaExtemplatescript les = null; |
| | | for (IvrLibaExtemplatescript ivrLibaExtemplatescript : ivrLibaExtemplatescripts) { |
| | | Matcher matcher = null; |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //通过valueType判断是什么题型(值类型(1 选项 2 文本 3 数值)) |
| | | if (ivrLibaTemplateScriptVO.getValueType() == 2 || ivrLibaTemplateScriptVO.getValueType() == 3) { |
| | |
| | | } |
| | | log.info("==============================Targetregex的值为:{}, Targetregex2的值为:{}", ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex(), ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); |
| | | |
| | | if (StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && |
| | | StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || |
| | | StringUtils.isEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && |
| | | StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && |
| | | matcher.matches()) { |
| | | log.error("匹配正确了"); |
| | | if (StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) { |
| | | log.info("匹配正确了"); |
| | | //说明匹配正确了 |
| | | ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).setIsUserOperation(1); |
| | | List<IvrLibaTemplateScriptVO> backQuset = redisCache.getCacheObject(userId + "backQuset"); |
| | |
| | | redisCache.setCacheObject(userId + "isOver", 1, 120, TimeUnit.MINUTES); |
| | | } else { |
| | | for (IvrLibaTemplateScriptVO script : ivrLibaTemplateScriptVOList) { |
| | | if (script.getSort() == nextQuestion) { |
| | | if (script.getSort().intValue() == nextQuestion) { |
| | | QuestionMessagePhone returnQues = new QuestionMessagePhone(); |
| | | returnQues.setNowQuestion(script); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | |
| | | break; |
| | | } |
| | | } else { |
| | | log.error("无匹配"); |
| | | log.info("无匹配"); |
| | | //没有匹配到 |
| | | Integer mateNum = redisCache.getCacheObject(userId + "mateNum"); |
| | | |
| | |
| | | // for (String str : list) { |
| | | // list1.add(Long.valueOf(str)); |
| | | // } |
| | | // List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = ivrLibaExtemplatescriptMapper.queryIvrLibaExtemplatescriptList(list1); |
| | | // List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = templateFacade.findIvrLibaExtemplatescriptsByIds(list1); |
| | | // for (IvrLibaExtemplatescript ivrLibaExtemplatescript : ivrLibaExtemplatescripts) { |
| | | // Matcher matcher = null; |
| | | // if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex())) { |