From 0184bf471382f9328df9bdd47acf451e4e2c5cb0 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期三, 11 六月 2025 13:57:37 +0800 Subject: [PATCH] 达梦数据库及数据库脚本 --- medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwMicroEquipmentRecordServiceImpl.java | 138 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 102 insertions(+), 36 deletions(-) diff --git a/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwMicroEquipmentRecordServiceImpl.java b/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwMicroEquipmentRecordServiceImpl.java index bd656d2..55e7046 100644 --- a/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwMicroEquipmentRecordServiceImpl.java +++ b/medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwMicroEquipmentRecordServiceImpl.java @@ -12,6 +12,8 @@ import com.sinata.common.utils.DateUtils; import com.sinata.common.utils.SecurityUtils; import com.sinata.common.utils.StringUtils; +import com.sinata.system.config.AutoColumnWidthEntityStrategy; +import com.sinata.system.config.AutoColumnWidthStrategy; import com.sinata.system.domain.MwCollectRecord; import com.sinata.system.domain.MwMicroEquipment; import com.sinata.system.domain.MwMicroEquipmentRecord; @@ -22,7 +24,6 @@ import com.sinata.system.domain.query.MwMicroEquipmentStaticsQuery; import com.sinata.system.domain.vo.DepartmentReportItemVO; import com.sinata.system.domain.vo.DepartmentReportVO; -import com.sinata.system.domain.vo.MwCollectRecordVO; import com.sinata.system.domain.vo.MwMicroEquipmentRecordVO; import com.sinata.system.domain.vo.MwMicroEquipmentStaticsTitleVO; import com.sinata.system.domain.vo.MwMicroEquipmentStaticsVO; @@ -89,6 +90,11 @@ public MwMicroEquipmentRecordVO detail(Long id) { MwMicroEquipmentRecordVO mwMicroEquipmentRecordVO = BeanUtils.copyBean(this.getById(id), MwMicroEquipmentRecordVO.class); if (Objects.nonNull(mwMicroEquipmentRecordVO)) { + MwMicroEquipment equipment = mwMicroEquipmentService.getById( + mwMicroEquipmentRecordVO.getEquipmentId()); + if (Objects.nonNull(equipment)) { + mwMicroEquipmentRecordVO.setEquipmentName(equipment.getEquipmentName()); + } mwMicroEquipmentRecordVO.setMedicalWasteList(mwStagingRoomService.queryMedicalWasteList(mwMicroEquipmentRecordVO.getId())); } return mwMicroEquipmentRecordVO; @@ -111,9 +117,11 @@ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setCharacterEncoding("utf-8"); // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 - String fileName = URLEncoder.encode("微波设备使用记录", "UTF-8").replaceAll("\\+", "%20"); + String fileName = URLEncoder.encode("小型微波设备使用记录", "UTF-8").replaceAll("\\+", "%20"); response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); - FastExcel.write(response.getOutputStream(), MwCollectRecordVO.class).sheet("微波设备使用记录").doWrite(list); + FastExcel.write(response.getOutputStream(), MwMicroEquipmentRecordVO.class) + .registerWriteHandler(new AutoColumnWidthEntityStrategy()) + .sheet("小型微波设备使用记录").doWrite(list); } /** @@ -209,8 +217,6 @@ vo.setLegend(wasteTypeList.stream().map(SysDictDataVO::getDictLabel).collect(Collectors.toList())); vo.getLegend().add("小计"); String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); - List<SysDictData> medicalWasteTypeList = sysDictDataService.lambdaQuery().eq(SysDictData::getDictType, "medical_waste_type").list(); - List<MwMicroEquipmentStaticsVO> staticsData = baseMapper.getStaticsData(query, treeCode); SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS); switch (query.getDateType()) { @@ -225,39 +231,88 @@ break; } List<String> dateList = DateUtils.getDayBetween(query.getStartTime(), query.getEndTime(), query.getDateType()); - if (CollUtils.isNotEmpty(staticsData)) { - List<DepartmentReportItemVO> result = new ArrayList<>(); - for (String date : dateList) { - DepartmentReportItemVO departmentReportItemVO = new DepartmentReportItemVO(); - departmentReportItemVO.setName(date); - departmentReportItemVO.setData(new ArrayList<>()); - SimpleDateFormat finalSdf = sdf; - BigDecimal totalWeight = BigDecimal.ZERO; - BigDecimal totalCount = BigDecimal.ZERO; - for (SysDictData sysDictData : medicalWasteTypeList) { - BigDecimal weight = staticsData.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) - && finalSdf.format(e.getUseTime()).equals(date) - ).map(MwMicroEquipmentStaticsVO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP); - long count = staticsData.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) - && finalSdf.format(e.getUseTime()).equals(date)).count(); - departmentReportItemVO.getData().add(weight); - departmentReportItemVO.getData().add(BigDecimal.valueOf(count)); - totalWeight = totalWeight.add(weight); - totalCount = totalCount.add(BigDecimal.valueOf(count)); - } - departmentReportItemVO.getData().add(totalWeight); - departmentReportItemVO.getData().add(totalCount); - result.add(departmentReportItemVO); + List<DepartmentReportItemVO> result = new ArrayList<>(); + for (String date : dateList) { + DepartmentReportItemVO departmentReportItemVO = new DepartmentReportItemVO(); + departmentReportItemVO.setName(date); + departmentReportItemVO.setData(new ArrayList<>()); + SimpleDateFormat finalSdf = sdf; + BigDecimal totalWeight = BigDecimal.ZERO; + BigDecimal totalCount = BigDecimal.ZERO; + for (SysDictDataVO sysDictData : wasteTypeList) { + BigDecimal weight = staticsData.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) + && finalSdf.format(e.getUseTime()).equals(date) + ).map(MwMicroEquipmentStaticsVO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP); + long count = staticsData.stream().filter(e -> e.getWasteType().equals(sysDictData.getDictCode()) + && finalSdf.format(e.getUseTime()).equals(date)).count(); + departmentReportItemVO.getData().add(BigDecimal.valueOf(count)); + departmentReportItemVO.getData().add(weight); + totalCount = totalCount.add(BigDecimal.valueOf(count)); + totalWeight = totalWeight.add(weight); } - vo.setList(result); + departmentReportItemVO.getData().add(totalCount); + departmentReportItemVO.getData().add(totalWeight); + result.add(departmentReportItemVO); } + + // 添加合计行 + if (!result.isEmpty()) { + DepartmentReportItemVO totalRow = new DepartmentReportItemVO(); + totalRow.setName("合计"); + totalRow.setData(new ArrayList<>()); + + // 计算各类型废物的重量和数量总计 + for (SysDictDataVO sysDictData : wasteTypeList) { + BigDecimal totalTypeWeight = BigDecimal.ZERO; + BigDecimal totalTypeCount = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : result) { + // 每种废物类型占用两列(重量和数量) + int index = wasteTypeList.indexOf(sysDictData); + int weightIndex = index * 2; + int countIndex = weightIndex + 1; + + if (weightIndex < item.getData().size()) { + totalTypeWeight = totalTypeWeight.add(item.getData().get(weightIndex)); + } + if (countIndex < item.getData().size()) { + totalTypeCount = totalTypeCount.add(item.getData().get(countIndex)); + } + } + + totalRow.getData().add(totalTypeWeight); + totalRow.getData().add(totalTypeCount); + } + + // 计算总的重量和数量 + BigDecimal finalTotalWeight = BigDecimal.ZERO; + BigDecimal finalTotalCount = BigDecimal.ZERO; + + for (DepartmentReportItemVO item : result) { + int totalWeightIndex = item.getData().size() - 2; + int totalCountIndex = item.getData().size() - 1; + + if (totalWeightIndex >= 0 && totalCountIndex >= 0) { + finalTotalWeight = finalTotalWeight.add(item.getData().get(totalWeightIndex)); + finalTotalCount = finalTotalCount.add(item.getData().get(totalCountIndex)); + } + } + + totalRow.getData().add(finalTotalWeight); + totalRow.getData().add(finalTotalCount); + + // 将合计行添加到列表开头 + result.add(0, totalRow); + } + + vo.setList(result); return vo; } @Override public void staticsExport(MwMicroEquipmentStaticsQuery query, HttpServletResponse response) throws IOException { - List<List<String>> head = head(); + List<List<String>> head = head(query); System.out.println(JSONObject.toJSONString(head)); // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); @@ -269,6 +324,7 @@ FastExcel.write(response.getOutputStream()) .head(head) .autoCloseStream(Boolean.TRUE) + .registerWriteHandler(new AutoColumnWidthStrategy()) .sheet("处置分析报表") .doWrite(getStaticsReportData(query)); } @@ -299,16 +355,26 @@ * * @return */ - private List<List<String>> head() { + private List<List<String>> head(MwMicroEquipmentStaticsQuery query) { List<SysDictData> medicalWasteTypeList = sysDictDataService.lambdaQuery().eq(SysDictData::getDictType, "medical_waste_type").list(); List<List<String>> headTitles = Lists.newArrayList(); - headTitles.add(Lists.newArrayList("日期")); + SysDepartment department = sysDepartmentService.getById(query.getDepartmentId()); + MwMicroEquipment microEquipment = mwMicroEquipmentService.getById(query.getEquipmentId()); + //修改代码判断department不为空才拼接 + String title = ""; + if (Objects.nonNull(department) && Objects.nonNull(microEquipment)) { + title = department.getDepartmentName() + microEquipment.getEquipmentName() + "处置报表"; + } else { + title = "处置报表"; + } + headTitles.add(Lists.newArrayList(title, "日期", "日期")); + String finalTitle = title; medicalWasteTypeList.forEach(item -> { - headTitles.add(Lists.newArrayList(item.getDictLabel(), "总重量(KG)")); - headTitles.add(Lists.newArrayList(item.getDictLabel(), "总数量")); + headTitles.add(Lists.newArrayList(finalTitle, item.getDictLabel(), "数量")); + headTitles.add(Lists.newArrayList(finalTitle, item.getDictLabel(), "总重量(kg)")); }); - headTitles.add(Lists.newArrayList("小计", "总重量(KG)")); - headTitles.add(Lists.newArrayList("小计", "总数量")); + headTitles.add(Lists.newArrayList(title, "小计", "数量")); + headTitles.add(Lists.newArrayList(title, "小计", "总重量(kg)")); return headTitles; } -- Gitblit v1.7.1