| | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.collections4.ListUtils; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | public Map<String, Object> patItemCount(ServiceSubtaskVO serviceSubtaskVO) { |
| | | // 直接调用数据库统计方法,在数据库层完成聚合计算 |
| | | Map<String, Object> result = serviceSubtaskMapper.countByCondition(serviceSubtaskVO); |
| | | |
| | | // 处理空异常 |
| | | if(MapUtils.isEmpty(result)){ |
| | | result = new HashMap<>(); |
| | | } |
| | | // 确保所有 key 都有值,避免空指针异常 |
| | | // MyBatis 的 SUM 在没有匹配行时会返回 null |
| | | result.putIfAbsent("wzx", 0); |
| | |
| | | } |
| | | if (ObjectUtils.isNotEmpty(serviceTaskVO.getIvrTaskTemplateVO())) { |
| | | tempid = Long.valueOf(ivrTaskTemplateService.saveOrUpdateTempScript(serviceTaskVO.getIvrTaskTemplateVO())); |
| | | tempName = ivrTaskTemplateService.selectIvrTaskTemplateByID(tempid).getTemplateName(); |
| | | log.info("IVR模板插入成功,返回的tempid={}", tempid); |
| | | |
| | | IvrTaskTemplate ivrTaskTemplate = ivrTaskTemplateService.selectIvrTaskTemplateByID(tempid); |
| | | if (ivrTaskTemplate == null) { |
| | | log.error("根据tempid={}查询IVR模板失败,返回null!请检查del_flag字段是否正确设置", tempid); |
| | | throw new BaseException("IVR模板保存成功但查询失败,请联系管理员检查数据"); |
| | | } |
| | | tempName = ivrTaskTemplate.getTemplateName(); |
| | | log.info("IVR模板查询成功,tempName={}", tempName); |
| | | } |
| | | |
| | | //往任务表中,新增任务 |
| | |
| | | return serviceSubtaskStatistics; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取满意度题目总量 |
| | | * type : 1-科室 2病区 |
| | |
| | | return serviceSubtaskMapper.getSfStatisticsJoydetails(serviceSubtaskCountReq); |
| | | } |
| | | |
| | | /** |
| | | * 获取随访统计比例 |
| | | * |
| | | * @param serviceSubtaskCountReq |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Cacheable(value = "sfStatisticsJoy", key = "T(org.springframework.util.DigestUtils).md5DigestAsHex(#serviceSubtaskCountReq.toString().getBytes())", unless = "#result == null or #result.isEmpty()") |
| | | public List<ServiceSubtaskStatistic> getSfStatisticsScript(ServiceSubtaskCountReq serviceSubtaskCountReq) { |
| | | log.error("getSfStatisticsScript的入参为:{}", serviceSubtaskCountReq); |
| | | List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>(); |
| | | |
| | | // 根据条件进行分组 |
| | | Map<String, List<ServiceSubtask>> collect = new HashMap<>(); |
| | | String orgid = null; |
| | | |
| | | if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && serviceSubtaskCountReq.getLeavehospitaldistrictcodes().size() > 0) { |
| | | if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) { |
| | | collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown"))); |
| | | |
| | | } else { |
| | | collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown"))); |
| | | } |
| | | } else if (serviceSubtaskCountReq.getDeptcodes() != null && serviceSubtaskCountReq.getDeptcodes().size() > 0) { |
| | | if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) { |
| | | collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown"))); |
| | | } else { |
| | | collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown"))); |
| | | } |
| | | } |
| | | //获取随访统计 |
| | | List<ServiceSubtaskCount> subCount = new ArrayList<>(); |
| | | subCount = serviceSubtaskMapper.getSfStatisticsCategory(serviceSubtaskCountReq); |
| | | for (List<ServiceSubtask> serviceSubtaskList : collect.values()) { |
| | | if (CollectionUtils.isEmpty(serviceSubtaskList)) { |
| | | continue; |
| | | } |
| | | ServiceSubtaskStatistic statistic = getStatisticJoy(serviceSubtaskList, subCount); |
| | | //及时率 |
| | | ServiceSubtask ss = new ServiceSubtask(); |
| | | orgid = serviceSubtaskList.get(0).getOrgid(); |
| | | ss.setOrgid(orgid); |
| | | |
| | | // 如果有医生编码,设置医生编码用于及时率查询 |
| | | if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) { |
| | | ss.setDrcode(serviceSubtaskList.get(0).getDrcode()); |
| | | } else { |
| | | if (CollectionUtils.isNotEmpty(serviceSubtaskCountReq.getLeavehospitaldistrictcodes())) { |
| | | ss.setLeavehospitaldistrictcode(serviceSubtaskList.get(0).getLeavehospitaldistrictcode()); |
| | | } else if (CollectionUtils.isNotEmpty(serviceSubtaskCountReq.getDeptcodes())) { |
| | | ss.setDeptcode(serviceSubtaskList.get(0).getDeptcode()); |
| | | } |
| | | } |
| | | |
| | | ss.setStarttime(serviceSubtaskCountReq.getStartTime()); |
| | | ss.setEndtime(serviceSubtaskCountReq.getEndTime()); |
| | | if (serviceSubtaskCountReq.getEndTime() != null && new Date().before(serviceSubtaskCountReq.getEndTime())) { |
| | | ss.setEndtime(new Date()); |
| | | } |
| | | Double jsRate = serviceSubtaskMapper.selectTimelyRate(ss); |
| | | statistic.setRate(jsRate); |
| | | if (ObjectUtils.isNotEmpty(statistic)) { |
| | | serviceSubtaskStatistics.add(statistic); |
| | | } |
| | | } |
| | | if (CollectionUtils.isNotEmpty(serviceSubtaskStatistics)) { |
| | | for (ServiceSubtaskStatistic serviceSubtaskStatistic : serviceSubtaskStatistics) { |
| | | //获取满意度题目总量 |
| | | BigDecimal mydtmzlsum = new BigDecimal(0); |
| | | //获取满意度题目填报量 |
| | | BigDecimal mydtblsum = new BigDecimal(0); |
| | | //完成比例 |
| | | Double wcbl = null; |
| | | if(ObjectUtils.isNotEmpty(serviceSubtaskStatistic.getJoyAllCount())){ |
| | | mydtblsum = new BigDecimal(serviceSubtaskStatistic.getJoyAllCount()); |
| | | } |
| | | |
| | | if(ObjectUtils.isNotEmpty(serviceSubtaskStatistic.getJoyCount())){ |
| | | mydtmzlsum = new BigDecimal(serviceSubtaskStatistic.getJoyCount()); |
| | | } |
| | | if(mydtmzlsum.intValue() != 0){ |
| | | wcbl = mydtblsum.divide(mydtmzlsum, 2, RoundingMode.HALF_UP).doubleValue(); |
| | | } |
| | | serviceSubtaskStatistic.setJoyAllCount(mydtmzlsum.intValue()); |
| | | serviceSubtaskStatistic.setJoyCount(mydtblsum.intValue()); |
| | | serviceSubtaskStatistic.setJoyTotal(wcbl); |
| | | } |
| | | } |
| | | |
| | | return serviceSubtaskStatistics; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, ServiceSubtaskScriptCount> getSfStatisticsScriptDetails(ServiceSubtaskCountReq serviceSubtaskCountReq) { |
| | | Map<String, ServiceSubtaskScriptCount> result = new HashMap<>(); |
| | | List<ServiceSubtaskScriptCount> allCounts = new ArrayList<>(); |
| | | List<ServiceSubtaskScriptCount> allItemCounts = new ArrayList<>(); |
| | | String type = serviceSubtaskCountReq.getType(); |
| | | if(ObjectUtils.isEmpty(type)){ |
| | | //查询语音统计明细 |
| | | serviceSubtaskCountReq.setType("1"); |
| | | List<ServiceSubtaskScriptCount> ivyCounts = serviceSubtaskMapper.getSfStatisticsScriptDetails(serviceSubtaskCountReq); |
| | | List<ServiceSubtaskScriptCount> ivyItemCounts = serviceSubtaskMapper.getSfStatisticsScriptItemDetails(serviceSubtaskCountReq); |
| | | |
| | | //查询短信统计明细 |
| | | serviceSubtaskCountReq.setType("2"); |
| | | List<ServiceSubtaskScriptCount> svyCounts = serviceSubtaskMapper.getSfStatisticsScriptDetails(serviceSubtaskCountReq); |
| | | List<ServiceSubtaskScriptCount> svyItemCounts = serviceSubtaskMapper.getSfStatisticsScriptItemDetails(serviceSubtaskCountReq); |
| | | |
| | | allCounts.addAll(ivyCounts); |
| | | allCounts.addAll(svyCounts); |
| | | allItemCounts.addAll(ivyItemCounts); |
| | | allItemCounts.addAll(svyItemCounts); |
| | | }else { |
| | | allCounts = serviceSubtaskMapper.getSfStatisticsScriptDetails(serviceSubtaskCountReq); |
| | | allItemCounts = serviceSubtaskMapper.getSfStatisticsScriptItemDetails(serviceSubtaskCountReq); |
| | | } |
| | | |
| | | for(ServiceSubtaskScriptCount count : allCounts){ |
| | | Map<String, ServiceSubtaskScriptCount> itemCountMap = new HashMap<>(); |
| | | if(ObjectUtils.isNotEmpty(count.getTemplateid())){ |
| | | SvyTaskTemplateVO svyTaskTemplateVO = new SvyTaskTemplateVO(); |
| | | svyTaskTemplateVO.setId(count.getTemplateid()); |
| | | SvyTaskTemplateVO svyTaskTemplateResultVo = svyTaskTemplateService.selectInfoByCondition(svyTaskTemplateVO); |
| | | if(ObjectUtils.isNotEmpty(svyTaskTemplateResultVo)){ |
| | | List<SvyTaskTemplateScriptVO> templateScriptVOS = svyTaskTemplateResultVo.getSvyTaskTemplateScriptVOS(); |
| | | if(ObjectUtils.isNotEmpty(templateScriptVOS)){ |
| | | //填入空白信息 |
| | | templateScriptVOS.forEach(templateScriptVO ->{ |
| | | ServiceSubtaskScriptCount emptyCount = new ServiceSubtaskScriptCount(); |
| | | emptyCount.setScriptContent(count.getScriptContent()); |
| | | emptyCount.setScriptType(count.getScriptType()); |
| | | emptyCount.setCompletedQuantity(count.getCompletedQuantity()); |
| | | emptyCount.setAllQuantity(count.getAllQuantity()); |
| | | emptyCount.setChosenQuantity(0); |
| | | emptyCount.setChosenPercentage("0.0"); |
| | | itemCountMap.put(templateScriptVO.getScriptResult(),emptyCount); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | allItemCounts.forEach(itemCount ->{ |
| | | if(ObjectUtils.isNotEmpty(count.getScriptid()) && ObjectUtils.isNotEmpty(itemCount.getScriptid())){ |
| | | if(count.getScriptid().equals(itemCount.getScriptid())){ |
| | | //放入统计信息 |
| | | itemCount.setScriptContent(count.getScriptContent()); |
| | | itemCount.setScriptType(count.getScriptType()); |
| | | itemCount.setCompletedQuantity(count.getCompletedQuantity()); |
| | | itemCount.setAllQuantity(count.getAllQuantity()); |
| | | //计算选择比例 |
| | | int chosenQuantity = ObjectUtils.isNotEmpty(itemCount.getChosenQuantity())?itemCount.getChosenQuantity():0; |
| | | int completedQuantity = itemCount.getCompletedQuantity(); |
| | | if(ObjectUtils.isNotEmpty(completedQuantity) && completedQuantity != 0){ |
| | | BigDecimal chosenPercentage = (new BigDecimal(chosenQuantity)).divide(new BigDecimal(completedQuantity), 2, RoundingMode.HALF_UP); |
| | | itemCount.setChosenPercentage(chosenPercentage.toString()); |
| | | } |
| | | itemCountMap.put(count.getOptionText(), itemCount); |
| | | } |
| | | } |
| | | }); |
| | | List<ServiceSubtaskScriptCount> itemCounts = new ArrayList<>(itemCountMap.values()); |
| | | count.setDetails(itemCounts); |
| | | result.put(count.getScriptid().toString(),count); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param serviceSubtask |
| | |
| | | serviceSubtaskPreachform.setTaskid(taskid); |
| | | List<ServiceSubtaskPreachform> serviceSubtaskPreachforms = serviceSubtaskPreachformMapper.selectServiceSubtaskPreachformList(serviceSubtaskPreachform); |
| | | if (CollectionUtils.isNotEmpty(serviceSubtaskPreachforms)) { |
| | | //没有随访时间则按当天来算--临时 |
| | | if (ObjectUtils.isEmpty(visitTime)) { |
| | | visitTime = new Date(); |
| | | } |
| | | |
| | | String compensateTime = serviceSubtaskPreachforms.get(0).getCompensateTime(); |
| | | int hoursToAdd = Integer.valueOf(compensateTime) * 24; |
| | | Calendar calendar = Calendar.getInstance(); |