| | |
| | | package com.smartor.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | |
| | | import com.smartor.common.FtpService; |
| | | import com.smartor.config.PhoneUtils; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.domain.VO.ServiceSubtaskCotinueCountVO; |
| | | import com.smartor.domain.entity.ServiceSubtaskEntity; |
| | | import com.smartor.mapper.*; |
| | | import com.smartor.service.*; |
| | |
| | | // 处理空异常 |
| | | if (MapUtils.isEmpty(result)) { |
| | | result = new HashMap<>(); |
| | | // 确保所有 key 都有值,避免空指针异常 |
| | | // MyBatis 的 SUM 在没有匹配行时会返回 null |
| | | result.putIfAbsent("wzx", 0); |
| | | result.putIfAbsent("ysf", 0); |
| | | result.putIfAbsent("yc", 0); |
| | | result.putIfAbsent("jg", 0); |
| | | result.putIfAbsent("fssb", 0); |
| | | result.putIfAbsent("yfs", 0); |
| | | result.putIfAbsent("blq", 0); |
| | | result.putIfAbsent("dsf", 0); |
| | | result.putIfAbsent("total", 0); |
| | | } |
| | | // 确保所有 key 都有值,避免空指针异常 |
| | | // MyBatis 的 SUM 在没有匹配行时会返回 null |
| | | result.putIfAbsent("wzx", 0); |
| | | result.putIfAbsent("ysf", 0); |
| | | result.putIfAbsent("yc", 0); |
| | | result.putIfAbsent("jg", 0); |
| | | result.putIfAbsent("fssb", 0); |
| | | result.putIfAbsent("yfs", 0); |
| | | result.putIfAbsent("blq", 0); |
| | | result.putIfAbsent("dsf", 0); |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | if (StringUtils.isNotEmpty(serviceTaskVO.getLibtemplateid())) { |
| | | serviceTask.setLibtemplateid(serviceTaskVO.getLibtemplateid()); |
| | | serviceTask.setLibtemplatename(serviceTaskVO.getLibtemplatename()); |
| | | }else { |
| | | } else { |
| | | if (ObjectUtils.isNotEmpty(serviceTaskVO.getSvyTaskTemplateVO())) { |
| | | serviceTask.setLibtemplateid(""+serviceTaskVO.getSvyTaskTemplateVO().getTemplateid()); |
| | | serviceTask.setLibtemplatename(""+serviceTaskVO.getLibtemplatename()); |
| | | serviceTask.setLibtemplateid("" + serviceTaskVO.getSvyTaskTemplateVO().getTemplateid()); |
| | | serviceTask.setLibtemplatename("" + serviceTaskVO.getLibtemplatename()); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(serviceTaskVO.getIvrTaskTemplateVO())) { |
| | | serviceTask.setLibtemplateid(""+serviceTaskVO.getIvrTaskTemplateVO().getLibtemplateid()); |
| | | serviceTask.setLibtemplatename(""+serviceTaskVO.getIvrTaskTemplateVO().getLibtemplatename()); |
| | | serviceTask.setLibtemplateid("" + serviceTaskVO.getIvrTaskTemplateVO().getLibtemplateid()); |
| | | serviceTask.setLibtemplatename("" + serviceTaskVO.getIvrTaskTemplateVO().getLibtemplatename()); |
| | | } |
| | | } |
| | | if (serviceTaskVO.getTemplateid() != null) { |
| | |
| | | subtaskDetailTrace.setAsrtext(phoneCallReqYQVO.getAsrtext()); |
| | | subtaskDetailTrace.setRecordpath(phoneCallReqYQVO.getRecordpath()); |
| | | subtaskDetailTrace.setPatid(serviceSubtask.getPatid()); |
| | | subtaskDetailTrace.setPatdesc(serviceSubtask.getSendname() + "," + serviceSubtask.getPhone() + "," + serviceSubtask.getDeptname()); |
| | | 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()); |
| | |
| | | // if (existSize > 0) return pullTaskVOList; |
| | | int count = 0; |
| | | long size = listOps.size("cache-0"); |
| | | log.error("---------打电话之前缓存中的数据量:{}", size); |
| | | log.info("---------打电话之前缓存中的数据量:{}", size); |
| | | if (size > 0) { |
| | | //phoneCount() 通过给出的每个小时需要打出的电话量,算出到晚上8点一点能打出多少个电话,获取到总量 |
| | | //如果需要立即执行的数据量大于一天要执行的上限,则只取上限的数量,其它的则放回redis中 |
| | |
| | | } |
| | | } |
| | | // if (existList.size() != 0) redisCache.setCacheListRight("cache-exist", existList); |
| | | log.error("-----------实际拉取的电话数据量:{}", CollectionUtils.isNotEmpty(pullTaskVOList) ? pullTaskVOList.size() : null); |
| | | log.info("-----------实际拉取的电话数据量:{}", CollectionUtils.isNotEmpty(pullTaskVOList) ? pullTaskVOList.size() : null); |
| | | return pullTaskVOList; |
| | | } |
| | | |
| | |
| | | public List<ServiceSubtaskStatistic> getSfStatistics(ServiceSubtaskCountReq serviceSubtaskCountReq) { |
| | | log.info("getSfStatistics的入参为:{}", serviceSubtaskCountReq); |
| | | String groupKey = "drcode"; |
| | | if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && !serviceSubtaskCountReq.getLeavehospitaldistrictcodes().isEmpty()) { |
| | | if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 1) { |
| | | if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) { |
| | | groupKey = "drcode"; |
| | | } else { |
| | | groupKey = "leavehospitaldistrictcode"; |
| | | } |
| | | } else if (serviceSubtaskCountReq.getDeptcodes() != null && !serviceSubtaskCountReq.getDeptcodes().isEmpty()) { |
| | | } else if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 2) { |
| | | if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) { |
| | | groupKey = "drcode"; |
| | | } else { |
| | |
| | | |
| | | if (visitCount != null && visitCount > 1) { |
| | | serviceSubtaskStatistic = getStatisticAgain(serviceSubtaskList, followUpCountStyle); |
| | | }else if(visitCount != null && visitCount == 1){ |
| | | } else if (visitCount != null && visitCount == 1) { |
| | | serviceSubtaskStatistic = getStatisticFirst(serviceSubtaskList, followUpCountStyle); |
| | | }else { |
| | | } else { |
| | | //格式化为两位小数的百分比 |
| | | DecimalFormat percentFormat = new DecimalFormat("##.##%"); |
| | | serviceSubtaskStatistic.setDeptname(serviceSubtaskList.get(0).getDeptname()); |
| | |
| | | |
| | | /** |
| | | * 首次随访统计 |
| | | * |
| | | * @param serviceSubtaskList |
| | | * @param followUpCountStyle |
| | | * @return |
| | |
| | | |
| | | /** |
| | | * 再次随访统计 |
| | | * |
| | | * @param serviceSubtaskList |
| | | * @param followUpCountStyle |
| | | * @return |
| | |
| | | if (serviceSubtaskPreachform1.getSort() == spSize.size() && failSendstate.equals("4")) { |
| | | serviceSubtask.setCurrentPreachform(preachform); |
| | | serviceSubtask.setSendstate(5L); |
| | | // serviceSubtask.setRemark("setFailPreachForm方法 当前的preachform已经是最后一个了,全失败了"); |
| | | serviceSubtask.setRemark("所有发送方式均未获取结果,任务失败"); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | return true; |
| | | } |
| | |
| | | public Map<String, Object> getCurrentUserServiceSubtaskCount(ServiceSubtaskEntity entity) { |
| | | return serviceSubtaskMapper.getCurrentUserServiceSubtaskCount(entity); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getContinueNurseCount(ServiceSubtaskCotinueCountVO vo) { |
| | | boolean hasDistrict = !CollectionUtils.isEmpty(vo.getLeavehospitaldistrictcodes()); |
| | | boolean hasDept = !CollectionUtils.isEmpty(vo.getDeptcodes()); |
| | | |
| | | List<Map<String, Object>> districtRows; |
| | | List<Map<String, Object>> deptRows; |
| | | |
| | | if (hasDistrict) { |
| | | // 只传了病区:仅按病区维度统计 |
| | | districtRows = serviceSubtaskMapper.getContinueNurseCount(vo); |
| | | deptRows = Collections.emptyList(); |
| | | } else if (hasDept) { |
| | | // 只传了科室:仅按科室维度统计 |
| | | districtRows = Collections.emptyList(); |
| | | deptRows = serviceSubtaskMapper.getContinueNurseCountByDept(vo); |
| | | } else { |
| | | // 都未传:病区和科室各统计一遍 |
| | | districtRows = serviceSubtaskMapper.getContinueNurseCount(vo); |
| | | deptRows = serviceSubtaskMapper.getContinueNurseCountByDept(vo); |
| | | } |
| | | |
| | | long totalNoContinue = 0L; |
| | | long totalContinue = 0L; |
| | | List<Map<String, Object>> detail = new ArrayList<>(); |
| | | |
| | | for (Map<String, Object> row : districtRows) { |
| | | String groupName = row.get("groupName") == null |
| | | ? (row.get("groupCode") == null ? "" : row.get("groupCode").toString()) |
| | | : row.get("groupName").toString(); |
| | | long noCnt = row.get("noContinueCnt") == null ? 0L : Long.parseLong(row.get("noContinueCnt").toString()); |
| | | long yesCnt = row.get("continueCnt") == null ? 0L : Long.parseLong(row.get("continueCnt").toString()); |
| | | totalNoContinue += noCnt; |
| | | totalContinue += yesCnt; |
| | | Map<String, Object> item = new LinkedHashMap<>(); |
| | | item.put("未延续_" + groupName, noCnt); |
| | | item.put("已延续_"+groupName, yesCnt); |
| | | detail.add(item); |
| | | } |
| | | |
| | | for (Map<String, Object> row : deptRows) { |
| | | String groupName = row.get("groupName") == null |
| | | ? (row.get("groupCode") == null ? "" : row.get("groupCode").toString()) |
| | | : row.get("groupName").toString(); |
| | | long noCnt = row.get("noContinueCnt") == null ? 0L : Long.parseLong(row.get("noContinueCnt").toString()); |
| | | long yesCnt = row.get("continueCnt") == null ? 0L : Long.parseLong(row.get("continueCnt").toString()); |
| | | totalNoContinue += noCnt; |
| | | totalContinue += yesCnt; |
| | | Map<String, Object> item = new LinkedHashMap<>(); |
| | | item.put("未延续_" + groupName, noCnt); |
| | | item.put("已延续_" + groupName, yesCnt); |
| | | detail.add(item); |
| | | } |
| | | |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | result.put("未延续总数量", totalNoContinue); |
| | | result.put("已延续总数量", totalContinue); |
| | | result.put("详情", detail); |
| | | return result; |
| | | } |
| | | } |