| | |
| | | @ApiOperation("查询患者随访信息") |
| | | @PostMapping("/patItem") |
| | | public Map<String, Object> patItem(@RequestBody ServiceSubtaskVO serviceSubtaskVO) { |
| | | // if (serviceSubtaskVO.getLeavehospitaldistrictcodes() != null && serviceSubtaskVO.getLeavehospitaldistrictcodes().size() > 10) { |
| | | // throw new BaseException("病区查询数量不能超过10个"); |
| | | // } |
| | | // if (serviceSubtaskVO.getLeaveldeptcodes() != null && serviceSubtaskVO.getLeaveldeptcodes().size() > 10) { |
| | | // throw new BaseException("科室查询数量不能超过10个"); |
| | | // } |
| | | |
| | | serviceSubtaskVO.setPageNum(PageUtils.getOffset(serviceSubtaskVO.getPageNum(), serviceSubtaskVO.getPageSize())); |
| | | List<ServiceSubtaskRes> serviceSubtaskList = null; |
| | |
| | | serviceSubtaskEntity.setContinueContent(ObjectUtils.isNotEmpty(serviceSubtaskVO.getContinueContent()) ? serviceSubtaskVO.getContinueContent().toString() : null); |
| | | serviceSubtaskList = serviceSubtaskService.patItem(serviceSubtaskEntity); |
| | | } |
| | | for (ServiceSubtaskRes serviceSubtask : serviceSubtaskList) { |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); |
| | | serviceSubtaskRecord.setOrgid(serviceSubtask.getOrgid()); |
| | | if (ObjectUtils.isNotEmpty((serviceSubtask.getTaskid()))) |
| | | serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); |
| | | serviceSubtask.setServiceSubtaskRecordList(serviceSubtaskRecordService.selectServiceSubtaskRecordList(serviceSubtaskRecord)); |
| | | |
| | | ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); |
| | | if (ObjectUtils.isNotEmpty(serviceTask)) serviceSubtask.setPreachform(serviceTask.getPreachform()); |
| | | // 批量查 subtask_record,1次SQL替代循环中N次单独查 |
| | | List<Long> subtaskIds = serviceSubtaskList.stream().map(ServiceSubtaskRes::getId).filter(ObjectUtils::isNotEmpty).collect(Collectors.toList()); |
| | | Map<Long, List<ServiceSubtaskRecord>> recordMap = serviceSubtaskRecordService.selectRecordMapBySubtaskIds(subtaskIds); |
| | | |
| | | for (ServiceSubtaskRes serviceSubtask : serviceSubtaskList) { |
| | | serviceSubtask.setServiceSubtaskRecordList(recordMap.getOrDefault(serviceSubtask.getId(), new ArrayList<>())); |
| | | } |
| | | |
| | | // patItemCount 调用redisCache记录统计数据 |
| | | Map<String, Object> map = serviceSubtaskService.patItemCount(serviceSubtaskEntity); |
| | | // patItemCount 走Redis缓存版,避免每次全表聚合扫描 |
| | | Map<String, Object> map = getPatItemCountWithCache(serviceSubtaskEntity); |
| | | map.put("serviceSubtaskList", serviceSubtaskList); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | list.add(map); |
| | | |
| | | serviceSubtaskEntity.setPageNum(null); |
| | | serviceSubtaskEntity.setPageSize(null); |
| | | List<ServiceSubtaskRes> serviceSubtasks = serviceSubtaskService.patItem(serviceSubtaskEntity); |
| | | // 直接从已有聚合结果推算total,避免去掉分页后再全量查一遍大表 |
| | | long total = 0L; |
| | | try { |
| | | long wzx = map.get("wzx") != null ? ((Number) map.get("wzx")).longValue() : 0L; |
| | | long ysf = map.get("ysf") != null ? ((Number) map.get("ysf")).longValue() : 0L; |
| | | long dsf = map.get("dsf") != null ? ((Number) map.get("dsf")).longValue() : 0L; |
| | | long yc = map.get("yc") != null ? ((Number) map.get("yc")).longValue() : 0L; |
| | | long jg = map.get("jg") != null ? ((Number) map.get("jg")).longValue() : 0L; |
| | | long fssb = map.get("fssb") != null ? ((Number) map.get("fssb")).longValue() : 0L; |
| | | long yfs = map.get("yfs") != null ? ((Number) map.get("yfs")).longValue() : 0L; |
| | | long blq = map.get("blq") != null ? ((Number) map.get("blq")).longValue() : 0L; |
| | | total = wzx + ysf + dsf + yc + jg + fssb + yfs + blq; |
| | | } catch (Exception e) { |
| | | // 兜底:全量count |
| | | serviceSubtaskEntity.setPageNum(null); |
| | | serviceSubtaskEntity.setPageSize(null); |
| | | List<ServiceSubtask> serviceSubtasks = serviceSubtaskService.selectServiceSubtaskList(serviceSubtaskEntity); |
| | | total = CollectionUtils.isNotEmpty(serviceSubtasks) ? serviceSubtasks.size() : 0L; |
| | | } |
| | | |
| | | return getDataTable3(CollectionUtils.isNotEmpty(serviceSubtasks) ? serviceSubtasks.size() : 0L, list); |
| | | return getDataTable3(total, list); |
| | | } |
| | | |
| | | /** |
| | |
| | | ServiceSubtaskEntity serviceSubtaskEntity = DtoConversionUtils.sourceToTarget(serviceSubtaskVO, ServiceSubtaskEntity.class); |
| | | serviceSubtaskEntity.setContinueContent(ObjectUtils.isNotEmpty(serviceSubtaskVO.getContinueContent()) ? serviceSubtaskVO.getContinueContent().toString() : null); |
| | | |
| | | // 通过redis记录结果 |
| | | Map<String, Object> redisMap = new HashMap<>(); |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser user = null; |
| | | Long userId = null; |
| | | if (ObjectUtils.isNotEmpty(loginUser)) { |
| | | user = loginUser.getUser(); |
| | | if (ObjectUtils.isNotEmpty(user)) { |
| | | userId = user.getUserId(); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(loginUser) && ObjectUtils.isNotEmpty(loginUser.getUser())) { |
| | | userId = loginUser.getUser().getUserId(); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(userId)) { |
| | | redisMap = redisCache.getCacheObject(userId + "patItemCount"); |
| | | //记录是否有可用缓存 |
| | | map = getPatItemCountWithCache(serviceSubtaskEntity); |
| | | } |
| | | |
| | | map.put("code", HttpStatus.SUCCESS); |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 带Redis缓存的统计查询,供patItem和patItemCount共用,条件不变时直接命中缓存 |
| | | */ |
| | | private Map<String, Object> getPatItemCountWithCache(ServiceSubtaskEntity serviceSubtaskEntity) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | LoginUser loginUser = getLoginUser(); |
| | | Long userId = null; |
| | | if (ObjectUtils.isNotEmpty(loginUser) && ObjectUtils.isNotEmpty(loginUser.getUser())) { |
| | | userId = loginUser.getUser().getUserId(); |
| | | } |
| | | if (ObjectUtils.isNotEmpty(userId)) { |
| | | Map<String, Object> redisMap = redisCache.getCacheObject(userId + "patItemCount"); |
| | | Boolean redisFlag = false; |
| | | ServiceSubtaskEntity oldCondition = null; |
| | | if (MapUtils.isNotEmpty(redisMap)) { |
| | | oldCondition = (ServiceSubtaskEntity) redisMap.get("searchCondition"); |
| | | // 比较查询条件是否一致 |
| | | ServiceSubtaskEntity oldCondition = (ServiceSubtaskEntity) redisMap.get("searchCondition"); |
| | | if (ObjectUtils.isNotEmpty(oldCondition) && isSameCondition(oldCondition, serviceSubtaskEntity)) { |
| | | // 条件一致,使用缓存 |
| | | redisFlag = true; |
| | | map = redisMap; |
| | | redisCache.setCacheObject(userId + "patItemCount", map, 120, TimeUnit.MINUTES); |
| | | } |
| | | } |
| | | |
| | | // 如果没有缓存或者条件不一致,重新查询 |
| | | if (!redisFlag) { |
| | | map = serviceSubtaskService.patItemCount(serviceSubtaskEntity); |
| | | map.put("searchCondition", serviceSubtaskEntity); |
| | | redisCache.setCacheObject(userId + "patItemCount", map, 120, TimeUnit.MINUTES); |
| | | } |
| | | } else { |
| | | map = serviceSubtaskService.patItemCount(serviceSubtaskEntity); |
| | | } |
| | | |
| | | map.put("code", HttpStatus.SUCCESS); |
| | | return map; |
| | | } |
| | | |
| | |
| | | |
| | | /** |
| | | * 统计任务各种状态的数量(优化版) |
| | | * |
| | | * @return Map<String, Object> 包含各状态统计数据 |
| | | * pendingVisitCount: 当前登录人截止今日待随访总量 |
| | | * failedVisitCount: 当前登录人随访任务失败总量 |
| | | * abnormalVisitVount: 当前登录人随访任务异常总量 |
| | | * allVisitCount: 当前登录人随访任务总量 |
| | | * pendingVisitCount: 当前登录人截止今日待随访总量 |
| | | * failedVisitCount: 当前登录人随访任务失败总量 |
| | | * abnormalVisitVount: 当前登录人随访任务异常总量 |
| | | * allVisitCount: 当前登录人随访任务总量 |
| | | */ |
| | | @ApiOperation("获取当前用户随访数量统计") |
| | | @PostMapping("/getCurrentUserServiceSubtaskCount") |
| | |
| | | entity.setOrgid(sysUser.getOrgid()); |
| | | entity.setLeaveldeptcodes(deptCodes); |
| | | entity.setLeavehospitaldistrictcodes(wardCodes); |
| | | if(ObjectUtils.isNotEmpty(sysUser)){ |
| | | if(!("admin").equals(sysUser.getUserName())){ |
| | | if(ObjectUtils.isNotEmpty(sysUserWards) && ObjectUtils.isNotEmpty(sysUserDepts)){ |
| | | if (ObjectUtils.isNotEmpty(sysUser)) { |
| | | if (!("admin").equals(sysUser.getUserName())) { |
| | | if (ObjectUtils.isNotEmpty(sysUserWards) && ObjectUtils.isNotEmpty(sysUserDepts)) { |
| | | map = serviceSubtaskService.getCurrentUserServiceSubtaskCount(entity); |
| | | } |
| | | }else { |
| | | } else { |
| | | map = serviceSubtaskService.getCurrentUserServiceSubtaskCount(entity); |
| | | } |
| | | } |