| | |
| | | |
| | | @Value("${phoneUpEveryHour}") |
| | | private Integer phoneUpEveryHour; |
| | | @Value("${phoneEndHour}") |
| | | private Integer phoneEndHour; |
| | | |
| | | /** |
| | | * 查询单一任务(随访) |
| | |
| | | patTaskRelevance.setPhone(serviceSubtask1.getPhone()); |
| | | patTaskRelevance.setTelcode(serviceSubtask1.getPhone()); |
| | | patTaskRelevance.setAddr(serviceSubtask1.getAddr()); |
| | | patTaskRelevance.setDiagname(serviceSubtask1.getDiagname()); |
| | | patTaskRelevance.setDiagname(serviceSubtask1.getLeavediagname()); |
| | | patTaskRelevance.setPatid(serviceSubtask1.getPatid()); |
| | | patTaskRelevance.setSendStatus(serviceSubtask1.getSendstate()); |
| | | patTaskRelevance.setDeptCode(serviceSubtask1.getDeptcode()); |
| | |
| | | patTaskRelevance.setDeptName(serviceSubtask1.getDeptname()); |
| | | patTaskRelevance.setDeptCode(serviceSubtask1.getDeptcode()); |
| | | patTaskRelevance.setBedNo(serviceSubtask1.getBedNo()); |
| | | patTaskRelevance.setDiagname(serviceSubtask1.getDiagname()); |
| | | patTaskRelevance.setDiagname(serviceSubtask1.getLeavediagname()); |
| | | patTaskRelevance.setPatid(serviceSubtask1.getPatid()); |
| | | patTaskRelevance.setSendStatus(serviceSubtask1.getSendstate()); |
| | | patTaskRelevance.setLeavehospitaldistrictcode(serviceSubtask1.getLeavehospitaldistrictcode()); |
| | |
| | | */ |
| | | @Override |
| | | public PhoneCallBackYQVO phoneCallBackYQ(PhoneCallReqYQVO phoneCallReqYQVO) { |
| | | //先把该subId从cache_exist中剔除,只要有回调就剔除(目的是,尽快让cache-exist为空,去缓存下一批要打的电话;这里剔除不影响电话的正常业务) |
| | | redisCache.removeElementFromList("cache-exist", phoneCallReqYQVO.getTaskid()); |
| | | |
| | | //判断是否挂机 |
| | | String hangupState = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "- hangup"); |
| | | Object cacheObject1 = redisCache.getCacheObject(phoneCallReqYQVO.getTaskid() + "recordAccept-hungup"); |
| | |
| | | if (ObjectUtils.isNotEmpty(cacheObject) && String.valueOf(cacheObject).equals("1")) { |
| | | return new PhoneCallBackYQVO(); |
| | | } |
| | | //如果发送状态为6,就说明已经打完了,也没有必要继续往下走了 |
| | | if (StringUtils.isNotEmpty(phoneCallReqYQVO.getTaskid())) { |
| | | ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(Long.valueOf(phoneCallReqYQVO.getTaskid())); |
| | | if (serviceSubtask.getSendstate() == 6L) return new PhoneCallBackYQVO(); |
| | | } |
| | | |
| | | ServiceSubtask serviceSubtask2 = new ServiceSubtask(); |
| | | serviceSubtask2.setRemark("电话发送成功(患者挂断)"); |
| | | serviceSubtask2.setSenduuid(phoneCallReqYQVO.getUuid()); |
| | |
| | | @Override |
| | | public List<PullTaskVO> taskPull() { |
| | | //pullTaskVOList用于数据返回 |
| | | List<PullTaskVO> pullTaskVOList = null; |
| | | List<PullTaskVO> pullTaskVOList = new ArrayList<>(); |
| | | List<String> cacheList = new ArrayList<>(); |
| | | ListOperations<String, String> listOps = redisTemplate.opsForList(); |
| | | //必须等ache-exist全部打完才能拉取下一批(主要是怕所有的数据都堆在电话的缓存里,在规定的时间打不完) |
| | | long existSize = listOps.size("cache-exist"); |
| | | if (existSize > 0) return pullTaskVOList; |
| | | |
| | | long size = listOps.size("cache-0"); |
| | | log.error("---------打电话之前缓存中的数据量:{}", size); |
| | | int count = 0; |
| | |
| | | //phoneCount() 通过给出的每个小时需要打出的电话量,算出到晚上8点一点能打出多少个电话,获取到总量 |
| | | //如果需要立即执行的数据量大于一天要执行的上限,则只取上限的数量,其它的则放回redis中 |
| | | count = Math.min(phoneCount(), (int) size); |
| | | cacheList = listOps.range("cache-0", 0, count - 1); |
| | | if (count != 0) { |
| | | cacheList = listOps.range("cache-0", 0, count - 1); |
| | | } |
| | | } |
| | | |
| | | log.error("任务拉取cache-0的值是多少:{}", cacheList); |
| | |
| | | listOps.trim("cache-0" + i, count1, -1); |
| | | } |
| | | } |
| | | //existList用来记录接下来需要执行的子任务ID |
| | | List<String> existList = new ArrayList<>(); |
| | | if (CollectionUtils.isNotEmpty(pullTaskVOList)) { |
| | | //给回调参数赋值 |
| | | for (PullTaskVO pullTaskVO : pullTaskVOList) { |
| | | existList.add(pullTaskVO.getTaskid()); |
| | | pullTaskVO.setAsrcallback(ASRCallBackPath); |
| | | } |
| | | } |
| | | if (existList.size() != 0) redisCache.setCacheListRight("cache-exist", existList); |
| | | log.error("-----------实际拉取的电话数据量:{}", pullTaskVOList.size()); |
| | | return pullTaskVOList; |
| | | } |
| | |
| | | PullTaskVO pullTaskVO = new PullTaskVO(); |
| | | String subId = subIds.get(i).trim(); |
| | | ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(Long.valueOf(subId)); |
| | | if (ObjectUtils.isEmpty(serviceSubtask)) { |
| | | log.error("该subId有问题,在表中查询不到:{}", subId); |
| | | continue; |
| | | } |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | IvrTaskTemplate ivrTaskTemplate = ivrTaskTemplateService.selectIvrTaskTemplateByID(serviceSubtask.getTemplateid()); |
| | | if (ObjectUtils.isEmpty(ivrTaskTemplate)) continue; |
| | |
| | | redisCache.setCacheObject(subId.trim() + "-" + serviceSubtask.getPhone().trim(), ivrTaskTemplateScript.getId().toString(), 120, TimeUnit.MINUTES); |
| | | } else { |
| | | newValue0.add(subIds.get(i)); |
| | | redisCache.setCacheList(cacheName, newValue0); |
| | | redisCache.setCacheListRight(cacheName, newValue0); |
| | | } |
| | | } |
| | | |
| | |
| | | ServiceSubtask serviceSubtask = new ServiceSubtask(); |
| | | serviceSubtask.setRemark("电话接通成功,患者拒绝随访"); |
| | | serviceSubtask.setId(Long.valueOf(phoneCallRecordVO.getTaskid())); |
| | | serviceSubtask.setSendstate(6L); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | int startIndex = phoneCallRecordVO.getRecord_path().indexOf("voice") + "voice".length() + 1; // 加1是跳过/符号 |
| | | int endIndex = phoneCallRecordVO.getRecord_path().lastIndexOf("/"); |
| | |
| | | redisCache.setCacheObject(subTaskId + "recordAccept-hungup", "1", 10, TimeUnit.MINUTES); |
| | | if (StringUtils.isNotEmpty(serviceSubtask.getRemark())) serviceSubtask.setRemark("电话发送拒接,短信补偿发送成功"); |
| | | else serviceSubtask.setRemark("短信补偿发送成功"); |
| | | serviceSubtask.setSendstate(3L); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | |
| | | } |
| | | |
| | | //通过当前时间,拉取电话总数 |
| | |
| | | // 当前时间 |
| | | LocalTime currentTime = LocalTime.now(); |
| | | // 目标时间(晚上 8 点) |
| | | LocalTime targetTime = LocalTime.of(20, 0); |
| | | LocalTime targetTime = LocalTime.of(phoneEndHour, 0); |
| | | // 计算当前时间到目标时间的时长 |
| | | Duration duration = Duration.between(currentTime, targetTime); |
| | | // 获取剩余时间的小时数 |
| | | long remainingHours = duration.toHours(); |
| | | long remainingHours = 0; |
| | | long remainingMinutes = duration.toMinutes(); |
| | | //如果超过8点,就设置为0 |
| | | if (remainingHours < 0) remainingHours = 0; |
| | | //距离结束时间小于20分钟,就不拉取了 |
| | | if (remainingMinutes < 20) remainingHours = 0; |
| | | else if (remainingMinutes < 60 && remainingMinutes > 20) remainingHours = 1; |
| | | else if (remainingMinutes > 60) remainingHours = remainingMinutes / 60; |
| | | // 计算剩余可以打的电话数 |
| | | int remainingCalls = (int) (remainingHours * phoneUpEveryHour); |
| | | return remainingCalls; |