luodangjia
2024-12-28 7dff38876f582644ae95daad8ac21d4f57088d56
medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java
New file
@@ -0,0 +1,578 @@
package com.sinata.system.service.biz;
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.system.domain.MedicalWasteStaticsVO;
import com.sinata.system.domain.MwCollectRecord;
import com.sinata.system.domain.MwWarningRecord;
import com.sinata.system.domain.SysDepartment;
import com.sinata.system.domain.query.DisposalReportQuery;
import com.sinata.system.domain.query.HospitalReportQuery;
import com.sinata.system.domain.query.TransformQuery;
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.MwDisposalRecordReportVO;
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.MwWarningRecordService;
import com.sinata.system.service.SysDepartmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
 * @author mitao
 * @date 2024/12/25
 */
@Service
@RequiredArgsConstructor
public class StaticsService {
    private final SysDepartmentService sysDepartmentService;
    private final MwCollectRecordService mwCollectRecordService;
    private final MwCheckoutRecordService mwCheckoutRecordService;
    private final ISysDictDataService sysDictDataService;
    private final MwWarningRecordService mwWarningRecordService;
    private final HttpServletResponse response;
    private final MwDisposalRecordService mwDisposalRecordService;
    private final MwDisposalHandleRecordService mwDisposalHandleRecordService;
    /**
     * 机构分布-获取机构列表
     *
     * @param type 1:全部 2:医院 3:处置单位
     * @return
     */
    public List<SysDepartment> departmentList(Integer type) {
        return sysDepartmentService.lambdaQuery().eq(type != 1, SysDepartment::getOrgType, type).list();
    }
    public MedicalWasteStaticsVO medicalWaste() {
        return null;
    }
    /**
     * 医院报表
     *
     * @param query
     * @return
     */
    public DepartmentReportVO hospitalReport(HospitalReportQuery query) {
        DepartmentReportVO vo = new DepartmentReportVO();
        List<SysDictDataVO> wasteTypeList = sysDictDataService.medicalWasteTypeList();
        if (CollUtils.isEmpty(wasteTypeList)) {
            return vo;
        }
        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())
                .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())
                .orderByDesc(MwCollectRecord::getCollectTime).list();
        SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS);
        switch (query.getDateType()) {
            case 1:
                sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD);
                break;
            case 2:
                sdf = new SimpleDateFormat(DateUtils.YYYY_MM);
                break;
            case 3:
                sdf = new SimpleDateFormat(DateUtils.YYYY);
                break;
        }
        List<String> dateList = DateUtils.getDayBetween(query.getStartTime(), query.getEndTime(), query.getDateType());
        List<DepartmentReportItemVO> list = new ArrayList<>();
        for (String date : dateList) {
            DepartmentReportItemVO itemVO = new DepartmentReportItemVO();
            itemVO.setName(date);
            itemVO.setData(new ArrayList<>());
            BigDecimal totalCount = BigDecimal.ZERO;
            BigDecimal totalWeight = BigDecimal.ZERO;
            SimpleDateFormat finalSdf = sdf;
            for (SysDictDataVO sysDictData : wasteTypeList) {
                BigDecimal weight = BigDecimal.ZERO;
                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();
                    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();
                    currentCount = BigDecimal.valueOf(count);
                }
                itemVO.getData().add(currentCount);
                itemVO.getData().add(weight);
                totalCount = totalCount.add(currentCount);
                totalWeight = totalWeight.add(weight);
            }
            //查询预警记录判断是否超时
            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<MwWarningRecord> warningRecordList = mwWarningRecordService.lambdaQuery().in(MwWarningRecord::getWarningTargetId, collectIdList).list();
                if (CollUtils.isNotEmpty(warningRecordList)) {
                    itemVO.setOverTimeFlag("是");
                }
            }
            list.add(itemVO);
        }
        vo.setList(list);
        return vo;
    }
    /**
     * 医院报表-导出
     *
     * @param query
     * @return
     */
    public void hospitalReportExport(HospitalReportQuery query) throws IOException {
        List<List<String>> head = hospitalReportHead();
        System.out.println(JSONObject.toJSONString(head));
        // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // 这里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())
                .head(head)
                .autoCloseStream(Boolean.TRUE)
                .sheet("医院报表")
                .doWrite(getHospitalReportStaticsData(query));
    }
    /**
     * 封装Excel导出数据
     *
     * @param query
     * @return
     */
    private List<List<Object>> getHospitalReportStaticsData(HospitalReportQuery query) {
        DepartmentReportVO vo = hospitalReport(query);
        if (CollUtils.isNotEmpty(vo.getList())) {
            List<List<Object>> result = new ArrayList<>();
            for (DepartmentReportItemVO departmentReportItemVO : vo.getList()) {
                List<Object> data = new ArrayList<>();
                data.add(departmentReportItemVO.getName());
                data.addAll(departmentReportItemVO.getData());
                if (query.getDateType().equals(1)) {
                    data.add(departmentReportItemVO.getOverTimeFlag());
                }
                result.add(data);
            }
            return result;
        }
        return CollUtils.emptyList();
    }
    /**
     * 医院报表表头
     *
     * @return
     */
    private List<List<String>> hospitalReportHead() {
        List<SysDictDataVO> wasteTypeList = sysDictDataService.medicalWasteTypeList();
        List<List<String>> headTitles = Lists.newArrayList();
        headTitles.add(Lists.newArrayList("日期", "日期"));
        wasteTypeList.forEach(item -> {
            headTitles.add(Lists.newArrayList(item.getDictLabel(), "数量"));
            headTitles.add(Lists.newArrayList(item.getDictLabel(), "重量(KG)"));
        });
        headTitles.add(Lists.newArrayList("小计", "数量"));
        headTitles.add(Lists.newArrayList("小计", "重量(KG)"));
        return headTitles;
    }
    /**
     * 转移联单
     *
     * @param query
     * @return
     */
    public DepartmentReportVO transformList(TransformQuery query) {
        DepartmentReportVO vo = new DepartmentReportVO();
        SysDepartment department = sysDepartmentService.getById(query.getDepartmentId());
        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("小计");
                    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(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);
                    }
                }
            }
        }
        return vo;
    }
    public void transformListExport(TransformQuery query) throws IOException {
        List<List<String>> head = transformReportHead(query.getWasteTypeCodeList());
        System.out.println(JSONObject.toJSONString(head));
        // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // 这里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())
                .head(head)
                .autoCloseStream(Boolean.TRUE)
                .sheet("转运联单")
                .doWrite(getTransformReportStaticsData(query));
    }
    /**
     * 转运联单导出数据
     *
     * @param query
     * @return
     * @throws MalformedURLException
     */
    private List<List<Object>> getTransformReportStaticsData(TransformQuery query) throws MalformedURLException {
        DepartmentReportVO vo = transformList(query);
        List<DepartmentReportItemVO> list = vo.getList();
        if (CollUtils.isNotEmpty(list)) {
            List<List<Object>> result = new ArrayList<>();
            for (DepartmentReportItemVO departmentReportItemVO : list) {
                List<Object> data = new ArrayList<>();
                data.add(departmentReportItemVO.getName());
                data.addAll(departmentReportItemVO.getData());
                data.add(new URL(departmentReportItemVO.getHospitalSignature()));
                data.add(departmentReportItemVO.getDriverName());
                data.add(departmentReportItemVO.getHandoverTime());
                result.add(data);
            }
            return result;
        }
        return CollUtils.emptyList();
    }
    /**
     * 转运联单导出表头
     *
     * @param wasteTypeCodeList
     * @return
     */
    private List<List<String>> transformReportHead(List<Long> wasteTypeCodeList) {
        //查询医废类型
        List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList).list();
        List<List<String>> headTitles = Lists.newArrayList();
        headTitles.add(Lists.newArrayList("医院名称", "医院名称"));
        wasteTypeList.forEach(item -> {
            headTitles.add(Lists.newArrayList(item.getDictLabel(), "数量"));
            headTitles.add(Lists.newArrayList(item.getDictLabel(), "重量(KG)"));
        });
        headTitles.add(Lists.newArrayList("小计", "数量"));
        headTitles.add(Lists.newArrayList("小计", "重量(KG)"));
        headTitles.add(Lists.newArrayList("机构人员签字", "机构人员签字"));
        headTitles.add(Lists.newArrayList("运输人员签字", "运输人员签字"));
        headTitles.add(Lists.newArrayList("交接时间", "交接时间"));
        return headTitles;
    }
    /**
     * 处置报表
     *
     * @param query
     * @return
     */
    public DepartmentReportVO disposalReport(DisposalReportQuery query) {
        DepartmentReportVO vo = new DepartmentReportVO();
        //已接收
        List<MwDisposalRecordReportVO> receivedList = mwDisposalRecordService.disposalReceiveReport(query);
        //已处置
        List<MwDisposalRecordReportVO> disposaledList = mwDisposalHandleRecordService.disposalReport(query);
        SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS);
        switch (query.getDateType()) {
            case 1:
                sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD);
                break;
            case 2:
                sdf = new SimpleDateFormat(DateUtils.YYYY_MM);
                break;
            case 3:
                sdf = new SimpleDateFormat(DateUtils.YYYY);
                break;
        }
        List<String> dateList = DateUtils.getDayBetween(query.getStartTime(), query.getEndTime(), query.getDateType());
        //查询医废类型
        List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, query.getWasteTypeCodeList()).list();
        if (CollUtils.isNotEmpty(wasteTypeList)) {
            List<String> legend = wasteTypeList.stream().map(SysDictData::getDictLabel).collect(Collectors.toList());
            vo.setLegend(legend);
            List<DepartmentReportItemVO> list = new ArrayList<>();
            for (String date : dateList) {
                DepartmentReportItemVO departmentReportItemVO = new DepartmentReportItemVO();
                departmentReportItemVO.setName(date);
                departmentReportItemVO.setData(new ArrayList<>());
                SimpleDateFormat finalSdf = sdf;
                //接收
                for (SysDictData sysDictData : wasteTypeList) {
                    departmentReportItemVO.getData().add(BigDecimal.ZERO);
                    if (CollUtils.isNotEmpty(receivedList)) {
                        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) {
                    departmentReportItemVO.getData().add(BigDecimal.ZERO);
                    if (CollUtils.isNotEmpty(disposaledList)) {
                        BigDecimal totalWeight = disposaledList.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);
                    }
                }
                list.add(departmentReportItemVO);
            }
            vo.setList(list);
        }
        return vo;
    }
    /**
     * 处置报表导出
     *
     * @param query
     * @throws IOException
     */
    public void disposalReportExport(DisposalReportQuery query) throws IOException {
        List<List<String>> head = disposalReportHead(query.getWasteTypeCodeList());
        System.out.println(JSONObject.toJSONString(head));
        // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // 这里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())
                .head(head)
                .autoCloseStream(Boolean.TRUE)
                .sheet("处置报表")
                .doWrite(getDisposalReportStaticsData(query));
    }
    /**
     * 处置报表统计数据
     *
     * @param query
     * @return
     */
    private List<List<Object>> getDisposalReportStaticsData(DisposalReportQuery query) {
        DepartmentReportVO vo = disposalReport(query);
        List<DepartmentReportItemVO> list = vo.getList();
        if (CollUtils.isNotEmpty(list)) {
            List<List<Object>> result = new ArrayList<>();
            for (DepartmentReportItemVO departmentReportItemVO : list) {
                List<Object> data = new ArrayList<>();
                data.add(departmentReportItemVO.getName());
                data.addAll(departmentReportItemVO.getData());
                result.add(data);
            }
            return result;
        }
        return CollUtils.emptyList();
    }
    /**
     * 处置报表表头
     *
     * @param wasteTypeCodeList
     * @return
     */
    private List<List<String>> disposalReportHead(List<Long> wasteTypeCodeList) {
        //查询医废类型
        List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList).list();
        List<List<String>> headTitles = Lists.newArrayList();
        headTitles.add(Lists.newArrayList("日期"));
        wasteTypeList.forEach(item -> {
            headTitles.add(Lists.newArrayList("医疗废物接收量(kg)", item.getDictLabel()));
        });
        wasteTypeList.forEach(item -> {
            headTitles.add(Lists.newArrayList("医疗废物处置量(kg)", item.getDictLabel()));
        });
        return headTitles;
    }
    /**
     * 监管报表
     *
     * @param query
     * @return
     */
    public DepartmentReportVO regulationReport(DisposalReportQuery query) {
        DepartmentReportVO vo = new DepartmentReportVO();
        //医废产生量
        List<MwCollectRecordVO> collectRecordList = mwCollectRecordService.getRegulationReportList(query);
        //医废转移量
        List<MwCollectRecordVO> checkoutRecordList = mwCheckoutRecordService.getRegulationReportList(query);
        //医废处置量
        List<MwCollectRecordVO> disposalRecordList = mwDisposalRecordService.getRegulationReportList(query);
        SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD_HH_MM_SS);
        switch (query.getDateType()) {
            case 1:
                sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD);
                break;
            case 2:
                sdf = new SimpleDateFormat(DateUtils.YYYY_MM);
                break;
            case 3:
                sdf = new SimpleDateFormat(DateUtils.YYYY);
                break;
        }
        List<String> dateList = DateUtils.getDayBetween(query.getStartTime(), query.getEndTime(), query.getDateType());
        //查询医废类型
        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.setList(new ArrayList<>());
            List<DepartmentReportItemVO> list = new ArrayList<>();
            for (String date : dateList) {
                DepartmentReportItemVO departmentReportItemVO = new DepartmentReportItemVO();
                departmentReportItemVO.setName(date);
                SimpleDateFormat finalSdf = sdf;
                for (SysDictData sysDictData : wasteTypeList) {
                    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) {
                    BigDecimal weight = checkoutRecordList.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) {
                    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);
                }
                list.add(departmentReportItemVO);
            }
            vo.setList(list);
        }
        return vo;
    }
    public void regulationReportExport(DisposalReportQuery query) throws IOException {
        List<List<String>> head = regulationReportHead(query.getWasteTypeCodeList());
        System.out.println(JSONObject.toJSONString(head));
        // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // 这里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())
                .head(head)
                .autoCloseStream(Boolean.TRUE)
                .sheet("监管报表")
                .doWrite(getRegulationReportStaticsData(query));
    }
    /**
     * 监管报表导出数据
     *
     * @param query
     * @return
     */
    private List<List<Object>> getRegulationReportStaticsData(DisposalReportQuery query) {
        DepartmentReportVO vo = regulationReport(query);
        List<DepartmentReportItemVO> list = vo.getList();
        if (CollUtils.isNotEmpty(list)) {
            List<List<Object>> result = new ArrayList<>();
            for (DepartmentReportItemVO departmentReportItemVO : list) {
                List<Object> data = new ArrayList<>();
                data.add(departmentReportItemVO.getName());
                data.addAll(departmentReportItemVO.getData());
                result.add(data);
            }
            return result;
        }
        return CollUtils.emptyList();
    }
    /**
     * 监管报表表头
     *
     * @param wasteTypeCodeList
     * @return
     */
    private List<List<String>> regulationReportHead(List<Long> wasteTypeCodeList) {
        //查询医废类型
        List<SysDictData> wasteTypeList = sysDictDataService.lambdaQuery().in(SysDictData::getDictCode, wasteTypeCodeList).list();
        List<List<String>> headTitles = Lists.newArrayList();
        headTitles.add(Lists.newArrayList("日期"));
        wasteTypeList.forEach(item -> {
            headTitles.add(Lists.newArrayList("医疗废物产生量(kg)", item.getDictLabel()));
        });
        wasteTypeList.forEach(item -> {
            headTitles.add(Lists.newArrayList("医疗废物转移量(kg)", item.getDictLabel()));
        });
        wasteTypeList.forEach(item -> {
            headTitles.add(Lists.newArrayList("医疗废物处置量(kg)", item.getDictLabel()));
        });
        return headTitles;
    }
}