diff --git a/src/main/java/digital/laboratory/platform/imr/service/CommonFeignService.java b/src/main/java/digital/laboratory/platform/imr/service/CommonFeignService.java index 944e928..4eaa478 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/CommonFeignService.java +++ b/src/main/java/digital/laboratory/platform/imr/service/CommonFeignService.java @@ -22,6 +22,15 @@ public interface CommonFeignService { */ SysOrg remoteGetSysOrg(String orgId); + /** + * 根据机构id远程获取系统子机构信息 + * + * @param orgId 用户信息 + * @return 对应的远程系统机构信息 + * @throws RuntimeException 如果未找到对应的机构信息,则抛出运行时异常 + */ + List remoteGetSysOrgByParentId(String orgId); + /** * 远程调用获取用户信息 * @param username diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/CommonFeignServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/CommonFeignServiceImpl.java index 882a318..214d11b 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/impl/CommonFeignServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/CommonFeignServiceImpl.java @@ -70,6 +70,25 @@ public class CommonFeignServiceImpl implements CommonFeignService { return sysOrg; } + /** + * 根据机构id远程获取系统子机构信息 + * + * @param orgId 用户信息 + * @return 对应的远程系统机构信息 + * @throws RuntimeException 如果未找到对应的机构信息,则抛出运行时异常 + */ + @Override + public List remoteGetSysOrgByParentId(String orgId) { + SysOrg sysOrg = new SysOrg(); + sysOrg.setParentId(orgId); + R> r = remoteOrgService.innerGetOrgList(sysOrg); + if (r != null && r.getCode() == CommonConstants.SUCCESS) { + return r.getData(); + } else { + throw new RuntimeException(String.format("没有找到 orgId 为 %s 的机构, 请确认用户所属机构的正确性!", orgId)); + } + } + /** * 远程调用或者用户信息 * @param username diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/DrugHandingOverStatisticServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/DrugHandingOverStatisticServiceImpl.java index 82a15ca..86f5bd3 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/impl/DrugHandingOverStatisticServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/DrugHandingOverStatisticServiceImpl.java @@ -1,6 +1,7 @@ package digital.laboratory.platform.imr.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import digital.laboratory.platform.imr.component.DateUtils; import digital.laboratory.platform.imr.entity.DrugCaseInfo; @@ -21,8 +22,10 @@ import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -65,15 +68,22 @@ public class DrugHandingOverStatisticServiceImpl implements DrugHandingOverStati List orgNameList = new ArrayList<>(); List dataList = new ArrayList<>(); + // 存储机构的map + Map sysOrgMap = new HashMap<>(); // 根据案件表取所有的送缴单位 - List drugCaseInfoList = drugCaseInfoService.list(); - Map sysOrgMap = drugCaseInfoList.stream() - .collect(Collectors.toMap( - DrugCaseInfo::getHandingOverOrg, - drugCaseInfo -> commonFeignService.remoteGetSysOrg(drugCaseInfo.getHandingOverOrg()), - (existing, replacement) -> existing - ) - ); + if (StrUtil.isBlank(query.getOrgId())) { + List drugCaseInfoList = drugCaseInfoService.list(); + sysOrgMap = drugCaseInfoList.stream() + .collect(Collectors.toMap( + DrugCaseInfo::getHandingOverOrg, + drugCaseInfo -> commonFeignService.remoteGetSysOrg(drugCaseInfo.getHandingOverOrg()), + (existing, replacement) -> existing + ) + ); + } else { + List sysOrgList = commonFeignService.remoteGetSysOrgByParentId(query.getOrgId()); + sysOrgMap = sysOrgList.stream().collect(Collectors.toMap(SysOrg::getOrgId, Function.identity())); + } // 根据时间点获取检材 List drugMaterialInfoVOList = drugMaterialInfoMapper.getDrugMaterialVO( Wrappers.query() @@ -112,23 +122,23 @@ public class DrugHandingOverStatisticServiceImpl implements DrugHandingOverStati // 默认统计 一年内的 LocalDate currentDate = LocalDate.now(); for (int i = 11; i >= 0; i--) { - fillLineChartData(monthsList, dataList, dateTimeFormatter, currentDate, i); + fillLineChartData(monthsList, dataList, dateTimeFormatter, currentDate, query.getOrgId(), i); } } else if (startDate != null && endDate != null) { // 计算查询开始时间和接受时间相差的月份数量 long between = ChronoUnit.MONTHS.between(startDate, endDate); for (int i = (int) (between -1); i >= 0; i--) { - fillLineChartData(monthsList, dataList, dateTimeFormatter, startDate, i); + fillLineChartData(monthsList, dataList, dateTimeFormatter, startDate, query.getOrgId(), i); } } else if (startDate == null && endDate != null) { // 只返回1年内的数据 for (int i = 11; i >= 0; i--) { - fillLineChartData(monthsList, dataList, dateTimeFormatter, endDate, i); + fillLineChartData(monthsList, dataList, dateTimeFormatter, endDate, query.getOrgId(), i); } } else { // 只返回1年内的数据 for (int i = 11; i >= 0; i--) { - fillLineChartData(monthsList, dataList, dateTimeFormatter, startDate.minusMonths(11), i); + fillLineChartData(monthsList, dataList, dateTimeFormatter, startDate.minusMonths(11), query.getOrgId(), i); } } lineChartData.add(monthsList); @@ -145,12 +155,13 @@ public class DrugHandingOverStatisticServiceImpl implements DrugHandingOverStati * @param startDate 起始日期 * @param i 月份偏移量 */ - private void fillLineChartData(List monthsList, List dataList, DateTimeFormatter dateTimeFormatter, LocalDate startDate, int i) { + private void fillLineChartData(List monthsList, List dataList, DateTimeFormatter dateTimeFormatter, LocalDate startDate, String orgId, int i) { LocalDate localDate = startDate.minusMonths(i); LocalDate withDayOfMonth = localDate.withDayOfMonth(1); dataList.add( drugMaterialInfoMapper.getDrugMaterialVO( Wrappers.query() + .eq(StrUtil.isNotBlank(orgId), "dc.handing_over_org", orgId) .ge("dc.handing_over_date", withDayOfMonth.atStartOfDay()) .le("dc.handing_over_date", withDayOfMonth.plusMonths(1).minusDays(1).atTime(LocalTime.MAX))