package com.ningdatech.carapi.report.manage;

import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.function.VUtils;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.basic.util.NdDateUtils;
import com.ningdatech.basic.util.StrPool;
import com.ningdatech.carapi.car.vehicle.contants.VehicleContant;
import com.ningdatech.carapi.common.aop.BuildChildrenRegionWrapper;
import com.ningdatech.carapi.common.constant.UserRoleTypeEnum;
import com.ningdatech.carapi.common.contants.DefValConstants;
import com.ningdatech.carapi.common.helper.UserInfoHelper;
import com.ningdatech.carapi.common.util.ExcelDownUtil;
import com.ningdatech.carapi.datascope.aop.LambdaDataScope;
import com.ningdatech.carapi.datascope.contants.LambdaDataScopeTypeEnum;
import com.ningdatech.carapi.report.constant.DataUploadAuditStatusEnum;
import com.ningdatech.carapi.report.constant.DataUploadAuditTypeEnum;
import com.ningdatech.carapi.report.constant.QueryTypeEnum;
import com.ningdatech.carapi.report.constant.UploadDataTypeEnum;
import com.ningdatech.carapi.report.constants.ReportConstant;
import com.ningdatech.carapi.report.model.dto.*;
import com.ningdatech.carapi.report.model.entity.*;
import com.ningdatech.carapi.report.model.po.ReqDataAuditPO;
import com.ningdatech.carapi.report.model.po.ReqDataQueryModifyPO;
import com.ningdatech.carapi.report.model.po.ReqDataUploadDetailPO;
import com.ningdatech.carapi.report.model.po.ReqDataUploadListPO;
import com.ningdatech.carapi.report.model.vo.*;
import com.ningdatech.carapi.report.service.*;
import com.ningdatech.carapi.sys.entity.dto.CompanyDTO;
import com.ningdatech.carapi.sys.entity.dto.RegionDTO;
import com.ningdatech.carapi.sys.helper.CompaniesCacheHelper;
import com.ningdatech.carapi.sys.helper.RegionsCacheHelper;
import com.ningdatech.carapi.user.security.auth.model.UserInfoDetails;
import com.ningdatech.carapi.user.util.LoginUserUtil;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.poi.excel.ExcelUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author CMM
 * @since 2023/09/28 11:15
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class BulkCementDirectSystemManage {

    private final IBulkCementDirectReportSystemAuditRecordService auditRecordService;
    private final IBulkCementDirectReportSystemAuditInfoService auditInfoService;
    private final IBulkCementSupplyBulletinService bulkCementSupplyBulletinService;
    private final RegionsCacheHelper regionsCacheHelper;
    private final IBulkCementDirectReportSystemDataRelevanceService dataRelevanceService;
    private final IBulkCementDirectReportSystemUniversalIndexService universalIndexService;
    private final CompaniesCacheHelper companiesCacheHelper;
    private final IBulkCementTransferBulletinService bulkCementTransferBulletinService;
    private final IBulkCementThreeCityUsageBulletinService bulkCementThreeCityUsageBulletinService;
    private final IConcreteSupplyBulletinService concreteSupplyBulletinService;
    private final IMortarSupplyBulletinService mortarSupplyBulletinService;
    private final INonProhibitedAreasBulkCementSalesUseService nonProhibitedAreasBulkCementSalesUseService;
    private final IBulkCementLogisticFacilityStatisticAnnualReportService bulkCementLogFacStaAnnualReportService;
    private final IMaterialLogisticEquipmentStatisticAnnualReportService materialLogEquipStaAnnualReportService;
    private final UserInfoHelper userInfoHelper;

    public PageVo<ResDataUploadListVO> dataAuditList(ReqDataUploadListPO req) {

        UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();

        Page<BulkCementDirectReportSystemAuditRecord> page = req.page();
        // 根据所属区域和登录用户角色查出对应的散装水泥供应量数据审核记录
        LambdaQueryWrapper<BulkCementDirectReportSystemAuditRecord> wrapper = Wrappers.lambdaQuery(BulkCementDirectReportSystemAuditRecord.class);
        BulkCementDirectSystemManage context = (BulkCementDirectSystemManage) AopContext.currentProxy();
        context.buildDataAuditListQuery(wrapper, req);
        auditRecordService.page(page,wrapper);
        List<BulkCementDirectReportSystemAuditRecord> records = page.getRecords();
        if (CollUtil.isEmpty(records)){
            return PageVo.empty();
        }
        // 获取审核信息
        List<Long> auditInfoIdList = records.stream().map(BulkCementDirectReportSystemAuditRecord::getAuditInfoId).collect(Collectors.toList());
        VUtils.isTrue(CollUtil.isEmpty(auditInfoIdList)).throwMessage("审核信息不存在!");
        Map<Long, BulkCementDirectReportSystemAuditInfo> auditInfoMap = auditInfoService.list(Wrappers.lambdaQuery(BulkCementDirectReportSystemAuditInfo.class)
                .in(BulkCementDirectReportSystemAuditInfo::getId, auditInfoIdList))
                .stream().collect(Collectors.toMap(BulkCementDirectReportSystemAuditInfo::getId, v -> v));
        Map<Long, BulkCementDirectReportSystemDataRelevance> dataRelevanceMap = dataRelevanceService.list(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class))
                .stream().collect(Collectors.toMap(BulkCementDirectReportSystemDataRelevance::getId, v -> v));
        List<ResDataUploadListVO> resVos = records.stream().map(r -> {
            ResDataUploadListVO vo = new ResDataUploadListVO();
            LocalDateTime month = r.getReportMonth();
            if (Objects.nonNull(month)) {
                String reportMonthStr = NdDateUtils.format(month, NdDateUtils.DEFAULT_MONTH_FORMAT);
                LocalDateTime reportMonth = LocalDateTimeUtil.parse(reportMonthStr, DateTimeFormatter.ofPattern(DatePattern.NORM_MONTH_PATTERN));
                vo.setReportMonth(reportMonth);
            }
            vo.setReportYear(r.getReportYear());
            vo.setRegionId(r.getRegionId());
            RegionDTO regionDto = regionsCacheHelper.getByRegionId(r.getRegionId());
            vo.setRegionName(regionDto.getRegionName());
            vo.setAuditDataId(r.getAuditDataId());

            // 如果登录用户是市散办
            if (UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId())){
                List<Long> auditDataIdList = Lists.newArrayList();
                auditDataIdList.add(r.getAuditDataId());
                vo.setAuditDataIdList(auditDataIdList);
            }
            // 如果登录用户是省散办
            else if (UserRoleTypeEnum.SYSTEM_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId()) ||
                    UserRoleTypeEnum.SYSTEM_ROLE_ID.getId().equals(userDetail.getRoleId())) {
                Long relevanceId = r.getAuditDataId();
                Map<Long, List<Long>> auditDataIdListMap = MapUtil.newHashMap();
                BulkCementDirectReportSystemDataRelevance dataRelevance = dataRelevanceMap.get(relevanceId);
                if (Objects.nonNull(dataRelevance) && StringUtils.isNotBlank(dataRelevance.getAuditDataIdList())){
                    String auditDataIdList = dataRelevance.getAuditDataIdList();
                    List<Long> idList = Arrays.stream(auditDataIdList.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                    auditDataIdListMap.put(relevanceId,idList);
                    vo.setAuditDataIdListMap(auditDataIdListMap);
                }
            }
            BulkCementDirectReportSystemAuditInfo auditInfo = auditInfoMap.get(r.getAuditInfoId());
            if (Objects.nonNull(auditInfo)) {
                vo.setAuditInfoId(auditInfo.getId());
                vo.setAuditOpinion(auditInfo.getAuditOpinion());
                vo.setAuditTime(auditInfo.getAuditTime());
                vo.setAuditStatus(r.getAuditStatus());
                String desc = DataUploadAuditStatusEnum.getDescByCode(r.getAuditStatus());
                vo.setAuditStatusName(desc);
            }
            vo.setSubmitTime(r.getCreateOn());
            vo.setAuditRecordId(r.getId());
            return vo;
        }).collect(Collectors.toList());
        return PageVo.of(resVos, page.getTotal());
    }

    @LambdaDataScope
    @BuildChildrenRegionWrapper
    public void buildDataAuditListQuery(LambdaQueryWrapper<BulkCementDirectReportSystemAuditRecord> wrapper, ReqDataUploadListPO req) {

        // 获取登录用户信息
        UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();
        Long roleId = userDetail.getRoleId();

        // 获取入参
        LocalDateTime reportStartMonth = req.getReportStartMonth();
        Integer reportStartYear = req.getReportStartYear();
        LocalDateTime reportEndMonth = req.getReportEndMonth();
        Integer reportEndYear = req.getReportEndYear();
        List<Integer> auditStatusList = req.getAuditStatusList();
        Integer auditStatus = req.getAuditStatus();
        Integer auditDataType = req.getAuditDataType();
        VUtils.isTrue(Objects.isNull(auditDataType)).throwMessage("请传入审核数据类型!");
        Long regionId = req.getRegionId();
        VUtils.isTrue(CollUtil.isEmpty(auditStatusList)).throwMessage("请传入审核列表审核状态筛选条件!");
        wrapper.ge(Objects.nonNull(reportStartMonth), BulkCementDirectReportSystemAuditRecord::getReportMonth, reportStartMonth)
                .le(Objects.nonNull(reportEndMonth), BulkCementDirectReportSystemAuditRecord::getReportMonth, reportEndMonth)
                .ge(Objects.nonNull(reportStartYear), BulkCementDirectReportSystemAuditRecord::getReportYear, reportStartYear)
                .le(Objects.nonNull(reportEndYear), BulkCementDirectReportSystemAuditRecord::getReportYear, reportEndYear)
                .in(BulkCementDirectReportSystemAuditRecord::getAuditStatus,auditStatusList)
                .eq(BulkCementDirectReportSystemAuditRecord::getAuditDataType,auditDataType)
                .eq(Objects.nonNull(auditStatus),BulkCementDirectReportSystemAuditRecord::getAuditStatus,auditStatus)
                .eq(Objects.nonNull(regionId),BulkCementDirectReportSystemAuditRecord::getRegionId,regionId)
                .orderByDesc(BulkCementDirectReportSystemAuditRecord::getUpdateOn)
                .isNotNull(BulkCementDirectReportSystemAuditRecord::getAuditInfoId);
        // 如果是市级散办，筛选出审核类型为市级散办审核的数据
        if (UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId().equals(roleId)){
            wrapper.eq(BulkCementDirectReportSystemAuditRecord::getAuditType,DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
        }
        // 如果是省级散办，筛选出审核类型为省散办审核的数据
        else if (UserRoleTypeEnum.SYSTEM_ADMIN_ROLE_ID.getId().equals(roleId) || UserRoleTypeEnum.SYSTEM_ROLE_ID.getId().equals(roleId)) {
            wrapper.eq(BulkCementDirectReportSystemAuditRecord::getAuditType,DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public String dataAudit(ReqDataAuditPO req) {

        UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();

        // 获取入参
        Long auditDataId = req.getAuditDataId();
        Long auditIndoId = req.getAuditInfoId();
        Long auditRecordId = req.getAuditRecordId();
        String auditOpinion = req.getAuditOpinion();
        Integer auditStatus = req.getAuditStatus();
        LocalDateTime reportMonth = req.getReportMonth();
        Integer reportYear = req.getReportYear();
        Integer auditDataType = req.getAuditDataType();

        // 更新审核信息
        BulkCementDirectReportSystemAuditInfo auditInfo = auditInfoService.getById(auditIndoId);
        VUtils.isTrue(Objects.isNull(auditInfo)).throwMessage("审核信息不存在!");
        auditInfo.setAuditOpinion(auditOpinion);
        auditInfo.setAuditTime(LocalDateTime.now());
        auditInfo.setAuditStatus(auditStatus);
        auditInfo.setAuditBy(userDetail.getUserId());
        auditInfo.setCreateBy(userDetail.getUserId());
        auditInfo.setCreateOn(LocalDateTime.now());
        auditInfo.setUpdateBy(userDetail.getUserId());
        auditInfo.setUpdateOn(LocalDateTime.now());
        auditInfoService.updateById(auditInfo);
        // 更新审核记录信息

        LambdaQueryWrapper<BulkCementDirectReportSystemAuditRecord> wrapper = Wrappers.lambdaQuery(BulkCementDirectReportSystemAuditRecord.class);
        BulkCementDirectSystemManage context = (BulkCementDirectSystemManage) AopContext.currentProxy();
        context.buildAuditRecordQuery(wrapper, auditRecordId);
        BulkCementDirectReportSystemAuditRecord auditRecord = auditRecordService.getOne(wrapper);
        VUtils.isTrue(Objects.isNull(auditRecord)).throwMessage("审核记录不存在!");
        auditRecord.setAuditStatus(auditStatus);
        auditRecord.setUpdateOn(LocalDateTime.now());
        auditRecord.setUpdateBy(userDetail.getUserId());
        auditRecordService.updateById(auditRecord);

        // 更新对应类型的审核数据
        // 如果登录审核用户是市级散办 更新对应数据信息
        if (UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId())) {
            switch (auditDataType) {
                // 散装水泥供应量数据
                case 1:
                    BulkCementSupplyBulletin cementSupplyBulletin = bulkCementSupplyBulletinService.getById(auditDataId);
                    cementSupplyBulletin.setAuditStatus(auditStatus);
                    cementSupplyBulletin.setUpdateOn(LocalDateTime.now());
                    cementSupplyBulletin.setUpdateBy(userDetail.getUserId());
                    bulkCementSupplyBulletinService.updateById(cementSupplyBulletin);
                    break;
                // 中转库进出量统计数据
                case 2:
                    BulkCementTransferBulletin bulkCementTransferBulletin = bulkCementTransferBulletinService.getById(auditDataId);
                    bulkCementTransferBulletin.setAuditStatus(auditStatus);
                    bulkCementTransferBulletin.setUpdateOn(LocalDateTime.now());
                    bulkCementTransferBulletin.setUpdateBy(userDetail.getUserId());
                    bulkCementTransferBulletinService.updateById(bulkCementTransferBulletin);
                    break;
                // 温台舟使用量快报数据
                case 3:
                    BulkCementThreeCityUsageBulletin bulkCementThreeCityUsageBulletin = bulkCementThreeCityUsageBulletinService.getById(auditDataId);
                    bulkCementThreeCityUsageBulletin.setAuditStatus(auditStatus);
                    bulkCementThreeCityUsageBulletin.setUpdateOn(LocalDateTime.now());
                    bulkCementThreeCityUsageBulletin.setUpdateBy(userDetail.getUserId());
                    bulkCementThreeCityUsageBulletinService.updateById(bulkCementThreeCityUsageBulletin);
                    break;
                // 混凝土供应量快报数据
                case 4:
                    ConcreteSupplyBulletin concreteSupplyBulletin = concreteSupplyBulletinService.getById(auditDataId);
                    concreteSupplyBulletin.setAuditStatus(auditStatus);
                    concreteSupplyBulletin.setUpdateOn(LocalDateTime.now());
                    concreteSupplyBulletin.setUpdateBy(userDetail.getUserId());
                    concreteSupplyBulletinService.updateById(concreteSupplyBulletin);
                    break;
                // 砂浆供应量快报数据
                case 5:
                    MortarSupplyBulletin mortarSupplyBulletin = mortarSupplyBulletinService.getById(auditDataId);
                    mortarSupplyBulletin.setAuditStatus(auditStatus);
                    mortarSupplyBulletin.setUpdateOn(LocalDateTime.now());
                    mortarSupplyBulletin.setUpdateBy(userDetail.getUserId());
                    mortarSupplyBulletinService.updateById(mortarSupplyBulletin);
                    break;
                // 非禁现区域散装水泥销售使用情况数据
                case 6:
                    NonProhibitedAreasBulkCementSalesUse nonProhibitedAreasBulkCementSalesUse = nonProhibitedAreasBulkCementSalesUseService.getById(auditDataId);
                    nonProhibitedAreasBulkCementSalesUse.setAuditStatus(auditStatus);
                    nonProhibitedAreasBulkCementSalesUse.setUpdateOn(LocalDateTime.now());
                    nonProhibitedAreasBulkCementSalesUse.setUpdateBy(userDetail.getUserId());
                    nonProhibitedAreasBulkCementSalesUseService.updateById(nonProhibitedAreasBulkCementSalesUse);
                    break;
                // 散装水泥物流设施统计年报表数据
                case 7:
                    // 获取填报的各设备名称的数据更新审核状态
                    BulkCementDirectReportSystemDataRelevance dataRelevance1 = dataRelevanceService.getById(auditDataId);
                    String auditDataIdList1 = dataRelevance1.getAuditDataIdList();
                    VUtils.isTrue(StringUtils.isBlank(auditDataIdList1)).throwMessage("审核数据不存在!");
                    List<Long> idList1 = Arrays.stream(auditDataIdList1.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                    for (Long id : idList1) {
                        BulkCementLogisticFacilityStatisticAnnualReport bulkCementLogFacStaAnnualReport = bulkCementLogFacStaAnnualReportService.getById(id);
                        bulkCementLogFacStaAnnualReport.setAuditStatus(auditStatus);
                        bulkCementLogFacStaAnnualReport.setUpdateOn(LocalDateTime.now());
                        bulkCementLogFacStaAnnualReport.setUpdateBy(userDetail.getUserId());
                        bulkCementLogFacStaAnnualReportService.updateById(bulkCementLogFacStaAnnualReport);
                    }
                    // 更新区县关联数据
                    dataRelevance1.setAuditStatus(auditStatus);
                    dataRelevance1.setUpdateOn(LocalDateTime.now());
                    dataRelevance1.setUpdateBy(userDetail.getUserId());
                    dataRelevanceService.updateById(dataRelevance1);
                    break;
                // 散装水泥、预拌砂浆、干混砂浆物流装备统计年报表数据
                case 8:
                    // 获取填报的各设备名称的数据更新审核状态
                    BulkCementDirectReportSystemDataRelevance dataRelevance2 = dataRelevanceService.getById(auditDataId);
                    String auditDataIdList2 = dataRelevance2.getAuditDataIdList();
                    VUtils.isTrue(StringUtils.isBlank(auditDataIdList2)).throwMessage("审核数据不存在!");
                    List<Long> idList2 = Arrays.stream(auditDataIdList2.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                    for (Long id : idList2) {
                        MaterialLogisticEquipmentStatisticAnnualReport materialLogEquipStaAnnualReport = materialLogEquipStaAnnualReportService.getById(id);
                        materialLogEquipStaAnnualReport.setAuditStatus(auditStatus);
                        materialLogEquipStaAnnualReport.setUpdateOn(LocalDateTime.now());
                        materialLogEquipStaAnnualReport.setUpdateBy(userDetail.getUserId());
                        materialLogEquipStaAnnualReportService.updateById(materialLogEquipStaAnnualReport);
                    }
                    // 更新区县关联数据
                    dataRelevance2.setAuditStatus(auditStatus);
                    dataRelevance2.setUpdateOn(LocalDateTime.now());
                    dataRelevance2.setUpdateBy(userDetail.getUserId());
                    dataRelevanceService.updateById(dataRelevance2);
                    break;
                default:
                    throw new IllegalStateException("Unexpected value: " + auditDataType);
            }
        }

        // 登录用户是市级散办更新对应的市级关联数据
        // 登录用户是省散办更新对应的省关联数
        Long regionId;
        if (UserRoleTypeEnum.SYSTEM_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId()) ||
        UserRoleTypeEnum.SYSTEM_ROLE_ID.getId().equals(userDetail.getRoleId())){
            regionId = DefValConstants.ZJREGION_ID;
        }else {
            regionId = userDetail.getRegionId();
        }

        BulkCementDirectReportSystemDataRelevance dataRelevance = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId)
                .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType,auditDataType)
                // 非年报关联数据，通过传入的上报月份查询
                .eq(Objects.nonNull(reportMonth), BulkCementDirectReportSystemDataRelevance::getReportMonth, reportMonth)
                // 年报数据，通过传入的上报年份查询
                .eq(Objects.nonNull(reportYear),BulkCementDirectReportSystemDataRelevance::getReportYear,reportYear));
        VUtils.isTrue(Objects.isNull(dataRelevance)).throwMessage("关联数据不存在!");

        // 如果审核通过,更新关联数据ID列表
        // 注意：审核数据类型如果为散装水泥物流设施统计年报或者散装水泥、预拌混凝土、干混砂浆物流装备统计年报数据
        // 实际上auditDataIdList中存放的是各区县关联数据ID
        if (DataUploadAuditStatusEnum.AUDIT_PASS.getCode().equals(auditStatus)){
            String auditDataIdList = dataRelevance.getAuditDataIdList();
            // 如果是审核的第一个数据，更新关联数据中上报数据列表
            if (StringUtils.isBlank(auditDataIdList)){
                List<Long> auditIdList = Lists.newArrayList();
                auditIdList.add(auditDataId);
                String idListStr = auditIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                dataRelevance.setAuditDataIdList(idListStr);
            }
            // 如果审核的不是第一个数据，更新关联数据中上报数据列表
            else {
                List<Long> idList = Arrays.stream(auditDataIdList.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                if (!idList.contains(auditDataId)){
                    idList.add(auditDataId);
                    String idListStr = idList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    dataRelevance.setAuditDataIdList(idListStr);
                }
            }
        }
        // 如果登录用户是市级散办,更新关联数据审核状态为未上报,更新关联表中数据的最近一次更新时间和关联数据ID列表
        if (UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId())){
            dataRelevance.setLastUpdateTime(LocalDateTime.now());
            dataRelevance.setAuditStatus(DataUploadAuditStatusEnum.NOT_REPORT.getCode());
        }
        // 如果登录用户是省散办,审核状态设置为审核通过
        else if (UserRoleTypeEnum.SYSTEM_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId()) ||
                UserRoleTypeEnum.SYSTEM_ROLE_ID.getId().equals(userDetail.getRoleId())) {
            dataRelevance.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            // 市级关联数据也要更新状态为审核通过
            BulkCementDirectReportSystemDataRelevance cityRelevanceData = dataRelevanceService.getById(auditDataId);
            cityRelevanceData.setAuditStatus(auditStatus);
            cityRelevanceData.setUpdateOn(LocalDateTime.now());
            cityRelevanceData.setLastUpdateTime(LocalDateTime.now());
            cityRelevanceData.setUpdateBy(userDetail.getUserId());
            dataRelevanceService.updateById(cityRelevanceData);
        }
        dataRelevance.setUpdateOn(LocalDateTime.now());
        dataRelevance.setUpdateBy(userDetail.getUserId());
        dataRelevanceService.updateById(dataRelevance);
        return "审核成功!";
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildAuditRecordQuery(LambdaQueryWrapper<BulkCementDirectReportSystemAuditRecord> wrapper, Long auditRecordId) {
        wrapper.eq(BulkCementDirectReportSystemAuditRecord::getId,auditRecordId);
    }

    public PageVo<ResDataQueryListVO> dataQueryList(ReqDataUploadListPO req) {

        UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();
        Integer pageNumber = req.getPageNumber();
        Integer pageSize = req.getPageSize();

        Long regionId;
        if (UserRoleTypeEnum.SYSTEM_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId()) ||
                UserRoleTypeEnum.SYSTEM_ROLE_ID.getId().equals(userDetail.getRoleId())){
            regionId = DefValConstants.ZJREGION_ID;
        }else {
            regionId = userDetail.getRegionId();
        }

        // 市级散办和省散办账号有该列表权限
        // 根据所属区域查出对应数据类型的上报记录
        LambdaQueryWrapper<BulkCementDirectReportSystemDataRelevance> wrapper = Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class);

        // 获取入参
        LocalDateTime reportStartMonth = req.getReportStartMonth();
        Integer reportStartYear = req.getReportStartYear();
        LocalDateTime reportEndMonth = req.getReportEndMonth();
        Integer reportEndYear = req.getReportEndYear();
        Integer auditStatus = req.getAuditStatus();
        Integer auditDataType = req.getAuditDataType();
        VUtils.isTrue(Objects.isNull(auditDataType)).throwMessage("请传入审核数据类型!");
        wrapper.ge(Objects.nonNull(reportStartMonth), BulkCementDirectReportSystemDataRelevance::getReportMonth, reportStartMonth)
                .le(Objects.nonNull(reportEndMonth), BulkCementDirectReportSystemDataRelevance::getReportMonth, reportEndMonth)
                .ge(Objects.nonNull(reportStartYear), BulkCementDirectReportSystemDataRelevance::getReportYear, reportStartYear)
                .le(Objects.nonNull(reportEndYear), BulkCementDirectReportSystemDataRelevance::getReportYear, reportEndYear)
                .eq(Objects.nonNull(auditStatus),BulkCementDirectReportSystemDataRelevance::getAuditStatus,auditStatus)
                // 其中市级关联数据对应的数据ID列表为对应上报数据的ID
                // 省级关联数据对应的数据ID列表为各市级关联数据的ID
                .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType,auditDataType)
                .eq(BulkCementDirectReportSystemDataRelevance::getRegionId,regionId)
                .orderByDesc(BulkCementDirectReportSystemDataRelevance::getReportMonth);
        List<BulkCementDirectReportSystemDataRelevance> list = dataRelevanceService.list(wrapper);
        if (CollUtil.isEmpty(list)){
            return PageVo.empty();
        }
        // 获取审核信息
        List<Long> auditInfoIdList = list.stream().map(BulkCementDirectReportSystemDataRelevance::getAuditInfoId).collect(Collectors.toList());
        Map<Long, BulkCementDirectReportSystemAuditInfo> auditInfoMap = auditInfoService.list(Wrappers.lambdaQuery(BulkCementDirectReportSystemAuditInfo.class).in(BulkCementDirectReportSystemAuditInfo::getId, auditInfoIdList))
                .stream().collect(Collectors.toMap(BulkCementDirectReportSystemAuditInfo::getId, v -> v));
        // 获取关联数据信息
        Map<Long, BulkCementDirectReportSystemDataRelevance> dataRelevanceMap = dataRelevanceService.list(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .select(BulkCementDirectReportSystemDataRelevance::getId,BulkCementDirectReportSystemDataRelevance::getAuditStatus, BulkCementDirectReportSystemDataRelevance::getAuditDataIdList))
                .stream().collect(Collectors.toMap(BulkCementDirectReportSystemDataRelevance::getId, v -> v));
        List<ResDataQueryListVO> resVos = list.stream().map(r -> {
            ResDataQueryListVO vo = new ResDataQueryListVO();
            LocalDateTime month = r.getReportMonth();
            if (Objects.nonNull(month)) {
                String reportMonthStr = NdDateUtils.format(month, NdDateUtils.DEFAULT_MONTH_FORMAT_EN);
                LocalDateTime reportMonth = LocalDateTimeUtil.parse(reportMonthStr, DateTimeFormatter.ofPattern(NdDateUtils.DEFAULT_MONTH_FORMAT_EN));
                vo.setReportMonth(reportMonth);
            }
            vo.setReportYear(r.getReportYear());
            vo.setRegionId(r.getRegionId());
            vo.setRelevanceDataId(r.getId());

            String auditDataIdList = r.getAuditDataIdList();
            if (StringUtils.isNotBlank(auditDataIdList)) {
                List<Long> idList = Lists.newArrayList();
                Map<Long, List<Long>> dataIdListMap = MapUtil.newHashMap();
                // 如果登录用户为市级散办或者查询列表为温台舟使用量列表,直接得到所属各区县(三 市)上报数据的ID列表
                // 注意：此处审核数据类型如果为散装水泥物流设施统计年报或者散装水泥、预拌混凝土、干混砂浆物流装备统计年报数据
                // 实际上auditDataIdList中存放的是各区县关联数据ID
                if (UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId())) {
                    idList = Arrays.stream(auditDataIdList.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                }
                // 如果登录用户为省级散办,先得到各所属市关联的数据ID列表,再得出各市所属各区县上报数据的ID列表
                else if (UserRoleTypeEnum.SYSTEM_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId()) ||
                        UserRoleTypeEnum.SYSTEM_ROLE_ID.getId().equals(userDetail.getRoleId())) {
                    List<Long> relevanceIdList = Arrays.stream(auditDataIdList.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                    for (Long relevanceId : relevanceIdList) {
                        BulkCementDirectReportSystemDataRelevance dataRelevance = dataRelevanceMap.get(relevanceId);
                        if (Objects.nonNull(dataRelevance) && StringUtils.isNotBlank(dataRelevance.getAuditDataIdList())) {
                            String dataIdList = dataRelevance.getAuditDataIdList();
                            List<Long> ids = Arrays.stream(dataIdList.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                                // 筛选出所有已经审核通过的关联上报数据
                                if (DataUploadAuditStatusEnum.AUDIT_PASS.getCode().equals(dataRelevance.getAuditStatus())){
                                    // 一对多的关系
                                    dataIdListMap.put(relevanceId, ids);
                                }
                        }
                    }
                }
                vo.setAuditDataIdList(idList);
                vo.setAuditDataIdListMap(dataIdListMap);
            }
            BulkCementDirectReportSystemAuditInfo auditInfo = auditInfoMap.get(r.getAuditInfoId());
            if (Objects.nonNull(auditInfo)) {
                vo.setAuditOpinion(auditInfo.getAuditOpinion());
                vo.setAuditInfoId(auditInfo.getId());
            }
            vo.setAuditStatus(r.getAuditStatus());
            String desc = DataUploadAuditStatusEnum.getDescByCode(r.getAuditStatus());
            vo.setAuditStatusName(desc);
            vo.setCreateOn(r.getCreateOn());
            vo.setUpdateTime(r.getUpdateOn());
            return vo;
        }).collect(Collectors.toList());
        List<ResDataQueryListVO> result;
        List<ResDataQueryListVO> dataList = Lists.newArrayList();
        // 省级账号 过滤掉没有数据的记录
        if (UserRoleTypeEnum.SYSTEM_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId()) ||
                UserRoleTypeEnum.SYSTEM_ROLE_ID.getId().equals(userDetail.getRoleId())){
            dataList = resVos.stream().filter(r -> CollUtil.isNotEmpty(r.getAuditDataIdListMap())).collect(Collectors.toList());
            result = dataList.stream().skip((long) (pageNumber - 1) * pageSize)
                    .limit(pageSize).collect(Collectors.toList());
        }else {
            result = resVos;
        }

        return PageVo.of(result, dataList.size());
    }

    public ResDataQueryDetailVO uploadDataQueryDetail(ReqDataUploadListPO req) {

        UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();

        List<Long> auditDataIdList = req.getAuditDataIdList();
        Map<Long, List<Long>> auditDataIdListMap = req.getAuditDataIdListMap();
        Integer auditDataType = req.getAuditDataType();
        LocalDateTime reportMonth = req.getReportMonth();
        Integer reportYear = req.getReportYear();
        Long regionId = req.getRegionId();

        // 判断传入的区域ID是否在登录用户所属的区域权限内
        Long userDetailRegionId = userDetail.getRegionId();
        List<Long> listChildRegionId = regionsCacheHelper.listChildRegionId(userDetailRegionId, true, false);
        if (!listChildRegionId.contains(userDetailRegionId)){
            throw new BizException("您无权查看该地区数据!");
        }

        Integer queryType = req.getQueryType();
        if (Objects.isNull(regionId)){
            if (UserRoleTypeEnum.SYSTEM_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId()) ||
                    UserRoleTypeEnum.SYSTEM_ROLE_ID.getId().equals(userDetail.getRoleId())){
                regionId = DefValConstants.ZJREGION_ID;
            }else {
                regionId = userDetail.getRegionId();
            }
        }
        ResDataQueryDetailVO vo = new ResDataQueryDetailVO();
        vo.setReportMonth(reportMonth);
        vo.setReportYear(reportYear);
        // 根据登录用户角色判断应当返回的数据
        // 如果登录用户是市级散办,返回所属各区县上报的对应类型的数据
        if (UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId())){
            if (CollUtil.isEmpty(auditDataIdList)){
                return vo;
            }
            Map<String, Object> dataMap = MapUtil.newHashMap();
            // 获取所属区县上报已审核通过的对应类型的数据
            Long companyId = userDetail.getCompanyId();
            getDataMap(auditDataIdList, auditDataType, companyId, dataMap, Boolean.FALSE, reportMonth,regionId,queryType);
            assemblyDetailVO(auditDataType, vo, dataMap, Boolean.FALSE, reportMonth,regionId,reportYear,queryType,userDetail);
        }
        // 如果登录用户是省散办,返回所属各市上报的对应类型的数据
        else if (UserRoleTypeEnum.SYSTEM_ADMIN_ROLE_ID.getId().equals(userDetail.getRoleId()) ||
                UserRoleTypeEnum.SYSTEM_ROLE_ID.getId().equals(userDetail.getRoleId())) {
            if (CollUtil.isNotEmpty(auditDataIdListMap)) {
                Map<String, Object> dataMap = MapUtil.newHashMap();
                Set<Long> relevanceIds = auditDataIdListMap.keySet();
                Map<Long, BulkCementDirectReportSystemDataRelevance> dataRelevanceMap = dataRelevanceService.list(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                                .in(BulkCementDirectReportSystemDataRelevance::getId, relevanceIds))
                        .stream().collect(Collectors.toMap(BulkCementDirectReportSystemDataRelevance::getId, v -> v));
                for (Long relevanceId : relevanceIds) {
                    BulkCementDirectReportSystemDataRelevance dataRelevance = dataRelevanceMap.get(relevanceId);
                    if (Objects.nonNull(dataRelevance)){
                        List<Long> idList = auditDataIdListMap.get(relevanceId);
                        Long companyId = dataRelevance.getCompanyId();
                        Long relevanceRegionId = dataRelevance.getRegionId();
                        Map<String, Object> tempDataMap = MapUtil.newHashMap();
                        if (UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode().equals(auditDataType) ||
                                UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode().equals(auditDataType)){
                            getDataMap(idList, auditDataType, companyId, tempDataMap, Boolean.TRUE, reportMonth, relevanceRegionId, queryType);
                            for (Map.Entry<String, Object> entry : tempDataMap.entrySet()) {
                                // key为发放库、中转库、固定接收库
                                String key = entry.getKey();
                                Map<String, Object> mapValue = (Map<String, Object>) entry.getValue();
                                Map<String, Object> value = (Map<String, Object>) dataMap.get(key);
                                if (Objects.nonNull(value)){
                                    for (Map.Entry<String, Object> objectEntry : mapValue.entrySet()) {
                                        // key为各市散装中心名称
                                        String entryKey = objectEntry.getKey();
                                        Object valueList = objectEntry.getValue();
                                        value.put(entryKey, valueList);
                                    }
                                }else {
                                    dataMap.put(key,mapValue);
                                }
                            }
                        }else {
                            getDataMap(idList, auditDataType, companyId, dataMap, Boolean.TRUE, reportMonth, relevanceRegionId, queryType);
                        }
                    }
                }
                assemblyDetailVO(auditDataType,vo,dataMap,Boolean.TRUE, reportMonth, regionId, reportYear, queryType, userDetail);
            }
        }
        return vo;
    }

    private void assemblyDetailVO(Integer auditDataType, ResDataQueryDetailVO vo, Map<String, Object> dataMap, Boolean flag, LocalDateTime reportMonth, Long regionId, Integer reportYear, Integer queryType, UserInfoDetails userDetail) {

        switch (auditDataType) {
            // 散装水泥供应量数据
            case 1:
                ResBulkCementSupplyDataQueryDetailVO bulkCementSupplyDataQueryDetailVo = new ResBulkCementSupplyDataQueryDetailVO();
                getBulkCementSupplyDataQueryDetailVo(dataMap, flag, reportMonth, bulkCementSupplyDataQueryDetailVo,regionId);
                // 返回单位信息
                // 如果是审核列表查询,登录用户是市散办，查询的是具体区县的详情，如果是12月的数据，要返回单位信息
                if (QueryTypeEnum.AUDIT_LIST.getCode().equals(queryType) &&
                        userDetail.getRoleId().equals(UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId()) &&
                        reportMonth.getMonthValue() == ReportConstant.TWELVE){
                    BulkCementSupplyBulletin bulkCementSupplyBulletin = bulkCementSupplyBulletinService.getOne(Wrappers.lambdaQuery(BulkCementSupplyBulletin.class)
                            .eq(BulkCementSupplyBulletin::getReportMonth, reportMonth)
                            .eq(BulkCementSupplyBulletin::getRegionId, regionId));
                    if (Objects.nonNull(bulkCementSupplyBulletin)){
                        bulkCementSupplyDataQueryDetailVo.setUnitResponsiblePerson(bulkCementSupplyBulletin.getUnitResponsiblePerson());
                        bulkCementSupplyDataQueryDetailVo.setPreparer(bulkCementSupplyBulletin.getPreparer());
                        bulkCementSupplyDataQueryDetailVo.setReviewer(bulkCementSupplyBulletin.getReviewer());
                        LocalDateTime submissionDate = bulkCementSupplyBulletin.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr, DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        bulkCementSupplyDataQueryDetailVo.setSubmissionDate(submitDate);
                    }
                }
                // 否则省审核、市/省查询列表查询,返回登录用户所在市/省关联数据的单位信息
                else {
                    BulkCementDirectReportSystemDataRelevance dataRelevance1 =
                            dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, reportMonth)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType,
                                            UploadDataTypeEnum.BULK_CEMENT_SUPPLY_BULLETIN.getCode())
                                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId));
                    if (Objects.nonNull(dataRelevance1)) {
                        bulkCementSupplyDataQueryDetailVo.setUnitResponsiblePerson(dataRelevance1.getUnitResponsiblePerson());
                        bulkCementSupplyDataQueryDetailVo.setPreparer(dataRelevance1.getPreparer());
                        bulkCementSupplyDataQueryDetailVo.setReviewer(dataRelevance1.getReviewer());
                        LocalDateTime submissionDate = dataRelevance1.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr,
                                DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        bulkCementSupplyDataQueryDetailVo.setSubmissionDate(submitDate);
                    }
                }
                vo.setBulkCementSupplyDataVo(bulkCementSupplyDataQueryDetailVo);
                break;
            // 中转库进出量统计数据
            case 2:
                ResBulkCementTransferDataQueryDetailVO bulkCementTransferDataQueryDetailVo = new ResBulkCementTransferDataQueryDetailVO();
                getBulkCementTransferDataQueryDetailVo(dataMap, flag,reportMonth,bulkCementTransferDataQueryDetailVo,regionId);
                // 返回单位信息
                // 如果是审核列表查询,查询的是具体区县的详情，如果是12月的数据，要返回单位信息
                if (QueryTypeEnum.AUDIT_LIST.getCode().equals(queryType) &&
                        userDetail.getRoleId().equals(UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId()) && reportMonth.getMonthValue() == ReportConstant.TWELVE){
                    BulkCementTransferBulletin bulkCementTransferBulletin = bulkCementTransferBulletinService.getOne(Wrappers.lambdaQuery(BulkCementTransferBulletin.class)
                            .eq(BulkCementTransferBulletin::getReportMonth, reportMonth)
                            .eq(BulkCementTransferBulletin::getRegionId, regionId));
                    if (Objects.nonNull(bulkCementTransferBulletin)){
                        bulkCementTransferDataQueryDetailVo.setUnitResponsiblePerson(bulkCementTransferBulletin.getUnitResponsiblePerson());
                        bulkCementTransferDataQueryDetailVo.setPreparer(bulkCementTransferBulletin.getPreparer());
                        bulkCementTransferDataQueryDetailVo.setReviewer(bulkCementTransferBulletin.getReviewer());
                        LocalDateTime submissionDate = bulkCementTransferBulletin.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr, DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        bulkCementTransferDataQueryDetailVo.setSubmissionDate(submitDate);
                    }
                }
                // 否则省审核、市/省查询列表查询,返回登录用户所在市/省关联数据的单位信息
                else {
                    BulkCementDirectReportSystemDataRelevance dataRelevance2 =
                            dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, reportMonth)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType,
                                            UploadDataTypeEnum.BULK_CEMENT_TRANSFER_BULLETIN.getCode())
                                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId));
                    if (Objects.nonNull(dataRelevance2)) {
                        bulkCementTransferDataQueryDetailVo.setUnitResponsiblePerson(dataRelevance2.getUnitResponsiblePerson());
                        bulkCementTransferDataQueryDetailVo.setPreparer(dataRelevance2.getPreparer());
                        bulkCementTransferDataQueryDetailVo.setReviewer(dataRelevance2.getReviewer());
                        LocalDateTime submissionDate = dataRelevance2.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr,
                                DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        bulkCementTransferDataQueryDetailVo.setSubmissionDate(submitDate);
                    }
                }
                vo.setBulkCementTransferDataVo(bulkCementTransferDataQueryDetailVo);
                break;
            // 温台舟使用量快报数据
            case 3:
                ResBulkCementThreeCityUsageDataQueryDetailVO bulkCementThreeCityUsageDataQueryDetailVO = new ResBulkCementThreeCityUsageDataQueryDetailVO();
                getBulkCementThreeCityUsageDataQueryDetailVo(dataMap,reportMonth, bulkCementThreeCityUsageDataQueryDetailVO,regionId);
                // 返回单位信息
                // 如果是审核列表查询，查询的是具体区县的详情，如果是12月的数据，要返回单位信息
                if (QueryTypeEnum.AUDIT_LIST.getCode().equals(queryType) &&
                        userDetail.getRoleId().equals(UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId()) && reportMonth.getMonthValue() == ReportConstant.TWELVE){
                    BulkCementThreeCityUsageBulletin bulkCementThreeCityUsageBulletin = bulkCementThreeCityUsageBulletinService.getOne(Wrappers.lambdaQuery(BulkCementThreeCityUsageBulletin.class)
                            .eq(BulkCementThreeCityUsageBulletin::getReportMonth, reportMonth)
                            .eq(BulkCementThreeCityUsageBulletin::getRegionId, regionId));
                    if (Objects.nonNull(bulkCementThreeCityUsageBulletin)){
                        bulkCementThreeCityUsageDataQueryDetailVO.setUnitResponsiblePerson(bulkCementThreeCityUsageBulletin.getUnitResponsiblePerson());
                        bulkCementThreeCityUsageDataQueryDetailVO.setPreparer(bulkCementThreeCityUsageBulletin.getPreparer());
                        bulkCementThreeCityUsageDataQueryDetailVO.setReviewer(bulkCementThreeCityUsageBulletin.getReviewer());
                        LocalDateTime submissionDate = bulkCementThreeCityUsageBulletin.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr, DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        bulkCementThreeCityUsageDataQueryDetailVO.setSubmissionDate(submitDate);
                    }
                }
                // 否则省审核、市/省查询列表查询,返回登录用户所在市/省关联数据的单位信息
                else {
                    BulkCementDirectReportSystemDataRelevance dataRelevance3 =
                            dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, reportMonth)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType,
                                            UploadDataTypeEnum.BULK_CEMENT_THREE_CITY_USAGE_BULLETIN.getCode())
                                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId));
                    if (Objects.nonNull(dataRelevance3)) {
                        bulkCementThreeCityUsageDataQueryDetailVO.setUnitResponsiblePerson(dataRelevance3.getUnitResponsiblePerson());
                        bulkCementThreeCityUsageDataQueryDetailVO.setPreparer(dataRelevance3.getPreparer());
                        bulkCementThreeCityUsageDataQueryDetailVO.setReviewer(dataRelevance3.getReviewer());
                        LocalDateTime submissionDate = dataRelevance3.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr,
                                DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        bulkCementThreeCityUsageDataQueryDetailVO.setSubmissionDate(submitDate);
                    }
                }
                vo.setBulkCementThreeCityUsageDataVo(bulkCementThreeCityUsageDataQueryDetailVO);
                break;
            // 混凝土供应量快报数据
            case 4:
                ResConcreteSupplyDataQueryDetailVO concreteSupplyDataQueryDetailVO = new ResConcreteSupplyDataQueryDetailVO();
                getConcreteSupplyDataQueryDetailVo(dataMap, flag, reportMonth, concreteSupplyDataQueryDetailVO, regionId);
                // 返回单位信息
                // 如果是审核列表查询，查询的是具体区县的详情，如果是12月的数据，要返回单位信息
                if (QueryTypeEnum.AUDIT_LIST.getCode().equals(queryType) &&
                        userDetail.getRoleId().equals(UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId()) && reportMonth.getMonthValue() == ReportConstant.TWELVE){
                    ConcreteSupplyBulletin concreteSupplyBulletin = concreteSupplyBulletinService.getOne(Wrappers.lambdaQuery(ConcreteSupplyBulletin.class)
                            .eq(ConcreteSupplyBulletin::getReportMonth, reportMonth)
                            .eq(ConcreteSupplyBulletin::getRegionId, regionId));
                    if (Objects.nonNull(concreteSupplyBulletin)){
                        concreteSupplyDataQueryDetailVO.setUnitResponsiblePerson(concreteSupplyBulletin.getUnitResponsiblePerson());
                        concreteSupplyDataQueryDetailVO.setPreparer(concreteSupplyBulletin.getPreparer());
                        concreteSupplyDataQueryDetailVO.setReviewer(concreteSupplyBulletin.getReviewer());
                        LocalDateTime submissionDate = concreteSupplyBulletin.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr, DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        concreteSupplyDataQueryDetailVO.setSubmissionDate(submitDate);
                    }
                }
                // 否则省审核、市/省查询列表查询,返回登录用户所在市/省关联数据的单位信息
                else {
                    BulkCementDirectReportSystemDataRelevance dataRelevance4 =
                            dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, reportMonth)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType,
                                            UploadDataTypeEnum.CONCRETE_SUPPLY_BULLETIN.getCode())
                                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId));
                    if (Objects.nonNull(dataRelevance4)) {
                        concreteSupplyDataQueryDetailVO.setUnitResponsiblePerson(dataRelevance4.getUnitResponsiblePerson());
                        concreteSupplyDataQueryDetailVO.setPreparer(dataRelevance4.getPreparer());
                        concreteSupplyDataQueryDetailVO.setReviewer(dataRelevance4.getReviewer());
                        LocalDateTime submissionDate = dataRelevance4.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr,
                                DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        concreteSupplyDataQueryDetailVO.setSubmissionDate(submitDate);
                    }
                }
                vo.setConcreteSupplyDataVo(concreteSupplyDataQueryDetailVO);
                break;
            // 砂浆供应量快报数据
            case 5:
                ResMortarSupplyDataQueryDetailVO mortarSupplyDataQueryDetailVO = new ResMortarSupplyDataQueryDetailVO();
                getMortarSupplyDataQueryDetailVo(dataMap, flag, reportMonth, mortarSupplyDataQueryDetailVO,regionId);
                // 返回单位信息
                // 如果是审核列表查询，查询的是具体区县的详情，如果是12月的数据，要返回单位信息
                if (QueryTypeEnum.AUDIT_LIST.getCode().equals(queryType) &&
                        userDetail.getRoleId().equals(UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId()) && reportMonth.getMonthValue() == ReportConstant.TWELVE){
                    MortarSupplyBulletin mortarSupplyBulletin = mortarSupplyBulletinService.getOne(Wrappers.lambdaQuery(MortarSupplyBulletin.class)
                            .eq(MortarSupplyBulletin::getReportMonth, reportMonth)
                            .eq(MortarSupplyBulletin::getRegionId, regionId));
                    if (Objects.nonNull(mortarSupplyBulletin)){
                        mortarSupplyDataQueryDetailVO.setUnitResponsiblePerson(mortarSupplyBulletin.getUnitResponsiblePerson());
                        mortarSupplyDataQueryDetailVO.setPreparer(mortarSupplyBulletin.getPreparer());
                        mortarSupplyDataQueryDetailVO.setReviewer(mortarSupplyBulletin.getReviewer());
                        LocalDateTime submissionDate = mortarSupplyBulletin.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr, DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        mortarSupplyDataQueryDetailVO.setSubmissionDate(submitDate);
                    }
                }
                // 否则省审核、市/省查询列表查询,返回登录用户所在市/省关联数据的单位信息
                else {
                    BulkCementDirectReportSystemDataRelevance dataRelevance5 =
                            dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, reportMonth)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType,
                                            UploadDataTypeEnum.MORTAR_SUPPLY_BULLETIN.getCode())
                                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId));
                    if (Objects.nonNull(dataRelevance5)) {
                        mortarSupplyDataQueryDetailVO.setUnitResponsiblePerson(dataRelevance5.getUnitResponsiblePerson());
                        mortarSupplyDataQueryDetailVO.setPreparer(dataRelevance5.getPreparer());
                        mortarSupplyDataQueryDetailVO.setReviewer(dataRelevance5.getReviewer());
                        LocalDateTime submissionDate = dataRelevance5.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr,
                                DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        mortarSupplyDataQueryDetailVO.setSubmissionDate(submitDate);
                    }
                }
                vo.setMortarSupplyDataVo(mortarSupplyDataQueryDetailVO);
                break;
            // 非禁现区域散装水泥销售使用情况数据
            case 6:
                ResNonProhibitedAreasDataQueryDetailVO nonProhibitedAreasDataQueryDetailVO = new ResNonProhibitedAreasDataQueryDetailVO();
                getNonProAreasDataQueryDetailVo(dataMap,reportYear, nonProhibitedAreasDataQueryDetailVO,regionId);
                // 返回单位信息
                // 如果是审核列表查询，查询的是具体区县的详情
                if (QueryTypeEnum.AUDIT_LIST.getCode().equals(queryType) &&
                        userDetail.getRoleId().equals(UserRoleTypeEnum.BULK_CEMENT_ADMIN_ROLE_ID.getId())){
                    NonProhibitedAreasBulkCementSalesUse nonProhibitedAreasBulkCementSalesUse = nonProhibitedAreasBulkCementSalesUseService.getOne(Wrappers.lambdaQuery(NonProhibitedAreasBulkCementSalesUse.class)
                            .eq(NonProhibitedAreasBulkCementSalesUse::getReportYear, reportYear)
                            .eq(NonProhibitedAreasBulkCementSalesUse::getRegionId, regionId));
                    if (Objects.nonNull(nonProhibitedAreasBulkCementSalesUse)){
                        nonProhibitedAreasDataQueryDetailVO.setUnitResponsiblePerson(nonProhibitedAreasBulkCementSalesUse.getUnitResponsiblePerson());
                        nonProhibitedAreasDataQueryDetailVO.setPreparer(nonProhibitedAreasBulkCementSalesUse.getPreparer());
                        nonProhibitedAreasDataQueryDetailVO.setReviewer(nonProhibitedAreasBulkCementSalesUse.getReviewer());
                        LocalDateTime submissionDate = nonProhibitedAreasBulkCementSalesUse.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr, DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        nonProhibitedAreasDataQueryDetailVO.setSubmissionDate(submitDate);
                        nonProhibitedAreasDataQueryDetailVO.setRemark(nonProhibitedAreasBulkCementSalesUse.getRemark());
                    }
                }
                // 否则省审核、市/省查询列表查询,返回登录用户所在市/省关联数据的单位信息
                else {
                    BulkCementDirectReportSystemDataRelevance dataRelevance6 =
                            dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getReportYear, reportYear)
                                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType,
                                            UploadDataTypeEnum.NON_PROHIBITED_AREAS_BULK_CEMENT_SALES_USE.getCode())
                                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId));
                    if (Objects.nonNull(dataRelevance6)) {
                        nonProhibitedAreasDataQueryDetailVO.setUnitResponsiblePerson(dataRelevance6.getUnitResponsiblePerson());
                        nonProhibitedAreasDataQueryDetailVO.setPreparer(dataRelevance6.getPreparer());
                        nonProhibitedAreasDataQueryDetailVO.setReviewer(dataRelevance6.getReviewer());
                        LocalDateTime submissionDate = dataRelevance6.getSubmissionDate();
                        String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                        LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr,
                                DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                        nonProhibitedAreasDataQueryDetailVO.setSubmissionDate(submitDate);
                    }
                }
                vo.setNonProAreasDataVo(nonProhibitedAreasDataQueryDetailVO);
                break;
            // 散装水泥物流设施统计年报表数据
            case 7:
                ResBulkCementLogFacStaDataQueryVO bulkCementLogFacStaDataQueryVo = new ResBulkCementLogFacStaDataQueryVO();
                Map<String, Object> resMap1 = MapUtil.newHashMap();
                // map中是三种设备名称对应的数据集合
                for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
                    Map<String, Object> map = (Map<String, Object>) entry.getValue();
                    String key = entry.getKey();
                    ResBulkCementLogFacStaDataQueryDetailVO bulkCementLogFacStaDataQueryDetailVO = new ResBulkCementLogFacStaDataQueryDetailVO();
                    getBulkCementLogFacStaDataQueryDetailVo(key, map,reportYear, bulkCementLogFacStaDataQueryDetailVO,regionId);
                    resMap1.put(key,bulkCementLogFacStaDataQueryDetailVO);
                }
                bulkCementLogFacStaDataQueryVo.setBulkCementLogFacStaDataMap(resMap1);
                // 返回单位信息
                BulkCementDirectReportSystemDataRelevance dataRelevance7 =
                        dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                                .eq(BulkCementDirectReportSystemDataRelevance::getReportYear, reportYear)
                                .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType,
                                        UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode())
                                .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId));
                if (Objects.nonNull(dataRelevance7)) {
                    bulkCementLogFacStaDataQueryVo.setUnitResponsiblePerson(dataRelevance7.getUnitResponsiblePerson());
                    bulkCementLogFacStaDataQueryVo.setPreparer(dataRelevance7.getPreparer());
                    bulkCementLogFacStaDataQueryVo.setReviewer(dataRelevance7.getReviewer());
                    LocalDateTime submissionDate = dataRelevance7.getSubmissionDate();
                    String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                    LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr,
                            DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                    bulkCementLogFacStaDataQueryVo.setSubmissionDate(submitDate);
                }
                vo.setBulkCementLogFacStaDataVo(bulkCementLogFacStaDataQueryVo);
                break;
            // 散装水泥、预拌砂浆、干混砂浆物流装备统计年报表数据
            case 8:
                ResMaterialLogEquipStaDataQueryVO materialLogEquipStaDataQueryVo = new ResMaterialLogEquipStaDataQueryVO();
                Map<String, Object> resMap2 = MapUtil.newHashMap();
                // map中是八种设备名称对应的数据集合
                for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
                    Map<String, Object> map = (Map<String, Object>) entry.getValue();
                    String key = entry.getKey();
                    ResMaterialLogEquipStaDataQueryDetailVO materialLogEquipStaDataQueryDetailVO = new ResMaterialLogEquipStaDataQueryDetailVO();
                    getMaterialLogEquipStaDataQueryDetailVo(key, map,reportYear, materialLogEquipStaDataQueryDetailVO,regionId);
                    resMap2.put(key,materialLogEquipStaDataQueryDetailVO);
                }
                // 返回单位信息
                BulkCementDirectReportSystemDataRelevance dataRelevance8 =
                        dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                                .eq(BulkCementDirectReportSystemDataRelevance::getReportYear, reportYear)
                                .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType,
                                        UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode())
                                .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId));
                if (Objects.nonNull(dataRelevance8)) {
                    materialLogEquipStaDataQueryVo.setUnitResponsiblePerson(dataRelevance8.getUnitResponsiblePerson());
                    materialLogEquipStaDataQueryVo.setPreparer(dataRelevance8.getPreparer());
                    materialLogEquipStaDataQueryVo.setReviewer(dataRelevance8.getReviewer());
                    LocalDateTime submissionDate = dataRelevance8.getSubmissionDate();
                    String submissionDateStr = NdDateUtils.format(submissionDate, DatePattern.CHINESE_DATE_PATTERN);
                    LocalDateTime submitDate = LocalDateTimeUtil.parse(submissionDateStr,
                            DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN));
                    materialLogEquipStaDataQueryVo.setSubmissionDate(submitDate);
                }
                materialLogEquipStaDataQueryVo.setMaterialLogEquipStaDataMap(resMap2);
                vo.setMaterialLogEquipStaDataVo(materialLogEquipStaDataQueryVo);
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + auditDataType);
        }
    }

    private void getBulkCementSupplyDataQueryDetailVo(Map<String, Object> dataMap, Boolean flag, LocalDateTime reportMonth, ResBulkCementSupplyDataQueryDetailVO bulkCementSupplyDataQueryDetailVo, Long regionId) {
        // 统计各字段合计值
        // 合计散装水泥总量
        List<BigDecimal> bulkCementAmountTotalList = Lists.newArrayList();
        // 合计水泥产量
        List<BigDecimal> cementOutputTotalList = Lists.newArrayList();
        // 合计完成量
        List<BigDecimal> completedAmountTotalList = Lists.newArrayList();
        // 合计水泥产量
        List<BigDecimal> cumulativeCementProductionTotalList = Lists.newArrayList();
        // 合计增加量
        List<BigDecimal> incrementTotalList = Lists.newArrayList();
        // 去年这个月的合计完成量
        List<BigDecimal> preYearCompletedAmountTotalList = Lists.newArrayList();

        // 对于市级散办，map中只有一个键值对，统计的是该市各区县对应字段的集合
        // 对于省散办，map中对应各市键值对，统计的是各个市下各区县对应字段的集合
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            List<ResBulkCementSupplyDataUploadDetailVO> value = (List<ResBulkCementSupplyDataUploadDetailVO>)entry.getValue();
            // 筛选出为市合计数据的那条记录(市散办有一条、省散办中有多个)
            List<ResBulkCementSupplyDataUploadDetailVO> totalDataList = value.stream().filter(v -> Boolean.TRUE.equals(v.getIsCityTotalData())).collect(Collectors.toList());
            // 散装水泥总量
            List<BigDecimal> data1List = totalDataList.stream().map(ResBulkCementSupplyDataUploadDetailVO::getBulkCementAmountTotal).collect(Collectors.toList());
            bulkCementAmountTotalList.addAll(data1List);
            // 水泥产量
            List<BigDecimal> data2List = totalDataList.stream().map(ResBulkCementSupplyDataUploadDetailVO::getCementOutputTotal).collect(Collectors.toList());
            cementOutputTotalList.addAll(data2List);
            // 完成量
            List<BigDecimal> data3List = totalDataList.stream().map(ResBulkCementSupplyDataUploadDetailVO::getCompletedTotalAmountTotal).collect(Collectors.toList());
            completedAmountTotalList.addAll(data3List);
            // 水泥产量
            List<BigDecimal> data4List = totalDataList.stream().map(ResBulkCementSupplyDataUploadDetailVO::getCumulativeCementProductionTotal).collect(Collectors.toList());
            cumulativeCementProductionTotalList.addAll(data4List);
            // 增加量
            List<BigDecimal> data5List = totalDataList.stream().map(ResBulkCementSupplyDataUploadDetailVO::getIncrementTotal).collect(Collectors.toList());
            incrementTotalList.addAll(data5List);
            // 去年这个月的合计完成量
            List<BigDecimal> data6List = totalDataList.stream().map(v -> {
                BigDecimal increaseRate = v.getIncreaseRateTotal();
                BigDecimal increment = v.getIncrementTotal();
                if (Objects.nonNull(increaseRate) && Objects.nonNull(increment)) {
                    if (BigDecimal.ZERO.compareTo(increaseRate) != 0) {
                        return increment.divide(increaseRate, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                    }
                }
                return BigDecimal.ZERO;
            }).collect(Collectors.toList());
            preYearCompletedAmountTotalList.addAll(data6List);
        }
        List<ResBulkCementSupplyDataUploadDetailVO> totalValues = Lists.newArrayList();
        ResBulkCementSupplyDataUploadDetailVO totalVo = new ResBulkCementSupplyDataUploadDetailVO();
        // 合计散装水泥总量
        BigDecimal bulkCementAmountTotal = bulkCementAmountTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setBulkCementAmount(bulkCementAmountTotal);
        // 合计水泥产量
        BigDecimal cementOutputTotal = cementOutputTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setCementOutput(cementOutputTotal);
        // 合计完成量
        BigDecimal completedAmountTotal = completedAmountTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setCompletedTotalAmount(completedAmountTotal);
        // 合计水泥产量
        BigDecimal cumulativeCementProductionTotal = cumulativeCementProductionTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setCumulativeCementProduction(cumulativeCementProductionTotal);
        // 合计增加量
        BigDecimal incrementTotal = incrementTotalList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setIncrement(incrementTotal);
        // 合计散装率: 合计完成量 / 合计水泥产量 * 100
        BigDecimal bulkRateTotal;
        if (BigDecimal.ZERO.compareTo(cumulativeCementProductionTotal) != 0) {
            bulkRateTotal = completedAmountTotal.divide(cumulativeCementProductionTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }else {
            bulkRateTotal = BigDecimal.ZERO;
        }
        totalVo.setBulkRate(bulkRateTotal);
        // 合计增长率：合计增长量 / 去年这个月的合计完成量 * 100
        BigDecimal increaseRateTotal;
        BigDecimal preYearCompletedAmountTotal = preYearCompletedAmountTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        if (BigDecimal.ZERO.compareTo(preYearCompletedAmountTotal) != 0) {
            increaseRateTotal = incrementTotal.divide(preYearCompletedAmountTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }else {
            increaseRateTotal = incrementTotal.multiply(BigDecimal.valueOf(100L));
        }
        totalVo.setIncreaseRate(increaseRateTotal);
        // 合计散装率目标
        // 如果是省散办查询详情
        if (Boolean.TRUE.equals(flag)) {
            int year = reportMonth.getYear();
            BulkCementDirectReportSystemUniversalIndex universalIndex = universalIndexService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemUniversalIndex.class)
                    .eq(BulkCementDirectReportSystemUniversalIndex::getYear, year)
                    .eq(BulkCementDirectReportSystemUniversalIndex::getRegionId, DefValConstants.ZJREGION_ID));
            if (Objects.nonNull(universalIndex)){
                totalVo.setBulkRateTarget(universalIndex.getBulkRateTarget());
            }
        }
        totalVo.setUnitName(ReportConstant.TOTAL);
        totalValues.add(totalVo);
        dataMap.put(ReportConstant.TOTAL,totalValues);
        bulkCementSupplyDataQueryDetailVo.setBulkCementSupplyDataMap(dataMap);
    }

    private void getBulkCementTransferDataQueryDetailVo(Map<String, Object> dataMap, Boolean flag, LocalDateTime reportMonth, ResBulkCementTransferDataQueryDetailVO bulkCementTransferDataQueryDetailVo, Long regionId) {
        // 统计各字段合计值
        // 合计上月末库存
        List<BigDecimal> lastMonthEndInventoryTotalList = Lists.newArrayList();
        // 合计本月进库量
        List<BigDecimal> thisMonthIncomingStorageTotalList = Lists.newArrayList();
        // 合计累计进库量
        List<BigDecimal> cumulativeIncomingStorageTotalList = Lists.newArrayList();
        // 合计本月出库量
        List<BigDecimal> thisMonthOutgoingStorageTotalList = Lists.newArrayList();
        // 合计累计出库量
        List<BigDecimal> cumulativeOutgoingStorageTotalList = Lists.newArrayList();
        // 合计月末库存量
        List<BigDecimal> monthEndInventoryTotalList = Lists.newArrayList();

        // 去年这个月的合计库存量
        List<BigDecimal> preYearMonthEndInventoryTotalList = Lists.newArrayList();

        // 对于市级散办，map中只有一个键值对，统计的是该市各区县对应字段的集合
        // 对于省散办，map中对应各市键值对，统计的是各个市下各区县对应字段的集合
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            List<ResBulkCementTransferDataUploadDetailVO> value = (List<ResBulkCementTransferDataUploadDetailVO>)entry.getValue();
            // 筛选出为市合计数据的那条记录(市散办有一条、省散办中有多个)
            List<ResBulkCementTransferDataUploadDetailVO> totalDataList = value.stream().filter(v -> Boolean.TRUE.equals(v.getIsCityTotalData())).collect(Collectors.toList());
            // 上月末库存
            List<BigDecimal> data1List = totalDataList.stream().map(ResBulkCementTransferDataUploadDetailVO::getLastMonthEndInventoryTotal).collect(Collectors.toList());
            lastMonthEndInventoryTotalList.addAll(data1List);
            // 本月进库量
            List<BigDecimal> data2List = totalDataList.stream().map(ResBulkCementTransferDataUploadDetailVO::getThisMonthIncomingStorageTotal).collect(Collectors.toList());
            thisMonthIncomingStorageTotalList.addAll(data2List);
            // 累计进库量
            List<BigDecimal> data3List = totalDataList.stream().map(ResBulkCementTransferDataUploadDetailVO::getCumulativeIncomingStorageTotal).collect(Collectors.toList());
            cumulativeIncomingStorageTotalList.addAll(data3List);
            // 本月出库量
            List<BigDecimal> data4List = totalDataList.stream().map(ResBulkCementTransferDataUploadDetailVO::getThisMonthOutgoingStorageTotal).collect(Collectors.toList());
            thisMonthOutgoingStorageTotalList.addAll(data4List);
            // 累计出库量
            List<BigDecimal> data5List = totalDataList.stream().map(ResBulkCementTransferDataUploadDetailVO::getCumulativeOutgoingStorageTotal).collect(Collectors.toList());
            cumulativeOutgoingStorageTotalList.addAll(data5List);
            // 月末库存量
            List<BigDecimal> data6List = totalDataList.stream().map(ResBulkCementTransferDataUploadDetailVO::getMonthEndInventoryTotal).collect(Collectors.toList());
            monthEndInventoryTotalList.addAll(data6List);

            // 去年这个月的合计月末库存量
            List<BigDecimal> data7List = totalDataList.stream().map(v -> {
                BigDecimal monthEndInventory = v.getMonthEndInventoryTotal();
                BigDecimal monthEndInventoryGrowthRate = v.getMonthEndInventoryGrowthRateTotal();
                return monthEndInventory.divide(monthEndInventoryGrowthRate.add(BigDecimal.valueOf(100L)),RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100L));
            }).collect(Collectors.toList());
            preYearMonthEndInventoryTotalList.addAll(data7List);
        }
        List<ResBulkCementTransferDataUploadDetailVO> totalValues = Lists.newArrayList();
        ResBulkCementTransferDataUploadDetailVO totalVo = new ResBulkCementTransferDataUploadDetailVO();
        // 合计上月末库存
        BigDecimal lastMonthEndInventoryTotal = lastMonthEndInventoryTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setLastMonthEndInventory(lastMonthEndInventoryTotal);
        // 合计本月进库量
        BigDecimal thisMonthIncomingStorageTotal = thisMonthIncomingStorageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisMonthIncomingStorage(thisMonthIncomingStorageTotal);
        // 合计累计进库量
        BigDecimal cumulativeIncomingStorageTotal = cumulativeIncomingStorageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setCumulativeIncomingStorage(cumulativeIncomingStorageTotal);
        // 合计本月出库量
        BigDecimal thisMonthOutgoingStorageTotal = thisMonthOutgoingStorageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisMonthOutgoingStorage(thisMonthOutgoingStorageTotal);
        // 合计累计出库量
        BigDecimal cumulativeOutgoingStorageTotal = cumulativeOutgoingStorageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setCumulativeOutgoingStorage(cumulativeOutgoingStorageTotal);
        // 合计月末库存量
        BigDecimal  monthEndInventoryTotal = monthEndInventoryTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setMonthEndInventory( monthEndInventoryTotal);
        // 合计月末库存同比增长率: (合计月末库存量 - 去年合计月末库存量) / 去年合计月末库存量 * 100
        BigDecimal monthEndInventoryGrowthRateTotal;
        BigDecimal  preYearMonthEndInventoryTotal = preYearMonthEndInventoryTotalList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        if (BigDecimal.ZERO.compareTo(preYearMonthEndInventoryTotal) != 0) {
            monthEndInventoryGrowthRateTotal = (monthEndInventoryTotal.subtract(preYearMonthEndInventoryTotal)).divide(preYearMonthEndInventoryTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }else {
            monthEndInventoryGrowthRateTotal = monthEndInventoryTotal.multiply(BigDecimal.valueOf(100L));
        }
        totalVo.setMonthEndInventoryGrowthRate(monthEndInventoryGrowthRateTotal);
        totalValues.add(totalVo);
        totalVo.setUnitName(ReportConstant.TOTAL);
        dataMap.put(ReportConstant.TOTAL,totalValues);
        bulkCementTransferDataQueryDetailVo.setBulkCementTransferDataMap(dataMap);
    }

    private void getBulkCementThreeCityUsageDataQueryDetailVo(Map<String, Object> dataMap, LocalDateTime reportMonth, ResBulkCementThreeCityUsageDataQueryDetailVO bulkCementThreeCityUsageDataQueryDetailVO, Long regionId) {

        // 统计各字段合计值
        // 合计年目标
        List<BigDecimal> yearTargetTotalList = Lists.newArrayList();
        // 合计本月使用量
        List<BigDecimal> thisMonthUsageTotalList = Lists.newArrayList();
        // 合计累计使用量
        List<BigDecimal> accumulativeUsageTotalList = Lists.newArrayList();
        // 合计本省本月使用量
        List<BigDecimal> thisProvinceThisMonthUsageTotalList = Lists.newArrayList();
        // 合计本省累计使用量
        List<BigDecimal> thisProvinceAccumulativeUsageTotalList = Lists.newArrayList();
        // 合计外省本月使用量
        List<BigDecimal> otherProvinceThisMonthUsageTotalList = Lists.newArrayList();
        // 合计外省累计使用量
        List<BigDecimal> otherProvinceAccumulativeUsageTotalList = Lists.newArrayList();

        // 合计去年这个月的累计使用量
        List<BigDecimal> preYearAccumulativeUsageTotalList = Lists.newArrayList();
        // 合计上个月的累计使用量
        List<BigDecimal> preAccumulativeUsageTotalList = Lists.newArrayList();

        // 对于市级散办，map中只有一个键值对，统计的是该市各区县对应字段的集合
        // 对于省散办，map中对应各市键值对，统计的是各个市下各区县对应字段的集合
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            List<ResBulkCementThreeCityUsageDataUploadDetailVO> value = (List<ResBulkCementThreeCityUsageDataUploadDetailVO>)entry.getValue();
            // 筛选出为市合计数据的那条记录(市散办有一条、省散办中有多个)
            List<ResBulkCementThreeCityUsageDataUploadDetailVO> totalDataList = value.stream().filter(v -> Boolean.TRUE.equals(v.getIsCityTotalData())).collect(Collectors.toList());
            // 年目标
            List<BigDecimal> data1List = totalDataList.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getYearTargetTotal).collect(Collectors.toList());
            yearTargetTotalList.addAll(data1List);
            // 本月使用量
            List<BigDecimal> data2List = totalDataList.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getThisMonthUsageTotal).collect(Collectors.toList());
            thisMonthUsageTotalList.addAll(data2List);
            // 累计使用量
            List<BigDecimal> data3List = totalDataList.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getAccumulativeUsageTotal).collect(Collectors.toList());
            accumulativeUsageTotalList.addAll(data3List);
            // 本省本月使用量
            List<BigDecimal> data4List = totalDataList.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getThisProvinceThisMonthUsageTotal).collect(Collectors.toList());
            thisProvinceThisMonthUsageTotalList.addAll(data4List);
            // 本省累计使用量
            List<BigDecimal> data5List = totalDataList.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getThisProvinceAccumulativeUsageTotal).collect(Collectors.toList());
            thisProvinceAccumulativeUsageTotalList.addAll(data5List);
            // 外省本月使用量
            List<BigDecimal> data6List = totalDataList.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getOtherProvinceThisMonthUsageTotal).collect(Collectors.toList());
            otherProvinceThisMonthUsageTotalList.addAll(data6List);
            // 外省累计使用量
            List<BigDecimal> data7List = totalDataList.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getOtherProvinceThisMonthUsageTotal).collect(Collectors.toList());
            otherProvinceAccumulativeUsageTotalList.addAll(data7List);

            // 去年这个月的累计使用量
            List<BigDecimal> data8List = totalDataList.stream().map(v -> {
                BigDecimal accumulativeUsageTotal = v.getAccumulativeUsageTotal();
                BigDecimal growthRateTotal = v.getGrowthRateTotal();
                if (Objects.nonNull(accumulativeUsageTotal) && Objects.nonNull(growthRateTotal)){
                    if (BigDecimal.ZERO.compareTo(growthRateTotal) != 0) {
                        return accumulativeUsageTotal.divide(growthRateTotal.add(BigDecimal.valueOf(100L)), RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100L));
                    }
                }
                return BigDecimal.ZERO;
            }).collect(Collectors.toList());
            preYearAccumulativeUsageTotalList.addAll(data8List);

            // 上个月的累计使用量
            List<BigDecimal> data9List = totalDataList.stream().map(v -> {
                BigDecimal thisMonthUsageTotal = v.getThisMonthUsageTotal();
                BigDecimal thisMonthUsage = v.getThisMonthUsage();
                if (Objects.nonNull(thisMonthUsage)) {
                    return thisMonthUsageTotal.subtract(thisMonthUsage);
                }else {
                    return thisMonthUsageTotal;
                }
            }).collect(Collectors.toList());
            preAccumulativeUsageTotalList.addAll(data9List);
        }

        List<ResBulkCementThreeCityUsageDataUploadDetailVO> totalValues = Lists.newArrayList();
        ResBulkCementThreeCityUsageDataUploadDetailVO totalVo = new ResBulkCementThreeCityUsageDataUploadDetailVO();

        // 合计年目标
        BigDecimal yearTargetTotal = yearTargetTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setYearTarget(yearTargetTotal);
        // 合计累计使用量
        BigDecimal accumulativeUsageTotal = accumulativeUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setAccumulativeUsage(accumulativeUsageTotal);
        // 合计占全年目标百分比：合计累计使用量 / 合计年目标 * 100
        BigDecimal percentageOfAnnualTargetTotal = BigDecimal.ZERO;
        
        if (BigDecimal.ZERO.compareTo(yearTargetTotal) != 0) {
            percentageOfAnnualTargetTotal = accumulativeUsageTotal.divide(yearTargetTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100L));
        }
        totalVo.setPercentageOfAnnualTarget(percentageOfAnnualTargetTotal);

        // 合计同比增长率: (合计累计使用量 - 去年合计累计使用量) / 去年合计累计使用量 * 100
        BigDecimal growthRateTotal;
        BigDecimal  preYearAccumulativeUsageTotal = preYearAccumulativeUsageTotalList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        if (BigDecimal.ZERO.compareTo(preYearAccumulativeUsageTotal) != 0) {
            growthRateTotal = (accumulativeUsageTotal.subtract(preYearAccumulativeUsageTotal)).divide(preYearAccumulativeUsageTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }else {
            growthRateTotal = accumulativeUsageTotal.multiply(BigDecimal.valueOf(100L));
        }
        totalVo.setGrowthRate(growthRateTotal);

        // 合计本月使用量
        BigDecimal thisMonthUsageTotal = thisMonthUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisMonthUsage(thisMonthUsageTotal);
        // 合计本省本月使用量
        BigDecimal thisProvinceThisMonthUsageTotal = thisProvinceThisMonthUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisProvinceThisMonthUsage(thisProvinceThisMonthUsageTotal);
        // 合计本省累计使用量
        BigDecimal thisProvinceAccumulativeUsageTotal = thisProvinceAccumulativeUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisProvinceAccumulativeUsage(thisProvinceAccumulativeUsageTotal);
        // 合计外省本月使用量
        BigDecimal otherProvinceThisMonthUsageTotal = otherProvinceThisMonthUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setOtherProvinceThisMonthUsage(otherProvinceThisMonthUsageTotal);
        // 合计外省累计使用量
        BigDecimal  otherProvinceAccumulativeUsageTotal = otherProvinceAccumulativeUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setOtherProvinceAccumulativeUsage(otherProvinceAccumulativeUsageTotal);
        totalVo.setUnitName(ReportConstant.TOTAL);
        totalValues.add(totalVo);
        dataMap.put(ReportConstant.TOTAL,totalValues);
        bulkCementThreeCityUsageDataQueryDetailVO.setBulkCementThreeCityUsageDataMap(dataMap);
    }

    private void getConcreteSupplyDataQueryDetailVo(Map<String, Object> dataMap, Boolean flag, LocalDateTime reportMonth, ResConcreteSupplyDataQueryDetailVO concreteSupplyDataQueryDetailVo, Long regionId) {

        // 统计各字段合计值
        // 合计三类指导目标
        List<BigDecimal> threeCategoryGuidGoalTotalList = Lists.newArrayList();
        // 合计生产企业数量
        List<Integer> productionCompanyNumsTotalList = Lists.newArrayList();
        // 合计年设计生产能力
        List<BigDecimal> annualDesignProductionCapacityTotalList = Lists.newArrayList();
        // 合计本月实际产量
        List<BigDecimal> thisMonthOutputTotalList = Lists.newArrayList();
        // 合计累计实际产量
        List<BigDecimal> accumulativeOutputTotalList = Lists.newArrayList();
        // 合计本月使用散装水泥量
        List<BigDecimal> thisMonthCementUsageTotalList = Lists.newArrayList();
        // 合计累计使用散装水泥量
        List<BigDecimal> cementAccumulativeUsageTotalList = Lists.newArrayList();
        // 合计本月废弃物综合利用量
        List<BigDecimal> thisMonthWasteUtilizationTotalList = Lists.newArrayList();
        // 合计累计废弃物综合利用量
        List<BigDecimal> accumulativeWasteUtilizationTotalList = Lists.newArrayList();

        // 对于市级散办，map中只有一个键值对，统计的是该市各区县对应字段的集合
        // 对于省散办，map中对应各市键值对，统计的是各个市下各区县对应字段的集合
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            List<ResConcreteSupplyDataUploadDetailVO> value = (List<ResConcreteSupplyDataUploadDetailVO>)entry.getValue();
            // 筛选出为市合计数据的那条记录(市散办有一条、省散办中有多个)
            List<ResConcreteSupplyDataUploadDetailVO> totalDataList = value.stream().filter(v -> Boolean.TRUE.equals(v.getIsCityTotalData())).collect(Collectors.toList());
            // 三类指导目标
            List<BigDecimal> data1List = totalDataList.stream().map(ResConcreteSupplyDataUploadDetailVO::getThreeCategoryGuidGoalTotal).collect(Collectors.toList());
            threeCategoryGuidGoalTotalList.addAll(data1List);
            // 生产企业数量
            List<Integer> data2List = totalDataList.stream().map(ResConcreteSupplyDataUploadDetailVO::getProductionCompanyNumsTotal).collect(Collectors.toList());
            productionCompanyNumsTotalList.addAll(data2List);
            // 年设计生产能力
            List<BigDecimal> data3List = totalDataList.stream().map(ResConcreteSupplyDataUploadDetailVO::getAnnualDesignProductionCapacityTotal).collect(Collectors.toList());
            annualDesignProductionCapacityTotalList.addAll(data3List);
            // 本月实际产量
            List<BigDecimal> data4List = totalDataList.stream().map(ResConcreteSupplyDataUploadDetailVO::getThisMonthOutputTotal).collect(Collectors.toList());
            thisMonthOutputTotalList.addAll(data4List);
            // 累计实际产量
            List<BigDecimal> data5List = totalDataList.stream().map(ResConcreteSupplyDataUploadDetailVO::getAccumulativeOutputTotal).collect(Collectors.toList());
            accumulativeOutputTotalList.addAll(data5List);

            // 本月使用散装水泥量
            List<BigDecimal> data6List = totalDataList.stream().map(ResConcreteSupplyDataUploadDetailVO::getThisMonthCementUsageTotal).collect(Collectors.toList());
            thisMonthCementUsageTotalList.addAll(data6List);
            // 累计使用散装水泥量
            List<BigDecimal> data7List = totalDataList.stream().map(ResConcreteSupplyDataUploadDetailVO::getCementAccumulativeUsageTotal).collect(Collectors.toList());
            cementAccumulativeUsageTotalList.addAll(data7List);
            // 本月废弃物综合利用量
            List<BigDecimal> data8List = totalDataList.stream().map(ResConcreteSupplyDataUploadDetailVO::getThisMonthWasteUtilizationTotal).collect(Collectors.toList());
            thisMonthWasteUtilizationTotalList.addAll(data8List);
            // 累计废弃物综合利用量
            List<BigDecimal> data9List = totalDataList.stream().map(ResConcreteSupplyDataUploadDetailVO::getAccumulativeWasteUtilizationTotal).collect(Collectors.toList());
            accumulativeWasteUtilizationTotalList.addAll(data9List);

        }
        List<ResConcreteSupplyDataUploadDetailVO> totalValues = Lists.newArrayList();
        ResConcreteSupplyDataUploadDetailVO totalVo = new ResConcreteSupplyDataUploadDetailVO();

        // 合计三类指导目标
        BigDecimal threeCategoryGuidGoalTotal = threeCategoryGuidGoalTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThreeCategoryGuidGoal(threeCategoryGuidGoalTotal);
        // 合计生产企业数量
        int productionCompanyNumsTotal = productionCompanyNumsTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setProductionCompanyNums(productionCompanyNumsTotal);
        // 合计年设计生产能力
        BigDecimal annualDesignProductionCapacityTotal = annualDesignProductionCapacityTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setAnnualDesignProductionCapacity(annualDesignProductionCapacityTotal);
        // 合计本月实际产量
        BigDecimal thisMonthOutputTotal = thisMonthOutputTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisMonthOutput(thisMonthOutputTotal);
        // 合计累计实际产量
        BigDecimal accumulativeOutputTotal = accumulativeOutputTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setAccumulativeOutput(accumulativeOutputTotal);

        // 合计本月使用散装水泥量
        BigDecimal thisMonthCementUsageTotal = thisMonthCementUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisMonthCementUsage(thisMonthCementUsageTotal);
        // 合计累计使用散装水泥量
        BigDecimal cementAccumulativeUsageTotal = cementAccumulativeUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setCementAccumulativeUsage(cementAccumulativeUsageTotal);
        // 合计本月废弃物综合利用量
        BigDecimal thisMonthWasteUtilizationTotal = thisMonthWasteUtilizationTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisMonthWasteUtilization(thisMonthWasteUtilizationTotal);
        // 合计累计废弃物综合利用量
        BigDecimal accumulativeWasteUtilizationTotal = accumulativeWasteUtilizationTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setAccumulativeWasteUtilization(accumulativeWasteUtilizationTotal);
        totalVo.setUnitName(ReportConstant.TOTAL);
        totalValues.add(totalVo);
        dataMap.put(ReportConstant.TOTAL,totalValues);
        concreteSupplyDataQueryDetailVo.setConcreteSupplyDataMap(dataMap);
    }
    private void getMortarSupplyDataQueryDetailVo(Map<String, Object> dataMap, Boolean flag, LocalDateTime reportMonth, ResMortarSupplyDataQueryDetailVO mortarSupplyDataQueryDetailVo, Long regionId) {

        // 统计各字段合计值
        // 合计二类指导目标
        List<BigDecimal> twoCategoryGuidGoalTotalList = Lists.newArrayList();
        // 合计普通干混砂浆生产企业数量
        List<Integer> dryMixedMortarProductionCompanyNumTotalList = Lists.newArrayList();
        // 合计普通干混砂浆生产总能力
        List<BigDecimal> dryMixedMortarProductiveCapacityTotalList = Lists.newArrayList();
        // 合计普通干混砂浆散装能力
        List<BigDecimal> dryMixedMortarBulkCapacityTotalList = Lists.newArrayList();
        // 合计本月总产量
        List<BigDecimal> thisMonthTotalOutputTotalList = Lists.newArrayList();
        // 合计本月累计总产量
        List<BigDecimal> thisMonthAccumulativeOutputTotalList = Lists.newArrayList();
        // 合计普通干混砂浆本月产量
        List<BigDecimal> dryMixedMortarThisMonthOutputTotalList = Lists.newArrayList();
        // 合计普通干混砂浆累计产量
        List<BigDecimal> dryMixedMortarThisMonthAccumulativeOutputTotalList = Lists.newArrayList();
        // 合计普通干混砂浆同比增长量
        List<BigDecimal> dryMixedMortarIncrementTotalList = Lists.newArrayList();

        // 合计去年这个月普通干混砂浆累计产量
        List<BigDecimal> preYearDryMixedMortarThisMonthAccumulativeOutputTotalList = Lists.newArrayList();

        // 合计普通干混砂浆本月散装量
        List<BigDecimal> dryMixedMortarThisMonthBulkQuantityTotalList = Lists.newArrayList();
        // 合计普通干混砂浆累计散装量
        List<BigDecimal> dryMixedMortarAccumulativeBulkQuantityTotalList = Lists.newArrayList();
        // 合计湿拌砂浆本月产量
        List<BigDecimal> wetMortarThisMonthOutputTotalList = Lists.newArrayList();
        // 合计湿拌砂浆累计产量
        List<BigDecimal> wetMortarAccumulativeOutputTotalList = Lists.newArrayList();
        // 合计散装水泥本月使用量
        List<BigDecimal> bulkCementThisMonthUsageTotalList = Lists.newArrayList();
        // 合计散装水泥累计使用量
        List<BigDecimal> bulkCementAccumulativeUsageTotalList = Lists.newArrayList();
        // 合计废弃物本月综合利用量
        List<BigDecimal> wasteThisMonthComprehensiveUtilizationTotalList = Lists.newArrayList();
        // 合计废弃物累计综合利用量
        List<BigDecimal> wasteAccumulativeComprehensiveUtilizationTotalList = Lists.newArrayList();


        // 对于市级散办，map中只有一个键值对，统计的是该市各区县对应字段的集合
        // 对于省散办，map中对应各市键值对，统计的是各个市下各区县对应字段的集合
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            List<ResMortarSupplyDataUploadDetailVO> value = (List<ResMortarSupplyDataUploadDetailVO>)entry.getValue();
            // 筛选出为市合计数据的那条记录(市散办有一条、省散办中有多个)
            List<ResMortarSupplyDataUploadDetailVO> totalDataList = value.stream().filter(v -> Boolean.TRUE.equals(v.getIsCityTotalData())).collect(Collectors.toList());
            // 二类指导目标
            List<BigDecimal> data1List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getTwoCategoryGuidGoalTotal).collect(Collectors.toList());
            twoCategoryGuidGoalTotalList.addAll(data1List);
            // 普通干混砂浆生产企业数量
            List<Integer> data2List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarProductionCompanyNumTotal).collect(Collectors.toList());
            dryMixedMortarProductionCompanyNumTotalList.addAll(data2List);
            // 普通干混砂浆生产总能力
            List<BigDecimal> data3List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarProductiveCapacityTotal).collect(Collectors.toList());
            dryMixedMortarProductiveCapacityTotalList.addAll(data3List);
            // 普通干混砂浆散装能力
            List<BigDecimal> data4List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarBulkCapacityTotal).collect(Collectors.toList());
            dryMixedMortarBulkCapacityTotalList.addAll(data4List);
            // 本月总产量
            List<BigDecimal> data5List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getThisMonthTotalOutputTotal).collect(Collectors.toList());
            thisMonthTotalOutputTotalList.addAll(data5List);

            // 本月累计总产量
            List<BigDecimal> data6List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getThisMonthAccumulativeOutputTotal).collect(Collectors.toList());
            thisMonthAccumulativeOutputTotalList.addAll(data6List);
            // 普通干混砂浆本月产量
            List<BigDecimal> data7List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarThisMonthOutputTotal).collect(Collectors.toList());
            dryMixedMortarThisMonthOutputTotalList.addAll(data7List);
            // 普通干混砂浆累计产量
            List<BigDecimal> data8List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarThisMonthAccumulativeOutputTotal).collect(Collectors.toList());
            dryMixedMortarThisMonthAccumulativeOutputTotalList.addAll(data8List);
            // 普通干混砂浆同比增长量
            List<BigDecimal> data9List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarIncrementTotal).collect(Collectors.toList());
            dryMixedMortarIncrementTotalList.addAll(data9List);
            // 去年这个月普通干混砂浆累计产量
            List<BigDecimal> data10List = totalDataList.stream().map(r -> {
                BigDecimal dryMixedMortarIncrementTotal = r.getDryMixedMortarIncrementTotal();
                BigDecimal dryMixedMortarGrowthRateTotal = r.getDryMixedMortarGrowthRateTotal();
                if (Objects.nonNull(dryMixedMortarIncrementTotal) && Objects.nonNull(dryMixedMortarGrowthRateTotal)){
                    if (BigDecimal.ZERO.compareTo(dryMixedMortarGrowthRateTotal) != 0){
                        return dryMixedMortarIncrementTotal.divide(dryMixedMortarGrowthRateTotal,RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100L));
                    }
                }
                return BigDecimal.ZERO;
            }).collect(Collectors.toList());
            preYearDryMixedMortarThisMonthAccumulativeOutputTotalList.addAll(data10List);
            // 普通干混砂浆本月散装量
            List<BigDecimal> data11List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarThisMonthBulkQuantityTotal).collect(Collectors.toList());
            dryMixedMortarThisMonthBulkQuantityTotalList.addAll(data11List);
            // 普通干混砂浆累计散装量
            List<BigDecimal> data12List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarAccumulativeBulkQuantityTotal).collect(Collectors.toList());
            dryMixedMortarAccumulativeBulkQuantityTotalList.addAll(data12List);
            // 湿拌砂浆本月产量
            List<BigDecimal> data13List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getWetMortarThisMonthOutputTotal).collect(Collectors.toList());
            wetMortarThisMonthOutputTotalList.addAll(data13List);
            // 湿拌砂浆累计产量
            List<BigDecimal> data14List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getWetMortarAccumulativeOutputTotal).collect(Collectors.toList());
            wetMortarAccumulativeOutputTotalList.addAll(data14List);
            // 散装水泥本月使用量
            List<BigDecimal> data15List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getBulkCementThisMonthUsageTotal).collect(Collectors.toList());
            bulkCementThisMonthUsageTotalList.addAll(data15List);
            // 散装水泥累计使用量
            List<BigDecimal> data16List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getBulkCementAccumulativeUsageTotal).collect(Collectors.toList());
            bulkCementAccumulativeUsageTotalList.addAll(data16List);
            // 废弃物本月综合利用量
            List<BigDecimal> data17List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getWasteThisMonthComprehensiveUtilizationTotal).collect(Collectors.toList());
            wasteThisMonthComprehensiveUtilizationTotalList.addAll(data17List);
            // 废弃物累计综合利用量
            List<BigDecimal> data18List = totalDataList.stream().map(ResMortarSupplyDataUploadDetailVO::getWasteAccumulativeComprehensiveUtilizationTotal).collect(Collectors.toList());
            wasteAccumulativeComprehensiveUtilizationTotalList.addAll(data18List);
        }

        List<ResMortarSupplyDataUploadDetailVO> totalValues = Lists.newArrayList();
        ResMortarSupplyDataUploadDetailVO totalVo = new ResMortarSupplyDataUploadDetailVO();

        // 合计二类指导目标
        BigDecimal twoCategoryGuidGoalTotal = twoCategoryGuidGoalTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setTwoCategoryGuidGoal(twoCategoryGuidGoalTotal);
        // 合计普通干混砂浆生产企业数量
        int dryMixedMortarProductionCompanyNumTotal = dryMixedMortarProductionCompanyNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setDryMixedMortarProductionCompanyNum(dryMixedMortarProductionCompanyNumTotal);
        // 合计普通干混砂浆生产总能力
        BigDecimal dryMixedMortarProductiveCapacityTotal = dryMixedMortarProductiveCapacityTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setDryMixedMortarProductiveCapacity(dryMixedMortarProductiveCapacityTotal);
        // 合计普通干混砂浆散装能力
        BigDecimal dryMixedMortarBulkCapacityTotal = dryMixedMortarBulkCapacityTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setDryMixedMortarBulkCapacity(dryMixedMortarBulkCapacityTotal);
        // 合计本月总产量
        BigDecimal thisMonthTotalOutputTotal = thisMonthTotalOutputTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisMonthTotalOutput(thisMonthTotalOutputTotal);
        // 合计本月累计总产量
        BigDecimal thisMonthAccumulativeOutputTotal = thisMonthAccumulativeOutputTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisMonthAccumulativeOutput(thisMonthAccumulativeOutputTotal);
        // 合计普通干混砂浆本月产量
        BigDecimal dryMixedMortarThisMonthOutputTotal = dryMixedMortarThisMonthOutputTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setDryMixedMortarThisMonthOutput(dryMixedMortarThisMonthOutputTotal);
        // 合计普通干混砂浆累计产量
        BigDecimal dryMixedMortarThisMonthAccumulativeOutputTotal = dryMixedMortarThisMonthAccumulativeOutputTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setDryMixedMortarThisMonthAccumulativeOutput(dryMixedMortarThisMonthAccumulativeOutputTotal);
        // 合计普通干混砂浆同比增长量
        BigDecimal dryMixedMortarIncrementTotal = dryMixedMortarIncrementTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setDryMixedMortarIncrement(dryMixedMortarIncrementTotal);
        // 合计增长率
        BigDecimal preYearDryMixedMortarThisMonthAccumulativeOutputTotal = preYearDryMixedMortarThisMonthAccumulativeOutputTotalList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        BigDecimal dryMixedMortarGrowthRateTotal;
        if (BigDecimal.ZERO.compareTo(preYearDryMixedMortarThisMonthAccumulativeOutputTotal) != 0){
            dryMixedMortarGrowthRateTotal = dryMixedMortarIncrementTotal.divide(preYearDryMixedMortarThisMonthAccumulativeOutputTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100L));
        }else {
            dryMixedMortarGrowthRateTotal = dryMixedMortarIncrementTotal.multiply(BigDecimal.valueOf(100L));
        }
        totalVo.setDryMixedMortarGrowthRate(dryMixedMortarGrowthRateTotal);

        // 合计普通干混砂浆本月散装量
        BigDecimal dryMixedMortarThisMonthBulkQuantityTotal = dryMixedMortarThisMonthBulkQuantityTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setDryMixedMortarThisMonthBulkQuantity(dryMixedMortarThisMonthBulkQuantityTotal);
        // 合计普通干混砂浆累计散装量
        BigDecimal dryMixedMortarAccumulativeBulkQuantityTotal = dryMixedMortarAccumulativeBulkQuantityTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setDryMixedMortarAccumulativeBulkQuantity(dryMixedMortarAccumulativeBulkQuantityTotal);
        // 合计湿拌砂浆本月产量
        BigDecimal wetMortarThisMonthOutputTotal = wetMortarThisMonthOutputTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setWetMortarThisMonthOutput(wetMortarThisMonthOutputTotal);
        // 合计湿拌砂浆累计产量
        BigDecimal wetMortarAccumulativeOutputTotal = wetMortarAccumulativeOutputTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setWetMortarAccumulativeOutput(wetMortarAccumulativeOutputTotal);
        // 合计散装水泥本月使用量
        BigDecimal bulkCementThisMonthUsageTotal = bulkCementThisMonthUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setBulkCementThisMonthUsage(bulkCementThisMonthUsageTotal);
        // 合计散装水泥累计使用量
        BigDecimal bulkCementAccumulativeUsageTotal = bulkCementAccumulativeUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setBulkCementAccumulativeUsage(bulkCementAccumulativeUsageTotal);
        // 合计废弃物本月综合利用量
        BigDecimal wasteThisMonthComprehensiveUtilizationTotal = wasteThisMonthComprehensiveUtilizationTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setWasteThisMonthComprehensiveUtilization(wasteThisMonthComprehensiveUtilizationTotal);
        // 合计废弃物累计综合利用量
        BigDecimal wasteAccumulativeComprehensiveUtilizationTotal = wasteAccumulativeComprehensiveUtilizationTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setWasteAccumulativeComprehensiveUtilization(wasteAccumulativeComprehensiveUtilizationTotal);
        totalVo.setRegionName(ReportConstant.TOTAL);
        totalValues.add(totalVo);
        dataMap.put(ReportConstant.TOTAL,totalValues);
        mortarSupplyDataQueryDetailVo.setMortarSupplyDataMap(dataMap);
    }
    private void getNonProAreasDataQueryDetailVo(Map<String, Object> dataMap, Integer reportYear, ResNonProhibitedAreasDataQueryDetailVO nonProhibitedAreasDataQueryDetailVO, Long regionId) {

        // 统计各字段合计值
        // 合计销售点总数
        List<Integer> salePointAccumulativeNumTotalList = Lists.newArrayList();
        // 合计水泥企业建点数量
        List<Integer> cementCompanyBuildPointNumTotalList = Lists.newArrayList();
        // 合计其他投资建点数量
        List<Integer> otherInvestmentBuildPointNumTotalList = Lists.newArrayList();
        // 合计销售量
        List<BigDecimal> saleVolumeTotalList = Lists.newArrayList();
        // 合计散装水泥罐数量
        List<Integer> bulkCementTankNumTotalList = Lists.newArrayList();

        // 合计散装水泥罐容量
        List<BigDecimal> bulkCementTankCapacityTotalList = Lists.newArrayList();
        // 合计水泥使用量
        List<BigDecimal> cementUsageTotalList = Lists.newArrayList();
        // 合计散装水泥使用量
        List<BigDecimal> bulkCementUsageTotalList = Lists.newArrayList();
        // 合计生产预拌混凝土使用散装水泥量
        List<BigDecimal> readyMixedConcreteBulkCementUsageTotalList = Lists.newArrayList();
        // 合计生产水泥制品使用散装水泥量
        List<BigDecimal> cementProductsBulkCementUsageTotalList = Lists.newArrayList();

        // 合计非禁现区生产预拌混凝土产量
        List<BigDecimal> readyMixedConcreteOutputTotalList = Lists.newArrayList();

        // 对于市级散办，map中只有一个键值对，统计的是该市各区县对应字段的集合
        // 对于省散办，map中对应各市键值对，统计的是各个市下各区县对应字段的集合
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            List<ResNonProhibitedAreasDataUploadDetailVO> value = (List<ResNonProhibitedAreasDataUploadDetailVO>)entry.getValue();
            // 筛选出为市合计数据的那条记录(市散办有一条、省散办中有多个)
            List<ResNonProhibitedAreasDataUploadDetailVO> totalDataList = value.stream().filter(v -> Boolean.TRUE.equals(v.getIsCityTotalData())).collect(Collectors.toList());
            // 销售点总数
            List<Integer> data1List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getSalePointAccumulativeNumTotal).collect(Collectors.toList());
            salePointAccumulativeNumTotalList.addAll(data1List);
            // 水泥企业建点数量
            List<Integer> data2List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getCementCompanyBuildPointNumTotal).collect(Collectors.toList());
            cementCompanyBuildPointNumTotalList.addAll(data2List);
            // 其他投资建点数量
            List<Integer> data3List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getOtherInvestmentBuildPointNumTotal).collect(Collectors.toList());
            otherInvestmentBuildPointNumTotalList.addAll(data3List);
            // 销售量
            List<BigDecimal> data4List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getSaleVolumeTotal).collect(Collectors.toList());
            saleVolumeTotalList.addAll(data4List);
            // 散装水泥罐数量
            List<Integer> data5List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getBulkCementTankNumTotal).collect(Collectors.toList());
            bulkCementTankNumTotalList.addAll(data5List);

            // 散装水泥罐容量
            List<BigDecimal> data6List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getBulkCementTankCapacityTotal).collect(Collectors.toList());
            bulkCementTankCapacityTotalList.addAll(data6List);
            // 水泥使用量
            List<BigDecimal> data7List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getCementUsageTotal).collect(Collectors.toList());
            cementUsageTotalList.addAll(data7List);
            // 散装水泥使用量
            List<BigDecimal> data8List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getBulkCementUsageTotal).collect(Collectors.toList());
            bulkCementUsageTotalList.addAll(data8List);
            // 生产预拌混凝土使用散装水泥量
            List<BigDecimal> data9List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getReadyMixedConcreteBulkCementUsageTotal).collect(Collectors.toList());
            readyMixedConcreteBulkCementUsageTotalList.addAll(data9List);
            // 生产水泥制品使用散装水泥量
            List<BigDecimal> data10List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getCementProductsBulkCementUsageTotal).collect(Collectors.toList());
            cementProductsBulkCementUsageTotalList.addAll(data10List);
            // 非禁现区生产预拌混凝土产量
            List<BigDecimal> data11List = totalDataList.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getReadyMixedConcreteOutputTotal).collect(Collectors.toList());
            readyMixedConcreteOutputTotalList.addAll(data11List);
        }

        List<ResNonProhibitedAreasDataUploadDetailVO> totalValues = Lists.newArrayList();
        ResNonProhibitedAreasDataUploadDetailVO totalVo = new ResNonProhibitedAreasDataUploadDetailVO();

        int salePointAccumulativeNumTotal = salePointAccumulativeNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setSalePointAccumulativeNum(salePointAccumulativeNumTotal);
        int cementCompanyBuildPointNumTotal = cementCompanyBuildPointNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setCementCompanyBuildPointNum(cementCompanyBuildPointNumTotal);
        int otherInvestmentBuildPointNumTotal = otherInvestmentBuildPointNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setOtherInvestmentBuildPointNum(otherInvestmentBuildPointNumTotal);
        BigDecimal saleVolumeTotal = saleVolumeTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setSaleVolume(saleVolumeTotal);
        int bulkCementTankNumTotal = bulkCementTankNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setBulkCementTankNum(bulkCementTankNumTotal);

        BigDecimal bulkCementTankCapacityTotal = bulkCementTankCapacityTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setBulkCementTankCapacity(bulkCementTankCapacityTotal);
        BigDecimal cementUsageTotal = cementUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setCementUsage(cementUsageTotal);
        BigDecimal bulkCementUsageTotal = bulkCementUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setBulkCementUsage(bulkCementUsageTotal);
        BigDecimal readyMixedConcreteBulkCementUsageTotal = readyMixedConcreteBulkCementUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setReadyMixedConcreteBulkCementUsage(readyMixedConcreteBulkCementUsageTotal);
        BigDecimal cementProductsBulkCementUsageTotal = cementProductsBulkCementUsageTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setCementProductsBulkCementUsage(cementProductsBulkCementUsageTotal);

        // 合计散装水泥使用率: 合计散装水泥使用量 / 合计水泥使用量 * 100
        BigDecimal bulkCementUsageRateTotal = bulkCementUsageTotal.divide(cementUsageTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        totalVo.setBulkCementUsageRate(bulkCementUsageRateTotal);

        BigDecimal readyMixedConcreteOutputTotal = readyMixedConcreteOutputTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setReadyMixedConcreteOutput(readyMixedConcreteOutputTotal);
        totalVo.setRegionName(ReportConstant.TOTAL);
        totalValues.add(totalVo);
        dataMap.put(ReportConstant.TOTAL,totalValues);
        nonProhibitedAreasDataQueryDetailVO.setNonProAreasDataMap(dataMap);
    }

    private void getBulkCementLogFacStaDataQueryDetailVo(String key, Map<String, Object> dataMap, Integer reportYear, ResBulkCementLogFacStaDataQueryDetailVO bulkCementLogFacStaDataQueryDetailVo, Long regionId) {

        // 统计各字段合计值
        // 合计年初数量
        List<Integer> yearBeginNumTotalList = Lists.newArrayList();
        // 合计年初容量
        List<BigDecimal> yearBeginCapacityTotalList = Lists.newArrayList();
        // 合计本年新增容量
        List<BigDecimal> thisYearNewAddCapacityTotalList = Lists.newArrayList();
        // 合计本年新增数量
        List<Integer> thisYearNewAddNumTotalList = Lists.newArrayList();
        // 合计本年报废数量
        List<Integer> thisYearScrapNumTotalList = Lists.newArrayList();

        // 合计本年报废容量
        List<BigDecimal> thisYearScrapCapacityTotalList = Lists.newArrayList();
        // 合计年末数量
        List<Integer> yearEndNumTotalList = Lists.newArrayList();
        // 合计年末容量
        List<BigDecimal> yearEndCapacityTotalList = Lists.newArrayList();
        // 合计本年实际作业量
        List<BigDecimal> thisYearWorkAmountTotalList = Lists.newArrayList();

        // 对于市级散办，map中只有一个键值对，统计的是该市各区县对应字段的集合
        // 对于省散办，map中对应各市键值对，统计的是各个市下各区县对应字段的集合
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            List<ResBulkCementLogFacStaDataUploadDetailVO> value = (List<ResBulkCementLogFacStaDataUploadDetailVO>)entry.getValue();
            // 筛选出为市合计数据的那条记录(市散办有一条、省散办中有多个)
            List<ResBulkCementLogFacStaDataUploadDetailVO> totalDataList = value.stream().filter(v -> Boolean.TRUE.equals(v.getIsCityTotalData())).collect(Collectors.toList());
            // 年初数量
            List<Integer> data1List = totalDataList.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getYearBeginNumTotal).collect(Collectors.toList());
            yearBeginNumTotalList.addAll(data1List);
            // 年初容量
            List<BigDecimal> data2List = totalDataList.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getYearBeginCapacityTotal).collect(Collectors.toList());
            yearBeginCapacityTotalList.addAll(data2List);
            // 本年新增容量
            List<BigDecimal> data3List = totalDataList.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getThisYearNewAddCapacityTotal).collect(Collectors.toList());
            thisYearNewAddCapacityTotalList.addAll(data3List);
            // 本年新增数量
            List<Integer> data4List = totalDataList.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getThisYearNewAddNumTotal).collect(Collectors.toList());
            thisYearNewAddNumTotalList.addAll(data4List);
            // 本年报废数量
            List<Integer> data5List = totalDataList.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getThisYearScrapNumTotal).collect(Collectors.toList());
            thisYearScrapNumTotalList.addAll(data5List);

            // 本年报废容量
            List<BigDecimal> data6List = totalDataList.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getThisYearScrapCapacityTotal).collect(Collectors.toList());
            thisYearScrapCapacityTotalList.addAll(data6List);
            // 年末数量
            List<Integer> data7List = totalDataList.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getYearEndNumTotal).collect(Collectors.toList());
            yearEndNumTotalList.addAll(data7List);
            // 年末容量
            List<BigDecimal> data8List = totalDataList.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getYearEndCapacityTotal).collect(Collectors.toList());
            yearEndCapacityTotalList.addAll(data8List);
            // 本年实际作业量
            List<BigDecimal> data9List = totalDataList.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getThisYearWorkAmountTotal).collect(Collectors.toList());
            thisYearWorkAmountTotalList.addAll(data9List);
        }

        List<ResBulkCementLogFacStaDataUploadDetailVO> totalValues = Lists.newArrayList();
        ResBulkCementLogFacStaDataUploadDetailVO totalVo = new ResBulkCementLogFacStaDataUploadDetailVO();
        int yearBeginNumTotal = yearBeginNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setYearBeginNum(yearBeginNumTotal);
        BigDecimal yearBeginCapacityTotal = yearBeginCapacityTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setYearBeginCapacity(yearBeginCapacityTotal);
        BigDecimal thisYearNewAddCapacityTotal = thisYearNewAddCapacityTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisYearNewAddCapacity(thisYearNewAddCapacityTotal);
        int thisYearNewAddNumTotal = thisYearNewAddNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setThisYearNewAddNum(thisYearNewAddNumTotal);
        int thisYearScrapNumTotal = thisYearScrapNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setThisYearScrapNum(thisYearScrapNumTotal);

        BigDecimal thisYearScrapCapacityTotal = thisYearScrapCapacityTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisYearScrapCapacity(thisYearScrapCapacityTotal);
        int yearEndNumTotal = yearEndNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setYearEndNum(yearEndNumTotal);
        BigDecimal yearEndCapacityTotal = yearEndCapacityTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setYearEndCapacity(yearEndCapacityTotal);
        BigDecimal thisYearWorkAmountTotal = thisYearWorkAmountTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisYearWorkAmount(thisYearWorkAmountTotal);
        // 将最终的合计数据也加入dataMap中
        totalVo.setRegionName(ReportConstant.TOTAL);
        totalVo.setFacilityName(key);
        totalVo.setReportYear(reportYear);
        totalValues.add(totalVo);
        dataMap.put(ReportConstant.TOTAL,totalValues);
        bulkCementLogFacStaDataQueryDetailVo.setBulkCementLogFacDataMap(dataMap);
    }

    private void getMaterialLogEquipStaDataQueryDetailVo(String key, Map<String, Object> dataMap, Integer reportYear, ResMaterialLogEquipStaDataQueryDetailVO materialLogEquipStaDataQueryDetailVo, Long regionId) {

        // 统计各字段合计值
        // 合计年初数量
        List<Integer> yearBeginNumTotalList = Lists.newArrayList();
        // 合计年初额定量
        List<BigDecimal> yearBeginNominalRateTotalList = Lists.newArrayList();
        // 合计本年新增额定量
        List<BigDecimal> thisYearNewAddNominalRateTotalList = Lists.newArrayList();
        // 合计本年新增数量
        List<Integer> thisYearNewAddNumTotalList = Lists.newArrayList();
        // 合计本年减少数量
        List<Integer> thisYearDecreaseNumTotalList = Lists.newArrayList();

        // 合计本年减少额定量
        List<BigDecimal> thisYearDecreaseNominalRateTotalList = Lists.newArrayList();
        // 合计年末数量
        List<Integer> yearEndNumTotalList = Lists.newArrayList();
        // 合计年末额定量
        List<BigDecimal> yearEndNominalTotalList = Lists.newArrayList();

        // 对于市级散办，map中只有一个键值对，统计的是该市各区县对应字段的集合
        // 对于省散办，map中对应各市键值对，统计的是各个市下各区县对应字段的集合
        for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
            List<ResMaterialLogEquipStaDataUploadDetailVO> value = (List<ResMaterialLogEquipStaDataUploadDetailVO>)entry.getValue();
            // 筛选出为市合计数据的那条记录(市散办有一条、省散办中有多个)
            List<ResMaterialLogEquipStaDataUploadDetailVO> totalDataList = value.stream().filter(v -> Boolean.TRUE.equals(v.getIsCityTotalData())).collect(Collectors.toList());
            // 年初数量
            List<Integer> data1List = totalDataList.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getYearBeginNumTotal).collect(Collectors.toList());
            yearBeginNumTotalList.addAll(data1List);
            // 年初额定量
            List<BigDecimal> data2List = totalDataList.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getYearBeginNominalRateTotal).collect(Collectors.toList());
            yearBeginNominalRateTotalList.addAll(data2List);
            // 本年新增额定量
            List<BigDecimal> data3List = totalDataList.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getThisYearNewAddNominalRateTotal).collect(Collectors.toList());
            thisYearNewAddNominalRateTotalList.addAll(data3List);
            // 本年新增数量
            List<Integer> data4List = totalDataList.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getThisYearNewAddNumTotal).collect(Collectors.toList());
            thisYearNewAddNumTotalList.addAll(data4List);
            // 本年减少数量
            List<Integer> data5List = totalDataList.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getThisYearDecreaseNumTotal).collect(Collectors.toList());
            thisYearDecreaseNumTotalList.addAll(data5List);

            // 本年减少额定量
            List<BigDecimal> data6List = totalDataList.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getThisYearDecreaseNominalRateTotal).collect(Collectors.toList());
            thisYearDecreaseNominalRateTotalList.addAll(data6List);
            // 年末数量
            List<Integer> data7List = totalDataList.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getYearEndNumTotal).collect(Collectors.toList());
            yearEndNumTotalList.addAll(data7List);
            // 年末额定量
            List<BigDecimal> data8List = totalDataList.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getYearEndNominalTotal).collect(Collectors.toList());
            yearEndNominalTotalList.addAll(data8List);
        }

        List<ResMaterialLogEquipStaDataUploadDetailVO> totalValues = Lists.newArrayList();
        ResMaterialLogEquipStaDataUploadDetailVO totalVo = new ResMaterialLogEquipStaDataUploadDetailVO();
        int yearBeginNumTotal = yearBeginNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setYearBeginNum(yearBeginNumTotal);
        BigDecimal yearBeginCapacityTotal = yearBeginNominalRateTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setYearBeginNominalRate(yearBeginCapacityTotal);
        BigDecimal thisYearNewAddCapacityTotal = thisYearNewAddNominalRateTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisYearNewAddNominalRate(thisYearNewAddCapacityTotal);
        int thisYearNewAddNumTotal = thisYearNewAddNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setThisYearNewAddNum(thisYearNewAddNumTotal);
        int thisYearScrapNumTotal = thisYearDecreaseNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setThisYearDecreaseNum(thisYearScrapNumTotal);

        BigDecimal thisYearScrapCapacityTotal = thisYearDecreaseNominalRateTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setThisYearDecreaseNominalRate(thisYearScrapCapacityTotal);
        int yearEndNumTotal = yearEndNumTotalList.stream().mapToInt(Integer::intValue).sum();
        totalVo.setYearEndNum(yearEndNumTotal);
        BigDecimal yearEndCapacityTotal = yearEndNominalTotalList.stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        totalVo.setYearEndNominal(yearEndCapacityTotal);
        // 将最终的合计数据也加入dataMap中
        totalVo.setRegionName(ReportConstant.TOTAL);
        totalVo.setEquipmentName(key);
        totalVo.setReportYear(reportYear);
        totalValues.add(totalVo);
        dataMap.put(ReportConstant.TOTAL,totalValues);
        materialLogEquipStaDataQueryDetailVo.setMaterialLogEquipDataMap(dataMap);
    }

    private void getDataMap(List<Long> auditDataIdList, Integer auditDataType, Long companyId, Map<String, Object> dataMap, Boolean flag, LocalDateTime reportMonth, Long regionId, Integer queryType) {
        CompanyDTO companyDto = companiesCacheHelper.getById(companyId);
        RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
        BulkCementDirectSystemManage context = (BulkCementDirectSystemManage) AopContext.currentProxy();
        switch (auditDataType) {
            // 散装水泥供应量数据
            case 1:
                assemblyBulkCementSupplyDataMap(context, auditDataIdList, dataMap, flag, reportMonth, regionDto,queryType);
                break;
            // 中转库进出量统计数据
            case 2:
                assemblyBulkCementTransferDataMap(context, auditDataIdList, dataMap, flag, reportMonth,regionDto,queryType);
                break;
            // 温台舟使用量快报数据
            case 3:
                assemblyBulkCementThreeCityUsageDataMap(context,auditDataIdList, dataMap, reportMonth, regionDto,queryType);
                break;
            // 混凝土供应量快报数据
            case 4:
                assemblyConcreteSupplyDataMap(context,auditDataIdList, dataMap, flag, regionDto);
                break;
            // 砂浆供应量快报数据
            case 5:
                assemblyMortarSupplyDataMap(context,auditDataIdList, dataMap, flag,reportMonth, regionDto,queryType);
                break;
            // 非禁现区域散装水泥销售使用情况数据
            case 6:
                assemblyNonProAreasDataMap(context,auditDataIdList, dataMap, flag, regionDto, companyDto);
                break;
            // 散装水泥物流设施统计年报表数据
            case 7:
                assemblyBulkCementLogFacStaDataMap(context,auditDataIdList, dataMap, flag, regionDto);
                break;
            // 散装水泥、预拌砂浆、干混砂浆物流装备统计年报表数据
            case 8:
                assemblyMaterialLogEquipStaDataMap(context,auditDataIdList, dataMap, flag, regionDto);
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + auditDataType);
        }
    }

    private void assemblyMaterialLogEquipStaDataMap(BulkCementDirectSystemManage context, List<Long> auditDataIdList, Map<String, Object> dataMap, Boolean flag, RegionDTO regionDto) {
        // 根据传入的关联数据ID列表，获取相关联的上报数据信息
        // 获取关联数据信息

        LambdaQueryWrapper<BulkCementDirectReportSystemDataRelevance> wrapper = Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class);
        context.buildRelevanceDataMapQuery(wrapper, auditDataIdList);
        List<BulkCementDirectReportSystemDataRelevance> dataList = dataRelevanceService.list(wrapper);
        if (CollUtil.isEmpty(dataList)){
            return;
        }

        Map<Long, BulkCementDirectReportSystemDataRelevance> dataRelevanceMap = dataList.stream().collect(Collectors.toMap(BulkCementDirectReportSystemDataRelevance::getId, v -> v));
        List<Long> dataIdList = Lists.newArrayList();
        for (Long relevanceId : auditDataIdList) {
            BulkCementDirectReportSystemDataRelevance relevance = dataRelevanceMap.get(relevanceId);
            if (Objects.nonNull(relevance) && StringUtils.isNotBlank(relevance.getAuditDataIdList())) {
                String auditDataIdListStr = relevance.getAuditDataIdList();
                List<Long> idList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                dataIdList.addAll(idList);
            }
        }
        Map<Long, MaterialLogisticEquipmentStatisticAnnualReport> materialLogEquipStaAnnualReportMap = materialLogEquipStaAnnualReportService.list(Wrappers.lambdaQuery(MaterialLogisticEquipmentStatisticAnnualReport.class)
                        .in(MaterialLogisticEquipmentStatisticAnnualReport::getId, dataIdList))
                .stream().collect(Collectors.toMap(MaterialLogisticEquipmentStatisticAnnualReport::getId, v -> v));
        List<ResMaterialLogEquipStaDataUploadDetailVO> vos8 = dataIdList.stream().map(a -> {
            ResMaterialLogEquipStaDataUploadDetailVO resVo = new ResMaterialLogEquipStaDataUploadDetailVO();
            MaterialLogisticEquipmentStatisticAnnualReport materialLogEquipStaAnnualReport = materialLogEquipStaAnnualReportMap.get(a);
            if (Objects.nonNull(materialLogEquipStaAnnualReport)) {
                BeanUtils.copyProperties(materialLogEquipStaAnnualReport, resVo);
                // 不为市合计数据
                resVo.setIsCityTotalData(Boolean.FALSE);
            }
            return resVo;
        }).collect(Collectors.toList());
        // 先按装备名称分组
        // 专用汽车
        List<ResMaterialLogEquipStaDataUploadDetailVO> specialVehicleDetailVos = vos8.stream()
                .filter(v -> ReportConstant.SPECIAL_VEHICLE.equals(v.getEquipmentName()))
                .collect(Collectors.toList());
        // 专用船
        List<ResMaterialLogEquipStaDataUploadDetailVO> specialVesselDetailVos = vos8.stream()
                .filter(v -> ReportConstant.SPECIAL_VESSEL.equals(v.getEquipmentName()))
                .collect(Collectors.toList());
        // 散装水泥罐
        List<ResMaterialLogEquipStaDataUploadDetailVO> bulkCementTankDetailVos = vos8.stream()
                .filter(v -> ReportConstant.BULK_CEMENT_TANK.equals(v.getEquipmentName()))
                .collect(Collectors.toList());
        // 混凝土搅拌车
        List<ResMaterialLogEquipStaDataUploadDetailVO> concreteMixerTruckDetailVos = vos8.stream()
                .filter(v -> ReportConstant.CONCRETE_MIXER_TRUCK.equals(v.getEquipmentName()))
                .collect(Collectors.toList());
        // 混凝土泵车
        List<ResMaterialLogEquipStaDataUploadDetailVO> concretePumpTruckDetailVos = vos8.stream()
                .filter(v -> ReportConstant.CONCRETE_PUMP_TRUCK.equals(v.getEquipmentName()))
                .collect(Collectors.toList());
        // 干混砂浆运输车
        List<ResMaterialLogEquipStaDataUploadDetailVO> dryMixMortarTruckDetailVos = vos8.stream()
                .filter(v -> ReportConstant.DRY_MIX_MORTAR_TRUCK.equals(v.getEquipmentName()))
                .collect(Collectors.toList());
        // 干混砂浆移动简仓
        List<ResMaterialLogEquipStaDataUploadDetailVO> dryMixMortarMovingStorageDetailVos = vos8.stream()
                .filter(v -> ReportConstant.DRY_MIX_MORTAR_MOVING_STORAGE.equals(v.getEquipmentName()))
                .collect(Collectors.toList());
        // 干混砂浆背罐车
        List<ResMaterialLogEquipStaDataUploadDetailVO> dryMixMortarBackTankCarDetailVos = vos8.stream()
                .filter(v -> ReportConstant.DRY_MIX_MORTAR_BACK_TANK_CAR.equals(v.getEquipmentName()))
                .collect(Collectors.toList());

        // 计算当前市各设备名称的合计数据，并加入到dataMap对应键值对中的vos中
        ResMaterialLogEquipStaDataUploadDetailVO vo1 = new ResMaterialLogEquipStaDataUploadDetailVO();
        ResMaterialLogEquipStaDataUploadDetailVO vo2 = new ResMaterialLogEquipStaDataUploadDetailVO();
        ResMaterialLogEquipStaDataUploadDetailVO vo3 = new ResMaterialLogEquipStaDataUploadDetailVO();
        ResMaterialLogEquipStaDataUploadDetailVO vo4 = new ResMaterialLogEquipStaDataUploadDetailVO();
        ResMaterialLogEquipStaDataUploadDetailVO vo5 = new ResMaterialLogEquipStaDataUploadDetailVO();
        ResMaterialLogEquipStaDataUploadDetailVO vo6 = new ResMaterialLogEquipStaDataUploadDetailVO();
        ResMaterialLogEquipStaDataUploadDetailVO vo7 = new ResMaterialLogEquipStaDataUploadDetailVO();
        ResMaterialLogEquipStaDataUploadDetailVO vo8 = new ResMaterialLogEquipStaDataUploadDetailVO();

        vo1.setIsCityTotalData(Boolean.TRUE);
        vo2.setIsCityTotalData(Boolean.TRUE);
        vo3.setIsCityTotalData(Boolean.TRUE);
        vo4.setIsCityTotalData(Boolean.TRUE);
        vo5.setIsCityTotalData(Boolean.TRUE);
        vo6.setIsCityTotalData(Boolean.TRUE);
        vo7.setIsCityTotalData(Boolean.TRUE);
        vo8.setIsCityTotalData(Boolean.TRUE);
        CompanyDTO companyDto = companiesCacheHelper.getByName(regionDto.getRegionName() + VehicleContant.ADMIN_COMPANY_NAME);
        vo1.setRegionName(ReportConstant.TOTAL);
        vo2.setRegionName(ReportConstant.TOTAL);
        vo3.setRegionName(ReportConstant.TOTAL);
        vo4.setRegionName(ReportConstant.TOTAL);
        vo5.setRegionName(ReportConstant.TOTAL);
        vo6.setRegionName(ReportConstant.TOTAL);
        vo7.setRegionName(ReportConstant.TOTAL);
        vo8.setRegionName(ReportConstant.TOTAL);
        
        // 统计专用汽车各字段合计值
        Map<String, Object> dataMap1 = MapUtil.newHashMap();
        getCityMaterialLogEquipStaTotalData(specialVehicleDetailVos, vo1);
        specialVehicleDetailVos.add(vo1);
        // 单位名称改成了地区
        dataMap1.put(regionDto.getRegionName(),specialVehicleDetailVos);
        dataMap.put(ReportConstant.SPECIAL_VEHICLE,dataMap1);
        // 统计专用船各字段合计值
        Map<String, Object> dataMap2 = MapUtil.newHashMap();
        getCityMaterialLogEquipStaTotalData(specialVesselDetailVos, vo2);
        specialVesselDetailVos.add(vo2);
        // 单位名称改成了地区
        dataMap2.put(regionDto.getRegionName(),specialVesselDetailVos);
        dataMap.put(ReportConstant.SPECIAL_VESSEL,dataMap2);
        // 统计散装水泥罐各字段合计值
        Map<String, Object> dataMap3 = MapUtil.newHashMap();
        getCityMaterialLogEquipStaTotalData(bulkCementTankDetailVos, vo3);
        bulkCementTankDetailVos.add(vo3);
        // 单位名称改成了地区
        dataMap3.put(regionDto.getRegionName(),bulkCementTankDetailVos);
        dataMap.put(ReportConstant.BULK_CEMENT_TANK,dataMap3);

        // 统计混凝土搅拌车各字段合计值
        Map<String, Object> dataMap4 = MapUtil.newHashMap();
        getCityMaterialLogEquipStaTotalData(concreteMixerTruckDetailVos, vo4);
        concreteMixerTruckDetailVos.add(vo4);
        // 单位名称改成了地区
        dataMap4.put(regionDto.getRegionName(),concreteMixerTruckDetailVos);
        dataMap.put(ReportConstant.CONCRETE_MIXER_TRUCK,dataMap4);
        // 统计混凝土泵车各字段合计值
        Map<String, Object> dataMap5 = MapUtil.newHashMap();
        getCityMaterialLogEquipStaTotalData(concretePumpTruckDetailVos, vo5);
        concretePumpTruckDetailVos.add(vo5);
        // 单位名称改成了地区
        dataMap5.put(regionDto.getRegionName(),concretePumpTruckDetailVos);
        dataMap.put(ReportConstant.CONCRETE_PUMP_TRUCK,dataMap5);
        // 统计干混砂浆运输车各字段合计值
        Map<String, Object> dataMap6 = MapUtil.newHashMap();
        getCityMaterialLogEquipStaTotalData(dryMixMortarTruckDetailVos, vo6);
        dryMixMortarTruckDetailVos.add(vo6);
        // 单位名称改成了地区
        dataMap6.put(regionDto.getRegionName(),dryMixMortarTruckDetailVos);
        dataMap.put(ReportConstant.DRY_MIX_MORTAR_TRUCK,dataMap6);

        // 统计干混砂浆移动简仓各字段合计值
        Map<String, Object> dataMap7 = MapUtil.newHashMap();
        getCityMaterialLogEquipStaTotalData(dryMixMortarMovingStorageDetailVos, vo7);
        dryMixMortarMovingStorageDetailVos.add(vo7);
        // 单位名称改成了地区
        dataMap7.put(regionDto.getRegionName(),concretePumpTruckDetailVos);
        dataMap.put(ReportConstant.DRY_MIX_MORTAR_MOVING_STORAGE,dataMap7);
        // 统计干混砂浆背罐车各字段合计值
        Map<String, Object> dataMap8 = MapUtil.newHashMap();
        getCityMaterialLogEquipStaTotalData(dryMixMortarBackTankCarDetailVos, vo8);
        dryMixMortarBackTankCarDetailVos.add(vo8);
        // 单位名称改成了地区
        dataMap8.put(regionDto.getRegionName(),dryMixMortarBackTankCarDetailVos);
        dataMap.put(ReportConstant.DRY_MIX_MORTAR_BACK_TANK_CAR,dataMap8);
    }
    private void assemblyBulkCementLogFacStaDataMap(BulkCementDirectSystemManage context, List<Long> auditDataIdList, Map<String, Object> dataMap, Boolean flag, RegionDTO regionDto) {
        // 根据传入的关联数据ID列表，获取相关联的上报数据信息
        // 获取关联数据信息

        LambdaQueryWrapper<BulkCementDirectReportSystemDataRelevance> wrapper = Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class);
        context.buildRelevanceDataMapQuery(wrapper, auditDataIdList);
        List<BulkCementDirectReportSystemDataRelevance> dataList = dataRelevanceService.list(wrapper);
        if (CollUtil.isEmpty(dataList)){
            return;
        }

        Map<Long, BulkCementDirectReportSystemDataRelevance> dataRelevanceMap = dataList.stream().collect(Collectors.toMap(BulkCementDirectReportSystemDataRelevance::getId, v -> v));
        List<Long> dataIdList = Lists.newArrayList();
        for (Long relevanceId : auditDataIdList) {
            BulkCementDirectReportSystemDataRelevance relevance = dataRelevanceMap.get(relevanceId);
            if (Objects.nonNull(relevance) && StringUtils.isNotBlank(relevance.getAuditDataIdList())) {
                String auditDataIdListStr = relevance.getAuditDataIdList();
                List<Long> idList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                dataIdList.addAll(idList);
            }
        }
        Map<Long, BulkCementLogisticFacilityStatisticAnnualReport> bulkCementLogFacStaAnnualReportMap = bulkCementLogFacStaAnnualReportService.list(Wrappers.lambdaQuery(BulkCementLogisticFacilityStatisticAnnualReport.class)
                        .in(BulkCementLogisticFacilityStatisticAnnualReport::getId, dataIdList))
                .stream().collect(Collectors.toMap(BulkCementLogisticFacilityStatisticAnnualReport::getId, v -> v));
        List<ResBulkCementLogFacStaDataUploadDetailVO> vos7 = dataIdList.stream().map(a -> {
            ResBulkCementLogFacStaDataUploadDetailVO resVo = new ResBulkCementLogFacStaDataUploadDetailVO();
            BulkCementLogisticFacilityStatisticAnnualReport bulkCementLogFacStaAnnualReport = bulkCementLogFacStaAnnualReportMap.get(a);
            if (Objects.nonNull(bulkCementLogFacStaAnnualReport)) {
                BeanUtils.copyProperties(bulkCementLogFacStaAnnualReport, resVo);
                // 不为市合计数据
                resVo.setIsCityTotalData(Boolean.FALSE);
            }
            return resVo;
        }).collect(Collectors.toList());
        // 先按设备名称分组
        // 发放库
        List<ResBulkCementLogFacStaDataUploadDetailVO> issueLibDetailVos = vos7.stream()
                .filter(v -> ReportConstant.ISSUE_LIBRARY.equals(v.getFacilityName()))
                .collect(Collectors.toList());
        // 中转库
        List<ResBulkCementLogFacStaDataUploadDetailVO> transferLibDetailVos = vos7.stream()
                .filter(v -> ReportConstant.TRANSFER_LIBRARY.equals(v.getFacilityName()))
                .collect(Collectors.toList());
        // 固定接收库
        List<ResBulkCementLogFacStaDataUploadDetailVO> fixRecLibDetailVos = vos7.stream()
                .filter(v -> ReportConstant.FIX_RECEIVE_LIBRARY.equals(v.getFacilityName()))
                .collect(Collectors.toList());

        // 计算当前市各设备名称的合计数据，并加入到dataMap对应键值对中的vos中
        ResBulkCementLogFacStaDataUploadDetailVO vo7 = new ResBulkCementLogFacStaDataUploadDetailVO();
        ResBulkCementLogFacStaDataUploadDetailVO vo8 = new ResBulkCementLogFacStaDataUploadDetailVO();
        ResBulkCementLogFacStaDataUploadDetailVO vo9 = new ResBulkCementLogFacStaDataUploadDetailVO();
        vo7.setIsCityTotalData(Boolean.TRUE);
        vo8.setIsCityTotalData(Boolean.TRUE);
        vo9.setIsCityTotalData(Boolean.TRUE);

        CompanyDTO companyDto = companiesCacheHelper.getByName(regionDto.getRegionName() + VehicleContant.ADMIN_COMPANY_NAME);
        vo7.setRegionName(ReportConstant.TOTAL);
        vo8.setRegionName(ReportConstant.TOTAL);
        vo9.setRegionName(ReportConstant.TOTAL);

        // 统计发放库各字段合计值
        Map<String, Object> dataMap1 = MapUtil.newHashMap();
        getCityBulkCementLogFacStaTotalData(issueLibDetailVos, vo7);
        issueLibDetailVos.add(vo7);
        // 单位名称改成了地区
        dataMap1.put(regionDto.getRegionName(),issueLibDetailVos);
        dataMap.put(ReportConstant.ISSUE_LIBRARY,dataMap1);
        // 统计中转库各字段合计值
        Map<String, Object> dataMap2 = MapUtil.newHashMap();
        getCityBulkCementLogFacStaTotalData(transferLibDetailVos, vo8);
        transferLibDetailVos.add(vo8);
        // 单位名称改成了地区
        dataMap2.put(regionDto.getRegionName(),transferLibDetailVos);
        dataMap.put(ReportConstant.TRANSFER_LIBRARY,dataMap2);
        // 统计固定接收库各字段合计值
        Map<String, Object> dataMap3 = MapUtil.newHashMap();
        getCityBulkCementLogFacStaTotalData(fixRecLibDetailVos, vo9);
        fixRecLibDetailVos.add(vo9);
        // 单位名称改成了地区
        dataMap3.put(regionDto.getRegionName(),fixRecLibDetailVos);
        dataMap.put(ReportConstant.FIX_RECEIVE_LIBRARY,dataMap3);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildRelevanceDataMapQuery(LambdaQueryWrapper<BulkCementDirectReportSystemDataRelevance> wrapper, List<Long> auditDataIdList) {
        wrapper.in(BulkCementDirectReportSystemDataRelevance::getId,auditDataIdList)
                .select(BulkCementDirectReportSystemDataRelevance::getId, BulkCementDirectReportSystemDataRelevance::getAuditDataIdList);
    }

    private void assemblyNonProAreasDataMap(BulkCementDirectSystemManage context, List<Long> auditDataIdList, Map<String, Object> dataMap, Boolean flag, RegionDTO regionDto, CompanyDTO companyDto) {

        LambdaQueryWrapper<NonProhibitedAreasBulkCementSalesUse> wrapper = Wrappers.lambdaQuery(NonProhibitedAreasBulkCementSalesUse.class);
        context.buildNonProAreasDataMapQuery(wrapper, auditDataIdList);
        List<NonProhibitedAreasBulkCementSalesUse> dataList = nonProhibitedAreasBulkCementSalesUseService.list(wrapper);
        if (CollUtil.isEmpty(dataList)){
            return;
        }

        Map<Long, NonProhibitedAreasBulkCementSalesUse> nonProhibitedAreasBulkCementSalesUseMap = dataList.stream().collect(Collectors.toMap(NonProhibitedAreasBulkCementSalesUse::getId, v -> v));
        List<ResNonProhibitedAreasDataUploadDetailVO> vos6 = auditDataIdList.stream().map(a -> {
            ResNonProhibitedAreasDataUploadDetailVO resVo = new ResNonProhibitedAreasDataUploadDetailVO();
            NonProhibitedAreasBulkCementSalesUse nonProhibitedAreasBulkCementSalesUse = nonProhibitedAreasBulkCementSalesUseMap.get(a);
            if (Objects.nonNull(nonProhibitedAreasBulkCementSalesUse)) {
                BeanUtils.copyProperties(nonProhibitedAreasBulkCementSalesUse, resVo);
                // 不为市合计数据
                resVo.setIsCityTotalData(Boolean.FALSE);
            }
            return resVo;
        }).collect(Collectors.toList());
        // 计算当前市的合计数据，并加入到dataMap对应键值对中的vos中
        ResNonProhibitedAreasDataUploadDetailVO vo6 = new ResNonProhibitedAreasDataUploadDetailVO();
        vo6.setIsCityTotalData(Boolean.TRUE);
        vo6.setRegionName(ReportConstant.TOTAL);
        // 统计各字段合计值
        getCityNonProAreasTotalData(vos6, vo6);
        vos6.add(vo6);
        // 单位名称改成了地区
        dataMap.put(regionDto.getRegionName(),vos6);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildNonProAreasDataMapQuery(LambdaQueryWrapper<NonProhibitedAreasBulkCementSalesUse> wrapper, List<Long> auditDataIdList) {
        wrapper.in(NonProhibitedAreasBulkCementSalesUse::getId,auditDataIdList);
    }

    private void assemblyMortarSupplyDataMap(BulkCementDirectSystemManage context, List<Long> auditDataIdList, Map<String, Object> dataMap, Boolean flag, LocalDateTime reportMonth, RegionDTO regionDto, Integer queryType) {

        LambdaQueryWrapper<MortarSupplyBulletin> wrapper = Wrappers.lambdaQuery(MortarSupplyBulletin.class);
        context.buildMortarSupplyDataMapQuery(wrapper, auditDataIdList);
        List<MortarSupplyBulletin> dataList = mortarSupplyBulletinService.list(wrapper);
        if (CollUtil.isEmpty(dataList)){
            return;
        }
        Map<Long, MortarSupplyBulletin> bulkCementSupplyBulletinMap = dataList.stream().collect(Collectors.toMap(MortarSupplyBulletin::getId, v -> v));
        List<ResMortarSupplyDataUploadDetailVO> vos5 = auditDataIdList.stream().map(a -> {
            ResMortarSupplyDataUploadDetailVO resVo = new ResMortarSupplyDataUploadDetailVO();
            MortarSupplyBulletin mortarSupplyBulletin = bulkCementSupplyBulletinMap.get(a);
            if (Objects.nonNull(mortarSupplyBulletin)) {
                BeanUtils.copyProperties(mortarSupplyBulletin, resVo);
                // 不为市合计数据
                resVo.setIsCityTotalData(Boolean.FALSE);
            }
            return resVo;
        }).collect(Collectors.toList());
        // 计算当前市的合计数据，并加入到dataMap对应键值对中的vos中
        ResMortarSupplyDataUploadDetailVO vo5 = new ResMortarSupplyDataUploadDetailVO();
        vo5.setIsCityTotalData(Boolean.TRUE);
        // 如果登录用户是市级散办
        vo5.setRegionName(ReportConstant.TOTAL);
        // 统计各字段合计值
        getCityMortarSupplyTotalData(vos5, vo5,reportMonth,regionDto,queryType);
        vos5.add(vo5);
        CompanyDTO companyDto = companiesCacheHelper.getByName(regionDto.getRegionName() + VehicleContant.ADMIN_COMPANY_NAME);
        // 单位名称改成了地区
        dataMap.put(regionDto.getRegionName(),vos5);
    }
    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildMortarSupplyDataMapQuery(LambdaQueryWrapper<MortarSupplyBulletin> wrapper, List<Long> auditDataIdList) {
        wrapper.in(MortarSupplyBulletin::getId,auditDataIdList);
    }

    private void assemblyConcreteSupplyDataMap(BulkCementDirectSystemManage context, List<Long> auditDataIdList, Map<String, Object> dataMap, Boolean flag, RegionDTO regionDto) {

        LambdaQueryWrapper<ConcreteSupplyBulletin> wrapper = Wrappers.lambdaQuery(ConcreteSupplyBulletin.class);
        context.buildConcreteSupplyDataMapQuery(wrapper, auditDataIdList);
        List<ConcreteSupplyBulletin> dataList = concreteSupplyBulletinService.list(wrapper);
        if (CollUtil.isEmpty(dataList)){
            return;
        }
        Map<Long, ConcreteSupplyBulletin> concreteSupplyBulletinMap = dataList.stream().collect(Collectors.toMap(ConcreteSupplyBulletin::getId, v -> v));
        List<ResConcreteSupplyDataUploadDetailVO> vos4 = auditDataIdList.stream().map(a -> {
            ResConcreteSupplyDataUploadDetailVO resVo = new ResConcreteSupplyDataUploadDetailVO();
            ConcreteSupplyBulletin concreteSupplyBulletin = concreteSupplyBulletinMap.get(a);
            if (Objects.nonNull(concreteSupplyBulletin)) {
                BeanUtils.copyProperties(concreteSupplyBulletin, resVo);
                // 不为市合计数据
                resVo.setIsCityTotalData(Boolean.FALSE);
            }
            return resVo;
        }).collect(Collectors.toList());
        // 计算当前市的合计数据，并加入到dataMap对应键值对中的vos中
        ResConcreteSupplyDataUploadDetailVO vo4 = new ResConcreteSupplyDataUploadDetailVO();
        vo4.setIsCityTotalData(Boolean.TRUE);
        vo4.setUnitName(ReportConstant.TOTAL);
        // 统计各字段合计值
        getCityConcreteSupplyTotalData(vos4, vo4);
        vos4.add(vo4);
        CompanyDTO companyDto = companiesCacheHelper.getByName(regionDto.getRegionName() + VehicleContant.ADMIN_COMPANY_NAME);
        // 单位名称改成了地区
        dataMap.put(regionDto.getRegionName(),vos4);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildConcreteSupplyDataMapQuery(LambdaQueryWrapper<ConcreteSupplyBulletin> wrapper, List<Long> auditDataIdList) {
        wrapper.in(ConcreteSupplyBulletin::getId,auditDataIdList);
    }

    private void assemblyBulkCementThreeCityUsageDataMap(BulkCementDirectSystemManage context, List<Long> auditDataIdList, Map<String, Object> dataMap, LocalDateTime reportMonth, RegionDTO regionDto, Integer queryType) {

        LambdaQueryWrapper<BulkCementThreeCityUsageBulletin> wrapper = Wrappers.lambdaQuery(BulkCementThreeCityUsageBulletin.class);
        context.buildBulkCementThreeCityUsageDataMapQuery(wrapper, auditDataIdList);
        List<BulkCementThreeCityUsageBulletin> dataList = bulkCementThreeCityUsageBulletinService.list(wrapper);
        if (CollUtil.isEmpty(dataList)){
            return;
        }
        Map<Long, BulkCementThreeCityUsageBulletin> bulkCementThreeCityUsageBulletinMap = dataList.stream().collect(Collectors.toMap(BulkCementThreeCityUsageBulletin::getId, v -> v));
        List<ResBulkCementThreeCityUsageDataUploadDetailVO> vos3 = auditDataIdList.stream().map(a -> {
            ResBulkCementThreeCityUsageDataUploadDetailVO resVo = new ResBulkCementThreeCityUsageDataUploadDetailVO();
            BulkCementThreeCityUsageBulletin bulkCementThreeCityUsageBulletin = bulkCementThreeCityUsageBulletinMap.get(a);
            if (Objects.nonNull(bulkCementThreeCityUsageBulletin)) {
                BeanUtils.copyProperties(bulkCementThreeCityUsageBulletin, resVo);
                // 本省本月、外省本月数据需取整返回(其余在数据填报时已经做过处理，数据库中存的就是取整后的值)
                BigDecimal thisProvinceThisMonthUsage = Objects.isNull(resVo.getThisProvinceThisMonthUsage()) ? BigDecimal.ZERO : resVo.getThisProvinceThisMonthUsage();
                resVo.setThisProvinceThisMonthUsage(thisProvinceThisMonthUsage.setScale(0, RoundingMode.HALF_UP));
                BigDecimal otherProvinceThisMonthUsage = Objects.isNull(resVo.getOtherProvinceThisMonthUsage()) ? BigDecimal.ZERO : resVo.getOtherProvinceThisMonthUsage();
                resVo.setThisMonthUsageTotal(otherProvinceThisMonthUsage.setScale(0, RoundingMode.HALF_UP));
                // 不为市合计数据
                resVo.setIsCityTotalData(Boolean.FALSE);
            }
            return resVo;
        }).collect(Collectors.toList());
        // 计算当前市的合计数据，并加入到dataMap对应键值对中的vos中
        ResBulkCementThreeCityUsageDataUploadDetailVO vo3 = new ResBulkCementThreeCityUsageDataUploadDetailVO();
        vo3.setIsCityTotalData(Boolean.TRUE);
        // 如果登录用户是市级散办，单位名称一列为合计
        // 登录用户是省散办不需要单独再加一条合计数据，dataMap中即为三个市各自上报的数据
        vo3.setUnitName(ReportConstant.TOTAL);
        // 统计各字段合计值(与原数据一致，因为市登录用户只有一条数据)
        getCityBulkCementThreeCityUsageTotalData(vos3, vo3,reportMonth,regionDto,queryType);
        vos3.add(vo3);
        CompanyDTO companyDto = companiesCacheHelper.getByName(regionDto.getRegionName() + VehicleContant.ADMIN_COMPANY_NAME);
        // 单位名称改成了地区
        dataMap.put(regionDto.getRegionName(),vos3);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildBulkCementThreeCityUsageDataMapQuery(LambdaQueryWrapper<BulkCementThreeCityUsageBulletin> wrapper, List<Long> auditDataIdList) {
        wrapper.in(BulkCementThreeCityUsageBulletin::getId,auditDataIdList);
    }

    private void assemblyBulkCementTransferDataMap(BulkCementDirectSystemManage context, List<Long> auditDataIdList, Map<String, Object> dataMap, Boolean flag, LocalDateTime reportMonth, RegionDTO regionDTO, Integer queryType) {

        LambdaQueryWrapper<BulkCementTransferBulletin> wrapper = Wrappers.lambdaQuery(BulkCementTransferBulletin.class);
        context.buildBulkCementTransferDataMapQuery(wrapper, auditDataIdList);
        List<BulkCementTransferBulletin> dataList = bulkCementTransferBulletinService.list(wrapper);
        if (CollUtil.isEmpty(dataList)){
            return;
        }
        Map<Long, BulkCementTransferBulletin> bulkCementTransferBulletinMap = dataList.stream().collect(Collectors.toMap(BulkCementTransferBulletin::getId, v -> v));
        List<ResBulkCementTransferDataUploadDetailVO> vos2 = auditDataIdList.stream().map(a -> {
            ResBulkCementTransferDataUploadDetailVO resVo = new ResBulkCementTransferDataUploadDetailVO();
            BulkCementTransferBulletin bulkCementTransferBulletin = bulkCementTransferBulletinMap.get(a);
            if (Objects.nonNull(bulkCementTransferBulletin)) {
                BeanUtils.copyProperties(bulkCementTransferBulletin, resVo);
                // 不为市合计数据
                resVo.setIsCityTotalData(Boolean.FALSE);
            }
            return resVo;
        }).collect(Collectors.toList());
        // 计算当前市的合计数据，并加入到dataMap对应键值对中的vos中
        ResBulkCementTransferDataUploadDetailVO vo2 = new ResBulkCementTransferDataUploadDetailVO();
        vo2.setIsCityTotalData(Boolean.TRUE);
        vo2.setUnitName(ReportConstant.TOTAL);
        // 统计各字段合计值
        getCityBulkCementTransferTotalData(vos2, vo2,reportMonth,regionDTO,queryType);
        vos2.add(vo2);
        CompanyDTO companyDto = companiesCacheHelper.getByName(regionDTO.getRegionName() + VehicleContant.ADMIN_COMPANY_NAME);
        // 单位名称改成了地区
        dataMap.put(regionDTO.getRegionName(),vos2);
    }
    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildBulkCementTransferDataMapQuery(LambdaQueryWrapper<BulkCementTransferBulletin> wrapper, List<Long> auditDataIdList) {
        wrapper.in(BulkCementTransferBulletin::getId,auditDataIdList);
    }

    private void assemblyBulkCementSupplyDataMap(BulkCementDirectSystemManage context, List<Long> auditDataIdList, Map<String, Object> dataMap, Boolean flag, LocalDateTime reportMonth, RegionDTO regionDTO, Integer queryType) {
        LambdaQueryWrapper<BulkCementSupplyBulletin> wrapper = Wrappers.lambdaQuery(BulkCementSupplyBulletin.class);
        context.buildBulkCementSupplyDataMapQuery(wrapper, auditDataIdList);
        List<BulkCementSupplyBulletin> dataList = bulkCementSupplyBulletinService.list(wrapper);
        if (CollUtil.isEmpty(dataList)){
            return;
        }
        Map<Long, BulkCementSupplyBulletin> bulkCementSupplyBulletinMap = dataList.stream().collect(Collectors.toMap(BulkCementSupplyBulletin::getId, v -> v));
        List<ResBulkCementSupplyDataUploadDetailVO> vos1 = auditDataIdList.stream().map(a -> {
            ResBulkCementSupplyDataUploadDetailVO resVo = new ResBulkCementSupplyDataUploadDetailVO();
            BulkCementSupplyBulletin bulkCementSupplyBulletin = bulkCementSupplyBulletinMap.get(a);
            if (Objects.nonNull(bulkCementSupplyBulletin)) {
                BeanUtils.copyProperties(bulkCementSupplyBulletin, resVo);
                // 不为市合计数据
                resVo.setIsCityTotalData(Boolean.FALSE);
            }
            return resVo;
        }).collect(Collectors.toList());
        // 计算当前市的合计数据，并加入到dataMap对应键值对中的vos中
        ResBulkCementSupplyDataUploadDetailVO vo1 = new ResBulkCementSupplyDataUploadDetailVO();
        vo1.setIsCityTotalData(Boolean.TRUE);
        // 如果登录用户是市级散办
        vo1.setUnitName(ReportConstant.TOTAL);
        // 如果是省散办查询页面，需要返回查询上报月份所在年份各市设定的散装率目标
        if (Boolean.TRUE.equals(flag)) {
            int year = reportMonth.getYear();
            BulkCementDirectReportSystemUniversalIndex universalIndex = universalIndexService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemUniversalIndex.class)
                    .eq(BulkCementDirectReportSystemUniversalIndex::getYear, year)
                    .eq(BulkCementDirectReportSystemUniversalIndex::getRegionId, regionDTO.getId()));
            if (Objects.nonNull(universalIndex)){
                vo1.setBulkRateTarget(universalIndex.getBulkRateTarget());
            }
        }
        // 统计各字段合计值
        getCityBulkCementSupplyTotalData(vos1, vo1,reportMonth,regionDTO,queryType);
        vos1.add(vo1);
        CompanyDTO companyDto = companiesCacheHelper.getByName(regionDTO.getRegionName() + VehicleContant.ADMIN_COMPANY_NAME);
        // 单位名称改成了地区
        dataMap.put(regionDTO.getRegionName(),vos1);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildBulkCementSupplyDataMapQuery(LambdaQueryWrapper<BulkCementSupplyBulletin> wrapper, List<Long> auditDataIdList) {
        wrapper.in(BulkCementSupplyBulletin::getId, auditDataIdList);
    }

    private void getCityBulkCementSupplyTotalData(List<ResBulkCementSupplyDataUploadDetailVO> vos, ResBulkCementSupplyDataUploadDetailVO vo, LocalDateTime reportMonth, RegionDTO regionDTO, Integer queryType) {
        // 合计散装水泥总量
        List<BigDecimal> bulkCementAmountList = vos.stream().map(ResBulkCementSupplyDataUploadDetailVO::getBulkCementAmount).collect(Collectors.toList());
        // 合计水泥产量
        List<BigDecimal> cementOutputList = vos.stream().map(ResBulkCementSupplyDataUploadDetailVO::getCementOutput).collect(Collectors.toList());
        // 合计完成量
        List<BigDecimal> completedAmountList = vos.stream().map(ResBulkCementSupplyDataUploadDetailVO::getCompletedTotalAmount).collect(Collectors.toList());
        // 合计水泥产量
        List<BigDecimal> cumulativeCementProductionList = vos.stream().map(ResBulkCementSupplyDataUploadDetailVO::getCumulativeCementProduction).collect(Collectors.toList());
        // 合计增加量
        List<BigDecimal> incrementList = vos.stream().map(ResBulkCementSupplyDataUploadDetailVO::getIncrement).collect(Collectors.toList());
        // 去年这个月的合计完成量
        List<Long> childRegionIdList;
        if (QueryTypeEnum.QUERY_LIST.getCode().equals(queryType)) {
            UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();
            Long regionId;
            if (userDetail.getRegionId().equals(DefValConstants.SYSTEM_ID)){
                regionId = DefValConstants.ZJREGION_ID;
            }else {
                regionId = userDetail.getRegionId();
            }
            childRegionIdList = regionsCacheHelper.listChildRegionId(regionId, false, true);
        }else {
            childRegionIdList = regionsCacheHelper.listChildRegionId(regionDTO.getId(), true, true);
        }
        LocalDateTime preYearReportMonth = reportMonth.minusYears(1L);
        List<BulkCementSupplyBulletin> preYearDataList = bulkCementSupplyBulletinService.list(Wrappers.lambdaQuery(BulkCementSupplyBulletin.class)
                .eq(BulkCementSupplyBulletin::getReportMonth, preYearReportMonth)
                .in(BulkCementSupplyBulletin::getRegionId, childRegionIdList));
        List<BigDecimal> preYearCompletedAmountList = preYearDataList.stream().map(BulkCementSupplyBulletin::getCompletedTotalAmount).collect(Collectors.toList());

        BigDecimal bulkCementAmountTotal = bulkCementAmountList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setBulkCementAmountTotal(bulkCementAmountTotal);
        BigDecimal cementOutputTotal = cementOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setCementOutputTotal(cementOutputTotal);
        BigDecimal completedAmountTotal = completedAmountList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setCompletedTotalAmountTotal(completedAmountTotal);
        BigDecimal cumulativeCementProductionTotal = cumulativeCementProductionList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setCumulativeCementProductionTotal(cumulativeCementProductionTotal);
        BigDecimal incrementTotal = incrementList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setIncrementTotal(incrementTotal);
        // 合计散装率: 合计完成量 / 合计水泥产量 * 100
        BigDecimal bulkRateTotal;
        if (BigDecimal.ZERO.compareTo(cumulativeCementProductionTotal) != 0) {
            bulkRateTotal = completedAmountTotal.divide(cumulativeCementProductionTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }else {
            bulkRateTotal = completedAmountTotal.multiply(BigDecimal.valueOf(100L));
        }
        vo.setBulkRateTotal(bulkRateTotal);
        // 合计增长率：合计增长量 / 去年这个月的合计完成量 * 100
        BigDecimal preYearCompletedAmountTotal = preYearCompletedAmountList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        BigDecimal increaseRateTotal;
        if (BigDecimal.ZERO.compareTo(preYearCompletedAmountTotal) != 0) {
            increaseRateTotal = incrementTotal.divide(preYearCompletedAmountTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }else {
            increaseRateTotal = incrementTotal.multiply(BigDecimal.valueOf(100L));
        }
        vo.setIncreaseRateTotal(increaseRateTotal);
    }

    private void getCityBulkCementTransferTotalData(List<ResBulkCementTransferDataUploadDetailVO> vos, ResBulkCementTransferDataUploadDetailVO vo, LocalDateTime reportMonth, RegionDTO regionDTO, Integer queryType) {
        // 合计上月末库存
        List<BigDecimal> lastMonthEndInventoryList = vos.stream().map(ResBulkCementTransferDataUploadDetailVO::getLastMonthEndInventory).collect(Collectors.toList());
        // 合计本月进库量
        List<BigDecimal> thisMonthIncomingStorageList = vos.stream().map(ResBulkCementTransferDataUploadDetailVO::getThisMonthIncomingStorage).collect(Collectors.toList());
        // 合计累计进库量
        List<BigDecimal> cumulativeIncomingStorageList = vos.stream().map(ResBulkCementTransferDataUploadDetailVO::getCumulativeIncomingStorage).collect(Collectors.toList());
        // 合计本月出库量
        List<BigDecimal> thisMonthOutgoingStorageList = vos.stream().map(ResBulkCementTransferDataUploadDetailVO::getThisMonthOutgoingStorage).collect(Collectors.toList());
        // 合计累计出库量
        List<BigDecimal> cumulativeOutgoingStorageList = vos.stream().map(ResBulkCementTransferDataUploadDetailVO::getCumulativeOutgoingStorage).collect(Collectors.toList());
        // 合计库存量
        List<BigDecimal> monthEndInventoryList = vos.stream().map(ResBulkCementTransferDataUploadDetailVO::getMonthEndInventory).collect(Collectors.toList());

        // 去年这个月的合计库存量
        LocalDateTime preYearReportMonth = reportMonth.minusYears(1L);
        List<Long> childRegionIdList = Lists.newArrayList();
        if (QueryTypeEnum.QUERY_LIST.getCode().equals(queryType)) {
            UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();
            Long regionId;
            if (userDetail.getRegionId().equals(DefValConstants.SYSTEM_ID)){
                regionId = DefValConstants.ZJREGION_ID;
            }else {
                regionId = userDetail.getRegionId();
            }
            childRegionIdList = regionsCacheHelper.listChildRegionId(regionId, false, true);
        }else {
            childRegionIdList = regionsCacheHelper.listChildRegionId(regionDTO.getId(), true, true);
        }
        List<BulkCementTransferBulletin> preYearDataList = bulkCementTransferBulletinService.list(Wrappers.lambdaQuery(BulkCementTransferBulletin.class)
                .eq(BulkCementTransferBulletin::getReportMonth, preYearReportMonth)
                .in(BulkCementTransferBulletin::getRegionId, childRegionIdList));
        List<BigDecimal> preYearMonthEndInventoryList = preYearDataList.stream().map(BulkCementTransferBulletin::getMonthEndInventory).collect(Collectors.toList());
        BigDecimal lastMonthEndInventoryTotal = lastMonthEndInventoryList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setLastMonthEndInventoryTotal(lastMonthEndInventoryTotal);
        BigDecimal thisMonthIncomingStorageTotal = thisMonthIncomingStorageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisMonthIncomingStorageTotal(thisMonthIncomingStorageTotal);
        BigDecimal cumulativeIncomingStorageTotal = cumulativeIncomingStorageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setCumulativeIncomingStorageTotal(cumulativeIncomingStorageTotal);
        BigDecimal thisMonthOutgoingStorageTotal = thisMonthOutgoingStorageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisMonthOutgoingStorageTotal(thisMonthOutgoingStorageTotal);
        BigDecimal cumulativeOutgoingStorageTotal = cumulativeOutgoingStorageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setCumulativeOutgoingStorageTotal(cumulativeOutgoingStorageTotal);
        BigDecimal monthEndInventoryTotal = monthEndInventoryList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setMonthEndInventoryTotal(monthEndInventoryTotal);
        // 合计同比增长率：(合计月末库存量 - 去年合计月末库存量) / 去年合计月末库存量 * 100
        BigDecimal preYearMonthEndInventoryTotal = preYearMonthEndInventoryList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        BigDecimal monthEndInventoryGrowthRateTotal = BigDecimal.ZERO;
        if (BigDecimal.ZERO.compareTo(monthEndInventoryTotal) != 0){
            if (BigDecimal.ZERO.compareTo(preYearMonthEndInventoryTotal) != 0) {
                BigDecimal subtract = monthEndInventoryTotal.subtract(preYearMonthEndInventoryTotal);
                monthEndInventoryGrowthRateTotal = subtract.divide(preYearMonthEndInventoryTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100L));
            }else {
                monthEndInventoryGrowthRateTotal = monthEndInventoryTotal.multiply(BigDecimal.valueOf(100L));
            }
        }
        vo.setMonthEndInventoryGrowthRateTotal(monthEndInventoryGrowthRateTotal);
    }

    private void getCityBulkCementThreeCityUsageTotalData(List<ResBulkCementThreeCityUsageDataUploadDetailVO> vos, ResBulkCementThreeCityUsageDataUploadDetailVO vo, LocalDateTime reportMonth, RegionDTO regionDto, Integer queryType) {
        // 合计年目标
        List<BigDecimal> yearTargetList = vos.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getYearTarget).collect(Collectors.toList());
        // 合计占全年目标百分比
        List<BigDecimal> percentageOfAnnualTargetList = vos.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getPercentageOfAnnualTarget).collect(Collectors.toList());
        // 合计本月使用量
        List<BigDecimal> thisMonthUsageList = vos.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getThisMonthUsage).collect(Collectors.toList());
        // 合计累计使用量
        List<BigDecimal> accumulativeUsageList = vos.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getAccumulativeUsage).collect(Collectors.toList());

        // 去年这个月的合计累计使用量
        List<Long> childRegionIdList = Lists.newArrayList();
        if (QueryTypeEnum.QUERY_LIST.getCode().equals(queryType)) {
            UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();
            Long regionId;
            if (userDetail.getRegionId().equals(DefValConstants.SYSTEM_ID)){
                regionId = DefValConstants.ZJREGION_ID;
            }else {
                regionId = userDetail.getRegionId();
            }
            childRegionIdList = regionsCacheHelper.listChildRegionId(regionId, false, true);
        }else {
            childRegionIdList = regionsCacheHelper.listChildRegionId(regionDto.getId(), true, true);;
        }
        LocalDateTime preYearReportMonth = reportMonth.minusYears(1L);
        List<BulkCementThreeCityUsageBulletin> preYearReportMonthDataList = bulkCementThreeCityUsageBulletinService.list(Wrappers.lambdaQuery(BulkCementThreeCityUsageBulletin.class)
                .eq(BulkCementThreeCityUsageBulletin::getReportMonth, preYearReportMonth)
                .in(BulkCementThreeCityUsageBulletin::getRegionId,childRegionIdList));
        List<BigDecimal> preYearAccumulativeUsage = preYearReportMonthDataList.stream().map(BulkCementThreeCityUsageBulletin::getAccumulativeUsage).collect(Collectors.toList());
        // 合计本省本月使用量
        List<BigDecimal> thisProvinceThisMonthUsageList = vos.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getThisProvinceThisMonthUsage).collect(Collectors.toList());
        // 合计本省累计使用量
        List<BigDecimal> thisProvinceAccumulativeUsageList = vos.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getThisProvinceAccumulativeUsage).collect(Collectors.toList());
        // 合计外省本月使用量
        List<BigDecimal> otherProvinceThisMonthUsageList = vos.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getOtherProvinceThisMonthUsage).collect(Collectors.toList());
        // 合计外省累计使用量
        List<BigDecimal> otherProvinceAccumulativeUsageList = vos.stream().map(ResBulkCementThreeCityUsageDataUploadDetailVO::getOtherProvinceAccumulativeUsage).collect(Collectors.toList());

        BigDecimal yearTargetTotal = yearTargetList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setYearTargetTotal(yearTargetTotal);
        BigDecimal percentageOfAnnualTargetTotal = percentageOfAnnualTargetList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setPercentageOfAnnualTargetTotal(percentageOfAnnualTargetTotal);
        BigDecimal thisMonthUsageTotal = thisMonthUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisMonthUsageTotal(thisMonthUsageTotal);
        BigDecimal accumulativeUsageTotal = accumulativeUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setAccumulativeUsageTotal(accumulativeUsageTotal);
        // 合计同比增长率 = (今年合计累计使用量 - 去年合计累计使用量) / 去年合计累计使用量 * 100
        BigDecimal growthRateTotal = BigDecimal.ZERO;
        BigDecimal preYearAccumulativeUsageTotal = preYearAccumulativeUsage.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        if (BigDecimal.ZERO.compareTo(accumulativeUsageTotal) != 0) {
            if (BigDecimal.ZERO.compareTo(preYearAccumulativeUsageTotal) != 0) {
                BigDecimal subtract = accumulativeUsageTotal.subtract(preYearAccumulativeUsageTotal);
                growthRateTotal = subtract.divide(preYearAccumulativeUsageTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100L));
            }else {
                growthRateTotal = accumulativeUsageTotal.multiply(BigDecimal.valueOf(100L));
            }
        }
        vo.setGrowthRateTotal(growthRateTotal);
        BigDecimal thisProvinceThisMonthUsageTotal = thisProvinceThisMonthUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisProvinceThisMonthUsageTotal(thisProvinceThisMonthUsageTotal);
        BigDecimal thisProvinceAccumulativeUsageTotal = thisProvinceAccumulativeUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisProvinceAccumulativeUsageTotal(thisProvinceAccumulativeUsageTotal);
        BigDecimal otherProvinceThisMonthUsageTotal = otherProvinceThisMonthUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setOtherProvinceThisMonthUsageTotal(otherProvinceThisMonthUsageTotal);
        BigDecimal otherProvinceAccumulativeUsageTotal = otherProvinceAccumulativeUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setOtherProvinceAccumulativeUsageTotal(otherProvinceAccumulativeUsageTotal);
    }
    private void getCityConcreteSupplyTotalData(List<ResConcreteSupplyDataUploadDetailVO> vos, ResConcreteSupplyDataUploadDetailVO vo) {
        // 合计三类指导目标
        List<BigDecimal> threeCategoryGuidGoalList = vos.stream().map(ResConcreteSupplyDataUploadDetailVO::getThreeCategoryGuidGoal).collect(Collectors.toList());
        // 合计生产企业数量
        List<Integer> productionCompanyNumsList = vos.stream().map(ResConcreteSupplyDataUploadDetailVO::getProductionCompanyNums).collect(Collectors.toList());
        // 合计年设计生产能力
        List<BigDecimal> annualDesignProductionCapacityList = vos.stream().map(ResConcreteSupplyDataUploadDetailVO::getAnnualDesignProductionCapacity).collect(Collectors.toList());
        // 合计本月实际产量
        List<BigDecimal> thisMonthOutputList = vos.stream().map(ResConcreteSupplyDataUploadDetailVO::getThisMonthOutput).collect(Collectors.toList());
        // 合计累计实际产量
        List<BigDecimal> accumulativeOutputList = vos.stream().map(ResConcreteSupplyDataUploadDetailVO::getAccumulativeOutput).collect(Collectors.toList());
        // 合计本月使用散装水泥量
        List<BigDecimal> thisMonthCementUsageList = vos.stream().map(ResConcreteSupplyDataUploadDetailVO::getThisMonthCementUsage).collect(Collectors.toList());
        // 合计累计使用散装水泥量
        List<BigDecimal> cementAccumulativeUsageList = vos.stream().map(ResConcreteSupplyDataUploadDetailVO::getCementAccumulativeUsage).collect(Collectors.toList());
        // 合计本月废弃物综合利用量
        List<BigDecimal> thisMonthWasteUtilizationList = vos.stream().map(ResConcreteSupplyDataUploadDetailVO::getThisMonthWasteUtilization).collect(Collectors.toList());
        // 合计累计废弃物综合利用量
        List<BigDecimal> accumulativeWasteUtilizationList = vos.stream().map(ResConcreteSupplyDataUploadDetailVO::getAccumulativeWasteUtilization).collect(Collectors.toList());

        BigDecimal threeCategoryGuidGoalTotal = threeCategoryGuidGoalList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThreeCategoryGuidGoalTotal(threeCategoryGuidGoalTotal);
        int productionCompanyNumsTotal = productionCompanyNumsList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setProductionCompanyNumsTotal(productionCompanyNumsTotal);
        BigDecimal annualDesignProductionCapacityTotal = annualDesignProductionCapacityList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setAnnualDesignProductionCapacityTotal(annualDesignProductionCapacityTotal);
        BigDecimal thisMonthOutputTotal = thisMonthOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisMonthOutputTotal(thisMonthOutputTotal);
        BigDecimal accumulativeOutputTotal = accumulativeOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setAccumulativeOutputTotal(accumulativeOutputTotal);
        BigDecimal thisMonthCementUsageTotal = thisMonthCementUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisMonthCementUsageTotal(thisMonthCementUsageTotal);
        BigDecimal cementAccumulativeUsageTotal = cementAccumulativeUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setCementAccumulativeUsageTotal(cementAccumulativeUsageTotal);
        BigDecimal thisMonthWasteUtilizationTotal = thisMonthWasteUtilizationList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisMonthWasteUtilizationTotal(thisMonthWasteUtilizationTotal);
        BigDecimal accumulativeWasteUtilizationTotal = accumulativeWasteUtilizationList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setAccumulativeWasteUtilizationTotal(accumulativeWasteUtilizationTotal);
    }

    private void getCityMortarSupplyTotalData(List<ResMortarSupplyDataUploadDetailVO> vos, ResMortarSupplyDataUploadDetailVO vo, LocalDateTime reportMonth, RegionDTO regionDto, Integer queryType) {
        // 合计二类指导目标
        List<BigDecimal> twoCategoryGuidGoalList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getTwoCategoryGuidGoal).collect(Collectors.toList());
        // 合计普通干混砂浆生产企业数量
        List<Integer> dryMixedMortarProductionCompanyNumList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarProductionCompanyNum).collect(Collectors.toList());
        // 合计普通干混砂浆生产总能力
        List<BigDecimal> dryMixedMortarProductiveCapacityList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarProductiveCapacity).collect(Collectors.toList());
        // 合计普通干混砂浆散装能力
        List<BigDecimal> dryMixedMortarBulkCapacityList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarBulkCapacity).collect(Collectors.toList());
        // 合计本月总产量
        List<BigDecimal> thisMonthTotalOutputList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getThisMonthTotalOutput).collect(Collectors.toList());
        // 合计本月累计总产量
        List<BigDecimal> thisMonthAccumulativeOutputList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getThisMonthAccumulativeOutput).collect(Collectors.toList());
        // 合计普通干混砂浆本月产量
        List<BigDecimal> dryMixedMortarThisMonthOutputList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarThisMonthOutput).collect(Collectors.toList());
        // 合计普通干混砂浆累计产量
        List<BigDecimal> dryMixedMortarThisMonthAccumulativeOutputList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarThisMonthAccumulativeOutput).collect(Collectors.toList());
        // 合计普通干混砂浆同比增长量
        List<BigDecimal> dryMixedMortarIncrementList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarIncrement).collect(Collectors.toList());

        // 合计去年这个月普通干混砂浆累计产量
        LocalDateTime preYearReportMonth = reportMonth.minusYears(1L);
        List<Long> childRegionIdList = Lists.newArrayList();
        if (QueryTypeEnum.QUERY_LIST.getCode().equals(queryType)) {
            UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();
            Long regionId;
            if (userDetail.getRegionId().equals(DefValConstants.SYSTEM_ID)){
                regionId = DefValConstants.ZJREGION_ID;
            }else {
                regionId = userDetail.getRegionId();
            }
            childRegionIdList = regionsCacheHelper.listChildRegionId(regionId, false, true);
        }else {
            childRegionIdList = regionsCacheHelper.listChildRegionId(regionDto.getId(), true, true);
        }
        List<MortarSupplyBulletin> preYearDataList = mortarSupplyBulletinService.list(Wrappers.lambdaQuery(MortarSupplyBulletin.class)
                .eq(MortarSupplyBulletin::getReportMonth, preYearReportMonth)
                .in(MortarSupplyBulletin::getRegionId, childRegionIdList));
        List<BigDecimal> preYearDryMixedMortarThisMonthAccumulativeOutputList = preYearDataList.stream().map(MortarSupplyBulletin::getDryMixedMortarThisMonthAccumulativeOutput).collect(Collectors.toList());

        // 合计普通干混砂浆本月散装量
        List<BigDecimal> dryMixedMortarThisMonthBulkQuantityList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarThisMonthBulkQuantity).collect(Collectors.toList());
        // 合计普通干混砂浆累计散装量
        List<BigDecimal> dryMixedMortarAccumulativeBulkQuantityList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getDryMixedMortarAccumulativeBulkQuantity).collect(Collectors.toList());
        // 合计湿拌砂浆本月产量
        List<BigDecimal> wetMortarThisMonthOutputList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getWetMortarThisMonthOutput).collect(Collectors.toList());
        // 合计湿拌砂浆累计产量
        List<BigDecimal> wetMortarAccumulativeOutputList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getWetMortarAccumulativeOutput).collect(Collectors.toList());
        // 合计散装水泥本月使用量
        List<BigDecimal> bulkCementThisMonthUsageList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getBulkCementThisMonthUsage).collect(Collectors.toList());
        // 合计散装水泥累计使用量
        List<BigDecimal> bulkCementAccumulativeUsageList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getBulkCementAccumulativeUsage).collect(Collectors.toList());
        // 合计废弃物本月综合利用量
        List<BigDecimal> wasteThisMonthComprehensiveUtilizationList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getWasteThisMonthComprehensiveUtilization).collect(Collectors.toList());
        // 合计废弃物累计综合利用量
        List<BigDecimal> wasteAccumulativeComprehensiveUtilizationList = vos.stream().map(ResMortarSupplyDataUploadDetailVO::getWasteAccumulativeComprehensiveUtilization).collect(Collectors.toList());

        BigDecimal twoCategoryGuidGoalTotal = twoCategoryGuidGoalList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setTwoCategoryGuidGoalTotal(twoCategoryGuidGoalTotal);
        int dryMixedMortarProductionCompanyNumTotal = dryMixedMortarProductionCompanyNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setDryMixedMortarProductionCompanyNumTotal(dryMixedMortarProductionCompanyNumTotal);
        BigDecimal dryMixedMortarProductiveCapacityTotal = dryMixedMortarProductiveCapacityList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setDryMixedMortarProductiveCapacityTotal(dryMixedMortarProductiveCapacityTotal);
        BigDecimal dryMixedMortarBulkCapacityTotal = dryMixedMortarBulkCapacityList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setDryMixedMortarBulkCapacityTotal(dryMixedMortarBulkCapacityTotal);

        BigDecimal thisMonthTotalOutputTotal = thisMonthTotalOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisMonthTotalOutputTotal(thisMonthTotalOutputTotal);
        BigDecimal thisMonthAccumulativeOutputTotal = thisMonthAccumulativeOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisMonthAccumulativeOutputTotal(thisMonthAccumulativeOutputTotal);
        BigDecimal dryMixedMortarThisMonthOutputTotal = dryMixedMortarThisMonthOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setDryMixedMortarThisMonthOutputTotal(dryMixedMortarThisMonthOutputTotal);
        BigDecimal dryMixedMortarThisMonthAccumulativeOutputTotal = dryMixedMortarThisMonthAccumulativeOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setDryMixedMortarThisMonthAccumulativeOutputTotal(dryMixedMortarThisMonthAccumulativeOutputTotal);
        BigDecimal dryMixedMortarIncrementTotal = dryMixedMortarIncrementList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setDryMixedMortarIncrementTotal(dryMixedMortarIncrementTotal);
        BigDecimal preYearDryMixedMortarThisMonthAccumulativeOutputTotal = preYearDryMixedMortarThisMonthAccumulativeOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        // 合计普通干混砂浆增长率: 合计普通干混砂浆同比增长量 / 合计去年这个月普通干混砂浆累计产量 * 100
        BigDecimal dryMixedMortarGrowthRateTotal = BigDecimal.ZERO;
        if (BigDecimal.ZERO.compareTo(preYearDryMixedMortarThisMonthAccumulativeOutputTotal) != 0){
            dryMixedMortarGrowthRateTotal = dryMixedMortarIncrementTotal.divide(preYearDryMixedMortarThisMonthAccumulativeOutputTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        }
        vo.setDryMixedMortarGrowthRateTotal(dryMixedMortarGrowthRateTotal);
        BigDecimal dryMixedMortarThisMonthBulkQuantityTotal = dryMixedMortarThisMonthBulkQuantityList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setDryMixedMortarThisMonthBulkQuantityTotal(dryMixedMortarThisMonthBulkQuantityTotal);
        BigDecimal dryMixedMortarAccumulativeBulkQuantityTotal = dryMixedMortarAccumulativeBulkQuantityList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setDryMixedMortarAccumulativeBulkQuantityTotal(dryMixedMortarAccumulativeBulkQuantityTotal);
        BigDecimal wetMortarThisMonthOutputTotal = wetMortarThisMonthOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setWetMortarThisMonthOutputTotal(wetMortarThisMonthOutputTotal);
        BigDecimal wetMortarAccumulativeOutputTotal = wetMortarAccumulativeOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setWetMortarAccumulativeOutputTotal(wetMortarAccumulativeOutputTotal);
        BigDecimal bulkCementThisMonthUsageTotal = bulkCementThisMonthUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setBulkCementThisMonthUsageTotal(bulkCementThisMonthUsageTotal);
        BigDecimal bulkCementAccumulativeUsageTotal = bulkCementAccumulativeUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setBulkCementAccumulativeUsageTotal(bulkCementAccumulativeUsageTotal);
        BigDecimal wasteThisMonthComprehensiveUtilizationTotal = wasteThisMonthComprehensiveUtilizationList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setWasteThisMonthComprehensiveUtilizationTotal(wasteThisMonthComprehensiveUtilizationTotal);
        BigDecimal wasteAccumulativeComprehensiveUtilizationTotal = wasteAccumulativeComprehensiveUtilizationList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setWasteAccumulativeComprehensiveUtilizationTotal(wasteAccumulativeComprehensiveUtilizationTotal);
    }

    private void getCityNonProAreasTotalData(List<ResNonProhibitedAreasDataUploadDetailVO> vos, ResNonProhibitedAreasDataUploadDetailVO vo) {
        // 合计销售点总数
        List<Integer> salePointAccumulativeNumList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getSalePointAccumulativeNum).collect(Collectors.toList());
        // 合计水泥企业建点数量
        List<Integer> cementCompanyBuildPointNumList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getCementCompanyBuildPointNum).collect(Collectors.toList());
        // 合计其他投资建点数量
        List<Integer> otherInvestmentBuildPointNumList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getOtherInvestmentBuildPointNum).collect(Collectors.toList());
        // 合计销售量
        List<BigDecimal> saleVolumeList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getSaleVolume).collect(Collectors.toList());
        // 合计散装水泥罐数量
        List<Integer> bulkCementTankNumList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getBulkCementTankNum).collect(Collectors.toList());

        // 合计散装水泥罐容量
        List<BigDecimal> bulkCementTankCapacityList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getBulkCementTankCapacity).collect(Collectors.toList());
        // 合计水泥使用量
        List<BigDecimal> cementUsageList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getCementUsage).collect(Collectors.toList());
        // 合计散装水泥使用量
        List<BigDecimal> bulkCementUsageList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getBulkCementUsage).collect(Collectors.toList());
        // 合计生产预拌混凝土使用散装水泥量
        List<BigDecimal> readyMixedConcreteBulkCementUsageList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getReadyMixedConcreteBulkCementUsage).collect(Collectors.toList());
        // 合计生产水泥制品使用散装水泥量
        List<BigDecimal> cementProductsBulkCementUsageList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getCementProductsBulkCementUsage).collect(Collectors.toList());

        // 合计非禁现区生产预拌混凝土产量
        List<BigDecimal> readyMixedConcreteOutputList = vos.stream().map(ResNonProhibitedAreasDataUploadDetailVO::getReadyMixedConcreteOutput).collect(Collectors.toList());

        int salePointAccumulativeNumTotal = salePointAccumulativeNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setSalePointAccumulativeNumTotal(salePointAccumulativeNumTotal);
        int cementCompanyBuildPointNumTotal = cementCompanyBuildPointNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setCementCompanyBuildPointNumTotal(cementCompanyBuildPointNumTotal);
        int otherInvestmentBuildPointNumTotal = otherInvestmentBuildPointNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setOtherInvestmentBuildPointNumTotal(otherInvestmentBuildPointNumTotal);
        BigDecimal saleVolumeTotal = saleVolumeList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setSaleVolumeTotal(saleVolumeTotal);
        int bulkCementTankNumTotal = bulkCementTankNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setBulkCementTankNumTotal(bulkCementTankNumTotal);

        BigDecimal bulkCementTankCapacityTotal = bulkCementTankCapacityList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setBulkCementTankCapacityTotal(bulkCementTankCapacityTotal);
        BigDecimal cementUsageTotal = cementUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setCementUsageTotal(cementUsageTotal);
        BigDecimal bulkCementUsageTotal = bulkCementUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setBulkCementUsageTotal(bulkCementUsageTotal);
        BigDecimal readyMixedConcreteBulkCementUsageTotal = readyMixedConcreteBulkCementUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setReadyMixedConcreteBulkCementUsageTotal(readyMixedConcreteBulkCementUsageTotal);
        BigDecimal cementProductsBulkCementUsageTotal = cementProductsBulkCementUsageList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setCementProductsBulkCementUsageTotal(cementProductsBulkCementUsageTotal);

        // 合计散装水泥使用率: 合计散装水泥使用量 / 合计水泥使用量 * 100
        BigDecimal bulkCementUsageRateTotal = bulkCementUsageTotal.divide(cementUsageTotal, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
        vo.setBulkCementUsageRateTotal(bulkCementUsageRateTotal);

        BigDecimal readyMixedConcreteOutputTotal = readyMixedConcreteOutputList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setReadyMixedConcreteOutputTotal(readyMixedConcreteOutputTotal);

    }
    private void getCityBulkCementLogFacStaTotalData(List<ResBulkCementLogFacStaDataUploadDetailVO> vos, ResBulkCementLogFacStaDataUploadDetailVO vo) {
        // 合计年初数量
        List<Integer> yearBeginNumList = vos.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getYearBeginNum).collect(Collectors.toList());
        // 合计年初容量
        List<BigDecimal> yearBeginCapacityList = vos.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getYearBeginCapacity).collect(Collectors.toList());
        // 合计本年新增容量
        List<BigDecimal> thisYearNewAddCapacityList = vos.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getThisYearNewAddCapacity).collect(Collectors.toList());
        // 合计本年新增数量
        List<Integer> thisYearNewAddNumList = vos.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getThisYearNewAddNum).collect(Collectors.toList());
        // 合计本年报废数量
        List<Integer> thisYearScrapNumList = vos.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getThisYearScrapNum).collect(Collectors.toList());

        // 合计本年报废容量
        List<BigDecimal> thisYearScrapCapacityList = vos.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getThisYearScrapCapacity).collect(Collectors.toList());
        // 合计年末数量
        List<Integer> yearEndNumList = vos.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getYearEndNum).collect(Collectors.toList());
        // 合计年末容量
        List<BigDecimal> yearEndCapacityList = vos.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getYearEndCapacity).collect(Collectors.toList());
        // 合计本年实际作业量
        List<BigDecimal> thisYearWorkAmountList = vos.stream().map(ResBulkCementLogFacStaDataUploadDetailVO::getThisYearWorkAmount).collect(Collectors.toList());

        int yearBeginNumTotal = yearBeginNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setYearBeginNumTotal(yearBeginNumTotal);
        BigDecimal yearBeginCapacityTotal = yearBeginCapacityList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setYearBeginCapacityTotal(yearBeginCapacityTotal);
        BigDecimal thisYearNewAddCapacityTotal = thisYearNewAddCapacityList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisYearNewAddCapacityTotal(thisYearNewAddCapacityTotal);
        int thisYearNewAddNumTotal = thisYearNewAddNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setThisYearNewAddNumTotal(thisYearNewAddNumTotal);
        int thisYearScrapNumTotal = thisYearScrapNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setThisYearScrapNumTotal(thisYearScrapNumTotal);

        BigDecimal thisYearScrapCapacityTotal = thisYearScrapCapacityList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisYearScrapCapacityTotal(thisYearScrapCapacityTotal);
        int yearEndNumTotal = yearEndNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setYearEndNumTotal(yearEndNumTotal);
        BigDecimal yearEndCapacityTotal = yearEndCapacityList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setYearEndCapacityTotal(yearEndCapacityTotal);
        BigDecimal thisYearWorkAmountTotal = thisYearWorkAmountList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisYearWorkAmountTotal(thisYearWorkAmountTotal);
    }
    private void getCityMaterialLogEquipStaTotalData(List<ResMaterialLogEquipStaDataUploadDetailVO> vos, ResMaterialLogEquipStaDataUploadDetailVO vo) {
        // 合计年初数量
        List<Integer> yearBeginNumList = vos.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getYearBeginNum).collect(Collectors.toList());
        // 合计年初额定量
        List<BigDecimal> yearBeginNominalRateList = vos.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getYearBeginNominalRate).collect(Collectors.toList());
        // 合计本年新增额定量
        List<BigDecimal> thisYearNewAddNominalRateList = vos.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getThisYearNewAddNominalRate).collect(Collectors.toList());
        // 合计本年新增数量
        List<Integer> thisYearNewAddNumList = vos.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getThisYearNewAddNum).collect(Collectors.toList());
        // 合计本年减少数量
        List<Integer> thisYearDecreaseNumList = vos.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getThisYearDecreaseNum).collect(Collectors.toList());

        // 合计本年减少额定量
        List<BigDecimal> thisYearDecreaseNominalRateList = vos.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getThisYearDecreaseNominalRate).collect(Collectors.toList());
        // 合计年末数量
        List<Integer> yearEndNumList = vos.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getYearEndNum).collect(Collectors.toList());
        // 合计年末额定量
        List<BigDecimal> yearEndNominalList = vos.stream().map(ResMaterialLogEquipStaDataUploadDetailVO::getYearEndNominal).collect(Collectors.toList());

        int yearBeginNumTotal = yearBeginNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setYearBeginNumTotal(yearBeginNumTotal);
        BigDecimal yearBeginNominalRateTotal = yearBeginNominalRateList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setYearBeginNominalRateTotal(yearBeginNominalRateTotal);
        BigDecimal thisYearNewAddNominalRateTotal = thisYearNewAddNominalRateList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisYearNewAddNominalRateTotal(thisYearNewAddNominalRateTotal);
        int thisYearNewAddNumTotal = thisYearNewAddNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setThisYearNewAddNumTotal(thisYearNewAddNumTotal);
        int thisYearDecreaseNumTotal = thisYearDecreaseNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setThisYearDecreaseNumTotal(thisYearDecreaseNumTotal);

        BigDecimal thisYearDecreaseNominalRateTotal = thisYearDecreaseNominalRateList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setThisYearDecreaseNominalRateTotal(thisYearDecreaseNominalRateTotal);
        int yearEndNumTotal = yearEndNumList.stream().filter(Objects::nonNull).mapToInt(Integer::intValue).sum();
        vo.setYearEndNumTotal(yearEndNumTotal);
        BigDecimal yearEndNominalTotal = yearEndNominalList.stream().filter(Objects::nonNull).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        vo.setYearEndNominalTotal(yearEndNominalTotal);
    }

    public String uploadDataQueryModify(ReqDataQueryModifyPO req) {
        UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();
        Long relevanceId = req.getRelevanceId();
        BulkCementDirectReportSystemDataRelevance dataRelevance = dataRelevanceService.getById(relevanceId);
        VUtils.isTrue(Objects.isNull(dataRelevance)).throwMessage("关联数据不存在!");
        dataRelevance.setUnitResponsiblePerson(req.getUnitResponsiblePerson());
        dataRelevance.setPreparer(req.getPreparer());
        dataRelevance.setReviewer(req.getReviewer());
        dataRelevance.setSubmissionDate(req.getSubmissionDate());
        dataRelevance.setUpdateOn(LocalDateTime.now());
        dataRelevance.setUpdateBy(userDetail.getUserId());
        dataRelevanceService.updateById(dataRelevance);
        return "编辑成功";
    }

    public void exportQueryData(ReqDataUploadListPO req, HttpServletResponse response) {

        ResDataQueryDetailVO resDataQueryDetailVo = uploadDataQueryDetail(req);

        Integer auditDataType = req.getAuditDataType();
        String templateName;
        String templatePath;
        List<Object> dtoList = Lists.newArrayList();
        List<Object> bulkCementLogFacStaDto1List = Lists.newArrayList();
        List<Object> bulkCementLogFacStaDto2List = Lists.newArrayList();
        List<Object> bulkCementLogFacStaDto3List = Lists.newArrayList();
        List<Object> materialLogEquipStaDto1List = Lists.newArrayList();
        List<Object> materialLogEquipStaDto2List = Lists.newArrayList();
        List<Object> materialLogEquipStaDto3List = Lists.newArrayList();
        List<Object> materialLogEquipStaDto4List = Lists.newArrayList();
        List<Object> materialLogEquipStaDto5List = Lists.newArrayList();
        List<Object> materialLogEquipStaDto6List = Lists.newArrayList();
        List<Object> materialLogEquipStaDto7List = Lists.newArrayList();
        List<Object> materialLogEquipStaDto8List = Lists.newArrayList();

        File directory = new File("");
        LocalDateTime reportMonth = req.getReportMonth();
        Integer reportYear = req.getReportYear();
        //设置日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日");
        String date;
        String unitResponsiblePerson = StrPool.EMPTY;
        String preparer = StrPool.EMPTY;
        String reviewer = StrPool.EMPTY;
        String submissionDate = StrPool.EMPTY;
        switch (auditDataType) {
            // 散装水泥供应量数据
            case 1:
                if (Objects.nonNull(resDataQueryDetailVo) && Objects.nonNull(resDataQueryDetailVo.getBulkCementSupplyDataVo())) {
                    templateName = ReportConstant.BULK_CEMENT_SUPPLY_TEMPLATE;
                    dtoList = getBulkCementSupplyDtoList(resDataQueryDetailVo);
                }else {
                    templateName = ReportConstant.BULK_CEMENT_SUPPLY_EMPTY_TEMPLATE;
                }
                VUtils.isTrue(Objects.isNull(reportMonth)).throwMessage("请传入上报月份");
                date = sdf.format(NdDateUtils.localDateTime2Date(reportMonth));
                break;
            // 中转库进出量统计数据
            case 2:
                if (Objects.nonNull(resDataQueryDetailVo) && Objects.nonNull(resDataQueryDetailVo.getBulkCementTransferDataVo())) {
                    templateName = ReportConstant.BULK_CEMENT_TRANSFER_TEMPLATE;
                    dtoList = getBulkCementTransferDtoList(resDataQueryDetailVo);
                }else {
                    templateName = ReportConstant.BULK_CEMENT_TRANSFER_EMPTY_TEMPLATE;
                }
                VUtils.isTrue(Objects.isNull(reportMonth)).throwMessage("请传入上报月份");
                date = sdf.format(NdDateUtils.localDateTime2Date(reportMonth));
                break;
            // 温台舟使用量快报数据
            case 3:
                if (Objects.nonNull(resDataQueryDetailVo) && Objects.nonNull(resDataQueryDetailVo.getBulkCementThreeCityUsageDataVo())) {
                    templateName = ReportConstant.BULK_CEMENT_THREE_CITY_USAGE_TEMPLATE;
                    dtoList = getBulkCementThreeCityUsageDtoList(resDataQueryDetailVo);
                }else {
                    templateName = ReportConstant.BULK_CEMENT_THREE_CITY_USAGE_EMPTY_TEMPLATE;
                }
                VUtils.isTrue(Objects.isNull(reportMonth)).throwMessage("请传入上报月份");
                date = sdf.format(NdDateUtils.localDateTime2Date(reportMonth));
                break;
            // 混凝土供应量快报数据
            case 4:
                if (Objects.nonNull(resDataQueryDetailVo) && Objects.nonNull(resDataQueryDetailVo.getConcreteSupplyDataVo())) {
                    templateName = ReportConstant.CONCRETE_SUPPLY_TEMPLATE;
                    dtoList = getConcreteSupplyDtoList(resDataQueryDetailVo);
                }else {
                    templateName = ReportConstant.CONCRETE_SUPPLY_EMPTY_TEMPLATE;
                }
                VUtils.isTrue(Objects.isNull(reportMonth)).throwMessage("请传入上报月份");
                date = sdf.format(NdDateUtils.localDateTime2Date(reportMonth));
                break;
            // 砂浆供应量快报数据
            case 5:
                if (Objects.nonNull(resDataQueryDetailVo) && Objects.nonNull(resDataQueryDetailVo.getMortarSupplyDataVo())) {
                    templateName = ReportConstant.MORTAR_SUPPLY_TEMPLATE;
                    List<Object> dataList = new ArrayList<>();
                    List<MortarSupplyQueryDataExportDTO> mortarSupplyDtoList = getMortarSupplyDtoList(resDataQueryDetailVo);
                    mortarSupplyDtoList.forEach(m -> {
                        LinkedHashMap<String, Object> dataMap = new LinkedHashMap<>();
                        dataMap.put("regionName",m.getRegionName());
                        dataMap.put("twoCategoryGuidGoal",m.getTwoCategoryGuidGoal());
                        dataMap.put("dryMixedMortarProductionCompanyNum",m.getDryMixedMortarProductionCompanyNum());
                        dataMap.put("dryMixedMortarProductiveCapacity",m.getDryMixedMortarProductiveCapacity());
                        dataMap.put("dryMixedMortarBulkCapacity",m.getDryMixedMortarBulkCapacity());
                        dataMap.put("thisMonthTotalOutput",m.getThisMonthTotalOutput());
                        dataMap.put("thisMonthAccumulativeOutput",m.getThisMonthAccumulativeOutput());
                        dataMap.put("dryMixedMortarThisMonthOutput",m.getDryMixedMortarThisMonthOutput());
                        dataMap.put("dryMixedMortarThisMonthAccumulativeOutput",m.getDryMixedMortarThisMonthAccumulativeOutput());
                        dataMap.put("dryMixedMortarIncrement",m.getDryMixedMortarIncrement());
                        dataMap.put("dryMixedMortarGrowthRate",m.getDryMixedMortarGrowthRate());
                        dataMap.put("dryMixedMortarThisMonthBulkQuantity",m.getDryMixedMortarThisMonthBulkQuantity());
                        dataMap.put("dryMixedMortarAccumulativeBulkQuantity",m.getDryMixedMortarAccumulativeBulkQuantity());
                        dataMap.put("wetMortarThisMonthOutput",m.getWetMortarThisMonthOutput());
                        dataMap.put("wetMortarAccumulativeOutput",m.getWetMortarAccumulativeOutput());
                        dataMap.put("bulkCementThisMonthUsage",m.getBulkCementThisMonthUsage());
                        dataMap.put("bulkCementAccumulativeUsage",m.getBulkCementAccumulativeUsage());
                        dataMap.put("wasteAccumulativeComprehensiveUtilization",m.getWasteAccumulativeComprehensiveUtilization());
                        dataList.add(dataMap);
                    });
                    dtoList = dataList;
                }else {
                    templateName = ReportConstant.MORTAR_SUPPLY_EMPTY_TEMPLATE;
                }
                VUtils.isTrue(Objects.isNull(reportMonth)).throwMessage("请传入上报月份");
                date = sdf.format(NdDateUtils.localDateTime2Date(reportMonth));
                break;
            // 非禁现区域散装水泥销售使用情况数据
            case 6:
                if (Objects.nonNull(resDataQueryDetailVo) && Objects.nonNull(resDataQueryDetailVo.getNonProAreasDataVo())) {
                    templateName = ReportConstant.NON_PRO_AREAS_TEMPLATE;
                    dtoList = getNonProAreasDtoList(resDataQueryDetailVo);
                }else {
                    templateName = ReportConstant.NON_PRO_AREAS_EMPTY_TEMPLATE;
                }
                VUtils.isTrue(Objects.isNull(reportYear)).throwMessage("请传入上报年份!");
                date = reportYear + ReportConstant.YEAR;
                ResNonProhibitedAreasDataQueryDetailVO nonProAreasDataVo = resDataQueryDetailVo.getNonProAreasDataVo();
                unitResponsiblePerson = nonProAreasDataVo.getUnitResponsiblePerson();
                preparer = nonProAreasDataVo.getPreparer();
                reviewer = nonProAreasDataVo.getReviewer();
                if (Objects.nonNull(nonProAreasDataVo.getSubmissionDate())) {
                    submissionDate = sdf2.format(NdDateUtils.localDateTime2Date(nonProAreasDataVo.getSubmissionDate()));
                }
                break;
            // 散装水泥物流设施统计年报表数据
            case 7:
                if (Objects.nonNull(resDataQueryDetailVo) && Objects.nonNull(resDataQueryDetailVo.getBulkCementLogFacStaDataVo())) {
                    templateName = ReportConstant.BULK_CEMENT_LOG_FAC_STA_TEMPLATE;
                    // 发放库
                    bulkCementLogFacStaDto1List = getBulkCementLogFacStaDtoList(resDataQueryDetailVo,ReportConstant.ISSUE_LIBRARY);
                    // 中转库
                    bulkCementLogFacStaDto2List = getBulkCementLogFacStaDtoList(resDataQueryDetailVo,ReportConstant.TRANSFER_LIBRARY);
                    // 固定接收库
                    bulkCementLogFacStaDto3List = getBulkCementLogFacStaDtoList(resDataQueryDetailVo,ReportConstant.FIX_RECEIVE_LIBRARY);
                }else {
                    templateName = ReportConstant.BULK_CEMENT_LOG_FAC_STA_EMPTY_TEMPLATE;
                }
                VUtils.isTrue(Objects.isNull(reportYear)).throwMessage("请传入上报年份!");
                date = reportYear + ReportConstant.YEAR;
                ResBulkCementLogFacStaDataQueryVO bulkCementLogFacStaDataVo = resDataQueryDetailVo.getBulkCementLogFacStaDataVo();
                unitResponsiblePerson = bulkCementLogFacStaDataVo.getUnitResponsiblePerson();
                preparer = bulkCementLogFacStaDataVo.getPreparer();
                reviewer = bulkCementLogFacStaDataVo.getReviewer();
                if (Objects.nonNull(bulkCementLogFacStaDataVo.getSubmissionDate())) {
                    submissionDate = sdf2.format(NdDateUtils.localDateTime2Date(bulkCementLogFacStaDataVo.getSubmissionDate()));
                }
                break;
            // 散装水泥、预拌砂浆、干混砂浆物流装备统计年报表数据
            case 8:
                if (Objects.nonNull(resDataQueryDetailVo) && Objects.nonNull(resDataQueryDetailVo.getMaterialLogEquipStaDataVo())) {
                    templateName = ReportConstant.MATERIAL_LOG_EQUIP_STA_TEMPLATE;
                    // 专用汽车
                    materialLogEquipStaDto1List = getMaterialLogEquipStaDtoList(resDataQueryDetailVo,ReportConstant.SPECIAL_VEHICLE);
                    // 专用船
                    materialLogEquipStaDto2List = getMaterialLogEquipStaDtoList(resDataQueryDetailVo,ReportConstant.SPECIAL_VESSEL);
                    // 散装水泥罐
                    materialLogEquipStaDto3List = getMaterialLogEquipStaDtoList(resDataQueryDetailVo,ReportConstant.BULK_CEMENT_TANK);
                    // 混凝土搅拌车
                    materialLogEquipStaDto4List = getMaterialLogEquipStaDtoList(resDataQueryDetailVo,ReportConstant.CONCRETE_MIXER_TRUCK);
                    // 混凝土泵车
                    materialLogEquipStaDto5List = getMaterialLogEquipStaDtoList(resDataQueryDetailVo,ReportConstant.CONCRETE_PUMP_TRUCK);
                    // 干混砂浆运输车
                    materialLogEquipStaDto6List = getMaterialLogEquipStaDtoList(resDataQueryDetailVo,ReportConstant.DRY_MIX_MORTAR_TRUCK);
                    // 干混砂浆移动简仓
                    materialLogEquipStaDto7List = getMaterialLogEquipStaDtoList(resDataQueryDetailVo,ReportConstant.DRY_MIX_MORTAR_MOVING_STORAGE);
                    // 干混砂浆背罐车
                    materialLogEquipStaDto8List = getMaterialLogEquipStaDtoList(resDataQueryDetailVo,ReportConstant.DRY_MIX_MORTAR_BACK_TANK_CAR);
                }else {
                    templateName = ReportConstant.MATERIAL_LOG_EQUIP_STA_EMPTY_TEMPLATE;
                }
                VUtils.isTrue(Objects.isNull(reportYear)).throwMessage("请传入上报年份!");
                date = reportYear + ReportConstant.YEAR;
                ResMaterialLogEquipStaDataQueryVO materialLogEquipStaDataVo = resDataQueryDetailVo.getMaterialLogEquipStaDataVo();
                unitResponsiblePerson = materialLogEquipStaDataVo.getUnitResponsiblePerson();
                preparer = materialLogEquipStaDataVo.getPreparer();
                reviewer = materialLogEquipStaDataVo.getReviewer();
                if (Objects.nonNull(materialLogEquipStaDataVo.getSubmissionDate())) {
                    submissionDate = sdf2.format(NdDateUtils.localDateTime2Date(materialLogEquipStaDataVo.getSubmissionDate()));
                }
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + auditDataType);
        }
        templatePath = directory.getAbsolutePath() + File.separator + "template" + File.separator + templateName + ".xls";
        // 获取本地目录的Excel模板
        TemplateExportParams temp = new TemplateExportParams(templatePath);
        temp.setSheetNum(new Integer[] {0});
        temp.setSheetName(new String[] {templateName});
        Map<String, Object> map = new HashMap<>(4);
        map.put("date", date);
        map.put("unitResponsiblePerson", unitResponsiblePerson);
        map.put("preparer", preparer);
        map.put("reviewer", reviewer);
        map.put("submissionDate", submissionDate);
        if (UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode().equals(auditDataType)){
            map.put("map1List", bulkCementLogFacStaDto1List);
            map.put("map2List", bulkCementLogFacStaDto2List);
            map.put("map3List", bulkCementLogFacStaDto3List);
        } else if (UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode().equals(auditDataType)) {
            map.put("map1List", materialLogEquipStaDto1List);
            map.put("map2List", materialLogEquipStaDto2List);
            map.put("map3List", materialLogEquipStaDto3List);
            map.put("map4List", materialLogEquipStaDto4List);
            map.put("map5List", materialLogEquipStaDto5List);
            map.put("map6List", materialLogEquipStaDto6List);
            map.put("map7List", materialLogEquipStaDto7List);
            map.put("map8List", materialLogEquipStaDto8List);
        } else {
            map.put("mapList", dtoList);
        }
        Workbook workbook = ExcelExportUtil.exportExcel(temp, map);
        if (!UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode().equals(auditDataType) &&
                !UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode().equals(auditDataType) &&
                CollUtil.isEmpty(dtoList)) {
            // 输出空模板
            // 获取本地目录的空Excel模板
            try {
                InputStream templateInputStream = this.getClass().getClassLoader().getResourceAsStream("template" + File.separator + templateName + ".xlsx");
                OutputStream outputStream = response.getOutputStream();
                // 设置要下载的文件的名称
                ExcelDownUtil.setFileName(templateName, response);
                // 设置文件的MIME类型
                response.setContentType("application/vnd.ms-excel;charset=UTF-8");

                byte[] b = new byte[2048];
                int len;
                while ((len = templateInputStream.read(b)) != -1) {
                    outputStream.write(b, 0, len);
                }
                templateInputStream.close();
                outputStream.flush();
                outputStream.close();
            } catch (IOException e) {
                throw new BizException("读取模板失败!");
            }
            return;
        }
        if (workbook == null){
            throw new BizException("读取编辑表模板失败!");
        }
        // 重置响应对象
        response.reset();
        try {
            response.setHeader("Content-disposition",
                    "attachment;filename*=utf-8''" + URLEncoder.encode(Objects.requireNonNull(templateName), "UTF-8") + ".xlsx");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        response.setContentType(ExcelUtil.XLS_CONTENT_TYPE);
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        // 写出数据输出流到页面
        try {
            OutputStream output = response.getOutputStream();
            BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
            workbook.write(bufferedOutPut);
            bufferedOutPut.flush();
            bufferedOutPut.close();
            output.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private List<Object> getMaterialLogEquipStaDtoList(ResDataQueryDetailVO resDataQueryDetailVo,String key) {
        List<Object> dtoList;
        ResMaterialLogEquipStaDataQueryVO materialLogEquipStaDataQueryVo = resDataQueryDetailVo.getMaterialLogEquipStaDataVo();
        Map<String, Object> materialLogEquipStaDataMap = materialLogEquipStaDataQueryVo.getMaterialLogEquipStaDataMap();

        List<ResMaterialLogEquipStaDataUploadDetailVO> dataList = Lists.newArrayList();
        // materialLogEquipStaDataMap为以装备名称为key的8组map值
        ResMaterialLogEquipStaDataQueryDetailVO detailVo = (ResMaterialLogEquipStaDataQueryDetailVO) materialLogEquipStaDataMap.get(key);
        Map<String, Object> dataMap = detailVo.getMaterialLogEquipDataMap();
        Set<Map.Entry<String, Object>> entries = dataMap.entrySet().stream()
                .filter(e -> !ReportConstant.TOTAL.equals(e.getKey())).collect(Collectors.toSet());
        List<ResMaterialLogEquipStaDataUploadDetailVO> values = (List<ResMaterialLogEquipStaDataUploadDetailVO>) dataMap.get(ReportConstant.TOTAL);
        dataList.add(values.get(0));
        // 如果是市级散办，map中只有一个键值对，且包含合计的数据
        // 如果是省散办，entries中有多个键值对，且包含合计的数据
        for (Map.Entry<String, Object> entry : entries) {
            List<ResMaterialLogEquipStaDataUploadDetailVO> value = (List<ResMaterialLogEquipStaDataUploadDetailVO>) entry.getValue();
            List<ResMaterialLogEquipStaDataUploadDetailVO> vos = value.stream().filter(v -> !ReportConstant.TOTAL.equals(v.getRegionName())).collect(Collectors.toList());
            String cityNameKey = entry.getKey();
            ResMaterialLogEquipStaDataUploadDetailVO totalVo = new ResMaterialLogEquipStaDataUploadDetailVO();
            ResMaterialLogEquipStaDataUploadDetailVO vo = value.stream().filter(v -> ReportConstant.TOTAL.equals(v.getRegionName())).collect(Collectors.toList()).get(0);
            totalVo.setRegionName(cityNameKey);
            totalVo.setYearBeginNum(vo.getYearBeginNumTotal());
            totalVo.setYearBeginNominalRate(vo.getYearBeginNominalRateTotal());
            totalVo.setThisYearNewAddNum(vo.getThisYearNewAddNumTotal());
            totalVo.setThisYearNewAddNominalRate(vo.getThisYearNewAddNominalRateTotal());
            totalVo.setThisYearDecreaseNum(vo.getThisYearDecreaseNumTotal());
            totalVo.setThisYearDecreaseNominalRate(vo.getThisYearDecreaseNominalRateTotal());
            totalVo.setYearEndNum(vo.getYearEndNumTotal());
            totalVo.setYearEndNominal(vo.getYearEndNominalTotal());
            totalVo.setRemark(vo.getRemark());
            dataList.add(totalVo);
            dataList.addAll(vos);
        }
        dtoList = dataList.stream().map(d -> {
            MaterialLogEquipStaQueryDataExportDTO exportDto = new MaterialLogEquipStaQueryDataExportDTO();
            BeanUtils.copyProperties(d, exportDto);
            return exportDto;
        }).collect(Collectors.toList());
        return dtoList;
    }
    private List<Object> getBulkCementLogFacStaDtoList(ResDataQueryDetailVO resDataQueryDetailVo, String key) {
        List<Object> dtoList = Lists.newArrayList();
        ResBulkCementLogFacStaDataQueryVO bulkCementLogFacStaDataQueryVo = resDataQueryDetailVo.getBulkCementLogFacStaDataVo();
        Map<String, Object> bulkCementLogFacStaDataMap = bulkCementLogFacStaDataQueryVo.getBulkCementLogFacStaDataMap();

        List<ResBulkCementLogFacStaDataUploadDetailVO> dataList = Lists.newArrayList();
        // bulkCementLogFacStaDataMap为以设备名称为key的三组map值
        ResBulkCementLogFacStaDataQueryDetailVO detailVo = (ResBulkCementLogFacStaDataQueryDetailVO) bulkCementLogFacStaDataMap.get(key);
        Map<String, Object> dataMap = detailVo.getBulkCementLogFacDataMap();
        Set<Map.Entry<String, Object>> entries = dataMap.entrySet().stream()
                .filter(e -> !ReportConstant.TOTAL.equals(e.getKey())).collect(Collectors.toSet());
        List<ResBulkCementLogFacStaDataUploadDetailVO> values = (List<ResBulkCementLogFacStaDataUploadDetailVO>) dataMap.get(ReportConstant.TOTAL);
        dataList.add(values.get(0));
        // 如果是市级散办，map中只有一个键值对，且包含合计的数据
        // 如果是省散办，entries中有多个键值对，且包含合计的数据
        for (Map.Entry<String, Object> entry : entries) {
            List<ResBulkCementLogFacStaDataUploadDetailVO> value = (List<ResBulkCementLogFacStaDataUploadDetailVO>) entry.getValue();
            List<ResBulkCementLogFacStaDataUploadDetailVO> vos = value.stream().filter(v -> !ReportConstant.TOTAL.equals(v.getRegionName())).collect(Collectors.toList());
            String cityNameKey = entry.getKey();
            ResBulkCementLogFacStaDataUploadDetailVO totalVo = new ResBulkCementLogFacStaDataUploadDetailVO();
            ResBulkCementLogFacStaDataUploadDetailVO vo = value.stream().filter(v -> ReportConstant.TOTAL.equals(v.getRegionName())).collect(Collectors.toList()).get(0);
            totalVo.setRegionName(cityNameKey);
            totalVo.setYearBeginNum(vo.getYearBeginNumTotal());
            totalVo.setYearBeginCapacity(vo.getYearBeginCapacityTotal());
            totalVo.setThisYearNewAddNum(vo.getThisYearNewAddNumTotal());
            totalVo.setThisYearNewAddCapacity(vo.getThisYearNewAddCapacityTotal());
            totalVo.setThisYearScrapNum(vo.getThisYearScrapNumTotal());
            totalVo.setThisYearScrapCapacity(vo.getThisYearScrapCapacityTotal());
            totalVo.setYearEndNum(vo.getYearEndNumTotal());
            totalVo.setYearEndCapacity(vo.getYearEndCapacityTotal());
            totalVo.setThisYearWorkAmount(vo.getThisYearWorkAmountTotal());
            totalVo.setRemark(vo.getRemark());
            dataList.add(totalVo);
            dataList.addAll(vos);
        }
        List<BulkCementLogFacStaQueryDataExportDTO> exportDtoList = dataList.stream().map(d -> {
            BulkCementLogFacStaQueryDataExportDTO exportDto = new BulkCementLogFacStaQueryDataExportDTO();
            BeanUtils.copyProperties(d,exportDto);
            return exportDto;
        }).collect(Collectors.toList());
        dtoList.addAll(exportDtoList);
        return dtoList;
    }
    private List<Object> getNonProAreasDtoList(ResDataQueryDetailVO resDataQueryDetailVo) {
        List<Object> dtoList;
        ResNonProhibitedAreasDataQueryDetailVO nonProAreasDataVo = resDataQueryDetailVo.getNonProAreasDataVo();
        Map<String, Object> nonProAreasDataMap = nonProAreasDataVo.getNonProAreasDataMap();
        List<ResNonProhibitedAreasDataUploadDetailVO> dataList = Lists.newArrayList();
        // 如果是市级散办，map中只有一个键值对，且包含合计的数据
        // 如果是省散办，entries中有多个键值对，且包含合计的数据
        Set<Map.Entry<String, Object>> entries = nonProAreasDataMap.entrySet().stream()
                .filter(e -> !ReportConstant.TOTAL.equals(e.getKey())).collect(Collectors.toSet());
        List<ResNonProhibitedAreasDataUploadDetailVO> values = (List<ResNonProhibitedAreasDataUploadDetailVO>) nonProAreasDataMap.get(ReportConstant.TOTAL);
        dataList.add(values.get(0));
        for (Map.Entry<String, Object> entry : entries) {
            List<ResNonProhibitedAreasDataUploadDetailVO> value = (List<ResNonProhibitedAreasDataUploadDetailVO>) entry.getValue();
            List<ResNonProhibitedAreasDataUploadDetailVO> vos = value.stream().filter(v -> !ReportConstant.TOTAL.equals(v.getRegionName())).collect(Collectors.toList());
            String key = entry.getKey();
            ResNonProhibitedAreasDataUploadDetailVO totalVo = new ResNonProhibitedAreasDataUploadDetailVO();
            ResNonProhibitedAreasDataUploadDetailVO vo = value.stream().filter(v -> ReportConstant.TOTAL.equals(v.getRegionName())).collect(Collectors.toList()).get(0);
            totalVo.setRegionName(key);
            totalVo.setSalePointAccumulativeNum(vo.getSalePointAccumulativeNumTotal());
            totalVo.setCementCompanyBuildPointNum(vo.getCementCompanyBuildPointNumTotal());
            totalVo.setOtherInvestmentBuildPointNum(vo.getOtherInvestmentBuildPointNumTotal());
            totalVo.setSaleVolume(vo.getSaleVolumeTotal());
            totalVo.setBulkCementTankNum(vo.getBulkCementTankNumTotal());
            totalVo.setBulkCementTankCapacity(vo.getBulkCementTankCapacityTotal());
            totalVo.setCementUsage(vo.getCementUsageTotal());
            totalVo.setBulkCementUsage(vo.getBulkCementUsageTotal());
            totalVo.setReadyMixedConcreteBulkCementUsage(vo.getReadyMixedConcreteBulkCementUsageTotal());
            totalVo.setBulkCementUsageRate(vo.getBulkCementUsageRateTotal());
            totalVo.setReadyMixedConcreteOutput(vo.getReadyMixedConcreteOutputTotal());
            totalVo.setRemark(vo.getRemark());
            dataList.add(totalVo);
            dataList.addAll(vos);
        }
        dtoList = dataList.stream().map(d -> {
            NonProAreasQueryDataExportDTO exportDto = new NonProAreasQueryDataExportDTO();
            BeanUtils.copyProperties(d, exportDto);
            return exportDto;
        }).collect(Collectors.toList());
        return dtoList;
    }
    private List<MortarSupplyQueryDataExportDTO> getMortarSupplyDtoList(ResDataQueryDetailVO resDataQueryDetailVo) {
        List<MortarSupplyQueryDataExportDTO> dtoList;
        ResMortarSupplyDataQueryDetailVO mortarSupplyDataVo = resDataQueryDetailVo.getMortarSupplyDataVo();
        Map<String, Object> mortarSupplyDataMap = mortarSupplyDataVo.getMortarSupplyDataMap();
        List<ResMortarSupplyDataUploadDetailVO> dataList = Lists.newArrayList();
        // 如果是市级散办，map中只有一个键值对，且包含合计的数据
        // 如果是省散办，entries中有多个键值对，且包含合计的数据
        Set<Map.Entry<String, Object>> entries = mortarSupplyDataMap.entrySet().stream()
                .filter(e -> !ReportConstant.TOTAL.equals(e.getKey())).collect(Collectors.toSet());
        List<ResMortarSupplyDataUploadDetailVO> values = (List<ResMortarSupplyDataUploadDetailVO>) mortarSupplyDataMap.get(ReportConstant.TOTAL);
        dataList.add(values.get(0));
        for (Map.Entry<String, Object> entry : entries) {
            List<ResMortarSupplyDataUploadDetailVO> value = (List<ResMortarSupplyDataUploadDetailVO>) entry.getValue();
            List<ResMortarSupplyDataUploadDetailVO> vos = value.stream().filter(v -> !ReportConstant.TOTAL.equals(v.getRegionName())).collect(Collectors.toList());
            String key = entry.getKey();
            ResMortarSupplyDataUploadDetailVO totalVo = new ResMortarSupplyDataUploadDetailVO();
            ResMortarSupplyDataUploadDetailVO vo = value.stream().filter(v -> ReportConstant.TOTAL.equals(v.getRegionName())).collect(Collectors.toList()).get(0);
            totalVo.setRegionName(key);
            totalVo.setTwoCategoryGuidGoal(vo.getTwoCategoryGuidGoalTotal());
            totalVo.setDryMixedMortarProductionCompanyNum(vo.getDryMixedMortarProductionCompanyNumTotal());
            totalVo.setDryMixedMortarProductiveCapacity(vo.getDryMixedMortarProductiveCapacityTotal());
            totalVo.setDryMixedMortarBulkCapacity(vo.getDryMixedMortarBulkCapacityTotal());
            totalVo.setThisMonthTotalOutput(vo.getThisMonthTotalOutputTotal());
            totalVo.setThisMonthAccumulativeOutput(vo.getThisMonthAccumulativeOutputTotal());
            totalVo.setDryMixedMortarThisMonthOutput(vo.getDryMixedMortarThisMonthOutputTotal());
            totalVo.setDryMixedMortarThisMonthAccumulativeOutput(vo.getDryMixedMortarThisMonthAccumulativeOutputTotal());
            totalVo.setDryMixedMortarIncrement(vo.getDryMixedMortarIncrementTotal());
            totalVo.setDryMixedMortarGrowthRate(vo.getDryMixedMortarGrowthRateTotal());
            totalVo.setDryMixedMortarThisMonthBulkQuantity(vo.getDryMixedMortarThisMonthBulkQuantityTotal());
            totalVo.setDryMixedMortarAccumulativeBulkQuantity(vo.getDryMixedMortarAccumulativeBulkQuantityTotal());
            totalVo.setWetMortarThisMonthOutput(vo.getWetMortarThisMonthOutputTotal());
            totalVo.setWetMortarAccumulativeOutput(vo.getWetMortarAccumulativeOutputTotal());
            totalVo.setBulkCementThisMonthUsage(vo.getBulkCementThisMonthUsageTotal());
            totalVo.setBulkCementAccumulativeUsage(vo.getBulkCementAccumulativeUsageTotal());
            totalVo.setWasteAccumulativeComprehensiveUtilization(vo.getWasteAccumulativeComprehensiveUtilizationTotal());
            dataList.add(totalVo);
            dataList.addAll(vos);
        }
        dtoList = dataList.stream().map(d -> {
            MortarSupplyQueryDataExportDTO exportDto = new MortarSupplyQueryDataExportDTO();
            BeanUtils.copyProperties(d, exportDto);
            return exportDto;
        }).collect(Collectors.toList());
        return dtoList;
    }
    private List<Object> getConcreteSupplyDtoList(ResDataQueryDetailVO resDataQueryDetailVo) {
        List<Object> dtoList;
        ResConcreteSupplyDataQueryDetailVO concreteSupplyDataVo = resDataQueryDetailVo.getConcreteSupplyDataVo();
        Map<String, Object> concreteSupplyDataMap = concreteSupplyDataVo.getConcreteSupplyDataMap();
        List<ResConcreteSupplyDataUploadDetailVO> dataList = Lists.newArrayList();
        // 如果是市级散办，map中只有一个键值对，且包含合计的数据
        // 如果是省散办，entries中有多个键值对，且包含合计的数据
        Set<Map.Entry<String, Object>> entries = concreteSupplyDataMap.entrySet().stream()
                .filter(e -> !ReportConstant.TOTAL.equals(e.getKey())).collect(Collectors.toSet());
        List<ResConcreteSupplyDataUploadDetailVO> values = (List<ResConcreteSupplyDataUploadDetailVO>) concreteSupplyDataMap.get(ReportConstant.TOTAL);
        dataList.add(values.get(0));
        for (Map.Entry<String, Object> entry : entries) {
            List<ResConcreteSupplyDataUploadDetailVO> value = (List<ResConcreteSupplyDataUploadDetailVO>) entry.getValue();
            List<ResConcreteSupplyDataUploadDetailVO> vos = value.stream()
                    .filter(v -> !ReportConstant.TOTAL.equals(v.getUnitName())).collect(Collectors.toList());
            String key = entry.getKey();
            ResConcreteSupplyDataUploadDetailVO totalVo = new ResConcreteSupplyDataUploadDetailVO();
            ResConcreteSupplyDataUploadDetailVO vo = value.stream()
                    .filter(v -> ReportConstant.TOTAL.equals(v.getUnitName())).collect(Collectors.toList()).get(0);
            totalVo.setUnitName(key);
            totalVo.setThreeCategoryGuidGoal(vo.getThreeCategoryGuidGoalTotal());
            totalVo.setProductionCompanyNums(vo.getProductionCompanyNumsTotal());
            totalVo.setAnnualDesignProductionCapacity(vo.getAnnualDesignProductionCapacityTotal());
            totalVo.setThisMonthOutput(vo.getThisMonthOutputTotal());
            totalVo.setAccumulativeOutput(vo.getAccumulativeOutputTotal());
            totalVo.setThisMonthCementUsage(vo.getThisMonthCementUsageTotal());
            totalVo.setCementAccumulativeUsage(vo.getCementAccumulativeUsageTotal());
            totalVo.setThisMonthWasteUtilization(vo.getThisMonthWasteUtilizationTotal());
            totalVo.setAccumulativeWasteUtilization(vo.getAccumulativeWasteUtilizationTotal());
            totalVo.setRemark(vo.getRemark());
            dataList.add(totalVo);
            dataList.addAll(vos);
        }
        dtoList = dataList.stream().map(d -> {
            ConcreteSupplyQueryDataExportDTO exportDto = new ConcreteSupplyQueryDataExportDTO();
            BeanUtils.copyProperties(d, exportDto);
            return exportDto;
        }).collect(Collectors.toList());
        return dtoList;
    }
    private List<Object> getBulkCementThreeCityUsageDtoList(ResDataQueryDetailVO resDataQueryDetailVo) {
        List<Object> dtoList;
        ResBulkCementThreeCityUsageDataQueryDetailVO bulkCementThreeCityUsageDataVo = resDataQueryDetailVo.getBulkCementThreeCityUsageDataVo();
        Map<String, Object> bulkCementThreeCityUsageDataMap = bulkCementThreeCityUsageDataVo.getBulkCementThreeCityUsageDataMap();
        List<ResBulkCementThreeCityUsageDataUploadDetailVO> dataList = Lists.newArrayList();
        // 如果是市级散办，map中只有一个键值对，且包含合计的数据
        // 如果是省散办，entries中有多个键值对，且包含合计的数据
        Set<Map.Entry<String, Object>> entries = bulkCementThreeCityUsageDataMap.entrySet().stream()
                .filter(e -> !ReportConstant.TOTAL.equals(e.getKey())).collect(Collectors.toSet());
        List<ResBulkCementThreeCityUsageDataUploadDetailVO> values = (List<ResBulkCementThreeCityUsageDataUploadDetailVO>) bulkCementThreeCityUsageDataMap.get(ReportConstant.TOTAL);
        dataList.add(values.get(0));
        for (Map.Entry<String, Object> entry : entries) {
            List<ResBulkCementThreeCityUsageDataUploadDetailVO> value = (List<ResBulkCementThreeCityUsageDataUploadDetailVO>) entry.getValue();
            List<ResBulkCementThreeCityUsageDataUploadDetailVO> vos = value.stream()
                    .filter(v -> !ReportConstant.TOTAL.equals(v.getUnitName())).collect(Collectors.toList());
            String key = entry.getKey();
            ResBulkCementThreeCityUsageDataUploadDetailVO totalVo = new ResBulkCementThreeCityUsageDataUploadDetailVO();
            ResBulkCementThreeCityUsageDataUploadDetailVO vo = value.stream()
                    .filter(v -> ReportConstant.TOTAL.equals(v.getUnitName())).collect(Collectors.toList()).get(0);
            totalVo.setUnitName(key);
            totalVo.setYearTarget(vo.getYearTargetTotal());
            totalVo.setPercentageOfAnnualTarget(vo.getPercentageOfAnnualTargetTotal());
            totalVo.setThisMonthUsage(vo.getThisMonthUsageTotal());
            totalVo.setAccumulativeUsage(vo.getAccumulativeUsageTotal());
            totalVo.setGrowthRate(vo.getGrowthRateTotal());
            totalVo.setThisProvinceThisMonthUsage(vo.getThisProvinceThisMonthUsageTotal());
            totalVo.setThisProvinceAccumulativeUsage(vo.getThisProvinceAccumulativeUsageTotal());
            totalVo.setOtherProvinceAccumulativeUsage(vo.getOtherProvinceAccumulativeUsageTotal());
            totalVo.setOtherProvinceAccumulativeUsage(vo.getOtherProvinceAccumulativeUsageTotal());
            dataList.add(totalVo);
            dataList.addAll(vos);
        }
        dtoList = dataList.stream().map(d -> {
            BulkCementThreeCityUsageQueryDataExportDTO exportDto = new BulkCementThreeCityUsageQueryDataExportDTO();
            BeanUtils.copyProperties(d, exportDto);
            return exportDto;
        }).collect(Collectors.toList());
        return dtoList;
    }
    private List<Object> getBulkCementTransferDtoList(ResDataQueryDetailVO resDataQueryDetailVo) {
        List<Object> dtoList;
        ResBulkCementTransferDataQueryDetailVO bulkCementTransferDataVo = resDataQueryDetailVo.getBulkCementTransferDataVo();
        Map<String, Object> bulkCementTransferDataMap = bulkCementTransferDataVo.getBulkCementTransferDataMap();
        List<ResBulkCementTransferDataUploadDetailVO> dataList = Lists.newArrayList();
        // 如果是市级散办，map中只有一个键值对，且包含合计的数据
        // 如果是省散办，entries中有多个键值对，且包含合计的数据
        Set<Map.Entry<String, Object>> entries = bulkCementTransferDataMap.entrySet().stream()
                .filter(e -> !ReportConstant.TOTAL.equals(e.getKey())).collect(Collectors.toSet());
        List<ResBulkCementTransferDataUploadDetailVO> values = (List<ResBulkCementTransferDataUploadDetailVO>) bulkCementTransferDataMap.get(ReportConstant.TOTAL);
        dataList.add(values.get(0));
        for (Map.Entry<String, Object> entry : entries) {
            List<ResBulkCementTransferDataUploadDetailVO> value = (List<ResBulkCementTransferDataUploadDetailVO>) entry.getValue();
            List<ResBulkCementTransferDataUploadDetailVO> vos = value.stream().filter(v -> !ReportConstant.TOTAL.equals(v.getUnitName())).collect(Collectors.toList());
            String key = entry.getKey();
            ResBulkCementTransferDataUploadDetailVO totalVo = new ResBulkCementTransferDataUploadDetailVO();
            ResBulkCementTransferDataUploadDetailVO vo = value.stream().filter(v -> ReportConstant.TOTAL.equals(v.getUnitName())).collect(Collectors.toList()).get(0);
            totalVo.setUnitName(key);
            totalVo.setLastMonthEndInventory(vo.getLastMonthEndInventoryTotal());
            totalVo.setThisMonthIncomingStorage(vo.getThisMonthIncomingStorageTotal());
            totalVo.setCumulativeIncomingStorage(vo.getCumulativeIncomingStorageTotal());
            totalVo.setThisMonthOutgoingStorage(vo.getThisMonthOutgoingStorageTotal());
            totalVo.setCumulativeOutgoingStorage(vo.getCumulativeOutgoingStorageTotal());
            totalVo.setMonthEndInventory(vo.getMonthEndInventoryTotal());
            totalVo.setMonthEndInventoryGrowthRate(vo.getMonthEndInventoryGrowthRateTotal());
            dataList.add(totalVo);
            dataList.addAll(vos);
        }
        dtoList = dataList.stream().map(d -> {
            BulkCementTransferQueryDataExportDTO exportDto = new BulkCementTransferQueryDataExportDTO();
            BeanUtils.copyProperties(d, exportDto);
            return exportDto;
        }).collect(Collectors.toList());
        return dtoList;
    }

    private List<Object> getBulkCementSupplyDtoList(ResDataQueryDetailVO resDataQueryDetailVo) {
        List<Object> dtoList;
        ResBulkCementSupplyDataQueryDetailVO bulkCementSupplyDataVo = resDataQueryDetailVo.getBulkCementSupplyDataVo();
        Map<String, Object> bulkCementSupplyDataMap = bulkCementSupplyDataVo.getBulkCementSupplyDataMap();
        List<ResBulkCementSupplyDataUploadDetailVO> dataList = Lists.newArrayList();
        // 如果是市级散办，map中只有一个键值对，且包含合计的数据
        // 如果是省散办，entries中有多个键值对，且包含合计的数据
        Set<Map.Entry<String, Object>> entries = bulkCementSupplyDataMap.entrySet().stream()
                .filter(e -> !ReportConstant.TOTAL.equals(e.getKey())).collect(Collectors.toSet());
        List<ResBulkCementSupplyDataUploadDetailVO> values = (List<ResBulkCementSupplyDataUploadDetailVO>) bulkCementSupplyDataMap.get(ReportConstant.TOTAL);
        dataList.add(values.get(0));
        for (Map.Entry<String, Object> entry : entries) {
            List<ResBulkCementSupplyDataUploadDetailVO> value = (List<ResBulkCementSupplyDataUploadDetailVO>) entry.getValue();
            List<ResBulkCementSupplyDataUploadDetailVO> vos = value.stream().filter(v -> !ReportConstant.TOTAL.equals(v.getUnitName())).collect(Collectors.toList());
            String key = entry.getKey();
            ResBulkCementSupplyDataUploadDetailVO totalVo = new  ResBulkCementSupplyDataUploadDetailVO();
            ResBulkCementSupplyDataUploadDetailVO vo = value.stream().filter(v -> ReportConstant.TOTAL.equals(v.getUnitName())).collect(Collectors.toList()).get(0);
            totalVo.setUnitName(key);
            totalVo.setBulkRateTarget(vo.getBulkRateTarget());
            totalVo.setBulkCementAmount(vo.getBulkCementAmountTotal());
            totalVo.setCementOutput(vo.getCementOutputTotal());
            totalVo.setCompletedTotalAmount(vo.getCompletedTotalAmountTotal());
            totalVo.setBulkRate(vo.getBulkRateTotal());
            totalVo.setIncrement(vo.getIncrementTotal());
            totalVo.setIncreaseRate(vo.getIncreaseRateTotal());
            totalVo.setCumulativeCementProduction(vo.getCumulativeCementProductionTotal());
            dataList.add(totalVo);
            dataList.addAll(vos);
        }
        dtoList = dataList.stream().map(d -> {
            BulkCementSupplyQueryDataExportDTO exportDto = new BulkCementSupplyQueryDataExportDTO();
            BeanUtils.copyProperties(d, exportDto);
            return exportDto;
        }).collect(Collectors.toList());
        return dtoList;
    }

    public ResDataUploadDetailVO uploadDataDetail(ReqDataUploadDetailPO req) {
        Long auditDataId = req.getAuditDataId();
        Integer auditDataType = req.getAuditDataType();
        ResDataUploadDetailVO resVo = new ResDataUploadDetailVO();
        BulkCementDirectSystemManage context = (BulkCementDirectSystemManage) AopContext.currentProxy();
        switch (auditDataType) {
            // 散装水泥供应量数据
            case 1:
                LambdaQueryWrapper<BulkCementSupplyBulletin> wrapper1 = Wrappers.lambdaQuery(BulkCementSupplyBulletin.class);
                context.buildBulkCementSupplyBulletinQuery(wrapper1, auditDataId);
                BulkCementSupplyBulletin bulkCementSupplyBulletin = bulkCementSupplyBulletinService.getOne(wrapper1);
                VUtils.isTrue(Objects.isNull(bulkCementSupplyBulletin)).throwMessage("数据不存在!");
                ResBulkCementSupplyDataUploadDetailVO vo1 = new ResBulkCementSupplyDataUploadDetailVO();
                BeanUtils.copyProperties(bulkCementSupplyBulletin, vo1);
                resVo.setBulkCementSupplyDataUploadDetailVo(vo1);
                resVo.setReportMonth(bulkCementSupplyBulletin.getReportMonth());
                resVo.setUnitResponsiblePerson(bulkCementSupplyBulletin.getUnitResponsiblePerson());
                resVo.setPreparer(bulkCementSupplyBulletin.getPreparer());
                resVo.setReviewer(bulkCementSupplyBulletin.getReviewer());
                resVo.setSubmissionDate(bulkCementSupplyBulletin.getSubmissionDate());
                break;
            // 中转库进出量统计数据
            case 2:
                LambdaQueryWrapper<BulkCementTransferBulletin> wrapper2 = Wrappers.lambdaQuery(BulkCementTransferBulletin.class);
                context.buildBulkCementTransferBulletinQuery(wrapper2, auditDataId);
                BulkCementTransferBulletin bulkCementTransferBulletin = bulkCementTransferBulletinService.getOne(wrapper2);
                VUtils.isTrue(Objects.isNull(bulkCementTransferBulletin)).throwMessage("数据不存在!");
                ResBulkCementTransferDataUploadDetailVO vo2 = new ResBulkCementTransferDataUploadDetailVO();
                BeanUtils.copyProperties(bulkCementTransferBulletin, vo2);
                resVo.setBulkCementTransferDataUploadDetailVo(vo2);
                resVo.setReportMonth(bulkCementTransferBulletin.getReportMonth());
                resVo.setUnitResponsiblePerson(bulkCementTransferBulletin.getUnitResponsiblePerson());
                resVo.setPreparer(bulkCementTransferBulletin.getPreparer());
                resVo.setReviewer(bulkCementTransferBulletin.getReviewer());
                resVo.setSubmissionDate(bulkCementTransferBulletin.getSubmissionDate());
                break;
            // 温台舟使用量快报数据
            case 3:
                LambdaQueryWrapper<BulkCementThreeCityUsageBulletin> wrapper3 = Wrappers.lambdaQuery(BulkCementThreeCityUsageBulletin.class);
                context.buildBulkCementThreeCityUsageBulletinQuery(wrapper3, auditDataId);
                BulkCementThreeCityUsageBulletin bulkCementThreeCityUsageBulletin = bulkCementThreeCityUsageBulletinService.getOne(wrapper3);
                VUtils.isTrue(Objects.isNull(bulkCementThreeCityUsageBulletin)).throwMessage("数据不存在!");
                ResBulkCementThreeCityUsageDataUploadDetailVO vo3 = new ResBulkCementThreeCityUsageDataUploadDetailVO();
                BeanUtils.copyProperties(bulkCementThreeCityUsageBulletin, vo3);
                resVo.setBulkCementThreeCityUsageDataUploadDetailVo(vo3);
                resVo.setReportMonth(bulkCementThreeCityUsageBulletin.getReportMonth());
                resVo.setUnitResponsiblePerson(bulkCementThreeCityUsageBulletin.getUnitResponsiblePerson());
                resVo.setPreparer(bulkCementThreeCityUsageBulletin.getPreparer());
                resVo.setReviewer(bulkCementThreeCityUsageBulletin.getReviewer());
                resVo.setSubmissionDate(bulkCementThreeCityUsageBulletin.getSubmissionDate());
                break;
            // 混凝土供应量快报数据
            case 4:
                LambdaQueryWrapper<ConcreteSupplyBulletin> wrapper4 = Wrappers.lambdaQuery(ConcreteSupplyBulletin.class);
                context.buildConcreteSupplyBulletinQuery(wrapper4, auditDataId);
                ConcreteSupplyBulletin concreteSupplyBulletin = concreteSupplyBulletinService.getOne(wrapper4);
                VUtils.isTrue(Objects.isNull(concreteSupplyBulletin)).throwMessage("数据不存在!");
                ResConcreteSupplyDataUploadDetailVO vo4 = new ResConcreteSupplyDataUploadDetailVO();
                BeanUtils.copyProperties(concreteSupplyBulletin, vo4);
                resVo.setConcreteSupplyDataUploadDetailVO(vo4);
                resVo.setRemark(concreteSupplyBulletin.getRemark());
                resVo.setReportMonth(concreteSupplyBulletin.getReportMonth());
                resVo.setUnitResponsiblePerson(concreteSupplyBulletin.getUnitResponsiblePerson());
                resVo.setPreparer(concreteSupplyBulletin.getPreparer());
                resVo.setReviewer(concreteSupplyBulletin.getReviewer());
                resVo.setSubmissionDate(concreteSupplyBulletin.getSubmissionDate());
                break;
            // 砂浆供应量快报数据
            case 5:
                LambdaQueryWrapper<MortarSupplyBulletin> wrapper5 = Wrappers.lambdaQuery(MortarSupplyBulletin.class);
                context.buildMortarSupplyBulletinQuery(wrapper5, auditDataId);
                MortarSupplyBulletin mortarSupplyBulletin = mortarSupplyBulletinService.getOne(wrapper5);
                VUtils.isTrue(Objects.isNull(mortarSupplyBulletin)).throwMessage("数据不存在!");
                ResMortarSupplyDataUploadDetailVO vo5 = new ResMortarSupplyDataUploadDetailVO();
                BeanUtils.copyProperties(mortarSupplyBulletin, vo5);
                resVo.setMortarSupplyDataUploadDetailVO(vo5);
                resVo.setReportMonth(mortarSupplyBulletin.getReportMonth());
                resVo.setUnitResponsiblePerson(mortarSupplyBulletin.getUnitResponsiblePerson());
                resVo.setPreparer(mortarSupplyBulletin.getPreparer());
                resVo.setReviewer(mortarSupplyBulletin.getReviewer());
                resVo.setSubmissionDate(mortarSupplyBulletin.getSubmissionDate());
                break;
            // 非禁现区域散装水泥销售使用情况数据
            case 6:
                LambdaQueryWrapper<NonProhibitedAreasBulkCementSalesUse> wrapper6 = Wrappers.lambdaQuery(NonProhibitedAreasBulkCementSalesUse.class);
                context.buildNonProhibitedAreasBulkCementSalesUseQuery(wrapper6, auditDataId);
                NonProhibitedAreasBulkCementSalesUse nonProhibitedAreasBulkCementSalesUse = nonProhibitedAreasBulkCementSalesUseService.getOne(wrapper6);
                VUtils.isTrue(Objects.isNull(nonProhibitedAreasBulkCementSalesUse)).throwMessage("数据不存在!");
                ResNonProhibitedAreasDataUploadDetailVO vo6 = new ResNonProhibitedAreasDataUploadDetailVO();
                BeanUtils.copyProperties(nonProhibitedAreasBulkCementSalesUse, vo6);
                resVo.setNonProhibitedAreasDataUploadDetailVO(vo6);
                resVo.setReportYear(nonProhibitedAreasBulkCementSalesUse.getReportYear());
                resVo.setUnitResponsiblePerson(nonProhibitedAreasBulkCementSalesUse.getUnitResponsiblePerson());
                resVo.setPreparer(nonProhibitedAreasBulkCementSalesUse.getPreparer());
                resVo.setReviewer(nonProhibitedAreasBulkCementSalesUse.getReviewer());
                resVo.setSubmissionDate(nonProhibitedAreasBulkCementSalesUse.getSubmissionDate());
                break;
            // 散装水泥物流设施统计年报表数据
            case 7:
                // 获取关联表数据
                LambdaQueryWrapper<BulkCementDirectReportSystemDataRelevance> wrapper7 = Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class);
                context.buildBulkCementDirectReportSystemDataRelevanceQuery(wrapper7, auditDataId);
                BulkCementDirectReportSystemDataRelevance dataRelevance1 = dataRelevanceService.getOne(wrapper7);
                VUtils.isTrue(Objects.isNull(dataRelevance1)).throwMessage("数据不存在!");
                String auditDataIdList1 = dataRelevance1.getAuditDataIdList();
                if (StringUtils.isBlank(auditDataIdList1)){
                    return null;
                }
                // 按设备名称分组返回
                Map<String, ResBulkCementLogFacStaDataUploadDetailVO> dataMap1 = MapUtil.newHashMap();
                List<Long> idList1 = Arrays.stream(auditDataIdList1.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                for (Long id : idList1) {
                    BulkCementLogisticFacilityStatisticAnnualReport bulkCementLogFacStaAnnualReport = bulkCementLogFacStaAnnualReportService.getById(id);
                    ResBulkCementLogFacStaDataUploadDetailVO vo = new ResBulkCementLogFacStaDataUploadDetailVO();
                    BeanUtils.copyProperties(bulkCementLogFacStaAnnualReport, vo);
                    dataMap1.put(bulkCementLogFacStaAnnualReport.getFacilityName(), vo);
                }
                resVo.setBulkCementLogFacStaDataUploadDetailVO(dataMap1);
                resVo.setReportYear(dataRelevance1.getReportYear());
                resVo.setUnitResponsiblePerson(dataRelevance1.getUnitResponsiblePerson());
                resVo.setPreparer(dataRelevance1.getPreparer());
                resVo.setReviewer(dataRelevance1.getReviewer());
                resVo.setSubmissionDate(dataRelevance1.getSubmissionDate());
                break;
            // 散装水泥、预拌砂浆、干混砂浆物流装备统计年报表数据
            case 8:
                // 获取关联表数据
                LambdaQueryWrapper<BulkCementDirectReportSystemDataRelevance> wrapper8 = Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class);
                context.buildBulkCementDirectReportSystemDataRelevanceQuery(wrapper8, auditDataId);
                BulkCementDirectReportSystemDataRelevance dataRelevance2 = dataRelevanceService.getOne(wrapper8);
                VUtils.isTrue(Objects.isNull(dataRelevance2)).throwMessage("数据不存在!");
                String auditDataIdList2 = dataRelevance2.getAuditDataIdList();
                if (StringUtils.isBlank(auditDataIdList2)){
                    return null;
                }
                // 按装备名称分组返回
                Map<String, ResMaterialLogEquipStaDataUploadDetailVO> dataMap2 = MapUtil.newHashMap();
                List<Long> idList2 = Arrays.stream(auditDataIdList2.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                for (Long id : idList2) {
                    MaterialLogisticEquipmentStatisticAnnualReport materialLogEquipStaAnnualReport = materialLogEquipStaAnnualReportService.getById(id);
                    ResMaterialLogEquipStaDataUploadDetailVO vo = new ResMaterialLogEquipStaDataUploadDetailVO();
                    BeanUtils.copyProperties(materialLogEquipStaAnnualReport, vo);
                    dataMap2.put(materialLogEquipStaAnnualReport.getEquipmentName(), vo);
                }
                resVo.setMaterialLogEquipStaDataUploadDetailVO(dataMap2);
                resVo.setReportYear(dataRelevance2.getReportYear());
                resVo.setUnitResponsiblePerson(dataRelevance2.getUnitResponsiblePerson());
                resVo.setPreparer(dataRelevance2.getPreparer());
                resVo.setReviewer(dataRelevance2.getReviewer());
                resVo.setSubmissionDate(dataRelevance2.getSubmissionDate());
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + auditDataType);
        }
        return resVo;
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildBulkCementDirectReportSystemDataRelevanceQuery(LambdaQueryWrapper<BulkCementDirectReportSystemDataRelevance> wrapper7, Long auditDataId) {
        wrapper7.eq(BulkCementDirectReportSystemDataRelevance::getId,auditDataId);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildNonProhibitedAreasBulkCementSalesUseQuery(LambdaQueryWrapper<NonProhibitedAreasBulkCementSalesUse> wrapper6, Long auditDataId) {
        wrapper6.eq(NonProhibitedAreasBulkCementSalesUse::getId,auditDataId);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildMortarSupplyBulletinQuery(LambdaQueryWrapper<MortarSupplyBulletin> wrapper5, Long auditDataId) {
        wrapper5.eq(MortarSupplyBulletin::getId,auditDataId);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildConcreteSupplyBulletinQuery(LambdaQueryWrapper<ConcreteSupplyBulletin> wrapper4, Long auditDataId) {
        wrapper4.eq(ConcreteSupplyBulletin::getId,auditDataId);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildBulkCementThreeCityUsageBulletinQuery(LambdaQueryWrapper<BulkCementThreeCityUsageBulletin> wrapper3, Long auditDataId) {
        wrapper3.eq(BulkCementThreeCityUsageBulletin::getId,auditDataId);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildBulkCementTransferBulletinQuery(LambdaQueryWrapper<BulkCementTransferBulletin> wrapper2, Long auditDataId) {
        wrapper2.eq(BulkCementTransferBulletin::getId,auditDataId);
    }

    @LambdaDataScope(type = LambdaDataScopeTypeEnum.ALL)
    public void buildBulkCementSupplyBulletinQuery(LambdaQueryWrapper<BulkCementSupplyBulletin> wrapper1, Long auditDataId) {
        wrapper1.eq(BulkCementSupplyBulletin::getId,auditDataId);
    }
}
