From c9d58304d2dcfe4271b7917909fc452e40821d52 Mon Sep 17 00:00:00 2001 From: chen <2710907404@qq.com> Date: Thu, 14 Nov 2024 15:29:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=201.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=80=BB=E8=BE=91=E4=B8=AD=E5=AF=B9=E4=BA=8E?= =?UTF-8?q?=E9=80=81=E7=BC=B4=E5=8D=95=E4=BD=8D=E7=9A=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E5=BD=93=E5=89=8D=E7=AB=AF=E4=BC=A0=E9=80=92=E7=9A=84?= =?UTF-8?q?orgId=E4=B8=8D=E4=B8=BA=E7=A9=BA=E6=97=B6=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=AD=90=E6=9C=BA=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../imr/service/CommonFeignService.java | 9 +++++ .../service/impl/CommonFeignServiceImpl.java | 19 ++++++++++ .../DrugHandingOverStatisticServiceImpl.java | 37 ++++++++++++------- 3 files changed, 52 insertions(+), 13 deletions(-) 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))