| | |
| | | package com.ruoyi.web.controller.smartor; |
| | | |
| | | import com.github.pagehelper.ISelect; |
| | | import com.github.pagehelper.Page; |
| | | import com.ruoyi.common.annotation.AddOrgId; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.CacheConstants; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.HttpStatus; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.entity.SysUserDept; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.enums.PreachFormEnum; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.utils.reflect.ReflectUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.system.domain.SysConfig; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.system.service.ISysUserDeptService; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.domain.VO.ServiceSubtaskCotinueCountVO; |
| | | import com.smartor.domain.VO.ServiceSubtaskVO; |
| | | import com.smartor.domain.entity.ServiceSubtaskEntity; |
| | | import com.smartor.mapper.PatMedInhospMapper; |
| | | import com.smartor.mapper.PatMedOuthospMapper; |
| | | import com.smartor.service.IServiceSubtaskRecordService; |
| | | import com.smartor.service.IServiceSubtaskService; |
| | | import com.smartor.service.IServiceTaskService; |
| | | import com.smartor.service.impl.ServiceSubtaskServiceImpl; |
| | | import com.sun.org.apache.bcel.internal.generic.NEW; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import net.bytebuddy.implementation.bytecode.Throw; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | 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; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.web.bind.WebDataBinder; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.text.DecimalFormat; |
| | | import java.time.LocalDate; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @RestController |
| | | @RequestMapping("/smartor/serviceSubtask") |
| | | public class ServiceSubtaskController extends BaseController { |
| | | @InitBinder |
| | | public void initBinder(WebDataBinder binder) { |
| | | binder.setAutoGrowCollectionLimit(1024); // 或 2048、4096 等 |
| | | } |
| | | |
| | | @Autowired |
| | | private IServiceSubtaskService serviceSubtaskService; |
| | | |
| | | @Autowired |
| | | private IServiceTaskService serviceTaskService; |
| | | |
| | | @Autowired |
| | | private ISysUserDeptService sysUserDeptService; |
| | | |
| | | @Autowired |
| | | private IServiceSubtaskRecordService serviceSubtaskRecordService; |
| | |
| | | @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 { |
| | | total = map.get("total") != null ? ((Number) map.get("total")).longValue() : 0L; |
| | | |
| | | return getDataTable3(CollectionUtils.isNotEmpty(serviceSubtasks) ? serviceSubtasks.size() : 0L, list); |
| | | } 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(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; |
| | | } |
| | | |
| | |
| | | @Log(title = "单一任务(随访宣教)", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/patItemExport") |
| | | public void patItemExport(HttpServletResponse response, ServiceSubtaskEntity serviceSubtaskVO) { |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser user = loginUser.getUser(); |
| | | serviceSubtaskVO.setOrgid(user.getOrgid()); |
| | | List<ServiceSubtaskRes> serviceSubtaskList = null; |
| | | if (serviceSubtaskVO != null) { |
| | | if (serviceSubtaskVO.getPageNum() != null && serviceSubtaskVO.getPageSize() != null) |
| | | PageUtils.startPageByPost(serviceSubtaskVO.getPageNum(), serviceSubtaskVO.getPageSize()); |
| | | serviceSubtaskList = serviceSubtaskService.patItem(serviceSubtaskVO); |
| | | } |
| | | List<ServiceSubtaskExprot> serviceSubtaskExprots = null; |
| | | List<ServiceSubtaskExport> serviceSubtaskExports = null; |
| | | if (!CollectionUtils.isEmpty(serviceSubtaskList)) { |
| | | serviceSubtaskExprots = DtoConversionUtils.sourceToTarget(serviceSubtaskList, ServiceSubtaskExprot.class); |
| | | for (ServiceSubtaskExprot serviceSubtaskExprot : serviceSubtaskExprots) { |
| | | String pf = PreachFormEnum.getDescByCode(serviceSubtaskExprot.getPreachform()); |
| | | serviceSubtaskExprot.setPreachform(pf); |
| | | serviceSubtaskExports = DtoConversionUtils.sourceToTarget(serviceSubtaskList, ServiceSubtaskExport.class); |
| | | for (ServiceSubtaskExport serviceSubtaskExport : serviceSubtaskExports) { |
| | | String pf = PreachFormEnum.getDescByCode(serviceSubtaskExport.getPreachform()); |
| | | serviceSubtaskExport.setPreachform(pf); |
| | | |
| | | //计算出院天数 |
| | | if (!Objects.isNull(serviceSubtaskExport.getEndtime())) { |
| | | Integer endDay = DateUtils.differentDaysByMillisecond(serviceSubtaskExport.getEndtime(), new Date()); |
| | | serviceSubtaskExport.setEndDay(endDay); |
| | | } |
| | | } |
| | | |
| | | } |
| | | ExcelUtil<ServiceSubtaskExprot> util = new ExcelUtil<ServiceSubtaskExprot>(ServiceSubtaskExprot.class); |
| | | util.exportExcel(response, serviceSubtaskExprots, "患者随访信息表单"); |
| | | ExcelUtil<ServiceSubtaskExport> util = new ExcelUtil<ServiceSubtaskExport>(ServiceSubtaskExport.class); |
| | | util.exportExcel(response, serviceSubtaskExports, "患者随访信息表单"); |
| | | } |
| | | |
| | | |
| | |
| | | @PostMapping("/getSfStatisticsExport") |
| | | public void export(HttpServletResponse response, ServiceSubtaskCountReq serviceSubtaskCountReq) { |
| | | List<ServiceSubtaskStatistic> sfStatistics = serviceSubtaskService.getSfStatisticsExport(serviceSubtaskCountReq); |
| | | |
| | | ExcelUtil<ServiceSubtaskStatistic> util = new ExcelUtil<ServiceSubtaskStatistic>(ServiceSubtaskStatistic.class); |
| | | |
| | | String sheetName = ""; |
| | | String fileName = ""; |
| | | if (active.equals("ls") || active.equals("druid")) { |
| | |
| | | } |
| | | return success(serviceSubtaskService.getSfStatisticsJoydetails(serviceSubtaskCountReq)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 延续护理统计 |
| | | */ |
| | | @ApiOperation("延续护理统计") |
| | | @AddOrgId(field = "orgid", paramIndex = 0, campusField = "campusid") |
| | | @PostMapping("/getContinueNerseCount") |
| | | public AjaxResult getContinueNerseCount(@RequestBody ServiceSubtaskCotinueCountVO serviceSubtaskCotinueCountVO) { |
| | | SysUser user = getLoginUser().getUser(); |
| | | serviceSubtaskCotinueCountVO.setOrgid(user.getOrgid()); |
| | | serviceSubtaskCotinueCountVO.setCampusid(user.getCampusid()); |
| | | boolean hasDistrict = !CollectionUtils.isEmpty(serviceSubtaskCotinueCountVO.getLeavehospitaldistrictcodes()); |
| | | boolean hasDept = !CollectionUtils.isEmpty(serviceSubtaskCotinueCountVO.getDeptcodes()); |
| | | if (hasDistrict && hasDept) { |
| | | return error("病区Code集合与科室Code集合互斥,不能同时传入"); |
| | | } |
| | | return success(serviceSubtaskService.getContinueNurseCount(serviceSubtaskCotinueCountVO)); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取随访分类统计明细 |
| | |
| | | |
| | | /** |
| | | * 统计任务各种状态的数量(优化版) |
| | | * |
| | | * @return Map<String, Object> 包含各状态统计数据 |
| | | * pendingVisitCount: 当前登录人截止今日待随访总量 |
| | | * failedVisitCount: 当前登录人随访任务失败总量 |
| | | * abnormalVisitVount: 当前登录人随访任务异常总量 |
| | | * allVisitCount: 当前登录人随访任务总量 |
| | | * pendingVisitCount: 当前登录人截止今日待随访总量 |
| | | * failedVisitCount: 当前登录人随访任务失败总量 |
| | | * abnormalVisitVount: 当前登录人随访任务异常总量 |
| | | * allVisitCount: 当前登录人随访任务总量 |
| | | */ |
| | | @ApiOperation("获取当前用户随访数量统计") |
| | | @PostMapping("/getCurrentUserServiceSubtaskCount") |
| | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser sysUser = loginUser.getUser(); |
| | | SysUserDept sysUserDept = new SysUserDept(); |
| | | sysUserDept.setUserId(sysUser.getUserId()); |
| | | sysUserDept.setOrgid(sysUser.getOrgid()); |
| | | sysUserDept.setDeptType("1"); |
| | | List<SysUserDept> sysUserDepts = sysUserDeptService.selectSysUserDeptList(sysUserDept); |
| | | SysUserDept sysUserWard = new SysUserDept(); |
| | | sysUserWard.setUserId(sysUser.getUserId()); |
| | | sysUserWard.setOrgid(sysUser.getOrgid()); |
| | | sysUserWard.setDeptType("2"); |
| | | List<SysUserDept> sysUserWards = sysUserDeptService.selectSysUserDeptList(sysUserWard); |
| | | List<String> deptCodes = sysUserDepts.stream().map(SysUserDept::getDeptCode).collect(Collectors.toList()); |
| | | List<String> wardCodes = sysUserWards.stream().map(SysUserDept::getDeptCode).collect(Collectors.toList()); |
| | | ServiceSubtaskEntity entity = new ServiceSubtaskEntity(); |
| | | entity.setOrgid(sysUser.getOrgid()); |
| | | entity.setLeaveldeptcodes(deptCodes); |
| | | entity.setLeavehospitaldistrictcodes(wardCodes); |
| | | if (ObjectUtils.isNotEmpty(sysUser)) { |
| | | List<String> deptCodes = sysUser.getDeptCodes(); |
| | | List<String> wardCodes = sysUser.getWardCodes(); |
| | | ServiceSubtaskEntity entity = new ServiceSubtaskEntity(); |
| | | entity.setOrgid(sysUser.getOrgid()); |
| | | entity.setDeptcode(sysUser.getDeptCode()); |
| | | entity.setLeaveldeptcodes(deptCodes); |
| | | entity.setLeavehospitaldistrictcodes(wardCodes); |
| | | map = serviceSubtaskService.getCurrentUserServiceSubtaskCount(entity); |
| | | if (!("admin").equals(sysUser.getUserName())) { |
| | | if (ObjectUtils.isNotEmpty(sysUserWards) && ObjectUtils.isNotEmpty(sysUserDepts)) { |
| | | map = serviceSubtaskService.getCurrentUserServiceSubtaskCount(entity); |
| | | } |
| | | } else { |
| | | map = serviceSubtaskService.getCurrentUserServiceSubtaskCount(entity); |
| | | } |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | |
| | | } |