mitao
2025-04-02 2f3d3fb97bd4ebdc00c40a2774465c8b3487b6d1
medicalWaste-system/src/main/java/com/sinata/system/service/impl/MwMicroEquipmentRecordServiceImpl.java
@@ -12,6 +12,7 @@
import com.sinata.common.utils.DateUtils;
import com.sinata.common.utils.SecurityUtils;
import com.sinata.common.utils.StringUtils;
import com.sinata.system.config.AutoColumnWidthStrategy;
import com.sinata.system.domain.MwCollectRecord;
import com.sinata.system.domain.MwMicroEquipment;
import com.sinata.system.domain.MwMicroEquipmentRecord;
@@ -118,7 +119,9 @@
        // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
        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(), MwCollectRecordVO.class)
                .registerWriteHandler(new AutoColumnWidthStrategy())
                .sheet("微波设备使用记录").doWrite(list);
    }
    /**
@@ -214,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").orderByDesc(SysDictData::getDictCode).list();
        List<MwMicroEquipmentStaticsVO> staticsData = baseMapper.getStaticsData(query, treeCode);
        SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS);
        switch (query.getDateType()) {
@@ -238,7 +239,7 @@
            SimpleDateFormat finalSdf = sdf;
            BigDecimal totalWeight = BigDecimal.ZERO;
            BigDecimal totalCount = BigDecimal.ZERO;
            for (SysDictData sysDictData : medicalWasteTypeList) {
            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);
@@ -253,6 +254,57 @@
            departmentReportItemVO.getData().add(totalCount);
            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;
    }
@@ -272,6 +324,7 @@
        FastExcel.write(response.getOutputStream())
                .head(head)
                .autoCloseStream(Boolean.TRUE)
                .registerWriteHandler(new AutoColumnWidthStrategy())
                .sheet("处置分析报表")
                .doWrite(getStaticsReportData(query));
    }