| | |
| | | import com.google.gson.Gson; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.core.service.IConfigService; |
| | | import com.ruoyi.common.dx.MessageSend; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.*; |
| | | import com.ruoyi.common.core.service.IConfigService; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.system.domain.SysConfig; |
| | |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.checkerframework.checker.nullness.qual.NonNull; |
| | | import org.junit.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.DecimalFormat; |
| | |
| | | |
| | | @Value("${spring.profiles.active}") |
| | | private String active; |
| | | @Autowired |
| | | private ServiceOutPathMapper serviceOutPathMapper; |
| | | |
| | | /** |
| | | * 查询单一任务(随访) |
| | |
| | | */ |
| | | @Override |
| | | public Map<String, Object> insertServiceSubtask(ServiceSubtask serviceSubtask) { |
| | | serviceSubtask.setCreateTime(DateUtils.getNowDate()); |
| | | serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); |
| | | //先查询一下该患者是否已经创建根据serviceType,sendstate,inhospid,patid,orgid |
| | | ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity(); |
| | | serviceSubtaskVO.setServiceType(serviceSubtask.getServiceType()); |
| | | serviceSubtaskVO.setSendstates(new ArrayList<>(Arrays.asList(1L, 2L, 3L, 5L, 7L))); |
| | | serviceSubtaskVO.setPatid(serviceSubtask.getPatid()); |
| | | serviceSubtaskVO.setOrgid(serviceSubtask.getOrgid()); |
| | | serviceSubtaskVO.setCampusid(serviceSubtask.getCampusid()); |
| | | List<ServiceSubtask> serviceSubtasks = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO); |
| | | RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); |
| | | String format = null; |
| | | if (CollectionUtils.isNotEmpty(serviceSubtasks)) { |
| | | ServiceSubtask serviceSubtask1 = serviceSubtasks.get(0); |
| | | ServiceOutPath serviceOutPath = new ServiceOutPath(); |
| | | serviceOutPath.setSubId(serviceSubtask1.getId()); |
| | | List<ServiceOutPath> serviceOutPaths = serviceOutPathMapper.selectServiceOutPathList(serviceOutPath); |
| | | if (CollectionUtils.isNotEmpty(serviceOutPaths)) |
| | | format = String.format("%03X", serviceOutPaths.get(0).getId()); |
| | | else format = getOutPath(serviceSubtask1, rsaPublicKeyExample); |
| | | serviceSubtask = serviceSubtask1; |
| | | } else { |
| | | //如果不存在,则新增 |
| | | serviceSubtask.setCreateTime(DateUtils.getNowDate()); |
| | | serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); |
| | | format = getOutPath(serviceSubtask, rsaPublicKeyExample); |
| | | } |
| | | |
| | | Map<String, Object> result = new HashMap<>(); |
| | | if (StringUtils.isNotEmpty(format)) |
| | | result.put("url", StringUtils.isNotEmpty(req_path) ? localIP + ":" + req_path + "/wt?p=" + format : localIP + "/wt?p=" + format); |
| | | else result.put("url", null); |
| | | result.put("subId", serviceSubtask.getId()); |
| | | return result; |
| | | } |
| | | |
| | | private String getOutPath(ServiceSubtask serviceSubtask, RSAPublicKeyExample rsaPublicKeyExample) { |
| | | String format; |
| | | String taskId = rsaPublicKeyExample.encryptedData(serviceSubtask.getTaskid().toString(), pub_key); |
| | | String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key); |
| | | String subId = rsaPublicKeyExample.encryptedData(serviceSubtask.getId().toString(), pub_key); |
| | |
| | | serviceOutPath.setCreateTime(new Date()); |
| | | serviceOutPath.setParam6(subId); |
| | | serviceOutPath.setOrgid(serviceSubtask.getOrgid()); |
| | | serviceOutPath.setTaskId(serviceSubtask.getTaskid()); |
| | | serviceOutPath.setSubId(serviceSubtask.getId()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | //转成16进制 |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | format = String.format("%03X", serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("url", StringUtils.isNotEmpty(req_path) ? localIP + ":" + req_path + "/wt?p=" + format : localIP + "/wt?p=" + format); |
| | | result.put("subId", serviceSubtask.getId()); |
| | | return result; |
| | | return format; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | } |
| | | else if (serviceTaskVO.getIsoperation() != null && serviceTaskVO.getIsoperation() == 2) { |
| | | } else if (serviceTaskVO.getIsoperation() != null && serviceTaskVO.getIsoperation() == 2) { |
| | | //任务修改 |
| | | if (ObjectUtils.isNotEmpty(serviceTaskVO.getSendTimeslot())) |
| | | serviceTask.setSendTimeSlot(JSON.toJSONString(serviceTaskVO.getSendTimeslot())); |
| | |
| | | return serviceSubtaskMapper.statQuestionOption(taskIds, startOutHospTime, endOutHospTime); |
| | | } |
| | | |
| | | @Override |
| | | public List<ServiceSubtaskDetailRatioExport> statQuestionOptionBySubtaskIds(List<Long> subtaskIds, Date startOutHospTime, Date endOutHospTime) { |
| | | //先清理一下重复数据 |
| | | List<Long> repeatIds = serviceSubtaskDetailMapper.selectRepeatDetailIds(); |
| | | if (!CollectionUtils.isEmpty(repeatIds)) { |
| | | serviceSubtaskDetailMapper.deleteRepeatDetailByIds(repeatIds); |
| | | } |
| | | return serviceSubtaskMapper.statQuestionOptionBySubtaskIds(subtaskIds, startOutHospTime, endOutHospTime); |
| | | } |
| | | |
| | | /** |
| | | * 标准化问卷答案文本:去掉 A/B/C/D 单字母前缀和后续空格 |
| | | * 例如 "A 是" -> "是","B 否" -> "否" |
| | |
| | | String jsonString = jsonObject.toJSONString(); |
| | | String result = null; |
| | | |
| | | // String url = "http://localhost:8099/matchOptionIndex"; |
| | | // String url = "cc"; |
| | | if (StringUtils.isNotEmpty(url)) { |
| | | try { |
| | | Map<String, String> headers = new HashMap<>(); |
| | |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | |
| | | public PhoneCallBackSHVO getFirstQues(PhoneCallReqYQVO phoneCallReqYQVO) { |
| | | //用于返回 |
| | | PhoneCallBackSHVO phoneCallBackSHVO = new PhoneCallBackSHVO(); |
| | | |
| | | //根据手机号获取用户的的子任务信息 |
| | | ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity(); |
| | | serviceSubtaskVO.setPhone(phoneCallReqYQVO.getPhone()); |
| | | serviceSubtaskVO.setType("1"); |
| | | serviceSubtaskVO.setSendstate(2L); |
| | | List<ServiceSubtask> serviceSubtasks = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO); |
| | | if (CollectionUtils.isNotEmpty(serviceSubtasks)) { |
| | | ServiceSubtask serviceSubtask = serviceSubtasks.get(0); |
| | | IvrTaskTemplate ivrTaskTemplate = ivrTaskTemplateService.selectIvrTaskTemplateByID(serviceSubtask.getTemplateid()); |
| | | |
| | | //通过任务模板中的"第一次问题编号"获取第一个问题; |
| | | IvrTaskTemplateScript ivrTaskTemplateScript = null; |
| | | IvrTaskTemplateScript ivrTaskTemplateScript1 = new IvrTaskTemplateScript(); |
| | | ivrTaskTemplateScript1.setTemplateID(ivrTaskTemplate.getId()); |
| | | List<IvrTaskTemplateScript> ivrTaskTemplateScripts = iIvrTaskTemplateScriptService.selectIvrTaskTemplateScriptList(ivrTaskTemplateScript1); |
| | | |
| | | for (IvrTaskTemplateScript ivrTaskTemplateScript2 : ivrTaskTemplateScripts) { |
| | | if (ivrTaskTemplate.getFirstQuestionNum() == Long.valueOf(ivrTaskTemplateScript2.getSort())) { |
| | | ivrTaskTemplateScript = ivrTaskTemplateScript2; |
| | | break; |
| | | } |
| | | } |
| | | //获取开场白 |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | |
| | | phoneCallBackSHVO.setSubId(serviceSubtask.getId()); |
| | | phoneCallBackSHVO.setScriptId(ivrTaskTemplateScript.getId()); |
| | | phoneCallBackSHVO.setSort(ivrTaskTemplateScript.getSort()); |
| | | phoneCallBackSHVO.setTaskTemplateid(ivrTaskTemplateScript.getTemplateID()); |
| | | phoneCallBackSHVO.setScriptContent(serviceTask.getKcb() + "," + ivrTaskTemplateScript.getScriptContent()); |
| | | } |
| | | return phoneCallBackSHVO; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 三汇ASR结果处理 |
| | | * |
| | | * @param phoneCallResultYQVO |
| | | * @return |
| | | */ |
| | | public PhoneCallBackSHVO processResust(PhoneCallResultYQVO phoneCallResultYQVO) { |
| | | PhoneCallBackSHVO phoneCallBackSHVO = new PhoneCallBackSHVO(); |
| | | //通过scriptid,获取所有的结果 |
| | | String url = configService.selectConfigByKey("sys.voice.match.ai.url", phoneCallResultYQVO.getOrgid()); |
| | | ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(phoneCallResultYQVO.getSubId()); |
| | | IvrTaskTemplate ivrTaskTemplate = ivrTaskTemplateService.selectIvrTaskTemplateByID(serviceSubtask.getTemplateid()); |
| | | IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO = iIvrTaskTemplateScriptService.getTaskTempScriptInfoByid(Long.valueOf(phoneCallResultYQVO.getScriptId())); |
| | | Integer i = matchOptionIndex(url, phoneCallResultYQVO.getScriptContent(), phoneCallResultYQVO.getAsrResult(), ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList(), phoneCallResultYQVO.getUuid()); |
| | | if (i >= 0) { |
| | | String optiondesc = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(i).getOptiondesc(); |
| | | //将患者的回答写进service_subtask_detail中 |
| | | ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq(); |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>(); |
| | | ivrTaskTemplateScriptVO.setQuestionResult(optiondesc); |
| | | |
| | | PhoneCallReqYQVO phoneCallReqYQVO = new PhoneCallReqYQVO(); |
| | | phoneCallReqYQVO.setTaskid("" + serviceSubtask.getId()); |
| | | phoneCallReqYQVO.setPhone(phoneCallResultYQVO.getPhone()); |
| | | phoneCallReqYQVO.setAsrtext(phoneCallResultYQVO.getAsrResult()); |
| | | ServiceSubtaskDetail serviceSubtaskDetail = getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate); |
| | | //修改一下语音路径(改成前端可以访问的,存到数据库中) |
| | | if (StringUtils.isNotEmpty(serviceSubtaskDetail.getQuestionvoice())) { |
| | | String questionvoice = serviceSubtaskDetail.getQuestionvoice(); |
| | | String[] split = questionvoice.split("\\\\"); |
| | | if (split.length > 0) { |
| | | String lastPart = split[split.length - 1]; |
| | | serviceSubtaskDetail.setQuestionvoice(voicePathPrefix + lastPart); |
| | | } |
| | | } |
| | | serviceSubtaskDetailList.add(serviceSubtaskDetail); |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList); |
| | | serviceSubTaskDetailReq.setGuid(phoneCallResultYQVO.getGuid()); |
| | | serviceSubTaskDetailReq.setOrgid(phoneCallResultYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(serviceSubTaskDetailReq); |
| | | |
| | | IvrTaskTemplateScript ivrTaskTemplateScript = new IvrTaskTemplateScript(); |
| | | ivrTaskTemplateScript.setTemplateID(ivrTaskTemplateScriptVO.getTemplateID()); |
| | | List<IvrTaskTemplateScript> ivrTaskTemplateScripts = iIvrTaskTemplateScriptService.selectIvrTaskTemplateScriptList(ivrTaskTemplateScript); |
| | | |
| | | //获取下一题 |
| | | for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) { |
| | | if (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0) { |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | phoneCallBackSHVO.setScriptContent(serviceTask.getJsy()); |
| | | phoneCallBackSHVO.setTaskTemplateid(script.getTemplateID()); |
| | | phoneCallBackSHVO.setSort(script.getSort()); |
| | | phoneCallBackSHVO.setScriptId(script.getId()); |
| | | phoneCallBackSHVO.setSubId(serviceSubtask.getId()); |
| | | phoneCallBackSHVO.setStatus("0"); |
| | | } else if (script.getSort() == ivrTaskTemplateScriptVO.getNextScriptno().intValue()) { |
| | | phoneCallBackSHVO.setScriptContent(script.getScriptContent()); |
| | | phoneCallBackSHVO.setTaskTemplateid(script.getTemplateID()); |
| | | phoneCallBackSHVO.setSort(script.getSort()); |
| | | phoneCallBackSHVO.setScriptId(script.getId()); |
| | | phoneCallBackSHVO.setSubId(serviceSubtask.getId()); |
| | | break; |
| | | } |
| | | } |
| | | //把缓存清除 |
| | | redisCache.deleteObject(phoneCallResultYQVO.getSubId() + "-" + phoneCallResultYQVO.getScriptId()); |
| | | } else { |
| | | //再将重复询问 |
| | | //记录一下这个问题被问题的次数 |
| | | Object cacheObject = redisCache.getCacheObject(phoneCallResultYQVO.getSubId() + "-" + phoneCallResultYQVO.getScriptId()); |
| | | if (cacheObject == null || (Integer) cacheObject < ivrTaskTemplate.getMateNum()) { |
| | | |
| | | |
| | | // 获取选项集合中的 optiondesc 用于引导患者 |
| | | List<IvrTaskTemplateTargetoption> optionList = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList(); |
| | | String optionDescStr = ""; |
| | | if (optionList != null && !optionList.isEmpty()) { |
| | | optionDescStr = optionList.stream().map(IvrTaskTemplateTargetoption::getTargetvalue).filter(StringUtils::isNotEmpty).collect(Collectors.joining("或")); |
| | | } |
| | | |
| | | String scriptContent = "请问" + phoneCallResultYQVO.getScriptContent(); |
| | | if (StringUtils.isNotEmpty(optionDescStr)) { |
| | | scriptContent += ",你可以回答:" + optionDescStr; |
| | | } |
| | | phoneCallBackSHVO.setScriptContent(scriptContent); |
| | | phoneCallBackSHVO.setTaskTemplateid(phoneCallResultYQVO.getTaskTemplateid()); |
| | | phoneCallBackSHVO.setSort(phoneCallResultYQVO.getSort()); |
| | | phoneCallBackSHVO.setScriptId(phoneCallResultYQVO.getScriptId()); |
| | | phoneCallBackSHVO.setSubId(phoneCallResultYQVO.getSubId()); |
| | | if (cacheObject == null) |
| | | redisCache.setCacheObject(phoneCallResultYQVO.getSubId() + "-" + phoneCallResultYQVO.getScriptId(), 1, 120, TimeUnit.MINUTES); |
| | | else |
| | | redisCache.setCacheObject(phoneCallResultYQVO.getSubId() + "-" + phoneCallResultYQVO.getScriptId(), (Integer) cacheObject + 1, 120, TimeUnit.MINUTES); |
| | | } else if ((Integer) cacheObject >= ivrTaskTemplate.getMateNum()) { |
| | | //如果已经问了规定次数,就不问了,继续问下一题(这个要商量一下,是继续问下一题,还是停了,是不是要做个开关) |
| | | IvrTaskTemplateScript ivrTaskTemplateScript = new IvrTaskTemplateScript(); |
| | | ivrTaskTemplateScript.setTemplateID(ivrTaskTemplateScriptVO.getTemplateID()); |
| | | List<IvrTaskTemplateScript> ivrTaskTemplateScripts = iIvrTaskTemplateScriptService.selectIvrTaskTemplateScriptList(ivrTaskTemplateScript); |
| | | //获取下一题 |
| | | for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) { |
| | | if (script.getSort() == ivrTaskTemplateScriptVO.getNextScriptno().intValue()) { |
| | | phoneCallBackSHVO.setScriptContent(script.getScriptContent()); |
| | | phoneCallBackSHVO.setTaskTemplateid(script.getTemplateID()); |
| | | phoneCallBackSHVO.setSort(script.getSort()); |
| | | phoneCallBackSHVO.setScriptId(script.getId()); |
| | | phoneCallBackSHVO.setSubId(serviceSubtask.getId()); |
| | | break; |
| | | } |
| | | } |
| | | //把缓存清除 |
| | | redisCache.deleteObject(phoneCallResultYQVO.getSubId() + "-" + phoneCallResultYQVO.getScriptId()); |
| | | } |
| | | } |
| | | return phoneCallBackSHVO; |
| | | } |
| | | |
| | | |
| | | public PhoneCallBackYQVO AiMatch(String url, PhoneCallReqYQVO phoneCallReqYQVO, PhoneCallBackYQVO phoneCallBackYQVO, IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO, ServiceSubtask serviceSubtask, IvrTaskTemplate ivrTaskTemplate, List<IvrTaskTemplateScript> ivrTaskTemplateScripts, String scriptId, Integer flag, String uuid) { |
| | | PhoneCallBackYQVO back = null; |
| | |
| | | } |
| | | |
| | | //获取任务组信息 |
| | | private void findServiceTaskScheduleVO(ServiceTaskVO serviceTaskVO){ |
| | | if(StringUtils.isNotEmpty(serviceTaskVO.getAppltype()) && serviceTaskVO.getAppltype().equals("5")){ |
| | | private void findServiceTaskScheduleVO(ServiceTaskVO serviceTaskVO) { |
| | | if (StringUtils.isNotEmpty(serviceTaskVO.getAppltype()) && serviceTaskVO.getAppltype().equals("5")) { |
| | | //任务组信息 |
| | | ServiceTaskSchedule schedule = serviceTaskScheduleService.selectByTaskid(serviceTaskVO.getTaskid()); |
| | | if (ObjectUtils.isNotEmpty(schedule)) { |
| | | ServiceTaskScheduleVO serviceTaskScheduleVO = DtoConversionUtils.sourceToTarget(schedule, ServiceTaskScheduleVO.class); |
| | | List<ServiceTaskScheduleDetail> scheduleDetailList = |
| | | serviceTaskScheduleService.selectDetailByScheduleid(schedule.getId()); |
| | | List<ServiceTaskScheduleDetail> scheduleDetailList = serviceTaskScheduleService.selectDetailByScheduleid(schedule.getId()); |
| | | serviceTaskScheduleVO.setDetailList(scheduleDetailList); |
| | | serviceTaskVO.setServiceTaskScheduleVO(serviceTaskScheduleVO); |
| | | } |