| | |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.google.gson.Gson; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | 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.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.sms.smsUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.system.domain.SysConfig; |
| | | import com.ruoyi.system.mapper.SysConfigMapper; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.smartor.common.DeepSeekApi; |
| | | 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.*; |
| | | import com.smartor.domain.VO.HeLibraryCountVO; |
| | | import com.smartor.domain.VO.ServiceSubtaskCotinueCountVO; |
| | | import com.smartor.domain.VO.*; |
| | | import com.smartor.domain.entity.ServiceSubtaskEntity; |
| | | import com.smartor.mapper.*; |
| | | import com.smartor.service.*; |
| | |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.ibatis.annotations.Param; |
| | | 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.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.MessageDigest; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.*; |
| | |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.hutool.core.convert.Convert.toHex; |
| | | |
| | | /** |
| | | * 单一任务(随访)Service业务层处理 |
| | |
| | | |
| | | @Autowired |
| | | private IServiceTaskdeptService serviceTaskdeptService; |
| | | @Autowired |
| | | private IServiceTaskmedicalService serviceTaskmedicalService; |
| | | |
| | | @Autowired |
| | | private IServiceTaskdiagService serviceTaskdiagService; |
| | |
| | | |
| | | @Autowired |
| | | private IServiceSubtaskDetailTraceService traceService; |
| | | |
| | | @Autowired |
| | | private IServiceTaskScheduleService serviceTaskScheduleService; |
| | | |
| | | @Autowired |
| | | private IPatArchiveService patArchiveService; |
| | | |
| | | @Autowired |
| | | private ScheduleSubtaskBuilder scheduleSubtaskBuilder; |
| | | |
| | | @Autowired |
| | | private FtpService ftpService; |
| | |
| | | @Value("${spring.profiles.active}") |
| | | private String active; |
| | | |
| | | @Autowired |
| | | private ServiceOutPathMapper serviceOutPathMapper; |
| | | |
| | | private static final String KEY_SEP = "\u0001"; |
| | | @Autowired |
| | | private PatMedOperationItemMapper patMedOperationItemMapper; |
| | | |
| | | /** |
| | | * 查询单一任务(随访) |
| | | * |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | findServiceTaskScheduleVO(serviceTaskVO); |
| | | return serviceTaskVO; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | serviceTaskVO.setPatTaskRelevances(patTaskRelevances); |
| | | findServiceTaskScheduleVO(serviceTaskVO); |
| | | return serviceTaskVO; |
| | | } |
| | | |
| | | @Override |
| | | public List<ServiceSubtaskRes> patItem(ServiceSubtaskEntity serviceSubtaskEntity) { |
| | | if (serviceSubtaskEntity.getSendstateView() != null) { |
| | | // 1:待随访(1 被领取、2 待发送、3 已发送、5 发送失败、7、超时);2:已完成( 6 已完成)、3:无需随访(4 不执行) |
| | | if (serviceSubtaskEntity.getSendstateView() == 1) |
| | | serviceSubtaskEntity.setSendstates(new ArrayList<>(Arrays.asList(1L, 2L, 3L, 5L, 7L))); |
| | | if (serviceSubtaskEntity.getSendstateView() == 2) |
| | | serviceSubtaskEntity.setSendstates(new ArrayList<>(Arrays.asList(6L))); |
| | | if (serviceSubtaskEntity.getSendstateView() == 3) |
| | | serviceSubtaskEntity.setSendstates(new ArrayList<>(Arrays.asList(4L))); |
| | | } |
| | | |
| | | List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskEntity); |
| | | List<ServiceSubtask> selectServiceSubtaskList = getServiceSubtasks(serviceSubtaskEntity); |
| | | |
| | | List<ServiceSubtaskRes> serviceSubtaskResList = new ArrayList<>(); |
| | | for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { |
| | |
| | | serviceSubtaskResList.add(serviceSubtaskRes); |
| | | } |
| | | return serviceSubtaskResList; |
| | | } |
| | | |
| | | public List<ServiceSubtask> getServiceSubtasks(ServiceSubtaskEntity serviceSubtaskEntity) { |
| | | if (serviceSubtaskEntity.getSendstateView() != null) { |
| | | // 1:待随访(1 被领取、2 待发送、3 已发送、5 发送失败、7、超时);2:已完成( 6 已完成)、3:无需随访(4 不执行) |
| | | if (serviceSubtaskEntity.getSendstateView() == 1) |
| | | serviceSubtaskEntity.setSendstates(new ArrayList<>(Arrays.asList(1L, 2L, 3L, 5L, 7L))); |
| | | if (serviceSubtaskEntity.getSendstateView() == 2) |
| | | serviceSubtaskEntity.setSendstates(new ArrayList<>(Arrays.asList(6L))); |
| | | if (serviceSubtaskEntity.getSendstateView() == 3) |
| | | serviceSubtaskEntity.setSendstates(new ArrayList<>(Arrays.asList(4L))); |
| | | } |
| | | //患者获取随访任务-需要查询同个患者(身份证)所有的任务 景宁 |
| | | if (StringUtils.isNotEmpty(serviceSubtaskEntity.getOrgid()) && serviceSubtaskEntity.getOrgid().equals("47255004333112711A1001")) { |
| | | if (ObjectUtils.isNotEmpty(serviceSubtaskEntity.getPatid())) { |
| | | PatArchive patArchive = patArchiveService.selectPatArchiveByPatid(serviceSubtaskEntity.getPatid()); |
| | | if (ObjectUtils.isNotEmpty(patArchive) && StringUtils.isNotEmpty(patArchive.getIdcardno())) { |
| | | serviceSubtaskEntity.setPatid(null); |
| | | serviceSubtaskEntity.setSfzh(patArchive.getIdcardno()); |
| | | } |
| | | } |
| | | } |
| | | List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskEntity); |
| | | return selectServiceSubtaskList; |
| | | } |
| | | |
| | | @Override |
| | | public Integer transferDept(TransferDeptVO transferDeptVO) { |
| | | log.info("transferDept的入参为:{}", transferDeptVO); |
| | | //查询该患者的子任务信息 |
| | | ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(transferDeptVO.getSubId()); |
| | | if (ObjectUtils.isEmpty(serviceSubtask)) throw new BaseException("转患者失败,请联系管理员处理"); |
| | | //删除该患者的信息通过subid |
| | | serviceSubtaskMapper.deleteServiceSubtaskById(transferDeptVO.getSubId()); |
| | | |
| | | //修改患者的离院科室病区通过inhospid和患者的任务生成状态 |
| | | PatMedInhosp patMedInhosp = new PatMedInhosp(); |
| | | patMedInhosp.setInhospid(serviceSubtask.getInhospid()); |
| | | patMedInhosp.setLeaveldeptcode(transferDeptVO.getLeavelDeptCode()); |
| | | patMedInhosp.setLeaveldeptname(transferDeptVO.getLeavelDeptName()); |
| | | patMedInhosp.setLeavehospitaldistrictcode(transferDeptVO.getLeavehospitaldistrictcode()); |
| | | patMedInhosp.setLeavehospitaldistrictname(transferDeptVO.getLeavehospitaldistrictname()); |
| | | patMedInhosp.setDeptcheckFlag("0"); |
| | | patMedInhosp.setWardcheckFlag("0"); |
| | | patMedInhosp.setDiagcheckFlag("0"); |
| | | return patMedInhospMapper.updatePatMedInhosp(patMedInhosp); |
| | | } |
| | | |
| | | public Map<String, String> calculateAge(LocalDate birthdate, LocalDate today) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 统计任务各种状态的数量(已优化) |
| | | * 优化说明: |
| | | * 1. 使用数据库层聚合计算,替代应用层遍历 |
| | | * 2. 性能提升 10-100 倍(取决于数据量) |
| | | * 3. 降低内存占用和网络传输 |
| | | * |
| | | * @param serviceSubtaskEntity 查询条件 |
| | | * @return 各状态统计结果 |
| | | */ |
| | | @Override |
| | | public Map<String, Object> countByCondition(ServiceSubtaskEntity serviceSubtaskEntity) { |
| | | // 直接调用数据库统计方法,在数据库层完成聚合计算 |
| | | Map<String, Object> result = serviceSubtaskMapper.countByCondition(serviceSubtaskEntity); |
| | | // 处理空异常 |
| | | if (MapUtils.isEmpty(result)) { |
| | | result = new HashMap<>(); |
| | | // 确保所有 key 都有值,避免空指针异常 |
| | | // MyBatis 的 SUM 在没有匹配行时会返回 null |
| | | result.putIfAbsent("wzx", 0); |
| | | result.putIfAbsent("ysf", 0); |
| | | result.putIfAbsent("fssb", 0); |
| | | result.putIfAbsent("yfs", 0); |
| | | result.putIfAbsent("blq", 0); |
| | | result.putIfAbsent("total", 0); |
| | | result.putIfAbsent("wxsf", 0); |
| | | result.putIfAbsent("xsf", 0); |
| | | result.putIfAbsent("dsf", 0); |
| | | result.putIfAbsent("dfs", 0); |
| | | result.putIfAbsent("yfs", 0); |
| | | result.putIfAbsent("ywc", 0); |
| | | result.putIfAbsent("yc", 0); |
| | | result.putIfAbsent("jg", 0); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 新增单一任务(随访) |
| | | * |
| | | * @param serviceSubtask 单一任务(随访) |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertServiceSubtask(ServiceSubtask serviceSubtask) { |
| | | serviceSubtask.setCreateTime(DateUtils.getNowDate()); |
| | | return serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); |
| | | public Map<String, Object> insertServiceSubtask(ServiceSubtask serviceSubtask) { |
| | | List<ServiceSubtask> serviceSubtasks = null; |
| | | //先查询一下该患者是否已经创建根据serviceType,sendstate,inhospid,patid,orgid |
| | | //这样判断主要是为了想让新华医院的外部导入患者创建任务,也能用这个接口 |
| | | if (StringUtils.isEmpty(serviceSubtask.getPatfrom()) || !serviceSubtask.getPatfrom().equals("2")) { |
| | | ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity(); |
| | | serviceSubtaskVO.setServiceType(serviceSubtask.getServiceType()); |
| | | serviceSubtaskVO.setInhospid(serviceSubtask.getInhospid()); |
| | | serviceSubtaskVO.setSendstates(new ArrayList<>(Arrays.asList(1L, 2L, 3L, 5L, 7L))); |
| | | serviceSubtaskVO.setPatid(serviceSubtask.getPatid()); |
| | | serviceSubtaskVO.setOrgid(serviceSubtask.getOrgid()); |
| | | serviceSubtaskVO.setCampusid(serviceSubtask.getCampusid()); |
| | | 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 { |
| | | //如果不存在,则新增 |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | if (ObjectUtils.isNotEmpty(serviceTask)) { |
| | | serviceSubtask.setTaskDesc(serviceTask.getTaskDesc()); |
| | | serviceSubtask.setTaskName(serviceTask.getTaskName()); |
| | | serviceSubtask.setTemplatename(serviceTask.getTemplatename()); |
| | | } |
| | | |
| | | serviceSubtask.setCreateTime(DateUtils.getNowDate()); |
| | | serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); |
| | | //修改住院满意度状态(避免重复查询) |
| | | if (serviceSubtask.getServiceType() != null && "6".equals(serviceSubtask.getServiceType())) { |
| | | Long inhospid = serviceSubtask.getInhospid(); |
| | | if (inhospid != null) { |
| | | PatMedInhosp patMedInhosp = new PatMedInhosp(); |
| | | patMedInhosp.setInhospMydFlag("1"); |
| | | patMedInhosp.setInhospid(inhospid); |
| | | patMedInhospMapper.updatePatMedInhosp(patMedInhosp); |
| | | } |
| | | } |
| | | 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 serviceOutPath = new ServiceOutPath(); |
| | | serviceOutPath.setParam1(taskId); |
| | | serviceOutPath.setParam2(patid); |
| | | serviceOutPath.setCreateTime(new Date()); |
| | | serviceOutPath.setParam6(subId); |
| | | serviceOutPath.setOrgid(serviceSubtask.getOrgid()); |
| | | serviceOutPath.setTaskId(serviceSubtask.getTaskid()); |
| | | serviceOutPath.setSubId(serviceSubtask.getId()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | //转成16进制 |
| | | format = String.format("%03X", serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | return format; |
| | | } |
| | | |
| | | /** |
| | |
| | | patMedInhosp.setInhospstate("0"); |
| | | List<PatMedInhosp> patMedInhospList = patMedInhospMapper.selectPatMedInhospList(patMedInhosp); |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(serviceSubtask1.getPatid()); |
| | | |
| | | if (patMedInhospList.size() > 0) { |
| | | //景宁 新增再次随访不能触发患者再入院 |
| | | boolean inhospAgain = true; |
| | | if (serviceSubtask1.getOrgid().equals("47255004333112711A1001")) { |
| | | inhospAgain = false; |
| | | } |
| | | if (patMedInhospList.size() > 0 && inhospAgain) { |
| | | serviceSubtask1.setIsVisitAgain(2); |
| | | serviceSubtask1.setRemark(StringUtils.isNotEmpty(serviceSubtask.getRemark()) ? serviceSubtask.getRemark() + ";患者再入院了" : "患者再入院了"); |
| | | serviceSubtask1.setSendstate(4L); |
| | |
| | | serviceSubtask.setUpdateTime(DateUtils.getNowDate()); |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() == 6) |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | |
| | | return serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | } |
| | | |
| | |
| | | serviceTaskoperService.insertServiceTaskoper(serviceTaskoper); |
| | | } |
| | | } |
| | | |
| | | } else if (serviceTaskVO.getAppltype().equals("5")) { |
| | | // 任务组:必须为长期任务(否则 findMatchingTaskIds 扫不到,无法自动纳入新出院患者) |
| | | if (serviceTaskVO.getLongTask() == null || serviceTaskVO.getLongTask() != 1) { |
| | | throw new BaseException("appltype=5 任务组必须为长期任务(longTask=1)"); |
| | | } |
| | | // 保存计划 + 明细 |
| | | ServiceTaskScheduleVO scheduleVO = serviceTaskVO.getServiceTaskScheduleVO(); |
| | | if (scheduleVO == null) { |
| | | throw new BaseException("appltype=5 任务组:serviceTaskScheduleVO 不能为空"); |
| | | } |
| | | scheduleVO.setTaskid(serviceTask.getTaskid()); |
| | | scheduleVO.setOrgid(serviceTask.getOrgid()); |
| | | scheduleVO.setCampusid(serviceTask.getCampusid()); |
| | | scheduleVO.setCreateBy(serviceTask.getCreateBy()); |
| | | |
| | | scheduleVO.setDeptCodes(serviceTaskVO.getDeptcode()); |
| | | scheduleVO.setWardCodes(serviceTaskVO.getLeavehospitaldistrictcode()); |
| | | scheduleVO.setIcd10Codes(serviceTaskVO.getIcd10code()); |
| | | scheduleVO.setOplevelCodes(serviceTaskVO.getOplevelcode()); |
| | | |
| | | log.info("----serviceTaskSchedule的值为:{}", scheduleVO); |
| | | serviceTaskScheduleService.saveScheduleWithDetail(scheduleVO); |
| | | } else if (serviceTaskVO.getAppltype().equals("6")) { |
| | | ServiceTaskmedical serviceTaskmedical = new ServiceTaskmedical(); |
| | | serviceTaskmedical.setTaskId(serviceTask.getTaskid()); |
| | | serviceTaskmedical.setTaskName(serviceTask.getTaskName()); |
| | | serviceTaskmedical.setServiceType(serviceTaskVO.getServiceType()); |
| | | serviceTaskmedical.setLongtask(Long.valueOf(serviceTask.getLongTask())); |
| | | if (serviceTaskVO.getLongTask() == 1) serviceTaskmedical.setLongtask(1L); |
| | | serviceTaskmedical.setMedicalCode(serviceTaskVO.getIcd10code()); |
| | | serviceTaskmedical.setMedicalName(serviceTaskVO.getIcd10name()); |
| | | serviceTaskmedical.setGuid(serviceTask.getGuid()); |
| | | serviceTaskmedical.setOrgid(serviceTask.getOrgid()); |
| | | serviceTaskmedical.setCreateTime(new Date()); |
| | | serviceTaskmedical.setDeptCode(serviceTaskVO.getDeptcode()); |
| | | serviceTaskmedical.setDeptName(serviceTaskVO.getDeptname()); |
| | | serviceTaskmedical.setWardCode(serviceTaskVO.getLeavehospitaldistrictcode()); |
| | | serviceTaskmedical.setWardName(serviceTaskVO.getLeavehospitaldistrictname()); |
| | | //南华附一的icd10code是有重复的,所以不能用南华附一的icd10code去查询 |
| | | log.info("----serviceTaskmedical的值为:{}", serviceTaskmedical); |
| | | if (!StringUtils.isEmpty(serviceTaskVO.getMedicalName())) { |
| | | String[] medicalNames = serviceTaskVO.getMedicalName().split(","); |
| | | String[] medicalcodes = serviceTaskVO.getMedicalCode().split(","); |
| | | String[] medicalCompanys = serviceTaskVO.getMedicalCompany().split(","); |
| | | for (int i = 0; i < medicalNames.length; i++) { |
| | | serviceTaskmedical.setMedicalCode(medicalNames[i]); |
| | | serviceTaskmedical.setMedicalName(medicalcodes[i]); |
| | | if (ObjectUtils.isNotEmpty(medicalCompanys)) |
| | | serviceTaskmedical.setMedicalCompany(medicalCompanys[i]); |
| | | serviceTaskmedicalService.insertServiceTaskmedical(serviceTaskmedical); |
| | | } |
| | | } |
| | | } else { |
| | | ServiceTaskdept serviceTaskdept = new ServiceTaskdept(); |
| | | serviceTaskdept.setTaskId(serviceTask.getTaskid()); |
| | |
| | | //将任务信息放到服务表中 |
| | | ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTaskVO, ServiceSubtask.class); |
| | | serviceSubtask.setTaskid(serviceTask.getTaskid().longValue()); |
| | | serviceSubtask.setTemplatename(tempName); |
| | | serviceSubtask.setTemplateid(tempid); |
| | | serviceSubtask.setTemplatename(ObjectUtils.isNotEmpty(tempid) ? tempName : serviceTask.getTemplatename()); |
| | | serviceSubtask.setTemplateid(ObjectUtils.isNotEmpty(tempid) ? tempid : serviceTask.getTemplateid()); |
| | | serviceSubtask.setLibtemplateid(ObjectUtils.isEmpty(serviceTask.getLibtemplateid()) ? null : Long.valueOf(serviceTask.getLibtemplateid())); |
| | | serviceSubtask.setLibtemplatename(serviceTask.getLibtemplatename()); |
| | | //新增 |
| | |
| | | serviceSubtask.setLongSendTime(patTaskRelevance.getLongSendTime()); |
| | | serviceSubtask.setVisitTime(patTaskRelevance.getVisittime()); |
| | | } |
| | | |
| | | // ===== appltype=5 任务组:按 schedule 的 detailList 派生多条 subtask ===== |
| | | if ("5".equals(serviceTaskVO.getAppltype())) { |
| | | ServiceTaskSchedule schedule = serviceTaskScheduleService.selectByTaskid(serviceTask.getTaskid()); |
| | | if (schedule == null) { |
| | | throw new BaseException("appltype=5 任务组:未找到 taskid=" + serviceTask.getTaskid() + " 的计划"); |
| | | } |
| | | List<ServiceTaskScheduleDetail> detailList = serviceTaskScheduleService.selectDetailByScheduleid(schedule.getId()); |
| | | scheduleSubtaskBuilder.buildSubtasksForPatient(serviceTask, serviceTaskVO.getPreachformList(), schedule, detailList, patTaskRelevance, serviceSubtask); |
| | | continue; |
| | | } |
| | | |
| | | serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); |
| | | serviceSubtask.getId().intValue(); |
| | | |
| | |
| | | redisCache.removeElementFromList("cache-3", serviceSubtask.getId().toString()); |
| | | redisCache.removeElementFromList("cache-4", serviceSubtask.getId().toString()); |
| | | //将出入院表的数据,还原成还未处理的状态 |
| | | if (serviceSubtask.getServiceType().equals("2")) { |
| | | if (serviceSubtask.getServiceType().equals("2") || serviceSubtask.getServiceType().equals("13")) { |
| | | ServiceTask st = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | //如果任务是长期任务,需要将该患者的出入院数据还原成还未处理的状态 |
| | | if (st != null && st.getLongTask() == 1) { |
| | |
| | | patMedOuthosp.setServerState("0"); |
| | | patMedOuthospService.updatePatMedOuthosp(patMedOuthosp); |
| | | } |
| | | } |
| | | } else if (serviceSubtask.getServiceType().equals("19")) { |
| | | ServiceTask st = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | //如果任务是长期任务,需要将该患者的出院详情状态还原成还未处理的状态 |
| | | if (st != null && st.getLongTask() == 1 |
| | | && ObjectUtils.isNotEmpty(serviceSubtask.getOperationItemId())) { |
| | | PatMedOperationItem patMedOperationItem = new PatMedOperationItem(); |
| | | patMedOperationItem.setOpercheckFlag("0"); |
| | | patMedOperationItem.setId(serviceSubtask.getOperationItemId()); |
| | | patMedOperationItemMapper.updatePatMedOperationItem(patMedOperationItem); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | } else if (serviceTaskVO.getAppltype().equals("6")) { |
| | | ServiceTaskmedical serviceTaskmedical = new ServiceTaskmedical(); |
| | | serviceTaskmedical.setTaskId(serviceTask.getTaskid()); |
| | | serviceTaskmedical.setTaskName(serviceTask.getTaskName()); |
| | | if (StringUtils.isEmpty(serviceTaskVO.getMedicalCode())) { |
| | | throw new BaseException("药品编码为空"); |
| | | } |
| | | serviceTaskmedical.setLongtask(Long.valueOf(serviceTask.getLongTask())); |
| | | serviceTaskmedical.setMedicalName(serviceTaskVO.getMedicalName()); |
| | | serviceTaskmedical.setGuid(serviceTask1.getGuid()); |
| | | serviceTaskmedical.setServiceType(serviceTask1.getServiceType()); |
| | | serviceTaskmedical.setOrgid(serviceTask1.getOrgid()); |
| | | serviceTaskmedical.setDeptCode(serviceTask1.getDeptcode()); |
| | | serviceTaskmedical.setDeptName(serviceTask1.getDeptname()); |
| | | serviceTaskmedical.setWardCode(serviceTask1.getLeavehospitaldistrictcode()); |
| | | serviceTaskmedical.setWardName(serviceTask1.getLeavehospitaldistrictname()); |
| | | serviceTaskmedical.setUpdateTime(new Date()); |
| | | if (StringUtils.isNotEmpty(serviceTaskVO.getMedicalCode())) { |
| | | String[] medicalCodes = serviceTaskVO.getMedicalCode().split(","); |
| | | String[] medicalNames = serviceTaskVO.getMedicalName().split(","); |
| | | String[] medicalCompanys = serviceTaskVO.getMedicalCompany().split(","); |
| | | if (!active.equals("nhfy") && !active.equals("druid")) { |
| | | if (medicalCodes.length != medicalNames.length && medicalNames.length != medicalCompanys.length) { |
| | | throw new BaseException("药品编码和药品名称数量不一致或者药品名称和药品公司数量不一致"); |
| | | } |
| | | } |
| | | |
| | | for (int i = 0; i < medicalCodes.length; i++) { |
| | | //先查询一下是否存在 |
| | | ServiceTaskmedical serviceTaskmedical1 = new ServiceTaskmedical(); |
| | | serviceTaskmedical1.setTaskId(serviceTaskVO.getTaskid()); |
| | | serviceTaskmedical1.setMedicalCode(medicalCodes[i]); |
| | | serviceTaskmedical1.setMedicalName(medicalNames[i]); |
| | | serviceTaskmedical1.setMedicalCompany(medicalCompanys[i]); |
| | | List<ServiceTaskmedical> serviceTaskmedicals = serviceTaskmedicalService.selectServiceTaskmedicalList(serviceTaskmedical1); |
| | | serviceTaskmedical.setMedicalCode(medicalCodes[i]); |
| | | serviceTaskmedical.setMedicalName(medicalNames[i]); |
| | | serviceTaskmedical.setMedicalCompany(medicalCompanys[i]); |
| | | log.info("----serviceTaskmedical更新的值为:{}", serviceTaskmedical); |
| | | if (CollectionUtils.isNotEmpty(serviceTaskmedicals)) { |
| | | serviceTaskmedical.setId(serviceTaskmedicals.get(0).getId()); |
| | | serviceTaskmedicalService.updateServiceTaskmedical(serviceTaskmedical); |
| | | } else { |
| | | serviceTaskmedicalService.insertServiceTaskmedical(serviceTaskmedical); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } else if (serviceTaskVO.getAppltype().equals("4")) { |
| | | ServiceTaskoper serviceTaskoper = new ServiceTaskoper(); |
| | | // if (StringUtils.isEmpty(serviceTaskVO.getOpcode())) { |
| | |
| | | } |
| | | } |
| | | } |
| | | } else if (serviceTaskVO.getAppltype().equals("5")) { |
| | | // 任务组修改:删旧 schedule + 明细,重建。subtask 上面已批量清理。 |
| | | if (serviceTaskVO.getLongTask() == null || serviceTaskVO.getLongTask() != 1) { |
| | | throw new BaseException("appltype=5 任务组必须为长期任务(longTask=1)"); |
| | | } |
| | | ServiceTaskScheduleVO scheduleVO = serviceTaskVO.getServiceTaskScheduleVO(); |
| | | if (scheduleVO == null) { |
| | | throw new BaseException("appltype=5 任务组:serviceTaskScheduleVO 不能为空"); |
| | | } |
| | | scheduleVO.setTaskid(serviceTask.getTaskid()); |
| | | scheduleVO.setOrgid(serviceTask.getOrgid()); |
| | | scheduleVO.setCampusid(serviceTask.getCampusid()); |
| | | scheduleVO.setDeptCodes(serviceTaskVO.getDeptcode()); |
| | | scheduleVO.setWardCodes(serviceTaskVO.getLeavehospitaldistrictcode()); |
| | | scheduleVO.setIcd10Codes(serviceTaskVO.getIcd10code()); |
| | | scheduleVO.setOplevelCodes(serviceTaskVO.getOplevelcode()); |
| | | scheduleVO.setCreateBy(serviceTask.getUpdateBy()); |
| | | serviceTaskScheduleService.saveScheduleWithDetail(scheduleVO); |
| | | } |
| | | } |
| | | if (ObjectUtils.isNotEmpty(serviceTaskVO.getIvrTaskTemplateVO())) { |
| | |
| | | ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTaskVO, ServiceSubtask.class); |
| | | serviceSubtask.setLibtemplateid(ObjectUtils.isEmpty(serviceTaskVO.getLibtemplateid()) ? null : Long.valueOf(serviceTaskVO.getLibtemplateid())); |
| | | serviceSubtask.setLibtemplatename(serviceTaskVO.getLibtemplatename()); |
| | | serviceSubtask.setTemplateid(serviceTask.getTemplateid()); |
| | | serviceSubtask.setTemplatename(serviceTask.getTemplatename()); |
| | | serviceSubtask.setSendname(patTaskRelevance.getName()); |
| | | serviceSubtask.setAge(patTaskRelevance.getAge()); |
| | | serviceSubtask.setSfzh(patTaskRelevance.getSfzh()); |
| | |
| | | serviceSubtask.setVisitTime(patTaskRelevance.getVisittime()); |
| | | serviceSubtask.setTextParam(new Gson().toJson(serviceTaskVO.getTextParam())); |
| | | if (patTaskRelevance.getIsoperation() != null) { |
| | | // appltype=5 任务组:追加患者(isoperation=1)走计划派生;修改(2)/删除(3)仍走原逻辑 |
| | | if ("5".equals(serviceTaskVO.getAppltype()) && patTaskRelevance.getIsoperation() == 1) { |
| | | ServiceTaskSchedule schedule = serviceTaskScheduleService.selectByTaskid(serviceTask.getTaskid()); |
| | | if (schedule == null) { |
| | | throw new BaseException("appltype=5 任务组:未找到 taskid=" + serviceTask.getTaskid() + " 的计划"); |
| | | } |
| | | List<ServiceTaskScheduleDetail> detailList = serviceTaskScheduleService.selectDetailByScheduleid(schedule.getId()); |
| | | serviceSubtask.setUpdateBy(serviceTask.getUpdateBy()); |
| | | serviceSubtask.setCreateBy(serviceTask.getUpdateBy()); |
| | | scheduleSubtaskBuilder.buildSubtasksForPatient(serviceTask, serviceTaskVO.getPreachformList(), schedule, detailList, patTaskRelevance, serviceSubtask); |
| | | continue; |
| | | } |
| | | if (patTaskRelevance.getIsoperation() == 2) { |
| | | serviceSubtask.setUpdateBy(serviceTask.getUpdateBy()); |
| | | serviceSubtaskMapper.updateServiceSubtaskByCondition(serviceSubtask); |
| | |
| | | map.put("taskId", serviceTask.getTaskid().intValue()); |
| | | return map; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) { |
| | |
| | | Long id = serviceSubtask.getId(); |
| | | //先更新一下分数 |
| | | double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | serviceSubtask.setScore(BigDecimal.valueOf(score)); |
| | | serviceSubtask.setScore(String.valueOf(score)); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtask.setUpdateTime(new Date()); |
| | | log.error("先更新一下分数,电话的serviceSubtask的值为:{}", serviceSubtask); |
| | |
| | | //用来标记,是否有匹配上的 |
| | | Integer flag = 0; |
| | | //1-AI识别 |
| | | SysConfig configVoiceMatchAi = new SysConfig(); |
| | | configVoiceMatchAi.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | configVoiceMatchAi.setConfigKey("sys.voice.match.ai"); |
| | | SysConfig matchAi = sysConfigMapper.selectConfig(configVoiceMatchAi); |
| | | String url = configService.selectConfigByKey("sys.voice.match.ai.url", phoneCallReqYQVO.getOrgid()); |
| | | |
| | | // if (ObjectUtils.isNotEmpty(matchAi) && StringUtils.isNotEmpty(matchAi.getConfigValue()) |
| | | // && matchAi.getConfigValue().equals("1")) { |
| | | // PhoneCallBackYQVO aiMatchResult = AiMatch(phoneCallReqYQVO, phoneCallBackYQVO, |
| | | // ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate, |
| | | // ivrTaskTemplateScripts, scriptId, flag); |
| | | // if(aiMatchResult != null){ |
| | | // return aiMatchResult; |
| | | // } |
| | | // } else { |
| | | //是选择题 |
| | | for (int j = 0; j < ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size(); j++) { |
| | | log.error("phoneCallReqYQVO.getAsrtext()的值为:{}", phoneCallReqYQVO.getAsrtext()); |
| | | if (StringUtils.isEmpty(phoneCallReqYQVO.getAsrtext())) { |
| | | continue; |
| | | if (ObjectUtils.isNotEmpty(url)) { |
| | | PhoneCallBackYQVO aiMatchResult = AiMatch(url, phoneCallReqYQVO, phoneCallBackYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate, ivrTaskTemplateScripts, scriptId, flag, phoneCallReqYQVO.getUuid()); |
| | | if (aiMatchResult != null) { |
| | | return aiMatchResult; |
| | | } |
| | | boolean matchedFlag = false; |
| | | //包含 |
| | | Matcher matcher = null; |
| | | if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex())) { |
| | | Pattern pattern = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()); |
| | | matcher = pattern.matcher(phoneCallReqYQVO.getAsrtext()); |
| | | } |
| | | //不包含 |
| | | Matcher matcher2 = null; |
| | | if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2())) { |
| | | Pattern pattern2 = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()); |
| | | matcher2 = pattern2.matcher(phoneCallReqYQVO.getAsrtext()); |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) { |
| | | matchedFlag = true; |
| | | } |
| | | //说明匹配正确了 |
| | | if(matchedFlag){ |
| | | //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法 |
| | | log.info("匹配正确了吗--------------"); |
| | | ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).setIsUserOperation(1); |
| | | serviceTaskScriptTargetoptionMapper.updateIvrTaskTemplateTargetoption(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j)); |
| | | |
| | | //将患者的回签写进service_subtask_detail中 |
| | | ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq(); |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>(); |
| | | ivrTaskTemplateScriptVO.setQuestionResult(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getOptiondesc()); |
| | | 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); |
| | | } |
| | | } else { |
| | | //是选择题 |
| | | for (int j = 0; j < ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size(); j++) { |
| | | log.error("phoneCallReqYQVO.getAsrtext()的值为:{}", phoneCallReqYQVO.getAsrtext()); |
| | | if (StringUtils.isEmpty(phoneCallReqYQVO.getAsrtext())) { |
| | | continue; |
| | | } |
| | | serviceSubtaskDetailList.add(serviceSubtaskDetail); |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList); |
| | | serviceSubTaskDetailReq.setGuid(phoneCallReqYQVO.getGuid()); |
| | | serviceSubTaskDetailReq.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(serviceSubTaskDetailReq); |
| | | |
| | | //判断一下当前的问题是不是满意度问题,并且dutyDeptCode是否有值,并且选项是不是异常选项,如果全符合,则往满意度问题异常表新增 |
| | | if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getDutyDeptCode()) && 1 == ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getIsabnormal()) { |
| | | ServiceSubtaskDetailTrace subtaskDetailTrace = new ServiceSubtaskDetailTrace(); |
| | | //用taskid、subid和scriptid去获取detailid |
| | | ServiceSubtaskDetail ssd = new ServiceSubtaskDetail(); |
| | | ssd.setSubId(serviceSubtask.getId()); |
| | | ssd.setTaskid(serviceSubtask.getTaskid()); |
| | | ssd.setScriptid(StringUtils.isNotEmpty(scriptId) ? Long.valueOf(scriptId) : null); |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetails = serviceSubtaskDetailMapper.selectServiceSubtaskDetailList(ssd); |
| | | subtaskDetailTrace.setDetailId(CollectionUtils.isNotEmpty(serviceSubtaskDetails) ? serviceSubtaskDetails.get(0).getId() : null); |
| | | |
| | | subtaskDetailTrace.setSubId(serviceSubtask.getId()); |
| | | subtaskDetailTrace.setTaskid(serviceSubtask.getTaskid()); |
| | | subtaskDetailTrace.setTemplateid(ivrTaskTemplateScriptVO.getId()); |
| | | subtaskDetailTrace.setTemplatequestionnum(ivrTaskTemplateScriptVO.getScriptno()); |
| | | subtaskDetailTrace.setSwitchid(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getId()); |
| | | subtaskDetailTrace.setQuestiontext(ivrTaskTemplateScriptVO.getScriptContent()); |
| | | subtaskDetailTrace.setQuestionvoice(null); |
| | | subtaskDetailTrace.setCategoryname(ivrTaskTemplateScriptVO.getScriptAssortname()); |
| | | subtaskDetailTrace.setCategoryid(ivrTaskTemplateScriptVO.getScriptAssortid()); |
| | | //获取所有选项 |
| | | String optionDescStr = Optional.ofNullable(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList()).filter(list -> !list.isEmpty()).map(list -> list.stream().map(IvrTaskTemplateTargetoption::getOptiondesc).filter(Objects::nonNull).collect(Collectors.joining("&"))).orElse(""); |
| | | subtaskDetailTrace.setTargetid(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getId()); |
| | | subtaskDetailTrace.setTargetvalue(optionDescStr); |
| | | subtaskDetailTrace.setMatchedtext(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getOptiondesc()); |
| | | subtaskDetailTrace.setValueType(serviceSubtaskDetails.get(0).getValueType()); |
| | | subtaskDetailTrace.setTemplateType(1); |
| | | |
| | | SvyLibScriptCategory svyLibScriptCategory = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryById(ivrTaskTemplateScriptVO.getScriptAssortid()); |
| | | subtaskDetailTrace.setType(svyLibScriptCategory.getType()); |
| | | subtaskDetailTrace.setScriptid(ivrTaskTemplateScriptVO.getId()); |
| | | subtaskDetailTrace.setAsrtext(phoneCallReqYQVO.getAsrtext()); |
| | | subtaskDetailTrace.setRecordpath(phoneCallReqYQVO.getRecordpath()); |
| | | subtaskDetailTrace.setPatid(serviceSubtask.getPatid()); |
| | | JSONObject patdescJson = new JSONObject(); |
| | | patdescJson.put("sendname", serviceSubtask.getSendname()); |
| | | patdescJson.put("phone", serviceSubtask.getPhone()); |
| | | patdescJson.put("age", serviceSubtask.getAge()); |
| | | patdescJson.put("sex", serviceSubtask.getSex() != null ? serviceSubtask.getSex() == 1 ? "男" : "女" : null); |
| | | subtaskDetailTrace.setPatdesc(patdescJson.toJSONString()); |
| | | subtaskDetailTrace.setTodeptcode(ivrTaskTemplateScriptVO.getDutyDeptCode()); |
| | | subtaskDetailTrace.setTodeptname(ivrTaskTemplateScriptVO.getDutyDeptName()); |
| | | subtaskDetailTrace.setOrgid(serviceSubtask.getOrgid()); |
| | | subtaskDetailTrace.setHandleFlag("0"); |
| | | subtaskDetailTrace.setGuid(phoneCallReqYQVO.getGuid()); |
| | | subtaskDetailTrace.setCreateTime(new Date()); |
| | | subtaskDetailTrace.setUpdateTime(new Date()); |
| | | subtaskDetailTrace.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | traceService.insertServiceSubtaskDetailTtrace(subtaskDetailTrace); |
| | | boolean matchedFlag = false; |
| | | //包含 |
| | | Matcher matcher = null; |
| | | if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex())) { |
| | | Pattern pattern = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()); |
| | | matcher = pattern.matcher(phoneCallReqYQVO.getAsrtext()); |
| | | } |
| | | //不包含 |
| | | Matcher matcher2 = null; |
| | | if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2())) { |
| | | Pattern pattern2 = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()); |
| | | matcher2 = pattern2.matcher(phoneCallReqYQVO.getAsrtext()); |
| | | } |
| | | |
| | | //判断一下,这个选项结果是不是还有继续问下去的必要,例如选项结果是别人不想继续回答问题,就要结束掉 |
| | | if (ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getIsEnd() == 1) { |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "noVoice"); |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask.getJsy()); |
| | | //记录状态 |
| | | setFailPreachForm(serviceSubtask, "3", "电话拨打已完成", "9"); |
| | | return phoneCallBackYQVO; |
| | | if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) { |
| | | matchedFlag = true; |
| | | } |
| | | //说明匹配正确了 |
| | | if (matchedFlag) { |
| | | //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法 |
| | | log.info("匹配正确了吗--------------"); |
| | | ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).setIsUserOperation(1); |
| | | serviceTaskScriptTargetoptionMapper.updateIvrTaskTemplateTargetoption(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j)); |
| | | |
| | | flag = 1; |
| | | //将当前前的播报状态删除,给下一题让位 |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | // //获取下一题 |
| | | log.error("获取下一题的信息:{}", ivrTaskTemplateScriptVO); |
| | | if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1") || ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() != null && ivrTaskTemplateScriptVO.getNextScriptno() != 0) { |
| | | Long nextQuestion = null; |
| | | if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1")) { |
| | | nextQuestion = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getNextQuestion(); |
| | | //更新分数 |
| | | double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | score = BigDecimal.valueOf(score).add(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getScore()).doubleValue(); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score); |
| | | } else { |
| | | nextQuestion = ivrTaskTemplateScriptVO.getNextScriptno(); |
| | | //更新分数 |
| | | Object obj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | Double score = (obj == null ? new Double(0.00) : new Double(((Double) obj).doubleValue())); |
| | | score = BigDecimal.valueOf(score).add(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getScore()).doubleValue(); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score, 120, TimeUnit.MINUTES); |
| | | } |
| | | if (nextQuestion == null || nextQuestion == 0L) { |
| | | //如果下一题为空,或者为0,则挂机 |
| | | ServiceSubtask ss = new ServiceSubtask(); |
| | | ss.setId(serviceSubtask.getId()); |
| | | ss.setSendstate(6L); |
| | | ss.setRemark("电话拨打已完成"); |
| | | serviceSubtaskMapper.updateServiceSubtask(ss); |
| | | //记录状态 |
| | | setFailPreachForm(serviceSubtask, "3", "电话拨打已完成", "9"); |
| | | |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "noVoice"); |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask.getJsy()); |
| | | //将结果写进detail表 |
| | | ServiceSubTaskDetailReq ssdReq = new ServiceSubTaskDetailReq(); |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetailList2 = new ArrayList<>(); |
| | | serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate)); |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList2); |
| | | ssdReq.setGuid(phoneCallReqYQVO.getGuid()); |
| | | ssdReq.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(ssdReq); |
| | | return phoneCallBackYQVO; |
| | | } |
| | | |
| | | for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) { |
| | | if (script.getSort() == nextQuestion.intValue()) { |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | String scriptContent = StringUtils.isNotEmpty(script.getIvrtext()) ? script.getIvrtext() : script.getScriptContent(); |
| | | log.error("下一题问题:{}", scriptContent); |
| | | log.error("下一题的子任务是:{}", serviceSubtask); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent)); |
| | | //将该患者的Redis中的题目ID,进行修改 |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES); |
| | | //删除无响应 |
| | | redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid()); |
| | | } |
| | | } |
| | | } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0) { |
| | | ServiceTask serviceTask1 = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | //更新一下分数 |
| | | double score = 0.0; |
| | | Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | if (ObjectUtils.isNotEmpty(scoreObj)) score = (double) scoreObj; |
| | | serviceSubtask.setScore(BigDecimal.valueOf(score)); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtask.setSendstate(6L); |
| | | serviceSubtask.setRemark("电话拨打已完成"); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | //记录状态 |
| | | setFailPreachForm(serviceSubtask, "3", "电话拨打已完成", "9"); |
| | | //设置结束语 |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask1.getJsy()); |
| | | Long id = serviceSubtask.getId(); |
| | | Map<String, String> map = delRedisValue(null, id.toString()); |
| | | log.error("map的值为:{}", map); |
| | | if (ObjectUtils.isNotEmpty(map)) |
| | | redisCache.setCacheObject(map.get("cacheName"), map.get("val")); |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES); |
| | | // return phoneCallBackYQVO; |
| | | |
| | | } |
| | | } else { |
| | | log.info("没有匹配上----------------------------"); |
| | | //flag=0,说明没 匹配上,也要把患者说的话记录下来 |
| | | if (j == ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size() - 1 && flag == 0) { |
| | | //将患者的回签写进service_subtask_detail中 |
| | | ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq(); |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>(); |
| | | ivrTaskTemplateScriptVO.setQuestionResult(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getOptiondesc()); |
| | | ServiceSubtaskDetail serviceSubtaskDetail = getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate); |
| | | //修改一下语音路径(改成前端可以访问的,存到数据库中) |
| | | if (StringUtils.isNotEmpty(serviceSubtaskDetail.getQuestionvoice())) { |
| | |
| | | } |
| | | } |
| | | serviceSubtaskDetailList.add(serviceSubtaskDetail); |
| | | //如果没有 匹配上,这个必须为null |
| | | serviceSubtaskDetailList.get(0).setMatchedtext(""); |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList); |
| | | serviceSubTaskDetailReq.setGuid(phoneCallReqYQVO.getGuid()); |
| | | serviceSubTaskDetailReq.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(serviceSubTaskDetailReq); |
| | | |
| | | //判断一下当前的问题是不是满意度问题,并且dutyDeptCode是否有值,并且选项是不是异常选项,如果全符合,则往满意度问题异常表新增 |
| | | if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getDutyDeptCode()) && 1 == ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getIsabnormal()) { |
| | | ServiceSubtaskDetailTrace subtaskDetailTrace = new ServiceSubtaskDetailTrace(); |
| | | //用taskid、subid和scriptid去获取detailid |
| | | ServiceSubtaskDetail ssd = new ServiceSubtaskDetail(); |
| | | ssd.setSubId(serviceSubtask.getId()); |
| | | ssd.setTaskid(serviceSubtask.getTaskid()); |
| | | ssd.setScriptid(StringUtils.isNotEmpty(scriptId) ? Long.valueOf(scriptId) : null); |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetails = serviceSubtaskDetailMapper.selectServiceSubtaskDetailList(ssd); |
| | | subtaskDetailTrace.setDetailId(CollectionUtils.isNotEmpty(serviceSubtaskDetails) ? serviceSubtaskDetails.get(0).getId() : null); |
| | | |
| | | subtaskDetailTrace.setSubId(serviceSubtask.getId()); |
| | | subtaskDetailTrace.setTaskid(serviceSubtask.getTaskid()); |
| | | subtaskDetailTrace.setTemplateid(ivrTaskTemplateScriptVO.getId()); |
| | | subtaskDetailTrace.setTemplatequestionnum(ivrTaskTemplateScriptVO.getScriptno()); |
| | | subtaskDetailTrace.setSwitchid(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getId()); |
| | | subtaskDetailTrace.setQuestiontext(ivrTaskTemplateScriptVO.getScriptContent()); |
| | | subtaskDetailTrace.setQuestionvoice(null); |
| | | subtaskDetailTrace.setCategoryname(ivrTaskTemplateScriptVO.getScriptAssortname()); |
| | | subtaskDetailTrace.setCategoryid(ivrTaskTemplateScriptVO.getScriptAssortid()); |
| | | //获取所有选项 |
| | | String optionDescStr = Optional.ofNullable(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList()).filter(list -> !list.isEmpty()).map(list -> list.stream().map(IvrTaskTemplateTargetoption::getOptiondesc).filter(Objects::nonNull).collect(Collectors.joining("&"))).orElse(""); |
| | | subtaskDetailTrace.setTargetid(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getId()); |
| | | subtaskDetailTrace.setTargetvalue(optionDescStr); |
| | | subtaskDetailTrace.setMatchedtext(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getOptiondesc()); |
| | | subtaskDetailTrace.setValueType(serviceSubtaskDetails.get(0).getValueType()); |
| | | subtaskDetailTrace.setTemplateType(1); |
| | | |
| | | SvyLibScriptCategory svyLibScriptCategory = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryById(ivrTaskTemplateScriptVO.getScriptAssortid()); |
| | | subtaskDetailTrace.setType(svyLibScriptCategory.getType()); |
| | | subtaskDetailTrace.setScriptid(ivrTaskTemplateScriptVO.getId()); |
| | | subtaskDetailTrace.setAsrtext(phoneCallReqYQVO.getAsrtext()); |
| | | subtaskDetailTrace.setRecordpath(phoneCallReqYQVO.getRecordpath()); |
| | | subtaskDetailTrace.setPatid(serviceSubtask.getPatid()); |
| | | JSONObject patdescJson = new JSONObject(); |
| | | patdescJson.put("sendname", serviceSubtask.getSendname()); |
| | | patdescJson.put("phone", serviceSubtask.getPhone()); |
| | | patdescJson.put("age", serviceSubtask.getAge()); |
| | | patdescJson.put("sex", serviceSubtask.getSex() != null ? serviceSubtask.getSex() == 1 ? "男" : "女" : null); |
| | | subtaskDetailTrace.setPatdesc(patdescJson.toJSONString()); |
| | | subtaskDetailTrace.setTodeptcode(ivrTaskTemplateScriptVO.getDutyDeptCode()); |
| | | subtaskDetailTrace.setTodeptname(ivrTaskTemplateScriptVO.getDutyDeptName()); |
| | | subtaskDetailTrace.setOrgid(serviceSubtask.getOrgid()); |
| | | subtaskDetailTrace.setHandleFlag("0"); |
| | | subtaskDetailTrace.setGuid(phoneCallReqYQVO.getGuid()); |
| | | subtaskDetailTrace.setCreateTime(new Date()); |
| | | subtaskDetailTrace.setUpdateTime(new Date()); |
| | | subtaskDetailTrace.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | traceService.insertServiceSubtaskDetailTtrace(subtaskDetailTrace); |
| | | } |
| | | |
| | | //判断一下,这个选项结果是不是还有继续问下去的必要,例如选项结果是别人不想继续回答问题,就要结束掉 |
| | | if (ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getIsEnd() == 1) { |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "noVoice"); |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask.getJsy()); |
| | | //记录状态 |
| | | setFailPreachForm(serviceSubtask, "3", "电话拨打已完成", "9"); |
| | | return phoneCallBackYQVO; |
| | | } |
| | | |
| | | flag = 1; |
| | | //将当前前的播报状态删除,给下一题让位 |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | // //获取下一题 |
| | | log.error("获取下一题的信息:{}", ivrTaskTemplateScriptVO); |
| | | if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1") || ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() != null && ivrTaskTemplateScriptVO.getNextScriptno() != 0) { |
| | | Long nextQuestion = null; |
| | | if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1")) { |
| | | nextQuestion = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getNextQuestion(); |
| | | //更新分数 |
| | | double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | score = BigDecimal.valueOf(score).add(new BigDecimal(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getScore())).doubleValue(); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score); |
| | | } else { |
| | | nextQuestion = ivrTaskTemplateScriptVO.getNextScriptno(); |
| | | //更新分数 |
| | | Object obj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | Double score = (obj == null ? new Double(0.00) : new Double(((Double) obj).doubleValue())); |
| | | score = BigDecimal.valueOf(score).add(new BigDecimal(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getScore())).doubleValue(); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score, 120, TimeUnit.MINUTES); |
| | | } |
| | | if (nextQuestion == null || nextQuestion == 0L) { |
| | | //如果下一题为空,或者为0,则挂机 |
| | | ServiceSubtask ss = new ServiceSubtask(); |
| | | ss.setId(serviceSubtask.getId()); |
| | | ss.setSendstate(6L); |
| | | ss.setRemark("电话拨打已完成"); |
| | | serviceSubtaskMapper.updateServiceSubtask(ss); |
| | | //记录状态 |
| | | setFailPreachForm(serviceSubtask, "3", "电话拨打已完成", "9"); |
| | | |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "noVoice"); |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask.getJsy()); |
| | | //将结果写进detail表 |
| | | ServiceSubTaskDetailReq ssdReq = new ServiceSubTaskDetailReq(); |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetailList2 = new ArrayList<>(); |
| | | serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate)); |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList2); |
| | | ssdReq.setGuid(phoneCallReqYQVO.getGuid()); |
| | | ssdReq.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(ssdReq); |
| | | return phoneCallBackYQVO; |
| | | } |
| | | |
| | | for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) { |
| | | if (script.getSort() == nextQuestion.intValue()) { |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | String scriptContent = StringUtils.isNotEmpty(script.getIvrtext()) ? script.getIvrtext() : script.getScriptContent(); |
| | | log.error("下一题问题:{}", scriptContent); |
| | | log.error("下一题的子任务是:{}", serviceSubtask); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent)); |
| | | //将该患者的Redis中的题目ID,进行修改 |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES); |
| | | //删除无响应 |
| | | redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid()); |
| | | } |
| | | } |
| | | } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0) { |
| | | ServiceTask serviceTask1 = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | //更新一下分数 |
| | | double score = 0.0; |
| | | 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"); |
| | | //设置结束语 |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask1.getJsy()); |
| | | Long id = serviceSubtask.getId(); |
| | | Map<String, String> map = delRedisValue(null, id.toString()); |
| | | log.error("map的值为:{}", map); |
| | | if (ObjectUtils.isNotEmpty(map)) |
| | | redisCache.setCacheObject(map.get("cacheName"), map.get("val")); |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES); |
| | | // return phoneCallBackYQVO; |
| | | |
| | | } |
| | | } else { |
| | | log.info("没有匹配上----------------------------"); |
| | | //flag=0,说明没 匹配上,也要把患者说的话记录下来 |
| | | if (j == 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); |
| | | } |
| | | } |
| | | serviceSubtaskDetailList.add(serviceSubtaskDetail); |
| | | //如果没有 匹配上,这个必须为null |
| | | serviceSubtaskDetailList.get(0).setMatchedtext(""); |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList); |
| | | serviceSubTaskDetailReq.setGuid(phoneCallReqYQVO.getGuid()); |
| | | serviceSubTaskDetailReq.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(serviceSubTaskDetailReq); |
| | | } |
| | | continue; |
| | | } |
| | | continue; |
| | | } |
| | | } |
| | | // } |
| | | //都没有匹配到 |
| | | if (StringUtils.isEmpty(phoneCallBackYQVO.getValue())) { |
| | | log.info("都没有匹配到-------------------------"); |
| | |
| | | Double score = null; |
| | | Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | if (ObjectUtils.isNotEmpty(scoreObj)) score = (Double) scoreObj; |
| | | serviceSubtask.setScore(BigDecimal.valueOf(score)); |
| | | serviceSubtask.setScore(String.valueOf(score)); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtask.setSendstate(6L); |
| | | serviceSubtask.setRemark("电话拨打已完成"); |
| | |
| | | Double score = null; |
| | | Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | if (ObjectUtils.isNotEmpty(scoreObj)) score = (Double) scoreObj; |
| | | score = BigDecimal.valueOf(score).add(script.getScore()).doubleValue(); |
| | | score = BigDecimal.valueOf(score).add(new BigDecimal(script.getScore())).doubleValue(); |
| | | |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score, 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(ivrTaskTemplateScriptVO.getScore()).doubleValue(); |
| | | score = BigDecimal.valueOf(score).add(new BigDecimal(ivrTaskTemplateScriptVO.getScore())).doubleValue(); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score, 120, TimeUnit.MINUTES); |
| | | |
| | | } |
| | |
| | | Double score = null; |
| | | Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | if (ObjectUtils.isNotEmpty(scoreObj)) score = (Double) scoreObj; |
| | | serviceSubtask.setScore(BigDecimal.valueOf(score)); |
| | | serviceSubtask.setScore(String.valueOf(score)); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtask.setRemark("电话拨打已完成"); |
| | | serviceSubtask.setSendstate(6L); |
| | |
| | | @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 groupKey = "drcode"; |
| | | String drcode = "drcode"; |
| | | //缙云人民 根据经管医生分组 |
| | | if (serviceSubtaskCountReq.getOrgid().equals("47246116333112211A1001")) { |
| | | drcode = "management_doctor_code"; |
| | | } |
| | | String groupKey = drcode; |
| | | if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 1) { |
| | | if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) { |
| | | groupKey = "drcode"; |
| | | groupKey = drcode; |
| | | } else { |
| | | groupKey = "leavehospitaldistrictcode"; |
| | | } |
| | | } else if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 2) { |
| | | if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) { |
| | | groupKey = "drcode"; |
| | | groupKey = drcode; |
| | | } else { |
| | | groupKey = "deptcode"; |
| | | } |
| | |
| | | serviceSubtaskCountReq.setGroupKeyList(groupKeyList); |
| | | List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq); |
| | | switch (groupKey) { |
| | | case "deptcode": |
| | | collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown"))); |
| | | break; |
| | | case "drcode": |
| | | collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown"))); |
| | | break; |
| | | case "management_doctor_code": |
| | | rawData = rawData.stream().peek(item -> { |
| | | item.setDrname(item.getManagementDoctor()); |
| | | item.setDrcode(item.getManagementDoctorCode()); |
| | | }).collect(Collectors.toList()); |
| | | collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getManagementDoctorCode()).orElse("Unknown"))); |
| | | break; |
| | | case "deptcode": |
| | | collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown"))); |
| | | break; |
| | | case "leavehospitaldistrictcode": |
| | | collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown"))); |
| | |
| | | serviceSubtaskStatistic.setWeChat(serviceSubtaskStatistic.getWeChat() + 1L); |
| | | } |
| | | } |
| | | |
| | | //首次随访人工成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("1")) { |
| | | serviceSubtaskStatistic.setManualSuccess(serviceSubtaskStatistic.getManualSuccess() + 1L); |
| | | } |
| | | //首次随访语音成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("3")) { |
| | | serviceSubtaskStatistic.setVoiceSuccess(serviceSubtaskStatistic.getVoiceSuccess() + 1L); |
| | | } |
| | | //首次随访短信成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("4")) { |
| | | serviceSubtaskStatistic.setSmsSuccess(serviceSubtaskStatistic.getSmsSuccess() + 1L); |
| | | } |
| | | //首次随访微信成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("5")) { |
| | | serviceSubtaskStatistic.setWeChatSuccess(serviceSubtaskStatistic.getWeChatSuccess() + 1L); |
| | | } |
| | | |
| | | if (serviceSubtaskStatistic.getNeedFollowUp() > 0) { |
| | | double rate = (double) (serviceSubtaskStatistic.getFollowUpSuccess() + serviceSubtaskStatistic.getFollowUpFail()) / serviceSubtaskStatistic.getNeedFollowUp(); |
| | | serviceSubtaskStatistic.setFollowUpRate(percentFormat.format(rate)); |
| | |
| | | serviceSubtaskStatistic.setWeChatAgain(serviceSubtaskStatistic.getWeChatAgain() + 1L); |
| | | } |
| | | } |
| | | |
| | | //再次随访人工成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("1")) { |
| | | serviceSubtaskStatistic.setManualAgainSuccess(serviceSubtaskStatistic.getManualAgainSuccess() + 1L); |
| | | } |
| | | //再次随访语音成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("3")) { |
| | | serviceSubtaskStatistic.setVoiceAgainSuccess(serviceSubtaskStatistic.getVoiceAgainSuccess() + 1L); |
| | | } |
| | | //再次随访短信成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("4")) { |
| | | serviceSubtaskStatistic.setSmsAgainSuccess(serviceSubtaskStatistic.getSmsAgainSuccess() + 1L); |
| | | } |
| | | //再次随访微信成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("5")) { |
| | | serviceSubtaskStatistic.setWeChatAgainSuccess(serviceSubtaskStatistic.getWeChatAgainSuccess() + 1L); |
| | | } |
| | | |
| | | if (serviceSubtaskStatistic.getNeedFollowUp() > 0) { |
| | | double rate = (double) (serviceSubtaskStatistic.getFollowUpSuccessAgain() + serviceSubtaskStatistic.getFollowUpFailAgain()) / serviceSubtaskStatistic.getNeedFollowUpAgain(); |
| | | serviceSubtaskStatistic.setFollowUpRateAgain(percentFormat.format(rate)); |
| | |
| | | serviceSubtaskStatistic.setWeChat(serviceSubtaskStatistic.getWeChat() + 1L); |
| | | } |
| | | } |
| | | |
| | | //首次随访人工成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("1")) { |
| | | serviceSubtaskStatistic.setManualSuccess(serviceSubtaskStatistic.getManualSuccess() + 1L); |
| | | } |
| | | //首次随访语音成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("3")) { |
| | | serviceSubtaskStatistic.setVoiceSuccess(serviceSubtaskStatistic.getVoiceSuccess() + 1L); |
| | | } |
| | | //首次随访短信成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("4")) { |
| | | serviceSubtaskStatistic.setSmsSuccess(serviceSubtaskStatistic.getSmsSuccess() + 1L); |
| | | } |
| | | //首次随访微信成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("5")) { |
| | | serviceSubtaskStatistic.setWeChatSuccess(serviceSubtaskStatistic.getWeChatSuccess() + 1L); |
| | | } |
| | | |
| | | if (serviceSubtaskStatistic.getNeedFollowUp() > 0) { |
| | | double rate = (double) (serviceSubtaskStatistic.getFollowUpSuccess() + serviceSubtaskStatistic.getFollowUpFail()) / serviceSubtaskStatistic.getNeedFollowUp(); |
| | | serviceSubtaskStatistic.setFollowUpRate(percentFormat.format(rate)); |
| | |
| | | serviceSubtaskStatistic.setWeChatAgain(serviceSubtaskStatistic.getWeChatAgain() + 1L); |
| | | } |
| | | } |
| | | |
| | | //再次随访人工成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("1")) { |
| | | serviceSubtaskStatistic.setManualAgainSuccess(serviceSubtaskStatistic.getManualAgainSuccess() + 1L); |
| | | } |
| | | //再次随访语音成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("3")) { |
| | | serviceSubtaskStatistic.setVoiceAgainSuccess(serviceSubtaskStatistic.getVoiceAgainSuccess() + 1L); |
| | | } |
| | | //再次随访短信成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("4")) { |
| | | serviceSubtaskStatistic.setSmsAgainSuccess(serviceSubtaskStatistic.getSmsAgainSuccess() + 1L); |
| | | } |
| | | //再次随访微信成功 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("5")) { |
| | | serviceSubtaskStatistic.setWeChatAgainSuccess(serviceSubtaskStatistic.getWeChatAgainSuccess() + 1L); |
| | | } |
| | | |
| | | if (serviceSubtaskStatistic.getNeedFollowUp() > 0) { |
| | | double rate = (double) (serviceSubtaskStatistic.getFollowUpSuccessAgain() + serviceSubtaskStatistic.getFollowUpFailAgain()) / serviceSubtaskStatistic.getNeedFollowUpAgain(); |
| | | serviceSubtaskStatistic.setFollowUpRateAgain(percentFormat.format(rate)); |
| | |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | //转成16进制 |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | String url = ""; |
| | | SendMagParam sendMagParam = new SendMagParam(); |
| | | url = localIP + ":" + req_path + "/sf?p=" + format; |
| | | sendMagParam.setUrl(url); |
| | | sendMagParam.setContent("【新华医院】您好,邀请您填写出院随访调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!"); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | serviceOutPath.setUrl(url); |
| | | 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()); |
| | |
| | | * voiceInfo - visitCount = 1 && currentPreachForm = "3" |
| | | * smsInfo - visitCount = 1 && currentPreachForm = "4" |
| | | * wechatInfo - visitCount = 1 && currentPreachForm = "5" |
| | | * manualSuccessInfo - visitCount = 1 && currentPreachForm = "1" && sendstate = 6 |
| | | * voiceSuccessInfo - visitCount = 1 && currentPreachForm = "3" && sendstate = 6 |
| | | * smsSuccessInfo - visitCount = 1 && currentPreachForm = "4" && sendstate = 6 |
| | | * wechatSuccessInfo - visitCount = 1 && currentPreachForm = "5" && sendstate = 6 |
| | | * abnormalInfo - visitCount = 1 && excep = "1" |
| | | * needFollowUpAgainInfo - visitCount > 1 && sendstate != 4 |
| | | * pendingFollowUpAgainInfo - visitCount > 1 && sendstate = 2 |
| | |
| | | * voiceAgainInfo - visitCount > 1 && currentPreachForm = "3" |
| | | * smsAgainInfo - visitCount > 1 && currentPreachForm = "4" |
| | | * wechatAgainInfo - visitCount > 1 && currentPreachForm = "5" |
| | | * manualAgainSuccessInfo - visitCount > 1 && currentPreachForm = "1" && sendstate = 6 |
| | | * voiceAgainSuccessInfo - visitCount > 1 && currentPreachForm = "3" && sendstate = 6 |
| | | * smsAgainSuccessInfo - visitCount > 1 && currentPreachForm = "4" && sendstate = 6 |
| | | * wechatAgainSuccessInfo - visitCount > 1&& currentPreachForm = "5" && sendstate = 6 |
| | | * abnormalAgainInfo- visitCount = 1 && excep = "1" |
| | | * taskSituation1Info - taskSituation = 1 |
| | | * taskSituation2Info - taskSituation = 2 |
| | |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setCurrentPreachform("5"); |
| | | break; |
| | | case "manualSuccessInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L))); |
| | | serviceSubtaskCountReq.setCurrentPreachform("1"); |
| | | break; |
| | | case "voiceSuccessInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L))); |
| | | serviceSubtaskCountReq.setCurrentPreachform("3"); |
| | | break; |
| | | case "smsSuccessInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L))); |
| | | serviceSubtaskCountReq.setCurrentPreachform("4"); |
| | | break; |
| | | case "wechatSuccessInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L))); |
| | | serviceSubtaskCountReq.setCurrentPreachform("5"); |
| | | break; |
| | | case "abnormalInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setExcep("1"); |
| | |
| | | break; |
| | | case "wechatAgainInfo": |
| | | serviceSubtaskCountReq.setVisitCount(2); |
| | | serviceSubtaskCountReq.setCurrentPreachform("5"); |
| | | break; |
| | | case "manualAgainSuccessInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L))); |
| | | serviceSubtaskCountReq.setCurrentPreachform("1"); |
| | | break; |
| | | case "voiceAgainSuccessInfo": |
| | | serviceSubtaskCountReq.setVisitCount(2); |
| | | serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L))); |
| | | serviceSubtaskCountReq.setCurrentPreachform("3"); |
| | | break; |
| | | case "smsAgainSuccessInfo": |
| | | serviceSubtaskCountReq.setVisitCount(2); |
| | | serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L))); |
| | | serviceSubtaskCountReq.setCurrentPreachform("4"); |
| | | break; |
| | | case "wechatAgainSuccessInfo": |
| | | serviceSubtaskCountReq.setVisitCount(2); |
| | | serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L))); |
| | | serviceSubtaskCountReq.setCurrentPreachform("5"); |
| | | break; |
| | | case "abnormalAgainInfo": |
| | |
| | | if (serviceSubtaskPreachform1.getSort() == spSize.size() && failSendstate.equals("4")) { |
| | | serviceSubtask.setCurrentPreachform(preachform); |
| | | serviceSubtask.setSendstate(5L); |
| | | serviceSubtask.setRemark(remark + ";所有发送方式均未获取结果,任务失败"); |
| | | serviceSubtask.setRemark(remark + ";所有执行方式均未获取结果,任务失败"); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | return true; |
| | | } else { |
| | |
| | | String subId = rsaPublicKeyExample.encryptedData(serviceSubtask.getId().toString(), pub_key); |
| | | String taskId = rsaPublicKeyExample.encryptedData(serviceSubtask.getTaskid().toString(), pub_key); |
| | | |
| | | //丽水中医院发送的是微信公众号 |
| | | if (StringUtils.isNotEmpty(serviceSubtask.getOrgid()) && serviceSubtask.getOrgid().equals("47231022633110211A2101")) { |
| | | resultMap = wechatSubTask(subid); |
| | | return resultMap; |
| | | } |
| | | |
| | | //发送数据的封装 |
| | | ServiceOutPath serviceOutPath = new ServiceOutPath(); |
| | | serviceOutPath.setParam1(taskId); |
| | |
| | | serviceOutPath.setOrgid(serviceSubtask.getOrgid()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | |
| | | String url = ""; |
| | | SendMagParam sendMagParam = new SendMagParam(); |
| | | sendMagParam.setType("4"); |
| | | sendMagParam.setPhone(serviceSubtask.getPhone()); |
| | | sendMagParam.setUrl(StringUtils.isNotEmpty(req_path) ? localIP + ":" + req_path + "/wt?p=" + format : localIP + "/wt?p=" + format); |
| | | url = StringUtils.isNotEmpty(req_path) ? localIP + ":" + req_path + "/wt?p=" + format : localIP + "/wt?p=" + format; |
| | | sendMagParam.setUrl(url); |
| | | |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | serviceOutPath.setUrl(url); |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | SysConfig sysConfig = new SysConfig(); |
| | | |
| | | sysConfig = sysConfigMapper.checkConfigKeyUnique("wj.sms.template"); |
| | |
| | | if (smsResult != null && smsResult.get("result") != null && smsResult.get("result").toString().equals("0")) { |
| | | resultMap.put("code", "200"); |
| | | resultMap.put("msg", "发送成功"); |
| | | serviceSubtask.setRemark(StringUtils.isNotEmpty(serviceSubtask.getRemark()) ? serviceSubtask.getRemark() + ";短信发送成功" : "短信发送成功"); |
| | | serviceSubtask.setRemark(StringUtils.isNotEmpty(serviceSubtask.getRemark()) ? serviceSubtask.getRemark() + ";短信发送成功(手动提交)" : "短信发送成功(手动提交)"); |
| | | log.info("是否发送成功:{}", serviceSubtask.getRemark()); |
| | | updateServiceSubtask(serviceSubtask); |
| | | serviceSubtask.setSendstate(3L); |
| | | serviceSubtask.setCurrentPreachform("4"); |
| | | } |
| | | } |
| | | return resultMap; |
| | | } |
| | | |
| | | public Map<String,Object> wechatSubTask(Long subid){ |
| | | log.info("wechatSubTask的入参为:{}", subid); |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | resultMap.put("code", "500"); |
| | | resultMap.put("msg", "发送失败"); |
| | | try{ |
| | | //获取随访的基本信息 |
| | | ServiceSubtask serviceSubtask = selectServiceSubtaskById(subid); |
| | | //获取患者信息 |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(serviceSubtask.getPatid()); |
| | | |
| | | RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); |
| | | String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key); |
| | | String subId = rsaPublicKeyExample.encryptedData(serviceSubtask.getId().toString(), pub_key); |
| | | String taskId = rsaPublicKeyExample.encryptedData(serviceSubtask.getTaskid().toString(), pub_key); |
| | | String url = localIP + ":" + req_path + "/outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" |
| | | + URLEncoder.encode(serviceSubtask.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false" |
| | | + "$param6=" + subId; |
| | | |
| | | ServiceOutPath serviceOutPath = new ServiceOutPath(); |
| | | serviceOutPath.setParam1(taskId); |
| | | serviceOutPath.setParam2(patid); |
| | | serviceOutPath.setParam3(serviceSubtask.getTaskName()); |
| | | serviceOutPath.setParam6(subId); |
| | | serviceOutPath.setCreateTime(new Date()); |
| | | serviceOutPath.setOrgid(serviceSubtask.getOrgid()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | serviceOutPath.setUrl(url); |
| | | 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; |
| | | } |
| | | |
| | | 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"); |
| | | } |
| | | |
| | | //发送完成后,修改状态 |
| | | serviceSubtask.setSendstate(3L); |
| | | if (wxCodeSuccess) { |
| | | serviceSubtask.setResult("success"); |
| | | resultMap.put("code", "200"); |
| | | resultMap.put("msg", "发送成功"); |
| | | } else { |
| | | log.error("【sfHandlle】公众号发送失败,患者信息:{},错误信息:{}", serviceSubtask, map.get("msg")); |
| | | resultMap.put("code", -1); |
| | | resultMap.put("message", "【公众号】公众号发送失败"); |
| | | return resultMap; |
| | | } |
| | | } catch (Exception e) { |
| | | String guid = UUID.randomUUID().toString(); |
| | | log.error("【sfHandlle】长期任务公众号发送失败,原因:{},GUID:{}", e.getMessage(), guid); |
| | | resultMap.put("code", -1); |
| | | resultMap.put("message", "【公众号】长期任务公众号发送失败,原因:" + e.getMessage()); |
| | | return resultMap; |
| | | } |
| | | return resultMap; |
| | | } |
| | | @Override |
| | | public List<ServiceSubtaskDetailRatioExport> statQuestionOption(List<Long> taskIds, Date startOutHospTime, Date endOutHospTime) { |
| | | return serviceSubtaskMapper.statQuestionOption(taskIds, startOutHospTime, endOutHospTime); |
| | | public List<ServiceSubtaskDetailRatioExport> statQuestionOption(List<Long> taskIds, Date startFinishTime, Date endFinishTime, Date startOutHospTime, Date endOutHospTime, String scriptContent, Double scoreStart, Double scoreEnd, String valueType, List<Long> subtaskIds) { |
| | | //先清理一下重复数据 |
| | | List<Long> repeatIds = serviceSubtaskDetailMapper.selectRepeatDetailIds(); |
| | | if (!CollectionUtils.isEmpty(repeatIds)) { |
| | | serviceSubtaskDetailMapper.deleteRepeatDetailByIds(repeatIds); |
| | | } |
| | | List<ServiceSubtaskDetailRatioExport> serviceSubtaskDetailRatioExports = serviceSubtaskMapper.statQuestionOption(taskIds, startOutHospTime, endOutHospTime, startFinishTime, endFinishTime, scoreStart, scoreEnd, scriptContent, valueType, subtaskIds); |
| | | |
| | | // 处理 targetvalue:按 & 分割成多条记录 |
| | | 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 |
| | | //注意必须带上 taskid 一起匹配:否则会把别的任务的数据填到本任务的行上, |
| | | //导致导出的「数量/比例」和该行的「任务名称/任务编号」对不上(同一任务同一题出现两个不同分母) |
| | | ServiceSubtaskDetailRatioExport existingExport = result.stream().filter(e -> Objects.equals(e.getTaskid(), export.getTaskid()) && e.getQuestiontext().equals(export.getQuestiontext()) && value.trim().equals(e.getTargetvalue())).findFirst().orElse(null); |
| | | if (existingExport != null && existingExport.getRatio().equals("0") && existingExport.getCount().equals("0")) { |
| | | //如果存在,则将 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 && !existingExport.getRatio().equals("0")) { |
| | | 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); |
| | | } |
| | | } |
| | | } else { |
| | | // targetvalue 不包含 &,直接添加到结果 |
| | | result.add(export); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<ServiceSubtaskDetailRatioExport> statMydQuestionOptionForExport(List<Long> subtaskIds, String questiontext) { |
| | | List<ServiceSubtaskDetailRatioExport> result = new ArrayList<>(); |
| | | if (CollectionUtils.isEmpty(subtaskIds)) { |
| | | return result; |
| | | } |
| | | List<ServiceSubtaskOptionStatDTO> statList = serviceSubtaskMapper.statMydQuestionOptionForExport(subtaskIds, questiontext); |
| | | if (CollectionUtils.isEmpty(statList)) { |
| | | return result; |
| | | } |
| | | return buildMydOptionRows(statList); |
| | | } |
| | | |
| | | /** |
| | | * 把「任务+题目+选项」的作答统计拼成导出的「问题详情占比」行 |
| | | * <ul> |
| | | * <li>选项清单:题目配置过的选项在 targetvalue(用 & 连接)里,全部列出,没人选的显示 0</li> |
| | | * <li>数量:患者选中的选项在 asrtext 里(多选题是「A&B」),每个选中项各记一次人数,一个患者只算一条明细</li> |
| | | * <li>比例:数量 / 该题作答患者数,所以单选题各选项数量之和 = 该题作答患者数</li> |
| | | * <li>分数:该选项明细的 score 之和;多选行按选中项份数均分,保证各选项分数之和 = 明细分数之和</li> |
| | | * </ul> |
| | | */ |
| | | private static List<ServiceSubtaskDetailRatioExport> buildMydOptionRows(List<ServiceSubtaskOptionStatDTO> statList) { |
| | | List<ServiceSubtaskDetailRatioExport> result = new ArrayList<>(); |
| | | |
| | | // 按「任务 + 题目」分组,保持 SQL 的顺序(先题目后任务) |
| | | Map<String, List<ServiceSubtaskOptionStatDTO>> grouped = new LinkedHashMap<>(); |
| | | for (ServiceSubtaskOptionStatDTO stat : statList) { |
| | | String key = stat.getTaskid() + "\u0001" + stat.getQuestiontext(); |
| | | grouped.computeIfAbsent(key, k -> new ArrayList<>()).add(stat); |
| | | } |
| | | |
| | | for (List<ServiceSubtaskOptionStatDTO> group : grouped.values()) { |
| | | ServiceSubtaskOptionStatDTO first = group.get(0); |
| | | // 选项 -> 人数(long[1] 便于累加),顺序即出现顺序 |
| | | Map<String, long[]> countMap = new LinkedHashMap<>(); |
| | | Map<String, BigDecimal> scoreMap = new LinkedHashMap<>(); |
| | | |
| | | for (ServiceSubtaskOptionStatDTO stat : group) { |
| | | // targetvalue = 本题所有选项的清单,没人选的也要列出来 |
| | | List<String> options = splitOptions(stat.getTargetvalue()); |
| | | // asrtext = 患者实际选中的选项,多选题会是「选中项1&选中项2」 |
| | | List<String> chosenOptions = splitOptions(stat.getOptionresult()); |
| | | for (String option : options) { |
| | | countMap.computeIfAbsent(option, k -> new long[1]); |
| | | scoreMap.computeIfAbsent(option, k -> BigDecimal.ZERO); |
| | | } |
| | | |
| | | long patientCount = stat.getPatientCount() == null ? 0L : stat.getPatientCount(); |
| | | BigDecimal scoreSum = stat.getScoreSum() == null ? BigDecimal.ZERO : stat.getScoreSum(); |
| | | |
| | | if (!chosenOptions.isEmpty()) { |
| | | BigDecimal[] scoreParts = splitScore(scoreSum, chosenOptions.size()); |
| | | for (int i = 0; i < chosenOptions.size(); i++) { |
| | | String chosen = chosenOptions.get(i); |
| | | // 选中的选项可能不在配置清单里(历史数据),补一行 |
| | | countMap.computeIfAbsent(chosen, k -> new long[1]); |
| | | scoreMap.computeIfAbsent(chosen, k -> BigDecimal.ZERO); |
| | | countMap.get(chosen)[0] += patientCount; |
| | | scoreMap.put(chosen, scoreMap.get(chosen).add(scoreParts[i])); |
| | | } |
| | | } else if (options.size() == 1) { |
| | | // 没有 asrtext(未答/无应答)时,只有唯一选项才能确定归属 |
| | | countMap.get(options.get(0))[0] += patientCount; |
| | | scoreMap.put(options.get(0), scoreMap.get(options.get(0)).add(scoreSum)); |
| | | } |
| | | } |
| | | |
| | | long total = 0L; |
| | | for (long[] count : countMap.values()) total += count[0]; |
| | | |
| | | for (Map.Entry<String, long[]> entry : countMap.entrySet()) { |
| | | long count = entry.getValue()[0]; |
| | | ServiceSubtaskDetailRatioExport row = new ServiceSubtaskDetailRatioExport(); |
| | | row.setQuestiontext(first.getQuestiontext()); |
| | | row.setOptionresult(entry.getKey()); |
| | | row.setTargetvalue(entry.getKey()); |
| | | row.setCount(String.valueOf(count)); |
| | | row.setRatio(formatRatio(count, total)); |
| | | row.setScore(formatScore(scoreMap.get(entry.getKey()))); |
| | | row.setTaskname(first.getTaskName()); |
| | | row.setTaskid(first.getTaskid()); |
| | | row.setValueType(first.getValueType()); |
| | | result.add(row); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 把一条明细的分数按选中项份数均分,余数补给第一个,保证各份之和 = 原分数 |
| | | */ |
| | | private static BigDecimal[] splitScore(BigDecimal total, int parts) { |
| | | BigDecimal[] result = new BigDecimal[parts]; |
| | | if (parts <= 0) { |
| | | return result; |
| | | } |
| | | BigDecimal each = total.divide(BigDecimal.valueOf(parts), 2, RoundingMode.HALF_UP); |
| | | for (int i = 0; i < parts; i++) { |
| | | result[i] = each; |
| | | } |
| | | result[0] = result[0].add(total.subtract(each.multiply(BigDecimal.valueOf(parts)))); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 拆分题目配置的选项(多个选项用 & 连接),顺带去掉全角/半角空白 |
| | | */ |
| | | private static List<String> splitOptions(String targetvalue) { |
| | | List<String> options = new ArrayList<>(); |
| | | if (StringUtils.isEmpty(targetvalue)) { |
| | | return options; |
| | | } |
| | | for (String part : targetvalue.split("&")) { |
| | | String option = trimAll(part); |
| | | if (StringUtils.isNotEmpty(option) && !options.contains(option)) { |
| | | options.add(option); |
| | | } |
| | | } |
| | | return options; |
| | | } |
| | | |
| | | /** |
| | | * 比例:数量 / 该题作答患者数,保留两位小数 |
| | | */ |
| | | private static String formatRatio(long count, long total) { |
| | | if (total <= 0) { |
| | | return "0.00%"; |
| | | } |
| | | return BigDecimal.valueOf(count * 100.0 / total).setScale(2, RoundingMode.HALF_UP).toPlainString() + "%"; |
| | | } |
| | | |
| | | /** |
| | | * 分数之和:去掉多余的小数位(0.00 -> 0) |
| | | */ |
| | | private static String formatScore(BigDecimal score) { |
| | | if (score == null) { |
| | | return "0"; |
| | | } |
| | | BigDecimal value = score.stripTrailingZeros(); |
| | | if (value.scale() < 0) { |
| | | value = value.setScale(0); |
| | | } |
| | | return value.toPlainString(); |
| | | } |
| | | |
| | | /* |
| | | * 根据科室或病区统计问卷选项(科室、题目查询的科室评分表) |
| | | */ |
| | | @Override |
| | | public Map<String, Map<String, List<QuestionCountKsOrBqDTO>>> statQuestionOptionByKsOrBq(QuestionCountKsOrBqVO vo) { |
| | | |
| | | // 1. 查明细 |
| | | List<QuestionCountKsOrBqDTO> sourceList = serviceSubtaskMapper.statQuestionOptionByKsOrBq(vo); |
| | | if (CollectionUtils.isEmpty(sourceList)) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | |
| | | // 2. 判断按科室还是按病区 |
| | | boolean byDept = vo.getLeaveldeptcodes() != null; |
| | | boolean byDistrict = !byDept && vo.getLeavehospitaldistrictcodes() != null; |
| | | if (!byDept && !byDistrict) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | |
| | | // 3. key = 科室/病区 + 题目 + 选项 |
| | | Map<String, QuestionCountKsOrBqDTO> map = new LinkedHashMap<>(); |
| | | |
| | | for (QuestionCountKsOrBqDTO dto : sourceList) { |
| | | |
| | | if (StringUtils.isEmpty(dto.getTargetvalue())) { |
| | | continue; |
| | | } |
| | | |
| | | // 分组名:科室 或 病区 |
| | | String groupName = byDept ? dto.getDeptname() : dto.getLeavehospitaldistrictname(); |
| | | if (StringUtils.isEmpty(groupName)) { |
| | | continue; |
| | | } |
| | | |
| | | String asrtext = trimAll(dto.getAsrtext()); // 用户实际选中的选项 |
| | | String questionText = trimAll(dto.getQuestionText()); // 题目 |
| | | if (StringUtils.isEmpty(questionText)) { |
| | | continue; |
| | | } |
| | | |
| | | // 拆分 targetvalue,每个选项都要有一条记录 |
| | | for (String raw : dto.getTargetvalue().split("&")) { |
| | | |
| | | String option = trimAll(raw); |
| | | if (option.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | // key = 科室/病区 + 题目 + 选项 |
| | | String key = buildKey(groupName, questionText, option); |
| | | |
| | | QuestionCountKsOrBqDTO item = map.get(key); |
| | | if (item == null) { |
| | | item = DtoConversionUtils.sourceToTarget(dto, QuestionCountKsOrBqDTO.class); |
| | | item.setTargetvalue(option); |
| | | item.setAsrtext(option); |
| | | item.setQuestionText(dto.getQuestionText()); |
| | | item.setAnswerCount("0"); |
| | | item.setSingleScore("0"); |
| | | map.put(key, item); |
| | | } |
| | | |
| | | // 只有当前选项 == 用户实际选中的选项,才累加 |
| | | if (option.equals(asrtext)) { |
| | | int count = parseCount(item.getAnswerCount()) + 1; |
| | | item.setAnswerCount(String.valueOf(count)); |
| | | |
| | | BigDecimal totalScore = new BigDecimal(item.getSingleScore()) |
| | | .add(new BigDecimal(dto.getSingleScore() == null ? "0" : dto.getSingleScore())); |
| | | item.setSingleScore(totalScore.toPlainString()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 4. 计算平均分 |
| | | for (QuestionCountKsOrBqDTO dto : map.values()) { |
| | | String answerCount = dto.getAnswerCount(); |
| | | String singleScore = dto.getSingleScore(); |
| | | |
| | | BigDecimal avg; |
| | | if (StringUtils.isEmpty(answerCount) |
| | | || BigDecimal.ZERO.compareTo(new BigDecimal(answerCount.trim())) == 0) { |
| | | avg = BigDecimal.ZERO; |
| | | } else { |
| | | avg = new BigDecimal(singleScore == null ? "0" : singleScore) |
| | | .divide(new BigDecimal(answerCount.trim()), 2, RoundingMode.HALF_UP); |
| | | } |
| | | dto.setAvgScore(avg.toPlainString()); |
| | | } |
| | | |
| | | // 5. 转成 Map<String, Map<String, List<QuestionCountKsOrBqDTO>>> |
| | | // 第一层 key:科室/病区 |
| | | // 第二层 key:题目 |
| | | // 第二层 value:该题目下的所有选项列表 |
| | | Map<String, Map<String, List<QuestionCountKsOrBqDTO>>> result = new LinkedHashMap<>(); |
| | | |
| | | for (QuestionCountKsOrBqDTO dto : map.values()) { |
| | | |
| | | // 分组名 |
| | | String groupName = byDept ? dto.getDeptname() : dto.getLeavehospitaldistrictname(); |
| | | if (StringUtils.isEmpty(groupName)) { |
| | | continue; |
| | | } |
| | | |
| | | // 题目名 |
| | | String questionText = dto.getQuestionText(); |
| | | if (StringUtils.isEmpty(questionText)) { |
| | | continue; |
| | | } |
| | | |
| | | // 第一层:科室/病区 |
| | | Map<String, List<QuestionCountKsOrBqDTO>> questionMap = |
| | | result.computeIfAbsent(groupName, k -> new LinkedHashMap<>()); |
| | | |
| | | // 第二层:题目 |
| | | List<QuestionCountKsOrBqDTO> optionList = |
| | | questionMap.computeIfAbsent(questionText, k -> new ArrayList<>()); |
| | | |
| | | optionList.add(dto); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<ServiceSubtaskDetailRatioExport> statQuestionOptionBySubtaskIds(List<Long> subtaskIds, Date startOutHospTime, Date endOutHospTime, Date startFinishTime, Date endFinishTime, String scriptContent, Double scoreStart, Double scoreEnd, String valueType) { |
| | | //先清理一下重复数据 |
| | | List<Long> repeatIds = serviceSubtaskDetailMapper.selectRepeatDetailIds(); |
| | | if (!CollectionUtils.isEmpty(repeatIds)) { |
| | | serviceSubtaskDetailMapper.deleteRepeatDetailByIds(repeatIds); |
| | | } |
| | | |
| | | List<ServiceSubtaskDetailRatioExport> serviceSubtaskDetailRatioExports = serviceSubtaskMapper.statQuestionOptionBySubtaskIds(subtaskIds, startOutHospTime, endOutHospTime, startFinishTime, endFinishTime, scoreStart, scoreEnd, scriptContent, valueType); |
| | | // 处理 targetvalue:按 & 分割成多条记录 |
| | | 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); |
| | | } |
| | | } |
| | | } else { |
| | | // targetvalue 不包含 &,直接添加到结果 |
| | | result.add(export); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 标准化问卷答案文本:去掉 A/B/C/D 单字母前缀和后续空格 |
| | | * 例如 "A 是" -> "是","B 否" -> "否" |
| | | */ |
| | | private String normalizeOptionAnswer(String answer) { |
| | | if (StringUtils.isBlank(answer)) { |
| | | return ""; |
| | | } |
| | | String trimmed = answer.trim(); |
| | | if (trimmed.length() >= 3 && trimmed.charAt(1) == ' ') { |
| | | char firstChar = trimmed.charAt(0); |
| | | if (firstChar >= 'A' && firstChar <= 'Z') { |
| | | return trimmed.substring(2).trim(); |
| | | } |
| | | } |
| | | return trimmed; |
| | | } |
| | | |
| | | private Boolean saveServiceSubtaskDetail(ServiceSubtask serviceSubtask) { |
| | |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | String url = ip + ":" + req_path + "/wt?p=" + format; |
| | | String url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format; |
| | | content = url; |
| | | serviceOutPath.setUrl(url); |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | |
| | | return content; |
| | | } |
| | | |
| | | /** |
| | | * 满意度趋势查询 |
| | | * |
| | | * @param mydTrendReqVO |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MydTrendReqDTO> mydTrend(MydTrendReqVO mydTrendReqVO) { |
| | | List<MydTrendReqDTO> list = serviceSubtaskMapper.mydTrend(mydTrendReqVO.getStartFinishTime(), mydTrendReqVO.getEndFinishTime(), mydTrendReqVO.getType()); |
| | | if (mydTrendReqVO.getType().equals("week")) list = getWeekDate(mydTrendReqVO, list); |
| | | if (mydTrendReqVO.getType().equals("year")) list = getYearDate(mydTrendReqVO, list); |
| | | if (mydTrendReqVO.getType().equals("month")) list = getMonthDate(mydTrendReqVO, list); |
| | | if (mydTrendReqVO.getType().equals("day")) list = getDayDate(mydTrendReqVO, list); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<MydTrendReqDTO> sltdMydTotalByDimension(MydTrendReqVO mydTrendReqVO) { |
| | | List<MydTrendReqDTO> list = null; |
| | | if (mydTrendReqVO.getDimensionType().equals("1")) |
| | | list = serviceSubtaskMapper.sltdMydTotalByDimension(mydTrendReqVO.getStartFinishTime(), mydTrendReqVO.getEndFinishTime(), mydTrendReqVO.getType()); |
| | | else if (mydTrendReqVO.getDimensionType().equals("2")) |
| | | list = serviceSubtaskMapper.sltdMydTotalByYQ(mydTrendReqVO.getStartFinishTime(), mydTrendReqVO.getEndFinishTime(), mydTrendReqVO.getType()); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | |
| | | public ServiceSubtask boxedServiceSubtask(ServiceTask serviceTask, ServiceTaskdept serviceTaskdept, PatArchive patArchive) { |
| | | ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTask, ServiceSubtask.class); |
| | | serviceSubtask.setTaskid(serviceTask.getTaskid()); |
| | |
| | | // serviceSubtask.setNurseName(patMedInhosp1.getNurseName()); |
| | | // serviceSubtask.setDrcode(patMedInhosp1.getDrcode()); |
| | | // serviceSubtask.setDrname(patMedInhosp1.getDrname()); |
| | | if(StringUtils.isNotEmpty(serviceTaskdept.getDeptType()) && serviceTaskdept.getDeptType().equals("1")){ |
| | | if (StringUtils.isNotEmpty(serviceTaskdept.getDeptType()) && serviceTaskdept.getDeptType().equals("1")) { |
| | | serviceSubtask.setDeptcode(serviceTaskdept.getDeptCode()); |
| | | serviceSubtask.setDeptname(serviceTaskdept.getDeptName()); |
| | | }else { |
| | | } else { |
| | | serviceSubtask.setLeavehospitaldistrictcode(serviceTaskdept.getDeptCode()); |
| | | serviceSubtask.setLeavehospitaldistrictname(serviceTaskdept.getDeptName()); |
| | | } |
| | |
| | | |
| | | /** |
| | | * Ai 匹配选项 |
| | | * |
| | | * @param questionText |
| | | * @param voiceText |
| | | * @param options |
| | | * @return |
| | | */ |
| | | public Integer matchOptionIndex(String questionText, String voiceText, List<IvrTaskTemplateTargetoption> options){ |
| | | @Override |
| | | public Integer matchOptionIndex(String url, String questionText, String voiceText, List<IvrTaskTemplateTargetoption> options, String uuid) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("userQuestion",questionText); |
| | | jsonObject.put("userAnswer",voiceText); |
| | | jsonObject.put("userQuestion", questionText); |
| | | jsonObject.put("userAnswer", voiceText); |
| | | jsonObject.put("options", options); |
| | | jsonObject.put("uuid", uuid); |
| | | String jsonString = jsonObject.toJSONString(); |
| | | String result = null; |
| | | |
| | | String url = "http://localhost:8099/matchOptionIndex"; |
| | | // String url = configService.selectConfigByKey("sys.voice.match.ai.url"); |
| | | if(StringUtils.isNotEmpty(url)){ |
| | | // String url = "http://localhost:8099/matchOptionIndex"; |
| | | if (StringUtils.isNotEmpty(url)) { |
| | | try { |
| | | Map<String, String> headers = new HashMap<>(); |
| | | headers.put("Content-Type", "application/json"); |
| | |
| | | log.error("AI识别失败", e); |
| | | } |
| | | } |
| | | if(StringUtils.isNotEmpty(result) && result.matches("^-?\\d+$")){ |
| | | if (StringUtils.isNotEmpty(result) && result.matches("^-?\\d+$")) { |
| | | return Integer.parseInt(result); |
| | | }else { |
| | | } else { |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | public PhoneCallBackYQVO AiMatch(PhoneCallReqYQVO phoneCallReqYQVO, PhoneCallBackYQVO phoneCallBackYQVO, |
| | | IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO, ServiceSubtask serviceSubtask, IvrTaskTemplate ivrTaskTemplate, |
| | | List<IvrTaskTemplateScript> ivrTaskTemplateScripts, String scriptId, Integer flag){ |
| | | |
| | | 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; |
| | | List<IvrTaskTemplateTargetoption> options = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList(); |
| | | String voiceText = phoneCallReqYQVO.getAsrtext(); |
| | | String questionText = StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrtext()) ? ivrTaskTemplateScriptVO.getIvrtext() : ivrTaskTemplateScriptVO.getScriptContent(); |
| | | Integer matched = -1; |
| | | matched = matchOptionIndex(questionText, voiceText, options); |
| | | matched = matchOptionIndex(url, questionText, voiceText, options, uuid); |
| | | //说明匹配正确了 |
| | | if(matched != null && matched >= 0){ |
| | | if (matched != null && matched >= 0) { |
| | | IvrTaskTemplateTargetoption chosenOption = options.get(matched); |
| | | //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法 |
| | | log.info("匹配正确了吗--------------"); |
| | |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | // //获取下一题 |
| | | log.error("获取下一题的信息:{}", ivrTaskTemplateScriptVO); |
| | | if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1") || ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() != null && ivrTaskTemplateScriptVO.getNextScriptno() != 0) { |
| | | //branchFlag为null时按分支0处理,避免NPE |
| | | if ("1".equals(ivrTaskTemplateScriptVO.getBranchFlag()) || "0".equals(ivrTaskTemplateScriptVO.getBranchFlag()) && ivrTaskTemplateScriptVO.getNextScriptno() != null && ivrTaskTemplateScriptVO.getNextScriptno() != 0) { |
| | | Long nextQuestion = null; |
| | | if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1")) { |
| | | if ("1".equals(ivrTaskTemplateScriptVO.getBranchFlag())) { |
| | | nextQuestion = chosenOption.getNextQuestion(); |
| | | //更新分数 |
| | | double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | score = BigDecimal.valueOf(score).add(chosenOption.getScore()).doubleValue(); |
| | | score = BigDecimal.valueOf(score).add(new BigDecimal(chosenOption.getScore())).doubleValue(); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score); |
| | | } else { |
| | | nextQuestion = ivrTaskTemplateScriptVO.getNextScriptno(); |
| | | //更新分数 |
| | | Object obj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | Double score = (obj == null ? new Double(0.00) : new Double(((Double) obj).doubleValue())); |
| | | score = BigDecimal.valueOf(score).add(chosenOption.getScore()).doubleValue(); |
| | | score = BigDecimal.valueOf(score).add(new BigDecimal(String.valueOf(chosenOption.getScore()))).doubleValue(); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score, 120, TimeUnit.MINUTES); |
| | | } |
| | | if (nextQuestion == null || nextQuestion == 0L) { |
| | |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask.getJsy()); |
| | | //将结果写进detail表 |
| | | ServiceSubTaskDetailReq ssdReq = new ServiceSubTaskDetailReq(); |
| | | List<ServiceSubtaskDetail> serviceSubtaskDetailList2 = new ArrayList<>(); |
| | | serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate)); |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList2); |
| | | ssdReq.setGuid(phoneCallReqYQVO.getGuid()); |
| | | ssdReq.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(ssdReq); |
| | | //将结果写进detail表(本题的明细在上面匹配成功时已经组装并存入serviceSubtaskDetailList,这里直接落库,避免重复新增) |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList); |
| | | serviceSubTaskDetailReq.setGuid(phoneCallReqYQVO.getGuid()); |
| | | serviceSubTaskDetailReq.setOrgid(phoneCallReqYQVO.getOrgid()); |
| | | saveQuestionAnswerPhone(serviceSubTaskDetailReq); |
| | | return phoneCallBackYQVO; |
| | | } |
| | | |
| | |
| | | double score = 0.0; |
| | | Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | if (ObjectUtils.isNotEmpty(scoreObj)) score = (double) scoreObj; |
| | | serviceSubtask.setScore(BigDecimal.valueOf(score)); |
| | | serviceSubtask.setScore(String.valueOf(score)); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtask.setSendstate(6L); |
| | | serviceSubtask.setRemark("电话拨打已完成"); |
| | |
| | | Long id = serviceSubtask.getId(); |
| | | Map<String, String> map = delRedisValue(null, id.toString()); |
| | | log.error("map的值为:{}", map); |
| | | if (ObjectUtils.isNotEmpty(map)) |
| | | redisCache.setCacheObject(map.get("cacheName"), map.get("val")); |
| | | if (ObjectUtils.isNotEmpty(map)) redisCache.setCacheObject(map.get("cacheName"), map.get("val")); |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | |
| | | return back; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 问题结果占比 |
| | | * |
| | | * @param sltdMydTotalVO |
| | | * @param serviceSubtaskRes |
| | | * @return |
| | | */ |
| | | public List<ServiceSubtaskDetailRatioExport> getDetailRatio(SltdMydTotalVO sltdMydTotalVO, List<ServiceSubtaskRes> serviceSubtaskRes) { |
| | | List<ServiceSubtaskDetailRatioExport> serviceSubtaskDetailRatioExports = null; |
| | | List<String> serviceTypeList = sltdMydTotalVO.getServiceTypeList(); |
| | | if (CollectionUtils.isEmpty(serviceTypeList)) { |
| | | log.warn("getDetailRatio 未传 serviceTypeList,无法统计问题占比"); |
| | | return serviceSubtaskDetailRatioExports; |
| | | } |
| | | // 判断口径:2=随访(按 taskid 统计),6/14=满意度(按 subtask id 统计) |
| | | boolean hasFollowUp = serviceTypeList.contains("2"); |
| | | boolean hasSatisfaction = serviceTypeList.contains("6") || serviceTypeList.contains("14"); |
| | | if (hasFollowUp && hasSatisfaction) { |
| | | //serviceType,即有随访又有满意度,暂时没法统计 |
| | | log.warn("getDetailRatio 暂不支持同时统计随访(2)与满意度(6/14),serviceTypeList={}", serviceTypeList); |
| | | return serviceSubtaskDetailRatioExports; |
| | | } |
| | | if (hasFollowUp) { |
| | | //获取serviceSubtaskList中的所有taskid |
| | | List<Long> taskIds = serviceSubtaskRes.stream().map(ServiceSubtaskRes::getTaskid).filter(ObjectUtils::isNotEmpty).distinct().collect(Collectors.toList()); |
| | | //同时带上本次导出的子任务 id:让「问题详情占比」只统计这批患者,与「患者随访信息表单」口径一致 |
| | | List<Long> subtaskIds = serviceSubtaskRes.stream().map(ServiceSubtaskRes::getId).filter(ObjectUtils::isNotEmpty).distinct().collect(Collectors.toList()); |
| | | serviceSubtaskDetailRatioExports = statQuestionOption(taskIds, sltdMydTotalVO.getStartFinishTime(), sltdMydTotalVO.getEndFinishTime(), sltdMydTotalVO.getStartOutHospTime(), sltdMydTotalVO.getEndOutHospTime(), sltdMydTotalVO.getQuestionContent(), sltdMydTotalVO.getStartScore(), sltdMydTotalVO.getEndScore(), sltdMydTotalVO.getValueType(), subtaskIds); |
| | | } else if (hasSatisfaction) { |
| | | //满意度统计 (通过 subtask 的 id 去统计) |
| | | List<Long> subtaskIds = serviceSubtaskRes.stream().map(ServiceSubtaskRes::getId).collect(Collectors.toList()); |
| | | serviceSubtaskDetailRatioExports = statQuestionOptionBySubtaskIds(subtaskIds, sltdMydTotalVO.getStartOutHospTime(), sltdMydTotalVO.getEndOutHospTime(), sltdMydTotalVO.getStartFinishTime(), sltdMydTotalVO.getEndFinishTime(), sltdMydTotalVO.getQuestionContent(), sltdMydTotalVO.getStartScore(), sltdMydTotalVO.getEndScore(), sltdMydTotalVO.getValueType()); |
| | | } else { |
| | | log.warn("getDetailRatio 暂不支持的 serviceTypeList={}(仅支持 2 或 6/14)", serviceTypeList); |
| | | } |
| | | return serviceSubtaskDetailRatioExports; |
| | | } |
| | | |
| | | //获取任务组信息 |
| | | 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()); |
| | | serviceTaskScheduleVO.setDetailList(scheduleDetailList); |
| | | serviceTaskVO.setServiceTaskScheduleVO(serviceTaskScheduleVO); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void TestMatch(){ |
| | | public void TestMatch() { |
| | | String questionText = "您好,请问您是患者本人还是家属?\n"; |
| | | String voiceText = "我自己"; |
| | | String matchedText = ""; |
| | |
| | | IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption3 = new IvrTaskTemplateTargetoption(); |
| | | ivrTaskTemplateTargetoption3.setTargetvalue("其他"); |
| | | options.add(ivrTaskTemplateTargetoption3); |
| | | |
| | | Integer matched = matchOptionIndex(questionText,voiceText,options); |
| | | if(ObjectUtils.isNotEmpty(matched)){ |
| | | if(matched >= 0){ |
| | | //1-AI识别 |
| | | String url = configService.selectConfigByKey("sys.voice.match.ai.url"); |
| | | Integer matched = matchOptionIndex(url, questionText, voiceText, options, "1"); |
| | | if (ObjectUtils.isNotEmpty(matched)) { |
| | | if (matched >= 0) { |
| | | matchedText = options.get(matched).getTargetvalue(); |
| | | } |
| | | } |
| | | log.info("ai匹配成功,匹配结果是:" + matchedText); |
| | | } |
| | | |
| | | private static String trimAll(String s) { |
| | | if (s == null) { |
| | | return ""; |
| | | } |
| | | int start = 0; |
| | | int end = s.length(); |
| | | while (start < end && isBlankChar(s.charAt(start))) { |
| | | start++; |
| | | } |
| | | while (end > start && isBlankChar(s.charAt(end - 1))) { |
| | | end--; |
| | | } |
| | | return s.substring(start, end); |
| | | } |
| | | |
| | | private static Boolean isBlankChar(char c) { |
| | | return c == '\u3000' // 全角空格 |
| | | || c == ' ' // 半角空格 |
| | | || c == '\t' || c == '\n' || c == '\r' || c == '\f' || Character.isWhitespace(c); |
| | | } |
| | | |
| | | |
| | | private String buildKey(String groupName, String questionText, String option) { |
| | | return groupName + "\u0001" + questionText + "\u0001" + option; |
| | | } |
| | | |
| | | private static int parseCount(String s) { |
| | | if (StringUtils.isEmpty(s)) { |
| | | return 0; |
| | | } |
| | | try { |
| | | return Integer.parseInt(s.trim()); |
| | | } catch (NumberFormatException e) { |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | private List<MydTrendReqDTO> getWeekDate(MydTrendReqVO mydTrendReqVO, List<MydTrendReqDTO> list) { |
| | | // 1. 计算总周数(和 SQL 里的公式保持一致) |
| | | long days = (mydTrendReqVO.getEndFinishTime().getTime() - mydTrendReqVO.getStartFinishTime().getTime()) / (1000L * 60 * 60 * 24); |
| | | int totalWeeks = (int) (days / 7) + 1; |
| | | |
| | | // 2. 已有数据:period -> totalScore |
| | | Map<Integer, String> exist = new HashMap<>(); |
| | | for (MydTrendReqDTO row : list) { |
| | | // period 是数字,可能是 Integer / Long / BigDecimal,统一转 int |
| | | int p = Integer.parseInt(StringUtils.isNotEmpty(row.getPeriod()) ? row.getPeriod() : "0"); |
| | | exist.put(p, row.getTotalScore() != null ? row.getTotalScore() : "0"); |
| | | // 下面这行按你的原逻辑保留(虽然看起来有点多余) |
| | | exist.put(p, String.valueOf(row.getTotalScore() != null ? row.getTotalScore() : 0)); |
| | | } |
| | | |
| | | // 3. 补全 1..totalWeeks |
| | | List<MydTrendReqDTO> result = new ArrayList<>(totalWeeks); |
| | | |
| | | // 获取整体的开始时间 |
| | | long startTimeMillis = mydTrendReqVO.getStartFinishTime().getTime(); |
| | | long endTimeMillis = mydTrendReqVO.getEndFinishTime().getTime(); |
| | | long oneWeekMillis = 7L * 24 * 60 * 60 * 1000; // 一周的毫秒数 |
| | | |
| | | for (int i = 1; i <= totalWeeks; i++) { |
| | | MydTrendReqDTO row = new MydTrendReqDTO(); |
| | | row.setPeriod(String.valueOf(i)); |
| | | row.setTotalScore(exist.getOrDefault(i, "0")); |
| | | |
| | | // -------- 新增:设置每周的 startDate 和 endDate -------- |
| | | // 当前周开始时间 = 整体开始时间 + (i - 1) * 7天 |
| | | long currentStartMillis = startTimeMillis + (long) (i - 1) * oneWeekMillis; |
| | | |
| | | // 当前周结束时间 = 当前周开始时间 + 7天 - 1毫秒(保证是这一周的最后一刻) |
| | | long currentEndMillis = currentStartMillis + oneWeekMillis - 1; |
| | | |
| | | // 如果是最后一周,结束时间不能超过整体的 endTime |
| | | if (i == totalWeeks) { |
| | | currentEndMillis = endTimeMillis; |
| | | } |
| | | |
| | | row.setStartDate(new Date(currentStartMillis)); |
| | | row.setEndDate(new Date(currentEndMillis)); |
| | | // ---------------------------------------------------- |
| | | |
| | | result.add(row); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private List<MydTrendReqDTO> getYearDate(MydTrendReqVO mydTrendReqVO, List<MydTrendReqDTO> list) { |
| | | // 获取整体开始和结束时间 |
| | | Date startTime = mydTrendReqVO.getStartFinishTime(); |
| | | Date endTime = mydTrendReqVO.getEndFinishTime(); |
| | | |
| | | // 1. 计算年份范围 |
| | | // 使用 Calendar 获取起始年份和结束年份 |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(startTime); |
| | | int startYear = cal.get(Calendar.YEAR); |
| | | |
| | | cal.setTime(endTime); |
| | | int endYear = cal.get(Calendar.YEAR); |
| | | |
| | | // 总年数 (包含首尾) |
| | | int totalYears = endYear - startYear + 1; |
| | | |
| | | // 2. 已有数据:period -> totalScore (假设 period 存的是年份字符串,如 "2024") |
| | | Map<String, String> exist = new HashMap<>(); |
| | | for (MydTrendReqDTO row : list) { |
| | | String period = row.getPeriod() != null ? row.getPeriod() : ""; |
| | | exist.put(period, row.getTotalScore() != null ? row.getTotalScore() : "0"); |
| | | } |
| | | |
| | | // 3. 补全所有年份 |
| | | List<MydTrendReqDTO> result = new ArrayList<>(totalYears); |
| | | |
| | | for (int i = 0; i < totalYears; i++) { |
| | | int currentYear = startYear + i; |
| | | String periodKey = String.valueOf(currentYear); |
| | | |
| | | MydTrendReqDTO row = new MydTrendReqDTO(); |
| | | row.setPeriod(periodKey); |
| | | // 如果没有该年份的数据,默认给 "0" |
| | | row.setTotalScore(exist.getOrDefault(periodKey, "0")); |
| | | |
| | | // -------- 设置该年份的 startDate 和 endDate -------- |
| | | Calendar yearCal = Calendar.getInstance(); |
| | | // 设置为该年的 1月1日 00:00:00 |
| | | yearCal.set(currentYear, Calendar.JANUARY, 1, 0, 0, 0); |
| | | yearCal.set(Calendar.MILLISECOND, 0); |
| | | row.setStartDate(yearCal.getTime()); |
| | | |
| | | // 设置为该年的 12月31日 23:59:59 |
| | | yearCal.set(currentYear, Calendar.DECEMBER, 31, 23, 59, 59); |
| | | yearCal.set(Calendar.MILLISECOND, 999); |
| | | row.setEndDate(yearCal.getTime()); |
| | | // ---------------------------------------------------- |
| | | |
| | | result.add(row); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private List<MydTrendReqDTO> getMonthDate(MydTrendReqVO mydTrendReqVO, List<MydTrendReqDTO> list) { |
| | | // 获取整体开始和结束时间 |
| | | Date startTime = mydTrendReqVO.getStartFinishTime(); |
| | | Date endTime = mydTrendReqVO.getEndFinishTime(); |
| | | |
| | | // 1. 计算月份范围 |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(startTime); |
| | | int startYear = cal.get(Calendar.YEAR); |
| | | int startMonth = cal.get(Calendar.MONTH); // 注意:Calendar.MONTH 从 0 开始 |
| | | |
| | | cal.setTime(endTime); |
| | | int endYear = cal.get(Calendar.YEAR); |
| | | int endMonth = cal.get(Calendar.MONTH); |
| | | |
| | | // 总月数 = (结束年 - 开始年) * 12 + (结束月 - 开始月) + 1 |
| | | int totalMonths = (endYear - startYear) * 12 + (endMonth - startMonth) + 1; |
| | | |
| | | // 2. 已有数据:period -> totalScore (period 存的是月份字符串,如 "2024-06") |
| | | Map<String, String> exist = new HashMap<>(); |
| | | for (MydTrendReqDTO row : list) { |
| | | String period = row.getPeriod() != null ? row.getPeriod() : ""; |
| | | exist.put(period, row.getTotalScore() != null ? row.getTotalScore() : "0"); |
| | | } |
| | | |
| | | // 3. 补全所有月份 |
| | | List<MydTrendReqDTO> result = new ArrayList<>(totalMonths); |
| | | |
| | | Calendar monthCal = Calendar.getInstance(); |
| | | monthCal.set(startYear, startMonth, 1, 0, 0, 0); |
| | | monthCal.set(Calendar.MILLISECOND, 0); |
| | | |
| | | for (int i = 0; i < totalMonths; i++) { |
| | | int currentYear = monthCal.get(Calendar.YEAR); |
| | | int currentMonth = monthCal.get(Calendar.MONTH) + 1; // 转成 1-12 月 |
| | | |
| | | // 拼接 period,格式:yyyy-MM,比如 "2024-06" |
| | | // 如果你希望是 "2024-6",可以把 String.format 改成 currentMonth |
| | | String periodKey = String.format("%04d-%02d", currentYear, currentMonth); |
| | | |
| | | MydTrendReqDTO row = new MydTrendReqDTO(); |
| | | row.setPeriod(periodKey); |
| | | row.setTotalScore(exist.getOrDefault(periodKey, "0")); |
| | | |
| | | // -------- 设置该月的 startDate 和 endDate -------- |
| | | // 当月开始时间:1号 00:00:00.000 |
| | | Calendar startCal = (Calendar) monthCal.clone(); |
| | | row.setStartDate(startCal.getTime()); |
| | | |
| | | // 当月结束时间:下个月1号 00:00:00.000 减 1 毫秒 |
| | | Calendar endCal = (Calendar) monthCal.clone(); |
| | | endCal.add(Calendar.MONTH, 1); |
| | | endCal.add(Calendar.MILLISECOND, -1); |
| | | row.setEndDate(endCal.getTime()); |
| | | // ---------------------------------------------------- |
| | | |
| | | result.add(row); |
| | | |
| | | // 进入下一个月 |
| | | monthCal.add(Calendar.MONTH, 1); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private List<MydTrendReqDTO> getDayDate(MydTrendReqVO mydTrendReqVO, List<MydTrendReqDTO> list) { |
| | | // 获取整体开始和结束时间 |
| | | Date startTime = mydTrendReqVO.getStartFinishTime(); |
| | | Date endTime = mydTrendReqVO.getEndFinishTime(); |
| | | |
| | | // 1. 计算总天数 |
| | | long oneDayMillis = 24L * 60 * 60 * 1000; |
| | | // 注意:这里只算日期差,不考虑时分秒,否则可能差一天 |
| | | Calendar startCal = Calendar.getInstance(); |
| | | startCal.setTime(startTime); |
| | | startCal.set(Calendar.HOUR_OF_DAY, 0); |
| | | startCal.set(Calendar.MINUTE, 0); |
| | | startCal.set(Calendar.SECOND, 0); |
| | | startCal.set(Calendar.MILLISECOND, 0); |
| | | |
| | | Calendar endCal = Calendar.getInstance(); |
| | | endCal.setTime(endTime); |
| | | endCal.set(Calendar.HOUR_OF_DAY, 0); |
| | | endCal.set(Calendar.MINUTE, 0); |
| | | endCal.set(Calendar.SECOND, 0); |
| | | endCal.set(Calendar.MILLISECOND, 0); |
| | | |
| | | long days = (endCal.getTimeInMillis() - startCal.getTimeInMillis()) / oneDayMillis; |
| | | int totalDays = (int) days + 1; |
| | | |
| | | // 2. 已有数据:period -> totalScore (period 存的是日期字符串,如 "2024-06-01") |
| | | Map<String, String> exist = new HashMap<>(); |
| | | for (MydTrendReqDTO row : list) { |
| | | String period = row.getPeriod() != null ? row.getPeriod() : ""; |
| | | exist.put(period, row.getTotalScore() != null ? row.getTotalScore() : "0"); |
| | | } |
| | | |
| | | // 3. 补全所有日期 |
| | | List<MydTrendReqDTO> result = new ArrayList<>(totalDays); |
| | | |
| | | Calendar dayCal = (Calendar) startCal.clone(); |
| | | for (int i = 0; i < totalDays; i++) { |
| | | // 拼接 period,格式:yyyy-MM-dd |
| | | String periodKey = String.format("%04d-%02d-%02d", dayCal.get(Calendar.YEAR), dayCal.get(Calendar.MONTH) + 1, dayCal.get(Calendar.DAY_OF_MONTH)); |
| | | |
| | | MydTrendReqDTO row = new MydTrendReqDTO(); |
| | | row.setPeriod(periodKey); |
| | | row.setTotalScore(exist.getOrDefault(periodKey, "0")); |
| | | |
| | | // -------- 设置该天的 startDate 和 endDate -------- |
| | | Calendar startOfDay = (Calendar) dayCal.clone(); |
| | | row.setStartDate(startOfDay.getTime()); |
| | | |
| | | Calendar endOfDay = (Calendar) dayCal.clone(); |
| | | endOfDay.set(Calendar.HOUR_OF_DAY, 23); |
| | | endOfDay.set(Calendar.MINUTE, 59); |
| | | endOfDay.set(Calendar.SECOND, 59); |
| | | endOfDay.set(Calendar.MILLISECOND, 999); |
| | | row.setEndDate(endOfDay.getTime()); |
| | | // ---------------------------------------------------- |
| | | |
| | | result.add(row); |
| | | |
| | | // 进入下一天 |
| | | dayCal.add(Calendar.DAY_OF_MONTH, 1); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 门诊满意度综合得分排名(按科室或病区) |
| | | * <p> |
| | | * 综合满意度 = Σ(评分明细权重) / 评分明细条数 × 100%, |
| | | * 权重只取 1、0.8、0.6、0.4、0.2 五档(很满意、满意、一般、不满意、很不满意)。 |
| | | * |
| | | * @param mzMydScoreRankVO 查询条件 |
| | | * @return 排名结果,名次从 1 开始顺序编号 |
| | | */ |
| | | @Override |
| | | public List<MzMydScoreRankDTO> mzMydScoreRank(MzMydScoreRankVO mzMydScoreRankVO) { |
| | | if (StringUtils.isEmpty(mzMydScoreRankVO.getDimensionType())) { |
| | | mzMydScoreRankVO.setDimensionType("1"); |
| | | } |
| | | if (CollectionUtils.isEmpty(mzMydScoreRankVO.getServiceTypes())) { |
| | | List<String> list=new ArrayList<>(Arrays.asList("14")); |
| | | mzMydScoreRankVO.setServiceTypes(list); |
| | | } |
| | | List<MzMydScoreRankDTO> list = serviceSubtaskMapper.selectMzMydScoreRank(mzMydScoreRankVO); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | // 名次:SQL 已按综合得分降序返回,这里顺序编号 |
| | | for (int i = 0; i < list.size(); i++) { |
| | | list.get(i).setRank(i + 1); |
| | | } |
| | | 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()); |
| | | } |
| | | } |