From 7250797dc5f267b70e9725616343fd17ed227ca8 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期二, 01 四月 2025 18:05:19 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/boymi/YiFeiNN --- medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java | 298 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 257 insertions(+), 41 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 8faca33..99967a7 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 @@ -6,6 +6,7 @@ import com.sinata.common.core.domain.entity.SysDictData; import com.sinata.common.utils.CollUtils; import com.sinata.common.utils.DateUtils; +import com.sinata.system.config.AutoColumnWidthStrategy; import com.sinata.system.domain.MwCollectRecord; import com.sinata.system.domain.MwWarningRecord; import com.sinata.system.domain.SysDepartment; @@ -19,13 +20,12 @@ import com.sinata.system.domain.vo.MwMedicalWasteBoxVO; import com.sinata.system.domain.vo.SysDictDataVO; import com.sinata.system.domain.vo.TransformVO; -import com.sinata.system.enums.DepartmentEnum; -import com.sinata.system.enums.MedicalWasteStatusEnum; import com.sinata.system.service.ISysDictDataService; import com.sinata.system.service.MwCheckoutRecordService; import com.sinata.system.service.MwCollectRecordService; import com.sinata.system.service.MwDisposalHandleRecordService; import com.sinata.system.service.MwDisposalRecordService; +import com.sinata.system.service.MwMicroEquipmentRecordItemService; import com.sinata.system.service.MwWarningRecordService; import com.sinata.system.service.SysDepartmentService; import com.sinata.system.utils.ImageToBase64; @@ -60,6 +60,7 @@ private final HttpServletResponse response; private final MwDisposalRecordService mwDisposalRecordService; private final MwDisposalHandleRecordService mwDisposalHandleRecordService; + private final MwMicroEquipmentRecordItemService mwMicroEquipmentRecordItemService; @@ -82,8 +83,8 @@ } vo.setLegend(wasteTypeList.stream().map(SysDictDataVO::getDictLabel).collect(Collectors.toList())); vo.getLegend().add("小计"); - List<MwCollectRecord> collectRecordList = mwCollectRecordService.lambdaQuery().eq(query.getReportType().equals(1), MwCollectRecord::getStatus, MedicalWasteStatusEnum.TEMPORARILY_STORED.getCode()) - .ne(query.getReportType().equals(2), MwCollectRecord::getStatus, MedicalWasteStatusEnum.TEMPORARILY_STORED.getCode()) + List<MwCollectRecord> collectRecordList = mwCollectRecordService.lambdaQuery()/*.eq(query.getReportType().equals(1), MwCollectRecord::getStatus, MedicalWasteStatusEnum.TEMPORARILY_STORED.getCode()) + .ne(query.getReportType().equals(2), MwCollectRecord::getStatus, MedicalWasteStatusEnum.TEMPORARILY_STORED.getCode())*/ .eq(MwCollectRecord::getDepartmentId, query.getDepartmentId()) .between(query.getReportType().equals(1), MwCollectRecord::getCollectTime, query.getStartTime(), query.getEndTime()) .between(query.getReportType().equals(2), MwCollectRecord::getCheckoutTime, query.getStartTime(), query.getEndTime()) @@ -143,6 +144,60 @@ } list.add(itemVO); } + // 添加合计行 + if (!list.isEmpty()) { + DepartmentReportItemVO totalRow = new DepartmentReportItemVO(); + totalRow.setName("合计"); + totalRow.setData(new ArrayList<>()); + + // 计算各类型废物的数量和重量总计 + for (SysDictDataVO sysDictDataVO : wasteTypeList) { + BigDecimal totalTypeCount = BigDecimal.ZERO; + BigDecimal totalTypeWeight = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : list) { + // 每种废物类型占用两列(数量和重量) + int index = wasteTypeList.indexOf(sysDictDataVO); + int countIndex = index * 2; + int weightIndex = countIndex + 1; + + if (countIndex < item.getData().size()) { + totalTypeCount = totalTypeCount.add(item.getData().get(countIndex)); + } + if (weightIndex < item.getData().size()) { + totalTypeWeight = totalTypeWeight.add(item.getData().get(weightIndex)); + } + } + + totalRow.getData().add(totalTypeCount); + totalRow.getData().add(totalTypeWeight); + } + + // 计算总的数量和重量 + BigDecimal finalTotalCount = BigDecimal.ZERO; + BigDecimal finalTotalWeight = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : list) { + int totalCountIndex = item.getData().size() - 2; + int totalWeightIndex = item.getData().size() - 1; + + if (totalCountIndex >= 0 && totalWeightIndex >= 0) { + finalTotalCount = finalTotalCount.add(item.getData().get(totalCountIndex)); + finalTotalWeight = finalTotalWeight.add(item.getData().get(totalWeightIndex)); + } + } + + totalRow.getData().add(finalTotalCount); + totalRow.getData().add(finalTotalWeight); + + // 超时标记处理(如果有) + if (query.getDateType().equals(1)) { + totalRow.setOverTimeFlag("—"); // 合计行不显示超时标记 + } + + // 将合计行添加到列表开头 + list.add(0, totalRow); + } vo.setList(list); return vo; } @@ -166,6 +221,7 @@ FastExcel.write(response.getOutputStream()) .head(head) .autoCloseStream(Boolean.TRUE) + .registerWriteHandler(new AutoColumnWidthStrategy()) .sheet("医院报表") .doWrite(getHospitalReportStaticsData(query)); } @@ -225,40 +281,92 @@ vo.setDepartmentName(department.getDepartmentName()); } SysDepartment region = sysDepartmentService.getDepartmentByParentId(department.getParentId()); - List<SysDepartment> hospitalList = sysDepartmentService.lambdaQuery().likeRight(SysDepartment::getTreeCode, region.getTreeCode()).eq(SysDepartment::getOrgType, DepartmentEnum.MEDICAL_INSTITUTION.getCode()).list(); - if (CollUtils.isNotEmpty(hospitalList)) { - List<TransformVO> checkoutRecordVOList = mwCheckoutRecordService.getCheckoutRecordList(query, region.getTreeCode()); - if (CollUtils.isNotEmpty(checkoutRecordVOList)) { - //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, query.getWasteTypeCodeList()).list(); - if (CollUtils.isNotEmpty(wasteTypeList)) { - vo.setLegend(wasteTypeList.stream().map(SysDictData::getDictLabel).collect(Collectors.toList())); - vo.getLegend().add("小计"); - List<DepartmentReportItemVO> list = new ArrayList<>(); - for (TransformVO transformVO : checkoutRecordVOList) { - BigDecimal totalCount = BigDecimal.ZERO; - BigDecimal totalWeight = BigDecimal.ZERO; - DepartmentReportItemVO departmentReportItemVO = new DepartmentReportItemVO(); - departmentReportItemVO.setName(transformVO.getHospitalName()); - departmentReportItemVO.setData(new ArrayList<>()); - departmentReportItemVO.setDriverName(transformVO.getDriverName()); - departmentReportItemVO.setHospitalSignature(ImageToBase64.convertImageToBase64(transformVO.getHospitalSignature())); - departmentReportItemVO.setHandoverTime(transformVO.getCheckoutTime()); - for (SysDictData sysDictData : wasteTypeList) { - 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); - departmentReportItemVO.getData().add(weight); - totalCount = totalCount.add(count); - totalWeight = totalWeight.add(weight); - } - departmentReportItemVO.getData().add(totalCount); - departmentReportItemVO.getData().add(totalWeight); - list.add(departmentReportItemVO); - } - vo.setList(list); + //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())); + vo.getLegend().add("小计"); + + List<DepartmentReportItemVO> list = new ArrayList<>(); + + // 处理各医院数据 + for (TransformVO transformVO : checkoutRecordVOList) { + BigDecimal totalCount = BigDecimal.ZERO; + BigDecimal totalWeight = BigDecimal.ZERO; + DepartmentReportItemVO departmentReportItemVO = new DepartmentReportItemVO(); + departmentReportItemVO.setName(transformVO.getHospitalName()); + departmentReportItemVO.setData(new ArrayList<>()); + departmentReportItemVO.setDriverName(transformVO.getDriverName()); + departmentReportItemVO.setHospitalSignature(ImageToBase64.convertImageToBase64(transformVO.getHospitalSignature())); + departmentReportItemVO.setHandoverTime(transformVO.getCheckoutTime()); + for (SysDictData sysDictData : wasteTypeList) { + 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); + departmentReportItemVO.getData().add(weight); + totalCount = totalCount.add(count); + totalWeight = totalWeight.add(weight); } + departmentReportItemVO.getData().add(totalCount); + departmentReportItemVO.getData().add(totalWeight); + list.add(departmentReportItemVO); } + + // 添加合计行 + if (!list.isEmpty()) { + DepartmentReportItemVO totalRow = new DepartmentReportItemVO(); + totalRow.setName("合计"); + totalRow.setData(new ArrayList<>()); + + // 计算各类型废物的总数量和总重量 + for (SysDictData sysDictData : wasteTypeList) { + BigDecimal totalTypeCount = BigDecimal.ZERO; + BigDecimal totalTypeWeight = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : list) { + // 获取当前废物类型在数据列表中的索引位置 + int index = wasteTypeList.indexOf(sysDictData); + // 每个废物类型占两列(数量和重量) + int countIndex = index * 2; + int weightIndex = countIndex + 1; + + if (countIndex < item.getData().size()) { + totalTypeCount = totalTypeCount.add(item.getData().get(countIndex)); + } + if (weightIndex < item.getData().size()) { + totalTypeWeight = totalTypeWeight.add(item.getData().get(weightIndex)); + } + } + + totalRow.getData().add(totalTypeCount); + totalRow.getData().add(totalTypeWeight); + } + + // 计算总的数量和重量 + BigDecimal finalTotalCount = BigDecimal.ZERO; + BigDecimal finalTotalWeight = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : list) { + int totalCountIndex = item.getData().size() - 2; + int totalWeightIndex = item.getData().size() - 1; + + if (totalCountIndex >= 0 && totalWeightIndex >= 0) { + finalTotalCount = finalTotalCount.add(item.getData().get(totalCountIndex)); + finalTotalWeight = finalTotalWeight.add(item.getData().get(totalWeightIndex)); + } + } + + totalRow.getData().add(finalTotalCount); + totalRow.getData().add(finalTotalWeight); + + // 将合计行添加到列表开头 + list.add(0, totalRow); + } + + vo.setList(list); } return vo; } @@ -276,6 +384,7 @@ FastExcel.write(response.getOutputStream()) .head(head) .autoCloseStream(Boolean.TRUE) + .registerWriteHandler(new AutoColumnWidthStrategy()) .sheet("转运联单") .doWrite(getTransformReportStaticsData(query)); } @@ -314,7 +423,8 @@ */ private List<List<String>> transformReportHead(List<Long> wasteTypeCodeList) { //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList).list(); + List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList) + .orderByDesc(SysDictData::getDictCode).list(); List<List<String>> headTitles = Lists.newArrayList(); headTitles.add(Lists.newArrayList("医院名称", "医院名称")); wasteTypeList.forEach(item -> { @@ -359,7 +469,8 @@ } List<String> dateList = DateUtils.getDayBetween(query.getStartTime(), query.getEndTime(), query.getDateType()); //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, query.getWasteTypeCodeList()).list(); + 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()); vo.setLegend(legend); @@ -385,6 +496,47 @@ } list.add(departmentReportItemVO); } + + // 添加合计行 + if (!list.isEmpty()) { + DepartmentReportItemVO totalRow = new DepartmentReportItemVO(); + totalRow.setName("合计"); + totalRow.setData(new ArrayList<>()); + + // 计算各类型废物的接收总量 + for (SysDictData sysDictData : wasteTypeList) { + BigDecimal totalReceiveWeight = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : list) { + int index = wasteTypeList.indexOf(sysDictData); + if (index < item.getData().size()) { + totalReceiveWeight = totalReceiveWeight.add(item.getData().get(index)); + } + } + + totalRow.getData().add(totalReceiveWeight); + } + + // 计算各类型废物的处置总量 + for (SysDictData sysDictData : wasteTypeList) { + BigDecimal totalDisposalWeight = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : list) { + int index = wasteTypeList.indexOf(sysDictData); + // 处置量数据在接收量数据之后,所以索引需要加上wasteTypeList的大小 + int disposalIndex = wasteTypeList.size() + index; + if (disposalIndex < item.getData().size()) { + totalDisposalWeight = totalDisposalWeight.add(item.getData().get(disposalIndex)); + } + } + + totalRow.getData().add(totalDisposalWeight); + } + + // 将合计行添加到列表开头 + list.add(0, totalRow); + } + vo.setList(list); } return vo; @@ -409,6 +561,7 @@ FastExcel.write(response.getOutputStream()) .head(head) .autoCloseStream(Boolean.TRUE) + .registerWriteHandler(new AutoColumnWidthStrategy()) .sheet("处置报表") .doWrite(getDisposalReportStaticsData(query)); } @@ -443,7 +596,8 @@ */ private List<List<String>> disposalReportHead(List<Long> wasteTypeCodeList) { //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList).list(); + List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList) + .orderByDesc(SysDictData::getDictCode).list(); List<List<String>> headTitles = Lists.newArrayList(); headTitles.add(Lists.newArrayList("日期")); wasteTypeList.forEach(item -> { @@ -473,6 +627,8 @@ List<MwCollectRecordVO> checkoutRecordList = mwCheckoutRecordService.getRegulationReportList(query); //医废处置量 List<MwCollectRecordVO> disposalRecordList = mwDisposalRecordService.getRegulationReportList(query); + List<MwCollectRecordVO> microEquipmentRecordList = mwMicroEquipmentRecordItemService.getRegulationReportList(query); + disposalRecordList.addAll(microEquipmentRecordList); SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS); switch (query.getDateType()) { case 1: @@ -487,7 +643,8 @@ } List<String> dateList = DateUtils.getDayBetween(query.getStartTime(), query.getEndTime(), query.getDateType()); //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, query.getWasteTypeCodeList()).list(); + 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())); vo.setList(new ArrayList<>()); @@ -515,6 +672,63 @@ } list.add(departmentReportItemVO); } + + // 添加合计行 + if (!list.isEmpty()) { + DepartmentReportItemVO totalRow = new DepartmentReportItemVO(); + totalRow.setName("合计"); + totalRow.setData(new ArrayList<>()); + + // 计算各类型废物的产生总量 + for (SysDictData sysDictData : wasteTypeList) { + BigDecimal totalGeneratedWeight = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : list) { + int index = wasteTypeList.indexOf(sysDictData); + if (index < item.getData().size()) { + totalGeneratedWeight = totalGeneratedWeight.add(item.getData().get(index)); + } + } + + totalRow.getData().add(totalGeneratedWeight); + } + + // 计算各类型废物的转移总量 + for (SysDictData sysDictData : wasteTypeList) { + BigDecimal totalTransferWeight = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : list) { + int index = wasteTypeList.indexOf(sysDictData); + // 转移量数据在产生量数据之后,所以索引需要加上wasteTypeList的大小 + int transferIndex = wasteTypeList.size() + index; + if (transferIndex < item.getData().size()) { + totalTransferWeight = totalTransferWeight.add(item.getData().get(transferIndex)); + } + } + + totalRow.getData().add(totalTransferWeight); + } + + // 计算各类型废物的处置总量 + for (SysDictData sysDictData : wasteTypeList) { + BigDecimal totalDisposalWeight = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : list) { + int index = wasteTypeList.indexOf(sysDictData); + // 处置量数据在产生量和转移量数据之后,所以索引需要加上wasteTypeList的大小的2倍 + int disposalIndex = wasteTypeList.size() * 2 + index; + if (disposalIndex < item.getData().size()) { + totalDisposalWeight = totalDisposalWeight.add(item.getData().get(disposalIndex)); + } + } + + totalRow.getData().add(totalDisposalWeight); + } + + // 将合计行添加到列表开头 + list.add(0, totalRow); + } + vo.setList(list); } return vo; @@ -533,6 +747,7 @@ FastExcel.write(response.getOutputStream()) .head(head) .autoCloseStream(Boolean.TRUE) + .registerWriteHandler(new AutoColumnWidthStrategy()) .sheet("监管报表") .doWrite(getRegulationReportStaticsData(query)); } @@ -567,7 +782,8 @@ */ private List<List<String>> regulationReportHead(List<Long> wasteTypeCodeList) { //查询医废类型 - List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList).list(); + List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList) + .orderByDesc(SysDictData::getDictCode).list(); List<List<String>> headTitles = Lists.newArrayList(); headTitles.add(Lists.newArrayList("日期")); wasteTypeList.forEach(item -> { -- Gitblit v1.7.1