| | |
| | | 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.enums.WxGZHEnum; |
| | | import com.ruoyi.message.sms.provider.sltd.ws.MessageSend; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.*; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.ruoyi.common.utils.sms.smsUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.message.SendResult; |
| | | import com.ruoyi.message.sms.SmsSendRequest; |
| | | import com.ruoyi.message.sms.SmsSenderFactory; |
| | | import com.ruoyi.message.wechat.WechatSendRequest; |
| | | import com.ruoyi.message.wechat.WechatSenderFactory; |
| | | import com.ruoyi.system.domain.SysConfig; |
| | | import com.ruoyi.system.mapper.SysConfigMapper; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.smartor.common.FtpService; |
| | | import com.smartor.common.MtSubmitSmUtil; |
| | | import com.smartor.common.ScheduleSubtaskBuilder; |
| | | import com.smartor.config.PhoneUtils; |
| | | import com.smartor.domain.DTO.MydTrendReqDTO; |
| | | import com.smartor.domain.DTO.MzMydScoreRankDTO; |
| | | import com.smartor.domain.DTO.QuestionCountKsOrBqDTO; |
| | | import com.smartor.domain.DTO.ServiceSubtaskDetailDTO; |
| | | import com.smartor.domain.DTO.ServiceSubtaskOptionStatDTO; |
| | | import com.smartor.domain.DTO.*; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.domain.VO.*; |
| | | import com.smartor.domain.entity.ServiceSubtaskEntity; |
| | |
| | | private ISysConfigService configService; |
| | | |
| | | @Autowired |
| | | private MtSubmitSmUtil mtSubmitSmUtil; |
| | | private SysConfigMapper sysConfigMapper; |
| | | |
| | | /** |
| | | * 消息发送方工厂(短信/微信公众号),替代原来直接调用各站点发送代码的写法 |
| | | */ |
| | | @Autowired |
| | | private SmsSenderFactory smsSenderFactory; |
| | | |
| | | @Autowired |
| | | private SysConfigMapper sysConfigMapper; |
| | | private WechatSenderFactory wechatSenderFactory; |
| | | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | |
| | | |
| | | @Value("${req_path}") |
| | | private String req_path; |
| | | |
| | | @Value("${xhsmsPath}") |
| | | private String xhsmsPath; |
| | | |
| | | @Value("${phoneUpEveryHour}") |
| | | private Integer phoneUpEveryHour; |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Cacheable(value = "sfStatistics", key = "T(org.springframework.util.DigestUtils).md5DigestAsHex(#serviceSubtaskCountReq.toString().getBytes())", unless = "#result == null or #result.isEmpty()") |
| | | // @Cacheable(value = "sfStatistics", key = "T(org.springframework.util.DigestUtils).md5DigestAsHex(#serviceSubtaskCountReq.toString().getBytes())", unless = "#result == null or #result.isEmpty()") |
| | | public List<ServiceSubtaskStatistic> getSfStatistics(ServiceSubtaskCountReq serviceSubtaskCountReq) { |
| | | log.info("getSfStatistics的入参为:{}", serviceSubtaskCountReq); |
| | | String drcode = "drcode"; |
| | |
| | | ssRate.setOrgid(serviceSubtaskCountReq.getOrgid()); |
| | | ssRate.setStarttime(serviceSubtaskCountReq.getStartTime()); |
| | | ssRate.setEndtime(serviceSubtaskCountReq.getEndTime()); |
| | | ssRate.setStartOutHospTime(serviceSubtaskCountReq.getHospitalStartTime()); |
| | | ssRate.setEndOutHospTime(serviceSubtaskCountReq.getHospitalEndTime()); |
| | | ssRate.setVisitCount(serviceSubtaskCountReq.getVisitCount()); |
| | | ssRate.setServiceTypeList(serviceSubtaskCountReq.getServiceType()); |
| | | if (serviceSubtaskCountReq.getEndTime() != null && new Date().before(serviceSubtaskCountReq.getEndTime())) { |
| | |
| | | if (serviceSubtaskCountReq.getEndTime() != null && new Date().before(serviceSubtaskCountReq.getEndTime())) { |
| | | ss.setEndtime(new Date()); |
| | | } |
| | | ss.setStartOutHospTime(serviceSubtaskCountReq.getHospitalStartTime()); |
| | | ss.setEndOutHospTime(serviceSubtaskCountReq.getHospitalEndTime()); |
| | | Double jsRate = serviceSubtaskMapper.selectTimelyRate(ss); |
| | | statistic.setRate(jsRate); |
| | | if (ObjectUtils.isNotEmpty(statistic)) { |
| | |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | serviceOutPath.setUrl(url); |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("phone", serviceSubtask.getPhone()); |
| | | map.put("content", sendMagParam.getContent()); |
| | | HttpUtil.postJsonRequest(xhsmsPath, new Gson().toJson(map)); |
| | | //短信发送已收口到 ruoyi-message 模块;与原实现一致:不判断发送结果 |
| | | smsSenderFactory.send(active, SmsSendRequest.of(serviceSubtask.getPhone(), sendMagParam.getContent(), serviceSubtask.getOrgid())); |
| | | redisCache.setCacheObject(subTaskId + "recordAccept-hungup", "1", 10, TimeUnit.MINUTES); |
| | | if (StringUtils.isNotEmpty(serviceSubtask.getRemark())) |
| | | serviceSubtask.setRemark("电话发送拒接,短信补偿发送成功"); |
| | |
| | | sendMagParam.setContent(smsContemt.replace("${wjurl}", sendMagParam.getUrl())); |
| | | } |
| | | |
| | | //短信发送:各站点对接方式差异较大,已收口到 ruoyi-message 模块 |
| | | if (active.equals("nhfy")) { |
| | | Map<String, Object> smsResult = mtSubmitSmUtil.submitSm(sendMagParam.getPhone(), sendMagParam.getContent()); |
| | | if (smsResult != null && smsResult.get("result") != null && smsResult.get("result").toString().equals("0")) { |
| | | SendResult smsResult = smsSenderFactory.send(active, |
| | | SmsSendRequest.of(sendMagParam.getPhone(), sendMagParam.getContent(), serviceSubtask.getOrgid())); |
| | | if (smsResult.isOk()) { |
| | | resultMap.put("code", "200"); |
| | | resultMap.put("msg", "发送成功"); |
| | | serviceSubtask.setRemark(StringUtils.isNotEmpty(serviceSubtask.getRemark()) ? serviceSubtask.getRemark() + ";短信发送成功(手动提交)" : "短信发送成功(手动提交)"); |
| | |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | |
| | | |
| | | //获取微信公众号请求信息根据机构ID |
| | | List<String> wxqqxx = WxGZHEnum.getDescByCode(serviceSubtask.getOrgid()); |
| | | if (CollectionUtils.isEmpty(wxqqxx) || wxqqxx.size() < 4) { |
| | | resultMap.put("code", -1); |
| | | resultMap.put("message", "发送异常:" + "【公众号】该机构的公众号配置信息不全,无法通过公众号发送"); |
| | | return resultMap; |
| | | } |
| | | |
| | | //his患者id校验(与原实现一致:先校验这一项) |
| | | if (StringUtils.isEmpty(serviceSubtask.getPatidHis())) { |
| | | resultMap.put("code", -1); |
| | | resultMap.put("message", "发送异常:" + "【公众号】公众号发送失败,his系统的患者id为空"); |
| | | return resultMap; |
| | | } |
| | | String wxCode = ""; |
| | | wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), patArchive.getTelcode(), serviceSubtask.getSendname(), patArchive.getPatidHis(), wxqqxx); |
| | | Map map = JSONObject.parseObject(wxCode, Map.class); |
| | | Boolean wxCodeSuccess = false; |
| | | if (!map.isEmpty() && map.get("succ") != null) { |
| | | wxCodeSuccess = (boolean) map.get("succ"); |
| | | } |
| | | |
| | | //机构配置校验、报文签名与返回判定均已收口到 ruoyi-message 的发送方实现 |
| | | WechatSendRequest wechatRequest = new WechatSendRequest(); |
| | | wechatRequest.setOrgid(serviceSubtask.getOrgid()); |
| | | wechatRequest.setIdCard(serviceSubtask.getSfzh()); |
| | | wechatRequest.setUrl(url); |
| | | wechatRequest.setTitle(serviceSubtask.getTaskName()); |
| | | wechatRequest.setContent(serviceSubtask.getTaskDesc()); |
| | | wechatRequest.setPhone(patArchive.getTelcode()); |
| | | wechatRequest.setPatientName(serviceSubtask.getSendname()); |
| | | wechatRequest.setPatidHis(patArchive.getPatidHis()); |
| | | SendResult wechatResult = wechatSenderFactory.send(active, wechatRequest); |
| | | |
| | | //发送完成后,修改状态 |
| | | serviceSubtask.setSendstate(3L); |
| | | if (wxCodeSuccess) { |
| | | if (wechatResult.isOk()) { |
| | | serviceSubtask.setResult("success"); |
| | | resultMap.put("code", "200"); |
| | | resultMap.put("msg", "发送成功"); |
| | | } else { |
| | | log.error("【sfHandlle】公众号发送失败,患者信息:{},错误信息:{}", serviceSubtask, map.get("msg")); |
| | | log.error("【sfHandlle】公众号发送失败,患者信息:{},错误信息:{}", serviceSubtask, wechatResult.getMessage()); |
| | | resultMap.put("code", -1); |
| | | resultMap.put("message", "【公众号】公众号发送失败"); |
| | | return resultMap; |
| | |
| | | } |
| | | |
| | | List<ServiceSubtaskDetailRatioExport> serviceSubtaskDetailRatioExports = serviceSubtaskMapper.statQuestionOptionBySubtaskIds(subtaskIds, startOutHospTime, endOutHospTime, startFinishTime, endFinishTime, scoreStart, scoreEnd, scriptContent, valueType); |
| | | // 处理 targetvalue:按 & 分割成多条记录 |
| | | // SQL 已按「题目 + 选项」汇总数量,这里再按题目合并(不同模板的 targetvalue 选项顺序不同,同一选项会拆成多行), |
| | | // 并把没人选的选项补成 0 行、按各选项数量之和重算比例 |
| | | return mergeMydOptionRows(serviceSubtaskDetailRatioExports); |
| | | } |
| | | |
| | | /** |
| | | * 把 SQL 返回的「题目 + 选项」明细合并成「一行一个选项」 |
| | | * <ul> |
| | | * <li>同一题目下相同 optionresult 的数量累加:原实现遇到同名选项直接 continue, |
| | | * 每个选项只会保留第一条明细的数量,多任务/多患者的项数全被丢掉,前端「数量」永远只有 1</li> |
| | | * <li>选项清单取 targetvalue(用 & 连接),没人选的选项补 0 行,前端固定六列才能渲染</li> |
| | | * <li>比例 = 该选项数量 / 该题各选项数量之和,保证一道题各选项比例合计 100%</li> |
| | | * </ul> |
| | | * |
| | | * @param rows SQL 明细 |
| | | */ |
| | | private List<ServiceSubtaskDetailRatioExport> mergeMydOptionRows(List<ServiceSubtaskDetailRatioExport> rows) { |
| | | List<ServiceSubtaskDetailRatioExport> result = new ArrayList<>(); |
| | | for (ServiceSubtaskDetailRatioExport export : serviceSubtaskDetailRatioExports) { |
| | | if (StringUtils.isNotEmpty(export.getTargetvalue()) && export.getTargetvalue().contains("&")) { |
| | | String[] values = export.getTargetvalue().split("&"); |
| | | // 如果有多条目标值,拆分成多行 |
| | | for (String value : values) { |
| | | //先去 result 中查一下,有没有这个 questiontext 和对应的 targetvalue |
| | | ServiceSubtaskDetailRatioExport existingExport = result.stream().filter(e -> { |
| | | if (e == null || export == null) { |
| | | return false; |
| | | } |
| | | String q1 = e.getQuestiontext() != null ? e.getQuestiontext() : ""; |
| | | String q2 = export.getQuestiontext() != null ? export.getQuestiontext() : ""; |
| | | String t1 = value.trim(); |
| | | String t2 = e.getTargetvalue() != null ? e.getTargetvalue() : ""; |
| | | return q1.equals(q2) && t1.equals(t2); |
| | | }).findFirst().orElse(null); |
| | | if (existingExport != null && "0".equals(existingExport.getRatio()) && "0".equals(existingExport.getCount())) { |
| | | //如果存在,则将 result 里的这个问题所对应的 Targetvalue=value 这条数据更新成当前这条数据 |
| | | if (value.equals(export.getOptionresult())) { |
| | | existingExport.setRatio(export.getRatio()); |
| | | existingExport.setScore(export.getScore()); |
| | | existingExport.setCount(export.getCount()); |
| | | existingExport.setOptionresult(export.getOptionresult()); |
| | | } |
| | | } else if (existingExport != null && !"0".equals(existingExport.getRatio())) { |
| | | continue; |
| | | } else { |
| | | ServiceSubtaskDetailRatioExport newExport = DtoConversionUtils.sourceToTarget(export, ServiceSubtaskDetailRatioExport.class); |
| | | newExport.setTargetvalue(value.trim()); // targetvalue 显示单个选项 |
| | | if (!value.equals(export.getOptionresult())) { |
| | | newExport.setOptionresult(null); |
| | | newExport.setCount("0"); |
| | | newExport.setRatio("0"); |
| | | } |
| | | result.add(newExport); |
| | | } |
| | | if (CollectionUtils.isEmpty(rows)) { |
| | | return result; |
| | | } |
| | | |
| | | // key -> 选项 -> 数量,用 LinkedHashMap 保序:选项顺序沿用问卷配置 targetvalue 的顺序 |
| | | Map<String, Map<String, long[]>> countMap = new LinkedHashMap<>(); |
| | | Map<String, Map<String, String>> scoreMap = new LinkedHashMap<>(); |
| | | Map<String, ServiceSubtaskDetailRatioExport> templateMap = new LinkedHashMap<>(); |
| | | |
| | | for (ServiceSubtaskDetailRatioExport row : rows) { |
| | | if (row == null) { |
| | | continue; |
| | | } |
| | | String key = row.getQuestiontext(); |
| | | if (key == null) { |
| | | continue; |
| | | } |
| | | Map<String, long[]> counts = countMap.computeIfAbsent(key, k -> new LinkedHashMap<>()); |
| | | Map<String, String> scores = scoreMap.computeIfAbsent(key, k -> new LinkedHashMap<>()); |
| | | templateMap.putIfAbsent(key, row); |
| | | |
| | | // 题目配置的选项清单:没人选的选项也要列出来(数量为 0) |
| | | for (String option : splitOptions(row.getTargetvalue())) { |
| | | counts.computeIfAbsent(option, k -> new long[1]); |
| | | } |
| | | |
| | | // 患者实际选中的选项:多选题 asrtext 是「选项1&选项2」,单选/问答题是整段文本 |
| | | List<String> chosenOptions = "2".equals(row.getValueType()) |
| | | ? splitOptions(row.getOptionresult()) |
| | | : singleOption(row.getOptionresult()); |
| | | if (chosenOptions.isEmpty()) { |
| | | // 未作答:不进任何选项,也不进分母 |
| | | continue; |
| | | } |
| | | long count = parseCount(row.getCount()); |
| | | for (String chosen : chosenOptions) { |
| | | // 选中的选项可能不在配置清单里(历史数据),补一行,数量不能丢 |
| | | counts.computeIfAbsent(chosen, k -> new long[1])[0] += count; |
| | | if (StringUtils.isNotEmpty(row.getScore()) && StringUtils.isEmpty(scores.get(chosen))) { |
| | | scores.put(chosen, row.getScore()); |
| | | } |
| | | } else { |
| | | // targetvalue 不包含 &,直接添加到结果 |
| | | result.add(export); |
| | | } |
| | | } |
| | | |
| | | for (Map.Entry<String, Map<String, long[]>> entry : countMap.entrySet()) { |
| | | ServiceSubtaskDetailRatioExport template = templateMap.get(entry.getKey()); |
| | | Map<String, String> scores = scoreMap.get(entry.getKey()); |
| | | long total = 0L; |
| | | for (long[] count : entry.getValue().values()) { |
| | | total += count[0]; |
| | | } |
| | | for (Map.Entry<String, long[]> optionEntry : entry.getValue().entrySet()) { |
| | | String option = optionEntry.getKey(); |
| | | long count = optionEntry.getValue()[0]; |
| | | ServiceSubtaskDetailRatioExport merged = DtoConversionUtils.sourceToTarget(template, ServiceSubtaskDetailRatioExport.class); |
| | | merged.setQuestiontext(template.getQuestiontext()); |
| | | merged.setTargetvalue(option); |
| | | // 没人选的选项 optionresult 置空,前端按 targetvalue 兜底展示,保持原有展示口径 |
| | | merged.setOptionresult(count > 0 ? option : null); |
| | | merged.setCount(String.valueOf(count)); |
| | | merged.setRatio(formatRatio(count, total)); |
| | | merged.setScore(StringUtils.isNotEmpty(scores.get(option)) ? scores.get(option) : template.getScore()); |
| | | result.add(merged); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 单选/问答题的作答文本:不按 & 拆,避免把问答题的文本答案拆坏 |
| | | */ |
| | | private static List<String> singleOption(String answer) { |
| | | List<String> options = new ArrayList<>(); |
| | | String text = trimAll(answer); |
| | | if (StringUtils.isNotEmpty(text)) { |
| | | options.add(text); |
| | | } |
| | | return options; |
| | | } |
| | | |
| | | /** |
| | |
| | | Date newDate = new Date(); |
| | | serviceSubtask.setLongSendTime(newDate); |
| | | serviceSubtask.setVisitTime(newDate); |
| | | // 院区:/scanGenerateSubtask 是匿名接口(SecurityConfig permitAll),取不到登录用户; |
| | | // 而 service_task.campusid 在本库是占位值 '1',直接沿用会让统计接口(@AddOrgId 按院区过滤)查不到数据。 |
| | | // 这里用任务配置的病区(其次科室)反查 sys_dept.campusid 落库,保证问卷统计能按院区取到。 |
| | | String campusIdByDept = queryCampusIdByDeptCode(serviceSubtask.getLeavehospitaldistrictcode(), serviceTask.getOrgid()); |
| | | if (StringUtils.isEmpty(campusIdByDept)) { |
| | | campusIdByDept = queryCampusIdByDeptCode(serviceSubtask.getDeptcode(), serviceTask.getOrgid()); |
| | | } |
| | | if (StringUtils.isNotEmpty(campusIdByDept)) { |
| | | serviceSubtask.setCampusid(campusIdByDept); |
| | | } |
| | | // 只配了科室(没有病区)的满意度任务:这道答卷在按病区筛选的报表里统计不到,留日志便于运维发现 |
| | | if (StringUtils.isEmpty(serviceSubtask.getLeavehospitaldistrictcode()) |
| | | && ("6".equals(serviceSubtask.getServiceType()) || "14".equals(serviceSubtask.getServiceType()))) { |
| | | log.warn("【扫码生成任务】满意度子任务没有病区,按病区筛选的报表将统计不到该答卷:taskid={}, deptcode={}, campusid={}", |
| | | serviceSubtask.getTaskid(), serviceSubtask.getDeptcode(), serviceSubtask.getCampusid()); |
| | | } |
| | | return serviceSubtask; |
| | | } |
| | | |
| | | /** |
| | | * 按科室/病区编码反查所属院区(查不到返回 null) |
| | | */ |
| | | private String queryCampusIdByDeptCode(String deptCode, String orgid) { |
| | | if (StringUtils.isEmpty(deptCode)) { |
| | | return null; |
| | | } |
| | | try { |
| | | SysDept sysDept = sysDept2Mapper.selectDeptByCode(deptCode, orgid); |
| | | return sysDept == null ? null : sysDept.getCampusid(); |
| | | } catch (Exception e) { |
| | | log.warn("按编码反查院区失败:deptCode={}, orgid={}, err={}", deptCode, orgid, e.getMessage()); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | String voiceText = phoneCallReqYQVO.getAsrtext(); |
| | | String questionText = StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrtext()) ? ivrTaskTemplateScriptVO.getIvrtext() : ivrTaskTemplateScriptVO.getScriptContent(); |
| | | Integer matched = -1; |
| | | log.info("AI匹配:url = {},questionText = {},voiceText = {},options = {},uuid ={}", |
| | | url,questionText,voiceText,options,uuid); |
| | | matched = matchOptionIndex(url, questionText, voiceText, options, uuid); |
| | | //说明匹配正确了 |
| | | if (matched != null && matched >= 0) { |
| | |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask.getJsy()); |
| | | //记录状态 |
| | | setFailPreachForm(serviceSubtask, "3", "电话拨打已完成", "9"); |
| | | return phoneCallBackYQVO; |
| | | back = phoneCallBackYQVO; |
| | | return back; |
| | | } |
| | | |
| | | flag = 1; |
| | |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask.getJsy()); |
| | | //将结果写进detail表(本题的明细在上面匹配成功时已经组装并存入serviceSubtaskDetailList,这里直接落库,避免重复新增) |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList); |
| | | serviceSubTaskDetailReq.setGuid(phoneCallReqYQVO.getGuid()); |
| | | serviceSubTaskDetailReq.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(serviceSubTaskDetailReq); |
| | | return phoneCallBackYQVO; |
| | | //明细在本题匹配成功时已落库(见上方 saveQuestionAnswerPhone),这里不再重复保存 |
| | | back = phoneCallBackYQVO; |
| | | return back; |
| | | } |
| | | |
| | | for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) { |
| | |
| | | redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid()); |
| | | } |
| | | } |
| | | //下一题脚本没找到时,兜底重问当前题,避免调用方误判为未处理而退回正则识别 |
| | | if (StringUtils.isEmpty(phoneCallBackYQVO.getValue())) { |
| | | log.error("下一题脚本未找到,重问当前题,nextQuestion:{}", nextQuestion); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, questionText)); |
| | | } |
| | | back = phoneCallBackYQVO; |
| | | return back; |
| | | } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0) { |
| | | ServiceTask serviceTask1 = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | phoneCallBackYQVO.setType("text"); |
| | |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES); |
| | | // return phoneCallBackYQVO; |
| | | //结束语已拼进返回值,挂机由平台按返回值执行 |
| | | back = phoneCallBackYQVO; |
| | | return back; |
| | | |
| | | } |
| | | } else { |
| | | log.info("没有匹配上----------------------------"); |
| | | //flag=0,说明没 匹配上,也要把患者说的话记录下来 |
| | | if (matched == ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size() - 1 && flag == 0) { |
| | | ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq(); |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>(); |
| | | 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); |
| | | //AI没有匹配上:由AI分支自己按"没问清就重问"的次数处理,不再退回正则识别 |
| | | log.info("ai没有匹配上----------------------------"); |
| | | //没匹配上也要把患者说的话记录下来(matchedtext置空,与正则路径口径一致) |
| | | ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq(); |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>(); |
| | | 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); |
| | | //如果没有 匹配上,这个必须为null |
| | | serviceSubtaskDetailList.get(0).setMatchedtext(""); |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList); |
| | | serviceSubTaskDetailReq.setGuid(phoneCallReqYQVO.getGuid()); |
| | | serviceSubTaskDetailReq.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(serviceSubTaskDetailReq); |
| | | |
| | | String mateKey = phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid(); |
| | | Integer count = null; |
| | | Object countObj = redisCache.getCacheObject(mateKey); |
| | | if (ObjectUtils.isNotEmpty(countObj)) count = (Integer) countObj; |
| | | if (count != null && count >= ivrTaskTemplate.getMateNum()) { |
| | | //没匹配次数已经用满,不能再重问了 |
| | | boolean noNextQuestion = ("0".equals(ivrTaskTemplateScriptVO.getBranchFlag()) || "1".equals(ivrTaskTemplateScriptVO.getBranchFlag())) |
| | | && (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0); |
| | | if (noNextQuestion) { |
| | | //已经是最后一题,直接挂机 |
| | | ServiceTask serviceTask1 = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask1.getJsy()); |
| | | //更新一下分数 |
| | | Double score = null; |
| | | Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | if (ObjectUtils.isNotEmpty(scoreObj)) score = (Double) scoreObj; |
| | | serviceSubtask.setScore(String.valueOf(score)); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtask.setSendstate(6L); |
| | | serviceSubtask.setRemark("电话拨打已完成"); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | //记录状态 |
| | | setFailPreachForm(serviceSubtask, "3", "电话拨打已完成", "9"); |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES); |
| | | //去redis中,把该子任务ID删除 |
| | | Long id = serviceSubtask.getId(); |
| | | Map<String, String> map = delRedisValue(null, id.toString()); |
| | | if (ObjectUtils.isNotEmpty(map)) { |
| | | redisCache.setCacheObject(map.get("cacheName"), map.get("val")); |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | } |
| | | } else { |
| | | //还有下一题,按nextScriptno继续提问 |
| | | for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) { |
| | | if (script.getSort() == ivrTaskTemplateScriptVO.getNextScriptno().intValue()) { |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | String scriptContent = StringUtils.isNotEmpty(script.getIvrtext()) ? script.getIvrtext() : script.getScriptContent(); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent)); |
| | | //将该患者的Redis中的题目ID,进行修改 |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES); |
| | | //更新一下分数 |
| | | Double score = null; |
| | | Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | if (ObjectUtils.isNotEmpty(scoreObj)) score = (Double) scoreObj; |
| | | score = BigDecimal.valueOf(score).add(new BigDecimal(script.getScore())).doubleValue(); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score, 120, TimeUnit.MINUTES); |
| | | //换题成功,没匹配次数清零 |
| | | redisCache.deleteObject(mateKey); |
| | | } |
| | | } |
| | | } |
| | | serviceSubtaskDetailList.add(serviceSubtaskDetail); |
| | | //如果没有 匹配上,这个必须为null |
| | | serviceSubtaskDetailList.get(0).setMatchedtext(""); |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList); |
| | | serviceSubTaskDetailReq.setGuid(phoneCallReqYQVO.getGuid()); |
| | | serviceSubTaskDetailReq.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(serviceSubTaskDetailReq); |
| | | } else { |
| | | //还没问满次数,用noMatchText引导患者重答 |
| | | redisCache.setCacheObject(mateKey, count == null ? 1 : count + 1, 120, TimeUnit.MINUTES); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | phoneCallBackYQVO.setValue(ivrTaskTemplateScriptVO.getNoMatchText() + getObject(serviceSubtask, StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrtext()) ? ivrTaskTemplateScriptVO.getIvrtext() : ivrTaskTemplateScriptVO.getScriptContent())); |
| | | } |
| | | back = phoneCallBackYQVO; |
| | | return back; |
| | | } |
| | | return back; |
| | | } |
| | |
| | | return list; |
| | | } |
| | | |
| | | private String getWXCode(String idcard, String url, String taskName, String taskDesc, String phone, String setPatientname, String setPatientid, List<String> wxqqxx) { |
| | | XinHuaWXReq xinHuaWXReq = new XinHuaWXReq(); |
| | | xinHuaWXReq.setIdcard(idcard); |
| | | xinHuaWXReq.setUrl(url); |
| | | xinHuaWXReq.setPatientid(setPatientid); |
| | | xinHuaWXReq.setPatientname(setPatientname); |
| | | xinHuaWXReq.setMobile(phone); |
| | | xinHuaWXReq.setMedcardno(null); |
| | | xinHuaWXReq.setTitlename(taskName); |
| | | xinHuaWXReq.setContent(taskDesc); |
| | | xinHuaWXReq.setAppid(wxqqxx.get(1)); |
| | | log.info("【getWXCode】微信公众号请求参数:{}", xinHuaWXReq); |
| | | String body = new Gson().toJson(xinHuaWXReq); |
| | | String encode = encode(wxqqxx.get(2).concat(body)); |
| | | Map<String, String> headerMap = new HashMap<>(); |
| | | headerMap.put("sign", encode); |
| | | String result = HttpUtils.sendPostByHeader(wxqqxx.get(3), body, headerMap); |
| | | log.info("【getWXCode】微信公众号返回参数:{}", result); |
| | | JSONObject jsonObject = JSONObject.parseObject(result); |
| | | String code = (String) jsonObject.toString(); |
| | | return code; |
| | | } |
| | | public String encode(String arg) { |
| | | if (arg == null) { |
| | | arg = ""; |
| | | } |
| | | MessageDigest md5 = null; |
| | | try { |
| | | md5 = MessageDigest.getInstance("MD5"); |
| | | md5.update(arg.getBytes("UTF-8")); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return toHex(md5.digest()); |
| | | } |
| | | // --------------------------------------------------------------------- |
| | | // 说明:原私有 getWXCode / encode 已随发送方一起收口到 ruoyi-message 模块 |
| | | // (XinHuaMpApi),此处已删除,避免三份拷贝各写一套签名逻辑。 |
| | | // --------------------------------------------------------------------- |
| | | } |