From 1fd9e721593f0d22d16cdbac6b341553b1168cf7 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期三, 02 四月 2025 20:49:44 +0800 Subject: [PATCH] bug修改 --- medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java | 176 ++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 103 insertions(+), 73 deletions(-) diff --git a/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java b/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java index 99967a7..6970076 100644 --- a/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java +++ b/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java @@ -3,9 +3,9 @@ import cn.idev.excel.FastExcel; import com.alibaba.fastjson2.JSONObject; import com.google.common.collect.Lists; -import com.sinata.common.core.domain.entity.SysDictData; import com.sinata.common.utils.CollUtils; import com.sinata.common.utils.DateUtils; +import com.sinata.common.utils.StringUtils; import com.sinata.system.config.AutoColumnWidthStrategy; import com.sinata.system.domain.MwCollectRecord; import com.sinata.system.domain.MwWarningRecord; @@ -115,13 +115,19 @@ BigDecimal currentCount = BigDecimal.ZERO; if (query.getReportType().equals(1)) { weight = collectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) - && finalSdf.format(e.getCollectTime()).equals(date)).map(MwCollectRecord::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, RoundingMode.HALF_UP); - long count = collectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && finalSdf.format(e.getCollectTime()).equals(date)).count(); + && finalSdf.format(e.getCollectTime()).equals(date)).map(MwCollectRecord::getWeight) + .reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, RoundingMode.HALF_UP); + long count = collectRecordList.stream() + .filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && finalSdf.format(e.getCollectTime()).equals(date)) + .count(); currentCount = BigDecimal.valueOf(count); } else { weight = collectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) - && finalSdf.format(e.getCheckoutTime()).equals(date)).map(MwCollectRecord::getWeight).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, RoundingMode.HALF_UP); - long count = collectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && finalSdf.format(e.getCheckoutTime()).equals(date)).count(); + && finalSdf.format(e.getCheckoutTime()).equals(date)).map(MwCollectRecord::getWeight) + .reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(2, RoundingMode.HALF_UP); + long count = collectRecordList.stream() + .filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && finalSdf.format(e.getCheckoutTime()).equals(date)) + .count(); currentCount = BigDecimal.valueOf(count); } itemVO.getData().add(currentCount); @@ -134,7 +140,8 @@ //查询预警记录判断是否超时 if (query.getDateType().equals(1)) { itemVO.setOverTimeFlag("否"); - List<Long> collectIdList = collectRecordList.stream().filter(e -> finalSdf.format(e.getCollectTime()).equals(date)).map(MwCollectRecord::getId).collect(Collectors.toList()); + List<Long> collectIdList = collectRecordList.stream().filter(e -> finalSdf.format(e.getCollectTime()).equals(date)) + .map(MwCollectRecord::getId).collect(Collectors.toList()); if (CollUtils.isNotEmpty(collectIdList)) { List<MwWarningRecord> warningRecordList = mwWarningRecordService.lambdaQuery().in(MwWarningRecord::getWarningTargetId, collectIdList).list(); if (CollUtils.isNotEmpty(warningRecordList)) { @@ -209,7 +216,7 @@ * @return */ public void hospitalReportExport(HospitalReportQuery query) throws IOException { - List<List<String>> head = hospitalReportHead(); + List<List<String>> head = hospitalReportHead(query.getDepartmentId()); System.out.println(JSONObject.toJSONString(head)); // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); @@ -255,16 +262,25 @@ * * @return */ - private List<List<String>> hospitalReportHead() { + private List<List<String>> hospitalReportHead(Long departmentId) { + SysDepartment department = sysDepartmentService.getById(departmentId); List<SysDictDataVO> wasteTypeList = sysDictDataService.medicalWasteTypeList(); List<List<String>> headTitles = Lists.newArrayList(); - headTitles.add(Lists.newArrayList("日期", "日期")); + String title = ""; + if (Objects.nonNull(department)) { + title = department.getDepartmentName() + "医废报表"; + } else { + title = "医废报表"; + } + headTitles.add(Lists.newArrayList(title, "日期", "日期")); + String finalTitle = title; wasteTypeList.forEach(item -> { - headTitles.add(Lists.newArrayList(item.getDictLabel(), "数量")); - headTitles.add(Lists.newArrayList(item.getDictLabel(), "重量(KG)")); + headTitles.add(Lists.newArrayList(finalTitle, item.getDictLabel(), "数量")); + headTitles.add(Lists.newArrayList(finalTitle, item.getDictLabel(), "重量(KG)")); }); - headTitles.add(Lists.newArrayList("小计", "数量")); - headTitles.add(Lists.newArrayList("小计", "重量(KG)")); + headTitles.add(Lists.newArrayList(title, "小计", "数量")); + headTitles.add(Lists.newArrayList(title, "小计", "重量(KG)")); + headTitles.add(Lists.newArrayList(title, "是否超时", "是否超时")); return headTitles; } @@ -284,10 +300,9 @@ //List<SysDepartment> hospitalList = sysDepartmentService.lambdaQuery().likeRight(SysDepartment::getTreeCode, region.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.MEDICAL_INSTITUTION.getCode()).list(); List<TransformVO> checkoutRecordVOList = mwCheckoutRecordService.getCheckoutRecordList(query, region.getTreeCode()); //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, query.getWasteTypeCodeList()) - .orderByDesc(SysDictData::getDictCode).list(); - if (CollUtils.isNotEmpty(wasteTypeList)) { - vo.setLegend(wasteTypeList.stream().map(SysDictData::getDictLabel).collect(Collectors.toList())); + List<SysDictDataVO> sysDictDataVOS = sysDictDataService.medicalWasteTypeListByDictCode(query.getWasteTypeCodeList()); + if (CollUtils.isNotEmpty(sysDictDataVOS)) { + vo.setLegend(sysDictDataVOS.stream().map(SysDictDataVO::getDictLabel).collect(Collectors.toList())); vo.getLegend().add("小计"); List<DepartmentReportItemVO> list = new ArrayList<>(); @@ -301,8 +316,9 @@ departmentReportItemVO.setData(new ArrayList<>()); departmentReportItemVO.setDriverName(transformVO.getDriverName()); departmentReportItemVO.setHospitalSignature(ImageToBase64.convertImageToBase64(transformVO.getHospitalSignature())); + departmentReportItemVO.setHospitalSignatureUrl(transformVO.getHospitalSignature()); departmentReportItemVO.setHandoverTime(transformVO.getCheckoutTime()); - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal count = BigDecimal.valueOf(transformVO.getCollectRecordList().stream().filter(item -> item.getWasteType().equals(sysDictData.getDictCode())).count()); BigDecimal weight = transformVO.getCollectRecordList().stream().filter(item -> item.getWasteType().equals(sysDictData.getDictCode())).map(MwMedicalWasteBoxVO::getTotalWeight).reduce(BigDecimal.ZERO, BigDecimal::add); departmentReportItemVO.getData().add(count); @@ -322,13 +338,13 @@ totalRow.setData(new ArrayList<>()); // 计算各类型废物的总数量和总重量 - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal totalTypeCount = BigDecimal.ZERO; BigDecimal totalTypeWeight = BigDecimal.ZERO; for (DepartmentReportItemVO item : list) { // 获取当前废物类型在数据列表中的索引位置 - int index = wasteTypeList.indexOf(sysDictData); + int index = sysDictDataVOS.indexOf(sysDictData); // 每个废物类型占两列(数量和重量) int countIndex = index * 2; int weightIndex = countIndex + 1; @@ -405,7 +421,7 @@ List<Object> data = new ArrayList<>(); data.add(departmentReportItemVO.getName()); data.addAll(departmentReportItemVO.getData()); - data.add(new URL(departmentReportItemVO.getHospitalSignature())); + data.add(StringUtils.isNotBlank(departmentReportItemVO.getHospitalSignatureUrl()) ? new URL(departmentReportItemVO.getHospitalSignatureUrl()) : ""); data.add(departmentReportItemVO.getDriverName()); data.add(departmentReportItemVO.getHandoverTime()); result.add(data); @@ -423,11 +439,10 @@ */ private List<List<String>> transformReportHead(List<Long> wasteTypeCodeList) { //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList) - .orderByDesc(SysDictData::getDictCode).list(); + List<SysDictDataVO> sysDictDataVOS = sysDictDataService.medicalWasteTypeListByDictCode(wasteTypeCodeList); List<List<String>> headTitles = Lists.newArrayList(); headTitles.add(Lists.newArrayList("医院名称", "医院名称")); - wasteTypeList.forEach(item -> { + sysDictDataVOS.forEach(item -> { headTitles.add(Lists.newArrayList(item.getDictLabel(), "数量")); headTitles.add(Lists.newArrayList(item.getDictLabel(), "重量(KG)")); }); @@ -469,10 +484,9 @@ } List<String> dateList = DateUtils.getDayBetween(query.getStartTime(), query.getEndTime(), query.getDateType()); //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, query.getWasteTypeCodeList()) - .orderByDesc(SysDictData::getDictCode).list(); - if (CollUtils.isNotEmpty(wasteTypeList)) { - List<String> legend = wasteTypeList.stream().map(SysDictData::getDictLabel).collect(Collectors.toList()); + List<SysDictDataVO> sysDictDataVOS = sysDictDataService.medicalWasteTypeListByDictCode(query.getWasteTypeCodeList()); + if (CollUtils.isNotEmpty(sysDictDataVOS)) { + List<String> legend = sysDictDataVOS.stream().map(SysDictDataVO::getDictLabel).collect(Collectors.toList()); vo.setLegend(legend); List<DepartmentReportItemVO> list = new ArrayList<>(); for (String date : dateList) { @@ -481,14 +495,14 @@ departmentReportItemVO.setData(new ArrayList<>()); SimpleDateFormat finalSdf = sdf; //接收 - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal totalWeight = receivedList.stream().filter(item -> item.getWasteType().equals(sysDictData.getDictCode()) && finalSdf.format(item.getReceiveTime()).equals(date)).map(MwDisposalRecordReportVO::getWeight) .reduce(BigDecimal.ZERO, BigDecimal::add); departmentReportItemVO.getData().add(totalWeight); } //处置 - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal totalWeight = disposaledList.stream().filter(item -> item.getWasteType().equals(sysDictData.getDictCode()) && finalSdf.format(item.getDisposalTime()).equals(date)).map(MwDisposalRecordReportVO::getWeight) .reduce(BigDecimal.ZERO, BigDecimal::add); @@ -504,11 +518,11 @@ totalRow.setData(new ArrayList<>()); // 计算各类型废物的接收总量 - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal totalReceiveWeight = BigDecimal.ZERO; for (DepartmentReportItemVO item : list) { - int index = wasteTypeList.indexOf(sysDictData); + int index = sysDictDataVOS.indexOf(sysDictData); if (index < item.getData().size()) { totalReceiveWeight = totalReceiveWeight.add(item.getData().get(index)); } @@ -518,13 +532,13 @@ } // 计算各类型废物的处置总量 - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal totalDisposalWeight = BigDecimal.ZERO; for (DepartmentReportItemVO item : list) { - int index = wasteTypeList.indexOf(sysDictData); - // 处置量数据在接收量数据之后,所以索引需要加上wasteTypeList的大小 - int disposalIndex = wasteTypeList.size() + index; + int index = sysDictDataVOS.indexOf(sysDictData); + // 处置量数据在接收量数据之后,所以索引需要加上sysDictDataVOS的大小 + int disposalIndex = sysDictDataVOS.size() + index; if (disposalIndex < item.getData().size()) { totalDisposalWeight = totalDisposalWeight.add(item.getData().get(disposalIndex)); } @@ -549,7 +563,7 @@ * @throws IOException */ public void disposalReportExport(DisposalReportQuery query) throws IOException { - List<List<String>> head = disposalReportHead(query.getWasteTypeCodeList()); + List<List<String>> head = disposalReportHead(query); System.out.println(JSONObject.toJSONString(head)); // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); @@ -591,20 +605,28 @@ /** * 处置报表表头 * - * @param wasteTypeCodeList + * @param query * @return */ - private List<List<String>> disposalReportHead(List<Long> wasteTypeCodeList) { + private List<List<String>> disposalReportHead(DisposalReportQuery query) { //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList) - .orderByDesc(SysDictData::getDictCode).list(); + List<SysDictDataVO> sysDictDataVOS = sysDictDataService.medicalWasteTypeListByDictCode(query.getWasteTypeCodeList()); + SysDepartment department = sysDepartmentService.getById(query.getDepartmentId()); + String title = ""; + if (Objects.nonNull(department)) { + title = department.getDepartmentName() + "处置报表"; + } else { + title = "处置报表"; + } List<List<String>> headTitles = Lists.newArrayList(); - headTitles.add(Lists.newArrayList("日期")); - wasteTypeList.forEach(item -> { - headTitles.add(Lists.newArrayList("医疗废物接收量(kg)", item.getDictLabel())); + headTitles.add(Lists.newArrayList(title, "日期", "日期")); + String finalTitle = title; + sysDictDataVOS.forEach(item -> { + headTitles.add(Lists.newArrayList(finalTitle, "医疗废物接收量(kg)", item.getDictLabel())); }); - wasteTypeList.forEach(item -> { - headTitles.add(Lists.newArrayList("医疗废物处置量(kg)", item.getDictLabel())); + String finalTitle1 = title; + sysDictDataVOS.forEach(item -> { + headTitles.add(Lists.newArrayList(finalTitle1, "医疗废物处置量(kg)", item.getDictLabel())); }); return headTitles; } @@ -643,10 +665,9 @@ } List<String> dateList = DateUtils.getDayBetween(query.getStartTime(), query.getEndTime(), query.getDateType()); //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, query.getWasteTypeCodeList()) - .orderByDesc(SysDictData::getDictCode).list(); - if (CollUtils.isNotEmpty(wasteTypeList)) { - vo.setLegend(wasteTypeList.stream().map(SysDictData::getDictLabel).collect(Collectors.toList())); + List<SysDictDataVO> sysDictDataVOS = sysDictDataService.medicalWasteTypeListByDictCode(query.getWasteTypeCodeList()); + if (CollUtils.isNotEmpty(sysDictDataVOS)) { + vo.setLegend(sysDictDataVOS.stream().map(SysDictDataVO::getDictLabel).collect(Collectors.toList())); vo.setList(new ArrayList<>()); List<DepartmentReportItemVO> list = new ArrayList<>(); for (String date : dateList) { @@ -654,18 +675,18 @@ departmentReportItemVO.setName(date); departmentReportItemVO.setData(new ArrayList<>()); SimpleDateFormat finalSdf = sdf; - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal weight = collectRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && finalSdf.format(e.getCollectTime()).equals(date)).map(MwCollectRecordVO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add); departmentReportItemVO.getData().add(weight); } - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal weight = checkoutRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && finalSdf.format(e.getCheckoutTime()).equals(date)).map(MwCollectRecordVO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add); departmentReportItemVO.getData().add(weight); } - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal weight = disposalRecordList.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) && finalSdf.format(e.getCollectTime()).equals(date)).map(MwCollectRecordVO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add); departmentReportItemVO.getData().add(weight); @@ -680,11 +701,11 @@ totalRow.setData(new ArrayList<>()); // 计算各类型废物的产生总量 - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal totalGeneratedWeight = BigDecimal.ZERO; for (DepartmentReportItemVO item : list) { - int index = wasteTypeList.indexOf(sysDictData); + int index = sysDictDataVOS.indexOf(sysDictData); if (index < item.getData().size()) { totalGeneratedWeight = totalGeneratedWeight.add(item.getData().get(index)); } @@ -694,13 +715,13 @@ } // 计算各类型废物的转移总量 - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal totalTransferWeight = BigDecimal.ZERO; for (DepartmentReportItemVO item : list) { - int index = wasteTypeList.indexOf(sysDictData); + int index = sysDictDataVOS.indexOf(sysDictData); // 转移量数据在产生量数据之后,所以索引需要加上wasteTypeList的大小 - int transferIndex = wasteTypeList.size() + index; + int transferIndex = sysDictDataVOS.size() + index; if (transferIndex < item.getData().size()) { totalTransferWeight = totalTransferWeight.add(item.getData().get(transferIndex)); } @@ -710,13 +731,13 @@ } // 计算各类型废物的处置总量 - for (SysDictData sysDictData : wasteTypeList) { + for (SysDictDataVO sysDictData : sysDictDataVOS) { BigDecimal totalDisposalWeight = BigDecimal.ZERO; for (DepartmentReportItemVO item : list) { - int index = wasteTypeList.indexOf(sysDictData); + int index = sysDictDataVOS.indexOf(sysDictData); // 处置量数据在产生量和转移量数据之后,所以索引需要加上wasteTypeList的大小的2倍 - int disposalIndex = wasteTypeList.size() * 2 + index; + int disposalIndex = sysDictDataVOS.size() * 2 + index; if (disposalIndex < item.getData().size()) { totalDisposalWeight = totalDisposalWeight.add(item.getData().get(disposalIndex)); } @@ -735,7 +756,7 @@ } public void regulationReportExport(DisposalReportQuery query) throws IOException { - List<List<String>> head = regulationReportHead(query.getWasteTypeCodeList()); + List<List<String>> head = regulationReportHead(query); System.out.println(JSONObject.toJSONString(head)); // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); @@ -777,23 +798,32 @@ /** * 监管报表表头 * - * @param wasteTypeCodeList + * @param query * @return */ - private List<List<String>> regulationReportHead(List<Long> wasteTypeCodeList) { + private List<List<String>> regulationReportHead(DisposalReportQuery query) { //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList) - .orderByDesc(SysDictData::getDictCode).list(); + List<SysDictDataVO> sysDictDataVOS = sysDictDataService.medicalWasteTypeListByDictCode(query.getWasteTypeCodeList()); + SysDepartment department = sysDepartmentService.getById(query.getDepartmentId()); + String title = ""; + if (Objects.nonNull(department)) { + title = department.getDepartmentName() + "监管报表"; + } else { + title = "监管报表"; + } List<List<String>> headTitles = Lists.newArrayList(); - headTitles.add(Lists.newArrayList("日期")); - wasteTypeList.forEach(item -> { - headTitles.add(Lists.newArrayList("医疗废物产生量(kg)", item.getDictLabel())); + headTitles.add(Lists.newArrayList(title, "日期", "日期")); + String finalTitle = title; + sysDictDataVOS.forEach(item -> { + headTitles.add(Lists.newArrayList(finalTitle, "医疗废物产生量(kg)", item.getDictLabel())); }); - wasteTypeList.forEach(item -> { - headTitles.add(Lists.newArrayList("医疗废物转移量(kg)", item.getDictLabel())); + String finalTitle1 = title; + sysDictDataVOS.forEach(item -> { + headTitles.add(Lists.newArrayList(finalTitle1, "医疗废物转移量(kg)", item.getDictLabel())); }); - wasteTypeList.forEach(item -> { - headTitles.add(Lists.newArrayList("医疗废物处置量(kg)", item.getDictLabel())); + String finalTitle2 = title; + sysDictDataVOS.forEach(item -> { + headTitles.add(Lists.newArrayList(finalTitle2, "医疗废物处置量(kg)", item.getDictLabel())); }); return headTitles; } -- Gitblit v1.7.1