| | |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.*; |
| | | import com.smartor.common.FtpService; |
| | | import com.smartor.common.SendService; |
| | | import com.smartor.config.PhoneUtils; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.*; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | |
| | | private IIvrTaskTemplateScriptService iIvrTaskTemplateScriptService; |
| | | |
| | | @Autowired |
| | | private IServiceOutPathService iServiceOutPathService; |
| | | |
| | | @Autowired |
| | | private FtpService ftpService; |
| | | |
| | | @Value("${pri_key}") |
| | | private String pri_key; |
| | | |
| | | @Value("${pub_key}") |
| | | private String pub_key; |
| | | |
| | | @Value("${ASRCallBackPath}") |
| | | private String ASRCallBackPath; |
| | | |
| | | @Autowired |
| | | private SendService sendService; |
| | | |
| | | @Value("${hangup}") |
| | | private String hangup; |
| | |
| | | @Value("${voicePathPrefix}") |
| | | private String voicePathPrefix; |
| | | |
| | | @Value("${localIP}") |
| | | private String localIP; |
| | | |
| | | @Value("${req_path}") |
| | | private String req_path; |
| | | |
| | | @Value("${xhsmsPath}") |
| | | private String xhsmsPath; |
| | | |
| | | /** |
| | | * 查询单一任务(随访) |
| | |
| | | public PhoneCallBackYQVO phoneCallBackYQ(PhoneCallReqYQVO phoneCallReqYQVO) { |
| | | //判断是否挂机 |
| | | String hangupState = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "- hangup"); |
| | | if (StringUtils.isNotEmpty(hangupState) && hangup.equals("1")) { |
| | | Object cacheObject1 = redisCache.getCacheObject(phoneCallReqYQVO.getTaskid() + "recordAccept-hungup"); |
| | | if (StringUtils.isNotEmpty(hangupState) && hangup.equals("1") || ObjectUtils.isNotEmpty(cacheObject1) && String.valueOf(cacheObject1).equals("1")) { |
| | | return new PhoneCallBackYQVO(); |
| | | } |
| | | if ("AsrCallback".equals(phoneCallReqYQVO.getOperate()) && phoneCallReqYQVO.getEnd_time() != null && phoneCallReqYQVO.getEnd_time() != -1) { |
| | | //处理挂断 |
| | | if (phoneCallReqYQVO.getAsrtext().contains("拨叫的用户正忙")) { |
| | | //判断 recordAccept-hungup 是否有值,如果有,则说明不用处理了,之前已经处理过了(recordAccept-hungup这个主要是给“通话记录用的,”) |
| | | Object cacheObject = redisCache.getCacheObject(phoneCallReqYQVO.getTaskid() + "recordAccept-hungup"); |
| | | if (ObjectUtils.isNotEmpty(cacheObject) && String.valueOf(cacheObject).equals("1")) { |
| | | return new PhoneCallBackYQVO(); |
| | | } |
| | | ServiceSubtask serviceSubtask2 = new ServiceSubtask(); |
| | | serviceSubtask2.setRemark("电话发送成功(患者挂断)"); |
| | | serviceSubtask2.setSenduuid(phoneCallReqYQVO.getUuid()); |
| | |
| | | req.put("caller", phoneCallReqYQVO.getPhone()); |
| | | HttpUtil.postJsonRequest(hangup, new Gson().toJson(req)); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- hangup", "1", 2, TimeUnit.MINUTES); |
| | | //这个时候就需要走补偿机制了,先暂定走短信 |
| | | getSmsCompensate(Long.valueOf(phoneCallReqYQVO.getTaskid())); |
| | | return new PhoneCallBackYQVO(); |
| | | } |
| | | } |
| | |
| | | HttpUtil.postJsonRequest(hangup, new Gson().toJson(req)); |
| | | //删除结束语的患存 |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "- jsy"); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getTaskid() + "recordAccept-hungup", "2", 10, TimeUnit.MINUTES); |
| | | } else { |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop", true, 120, TimeUnit.MINUTES); |
| | | log.error("-------PlayEventCallbackPlaystop的值为:{}", true); |
| | |
| | | |
| | | @Override |
| | | public Integer recordAccept(PhoneCallRecordVO phoneCallRecordVO) { |
| | | if (phoneCallRecordVO.getAnswered() != null && phoneCallRecordVO.getAnswered() == true) { |
| | | Object cacheObject = redisCache.getCacheObject("recordAccept-hungup"); |
| | | if (ObjectUtils.isNotEmpty(cacheObject) && String.valueOf(cacheObject).equals("2")) { |
| | | // if (phoneCallRecordVO.getAnswered() != null && phoneCallRecordVO.getAnswered() == true) { |
| | | log.error("有人接电话了,并且完了"); |
| | | //说明有人接了 |
| | | int startIndex = phoneCallRecordVO.getRecord_path().indexOf("voice") + "voice".length() + 1; // 加1是跳过/符号 |
| | |
| | | String result = phoneCallRecordVO.getRecord_path().substring(startIndex, endIndex); |
| | | //下载文件 |
| | | ftpService.downloadFolder("/" + LocalDate.now().toString(), profile + "/upload/vadio/voice/" + LocalDate.now().toString()); |
| | | } else if (phoneCallRecordVO.getHangup_cause().equals("NO_USER_RESPONSE") || ObjectUtils.isNotEmpty(cacheObject) && !String.valueOf(cacheObject).equals("2")) { |
| | | //无人接听 |
| | | getSmsCompensate(Long.valueOf(phoneCallRecordVO.getTaskid())); |
| | | } |
| | | redisCache.deleteObject("recordAccept-hungup"); |
| | | return 1; |
| | | } |
| | | |
| | |
| | | return serviceSubtaskDetail; |
| | | } |
| | | |
| | | private void getSmsCompensate(Long subTaskId) { |
| | | ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(subTaskId); |
| | | RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); |
| | | String taskId = rsaPublicKeyExample.encryptedData(serviceSubtask.getTaskid().toString(), pub_key); |
| | | String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key); |
| | | ServiceOutPath serviceOutPath = new ServiceOutPath(); |
| | | serviceOutPath.setParam1(taskId); |
| | | serviceOutPath.setParam2(patid); |
| | | serviceOutPath.setCreateTime(new Date()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | //转成16进制 |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | SendMagParam sendMagParam = new SendMagParam(); |
| | | sendMagParam.setUrl(localIP + ":" + req_path + "/sf?p=" + format); |
| | | sendMagParam.setContent("【新华医院】您好,邀请您填写出院随访调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!"); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("phone", serviceSubtask.getPhone()); |
| | | map.put("content", sendMagParam.getContent()); |
| | | String result = HttpUtil.postJsonRequest(xhsmsPath, new Gson().toJson(map)); |
| | | redisCache.setCacheObject(subTaskId + "recordAccept-hungup", "1", 10, TimeUnit.MINUTES); |
| | | if (StringUtils.isNotEmpty(serviceSubtask.getRemark())) |
| | | serviceSubtask.setRemark("电话发送拒接,短信补偿发送成功"); |
| | | else serviceSubtask.setRemark("短信补偿发送成功"); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | } |
| | | } |