package com.ningdatech.carapi.report;

import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.function.VUtils;
import com.ningdatech.basic.util.NdDateUtils;
import com.ningdatech.basic.util.StrPool;
import com.ningdatech.carapi.AppTests;
import com.ningdatech.carapi.car.vehicle.contants.VehicleContant;
import com.ningdatech.carapi.common.contants.DefValConstants;
import com.ningdatech.carapi.report.constant.DataUploadAuditStatusEnum;
import com.ningdatech.carapi.report.constant.DataUploadAuditTypeEnum;
import com.ningdatech.carapi.report.constant.UploadDataTypeEnum;
import com.ningdatech.carapi.report.model.dto.ReqBulkCementLogFacStaDataUploadDTO;
import com.ningdatech.carapi.report.model.dto.ReqMaterialLogEquipStaDataUploadDTO;
import com.ningdatech.carapi.report.model.entity.*;
import com.ningdatech.carapi.report.service.*;
import com.ningdatech.carapi.sys.entity.Region;
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.sys.service.IRegionService;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author CMM
 * @since 2023/10/10 10:08
 */

@Slf4j
public class ReportTest extends AppTests {

    @Autowired
    private IRegionService regionService;
    @Autowired
    private IBulkCementDirectReportSystemAuditInfoService auditInfoService;
    @Autowired
    private CompaniesCacheHelper companiesCacheHelper;
    @Autowired
    private IBulkCementSupplyBulletinService bulkCementSupplyBulletinService;
    @Autowired
    private IBulkCementThreeCityUsageBulletinService bulkCementThreeCityUsageBulletinService;
    @Autowired
    private IBulkCementDirectReportSystemAuditRecordService auditRecordService;
    @Autowired
    private RegionsCacheHelper regionsCacheHelper;
    @Autowired
    private IBulkCementDirectReportSystemDataRelevanceService dataRelevanceService;
    @Autowired
    private IConcreteSupplyBulletinService concreteSupplyBulletinService;
    @Autowired
    private IMortarSupplyBulletinService mortarSupplyBulletinService;
    @Autowired
    private IBulkCementLogisticFacilityStatisticAnnualReportService bulkCementLogFacStaService;
    @Autowired
    private IMaterialLogisticEquipmentStatisticAnnualReportService materialLogEquipStaAnnualReportService;
    @Autowired
    private IBulkCementTransferBulletinService bulkCementTransferBulletinService;
    @Autowired
    private INonProhibitedAreasBulkCementSalesUseService nonProhibitedAreasBulkCementSalesUseService;

    @Test
    public void bulkCementSupplyTest() throws FileNotFoundException {
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-01.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-02.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-03.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-04.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-05.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-06.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-07.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-08.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-09.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-10.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-11.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2022-12.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2023-01.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2023-02.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2023-03.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2023-04.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2023-05.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2023-06.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2023-07.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2023-08.xlsx");
        File f = new File("D:\\work\\水泥车直报系统\\data\\散装水泥供应量快报\\散装水泥供应量-2023-09.xlsx");
        Workbook wb = readExcel(new FileInputStream(f),f.getName());
        Row row = null;
        List<Long> userList = Lists.newArrayList();
        if(wb != null) {
            //获取第一个sheet
            Sheet sheet = wb.getSheetAt(0);
            //获取最大行数
            int rownum = sheet.getPhysicalNumberOfRows();
            //获取第一行
            row = sheet.getRow(0);

            // 根据区县名称获取区域ID
            HashSet<String> countySet = new HashSet<>();
            Map<String, Region> regionMap = regionService.list().stream()
                    .filter(v -> !StrPool.EMPTY.equals(v.getName()) &&
                            !"市本级".equals(v.getName()) &&
                            countySet.add(v.getName()))
                    .collect(Collectors.toMap(Region::getName, v -> v));
            for (int i = 1; i < rownum; i++) {
                row = sheet.getRow(i);

                // 区域名称
                String regionName = Objects.nonNull(row.getCell(0)) ? row.getCell(0).toString() : StringUtils.EMPTY;
                // 上报月份
                Date reportMonth = Objects.nonNull(row.getCell(1)) ? row.getCell(1).getDateCellValue() : null;
                LocalDateTime month = reportMonth.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
                // 本月实际散装水泥总量
                String bulkCementAmount = Objects.nonNull(row.getCell(2)) ? row.getCell(2).toString() : StringUtils.EMPTY;
                // 本月实际水泥产量
                String cementOutput = Objects.nonNull(row.getCell(3)) ? row.getCell(3).toString() : StringUtils.EMPTY;
                // 年初至本月累计完成量
                String completedTotalAmount = Objects.nonNull(row.getCell(4)) ? row.getCell(4).toString() : StringUtils.EMPTY;
                // 年初至本月累计散装率
                String bulkRate = Objects.nonNull(row.getCell(5)) ? row.getCell(5).toString() : StringUtils.EMPTY;
                // 年初至本月累计 比去年同期增加量
                String increment = Objects.nonNull(row.getCell(6)) ? row.getCell(6).toString() : StringUtils.EMPTY;
                // 年初至本月累计比去年同期 增长率
                String increaseRate = Objects.nonNull(row.getCell(7)) ? row.getCell(7).toString() : StringUtils.EMPTY;
                // 年初至本月累计水泥产量
                String cumulativeCementProduction = Objects.nonNull(row.getCell(8)) ? row.getCell(8).toString() : StringUtils.EMPTY;

                // 区县名称 获取区域ID、上级区域ID
                Long regionId = null;
                Long cityRegionId = null;
                String cityRegionName = null;
                for (Map.Entry<String, Region> regionEntry : regionMap.entrySet()) {
                    String regionNameStr = regionEntry.getKey();
                    if (regionNameStr.contains(regionName) && regionNameStr.length() < 4){
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    }
                }
                if (Objects.isNull(regionId)){
                    throw new BizException("区域不存在!");
                }

                // 根据地区名称获取对应散装中心的企业信息
                Long companyId;
                Long cityCompanyId;
                CompanyDTO companyDto = companiesCacheHelper.getByName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                CompanyDTO cityCompanyDto = companiesCacheHelper.getByName(cityRegionName + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.isNull(companyDto) || Objects.isNull(cityCompanyDto)){
                    throw new BizException("管理企业不存在!");
                }else {
                    companyId = companyDto.getId();
                    cityCompanyId = cityCompanyDto.getId();
                }

                // 创建市级审核通过申请
                BulkCementDirectReportSystemAuditInfo cityAuditInfo = new BulkCementDirectReportSystemAuditInfo();
                cityAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityAuditInfo.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_SUPPLY_BULLETIN.getCode());
                cityAuditInfo.setCreateOn(month);
                cityAuditInfo.setCreateBy(null);
                cityAuditInfo.setUpdateOn(month);
                cityAuditInfo.setUpdateBy(null);
                cityAuditInfo.setAuditTime(month);
                cityAuditInfo.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                auditInfoService.save(cityAuditInfo);

                // 保存上报数据信息
                // 创建上报记录
                BulkCementSupplyBulletin concreteSupplyBulletin = new BulkCementSupplyBulletin();
                concreteSupplyBulletin.setUnitName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                concreteSupplyBulletin.setBulkCementAmount(BigDecimal.valueOf(Double.parseDouble(bulkCementAmount)));
                concreteSupplyBulletin.setCementOutput(BigDecimal.valueOf(Double.parseDouble(cementOutput)));
                concreteSupplyBulletin.setCompletedTotalAmount(BigDecimal.valueOf(Double.parseDouble(completedTotalAmount)));
                concreteSupplyBulletin.setBulkRate(BigDecimal.valueOf(Double.parseDouble(bulkRate)));
                concreteSupplyBulletin.setIncrement(BigDecimal.valueOf(Double.parseDouble(increment)));
                concreteSupplyBulletin.setIncreaseRate(BigDecimal.valueOf(Double.parseDouble(increaseRate)));
                concreteSupplyBulletin.setCumulativeCementProduction(BigDecimal.valueOf(Double.parseDouble(cumulativeCementProduction)));
                concreteSupplyBulletin.setReportMonth(month);
                concreteSupplyBulletin.setCompanyId(companyId);
                concreteSupplyBulletin.setUnitResponsiblePerson(null);
                concreteSupplyBulletin.setPreparer(null);
                concreteSupplyBulletin.setReviewer(null);
                concreteSupplyBulletin.setSubmissionDate(null);
                concreteSupplyBulletin.setRegionId(regionId);
                concreteSupplyBulletin.setCreateOn(month);
                concreteSupplyBulletin.setCreateBy(null);
                concreteSupplyBulletin.setUpdateOn(month);
                concreteSupplyBulletin.setUpdateBy(null);
                concreteSupplyBulletin.setAuditInfoId(cityAuditInfo.getId());
                concreteSupplyBulletin.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                bulkCementSupplyBulletinService.saveOrUpdate(concreteSupplyBulletin);

                // 补充市级数据审核表信息
                BulkCementDirectReportSystemAuditRecord auditRecord = new BulkCementDirectReportSystemAuditRecord();
                auditRecord.setAuditDataId(concreteSupplyBulletin.getId());
                auditRecord.setAuditInfoId(cityAuditInfo.getId());
                auditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                auditRecord.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_SUPPLY_BULLETIN.getCode());
                auditRecord.setCompanyId(companyId);
                auditRecord.setRegionId(regionId);
                auditRecord.setCreateOn(month.plusDays(20));
                auditRecord.setCreateBy(null);
                auditRecord.setUpdateOn(month.plusDays(20));
                auditRecord.setUpdateBy(null);
                auditRecord.setReportMonth(month);
                auditRecord.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                auditRecordService.save(auditRecord);

                Long relevanceDataId;
                // 判断上报月份所在市的关联数据不存在
                BulkCementDirectReportSystemDataRelevance cityData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, cityRegionId)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.CITY_AUDIT.getCode())
                        .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, month)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.BULK_CEMENT_SUPPLY_BULLETIN.getCode()));
                // 已经存在，更新上报数据ID列表
                if (Objects.nonNull(cityData)){
                    String auditDataIdListStr = cityData.getAuditDataIdList();
                    List<Long> auditDataIdList;
                    if (StringUtils.isNotBlank(auditDataIdListStr)){
                        auditDataIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                        if (!auditDataIdList.contains(concreteSupplyBulletin.getId())){
                            auditDataIdList.add(concreteSupplyBulletin.getId());
                            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                            cityData.setAuditDataIdList(idListStr);
                        }
                        // 更新最后一次更新时间
                        cityData.setLastUpdateTime(LocalDateTime.now());
                        cityData.setUpdateOn(LocalDateTime.now());
                        cityData.setUpdateBy(null);
                        // 有新上报的数据，就更新关联数据状态为未上报
                        cityData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                        dataRelevanceService.updateById(cityData);
                    }
                    relevanceDataId = cityData.getId();
                }else {
                    // 补充所在市的关联数据信息
                    BulkCementDirectReportSystemDataRelevance cityRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                    cityRelevanceData.setReportMonth(month);
                    List<Long> auditDataIdList = Lists.newArrayList();
                    auditDataIdList.add(concreteSupplyBulletin.getId());
                    String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    cityRelevanceData.setAuditDataIdList(idListStr);
                    cityRelevanceData.setUnitResponsiblePerson(null);
                    cityRelevanceData.setPreparer(null);
                    cityRelevanceData.setReviewer(null);
                    cityRelevanceData.setSubmissionDate(null);
                    cityRelevanceData.setCreateOn(LocalDateTime.now());
                    cityRelevanceData.setCreateBy(null);
                    cityRelevanceData.setUpdateOn(LocalDateTime.now());
                    cityRelevanceData.setUpdateBy(null);
                    cityRelevanceData.setLastUpdateTime(LocalDateTime.now());
                    cityRelevanceData.setRegionId(cityRegionId);
                    // 获取所在市散装中心所属的管理企业ID
                    cityRelevanceData.setCompanyId(cityCompanyId);
                    cityRelevanceData.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                    cityRelevanceData.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_SUPPLY_BULLETIN.getCode());
                    // 有新上报的数据，就更新关联数据
                    cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.saveOrUpdate(cityRelevanceData);
                    relevanceDataId = cityRelevanceData.getId();
                }

                // 补充省级审核申请
                BulkCementDirectReportSystemAuditInfo provinceAuditInfo = new BulkCementDirectReportSystemAuditInfo();
                provinceAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                provinceAuditInfo.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_SUPPLY_BULLETIN.getCode());
                provinceAuditInfo.setCreateOn(month);
                provinceAuditInfo.setCreateBy(null);
                provinceAuditInfo.setUpdateOn(month);
                provinceAuditInfo.setUpdateBy(null);
                provinceAuditInfo.setAuditTime(month);
                provinceAuditInfo.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                auditInfoService.save(provinceAuditInfo);
                // 更新市级关联数据
                BulkCementDirectReportSystemDataRelevance cityRelevanceData = dataRelevanceService.getById(relevanceDataId);
                VUtils.isTrue(Objects.isNull(cityRelevanceData)).throwMessage("数据不存在!");
                // 关联审核信息ID
                cityRelevanceData.setAuditInfoId(provinceAuditInfo.getId());
                cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityRelevanceData.setUpdateOn(month.plusDays(20L));
                cityRelevanceData.setUpdateBy(null);
                cityRelevanceData.setUnitResponsiblePerson(null);
                cityRelevanceData.setPreparer(null);
                cityRelevanceData.setReviewer(null);
                cityRelevanceData.setSubmissionDate(null);
                dataRelevanceService.updateById(cityRelevanceData);

                // 判断上报月份省关联数据是否存在
                BulkCementDirectReportSystemDataRelevance provinceData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, DefValConstants.ZJREGION_ID)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode())
                        .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, month)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.BULK_CEMENT_SUPPLY_BULLETIN.getCode()));
                // 存在，更新市关联数据ID列表
                if (Objects.nonNull(provinceData)){
                    String auditDataIdListStr = provinceData.getAuditDataIdList();
                    List<Long> auditDataIdList;
                    if (StringUtils.isNotBlank(auditDataIdListStr)){
                        auditDataIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                        if (!auditDataIdList.contains(relevanceDataId)){
                            auditDataIdList.add(relevanceDataId);
                            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                            provinceData.setAuditDataIdList(idListStr);
                        }
                        // 更新最后一次更新时间
                        provinceData.setLastUpdateTime(month);
                        provinceData.setUpdateOn(month);
                        provinceData.setUpdateBy(null);
                        // 有新上报的数据，就更新关联数据状态为审核中
                        provinceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                        dataRelevanceService.updateById(provinceData);
                    }
                }else {
                    // 如果上报月份省级关联数据不存在
                    // 补充省散办关联数据信息
                    BulkCementDirectReportSystemDataRelevance provinceRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                    provinceRelevanceData.setReportMonth(month);
                    List<Long> auditDataIdList = Lists.newArrayList();
                    auditDataIdList.add(relevanceDataId);
                    String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    provinceRelevanceData.setAuditDataIdList(idListStr);

                    provinceRelevanceData.setUnitResponsiblePerson(null);
                    provinceRelevanceData.setPreparer(null);
                    provinceRelevanceData.setReviewer(null);
                    provinceRelevanceData.setSubmissionDate(null);
                    provinceRelevanceData.setCreateOn(month);
                    provinceRelevanceData.setCreateBy(null);
                    provinceRelevanceData.setUpdateOn(month);
                    provinceRelevanceData.setUpdateBy(null);
                    provinceRelevanceData.setLastUpdateTime(month);
                    provinceRelevanceData.setRegionId(DefValConstants.ZJREGION_ID);
                    provinceRelevanceData.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                    // 获取省散装中心所属的管理企业ID
                    CompanyDTO provinceCompanyDto = companiesCacheHelper.getByName(DefValConstants.PROVINCE + VehicleContant.ADMIN_COMPANY_NAME);
                    if (Objects.nonNull(provinceCompanyDto)) {
                        provinceRelevanceData.setCompanyId(provinceCompanyDto.getId());
                    }
                    provinceRelevanceData.setUnitResponsiblePerson(null);
                    provinceRelevanceData.setPreparer(null);
                    provinceRelevanceData.setReviewer(null);
                    provinceRelevanceData.setSubmissionDate(null);
                    provinceRelevanceData.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_SUPPLY_BULLETIN.getCode());
                    provinceRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.save(provinceRelevanceData);
                }

                // 创建省级审核记录
                BulkCementDirectReportSystemAuditRecord provinceAuditRecord = new BulkCementDirectReportSystemAuditRecord();
                provinceAuditRecord.setAuditDataId(cityRelevanceData.getId());
                provinceAuditRecord.setAuditInfoId(provinceAuditInfo.getId());
                provinceAuditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                provinceAuditRecord.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_SUPPLY_BULLETIN.getCode());
                provinceAuditRecord.setCompanyId(cityRelevanceData.getCompanyId());
                provinceAuditRecord.setRegionId(cityRelevanceData.getRegionId());
                provinceAuditRecord.setCreateOn(cityRelevanceData.getReportMonth());
                provinceAuditRecord.setCreateBy(null);
                provinceAuditRecord.setUpdateOn(cityRelevanceData.getReportMonth());
                provinceAuditRecord.setUpdateBy(null);
                provinceAuditRecord.setReportMonth(month);
                provinceAuditRecord.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                auditRecordService.save(provinceAuditRecord);

                System.out.println("已成功插入第" + i + "条数据!");
            }
        }
    }

    @Test
    public void bulkCementTransferTest() throws FileNotFoundException {
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-01-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-02-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-03-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-04-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-05-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-06-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-07-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-08-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-09-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-10-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-11-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2022-12-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2023-01-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2023-02-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2023-03-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2023-04-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2023-05-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2023-06-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2023-07-中转库进出量.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2023-08-中转库进出量.xlsx");
        File f = new File("D:\\work\\水泥车直报系统\\data\\中转库进出量\\2023-09-中转库进出量.xlsx");
        Workbook wb = readExcel(new FileInputStream(f),f.getName());
        Row row = null;
        List<Long> userList = Lists.newArrayList();
        if(wb != null) {
            //获取第一个sheet
            Sheet sheet = wb.getSheetAt(0);
            //获取最大行数
            int rownum = sheet.getPhysicalNumberOfRows();
            //获取第一行
            row = sheet.getRow(0);

            // 根据区县名称获取区域ID
            HashSet<String> countySet = new HashSet<>();
            Map<String, Region> regionMap = regionService.list().stream()
                    .filter(v -> !StrPool.EMPTY.equals(v.getName()) &&
                            !"市本级".equals(v.getName()) &&
                            countySet.add(v.getName()))
                    .collect(Collectors.toMap(Region::getName, v -> v));
            for (int i = 1; i < rownum; i++) {
                row = sheet.getRow(i);

                // 区域名称
                String regionName = Objects.nonNull(row.getCell(0)) ? row.getCell(0).toString() : StringUtils.EMPTY;
                // 上报月份
                Date reportMonth = Objects.nonNull(row.getCell(1)) ? row.getCell(1).getDateCellValue() : null;
                LocalDateTime month = reportMonth.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
                // 上月末库存
                String lastMonthEndInventory = Objects.nonNull(row.getCell(2)) ? row.getCell(2).toString() : StringUtils.EMPTY;
                // 本月进库量
                String thisMonthIncomingStorage = Objects.nonNull(row.getCell(3)) ? row.getCell(3).toString() : StringUtils.EMPTY;
                // 累计进库量
                String cumulativeIncomingStorage = Objects.nonNull(row.getCell(4)) ? row.getCell(4).toString() : StringUtils.EMPTY;
                // 本月出库量
                String thisMonthOutgoingStorage = Objects.nonNull(row.getCell(5)) ? row.getCell(5).toString() : StringUtils.EMPTY;
                // 累计出库量
                String cumulativeOutgoingStorage = Objects.nonNull(row.getCell(6)) ? row.getCell(6).toString() : StringUtils.EMPTY;
                // 月末库存量
                String monthEndInventory = Objects.nonNull(row.getCell(7)) ? row.getCell(7).toString() : StringUtils.EMPTY;
                // 月末库存同比增长率
                String monthEndInventoryGrowthRate = Objects.nonNull(row.getCell(8)) ? row.getCell(8).toString() : StringUtils.EMPTY;

                // 区县名称 获取区域ID、上级区域ID
                Long regionId = null;
                Long cityRegionId = null;
                String cityRegionName = null;
                for (Map.Entry<String, Region> regionEntry : regionMap.entrySet()) {
                    String regionNameStr = regionEntry.getKey();
                    if (regionNameStr.contains(regionName) && regionNameStr.length() < 4){
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    }
                }
                if (Objects.isNull(regionId)){
                    throw new BizException("区域不存在!");
                }

                // 根据地区名称获取对应散装中心的企业信息
                Long companyId;
                Long cityCompanyId;
                CompanyDTO companyDto = companiesCacheHelper.getByName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                CompanyDTO cityCompanyDto = companiesCacheHelper.getByName(cityRegionName + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.isNull(companyDto) || Objects.isNull(cityCompanyDto)){
                    throw new BizException("管理企业不存在!");
                }else {
                    companyId = companyDto.getId();
                    cityCompanyId = cityCompanyDto.getId();
                }

                // 创建市级审核通过申请
                BulkCementDirectReportSystemAuditInfo cityAuditInfo = new BulkCementDirectReportSystemAuditInfo();
                cityAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityAuditInfo.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_TRANSFER_BULLETIN.getCode());
                cityAuditInfo.setCreateOn(month);
                cityAuditInfo.setCreateBy(null);
                cityAuditInfo.setUpdateOn(month);
                cityAuditInfo.setUpdateBy(null);
                cityAuditInfo.setAuditTime(month);
                cityAuditInfo.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                auditInfoService.save(cityAuditInfo);

                // 保存上报数据信息
                // 创建上报记录
                BulkCementTransferBulletin bulkCementTransferBulletin = new BulkCementTransferBulletin();
                bulkCementTransferBulletin.setUnitName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                bulkCementTransferBulletin.setLastMonthEndInventory(BigDecimal.valueOf(Double.parseDouble(lastMonthEndInventory)));
                bulkCementTransferBulletin.setThisMonthIncomingStorage(BigDecimal.valueOf(Double.parseDouble(thisMonthIncomingStorage)));
                bulkCementTransferBulletin.setCumulativeIncomingStorage(BigDecimal.valueOf(Double.parseDouble(cumulativeIncomingStorage)));
                bulkCementTransferBulletin.setThisMonthIncomingStorage(BigDecimal.valueOf(Double.parseDouble(thisMonthIncomingStorage)));
                bulkCementTransferBulletin.setThisMonthOutgoingStorage(BigDecimal.valueOf(Double.parseDouble(thisMonthOutgoingStorage)));
                bulkCementTransferBulletin.setCumulativeOutgoingStorage(BigDecimal.valueOf(Double.parseDouble(cumulativeOutgoingStorage)));
                bulkCementTransferBulletin.setMonthEndInventory(BigDecimal.valueOf(Double.parseDouble(monthEndInventory)));
                bulkCementTransferBulletin.setMonthEndInventoryGrowthRate(BigDecimal.valueOf(Double.parseDouble(monthEndInventoryGrowthRate)));
                bulkCementTransferBulletin.setReportMonth(month);
                bulkCementTransferBulletin.setCompanyId(companyId);
                bulkCementTransferBulletin.setUnitResponsiblePerson(null);
                bulkCementTransferBulletin.setPreparer(null);
                bulkCementTransferBulletin.setReviewer(null);
                bulkCementTransferBulletin.setSubmissionDate(null);
                bulkCementTransferBulletin.setRegionId(regionId);
                bulkCementTransferBulletin.setCreateOn(month);
                bulkCementTransferBulletin.setCreateBy(null);
                bulkCementTransferBulletin.setUpdateOn(month);
                bulkCementTransferBulletin.setUpdateBy(null);
                bulkCementTransferBulletin.setAuditInfoId(cityAuditInfo.getId());
                bulkCementTransferBulletin.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                bulkCementTransferBulletinService.saveOrUpdate(bulkCementTransferBulletin);

                // 补充市级数据审核表信息
                BulkCementDirectReportSystemAuditRecord auditRecord = new BulkCementDirectReportSystemAuditRecord();
                auditRecord.setAuditDataId(bulkCementTransferBulletin.getId());
                auditRecord.setAuditInfoId(cityAuditInfo.getId());
                auditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                auditRecord.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_TRANSFER_BULLETIN.getCode());
                auditRecord.setCompanyId(companyId);
                auditRecord.setRegionId(regionId);
                auditRecord.setCreateOn(month.plusDays(20));
                auditRecord.setCreateBy(null);
                auditRecord.setUpdateOn(month.plusDays(20));
                auditRecord.setUpdateBy(null);
                auditRecord.setReportMonth(month);
                auditRecord.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                auditRecordService.save(auditRecord);

                Long relevanceDataId;
                // 判断上报月份所在市的关联数据不存在
                BulkCementDirectReportSystemDataRelevance cityData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, cityRegionId)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.CITY_AUDIT.getCode())
                        .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, month)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.BULK_CEMENT_TRANSFER_BULLETIN.getCode()));
                // 已经存在，更新上报数据ID列表
                if (Objects.nonNull(cityData)){
                    String auditDataIdListStr = cityData.getAuditDataIdList();
                    List<Long> auditDataIdList;
                    if (StringUtils.isNotBlank(auditDataIdListStr)){
                        auditDataIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                        if (!auditDataIdList.contains(bulkCementTransferBulletin.getId())){
                            auditDataIdList.add(bulkCementTransferBulletin.getId());
                            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                            cityData.setAuditDataIdList(idListStr);
                        }
                        // 更新最后一次更新时间
                        cityData.setLastUpdateTime(LocalDateTime.now());
                        cityData.setUpdateOn(LocalDateTime.now());
                        cityData.setUpdateBy(null);
                        // 有新上报的数据
                        cityData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                        dataRelevanceService.updateById(cityData);
                    }
                    relevanceDataId = cityData.getId();
                }else {
                    // 补充所在市的关联数据信息
                    BulkCementDirectReportSystemDataRelevance cityRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                    cityRelevanceData.setReportMonth(month);
                    List<Long> auditDataIdList = Lists.newArrayList();
                    auditDataIdList.add(bulkCementTransferBulletin.getId());
                    String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    cityRelevanceData.setAuditDataIdList(idListStr);
                    cityRelevanceData.setUnitResponsiblePerson(null);
                    cityRelevanceData.setPreparer(null);
                    cityRelevanceData.setReviewer(null);
                    cityRelevanceData.setSubmissionDate(null);
                    cityRelevanceData.setCreateOn(LocalDateTime.now());
                    cityRelevanceData.setCreateBy(null);
                    cityRelevanceData.setUpdateOn(LocalDateTime.now());
                    cityRelevanceData.setUpdateBy(null);
                    cityRelevanceData.setLastUpdateTime(LocalDateTime.now());
                    cityRelevanceData.setRegionId(cityRegionId);
                    // 获取所在市散装中心所属的管理企业ID
                    cityRelevanceData.setCompanyId(cityCompanyId);
                    cityRelevanceData.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                    cityRelevanceData.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_TRANSFER_BULLETIN.getCode());
                    // 有新上报的数据，就更新关联数据
                    cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.saveOrUpdate(cityRelevanceData);
                    relevanceDataId = cityRelevanceData.getId();
                }

                // 补充省级审核申请
                BulkCementDirectReportSystemAuditInfo provinceAuditInfo = new BulkCementDirectReportSystemAuditInfo();
                provinceAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                provinceAuditInfo.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_TRANSFER_BULLETIN.getCode());
                provinceAuditInfo.setCreateOn(month);
                provinceAuditInfo.setCreateBy(null);
                provinceAuditInfo.setUpdateOn(month);
                provinceAuditInfo.setUpdateBy(null);
                provinceAuditInfo.setAuditTime(month);
                provinceAuditInfo.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                auditInfoService.save(provinceAuditInfo);
                // 更新市级关联数据
                BulkCementDirectReportSystemDataRelevance cityRelevanceData = dataRelevanceService.getById(relevanceDataId);
                VUtils.isTrue(Objects.isNull(cityRelevanceData)).throwMessage("数据不存在!");
                // 关联审核信息ID
                cityRelevanceData.setAuditInfoId(provinceAuditInfo.getId());
                cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityRelevanceData.setUpdateOn(month.plusDays(20L));
                cityRelevanceData.setUpdateBy(null);
                cityRelevanceData.setUnitResponsiblePerson(null);
                cityRelevanceData.setPreparer(null);
                cityRelevanceData.setReviewer(null);
                cityRelevanceData.setSubmissionDate(null);
                dataRelevanceService.updateById(cityRelevanceData);

                // 判断上报月份省关联数据是否存在
                BulkCementDirectReportSystemDataRelevance provinceData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, DefValConstants.ZJREGION_ID)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode())
                        .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, month)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.BULK_CEMENT_TRANSFER_BULLETIN.getCode()));
                // 存在，更新市关联数据ID列表
                if (Objects.nonNull(provinceData)){
                    String auditDataIdListStr = provinceData.getAuditDataIdList();
                    List<Long> auditDataIdList;
                    if (StringUtils.isNotBlank(auditDataIdListStr)){
                        auditDataIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                        if (!auditDataIdList.contains(relevanceDataId)){
                            auditDataIdList.add(relevanceDataId);
                            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                            provinceData.setAuditDataIdList(idListStr);
                        }
                        // 更新最后一次更新时间
                        provinceData.setLastUpdateTime(month);
                        provinceData.setUpdateOn(month);
                        provinceData.setUpdateBy(null);
                        // 有新上报的数据，就更新关联数据状态为审核中
                        provinceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                        dataRelevanceService.updateById(provinceData);
                    }
                }else {
                    // 如果上报月份省级关联数据不存在
                    // 补充省散办关联数据信息
                    BulkCementDirectReportSystemDataRelevance provinceRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                    provinceRelevanceData.setReportMonth(month);
                    List<Long> auditDataIdList = Lists.newArrayList();
                    auditDataIdList.add(relevanceDataId);
                    String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    provinceRelevanceData.setAuditDataIdList(idListStr);

                    provinceRelevanceData.setUnitResponsiblePerson(null);
                    provinceRelevanceData.setPreparer(null);
                    provinceRelevanceData.setReviewer(null);
                    provinceRelevanceData.setSubmissionDate(null);
                    provinceRelevanceData.setCreateOn(month);
                    provinceRelevanceData.setCreateBy(null);
                    provinceRelevanceData.setUpdateOn(month);
                    provinceRelevanceData.setUpdateBy(null);
                    provinceRelevanceData.setLastUpdateTime(month);
                    provinceRelevanceData.setRegionId(DefValConstants.ZJREGION_ID);
                    provinceRelevanceData.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                    // 获取省散装中心所属的管理企业ID
                    CompanyDTO provinceCompanyDto = companiesCacheHelper.getByName(DefValConstants.PROVINCE + VehicleContant.ADMIN_COMPANY_NAME);
                    if (Objects.nonNull(provinceCompanyDto)) {
                        provinceRelevanceData.setCompanyId(provinceCompanyDto.getId());
                    }
                    provinceRelevanceData.setUnitResponsiblePerson(null);
                    provinceRelevanceData.setPreparer(null);
                    provinceRelevanceData.setReviewer(null);
                    provinceRelevanceData.setSubmissionDate(null);
                    provinceRelevanceData.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_TRANSFER_BULLETIN.getCode());
                    provinceRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.save(provinceRelevanceData);
                }

                // 创建省级审核记录
                BulkCementDirectReportSystemAuditRecord provinceAuditRecord = new BulkCementDirectReportSystemAuditRecord();
                provinceAuditRecord.setAuditDataId(cityRelevanceData.getId());
                provinceAuditRecord.setAuditInfoId(provinceAuditInfo.getId());
                provinceAuditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                provinceAuditRecord.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_TRANSFER_BULLETIN.getCode());
                provinceAuditRecord.setCompanyId(cityRelevanceData.getCompanyId());
                provinceAuditRecord.setRegionId(cityRelevanceData.getRegionId());
                provinceAuditRecord.setCreateOn(cityRelevanceData.getReportMonth());
                provinceAuditRecord.setCreateBy(null);
                provinceAuditRecord.setUpdateOn(cityRelevanceData.getReportMonth());
                provinceAuditRecord.setUpdateBy(null);
                provinceAuditRecord.setReportMonth(month);
                provinceAuditRecord.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                auditRecordService.save(provinceAuditRecord);

                System.out.println("已成功插入第" + i + "条数据!");
            }
        }
    }

    @Test
    public void bulkCementThreeCityUsageTest() throws FileNotFoundException {

        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-01.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-02.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-03.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-04.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-05.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-06.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-07.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-08.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-09.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-10.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-11.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2022-12.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2023-01.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2023-02.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2023-03.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2023-04.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2023-05.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2023-06.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2023-07.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2023-08.xlsx");
        File f = new File("D:\\work\\水泥车直报系统\\data\\温台舟使用量快报\\温台舟使用量快报-2023-09.xlsx");
        Workbook wb = readExcel(new FileInputStream(f),f.getName());
        Row row = null;
        List<Long> userList = Lists.newArrayList();
        if(wb != null) {
            //获取第一个sheet
            Sheet sheet = wb.getSheetAt(0);
            //获取最大行数
            int rownum = sheet.getPhysicalNumberOfRows();
            //获取第一行
            row = sheet.getRow(0);

            // 根据区县名称获取区域ID
            HashSet<String> countySet = new HashSet<>();
            Map<String, Region> regionMap = regionService.list().stream()
                    .filter(v -> !StrPool.EMPTY.equals(v.getName()) &&
                            !"市本级".equals(v.getName()) &&
                            countySet.add(v.getName()))
                    .collect(Collectors.toMap(Region::getName, v -> v));
            for (int i = 1; i < rownum; i++) {
                row = sheet.getRow(i);

                // 单位名称
                String regionName = Objects.nonNull(row.getCell(0)) ? row.getCell(0).toString() : StringUtils.EMPTY;
                // 上报月份
                Date reportMonth = Objects.nonNull(row.getCell(1)) ? row.getCell(1).getDateCellValue() : null;
                LocalDateTime month = reportMonth.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
                // 年目标
                String yearTarget = Objects.nonNull(row.getCell(2)) ? row.getCell(2).toString() : StringUtils.EMPTY;
                // 占全年目标
                String percentageOfAnnualTarget = Objects.nonNull(row.getCell(3)) ? row.getCell(3).toString() : StringUtils.EMPTY;
                // 本月合计
                String thisMonthUsage = Objects.nonNull(row.getCell(4)) ? row.getCell(4).toString() : StringUtils.EMPTY;
                // 累计合计
                String accumulativeUsage = Objects.nonNull(row.getCell(5)) ? row.getCell(5).toString() : StringUtils.EMPTY;
                // 本省本月
                String thisProvinceThisMonthUsage = Objects.nonNull(row.getCell(6)) ? row.getCell(6).toString() : StringUtils.EMPTY;
                // 本省累计
                String thisProvinceAccumulativeUsage = Objects.nonNull(row.getCell(7)) ? row.getCell(7).toString() : StringUtils.EMPTY;
                // 外省本月
                String otherProvinceThisMonthUsage = Objects.nonNull(row.getCell(8)) ? row.getCell(8).toString() : StringUtils.EMPTY;
                // 外省累计
                String otherProvinceAccumulativeUsage = Objects.nonNull(row.getCell(9)) ? row.getCell(9).toString() : StringUtils.EMPTY;

                // 区县名称 获取区域ID、上级区域ID
                Long regionId = null;
                Long cityRegionId = null;
                String cityRegionName = null;
                for (Map.Entry<String, Region> regionEntry : regionMap.entrySet()) {
                    String regionNameStr = regionEntry.getKey();
                    if (regionNameStr.contains(regionName) && regionNameStr.length() < 4){
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    }
                }
                if (Objects.isNull(regionId)){
                    throw new BizException("区域不存在!");
                }

                // 根据地区名称获取对应散装中心的企业信息
                Long companyId;
                Long cityCompanyId;
                CompanyDTO companyDto = companiesCacheHelper.getByName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                CompanyDTO cityCompanyDto = companiesCacheHelper.getByName(cityRegionName + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.isNull(companyDto) || Objects.isNull(cityCompanyDto)){
                    throw new BizException("管理企业不存在!");
                }else {
                    companyId = companyDto.getId();
                    cityCompanyId = cityCompanyDto.getId();
                }

                // 创建市级审核通过申请
                BulkCementDirectReportSystemAuditInfo cityAuditInfo = new BulkCementDirectReportSystemAuditInfo();
                cityAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityAuditInfo.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_THREE_CITY_USAGE_BULLETIN.getCode());
                cityAuditInfo.setCreateOn(month);
                cityAuditInfo.setCreateBy(null);
                cityAuditInfo.setUpdateOn(month);
                cityAuditInfo.setUpdateBy(null);
                cityAuditInfo.setAuditTime(month);
                cityAuditInfo.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                auditInfoService.save(cityAuditInfo);

                // 保存上报数据信息
                // 创建上报记录
                BulkCementThreeCityUsageBulletin bulkCementThreeCityUsageBulletIn = new BulkCementThreeCityUsageBulletin();
                bulkCementThreeCityUsageBulletIn.setUnitName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                bulkCementThreeCityUsageBulletIn.setYearTarget(BigDecimal.valueOf(Double.parseDouble(yearTarget)));
                bulkCementThreeCityUsageBulletIn.setPercentageOfAnnualTarget(BigDecimal.valueOf(Double.parseDouble(percentageOfAnnualTarget)));
                bulkCementThreeCityUsageBulletIn.setThisMonthUsage(BigDecimal.valueOf(Double.parseDouble(thisMonthUsage)));
                bulkCementThreeCityUsageBulletIn.setAccumulativeUsage(BigDecimal.valueOf(Double.parseDouble(accumulativeUsage)));
                bulkCementThreeCityUsageBulletIn.setThisProvinceThisMonthUsage(BigDecimal.valueOf(Double.parseDouble(thisProvinceThisMonthUsage)));
                bulkCementThreeCityUsageBulletIn.setThisProvinceAccumulativeUsage(BigDecimal.valueOf(Double.parseDouble(thisProvinceAccumulativeUsage)));
                bulkCementThreeCityUsageBulletIn.setOtherProvinceThisMonthUsage(BigDecimal.valueOf(Double.parseDouble(otherProvinceThisMonthUsage)));
                bulkCementThreeCityUsageBulletIn.setOtherProvinceAccumulativeUsage(BigDecimal.valueOf(Double.parseDouble(otherProvinceAccumulativeUsage)));
                bulkCementThreeCityUsageBulletIn.setReportMonth(month);
                bulkCementThreeCityUsageBulletIn.setCompanyId(companyId);
                bulkCementThreeCityUsageBulletIn.setUnitResponsiblePerson(null);
                bulkCementThreeCityUsageBulletIn.setPreparer(null);
                bulkCementThreeCityUsageBulletIn.setReviewer(null);
                bulkCementThreeCityUsageBulletIn.setSubmissionDate(null);
                bulkCementThreeCityUsageBulletIn.setRegionId(regionId);
                bulkCementThreeCityUsageBulletIn.setCreateOn(month);
                bulkCementThreeCityUsageBulletIn.setCreateBy(null);
                bulkCementThreeCityUsageBulletIn.setUpdateOn(month);
                bulkCementThreeCityUsageBulletIn.setUpdateBy(null);
                bulkCementThreeCityUsageBulletIn.setAuditInfoId(cityAuditInfo.getId());
                bulkCementThreeCityUsageBulletIn.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                bulkCementThreeCityUsageBulletinService.saveOrUpdate(bulkCementThreeCityUsageBulletIn);

                // 补充市级数据审核表信息
                BulkCementDirectReportSystemAuditRecord auditRecord = new BulkCementDirectReportSystemAuditRecord();
                auditRecord.setAuditDataId(bulkCementThreeCityUsageBulletIn.getId());
                auditRecord.setAuditInfoId(cityAuditInfo.getId());
                auditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                auditRecord.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_THREE_CITY_USAGE_BULLETIN.getCode());
                auditRecord.setCompanyId(companyId);
                auditRecord.setRegionId(regionId);
                auditRecord.setCreateOn(month.plusDays(20));
                auditRecord.setCreateBy(null);
                auditRecord.setUpdateOn(month.plusDays(20));
                auditRecord.setUpdateBy(null);
                auditRecord.setReportMonth(month);
                auditRecord.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                auditRecordService.save(auditRecord);

                Long relevanceDataId;
                // 判断上报月份所在市的关联数据不存在
                BulkCementDirectReportSystemDataRelevance cityData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, cityRegionId)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.CITY_AUDIT.getCode())
                        .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, month)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.BULK_CEMENT_THREE_CITY_USAGE_BULLETIN.getCode()));
                // 已经存在，更新上报数据ID列表
                if (Objects.nonNull(cityData)){
                    String auditDataIdListStr = cityData.getAuditDataIdList();
                    List<Long> auditDataIdList;
                    if (StringUtils.isNotBlank(auditDataIdListStr)){
                        auditDataIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                        if (!auditDataIdList.contains(bulkCementThreeCityUsageBulletIn.getId())){
                            auditDataIdList.add(bulkCementThreeCityUsageBulletIn.getId());
                            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                            cityData.setAuditDataIdList(idListStr);
                        }
                        // 更新最后一次更新时间
                        cityData.setLastUpdateTime(LocalDateTime.now());
                        cityData.setUpdateOn(LocalDateTime.now());
                        cityData.setUpdateBy(null);
                        // 有新上报的数据，就更新关联数据状态为未上报
                        cityData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                        dataRelevanceService.updateById(cityData);
                    }
                    relevanceDataId = cityData.getId();
                }else {
                    // 补充所在市的关联数据信息
                    BulkCementDirectReportSystemDataRelevance cityRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                    cityRelevanceData.setReportMonth(month);
                    List<Long> auditDataIdList = Lists.newArrayList();
                    auditDataIdList.add(bulkCementThreeCityUsageBulletIn.getId());
                    String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    cityRelevanceData.setAuditDataIdList(idListStr);
                    cityRelevanceData.setUnitResponsiblePerson(null);
                    cityRelevanceData.setPreparer(null);
                    cityRelevanceData.setReviewer(null);
                    cityRelevanceData.setSubmissionDate(null);
                    cityRelevanceData.setCreateOn(LocalDateTime.now());
                    cityRelevanceData.setCreateBy(null);
                    cityRelevanceData.setUpdateOn(LocalDateTime.now());
                    cityRelevanceData.setUpdateBy(null);
                    cityRelevanceData.setLastUpdateTime(LocalDateTime.now());
                    cityRelevanceData.setRegionId(cityRegionId);
                    // 获取所在市散装中心所属的管理企业ID
                    cityRelevanceData.setCompanyId(cityCompanyId);
                    cityRelevanceData.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                    cityRelevanceData.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_THREE_CITY_USAGE_BULLETIN.getCode());
                    // 有新上报的数据，就更新关联数据
                    cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.saveOrUpdate(cityRelevanceData);
                    relevanceDataId = cityRelevanceData.getId();
                }

                // 补充省级审核申请
                BulkCementDirectReportSystemAuditInfo provinceAuditInfo = new BulkCementDirectReportSystemAuditInfo();
                provinceAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                provinceAuditInfo.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_THREE_CITY_USAGE_BULLETIN.getCode());
                provinceAuditInfo.setCreateOn(month);
                provinceAuditInfo.setCreateBy(null);
                provinceAuditInfo.setUpdateOn(month);
                provinceAuditInfo.setUpdateBy(null);
                provinceAuditInfo.setAuditTime(month);
                provinceAuditInfo.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                auditInfoService.save(provinceAuditInfo);
                // 更新市级关联数据
                BulkCementDirectReportSystemDataRelevance cityRelevanceData = dataRelevanceService.getById(relevanceDataId);
                VUtils.isTrue(Objects.isNull(cityRelevanceData)).throwMessage("数据不存在!");
                // 关联审核信息ID
                cityRelevanceData.setAuditInfoId(provinceAuditInfo.getId());
                cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityRelevanceData.setUpdateOn(month.plusDays(20L));
                cityRelevanceData.setUpdateBy(null);
                cityRelevanceData.setUnitResponsiblePerson(null);
                cityRelevanceData.setPreparer(null);
                cityRelevanceData.setReviewer(null);
                cityRelevanceData.setSubmissionDate(null);
                dataRelevanceService.updateById(cityRelevanceData);

                // 判断上报月份省关联数据是否存在
                BulkCementDirectReportSystemDataRelevance provinceData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, DefValConstants.ZJREGION_ID)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode())
                        .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, month)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.BULK_CEMENT_THREE_CITY_USAGE_BULLETIN.getCode()));
                // 存在，更新市关联数据ID列表
                if (Objects.nonNull(provinceData)){
                    String auditDataIdListStr = provinceData.getAuditDataIdList();
                    List<Long> auditDataIdList;
                    if (StringUtils.isNotBlank(auditDataIdListStr)){
                        auditDataIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                        if (!auditDataIdList.contains(relevanceDataId)){
                            auditDataIdList.add(relevanceDataId);
                            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                            provinceData.setAuditDataIdList(idListStr);
                        }
                        // 更新最后一次更新时间
                        provinceData.setLastUpdateTime(month);
                        provinceData.setUpdateOn(month);
                        provinceData.setUpdateBy(null);
                        // 有新上报的数据，就更新关联数据状态为审核中
                        provinceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                        dataRelevanceService.updateById(provinceData);
                    }
                }else {
                    // 如果上报月份省级关联数据不存在
                    // 补充省散办关联数据信息
                    BulkCementDirectReportSystemDataRelevance provinceRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                    provinceRelevanceData.setReportMonth(month);
                    List<Long> auditDataIdList = Lists.newArrayList();
                    auditDataIdList.add(relevanceDataId);
                    String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    provinceRelevanceData.setAuditDataIdList(idListStr);

                    provinceRelevanceData.setUnitResponsiblePerson(null);
                    provinceRelevanceData.setPreparer(null);
                    provinceRelevanceData.setReviewer(null);
                    provinceRelevanceData.setSubmissionDate(null);
                    provinceRelevanceData.setCreateOn(month);
                    provinceRelevanceData.setCreateBy(null);
                    provinceRelevanceData.setUpdateOn(month);
                    provinceRelevanceData.setUpdateBy(null);
                    provinceRelevanceData.setLastUpdateTime(month);
                    provinceRelevanceData.setRegionId(DefValConstants.ZJREGION_ID);
                    provinceRelevanceData.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                    // 获取省散装中心所属的管理企业ID
                    CompanyDTO provinceCompanyDto = companiesCacheHelper.getByName(DefValConstants.PROVINCE + VehicleContant.ADMIN_COMPANY_NAME);
                    if (Objects.nonNull(provinceCompanyDto)) {
                        provinceRelevanceData.setCompanyId(provinceCompanyDto.getId());
                    }
                    provinceRelevanceData.setUnitResponsiblePerson(null);
                    provinceRelevanceData.setPreparer(null);
                    provinceRelevanceData.setReviewer(null);
                    provinceRelevanceData.setSubmissionDate(null);
                    provinceRelevanceData.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_THREE_CITY_USAGE_BULLETIN.getCode());
                    provinceRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.save(provinceRelevanceData);
                }

                // 创建省级审核记录
                BulkCementDirectReportSystemAuditRecord provinceAuditRecord = new BulkCementDirectReportSystemAuditRecord();
                provinceAuditRecord.setAuditDataId(cityRelevanceData.getId());
                provinceAuditRecord.setAuditInfoId(provinceAuditInfo.getId());
                provinceAuditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                provinceAuditRecord.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_THREE_CITY_USAGE_BULLETIN.getCode());
                provinceAuditRecord.setCompanyId(cityRelevanceData.getCompanyId());
                provinceAuditRecord.setRegionId(cityRelevanceData.getRegionId());
                provinceAuditRecord.setCreateOn(cityRelevanceData.getReportMonth());
                provinceAuditRecord.setCreateBy(null);
                provinceAuditRecord.setUpdateOn(cityRelevanceData.getReportMonth());
                provinceAuditRecord.setUpdateBy(null);
                provinceAuditRecord.setReportMonth(month);
                provinceAuditRecord.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                auditRecordService.save(provinceAuditRecord);

                System.out.println("已成功插入第" + i + "条数据!");
            }
        }
    }


    /**
     * 计算温台舟使用量数据同比增长率
     */
    @Test
    public void calculateBulkCementThreeCityUsageGrowthRateTest()  {

        List<BulkCementThreeCityUsageBulletin> dataList = bulkCementThreeCityUsageBulletinService.list();
        for (BulkCementThreeCityUsageBulletin data : dataList) {
            LocalDateTime reportMonth = data.getReportMonth();
            Long regionId = data.getRegionId();
            LocalDateTime preReportMonth = reportMonth.minusMonths(1L);
            // 获取去年当前上报月份该地区的散装水泥使用量数据
            LocalDateTime preYearReportMonth = preReportMonth.minusYears(1L);
            BulkCementThreeCityUsageBulletin preYearBulkCementThreeCityUsageBulletin = bulkCementThreeCityUsageBulletinService.getOne(Wrappers.lambdaQuery(BulkCementThreeCityUsageBulletin.class)
                    .eq(BulkCementThreeCityUsageBulletin::getRegionId, regionId)
                    .eq(BulkCementThreeCityUsageBulletin::getReportMonth, preYearReportMonth));
            if (Objects.isNull(preYearBulkCementThreeCityUsageBulletin)) {
                // 如果去年没有数据，那么今年的数据就不用计算了
                continue;
            }
            BigDecimal accumulativeUsage = data.getAccumulativeUsage();
            // 同比增长率: (今年这个月的累计使用量 - 去年这个月的累计使用量) / 去年这个月的累计使用量 * 100
            BigDecimal preYearAccumulativeUsage = preYearBulkCementThreeCityUsageBulletin.getAccumulativeUsage();
            BigDecimal preYearAccUsage = Objects.isNull(preYearAccumulativeUsage) ? BigDecimal.ZERO : preYearAccumulativeUsage;
            BigDecimal growthRate = accumulativeUsage.subtract(preYearAccUsage).divide(preYearAccUsage, 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100L));
            data.setGrowthRate(growthRate);
            bulkCementThreeCityUsageBulletinService.updateById(data);
        }
    }

    @Test
    public void concreteSupplyTest() throws FileNotFoundException {
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-01.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-02.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-03.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-04.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-05.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-06.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-07.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-08.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-09.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-10.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-11.xlsx");
        File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2022-12.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2023-01.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2023-02.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2023-03.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2023-04.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2023-05.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2023-06.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2023-07.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2023-08.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\混凝土供应量快报\\混凝土供应量快报-2023-09.xlsx");
        Workbook wb = readExcel(new FileInputStream(f),f.getName());
        Row row = null;
        List<Long> userList = Lists.newArrayList();
        if(wb != null) {
            //获取第一个sheet
            Sheet sheet = wb.getSheetAt(0);
            //获取最大行数
            int rownum = sheet.getPhysicalNumberOfRows();
            //获取第一行
            row = sheet.getRow(0);

            // 根据区县名称获取区域ID
            HashSet<String> countySet = new HashSet<>();
            Map<String, Region> regionMap = regionService.list().stream()
                    .filter(v -> !StrPool.EMPTY.equals(v.getName()) &&
                            !"市本级".equals(v.getName()) &&
                            countySet.add(v.getName()))
                    .collect(Collectors.toMap(Region::getName, v -> v));
            for (int i = 1; i < rownum; i++) {
                row = sheet.getRow(i);
                // 单位
                String regionName = Objects.nonNull(row.getCell(0)) ? row.getCell(0).toString() : StringUtils.EMPTY;
                // 上报月份
                Date reportMonth = Objects.nonNull(row.getCell(1)) ? row.getCell(1).getDateCellValue() : null;
                LocalDateTime month = reportMonth.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
                // 三类指导目标
                String threeCategoryGuidGoal = Objects.nonNull(row.getCell(2)) ? row.getCell(2).toString() : StringUtils.EMPTY;
                // 生产企业数量
                String productionCompanyNums = Objects.nonNull(row.getCell(3)) ? row.getCell(3).toString() : StringUtils.EMPTY;
                // 年设计生产能力
                String annualDesignProductionCapacity = Objects.nonNull(row.getCell(4)) ? row.getCell(4).toString() : StringUtils.EMPTY;
                // 本月实际产量
                String thisMonthOutput = Objects.nonNull(row.getCell(5)) ? row.getCell(5).toString() : StringUtils.EMPTY;
                // 累计实际产量
                String accumulativeOutput = Objects.nonNull(row.getCell(6)) ? row.getCell(6).toString() : StringUtils.EMPTY;
                // 本月使用散装水泥量
                String thisMonthCementUsage = Objects.nonNull(row.getCell(7)) ? row.getCell(7).toString() : StringUtils.EMPTY;
                // 累计使用散装水泥量
                String cementAccumulativeUsage = Objects.nonNull(row.getCell(8)) ? row.getCell(8).toString() : StringUtils.EMPTY;
                // 本月废弃物综合利用量
                String thisMonthWasteUtilization = Objects.nonNull(row.getCell(9)) ? row.getCell(9).toString() : StringUtils.EMPTY;
                // 累计废弃物综合利用量
                String accumulativeWasteUtilization = Objects.nonNull(row.getCell(10)) ? row.getCell(10).toString() : StringUtils.EMPTY;


                // 区县名称 获取区域ID、上级区域ID
                Long regionId = null;
                Long cityRegionId = null;
                String cityRegionName = null;
                for (Map.Entry<String, Region> regionEntry : regionMap.entrySet()) {
                    String regionNameStr = regionEntry.getKey();
                    if (regionNameStr.contains(regionName) && regionNameStr.length() < 4){
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    } else if ((regionNameStr.contains(regionName) && regionNameStr.equals("丽水经济技术开发区")) ||
                            (regionNameStr.contains(regionName) && regionNameStr.equals("景宁畲族自治县"))) {
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    }
                }
                if (Objects.isNull(regionId)){
                    throw new BizException("区域不存在!");
                }

                // 根据地区名称获取对应散装中心的企业信息
                Long companyId;
                Long cityCompanyId;
                CompanyDTO companyDto = companiesCacheHelper.getByName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                CompanyDTO cityCompanyDto = companiesCacheHelper.getByName(cityRegionName + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.isNull(companyDto) || Objects.isNull(cityCompanyDto)){
                    throw new BizException("管理企业不存在!");
                }else {
                    companyId = companyDto.getId();
                    cityCompanyId = cityCompanyDto.getId();
                }

                // 创建市级审核通过申请
                BulkCementDirectReportSystemAuditInfo cityAuditInfo = new BulkCementDirectReportSystemAuditInfo();
                cityAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityAuditInfo.setAuditDataType(UploadDataTypeEnum.CONCRETE_SUPPLY_BULLETIN.getCode());
                cityAuditInfo.setCreateOn(month);
                cityAuditInfo.setCreateBy(null);
                cityAuditInfo.setUpdateOn(month);
                cityAuditInfo.setUpdateBy(null);
                cityAuditInfo.setAuditTime(month);
                cityAuditInfo.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                auditInfoService.save(cityAuditInfo);

                // 保存上报数据信息
                // 创建上报记录
                ConcreteSupplyBulletin concreteSupplyBulletin = new ConcreteSupplyBulletin();
                concreteSupplyBulletin.setUnitName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                concreteSupplyBulletin.setThreeCategoryGuidGoal(BigDecimal.valueOf(Double.parseDouble(threeCategoryGuidGoal)));
                Double d = Double.parseDouble(productionCompanyNums);
                int proNum = d.intValue();
                concreteSupplyBulletin.setProductionCompanyNums(proNum);
                concreteSupplyBulletin.setAnnualDesignProductionCapacity(BigDecimal.valueOf(Double.parseDouble(annualDesignProductionCapacity)));
                concreteSupplyBulletin.setThisMonthOutput(BigDecimal.valueOf(Double.parseDouble(thisMonthOutput)));
                concreteSupplyBulletin.setAccumulativeOutput(BigDecimal.valueOf(Double.parseDouble(accumulativeOutput)));
                concreteSupplyBulletin.setThisMonthCementUsage(BigDecimal.valueOf(Double.parseDouble(thisMonthCementUsage)));
                concreteSupplyBulletin.setCementAccumulativeUsage(BigDecimal.valueOf(Double.parseDouble(cementAccumulativeUsage)));
                concreteSupplyBulletin.setThisMonthWasteUtilization(BigDecimal.valueOf(Double.parseDouble(thisMonthWasteUtilization)));
                concreteSupplyBulletin.setAccumulativeWasteUtilization(BigDecimal.valueOf(Double.parseDouble(accumulativeWasteUtilization)));
                concreteSupplyBulletin.setReportMonth(month);
                concreteSupplyBulletin.setCompanyId(companyId);
                concreteSupplyBulletin.setUnitResponsiblePerson(null);
                concreteSupplyBulletin.setPreparer(null);
                concreteSupplyBulletin.setReviewer(null);
                concreteSupplyBulletin.setSubmissionDate(null);
                concreteSupplyBulletin.setRegionId(regionId);
                concreteSupplyBulletin.setCreateOn(month);
                concreteSupplyBulletin.setCreateBy(null);
                concreteSupplyBulletin.setUpdateOn(month);
                concreteSupplyBulletin.setUpdateBy(null);
                concreteSupplyBulletin.setAuditInfoId(cityAuditInfo.getId());
                concreteSupplyBulletin.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                concreteSupplyBulletinService.saveOrUpdate(concreteSupplyBulletin);

                // 补充市级数据审核表信息
                BulkCementDirectReportSystemAuditRecord auditRecord = new BulkCementDirectReportSystemAuditRecord();
                auditRecord.setAuditDataId(concreteSupplyBulletin.getId());
                auditRecord.setAuditInfoId(cityAuditInfo.getId());
                auditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                auditRecord.setAuditDataType(UploadDataTypeEnum.CONCRETE_SUPPLY_BULLETIN.getCode());
                auditRecord.setCompanyId(companyId);
                auditRecord.setRegionId(regionId);
                auditRecord.setCreateOn(month.plusDays(20));
                auditRecord.setCreateBy(null);
                auditRecord.setUpdateOn(month.plusDays(20));
                auditRecord.setUpdateBy(null);
                auditRecord.setReportMonth(month);
                auditRecord.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                auditRecordService.save(auditRecord);

                Long relevanceDataId;
                // 判断上报月份所在市的关联数据不存在
                BulkCementDirectReportSystemDataRelevance cityData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, cityRegionId)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.CITY_AUDIT.getCode())
                        .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, month)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.CONCRETE_SUPPLY_BULLETIN.getCode()));
                // 已经存在，更新上报数据ID列表
                if (Objects.nonNull(cityData)){
                    String auditDataIdListStr = cityData.getAuditDataIdList();
                    List<Long> auditDataIdList;
                    if (StringUtils.isNotBlank(auditDataIdListStr)){
                        auditDataIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                        if (!auditDataIdList.contains(concreteSupplyBulletin.getId())){
                            auditDataIdList.add(concreteSupplyBulletin.getId());
                            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                            cityData.setAuditDataIdList(idListStr);
                        }
                        // 更新最后一次更新时间
                        cityData.setLastUpdateTime(LocalDateTime.now());
                        cityData.setUpdateOn(LocalDateTime.now());
                        cityData.setUpdateBy(null);
                        // 有新上报的数据，就更新关联数据状态为未上报
                        cityData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                        dataRelevanceService.updateById(cityData);
                    }
                    relevanceDataId = cityData.getId();
                }else {
                    // 补充所在市的关联数据信息
                    BulkCementDirectReportSystemDataRelevance cityRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                    cityRelevanceData.setReportMonth(month);
                    List<Long> auditDataIdList = Lists.newArrayList();
                    auditDataIdList.add(concreteSupplyBulletin.getId());
                    String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    cityRelevanceData.setAuditDataIdList(idListStr);
                    cityRelevanceData.setUnitResponsiblePerson(null);
                    cityRelevanceData.setPreparer(null);
                    cityRelevanceData.setReviewer(null);
                    cityRelevanceData.setSubmissionDate(null);
                    cityRelevanceData.setCreateOn(LocalDateTime.now());
                    cityRelevanceData.setCreateBy(null);
                    cityRelevanceData.setUpdateOn(LocalDateTime.now());
                    cityRelevanceData.setUpdateBy(null);
                    cityRelevanceData.setLastUpdateTime(LocalDateTime.now());
                    cityRelevanceData.setRegionId(cityRegionId);
                    // 获取所在市散装中心所属的管理企业ID
                    cityRelevanceData.setCompanyId(cityCompanyId);
                    cityRelevanceData.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                    cityRelevanceData.setAuditDataType(UploadDataTypeEnum.CONCRETE_SUPPLY_BULLETIN.getCode());
                    // 有新上报的数据，就更新关联数据
                    cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.saveOrUpdate(cityRelevanceData);
                    relevanceDataId = cityRelevanceData.getId();
                }

                // 补充省级审核申请
                BulkCementDirectReportSystemAuditInfo provinceAuditInfo = new BulkCementDirectReportSystemAuditInfo();
                provinceAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                provinceAuditInfo.setAuditDataType(UploadDataTypeEnum.CONCRETE_SUPPLY_BULLETIN.getCode());
                provinceAuditInfo.setCreateOn(month);
                provinceAuditInfo.setCreateBy(null);
                provinceAuditInfo.setUpdateOn(month);
                provinceAuditInfo.setUpdateBy(null);
                provinceAuditInfo.setAuditTime(month);
                provinceAuditInfo.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                auditInfoService.save(provinceAuditInfo);
                // 更新市级关联数据
                BulkCementDirectReportSystemDataRelevance cityRelevanceData = dataRelevanceService.getById(relevanceDataId);
                VUtils.isTrue(Objects.isNull(cityRelevanceData)).throwMessage("数据不存在!");
                // 关联审核信息ID
                cityRelevanceData.setAuditInfoId(provinceAuditInfo.getId());
                cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityRelevanceData.setUpdateOn(month.plusDays(20L));
                cityRelevanceData.setUpdateBy(null);
                cityRelevanceData.setUnitResponsiblePerson(null);
                cityRelevanceData.setPreparer(null);
                cityRelevanceData.setReviewer(null);
                cityRelevanceData.setSubmissionDate(null);
                dataRelevanceService.updateById(cityRelevanceData);

                // 判断上报月份省关联数据是否存在
                BulkCementDirectReportSystemDataRelevance provinceData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, DefValConstants.ZJREGION_ID)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode())
                        .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, month)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.CONCRETE_SUPPLY_BULLETIN.getCode()));
                // 存在，更新市关联数据ID列表
                if (Objects.nonNull(provinceData)){
                    String auditDataIdListStr = provinceData.getAuditDataIdList();
                    List<Long> auditDataIdList;
                    if (StringUtils.isNotBlank(auditDataIdListStr)){
                        auditDataIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                        if (!auditDataIdList.contains(relevanceDataId)){
                            auditDataIdList.add(relevanceDataId);
                            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                            provinceData.setAuditDataIdList(idListStr);
                        }
                        // 更新最后一次更新时间
                        provinceData.setLastUpdateTime(month);
                        provinceData.setUpdateOn(month);
                        provinceData.setUpdateBy(null);
                        // 有新上报的数据，就更新关联数据状态为审核中
                        provinceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                        dataRelevanceService.updateById(provinceData);
                    }
                }else {
                    // 如果上报月份省级关联数据不存在
                    // 补充省散办关联数据信息
                    BulkCementDirectReportSystemDataRelevance provinceRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                    provinceRelevanceData.setReportMonth(month);
                    List<Long> auditDataIdList = Lists.newArrayList();
                    auditDataIdList.add(relevanceDataId);
                    String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    provinceRelevanceData.setAuditDataIdList(idListStr);

                    provinceRelevanceData.setUnitResponsiblePerson(null);
                    provinceRelevanceData.setPreparer(null);
                    provinceRelevanceData.setReviewer(null);
                    provinceRelevanceData.setSubmissionDate(null);
                    provinceRelevanceData.setCreateOn(month);
                    provinceRelevanceData.setCreateBy(null);
                    provinceRelevanceData.setUpdateOn(month);
                    provinceRelevanceData.setUpdateBy(null);
                    provinceRelevanceData.setLastUpdateTime(month);
                    provinceRelevanceData.setRegionId(DefValConstants.ZJREGION_ID);
                    provinceRelevanceData.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                    // 获取省散装中心所属的管理企业ID
                    CompanyDTO provinceCompanyDto = companiesCacheHelper.getByName(DefValConstants.PROVINCE + VehicleContant.ADMIN_COMPANY_NAME);
                    if (Objects.nonNull(provinceCompanyDto)) {
                        provinceRelevanceData.setCompanyId(provinceCompanyDto.getId());
                    }
                    provinceRelevanceData.setUnitResponsiblePerson(null);
                    provinceRelevanceData.setPreparer(null);
                    provinceRelevanceData.setReviewer(null);
                    provinceRelevanceData.setSubmissionDate(null);
                    provinceRelevanceData.setAuditDataType(UploadDataTypeEnum.CONCRETE_SUPPLY_BULLETIN.getCode());
                    provinceRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.save(provinceRelevanceData);
                }

                // 创建省级审核记录
                BulkCementDirectReportSystemAuditRecord provinceAuditRecord = new BulkCementDirectReportSystemAuditRecord();
                provinceAuditRecord.setAuditDataId(cityRelevanceData.getId());
                provinceAuditRecord.setAuditInfoId(provinceAuditInfo.getId());
                provinceAuditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                provinceAuditRecord.setAuditDataType(UploadDataTypeEnum.CONCRETE_SUPPLY_BULLETIN.getCode());
                provinceAuditRecord.setCompanyId(cityRelevanceData.getCompanyId());
                provinceAuditRecord.setRegionId(cityRelevanceData.getRegionId());
                provinceAuditRecord.setCreateOn(cityRelevanceData.getReportMonth());
                provinceAuditRecord.setCreateBy(null);
                provinceAuditRecord.setUpdateOn(cityRelevanceData.getReportMonth());
                provinceAuditRecord.setUpdateBy(null);
                provinceAuditRecord.setReportMonth(month);
                provinceAuditRecord.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                auditRecordService.save(provinceAuditRecord);

                System.out.println("已成功插入第" + i + "条数据!");
            }
        }
    }

    @Test
    public void mortarSupplyTest() throws FileNotFoundException {
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-01.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-02.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-03.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-04.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-05.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-06.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-07.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-08.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-09.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-10.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-11.xlsx");
        File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2022-12.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2023-01.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2023-02.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2023-03.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2023-04.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2023-05.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2023-06.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2023-07.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2023-08.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\砂浆供应量快报\\砂浆供应量快报-2023-09.xlsx");
        Workbook wb = readExcel(new FileInputStream(f),f.getName());
        Row row = null;
        List<Long> userList = Lists.newArrayList();
        if(wb != null) {
            //获取第一个sheet
            Sheet sheet = wb.getSheetAt(0);
            //获取最大行数
            int rownum = sheet.getPhysicalNumberOfRows();
            //获取第一行
            row = sheet.getRow(0);

            // 根据区县名称获取区域ID
            HashSet<String> countySet = new HashSet<>();
            Map<String, Region> regionMap = regionService.list().stream()
                    .filter(v -> !StrPool.EMPTY.equals(v.getName()) &&
                            !"市本级".equals(v.getName()) &&
                            countySet.add(v.getName()))
                    .collect(Collectors.toMap(Region::getName, v -> v));
            for (int i = 1; i < rownum; i++) {
                row = sheet.getRow(i);
                // 地区
                String regionName = Objects.nonNull(row.getCell(0)) ? row.getCell(0).toString() : StringUtils.EMPTY;
                // 上报月份
                Date reportMonth = Objects.nonNull(row.getCell(1)) ? row.getCell(1).getDateCellValue() : null;
                LocalDateTime month = reportMonth.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
                // 二类指导目标
                String twoCategoryGuidGoal = Objects.nonNull(row.getCell(2)) ? row.getCell(2).toString() : StringUtils.EMPTY;
                // 普通干混砂浆生产企业数量
                String dryMixedMortarProductionCompanyNum = Objects.nonNull(row.getCell(3)) ? row.getCell(3).toString() : StringUtils.EMPTY;
                // 普通干混砂浆生产总能力
                String dryMixedMortarProductiveCapacity = Objects.nonNull(row.getCell(4)) ? row.getCell(4).toString() : StringUtils.EMPTY;
                // 普通干混砂浆散装能力
                String dryMixedMortarBulkCapacity = Objects.nonNull(row.getCell(5)) ? row.getCell(5).toString() : StringUtils.EMPTY;
                // 本月总产量
                String thisMonthTotalOutput = Objects.nonNull(row.getCell(6)) ? row.getCell(6).toString() : StringUtils.EMPTY;
                // 本月累计产量
                String thisMonthAccumulativeOutput = Objects.nonNull(row.getCell(7)) ? row.getCell(7).toString() : StringUtils.EMPTY;
                // 普通干混砂浆本月产量
                String dryMixedMortarThisMonthOutput = Objects.nonNull(row.getCell(8)) ? row.getCell(8).toString() : StringUtils.EMPTY;
                // 普通干混砂浆累计产量
                String dryMixedMortarThisMonthAccumulativeOutput = Objects.nonNull(row.getCell(9)) ? row.getCell(9).toString() : StringUtils.EMPTY;
                // 普通干混砂浆同比增长量
                String dryMixedMortarIncrement = Objects.nonNull(row.getCell(10)) ? row.getCell(10).toString() : StringUtils.EMPTY;
                // 普通干混砂浆增长率
                String dryMixedMortarGrowthRate = Objects.nonNull(row.getCell(11)) ? row.getCell(11).toString() : StringUtils.EMPTY;
                // 普通干混砂浆本月散装量
                String dryMixedMortarThisMonthBulkQuantity = Objects.nonNull(row.getCell(12)) ? row.getCell(12).toString() : StringUtils.EMPTY;
                // 普通干混砂浆累计散装量
                String dryMixedMortarAccumulativeBulkQuantity = Objects.nonNull(row.getCell(13)) ? row.getCell(13).toString() : StringUtils.EMPTY;
                // 湿拌砂浆本月产量
                String wetMortarThisMonthOutput = Objects.nonNull(row.getCell(14)) ? row.getCell(14).toString() : StringUtils.EMPTY;
                // 湿拌砂浆累计产量
                String wetMortarAccumulativeOutput = Objects.nonNull(row.getCell(15)) ? row.getCell(15).toString() : StringUtils.EMPTY;
                // 散装水泥本月使用量
                String bulkCementThisMonthUsage = Objects.nonNull(row.getCell(16)) ? row.getCell(16).toString() : StringUtils.EMPTY;
                // 散装水泥累计使用量
                String bulkCementAccumulativeUsage = Objects.nonNull(row.getCell(17)) ? row.getCell(17).toString() : StringUtils.EMPTY;
                // 废弃物本月综合利用量
                String wasteThisMonthComprehensiveUtilization = Objects.nonNull(row.getCell(18)) ? row.getCell(18).toString() : StringUtils.EMPTY;
                // 废弃物累计综合利用量
                String wasteAccumulativeComprehensiveUtilization = Objects.nonNull(row.getCell(19)) ? row.getCell(19).toString() : StringUtils.EMPTY;


                // 区县名称 获取区域ID、上级区域ID
                Long regionId = null;
                Long cityRegionId = null;
                String cityRegionName = null;
                for (Map.Entry<String, Region> regionEntry : regionMap.entrySet()) {
                    String regionNameStr = regionEntry.getKey();
                    if (regionNameStr.contains(regionName) && regionNameStr.length() < 4){
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    } else if ((regionNameStr.contains(regionName) && regionNameStr.equals("丽水经济技术开发区")) ||
                            (regionNameStr.contains(regionName) && regionNameStr.equals("景宁畲族自治县"))) {
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    }
                }
                if (Objects.isNull(regionId)){
                    throw new BizException("区域不存在!");
                }

                // 根据地区名称获取对应散装中心的企业信息
                Long companyId;
                Long cityCompanyId;
                CompanyDTO companyDto = companiesCacheHelper.getByName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                CompanyDTO cityCompanyDto = companiesCacheHelper.getByName(cityRegionName + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.isNull(companyDto) || Objects.isNull(cityCompanyDto)){
                    throw new BizException("管理企业不存在!");
                }else {
                    companyId = companyDto.getId();
                    cityCompanyId = cityCompanyDto.getId();
                }

                // 创建市级审核通过申请
                BulkCementDirectReportSystemAuditInfo cityAuditInfo = new BulkCementDirectReportSystemAuditInfo();
                cityAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityAuditInfo.setAuditDataType(UploadDataTypeEnum.MORTAR_SUPPLY_BULLETIN.getCode());
                cityAuditInfo.setCreateOn(month);
                cityAuditInfo.setCreateBy(null);
                cityAuditInfo.setUpdateOn(month);
                cityAuditInfo.setUpdateBy(null);
                cityAuditInfo.setAuditTime(month);
                cityAuditInfo.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                auditInfoService.save(cityAuditInfo);

                // 保存上报数据信息
                // 创建上报记录
                MortarSupplyBulletin mortarSupplyBulletin = new MortarSupplyBulletin();
                mortarSupplyBulletin.setRegionName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                mortarSupplyBulletin.setTwoCategoryGuidGoal(BigDecimal.valueOf(Double.parseDouble(twoCategoryGuidGoal)));
                Double d = Double.parseDouble(dryMixedMortarProductionCompanyNum);
                int proNum = d.intValue();
                mortarSupplyBulletin.setDryMixedMortarProductionCompanyNum(proNum);
                mortarSupplyBulletin.setDryMixedMortarProductiveCapacity(BigDecimal.valueOf(Double.parseDouble(dryMixedMortarProductiveCapacity)));
                mortarSupplyBulletin.setDryMixedMortarBulkCapacity(BigDecimal.valueOf(Double.parseDouble(dryMixedMortarBulkCapacity)));
                mortarSupplyBulletin.setThisMonthTotalOutput(BigDecimal.valueOf(Double.parseDouble(thisMonthTotalOutput)));
                mortarSupplyBulletin.setThisMonthAccumulativeOutput(BigDecimal.valueOf(Double.parseDouble(thisMonthAccumulativeOutput)));
                mortarSupplyBulletin.setDryMixedMortarThisMonthOutput(BigDecimal.valueOf(Double.parseDouble(dryMixedMortarThisMonthOutput)));
                mortarSupplyBulletin.setDryMixedMortarThisMonthAccumulativeOutput(BigDecimal.valueOf(Double.parseDouble(dryMixedMortarThisMonthAccumulativeOutput)));
                mortarSupplyBulletin.setDryMixedMortarIncrement(BigDecimal.valueOf(Double.parseDouble(dryMixedMortarIncrement)));
                mortarSupplyBulletin.setDryMixedMortarGrowthRate(BigDecimal.valueOf(Double.parseDouble(dryMixedMortarGrowthRate)));
                mortarSupplyBulletin.setDryMixedMortarThisMonthBulkQuantity(BigDecimal.valueOf(Double.parseDouble(dryMixedMortarThisMonthBulkQuantity)));
                mortarSupplyBulletin.setDryMixedMortarAccumulativeBulkQuantity(BigDecimal.valueOf(Double.parseDouble(dryMixedMortarAccumulativeBulkQuantity)));
                mortarSupplyBulletin.setWetMortarThisMonthOutput(BigDecimal.valueOf(Double.parseDouble(wetMortarThisMonthOutput)));
                mortarSupplyBulletin.setWetMortarAccumulativeOutput(BigDecimal.valueOf(Double.parseDouble(wetMortarAccumulativeOutput)));
                mortarSupplyBulletin.setBulkCementThisMonthUsage(BigDecimal.valueOf(Double.parseDouble(bulkCementThisMonthUsage)));
                mortarSupplyBulletin.setBulkCementAccumulativeUsage(BigDecimal.valueOf(Double.parseDouble(bulkCementAccumulativeUsage)));
                mortarSupplyBulletin.setWasteThisMonthComprehensiveUtilization(BigDecimal.valueOf(Double.parseDouble(wasteThisMonthComprehensiveUtilization)));
                mortarSupplyBulletin.setWasteAccumulativeComprehensiveUtilization(BigDecimal.valueOf(Double.parseDouble(wasteAccumulativeComprehensiveUtilization)));
                mortarSupplyBulletin.setReportMonth(month);
                mortarSupplyBulletin.setCompanyId(companyId);
                mortarSupplyBulletin.setUnitResponsiblePerson(null);
                mortarSupplyBulletin.setPreparer(null);
                mortarSupplyBulletin.setReviewer(null);
                mortarSupplyBulletin.setSubmissionDate(null);
                mortarSupplyBulletin.setRegionId(regionId);
                mortarSupplyBulletin.setCreateOn(month);
                mortarSupplyBulletin.setCreateBy(null);
                mortarSupplyBulletin.setUpdateOn(month);
                mortarSupplyBulletin.setUpdateBy(null);
                mortarSupplyBulletin.setAuditInfoId(cityAuditInfo.getId());
                mortarSupplyBulletin.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                mortarSupplyBulletinService.saveOrUpdate(mortarSupplyBulletin);

                // 补充市级数据审核表信息
                BulkCementDirectReportSystemAuditRecord auditRecord = new BulkCementDirectReportSystemAuditRecord();
                auditRecord.setAuditDataId(mortarSupplyBulletin.getId());
                auditRecord.setAuditInfoId(cityAuditInfo.getId());
                auditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                auditRecord.setAuditDataType(UploadDataTypeEnum.MORTAR_SUPPLY_BULLETIN.getCode());
                auditRecord.setCompanyId(companyId);
                auditRecord.setRegionId(regionId);
                auditRecord.setCreateOn(month.plusDays(20));
                auditRecord.setCreateBy(null);
                auditRecord.setUpdateOn(month.plusDays(20));
                auditRecord.setUpdateBy(null);
                auditRecord.setReportMonth(month);
                auditRecord.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                auditRecordService.save(auditRecord);

                Long relevanceDataId;
                // 判断上报月份所在市的关联数据不存在
                BulkCementDirectReportSystemDataRelevance cityData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, cityRegionId)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.CITY_AUDIT.getCode())
                        .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, month)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.MORTAR_SUPPLY_BULLETIN.getCode()));
                // 已经存在，更新上报数据ID列表
                if (Objects.nonNull(cityData)){
                    String auditDataIdListStr = cityData.getAuditDataIdList();
                    List<Long> auditDataIdList;
                    if (StringUtils.isNotBlank(auditDataIdListStr)){
                        auditDataIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                        if (!auditDataIdList.contains(mortarSupplyBulletin.getId())){
                            auditDataIdList.add(mortarSupplyBulletin.getId());
                            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                            cityData.setAuditDataIdList(idListStr);
                        }
                        // 更新最后一次更新时间
                        cityData.setLastUpdateTime(LocalDateTime.now());
                        cityData.setUpdateOn(LocalDateTime.now());
                        cityData.setUpdateBy(null);
                        // 有新上报的数据，就更新关联数据状态为未上报
                        cityData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                        dataRelevanceService.updateById(cityData);
                    }
                    relevanceDataId = cityData.getId();
                }else {
                    // 补充所在市的关联数据信息
                    BulkCementDirectReportSystemDataRelevance cityRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                    cityRelevanceData.setReportMonth(month);
                    List<Long> auditDataIdList = Lists.newArrayList();
                    auditDataIdList.add(mortarSupplyBulletin.getId());
                    String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    cityRelevanceData.setAuditDataIdList(idListStr);
                    cityRelevanceData.setUnitResponsiblePerson(null);
                    cityRelevanceData.setPreparer(null);
                    cityRelevanceData.setReviewer(null);
                    cityRelevanceData.setSubmissionDate(null);
                    cityRelevanceData.setCreateOn(LocalDateTime.now());
                    cityRelevanceData.setCreateBy(null);
                    cityRelevanceData.setUpdateOn(LocalDateTime.now());
                    cityRelevanceData.setUpdateBy(null);
                    cityRelevanceData.setLastUpdateTime(LocalDateTime.now());
                    cityRelevanceData.setRegionId(cityRegionId);
                    // 获取所在市散装中心所属的管理企业ID
                    cityRelevanceData.setCompanyId(cityCompanyId);
                    cityRelevanceData.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                    cityRelevanceData.setAuditDataType(UploadDataTypeEnum.MORTAR_SUPPLY_BULLETIN.getCode());
                    // 有新上报的数据，就更新关联数据
                    cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.saveOrUpdate(cityRelevanceData);
                    relevanceDataId = cityRelevanceData.getId();
                }

                // 补充省级审核申请
                BulkCementDirectReportSystemAuditInfo provinceAuditInfo = new BulkCementDirectReportSystemAuditInfo();
                provinceAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                provinceAuditInfo.setAuditDataType(UploadDataTypeEnum.MORTAR_SUPPLY_BULLETIN.getCode());
                provinceAuditInfo.setCreateOn(month);
                provinceAuditInfo.setCreateBy(null);
                provinceAuditInfo.setUpdateOn(month);
                provinceAuditInfo.setUpdateBy(null);
                provinceAuditInfo.setAuditTime(month);
                provinceAuditInfo.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                auditInfoService.save(provinceAuditInfo);
                // 更新市级关联数据
                BulkCementDirectReportSystemDataRelevance cityRelevanceData = dataRelevanceService.getById(relevanceDataId);
                VUtils.isTrue(Objects.isNull(cityRelevanceData)).throwMessage("数据不存在!");
                // 关联审核信息ID
                cityRelevanceData.setAuditInfoId(provinceAuditInfo.getId());
                cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityRelevanceData.setUpdateOn(month.plusDays(20L));
                cityRelevanceData.setUpdateBy(null);
                cityRelevanceData.setUnitResponsiblePerson(null);
                cityRelevanceData.setPreparer(null);
                cityRelevanceData.setReviewer(null);
                cityRelevanceData.setSubmissionDate(null);
                dataRelevanceService.updateById(cityRelevanceData);

                // 判断上报月份省关联数据是否存在
                BulkCementDirectReportSystemDataRelevance provinceData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                        .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, DefValConstants.ZJREGION_ID)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode())
                        .eq(BulkCementDirectReportSystemDataRelevance::getReportMonth, month)
                        .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.MORTAR_SUPPLY_BULLETIN.getCode()));
                // 存在，更新市关联数据ID列表
                if (Objects.nonNull(provinceData)){
                    String auditDataIdListStr = provinceData.getAuditDataIdList();
                    List<Long> auditDataIdList;
                    if (StringUtils.isNotBlank(auditDataIdListStr)){
                        auditDataIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                        if (!auditDataIdList.contains(relevanceDataId)){
                            auditDataIdList.add(relevanceDataId);
                            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                            provinceData.setAuditDataIdList(idListStr);
                        }
                        // 更新最后一次更新时间
                        provinceData.setLastUpdateTime(month);
                        provinceData.setUpdateOn(month);
                        provinceData.setUpdateBy(null);
                        // 有新上报的数据，就更新关联数据状态为审核中
                        provinceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                        dataRelevanceService.updateById(provinceData);
                    }
                }else {
                    // 如果上报月份省级关联数据不存在
                    // 补充省散办关联数据信息
                    BulkCementDirectReportSystemDataRelevance provinceRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                    provinceRelevanceData.setReportMonth(month);
                    List<Long> auditDataIdList = Lists.newArrayList();
                    auditDataIdList.add(relevanceDataId);
                    String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    provinceRelevanceData.setAuditDataIdList(idListStr);

                    provinceRelevanceData.setUnitResponsiblePerson(null);
                    provinceRelevanceData.setPreparer(null);
                    provinceRelevanceData.setReviewer(null);
                    provinceRelevanceData.setSubmissionDate(null);
                    provinceRelevanceData.setCreateOn(month);
                    provinceRelevanceData.setCreateBy(null);
                    provinceRelevanceData.setUpdateOn(month);
                    provinceRelevanceData.setUpdateBy(null);
                    provinceRelevanceData.setLastUpdateTime(month);
                    provinceRelevanceData.setRegionId(DefValConstants.ZJREGION_ID);
                    provinceRelevanceData.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                    // 获取省散装中心所属的管理企业ID
                    CompanyDTO provinceCompanyDto = companiesCacheHelper.getByName(DefValConstants.PROVINCE + VehicleContant.ADMIN_COMPANY_NAME);
                    if (Objects.nonNull(provinceCompanyDto)) {
                        provinceRelevanceData.setCompanyId(provinceCompanyDto.getId());
                    }
                    provinceRelevanceData.setUnitResponsiblePerson(null);
                    provinceRelevanceData.setPreparer(null);
                    provinceRelevanceData.setReviewer(null);
                    provinceRelevanceData.setSubmissionDate(null);
                    provinceRelevanceData.setAuditDataType(UploadDataTypeEnum.MORTAR_SUPPLY_BULLETIN.getCode());
                    provinceRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.save(provinceRelevanceData);
                }

                // 创建省级审核记录
                BulkCementDirectReportSystemAuditRecord provinceAuditRecord = new BulkCementDirectReportSystemAuditRecord();
                provinceAuditRecord.setAuditDataId(cityRelevanceData.getId());
                provinceAuditRecord.setAuditInfoId(provinceAuditInfo.getId());
                provinceAuditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                provinceAuditRecord.setAuditDataType(UploadDataTypeEnum.MORTAR_SUPPLY_BULLETIN.getCode());
                provinceAuditRecord.setCompanyId(cityRelevanceData.getCompanyId());
                provinceAuditRecord.setRegionId(cityRelevanceData.getRegionId());
                provinceAuditRecord.setCreateOn(cityRelevanceData.getReportMonth());
                provinceAuditRecord.setCreateBy(null);
                provinceAuditRecord.setUpdateOn(cityRelevanceData.getReportMonth());
                provinceAuditRecord.setUpdateBy(null);
                provinceAuditRecord.setReportMonth(month);
                provinceAuditRecord.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                auditRecordService.save(provinceAuditRecord);

                System.out.println("已成功插入第" + i + "条数据!");
            }
        }
    }

    @Test
    public void bulkCementLogFacStaTest() throws FileNotFoundException {
        // ------------------------------------------杭州市-------------------------------------
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\杭州市\\萧山.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\杭州市\\余杭.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\杭州市\\富阳.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\杭州市\\桐庐.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\杭州市\\建德.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\杭州市\\临安.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\杭州市\\淳安.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\杭州市\\钱塘.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\杭州市\\临平.xlsx");
        // ------------------------------------------宁波市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\宁波市\\余姚.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\宁波市\\慈溪.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\宁波市\\象山.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\宁波市\\宁海.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\宁波市\\鄞州.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\宁波市\\北仑.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\宁波市\\镇海.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\宁波市\\奉化.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\宁波市\\江北.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\宁波市\\海曙.xlsx");
        // ------------------------------------------温州市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\鹿城.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\瓯海.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\龙湾.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\瑞安.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\乐清.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\永嘉.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\平阳.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\苍南.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\文成.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\洞头.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\泰顺.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\温州市\\龙港.xlsx");
        // ------------------------------------------嘉兴市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\嘉兴市\\南湖.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\嘉兴市\\秀洲.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\嘉兴市\\嘉善.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\嘉兴市\\平湖.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\嘉兴市\\海盐.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\嘉兴市\\海宁.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\嘉兴市\\桐乡.xlsx");
        // ------------------------------------------湖州市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\湖州市\\德清.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\湖州市\\长兴.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\湖州市\\安吉.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\湖州市\\吴兴.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\湖州市\\吴兴.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\湖州市\\南浔.xlsx");
        // ------------------------------------------绍兴市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\绍兴市\\越城.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\绍兴市\\柯桥.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\绍兴市\\诸暨.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\绍兴市\\上虞.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\绍兴市\\嵊州.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\绍兴市\\新昌.xlsx");
        // ------------------------------------------金华市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\金华市\\金东.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\金华市\\婺城.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\金华市\\兰溪.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\金华市\\浦江.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\金华市\\东阳.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\金华市\\义乌.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\金华市\\永康.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\金华市\\武义.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\金华市\\磐安.xlsx");
        // ------------------------------------------衢州市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\衢州市\\衢江.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\衢州市\\江山.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\衢州市\\常山.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\衢州市\\开化.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\衢州市\\龙游.xlsx");
        // ------------------------------------------舟山市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\舟山市\\定海.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\舟山市\\普陀.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\舟山市\\岱山.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\舟山市\\嵊泗.xlsx");
        // ------------------------------------------台州市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\台州市\\椒江.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\台州市\\路桥.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\台州市\\黄岩.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\台州市\\临海.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\台州市\\温岭.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\台州市\\仙居.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\台州市\\天台.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\台州市\\三门.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\台州市\\玉环.xlsx");
        // ------------------------------------------丽水市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\丽水市\\莲都.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\丽水市\\青田.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\丽水市\\缙云.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\丽水市\\松阳.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\丽水市\\遂昌.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\丽水市\\龙泉.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\丽水市\\云和.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\丽水市\\景宁畲族自治县.xlsx");
        File f = new File("D:\\work\\水泥车直报系统\\data\\物流设施统计年报\\丽水市\\丽水经济技术开发区.xlsx");

        Workbook wb = readExcel(new FileInputStream(f),f.getName());
        Row row = null;
        List<Long> userList = Lists.newArrayList();
        if(wb != null) {
            //获取第一个sheet
            Sheet sheet = wb.getSheetAt(0);
            //获取最大行数
            int rownum = sheet.getPhysicalNumberOfRows();
            //获取第一行
            row = sheet.getRow(0);

            // 根据区县名称获取区域ID
            HashSet<String> countySet = new HashSet<>();
            Map<String, Region> regionMap = regionService.list().stream()
                    .filter(v -> !StrPool.EMPTY.equals(v.getName()) &&
                            !"市本级".equals(v.getName()) &&
                            countySet.add(v.getName()))
                    .collect(Collectors.toMap(Region::getName, v -> v));

            List<ReqBulkCementLogFacStaDataUploadDTO> dataList = Lists.newArrayList();

            Long regionId = null;
            Long cityRegionId = null;
            String cityRegionName = null;

            Long companyId = null;
            Long cityCompanyId = null;

            String unitResponsiblePerson = null;
            String preparer = null;
            String reviewer = null;
            LocalDateTime subDate = null;

            for (int i = 1; i < rownum; i++) {
                row = sheet.getRow(i);
                // 地区
                String regionName = Objects.nonNull(row.getCell(0)) ? row.getCell(0).toString() : StringUtils.EMPTY;
                // 上报年份
                String reportYear = Objects.nonNull(row.getCell(1)) ? row.getCell(1).toString() : null;
                Double parseDouble = Double.parseDouble(reportYear);
                int year = parseDouble.intValue();
                // 设备名称
                String facilityName = Objects.nonNull(row.getCell(2)) ? row.getCell(2).toString() : StringUtils.EMPTY;
                // 年初数量
                String yearBeginNum = Objects.nonNull(row.getCell(3)) ? row.getCell(3).toString() : StringUtils.EMPTY;
                // 年初容量
                String yearBeginCapacity = Objects.nonNull(row.getCell(4)) ? row.getCell(4).toString() : StringUtils.EMPTY;
                // 本年新增数量
                String thisYearNewAddNum = Objects.nonNull(row.getCell(5)) ? row.getCell(5).toString() : StringUtils.EMPTY;
                // 本年新增容量
                String thisYearNewAddCapacity = Objects.nonNull(row.getCell(6)) ? row.getCell(6).toString() : StringUtils.EMPTY;
                // 本年报废数量
                String thisYearScrapNum = Objects.nonNull(row.getCell(7)) ? row.getCell(7).toString() : StringUtils.EMPTY;
                // 本年报废容量
                String thisYearScrapCapacity = Objects.nonNull(row.getCell(8)) ? row.getCell(8).toString() : StringUtils.EMPTY;
                // 年末数量
                String yearEndNum = Objects.nonNull(row.getCell(9)) ? row.getCell(9).toString() : StringUtils.EMPTY;
                // 年末容量
                String yearEndCapacity = Objects.nonNull(row.getCell(10)) ? row.getCell(10).toString() : StringUtils.EMPTY;
                // 本年实际作业量
                String thisYearWorkAmount = Objects.nonNull(row.getCell(11)) ? row.getCell(11).toString() : StringUtils.EMPTY;
                // 单位负责人
                unitResponsiblePerson = Objects.nonNull(row.getCell(12)) ? row.getCell(12).toString() : StringUtils.EMPTY;
                // 填表人
                preparer = Objects.nonNull(row.getCell(13)) ? row.getCell(13).toString() : StringUtils.EMPTY;
                // 复核人
                reviewer = Objects.nonNull(row.getCell(14)) ? row.getCell(14).toString() : StringUtils.EMPTY;
                // 报出日期
                Date submissionDate = Objects.nonNull(row.getCell(15)) ? row.getCell(15).getDateCellValue() : null;
                if (Objects.nonNull(submissionDate)) {
                    subDate = submissionDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
                }else {
                    subDate = LocalDateTime.now().minusMonths(9).minusDays(15L);
                }

                // 区县名称 获取区域ID、上级区域ID
                for (Map.Entry<String, Region> regionEntry : regionMap.entrySet()) {
                    String regionNameStr = regionEntry.getKey();
                    if (regionNameStr.contains(regionName) && regionNameStr.length() < 4){
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    } else if ((regionNameStr.contains(regionName) && regionNameStr.equals("丽水经济技术开发区")) ||
                            (regionNameStr.contains(regionName) && regionNameStr.equals("景宁畲族自治县"))) {
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    }
                }
                if (Objects.isNull(regionId)){
                    throw new BizException("区域不存在!");
                }

                // 根据地区名称获取对应散装中心的企业信息
                CompanyDTO companyDto = companiesCacheHelper.getByName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                CompanyDTO cityCompanyDto = companiesCacheHelper.getByName(cityRegionName + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.isNull(companyDto) || Objects.isNull(cityCompanyDto)){
                    throw new BizException("管理企业不存在!");
                }else {
                    companyId = companyDto.getId();
                    cityCompanyId = cityCompanyDto.getId();
                }

                ReqBulkCementLogFacStaDataUploadDTO uploadDto = new ReqBulkCementLogFacStaDataUploadDTO();
                uploadDto.setRegionName(regionName);
                uploadDto.setCompanyId(companyId);
                uploadDto.setRegionId(regionId);
                uploadDto.setFacilityName(facilityName);
                Double d = Double.parseDouble(yearBeginNum);
                int beginNum = d.intValue();
                uploadDto.setYearBeginNum(beginNum);
                uploadDto.setYearBeginCapacity(BigDecimal.valueOf(Double.parseDouble(yearBeginCapacity)));
                Double d2 = Double.parseDouble(thisYearNewAddNum);
                int newAddNum = d2.intValue();
                uploadDto.setThisYearNewAddNum(newAddNum);
                uploadDto.setThisYearNewAddCapacity(BigDecimal.valueOf(Double.parseDouble(thisYearNewAddCapacity)));
                Double d3 = Double.parseDouble(thisYearScrapNum);
                int scrapNum = d3.intValue();
                uploadDto.setThisYearScrapNum(scrapNum);
                uploadDto.setThisYearScrapCapacity(BigDecimal.valueOf(Double.parseDouble(thisYearScrapCapacity)));
                Double d4 = Double.parseDouble(yearEndNum);
                int endNum = d4.intValue();
                uploadDto.setYearEndNum(endNum);
                uploadDto.setYearEndCapacity(BigDecimal.valueOf(Double.parseDouble(yearEndCapacity)));
                uploadDto.setThisYearWorkAmount(BigDecimal.valueOf(Double.parseDouble(thisYearWorkAmount)));
                uploadDto.setReportYear(year);
                uploadDto.setUnitResponsiblePerson(unitResponsiblePerson);
                uploadDto.setPreparer(preparer);
                uploadDto.setReviewer(reviewer);
                uploadDto.setSubmissionDate(subDate);
                dataList.add(uploadDto);
            }

            // 先提交市级审核申请
            BulkCementDirectReportSystemAuditInfo cityAuditInfo = new BulkCementDirectReportSystemAuditInfo();
            cityAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            cityAuditInfo.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode());
            cityAuditInfo.setCreateOn(subDate);
            cityAuditInfo.setCreateBy(null);
            cityAuditInfo.setUpdateOn(subDate);
            cityAuditInfo.setUpdateBy(null);
            cityAuditInfo.setAuditTime(subDate);
            cityAuditInfo.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
            auditInfoService.save(cityAuditInfo);

            // 创建区县关联数据信息(对应每个设备名称的数据关系为一对多)
            BulkCementDirectReportSystemDataRelevance countryData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId)
                    .eq(BulkCementDirectReportSystemDataRelevance::getReportYear, 2022)
                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode()));
            BulkCementDirectReportSystemDataRelevance countryRelevanceData = new BulkCementDirectReportSystemDataRelevance();
            // 说明为重新提交
            if (Objects.nonNull(countryData)){
                // 先删除关联的已经保存的各设备名称的数据
                String auditDataIdList = countryData.getAuditDataIdList();
                if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(auditDataIdList)){
                    List<Long> idList = Arrays.stream(auditDataIdList.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                    if (CollUtil.isNotEmpty(idList)){
                        bulkCementLogFacStaService.remove(Wrappers.lambdaQuery(BulkCementLogisticFacilityStatisticAnnualReport.class)
                                .in(BulkCementLogisticFacilityStatisticAnnualReport::getId,idList));
                    }
                }
                countryRelevanceData.setId(countryData.getId());
            }
            countryRelevanceData.setReportYear(2022);
            countryRelevanceData.setUnitResponsiblePerson(unitResponsiblePerson);
            countryRelevanceData.setPreparer(preparer);
            countryRelevanceData.setReviewer(reviewer);
            countryRelevanceData.setSubmissionDate(subDate);
            countryRelevanceData.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode());
            countryRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            countryRelevanceData.setCreateOn(LocalDateTime.now());
            countryRelevanceData.setCreateBy(null);
            countryRelevanceData.setUpdateOn(subDate);
            countryRelevanceData.setUpdateBy(null);
            countryRelevanceData.setLastUpdateTime(subDate);
            countryRelevanceData.setRegionId(regionId);
            countryRelevanceData.setCompanyId(companyId);
            List<Long> auditDataIdList = Lists.newArrayList();

            // 保存本次上报数据信息
            for (ReqBulkCementLogFacStaDataUploadDTO uploadDto : dataList) {
                BulkCementLogisticFacilityStatisticAnnualReport bulkCementLogFacStaAnnualReport =
                        new BulkCementLogisticFacilityStatisticAnnualReport();
                RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                String regionName = regionDto.getRegionName();
                bulkCementLogFacStaAnnualReport.setRegionName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                bulkCementLogFacStaAnnualReport.setFacilityName(uploadDto.getFacilityName());
                bulkCementLogFacStaAnnualReport.setYearBeginNum(uploadDto.getYearBeginNum());
                bulkCementLogFacStaAnnualReport.setYearBeginCapacity(uploadDto.getYearBeginCapacity());
                bulkCementLogFacStaAnnualReport.setThisYearNewAddNum(uploadDto.getThisYearNewAddNum());
                bulkCementLogFacStaAnnualReport.setThisYearNewAddCapacity(uploadDto.getThisYearNewAddCapacity());
                bulkCementLogFacStaAnnualReport.setThisYearScrapNum(uploadDto.getThisYearScrapNum());
                bulkCementLogFacStaAnnualReport.setThisYearScrapCapacity(uploadDto.getThisYearScrapCapacity());
                bulkCementLogFacStaAnnualReport.setYearEndNum(uploadDto.getYearEndNum());
                bulkCementLogFacStaAnnualReport.setYearEndCapacity(uploadDto.getYearEndCapacity());
                bulkCementLogFacStaAnnualReport.setThisYearWorkAmount(uploadDto.getThisYearWorkAmount());
                bulkCementLogFacStaAnnualReport.setReportYear(uploadDto.getReportYear());
                bulkCementLogFacStaAnnualReport.setRemark(uploadDto.getRemark());
                bulkCementLogFacStaAnnualReport.setCompanyId(companyId);
                bulkCementLogFacStaAnnualReport.setUnitResponsiblePerson(uploadDto.getUnitResponsiblePerson());
                bulkCementLogFacStaAnnualReport.setPreparer(uploadDto.getPreparer());
                bulkCementLogFacStaAnnualReport.setReviewer(uploadDto.getReviewer());
                bulkCementLogFacStaAnnualReport.setSubmissionDate(uploadDto.getSubmissionDate());
                bulkCementLogFacStaAnnualReport.setRegionId(regionId);
                bulkCementLogFacStaAnnualReport.setCreateOn(subDate);
                bulkCementLogFacStaAnnualReport.setCreateBy(null);
                bulkCementLogFacStaAnnualReport.setUpdateOn(subDate);
                bulkCementLogFacStaAnnualReport.setUpdateBy(null);
                bulkCementLogFacStaAnnualReport.setAuditInfoId(cityAuditInfo.getId());
                bulkCementLogFacStaAnnualReport.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                bulkCementLogFacStaService.save(bulkCementLogFacStaAnnualReport);
                auditDataIdList.add(bulkCementLogFacStaAnnualReport.getId());
            }
            // 保存关联数据ID集合(一条关联数据对应多条不同设备名称的数据)
            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
            countryRelevanceData.setAuditDataIdList(idListStr);
            dataRelevanceService.saveOrUpdate(countryRelevanceData);

            // 补充数据审核表信息
            BulkCementDirectReportSystemAuditRecord auditRecord = new BulkCementDirectReportSystemAuditRecord();
            auditRecord.setAuditDataId(countryRelevanceData.getId());
            auditRecord.setAuditInfoId(cityAuditInfo.getId());
            auditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            auditRecord.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode());
            auditRecord.setCompanyId(companyId);
            auditRecord.setRegionId(regionId);
            auditRecord.setCreateOn(subDate);
            auditRecord.setCreateBy(null);
            auditRecord.setUpdateOn(subDate);
            auditRecord.setUpdateBy(null);
            auditRecord.setReportYear(2022);
            auditRecord.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
            auditRecordService.save(auditRecord);

            // 杭州市
            //String cityUnitResponsiblePerson = "赵斌";
            //String cityPreparer = "蔡义超";
            //String cityReviewer = "王瑞理";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-15 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            // 宁波市
            //String cityUnitResponsiblePerson = "卢汉";
            //String cityPreparer = "杨浩杰";
            //String cityReviewer = "徐立国";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-09 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            // 温州市
            //String cityUnitResponsiblePerson = null;
            //String cityPreparer = null;
            //String cityReviewer = null;
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-01-01 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            // 嘉兴市
            //String cityUnitResponsiblePerson = "潘卫国";
            //String cityPreparer = "倪竹红";
            //String cityReviewer = "倪竹红";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-15 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            // 湖州市
            //String cityUnitResponsiblePerson = "傅饶";
            //String cityPreparer = "付平安";
            //String cityReviewer = "沈宁儿";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-06 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            // 绍兴市
            //String cityUnitResponsiblePerson = "丁正龙";
            //String cityPreparer = "寿晨杰";
            //String cityReviewer = "寿晨杰";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-13 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 金华市
            //String cityUnitResponsiblePerson = "汪欣";
            //String cityPreparer = "吴昌蒲";
            //String cityReviewer = "杨裕发";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-10 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 衢州市
            //String cityUnitResponsiblePerson = "徐欣";
            //String cityPreparer = "徐欣";
            //String cityReviewer = "徐欣";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-10 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 舟山市
            //String cityUnitResponsiblePerson = "刘海港";
            //String cityPreparer = "吴煜之";
            //String cityReviewer = "檀坤";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-01-10 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 台州市
            //String cityUnitResponsiblePerson = "陈虹";
            //String cityPreparer = "林";
            //String cityReviewer = "林";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-15 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            // 丽水市
            String cityUnitResponsiblePerson = null;
            String cityPreparer = null;
            String cityReviewer = null;
            LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-01-01 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            Long relevanceDataId;
            // 判断上报年份所在市的市级关联数据不存在
            // 区县的区域ID
            // 获取所在市的区域ID
            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
            Long parentId = regionDto.getParentId();
            BulkCementDirectReportSystemDataRelevance cityData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, parentId)
                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.CITY_AUDIT.getCode())
                    .eq(BulkCementDirectReportSystemDataRelevance::getReportYear, 2022)
                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode()));
            // 已经存在，更新上报数据ID列表
            if (Objects.nonNull(cityData)){
                String auditDataIdListStr = cityData.getAuditDataIdList();
                List<Long> auditIdList;
                if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(auditDataIdListStr)){
                    auditIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                    if (!auditIdList.contains(countryRelevanceData.getId())){
                        auditIdList.add(countryRelevanceData.getId());
                        String dataIdListStr = auditIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                        cityData.setAuditDataIdList(dataIdListStr);
                    }
                    // 更新最后一次更新时间
                    cityData.setLastUpdateTime(subDate);
                    cityData.setUpdateOn(subDate);
                    cityData.setUpdateBy(null);
                    // 有新上报的数据
                    cityData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.updateById(cityData);
                }
                relevanceDataId = cityData.getId();
            }else {
                // 补充所在市的关联数据信息
                BulkCementDirectReportSystemDataRelevance cityRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                cityRelevanceData.setReportYear(2022);
                List<Long> auditIdList = Lists.newArrayList();
                if (Objects.nonNull(countryRelevanceData.getId())) {
                    auditIdList.add(countryRelevanceData.getId());
                    String idListString = auditIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    cityRelevanceData.setAuditDataIdList(idListString);
                }
                cityRelevanceData.setUnitResponsiblePerson(cityUnitResponsiblePerson);
                cityRelevanceData.setPreparer(cityPreparer);
                cityRelevanceData.setReviewer(cityReviewer);
                cityRelevanceData.setSubmissionDate(citySubDate);
                cityRelevanceData.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode());
                cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityRelevanceData.setCreateOn(citySubDate);
                cityRelevanceData.setCreateBy(null);
                cityRelevanceData.setUpdateOn(citySubDate);
                cityRelevanceData.setUpdateBy(null);
                cityRelevanceData.setLastUpdateTime(citySubDate);
                cityRelevanceData.setRegionId(parentId);
                // 获取所在市散装中心所属的管理企业ID
                CompanyDTO companyDto = companiesCacheHelper.getByName(regionDto.getRegionName() + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.nonNull(companyDto)) {
                    cityRelevanceData.setCompanyId(companyDto.getId());
                }
                cityRelevanceData.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                cityRelevanceData.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode());
                // 有新上报的数据，就更新关联数据状态为未上报
                cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                dataRelevanceService.saveOrUpdate(cityRelevanceData);
                relevanceDataId = cityRelevanceData.getId();
            }


            // 补充省级审核申请
            BulkCementDirectReportSystemAuditInfo provinceAuditInfo = new BulkCementDirectReportSystemAuditInfo();
            provinceAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            provinceAuditInfo.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode());
            provinceAuditInfo.setCreateOn(citySubDate);
            provinceAuditInfo.setCreateBy(null);
            provinceAuditInfo.setUpdateOn(citySubDate);
            provinceAuditInfo.setUpdateBy(null);
            provinceAuditInfo.setAuditTime(citySubDate);
            provinceAuditInfo.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
            auditInfoService.save(provinceAuditInfo);
            // 更新市级关联数据
            BulkCementDirectReportSystemDataRelevance cityRelevanceData = dataRelevanceService.getById(relevanceDataId);
            VUtils.isTrue(Objects.isNull(cityRelevanceData)).throwMessage("数据不存在!");
            // 关联审核信息ID
            cityRelevanceData.setAuditInfoId(provinceAuditInfo.getId());
            cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            cityRelevanceData.setUpdateOn(citySubDate);
            cityRelevanceData.setUpdateBy(null);
            cityRelevanceData.setUnitResponsiblePerson(null);
            cityRelevanceData.setPreparer(null);
            cityRelevanceData.setReviewer(null);
            cityRelevanceData.setSubmissionDate(citySubDate);
            dataRelevanceService.updateById(cityRelevanceData);

            // 判断上报月份省关联数据是否存在
            BulkCementDirectReportSystemDataRelevance provinceData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, DefValConstants.ZJREGION_ID)
                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode())
                    .eq(BulkCementDirectReportSystemDataRelevance::getReportYear, 2022)
                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode()));
            // 存在，更新市关联数据ID列表
            if (Objects.nonNull(provinceData)){
                String auditDataIdListStr = provinceData.getAuditDataIdList();
                List<Long> auditIdList;
                if (StringUtils.isNotBlank(auditDataIdListStr)){
                    auditIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                    if (!auditIdList.contains(relevanceDataId)){
                        auditIdList.add(relevanceDataId);
                        String idListString = auditIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                        provinceData.setAuditDataIdList(idListString);
                    }
                    // 更新最后一次更新时间
                    provinceData.setLastUpdateTime(citySubDate);
                    provinceData.setUpdateOn(citySubDate);
                    provinceData.setUpdateBy(null);
                    // 有新上报的数据，就更新关联数据状态为审核中
                    provinceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.updateById(provinceData);
                }
            }else {
                // 如果上报月份省级关联数据不存在
                // 补充省散办关联数据信息
                BulkCementDirectReportSystemDataRelevance provinceRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                provinceRelevanceData.setReportYear(2022);
                List<Long> auditIdList = Lists.newArrayList();
                auditIdList.add(relevanceDataId);
                String idListString = auditIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                provinceRelevanceData.setAuditDataIdList(idListString);

                provinceRelevanceData.setUnitResponsiblePerson(null);
                provinceRelevanceData.setPreparer(null);
                provinceRelevanceData.setReviewer(null);
                provinceRelevanceData.setSubmissionDate(null);
                provinceRelevanceData.setCreateOn(citySubDate);
                provinceRelevanceData.setCreateBy(null);
                provinceRelevanceData.setUpdateOn(citySubDate);
                provinceRelevanceData.setUpdateBy(null);
                provinceRelevanceData.setLastUpdateTime(citySubDate);
                provinceRelevanceData.setRegionId(DefValConstants.ZJREGION_ID);
                provinceRelevanceData.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                // 获取省散装中心所属的管理企业ID
                CompanyDTO provinceCompanyDto = companiesCacheHelper.getByName(DefValConstants.PROVINCE + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.nonNull(provinceCompanyDto)) {
                    provinceRelevanceData.setCompanyId(provinceCompanyDto.getId());
                }
                provinceRelevanceData.setUnitResponsiblePerson(null);
                provinceRelevanceData.setPreparer(null);
                provinceRelevanceData.setReviewer(null);
                provinceRelevanceData.setSubmissionDate(null);
                provinceRelevanceData.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode());
                provinceRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                dataRelevanceService.save(provinceRelevanceData);
            }

            // 创建省级审核记录
            BulkCementDirectReportSystemAuditRecord provinceAuditRecord = new BulkCementDirectReportSystemAuditRecord();
            provinceAuditRecord.setAuditDataId(cityRelevanceData.getId());
            provinceAuditRecord.setAuditInfoId(provinceAuditInfo.getId());
            provinceAuditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            provinceAuditRecord.setAuditDataType(UploadDataTypeEnum.BULK_CEMENT_LOGISTIC_FACILITY_STATISTIC_ANNUAL_REPORT.getCode());
            provinceAuditRecord.setCompanyId(cityRelevanceData.getCompanyId());
            provinceAuditRecord.setRegionId(cityRelevanceData.getRegionId());
            provinceAuditRecord.setCreateOn(cityRelevanceData.getSubmissionDate());
            provinceAuditRecord.setCreateBy(null);
            provinceAuditRecord.setUpdateOn(cityRelevanceData.getSubmissionDate());
            provinceAuditRecord.setUpdateBy(null);
            provinceAuditRecord.setReportYear(2022);
            provinceAuditRecord.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
            auditRecordService.save(provinceAuditRecord);
        }
    }

    @Test
    public void materialLogEquipStaTest() throws FileNotFoundException {
        // ------------------------------------------杭州市-------------------------------------
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\杭州市\\萧山.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\杭州市\\余杭.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\杭州市\\富阳.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\杭州市\\桐庐.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\杭州市\\建德.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\杭州市\\临安.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\杭州市\\淳安.xlsx");
        // File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\杭州市\\钱塘.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\杭州市\\临平.xlsx");
        // ------------------------------------------宁波市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\宁波市\\余姚.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\宁波市\\慈溪.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\宁波市\\象山.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\宁波市\\宁海.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\宁波市\\鄞州.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\宁波市\\北仑.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\宁波市\\镇海.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\宁波市\\奉化.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\宁波市\\江北.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\宁波市\\海曙.xlsx");
        // ------------------------------------------温州市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\鹿城.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\瓯海.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\龙湾.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\瑞安.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\乐清.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\永嘉.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\平阳.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\苍南.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\文成.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\洞头.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\泰顺.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\温州市\\龙港.xlsx");
        // ------------------------------------------嘉兴市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\嘉兴市\\南湖.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\嘉兴市\\秀洲.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\嘉兴市\\嘉善.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\嘉兴市\\平湖.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\嘉兴市\\海盐.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\嘉兴市\\海宁.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\嘉兴市\\桐乡.xlsx");
        // ------------------------------------------湖州市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\湖州市\\德清.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\湖州市\\长兴.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\湖州市\\安吉.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\湖州市\\吴兴.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\湖州市\\南浔.xlsx");
        // ------------------------------------------绍兴市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\绍兴市\\越城.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\绍兴市\\柯桥.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\绍兴市\\诸暨.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\绍兴市\\上虞.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\绍兴市\\嵊州.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\绍兴市\\新昌.xlsx");
        // ------------------------------------------金华市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\金华市\\金东.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\金华市\\婺城.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\金华市\\兰溪.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\金华市\\浦江.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\金华市\\东阳.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\金华市\\义乌.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\金华市\\永康.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\金华市\\武义.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\金华市\\磐安.xlsx");
        // ------------------------------------------衢州市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\衢州市\\衢江.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\衢州市\\江山.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\衢州市\\常山.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\衢州市\\开化.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\衢州市\\龙游.xlsx");
        // ------------------------------------------舟山市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\舟山市\\定海.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\舟山市\\普陀.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\舟山市\\岱山.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\舟山市\\嵊泗.xlsx");
        // ------------------------------------------台州市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\台州市\\椒江.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\台州市\\路桥.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\台州市\\黄岩.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\台州市\\临海.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\台州市\\温岭.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\台州市\\仙居.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\台州市\\天台.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\台州市\\三门.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\台州市\\玉环.xlsx");
        // ------------------------------------------丽水市-------------------------------------
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\丽水市\\莲都.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\丽水市\\青田.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\丽水市\\缙云.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\丽水市\\松阳.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\丽水市\\遂昌.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\丽水市\\龙泉.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\丽水市\\云和.xlsx");
        //File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\丽水市\\景宁畲族自治县.xlsx");
        File f = new File("D:\\work\\水泥车直报系统\\data\\物流装备统计年报\\丽水市\\丽水经济技术开发区.xlsx");

        Workbook wb = readExcel(new FileInputStream(f),f.getName());
        Row row = null;
        List<Long> userList = Lists.newArrayList();
        if(wb != null) {
            //获取第一个sheet
            Sheet sheet = wb.getSheetAt(0);
            //获取最大行数
            int rownum = sheet.getPhysicalNumberOfRows();
            //获取第一行
            row = sheet.getRow(0);

            // 根据区县名称获取区域ID
            HashSet<String> countySet = new HashSet<>();
            Map<String, Region> regionMap = regionService.list().stream()
                    .filter(v -> !StrPool.EMPTY.equals(v.getName()) &&
                            !"市本级".equals(v.getName()) &&
                            countySet.add(v.getName()))
                    .collect(Collectors.toMap(Region::getName, v -> v));

            List<ReqMaterialLogEquipStaDataUploadDTO> dataList = Lists.newArrayList();

            Long regionId = null;
            Long cityRegionId = null;
            String cityRegionName = null;

            Long companyId = null;
            Long cityCompanyId = null;

            String unitResponsiblePerson = null;
            String preparer = null;
            String reviewer = null;
            LocalDateTime subDate = null;

            for (int i = 1; i < rownum; i++) {
                row = sheet.getRow(i);
                // 地区
                String regionName = Objects.nonNull(row.getCell(0)) ? row.getCell(0).toString() : StringUtils.EMPTY;
                // 上报年份
                String reportYear = Objects.nonNull(row.getCell(1)) ? row.getCell(1).toString() : null;
                Double parseDouble = Double.parseDouble(reportYear);
                int year = parseDouble.intValue();
                // 装备名称
                String equipmentName = Objects.nonNull(row.getCell(2)) ? row.getCell(2).toString() : StringUtils.EMPTY;
                // 年初数量
                String yearBeginNum = Objects.nonNull(row.getCell(3)) ? row.getCell(3).toString() : StringUtils.EMPTY;
                // 年初额定量
                String yearBeginNominalRate = Objects.nonNull(row.getCell(4)) ? row.getCell(4).toString() : StringUtils.EMPTY;
                // 本年新增数量
                String thisYearNewAddNum = Objects.nonNull(row.getCell(5)) ? row.getCell(5).toString() : StringUtils.EMPTY;
                // 本年新增额定量
                String thisYearNewAddNominalRate = Objects.nonNull(row.getCell(6)) ? row.getCell(6).toString() : StringUtils.EMPTY;
                // 本年减少数量
                String thisYearDecreaseNum = Objects.nonNull(row.getCell(7)) ? row.getCell(7).toString() : StringUtils.EMPTY;
                // 本年减少额定量
                String thisYearDecreaseNominalRate = Objects.nonNull(row.getCell(8)) ? row.getCell(8).toString() : StringUtils.EMPTY;
                // 年末数量
                String yearEndNum = Objects.nonNull(row.getCell(9)) ? row.getCell(9).toString() : StringUtils.EMPTY;
                // 年末额定量
                String yearEndNominal = Objects.nonNull(row.getCell(10)) ? row.getCell(10).toString() : StringUtils.EMPTY;
                // 单位负责人
                unitResponsiblePerson = Objects.nonNull(row.getCell(11)) ? row.getCell(11).toString() : StringUtils.EMPTY;
                // 填表人
                preparer = Objects.nonNull(row.getCell(12)) ? row.getCell(12).toString() : StringUtils.EMPTY;
                // 复核人
                reviewer = Objects.nonNull(row.getCell(13)) ? row.getCell(13).toString() : StringUtils.EMPTY;
                // 报出日期
                Date submissionDate = Objects.nonNull(row.getCell(14)) ? row.getCell(14).getDateCellValue() : null;
                if (Objects.nonNull(submissionDate)) {
                    subDate = submissionDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
                }else {
                    subDate = LocalDateTime.now().minusMonths(9).minusDays(15L);
                }

                // 区县名称 获取区域ID、上级区域ID
                for (Map.Entry<String, Region> regionEntry : regionMap.entrySet()) {
                    String regionNameStr = regionEntry.getKey();
                    if (regionNameStr.contains(regionName) && regionNameStr.length() < 4){
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    } else if ((regionNameStr.contains(regionName) && regionNameStr.equals("丽水经济技术开发区")) ||
                            (regionNameStr.contains(regionName) && regionNameStr.equals("景宁畲族自治县"))) {
                        regionName = regionNameStr;
                        Region region = regionMap.get(regionNameStr);
                        if (Objects.nonNull(region)) {
                            regionId = region.getId();
                            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                            cityRegionId = regionDto.getParentId();
                            cityRegionName = regionDto.getRegionName();
                        }
                    }
                }
                if (Objects.isNull(regionId)){
                    throw new BizException("区域不存在!");
                }

                // 根据地区名称获取对应散装中心的企业信息
                CompanyDTO companyDto = companiesCacheHelper.getByName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                CompanyDTO cityCompanyDto = companiesCacheHelper.getByName(cityRegionName + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.isNull(companyDto) || Objects.isNull(cityCompanyDto)){
                    throw new BizException("管理企业不存在!");
                }else {
                    companyId = companyDto.getId();
                    cityCompanyId = cityCompanyDto.getId();
                }

                ReqMaterialLogEquipStaDataUploadDTO uploadDto = new ReqMaterialLogEquipStaDataUploadDTO();
                uploadDto.setRegionName(regionName);
                uploadDto.setCompanyId(companyId);
                uploadDto.setRegionId(regionId);
                uploadDto.setEquipmentName(equipmentName);
                Double d = Double.parseDouble(yearBeginNum);
                int beginNum = d.intValue();
                uploadDto.setYearBeginNum(beginNum);
                uploadDto.setYearBeginNominalRate(BigDecimal.valueOf(Double.parseDouble(yearBeginNominalRate)));
                Double d2 = Double.parseDouble(thisYearNewAddNum);
                int newAddNum = d2.intValue();
                uploadDto.setThisYearNewAddNum(newAddNum);
                uploadDto.setThisYearNewAddNominalRate(BigDecimal.valueOf(Double.parseDouble(thisYearNewAddNominalRate)));
                Double d3 = Double.parseDouble(thisYearDecreaseNum);
                int decreaseNum = d3.intValue();
                uploadDto.setThisYearDecreaseNum(decreaseNum);
                uploadDto.setThisYearDecreaseNominalRate(BigDecimal.valueOf(Double.parseDouble(thisYearDecreaseNominalRate)));
                Double d4 = Double.parseDouble(yearEndNum);
                int endNum = d4.intValue();
                uploadDto.setYearEndNum(endNum);
                uploadDto.setYearEndNominal(BigDecimal.valueOf(Double.parseDouble(yearEndNominal)));

                uploadDto.setReportYear(year);
                uploadDto.setUnitResponsiblePerson(unitResponsiblePerson);
                uploadDto.setPreparer(preparer);
                uploadDto.setReviewer(reviewer);
                uploadDto.setSubmissionDate(subDate);
                dataList.add(uploadDto);
            }

            // 先提交市级审核申请
            BulkCementDirectReportSystemAuditInfo cityAuditInfo = new BulkCementDirectReportSystemAuditInfo();
            cityAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            cityAuditInfo.setAuditDataType(UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode());
            cityAuditInfo.setCreateOn(subDate);
            cityAuditInfo.setCreateBy(null);
            cityAuditInfo.setUpdateOn(subDate);
            cityAuditInfo.setUpdateBy(null);
            cityAuditInfo.setAuditTime(subDate);
            cityAuditInfo.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
            auditInfoService.save(cityAuditInfo);

            // 创建区县关联数据信息(对应每个设备名称的数据关系为一对多)
            BulkCementDirectReportSystemDataRelevance countryData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, regionId)
                    .eq(BulkCementDirectReportSystemDataRelevance::getReportYear, 2022)
                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode()));
            BulkCementDirectReportSystemDataRelevance countryRelevanceData = new BulkCementDirectReportSystemDataRelevance();
            // 说明为重新提交
            if (Objects.nonNull(countryData)){
                // 先删除关联的已经保存的各设备名称的数据
                String auditDataIdList = countryData.getAuditDataIdList();
                if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(auditDataIdList)){
                    List<Long> idList = Arrays.stream(auditDataIdList.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                    if (CollUtil.isNotEmpty(idList)){
                        bulkCementLogFacStaService.remove(Wrappers.lambdaQuery(BulkCementLogisticFacilityStatisticAnnualReport.class)
                                .in(BulkCementLogisticFacilityStatisticAnnualReport::getId,idList));
                    }
                }
                countryRelevanceData.setId(countryData.getId());
            }
            countryRelevanceData.setReportYear(2022);
            countryRelevanceData.setUnitResponsiblePerson(unitResponsiblePerson);
            countryRelevanceData.setPreparer(preparer);
            countryRelevanceData.setReviewer(reviewer);
            countryRelevanceData.setSubmissionDate(subDate);
            countryRelevanceData.setAuditDataType(UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode());
            countryRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            countryRelevanceData.setCreateOn(LocalDateTime.now());
            countryRelevanceData.setCreateBy(null);
            countryRelevanceData.setUpdateOn(subDate);
            countryRelevanceData.setUpdateBy(null);
            countryRelevanceData.setLastUpdateTime(subDate);
            countryRelevanceData.setRegionId(regionId);
            countryRelevanceData.setCompanyId(companyId);
            List<Long> auditDataIdList = Lists.newArrayList();

            // 保存本次上报数据信息
            for (ReqMaterialLogEquipStaDataUploadDTO uploadDto : dataList) {
                MaterialLogisticEquipmentStatisticAnnualReport materialLogEquipStaAnnualReport =
                        new MaterialLogisticEquipmentStatisticAnnualReport();
                RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
                String regionName = regionDto.getRegionName();
                materialLogEquipStaAnnualReport.setRegionName(regionName + VehicleContant.ADMIN_COMPANY_NAME);
                materialLogEquipStaAnnualReport.setEquipmentName(uploadDto.getEquipmentName());
                materialLogEquipStaAnnualReport.setYearBeginNum(uploadDto.getYearBeginNum());
                materialLogEquipStaAnnualReport.setYearBeginNominalRate(uploadDto.getYearBeginNominalRate());
                materialLogEquipStaAnnualReport.setThisYearNewAddNum(uploadDto.getThisYearNewAddNum());
                materialLogEquipStaAnnualReport.setThisYearNewAddNominalRate(uploadDto.getThisYearNewAddNominalRate());
                materialLogEquipStaAnnualReport.setThisYearDecreaseNum(uploadDto.getThisYearDecreaseNum());
                materialLogEquipStaAnnualReport.setThisYearDecreaseNominalRate(uploadDto.getThisYearDecreaseNominalRate());
                materialLogEquipStaAnnualReport.setYearEndNum(uploadDto.getYearEndNum());
                materialLogEquipStaAnnualReport.setYearEndNominal(uploadDto.getYearEndNominal());
                materialLogEquipStaAnnualReport.setReportYear(uploadDto.getReportYear());
                materialLogEquipStaAnnualReport.setRemark(uploadDto.getRemark());
                materialLogEquipStaAnnualReport.setCompanyId(companyId);
                materialLogEquipStaAnnualReport.setUnitResponsiblePerson(uploadDto.getUnitResponsiblePerson());
                materialLogEquipStaAnnualReport.setPreparer(uploadDto.getPreparer());
                materialLogEquipStaAnnualReport.setReviewer(uploadDto.getReviewer());
                materialLogEquipStaAnnualReport.setSubmissionDate(uploadDto.getSubmissionDate());
                materialLogEquipStaAnnualReport.setRegionId(regionId);
                materialLogEquipStaAnnualReport.setCreateOn(subDate);
                materialLogEquipStaAnnualReport.setCreateBy(null);
                materialLogEquipStaAnnualReport.setUpdateOn(subDate);
                materialLogEquipStaAnnualReport.setUpdateBy(null);
                materialLogEquipStaAnnualReport.setAuditInfoId(cityAuditInfo.getId());
                materialLogEquipStaAnnualReport.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                materialLogEquipStaAnnualReportService.save(materialLogEquipStaAnnualReport);
                auditDataIdList.add(materialLogEquipStaAnnualReport.getId());
            }
            // 保存关联数据ID集合(一条关联数据对应多条不同设备名称的数据)
            String idListStr = auditDataIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
            countryRelevanceData.setAuditDataIdList(idListStr);
            dataRelevanceService.saveOrUpdate(countryRelevanceData);

            // 补充数据审核表信息
            BulkCementDirectReportSystemAuditRecord auditRecord = new BulkCementDirectReportSystemAuditRecord();
            auditRecord.setAuditDataId(countryRelevanceData.getId());
            auditRecord.setAuditInfoId(cityAuditInfo.getId());
            auditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            auditRecord.setAuditDataType(UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode());
            auditRecord.setCompanyId(companyId);
            auditRecord.setRegionId(regionId);
            auditRecord.setCreateOn(subDate);
            auditRecord.setCreateBy(null);
            auditRecord.setUpdateOn(subDate);
            auditRecord.setUpdateBy(null);
            auditRecord.setReportYear(2022);
            auditRecord.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
            auditRecordService.save(auditRecord);

            //// 杭州市
            //String cityUnitResponsiblePerson = "赵斌";
            //String cityPreparer = "蔡义超";
            //String cityReviewer = "王瑞理";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-16 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 宁波市
            //String cityUnitResponsiblePerson = "卢汉";
            //String cityPreparer = "杨浩杰";
            //String cityReviewer = "徐立国";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-09 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 温州市
            //String cityUnitResponsiblePerson = null;
            //String cityPreparer = null;
            //String cityReviewer = null;
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-01-01 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 嘉兴市
            //String cityUnitResponsiblePerson = "潘卫国";
            //String cityPreparer = "倪竹红";
            //String cityReviewer = "倪竹红";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-15 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 湖州市
            //String cityUnitResponsiblePerson = "傅饶";
            //String cityPreparer = "付平安";
            //String cityReviewer = "沈宁儿";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-06 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 绍兴市
            //String cityUnitResponsiblePerson = "丁正龙";
            //String cityPreparer = "寿晨杰";
            //String cityReviewer = "寿晨杰";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-13 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 金华市
            //String cityUnitResponsiblePerson = "汪欣";
            //String cityPreparer = "吴昌蒲";
            //String cityReviewer = "杨裕发";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-10 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 衢州市
            //String cityUnitResponsiblePerson = "徐欣";
            //String cityPreparer = "徐欣";
            //String cityReviewer = "徐欣";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-10 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 舟山市
            //String cityUnitResponsiblePerson = "刘海港";
            //String cityPreparer = "吴煜之";
            //String cityReviewer = "檀坤";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-01-10 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            //// 台州市
            //String cityUnitResponsiblePerson = "陈虹";
            //String cityPreparer = "林";
            //String cityReviewer = "林";
            //LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-02-16 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            // 丽水市
            String cityUnitResponsiblePerson = null;
            String cityPreparer = null;
            String cityReviewer = null;
            LocalDateTime citySubDate  = LocalDateTimeUtil.parse("2023-01-01 00:00:00", NdDateUtils.DEFAULT_DATE_TIME_FORMAT);
            Long relevanceDataId;
            // 判断上报年份所在市的市级关联数据不存在
            // 区县的区域ID
            // 获取所在市的区域ID
            RegionDTO regionDto = regionsCacheHelper.getByRegionId(regionId);
            Long parentId = regionDto.getParentId();
            BulkCementDirectReportSystemDataRelevance cityData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, parentId)
                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.CITY_AUDIT.getCode())
                    .eq(BulkCementDirectReportSystemDataRelevance::getReportYear, 2022)
                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode()));
            // 已经存在，更新上报数据ID列表
            if (Objects.nonNull(cityData)){
                String auditDataIdListStr = cityData.getAuditDataIdList();
                List<Long> auditIdList;
                if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(auditDataIdListStr)){
                    auditIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                    if (!auditIdList.contains(countryRelevanceData.getId())){
                        auditIdList.add(countryRelevanceData.getId());
                        String dataIdListStr = auditIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                        cityData.setAuditDataIdList(dataIdListStr);
                    }
                    // 更新最后一次更新时间
                    cityData.setLastUpdateTime(subDate);
                    cityData.setUpdateOn(subDate);
                    cityData.setUpdateBy(null);
                    // 有新上报的数据
                    cityData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.updateById(cityData);
                }
                relevanceDataId = cityData.getId();
            }else {
                // 补充所在市的关联数据信息
                BulkCementDirectReportSystemDataRelevance cityRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                cityRelevanceData.setReportYear(2022);
                List<Long> auditIdList = Lists.newArrayList();
                if (Objects.nonNull(countryRelevanceData.getId())) {
                    auditIdList.add(countryRelevanceData.getId());
                    String idListString = auditIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                    cityRelevanceData.setAuditDataIdList(idListString);
                }
                cityRelevanceData.setUnitResponsiblePerson(cityUnitResponsiblePerson);
                cityRelevanceData.setPreparer(cityPreparer);
                cityRelevanceData.setReviewer(cityReviewer);
                cityRelevanceData.setSubmissionDate(citySubDate);
                cityRelevanceData.setAuditDataType(UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode());
                cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                cityRelevanceData.setCreateOn(citySubDate);
                cityRelevanceData.setCreateBy(null);
                cityRelevanceData.setUpdateOn(citySubDate);
                cityRelevanceData.setUpdateBy(null);
                cityRelevanceData.setLastUpdateTime(citySubDate);
                cityRelevanceData.setRegionId(parentId);
                // 获取所在市散装中心所属的管理企业ID
                CompanyDTO companyDto = companiesCacheHelper.getByName(regionDto.getRegionName() + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.nonNull(companyDto)) {
                    cityRelevanceData.setCompanyId(companyDto.getId());
                }
                cityRelevanceData.setAuditType(DataUploadAuditTypeEnum.CITY_AUDIT.getCode());
                cityRelevanceData.setAuditDataType(UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode());
                // 有新上报的数据，就更新关联数据状态为未上报
                cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                dataRelevanceService.saveOrUpdate(cityRelevanceData);
                relevanceDataId = cityRelevanceData.getId();
            }


            // 补充省级审核申请
            BulkCementDirectReportSystemAuditInfo provinceAuditInfo = new BulkCementDirectReportSystemAuditInfo();
            provinceAuditInfo.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            provinceAuditInfo.setAuditDataType(UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode());
            provinceAuditInfo.setCreateOn(citySubDate);
            provinceAuditInfo.setCreateBy(null);
            provinceAuditInfo.setUpdateOn(citySubDate);
            provinceAuditInfo.setUpdateBy(null);
            provinceAuditInfo.setAuditTime(citySubDate);
            provinceAuditInfo.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
            auditInfoService.save(provinceAuditInfo);
            // 更新市级关联数据
            BulkCementDirectReportSystemDataRelevance cityRelevanceData = dataRelevanceService.getById(relevanceDataId);
            VUtils.isTrue(Objects.isNull(cityRelevanceData)).throwMessage("数据不存在!");
            // 关联审核信息ID
            cityRelevanceData.setAuditInfoId(provinceAuditInfo.getId());
            cityRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            cityRelevanceData.setUpdateOn(citySubDate);
            cityRelevanceData.setUpdateBy(null);
            cityRelevanceData.setUnitResponsiblePerson(null);
            cityRelevanceData.setPreparer(null);
            cityRelevanceData.setReviewer(null);
            cityRelevanceData.setSubmissionDate(citySubDate);
            dataRelevanceService.updateById(cityRelevanceData);

            // 判断上报月份省关联数据是否存在
            BulkCementDirectReportSystemDataRelevance provinceData = dataRelevanceService.getOne(Wrappers.lambdaQuery(BulkCementDirectReportSystemDataRelevance.class)
                    .eq(BulkCementDirectReportSystemDataRelevance::getRegionId, DefValConstants.ZJREGION_ID)
                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditType,DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode())
                    .eq(BulkCementDirectReportSystemDataRelevance::getReportYear, 2022)
                    .eq(BulkCementDirectReportSystemDataRelevance::getAuditDataType, UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode()));
            // 存在，更新市关联数据ID列表
            if (Objects.nonNull(provinceData)){
                String auditDataIdListStr = provinceData.getAuditDataIdList();
                List<Long> auditIdList;
                if (StringUtils.isNotBlank(auditDataIdListStr)){
                    auditIdList = Arrays.stream(auditDataIdListStr.split(StrPool.COMMA)).map(Long::valueOf).collect(Collectors.toList());
                    if (!auditIdList.contains(relevanceDataId)){
                        auditIdList.add(relevanceDataId);
                        String idListString = auditIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                        provinceData.setAuditDataIdList(idListString);
                    }
                    // 更新最后一次更新时间
                    provinceData.setLastUpdateTime(citySubDate);
                    provinceData.setUpdateOn(citySubDate);
                    provinceData.setUpdateBy(null);
                    // 有新上报的数据，就更新关联数据状态为审核中
                    provinceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                    dataRelevanceService.updateById(provinceData);
                }
            }else {
                // 如果上报月份省级关联数据不存在
                // 补充省散办关联数据信息
                BulkCementDirectReportSystemDataRelevance provinceRelevanceData = new BulkCementDirectReportSystemDataRelevance();
                provinceRelevanceData.setReportYear(2022);
                List<Long> auditIdList = Lists.newArrayList();
                auditIdList.add(relevanceDataId);
                String idListString = auditIdList.stream().map(String::valueOf).collect(Collectors.joining(StrPool.COMMA));
                provinceRelevanceData.setAuditDataIdList(idListString);

                provinceRelevanceData.setUnitResponsiblePerson(null);
                provinceRelevanceData.setPreparer(null);
                provinceRelevanceData.setReviewer(null);
                provinceRelevanceData.setSubmissionDate(null);
                provinceRelevanceData.setCreateOn(citySubDate);
                provinceRelevanceData.setCreateBy(null);
                provinceRelevanceData.setUpdateOn(citySubDate);
                provinceRelevanceData.setUpdateBy(null);
                provinceRelevanceData.setLastUpdateTime(citySubDate);
                provinceRelevanceData.setRegionId(DefValConstants.ZJREGION_ID);
                provinceRelevanceData.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
                // 获取省散装中心所属的管理企业ID
                CompanyDTO provinceCompanyDto = companiesCacheHelper.getByName(DefValConstants.PROVINCE + VehicleContant.ADMIN_COMPANY_NAME);
                if (Objects.nonNull(provinceCompanyDto)) {
                    provinceRelevanceData.setCompanyId(provinceCompanyDto.getId());
                }
                provinceRelevanceData.setUnitResponsiblePerson(null);
                provinceRelevanceData.setPreparer(null);
                provinceRelevanceData.setReviewer(null);
                provinceRelevanceData.setSubmissionDate(null);
                provinceRelevanceData.setAuditDataType(UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode());
                provinceRelevanceData.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
                dataRelevanceService.save(provinceRelevanceData);
            }

            // 创建省级审核记录
            BulkCementDirectReportSystemAuditRecord provinceAuditRecord = new BulkCementDirectReportSystemAuditRecord();
            provinceAuditRecord.setAuditDataId(cityRelevanceData.getId());
            provinceAuditRecord.setAuditInfoId(provinceAuditInfo.getId());
            provinceAuditRecord.setAuditStatus(DataUploadAuditStatusEnum.AUDIT_PASS.getCode());
            provinceAuditRecord.setAuditDataType(UploadDataTypeEnum.MATERIAL_LOGISTIC_EQUIPMENT_STATISTIC_ANNUAL_REPORT.getCode());
            provinceAuditRecord.setCompanyId(cityRelevanceData.getCompanyId());
            provinceAuditRecord.setRegionId(cityRelevanceData.getRegionId());
            provinceAuditRecord.setCreateOn(cityRelevanceData.getSubmissionDate());
            provinceAuditRecord.setCreateBy(null);
            provinceAuditRecord.setUpdateOn(cityRelevanceData.getSubmissionDate());
            provinceAuditRecord.setUpdateBy(null);
            provinceAuditRecord.setReportYear(2022);
            provinceAuditRecord.setAuditType(DataUploadAuditTypeEnum.PROVINCE_AUDIT.getCode());
            auditRecordService.save(provinceAuditRecord);
        }
    }

    @Test
    public void updateTest()  {
        // 散装水泥供应量数据
        List<BulkCementSupplyBulletin> bulkCementSupplyBulletinList = bulkCementSupplyBulletinService.list();
        for (BulkCementSupplyBulletin bulkCementSupplyBulletin : bulkCementSupplyBulletinList) {
            Long regionId = bulkCementSupplyBulletin.getRegionId();
            RegionDTO regionDTO = regionsCacheHelper.getByRegionId(regionId);
            bulkCementSupplyBulletin.setUnitName(regionDTO.getRegionName());
            bulkCementSupplyBulletinService.updateById(bulkCementSupplyBulletin);
        }

        // 中转库进出量数据
        List<BulkCementTransferBulletin> bulkCementTransferBulletins = bulkCementTransferBulletinService.list();
        for (BulkCementTransferBulletin bulkCementTransferBulletin : bulkCementTransferBulletins) {
            Long regionId = bulkCementTransferBulletin.getRegionId();
            RegionDTO regionDTO = regionsCacheHelper.getByRegionId(regionId);
            bulkCementTransferBulletin.setUnitName(regionDTO.getRegionName());
            bulkCementTransferBulletinService.updateById(bulkCementTransferBulletin);
        }


        // 温台州使用量数据
        List<BulkCementThreeCityUsageBulletin> bulkCementThreeCityUsageBulletins = bulkCementThreeCityUsageBulletinService.list();
        for (BulkCementThreeCityUsageBulletin bulkCementThreeCityUsageBulletin : bulkCementThreeCityUsageBulletins) {
            Long regionId = bulkCementThreeCityUsageBulletin.getRegionId();
            RegionDTO regionDTO = regionsCacheHelper.getByRegionId(regionId);
            bulkCementThreeCityUsageBulletin.setUnitName(regionDTO.getRegionName());
            bulkCementThreeCityUsageBulletinService.updateById(bulkCementThreeCityUsageBulletin);
        }

        // 混凝土供应量数据
        List<ConcreteSupplyBulletin> concreteSupplyBulletins = concreteSupplyBulletinService.list();
        for (ConcreteSupplyBulletin concreteSupplyBulletin : concreteSupplyBulletins) {
            Long regionId = concreteSupplyBulletin.getRegionId();
            RegionDTO regionDTO = regionsCacheHelper.getByRegionId(regionId);
            concreteSupplyBulletin.setUnitName(regionDTO.getRegionName());
            concreteSupplyBulletinService.updateById(concreteSupplyBulletin);
        }

        // 砂浆供应量数据
        List<MortarSupplyBulletin> mortarSupplyBulletins = mortarSupplyBulletinService.list();
        for (MortarSupplyBulletin mortarSupplyBulletin : mortarSupplyBulletins) {
            Long regionId = mortarSupplyBulletin.getRegionId();
            RegionDTO regionDTO = regionsCacheHelper.getByRegionId(regionId);
            mortarSupplyBulletin.setRegionName(regionDTO.getRegionName());
            mortarSupplyBulletinService.updateById(mortarSupplyBulletin);
        }

        // 非禁现区数据
        List<NonProhibitedAreasBulkCementSalesUse> nonProhibitedAreasBulkCementSalesUses = nonProhibitedAreasBulkCementSalesUseService.list();
        for (NonProhibitedAreasBulkCementSalesUse nonProhibitedAreasBulkCementSalesUse : nonProhibitedAreasBulkCementSalesUses) {
            Long regionId = nonProhibitedAreasBulkCementSalesUse.getRegionId();
            RegionDTO regionDTO = regionsCacheHelper.getByRegionId(regionId);
            nonProhibitedAreasBulkCementSalesUse.setRegionName(regionDTO.getRegionName());
            nonProhibitedAreasBulkCementSalesUseService.updateById(nonProhibitedAreasBulkCementSalesUse);
        }

        // 物流设施数据
        List<BulkCementLogisticFacilityStatisticAnnualReport> bulkCementLogisticFacilityStatisticAnnualReports = bulkCementLogFacStaService.list();
        for (BulkCementLogisticFacilityStatisticAnnualReport bulkCementLogisticFacilityStatisticAnnualReport : bulkCementLogisticFacilityStatisticAnnualReports) {
            Long regionId = bulkCementLogisticFacilityStatisticAnnualReport.getRegionId();
            RegionDTO regionDTO = regionsCacheHelper.getByRegionId(regionId);
            bulkCementLogisticFacilityStatisticAnnualReport.setRegionName(regionDTO.getRegionName());
            bulkCementLogFacStaService.updateById(bulkCementLogisticFacilityStatisticAnnualReport);
        }

        // 物流装备数据
        List<MaterialLogisticEquipmentStatisticAnnualReport> materialLogisticEquipmentStatisticAnnualReports = materialLogEquipStaAnnualReportService.list();
        for (MaterialLogisticEquipmentStatisticAnnualReport materialLogisticEquipmentStatisticAnnualReport : materialLogisticEquipmentStatisticAnnualReports) {
            Long regionId = materialLogisticEquipmentStatisticAnnualReport.getRegionId();
            RegionDTO regionDTO = regionsCacheHelper.getByRegionId(regionId);
            materialLogisticEquipmentStatisticAnnualReport.setRegionName(regionDTO.getRegionName());
            materialLogEquipStaAnnualReportService.updateById(materialLogisticEquipmentStatisticAnnualReport);
        }
    }



    //这个下面是单独函数
    public static org.apache.poi.ss.usermodel.Workbook readExcel(InputStream is, String extString){
        Workbook wb = null;
        extString = extString.substring(extString.lastIndexOf("."));
        try {
            if(".xls".equals(extString)){
                return wb = new HSSFWorkbook(is);
            }else if(".xlsx".equals(extString)){
                return wb = new XSSFWorkbook(is);
            }else {
                return wb = null;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return wb;
    }
}

