package com.usky.fire.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.fire.domain.*;
import com.usky.fire.mapper.ReportIndexResultMapper;
import com.usky.fire.service.*;
import com.usky.common.mybatis.core.AbstractCrudService;
import com.usky.fire.service.config.pdf.MyHeaderFooter;
import com.usky.fire.service.util.OnlineMethod;
import com.usky.fire.service.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.List;

/**
 * <p>
 * 指数结果表 服务实现类
 * </p>
 *
 * @author han
 * @since 2023-06-27
 */
@Service
public class ReportIndexResultServiceImpl extends AbstractCrudService<ReportIndexResultMapper, ReportIndexResult> implements ReportIndexResultService {
    @Autowired
    private BaseCompanyService baseCompanyService;
    @Autowired
    private BaseBuildService baseBuildService;
    @Autowired
    private ReportIndexConfigService reportIndexConfigService;
    @Autowired
    private BaseDeviceService baseDeviceService;
    @Autowired
    private BaseDeviceStatusService baseDeviceStatusService;
    @Autowired
    private AlarmFireService alarmFireService;
    @Autowired
    private AlarmSmokeControlService alarmSmokeControlService;
    @Autowired
    private AlarmHydrantWaterService alarmHydrantWaterService;
    @Autowired
    private AlarmSprayWaterService alarmSprayWaterService;
    @Autowired
    private BaseCompanyPersonService baseCompanyPersonService;
    @Autowired
    private DemEnforceInspectRecordService demEnforceInspectRecordService;
    @Autowired
    private DemLawSituationService demLawSituationService;
    @Autowired
    private DemEnforceReportComplaintService demEnforceReportComplaintService;
    @Autowired
    private DemFireStatisticsService demFireStatisticsService;
    @Autowired
    private ReportResultService reportResultService;
    @Autowired
    private BaseCompanyAttach1Service baseCompanyAttach1Service;

    @Override
    public void reportIndexResult() {
        try {
            List<BaseCompany> baseCompanies = baseCompanyService.companyIdByTypeList("1");
            if (CollectionUtils.isNotEmpty(baseCompanies)) {
                Calendar now = Calendar.getInstance();
                LocalDate date=LocalDate.now();
                LocalDateTime dateTime=LocalDateTime.now();
                for (int i = 0; i < baseCompanies.size(); i++) {
                     //1.新建document对象
                    Document document = new Document(PageSize.A4);// 建立一个Document对象

// 2.建立一个书写器(Writer)与document对象关联
                    File file =
                            new File("/var/www/usky-file/"+now.get(Calendar.YEAR)+"0"+now.get(Calendar.MONTH+1)+"/"+now.get(Calendar.YEAR)+now.get(Calendar.MONTH)+baseCompanies.get(i).getCompanyId()+".pdf");
//                    File file = new File("D:\\"+now.get(Calendar.YEAR)+now.get(Calendar.MONTH)+baseCompanies.get(i).getCompanyId()+".pdf");
                    file.createNewFile();
                    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
//                    writer.setPageEvent(new Watermark("hello word"));// 水印
                    writer.setPageEvent(new MyHeaderFooter());// 页眉/页脚
                    // 3.打开文档
                    document.open();
                    document.addTitle("fire report");// 标题
                    document.addAuthor("mhzd");// 作者
                    DemReportDataVo demReportDataVo = new DemReportDataVo();
                    demReportDataVo.setCompanyName(baseCompanies.get(i).getCompanyName());
                    demReportDataVo.setLastMonthEndTime(date.toString());
                    ReportResult reportResult = new ReportResult();
                    reportResult.setObjectId(baseCompanies.get(i).getId());
                    reportResult.setReportObject(baseCompanies.get(i).getCompanyName());
                    reportResult.setObjectType(1);
                    reportResult.setCreateDate(date);
                    reportResult.setConfigId(1);
                    reportResult.setCreateTime(dateTime);
                    reportResult.setCreateBy(SecurityUtils.getUsername());
                    List<BaseBuildAddVO> baseBuilds =
                            baseBuildService.baseBuildByIdList(baseCompanies.get(i).getCompanyId(), "");
                    List<ReportIndexConfig> indexConfig3 = reportIndexConfigService.indexConfigList(1, 3);
                    List<ReportIndexConfig> indexConfig2 = reportIndexConfigService.indexConfigList(1, 2);
                    List<ReportIndexConfig> indexConfig1 = reportIndexConfigService.indexConfigList(1, 1);
                    int fireDeviceNum = baseDeviceService.deviceCount(baseCompanies.get(i).getCompanyId(), 1);
                    int smokeDeviceNum = baseDeviceService.deviceCount(baseCompanies.get(i).getCompanyId(), 3);
                    int fireDeviceOfflineNum =
                            baseDeviceStatusService.deviceStatusByTypeCount(baseCompanies.get(i).getCompanyId(), 0, 1);
                    int smokeDeviceOfflineNum =
                            baseDeviceStatusService.deviceStatusByTypeCount(baseCompanies.get(i).getCompanyId(), 0, 3);
                    int fireDeviceHitchNum =
                            baseDeviceStatusService.deviceStatusByTypeCount(baseCompanies.get(i).getCompanyId(), 2, 1);
                    int smokeDeviceHitchNum =
                            baseDeviceStatusService.deviceStatusByTypeCount(baseCompanies.get(i).getCompanyId(), 2, 3);
                    int fireAlarmOfflineNum = fireDeviceOfflineNum + smokeDeviceOfflineNum;
                    int fireAlarmHitchNum = fireDeviceHitchNum + smokeDeviceHitchNum;
                    int fireAlarmNum = fireDeviceNum + smokeDeviceNum;
                    demReportDataVo.setFireDeviceNum(fireAlarmNum);
                    double fireOnlineRate = 0;
                    double fireFaultRate = 0;
                    if (fireAlarmNum > 0) {
                        fireOnlineRate = 1 - Math.round(fireAlarmOfflineNum / fireAlarmNum * 100) * 0.01;
                        fireFaultRate = Math.round(fireAlarmHitchNum / fireAlarmNum * 100) * 0.01;
                    }
                    demReportDataVo.setFireOnlineRate(fireOnlineRate);
                    demReportDataVo.setFireFaultRate(fireFaultRate);
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    Calendar lastMonthFirstDateCal = Calendar.getInstance();
                    lastMonthFirstDateCal.add(Calendar.MONTH, -1);
                    String lastMonthFirstTime = format.format(lastMonthFirstDateCal.getTime());
                    Calendar lastYearFirstDateCal = Calendar.getInstance();
                    lastYearFirstDateCal.add(Calendar.YEAR, -2);
                    String lastYearFirstTime = format.format(lastYearFirstDateCal.getTime());
                    Calendar lastYearFirstDateCal2 = Calendar.getInstance();
                    lastYearFirstDateCal2.add(Calendar.YEAR, -1);
                    String lastYearFirstTime2 = format.format(lastYearFirstDateCal2.getTime());
                    Integer fireAlarmWcl = alarmFireService.fireAlarmCount(baseCompanies.get(i).getCompanyId(), 0,
                            "101", lastYearFirstTime2, lastMonthFirstTime);
                    demReportDataVo.setFireUnhandled(fireAlarmWcl);
                    LambdaQueryWrapper<AlarmFire> queryWrapper6 = Wrappers.lambdaQuery();
                    queryWrapper6.eq(AlarmFire::getCompanyId, baseCompanies.get(i).getCompanyId())
                            .eq(AlarmFire::getHandlingStatus, 1)
                            .last("limit 1");
                    List<AlarmFire> list6 = alarmFireService.list(queryWrapper6);
                    long clFireDays = 0;
                    if (CollectionUtils.isNotEmpty(list6)) {
                        clFireDays = ChronoUnit.DAYS.between(list6.get(0).getAlarmTime(),
                                list6.get(0).getHandlingTime());
                    }
                    LambdaQueryWrapper<BaseDevice> queryWrapper2 = Wrappers.lambdaQuery();
                    queryWrapper2.select(BaseDevice::getId, BaseDevice::getDeviceCode)
                            .eq(BaseDevice::getCompanyId, baseCompanies.get(i).getCompanyId())
                            .in(BaseDevice::getDeviceType, 2, 5, 6)
                            .notLike(BaseDevice::getDeviceName, "风机");
                    List<BaseDevice> list2 = baseDeviceService.list(queryWrapper2);
                    demReportDataVo.setWaterDeviceNum(list2.size());
                    double waterOnlineRate = 0;
                    double waterFaultRate = 0;
                    Integer waterAlarmWcl = 0;
                    long clHydrantWaterDays = 0;
                    if (CollectionUtils.isNotEmpty(list2)) {
                        List<String> deviceCodeList = new ArrayList<>();
                        for (int j = 0; j < list2.size(); j++) {
                            deviceCodeList.add(list2.get(j).getDeviceCode());
                        }
                        List<BaseDeviceStatus> list3 = new ArrayList<>();
                        List<BaseDeviceStatus> list3l = new ArrayList<>();
                        if (CollectionUtils.isNotEmpty(deviceCodeList)) {
                            LambdaQueryWrapper<BaseDeviceStatus> queryWrapper3 = Wrappers.lambdaQuery();
                            queryWrapper3.select(BaseDeviceStatus::getId, BaseDeviceStatus::getDeviceCode)
                                    .in(BaseDeviceStatus::getDeviceCode, deviceCodeList)
                                    .ne(BaseDeviceStatus::getDeviceStatus, 0);
                            list3 = baseDeviceStatusService.list(queryWrapper3);
                            waterOnlineRate = Math.round(list3.size() / list2.size() * 100) * 0.01;
                            LambdaQueryWrapper<BaseDeviceStatus> queryWrapper3l = Wrappers.lambdaQuery();
                            queryWrapper3l.select(BaseDeviceStatus::getId, BaseDeviceStatus::getDeviceCode)
                                    .in(BaseDeviceStatus::getDeviceCode, deviceCodeList)
                                    .eq(BaseDeviceStatus::getDeviceStatus, 2);
                            list3l = baseDeviceStatusService.list(queryWrapper3l);
                            waterFaultRate = Math.round(list3l.size() / list2.size() * 100) * 0.01;
                        }
                        waterAlarmWcl = alarmHydrantWaterService.hydrantWaterCount(baseCompanies.get(i).getCompanyId(), 0,
                                lastYearFirstTime2, lastMonthFirstTime);
                        LambdaQueryWrapper<AlarmHydrantWater> queryWrapper7 = Wrappers.lambdaQuery();
                        queryWrapper7.eq(AlarmHydrantWater::getCompanyId, baseCompanies.get(i).getCompanyId())
                                .eq(AlarmHydrantWater::getHandlingStatus, 1)
                                .last("limit 1");
                        List<AlarmHydrantWater> list7 = alarmHydrantWaterService.list(queryWrapper7);
                        if (CollectionUtils.isNotEmpty(list7)) {
                            clHydrantWaterDays = ChronoUnit.DAYS.between(list7.get(0).getAlarmTime(),
                                    list7.get(0).getHandlingTime());
                        }
                    }
                    demReportDataVo.setWaterOnlineRate(waterOnlineRate);
                    demReportDataVo.setWaterFaultRate(waterFaultRate);
                    demReportDataVo.setWaterUnhandled(waterAlarmWcl);
                    LambdaQueryWrapper<BaseDevice> queryWrapper4 = Wrappers.lambdaQuery();
                    queryWrapper4.select(BaseDevice::getId, BaseDevice::getDeviceCode)
                            .eq(BaseDevice::getCompanyId, baseCompanies.get(i).getCompanyId())
                            .eq(BaseDevice::getDeviceType, 6)
                            .like(BaseDevice::getDeviceName, "风机");
                    List<BaseDevice> list4 = baseDeviceService.list(queryWrapper4);
                    demReportDataVo.setSmokeDeviceNum(list4.size());
                    double smokeOnlineRate = 0;
                    double smokeFaultRate = 0;
                    Integer smokeAlarmWcl = 0;
                    long clSmokeDays = 0;
                    if (CollectionUtils.isNotEmpty(list4)) {
                        List<String> deviceCodeList = new ArrayList<>();
                        for (int j = 0; j < list4.size(); j++) {
                            deviceCodeList.add(list4.get(j).getDeviceCode());
                        }
                        List<BaseDeviceStatus> list5 = new ArrayList<>();
                        List<BaseDeviceStatus> list5l = new ArrayList<>();
                        if (CollectionUtils.isNotEmpty(deviceCodeList)) {
                            LambdaQueryWrapper<BaseDeviceStatus> queryWrapper5 = Wrappers.lambdaQuery();
                            queryWrapper5.select(BaseDeviceStatus::getId, BaseDeviceStatus::getDeviceCode)
                                    .in(BaseDeviceStatus::getDeviceCode, deviceCodeList)
                                    .ne(BaseDeviceStatus::getDeviceStatus, 0);
                            list5 = baseDeviceStatusService.list(queryWrapper5);
                            smokeOnlineRate = Math.round(list5.size() / list4.size()) * 0.01;
                            LambdaQueryWrapper<BaseDeviceStatus> queryWrapper5l = Wrappers.lambdaQuery();
                            queryWrapper5l.select(BaseDeviceStatus::getId, BaseDeviceStatus::getDeviceCode)
                                    .in(BaseDeviceStatus::getDeviceCode, deviceCodeList)
                                    .ne(BaseDeviceStatus::getDeviceStatus, 2);
                            list5l = baseDeviceStatusService.list(queryWrapper5l);
                            smokeFaultRate = Math.round(list5l.size() / list4.size()) * 0.01;
                        }
                        smokeAlarmWcl = alarmSmokeControlService.smokeControlCount(baseCompanies.get(i).getCompanyId(), 0,
                                lastYearFirstTime2, lastMonthFirstTime);
                        LambdaQueryWrapper<AlarmSmokeControl> queryWrapper8 = Wrappers.lambdaQuery();
                        queryWrapper8.eq(AlarmSmokeControl::getCompanyId, baseCompanies.get(i).getCompanyId())
                                .eq(AlarmSmokeControl::getHandlingStatus, 1)
                                .last("limit 1");
                        List<AlarmSmokeControl> list8 = alarmSmokeControlService.list(queryWrapper8);
                        if (CollectionUtils.isNotEmpty(list8)) {
                            clSmokeDays = ChronoUnit.DAYS.between(list8.get(0).getAlarmTime(),
                                    list8.get(0).getHandlingTime());
                        }
                    }
                    demReportDataVo.setSmokeOnlineRate(smokeOnlineRate);
                    demReportDataVo.setSmokeFaultRate(smokeFaultRate);
                    demReportDataVo.setSmokeUnhandled(smokeAlarmWcl);
                    LambdaQueryWrapper<BaseCompanyPerson> queryWrapperPerson = Wrappers.lambdaQuery();
                    queryWrapperPerson.select(BaseCompanyPerson::getFireManageName)
                            .eq(BaseCompanyPerson::getCompanyId, baseCompanies.get(i).getCompanyId());
                    List<BaseCompanyPerson> list9 =
                            baseCompanyPersonService.list(queryWrapperPerson);
                    LambdaQueryWrapper<DemEnforceInspectRecord> queryWrapper10 = Wrappers.lambdaQuery();
                    queryWrapper10.select(DemEnforceInspectRecord::getId)
                            .like(DemEnforceInspectRecord::getCompanyName, baseCompanies.get(i).getCompanyName())
                            .eq(DemEnforceInspectRecord::getInspectQualified, 0)
                            .between(DemEnforceInspectRecord::getInspectEndTime, lastYearFirstTime, date);
                    List<DemEnforceInspectRecord> list10 = demEnforceInspectRecordService.list(queryWrapper10);
                    demReportDataVo.setDoubleRandomNum(list10.size());
                    Calendar lastYearFirstDateCal3 = Calendar.getInstance();
                    lastYearFirstDateCal3.add(Calendar.YEAR, -3);
                    String lastYearFirstTime3 = format.format(lastYearFirstDateCal3.getTime());
                    demReportDataVo.setLastMonthFirstTime(lastYearFirstTime3);
                    LambdaQueryWrapper<DemLawSituation> queryWrapper11 = Wrappers.lambdaQuery();
                    queryWrapper11.select(DemLawSituation::getId)
                            .like(DemLawSituation::getPunishedPerson, baseCompanies.get(i).getCompanyName())
                            .eq(DemLawSituation::getEnable, 0)
                            .between(DemLawSituation::getPunishmentDecisionTime, lastYearFirstTime3, date);
                    List<DemLawSituation> list11 = demLawSituationService.list(queryWrapper11);
                    demReportDataVo.setPunishNum(list11.size());
                    LambdaQueryWrapper<DemEnforceReportComplaint> queryWrapper12 = Wrappers.lambdaQuery();
                    queryWrapper12.select(DemEnforceReportComplaint::getId)
                            .like(DemEnforceReportComplaint::getReportAddress, baseCompanies.get(i).getAddress())
                            .eq(DemEnforceReportComplaint::getEnable, 0)
                            .in(DemEnforceReportComplaint::getFactFind, 1, 2)
                            .between(DemEnforceReportComplaint::getReportTime, lastYearFirstTime, date);
                    List<DemEnforceReportComplaint> list12 = demEnforceReportComplaintService.list(queryWrapper12);
                    demReportDataVo.setReportComplaintNum(list12.size());
                    Calendar lastYearFirstDateCal1 = Calendar.getInstance();
                    lastYearFirstDateCal1.add(Calendar.YEAR, -1);
                    String lastYearFirstTime1 = format.format(lastYearFirstDateCal1.getTime());
                    LambdaQueryWrapper<DemFireStatistics> queryWrapper13 = Wrappers.lambdaQuery();
                    queryWrapper13.select(DemFireStatistics::getId,DemFireStatistics::getDeathToll,
                            DemFireStatistics::getDirectPropertyLoss)
                            .like(DemFireStatistics::getFireAddress, baseCompanies.get(i).getAddress())
                            .between(DemFireStatistics::getFireTime, lastYearFirstTime1, date);
                    List<DemFireStatistics> list13 = demFireStatisticsService.list(queryWrapper13);
                    int deathToll=0;
                    int directPropertyLoss=0;
                    if (CollectionUtils.isNotEmpty(list13)){
                        for (int h = 0; h < list13.size(); h++) {
                            deathToll+=Integer.parseInt(list13.get(h).getDeathToll());
                            directPropertyLoss+=Integer.parseInt(list13.get(h).getDirectPropertyLoss());
                        }
                    }
                    demReportDataVo.setMajorFireNum(deathToll);
                    demReportDataVo.setFireDisasterNum(directPropertyLoss);
                    demReportDataVo.setGeneralFireNum(list13.size());
                    demReportDataVo.setManagerStatus(0);
                    if (CollectionUtils.isNotEmpty(indexConfig1)) {
                        for (int l = 0; l < indexConfig1.size(); l++) {
                            ReportIndexResult reportIndexResult1 = new ReportIndexResult();
                            reportIndexResult1.setIndexCode(indexConfig1.get(l).getIndexCode());
                            reportIndexResult1.setIndexName(indexConfig1.get(l).getIndexName());
                            reportIndexResult1.setObjectId(baseCompanies.get(i).getId());
                            reportIndexResult1.setCreateDate(date);
                            reportIndexResult1.setScoreDesc(indexConfig1.get(l).getIndexDesc());
                            if (CollectionUtils.isNotEmpty(indexConfig2)) {
                                for (int k = 0; k < indexConfig2.size(); k++) {
                                    if (indexConfig1.get(l).getId().equals(indexConfig2.get(k).getSeniorIndex())) {
                                        ReportIndexResult reportIndexResult2 = new ReportIndexResult();
                                        reportIndexResult2.setIndexCode(indexConfig2.get(k).getIndexCode());
                                        reportIndexResult2.setIndexName(indexConfig2.get(k).getIndexName());
                                        reportIndexResult2.setObjectId(baseCompanies.get(i).getId());
                                        reportIndexResult2.setCreateDate(date);
                                        reportIndexResult2.setScoreDesc(indexConfig2.get(k).getIndexDesc());
                                        if (CollectionUtils.isNotEmpty(indexConfig3)) {
                                            for (int j = 0; j < indexConfig3.size(); j++) {
                                                if (indexConfig2.get(k).getId().equals(indexConfig3.get(j).getSeniorIndex())) {
                                                    ReportIndexResult reportIndexResult = new ReportIndexResult();
                                                    reportIndexResult.setIndexCode(indexConfig3.get(j).getIndexCode());
                                                    reportIndexResult.setIndexName(indexConfig3.get(j).getIndexName());
                                                    reportIndexResult.setObjectId(baseCompanies.get(i).getId());
                                                    reportIndexResult.setCreateDate(date);
                                                    reportIndexResult.setScoreDesc(indexConfig3.get(j).getIndexDesc());
                                                    if (CollectionUtils.isNotEmpty(baseBuilds)) {
                                                        reportIndexResult.setScoreType(1);
                                                        if (indexConfig3.get(j).getSeniorIndex().equals(2)) {
                                                            if (indexConfig3.get(j).getIndexCode().equals("10024")) {
                                                                if (baseBuilds.get(0).getBaseBuild().getFireRating()!=null){
                                                                    reportIndexResult.setIndexData(baseBuilds.get(0).getBaseBuild().getFireRating().toString());
                                                                    if (baseBuilds.get(0).getBaseBuild().getFireRating().equals(1)) {
                                                                        reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight() * indexConfig2.get(k).getIndexWeight());
                                                                    } else if (baseBuilds.get(0).getBaseBuild().getFireRating().equals(2)) {
                                                                        reportIndexResult.setIndexScore(75 * indexConfig3.get(j).getIndexWeight());
                                                                        reportIndexResult2.setIndexScore(75 * indexConfig3.get(j).getIndexWeight() * indexConfig2.get(k).getIndexWeight());
                                                                    } else if (baseBuilds.get(0).getBaseBuild().getFireRating().equals(3)) {
                                                                        reportIndexResult.setIndexScore(50 * indexConfig3.get(j).getIndexWeight());
                                                                        reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight() * indexConfig2.get(k).getIndexWeight());
                                                                    } else {
                                                                        reportIndexResult.setIndexScore(25 * indexConfig3.get(j).getIndexWeight());
                                                                        reportIndexResult2.setIndexScore(25 * indexConfig3.get(j).getIndexWeight() * indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }else {
                                                                    reportIndexResult.setIndexScore(50 * indexConfig3.get(j).getIndexWeight());
                                                                    reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight() * indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            }
                                                            this.save(reportIndexResult);
                                                        }else if (indexConfig3.get(j).getSeniorIndex().equals(7)){
                                                            if (indexConfig3.get(j).getIndexCode().equals("10025")) {
                                                                reportIndexResult.setIndexData(baseBuilds.get(0).getBaseBuild().getAboveFloor().toString());
                                                                if (baseBuilds.get(0).getBaseBuild().getAboveFloor() < 10) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else if (baseBuilds.get(0).getBaseBuild().getAboveFloor() > 10 && baseBuilds.get(0).getBaseBuild().getAboveFloor() < 40) {
                                                                    reportIndexResult.setIndexScore(66.67 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(66.67 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else{
                                                                        reportIndexResult2.setIndexScore(66.67 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(33.33 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(33.33 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                    reportIndexResult.setIndexScore(33.33 * indexConfig3.get(j).getIndexWeight());
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10026")) {
                                                                reportIndexResult.setIndexData(baseBuilds.get(0).getBaseBuild().getUnderSpace().toString());
                                                                if (baseBuilds.get(0).getBaseBuild().getUnderSpace() > 20000) {
                                                                    reportIndexResult.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else if (baseBuilds.get(0).getBaseBuild().getUnderSpace() > 10000 && baseBuilds.get(0).getBaseBuild().getUnderSpace() < 20000) {
                                                                    reportIndexResult.setIndexScore(-75 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-75 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-75 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else if (baseBuilds.get(0).getBaseBuild().getUnderSpace() > 5000 && baseBuilds.get(0).getBaseBuild().getUnderSpace() < 10000) {
                                                                    reportIndexResult.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(-25 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-25 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-25 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            }
                                                            this.save(reportIndexResult);
                                                        }else if (indexConfig3.get(j).getSeniorIndex().equals(8)){
                                                            if (indexConfig3.get(j).getIndexCode().equals("10027")) {
                                                                reportIndexResult.setIndexData(baseBuilds.get(0).getBaseBuild().getUseCharacter().toString());
                                                                if (baseBuilds.get(0).getBaseBuild().getUseCharacter().equals(16)) {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                } else if (baseBuilds.get(0).getBaseBuild().getUseCharacter().equals(14) || baseBuilds.get(0).getBaseBuild().getUseCharacter().equals(15)) {
                                                                    reportIndexResult.setIndexScore(50 * indexConfig3.get(j).getIndexWeight());
                                                                    reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                } else if (baseBuilds.get(0).getBaseBuild().getUseCharacter().equals(2)) {
                                                                    reportIndexResult.setIndexScore(75 * indexConfig3.get(j).getIndexWeight());
                                                                    reportIndexResult2.setIndexScore(75 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                } else {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10028")) {
                                                                reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult.setScoreType(0);
                                                            }
                                                            this.save(reportIndexResult);
                                                        }else if (indexConfig3.get(j).getSeniorIndex().equals(9)){
                                                             if (indexConfig3.get(j).getIndexCode().equals("10029")) {
                                                                reportIndexResult.setIndexData(baseBuilds.get(0).getBaseBuild().getCompleteYear().toString());
                                                                long days = date.toEpochDay() - baseBuilds.get(0).getBaseBuild().getCompleteYear().toEpochDay();
                                                                if (days < 7300) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            }
                                                            this.save(reportIndexResult);
                                                        }
                                                    } else {
                                                        if (indexConfig3.get(j).getSeniorIndex().equals(2) || indexConfig3.get(j).getSeniorIndex().equals(7) || indexConfig3.get(j).getSeniorIndex().equals(8) || indexConfig3.get(j).getSeniorIndex().equals(9)) {
                                                            if (indexConfig3.get(j).getIndexCode().equals("10026") || indexConfig3.get(j).getIndexCode().equals("10028")) {
                                                                reportIndexResult.setIndexScore(0.00);
                                                            } else {
                                                                reportIndexResult.setIndexScore(50 * indexConfig3.get(j).getIndexWeight());
                                                            }
                                                            reportIndexResult.setScoreType(0);
                                                            reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            this.save(reportIndexResult);
                                                        }
                                                    }
                                                    if (indexConfig3.get(j).getSeniorIndex().equals(10)) {
                                                        if (fireAlarmNum == 0) {
                                                            reportIndexResult.setScoreType(0);
                                                            if (indexConfig3.get(j).getIndexCode().equals("10030")) {
                                                                reportIndexResult.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10031")) {
                                                                reportIndexResult.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            } else {
                                                                reportIndexResult.setIndexScore(50 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            }
                                                        } else {
                                                            reportIndexResult.setScoreType(1);
                                                            if (indexConfig3.get(j).getIndexCode().equals("10030")) {
                                                                reportIndexResult.setIndexData(String.valueOf(fireOnlineRate));
                                                                if (fireOnlineRate < 0.95) {
                                                                    reportIndexResult.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10031")) {
                                                                reportIndexResult.setIndexData(String.valueOf(fireFaultRate));
                                                                if (fireFaultRate > 0.05) {
                                                                    reportIndexResult.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10032")) {
                                                                reportIndexResult.setIndexData(String.valueOf(fireOnlineRate));
                                                                if (fireOnlineRate > 0.9) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10033")) {
                                                                reportIndexResult.setIndexData(String.valueOf(fireFaultRate));
                                                                if (fireFaultRate < 0.05) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10034")) {
                                                                reportIndexResult.setIndexData(String.valueOf(fireAlarmWcl));
                                                                if (fireAlarmWcl > 0) {
                                                                    reportIndexResult.setIndexScore(-15 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-15 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-15 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else if (clFireDays < 7) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else if (clFireDays < 30) {
                                                                    reportIndexResult.setIndexScore(25 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(25 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(25 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        this.save(reportIndexResult);
                                                    }
                                                    if (indexConfig3.get(j).getSeniorIndex().equals(11)) {
                                                        if (list2.size() == 0) {
                                                            reportIndexResult.setScoreType(0);
                                                            if (indexConfig3.get(j).getIndexCode().equals("10035")) {
                                                                reportIndexResult.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10036")) {
                                                                reportIndexResult.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            } else {
                                                                reportIndexResult.setIndexScore(50 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            }
                                                        } else {
                                                            reportIndexResult.setScoreType(1);
                                                            if (indexConfig3.get(j).getIndexCode().equals("10035")) {
                                                                reportIndexResult.setIndexData(String.valueOf(waterOnlineRate));
                                                                if (waterOnlineRate < 0.95) {
                                                                    reportIndexResult.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10036")) {
                                                                reportIndexResult.setIndexData(String.valueOf(waterFaultRate));
                                                                if (waterFaultRate > 0.05) {
                                                                    reportIndexResult.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10037")) {
                                                                reportIndexResult.setIndexData(String.valueOf(waterOnlineRate));
                                                                if (waterOnlineRate > 0.9) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10038")) {
                                                                reportIndexResult.setIndexData(String.valueOf(waterFaultRate));
                                                                if (waterFaultRate < 0.05) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10039")) {
                                                                reportIndexResult.setIndexData(String.valueOf(waterAlarmWcl));
                                                                if (waterAlarmWcl > 0) {
                                                                    reportIndexResult.setIndexScore(-15 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-15 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-15 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else if (clHydrantWaterDays < 7) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else if (clHydrantWaterDays < 30) {
                                                                    reportIndexResult.setIndexScore(25 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(25 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(25 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        this.save(reportIndexResult);
                                                    }
                                                    if (indexConfig3.get(j).getSeniorIndex().equals(12)) {
                                                        if (list4.size() == 0) {
                                                            reportIndexResult.setScoreType(0);
                                                            if (indexConfig3.get(j).getIndexCode().equals("10040")) {
                                                                reportIndexResult.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10041")) {
                                                                reportIndexResult.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            } else {
                                                                reportIndexResult.setIndexScore(50 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                            }
                                                        } else {
                                                            reportIndexResult.setScoreType(1);
                                                            if (indexConfig3.get(j).getIndexCode().equals("10040")) {
                                                                reportIndexResult.setIndexData(String.valueOf(smokeOnlineRate));
                                                                if (smokeOnlineRate < 0.95) {
                                                                    reportIndexResult.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10041")) {
                                                                reportIndexResult.setIndexData(String.valueOf(smokeFaultRate));
                                                                if (smokeFaultRate > 0.05) {
                                                                    reportIndexResult.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10042")) {
                                                                reportIndexResult.setIndexData(String.valueOf(smokeOnlineRate));
                                                                if (smokeOnlineRate > 0.9) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10043")) {
                                                                reportIndexResult.setIndexData(String.valueOf(smokeFaultRate));
                                                                if (smokeFaultRate < 0.05) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            } else if (indexConfig3.get(j).getIndexCode().equals("10044")) {
                                                                reportIndexResult.setIndexData(String.valueOf(smokeAlarmWcl));
                                                                if (smokeAlarmWcl > 0) {
                                                                    reportIndexResult.setIndexScore(-15 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(-15 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(-15 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else if (clSmokeDays < 7) {
                                                                    reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else if (clSmokeDays < 30) {
                                                                    reportIndexResult.setIndexScore(25 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(25 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(25 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                } else {
                                                                    reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                    if (reportIndexResult2.getIndexScore()!=null){
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                    }else {
                                                                        reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        this.save(reportIndexResult);
                                                    }
                                                    if (indexConfig3.get(j).getSeniorIndex().equals(13)) {
                                                        reportIndexResult.setScoreType(0);
                                                        if (indexConfig3.get(j).getIndexCode().equals("10046") || indexConfig3.get(j).getIndexCode().equals("10048")) {
                                                            reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                            if (reportIndexResult2.getIndexScore()!=null){
                                                                reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                            }else {
                                                                reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            }
                                                        } else {
                                                            reportIndexResult.setIndexScore(50 * indexConfig3.get(j).getIndexWeight());
                                                            if (reportIndexResult2.getIndexScore()!=null){
                                                                reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                            }else {
                                                                reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            }
                                                        }
                                                        this.save(reportIndexResult);
                                                    }
                                                    if (indexConfig3.get(j).getSeniorIndex().equals(14) || indexConfig3.get(j).getSeniorIndex().equals(15) || indexConfig3.get(j).getSeniorIndex().equals(16) || indexConfig3.get(j).getSeniorIndex().equals(17)) {
                                                        if (indexConfig3.get(j).getIndexCode().equals("10054")) {
                                                            if (CollectionUtils.isNotEmpty(list9)) {
                                                                reportIndexResult.setIndexData(list9.get(0).getFireManageName());
                                                            }
                                                            if (list9.size() == 0 || list9.get(0).getFireManageName() == null || list9.get(0).getFireManageName().equals("暂缺") || list9.get(0).getFireManageName().equals("")) {
                                                                reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                                demReportDataVo.setManagerStatus(0);
                                                            } else {
                                                                reportIndexResult.setIndexScore(100 * indexConfig3.get(j).getIndexWeight());
                                                                if (reportIndexResult2.getIndexScore()!=null){
                                                                    reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                                }else {
                                                                    reportIndexResult2.setIndexScore(100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                                }
                                                                demReportDataVo.setManagerStatus(1);
                                                            }
                                                            reportIndexResult.setScoreType(1);
                                                        } else {
                                                            reportIndexResult.setIndexScore(50 * indexConfig3.get(j).getIndexWeight());
                                                            if (reportIndexResult2.getIndexScore()!=null){
                                                                reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight()+reportIndexResult2.getIndexScore());
                                                            }else {
                                                                reportIndexResult2.setIndexScore(50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            }
                                                            reportIndexResult.setScoreType(0);
                                                        }
                                                        this.save(reportIndexResult);
                                                    }
                                                    if (indexConfig3.get(j).getSeniorIndex().equals(18) || indexConfig3.get(j).getSeniorIndex().equals(19) || indexConfig3.get(j).getSeniorIndex().equals(20) || indexConfig3.get(j).getSeniorIndex().equals(21)) {
                                                        if (indexConfig3.get(j).getIndexCode().equals("10067")) {
                                                            reportIndexResult.setIndexData(String.valueOf(list10.size()));
                                                            if (list10.size() == 0) {
                                                                reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            } else if (list10.size() < 4) {
                                                                reportIndexResult.setIndexScore(-20 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(-20 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            } else if (list10.size() < 7) {
                                                                reportIndexResult.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(-50 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            } else {
                                                                reportIndexResult.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            }
                                                            reportIndexResult.setScoreType(1);
                                                        } else if (indexConfig3.get(j).getIndexCode().equals("10068")) {
                                                            reportIndexResult.setIndexData(String.valueOf(list11.size()));
                                                            if (list11.size() == 0) {
                                                                reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            } else if (list11.size() == 1) {
                                                                reportIndexResult.setIndexScore(-20 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(-20 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            } else if (list11.size() == 2) {
                                                                reportIndexResult.setIndexScore(-40 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(-40 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            } else if (list11.size() == 3) {
                                                                reportIndexResult.setIndexScore(-80 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(-80 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            } else {
                                                                reportIndexResult.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            }
                                                            reportIndexResult.setScoreType(1);
                                                        } else if (indexConfig3.get(j).getIndexCode().equals("10069")) {
                                                            reportIndexResult.setIndexData(String.valueOf(list12.size()));
                                                            if (list12.size() < 5) {
                                                                reportIndexResult.setIndexScore(-25 * list12.size() * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(-25 * list12.size() * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            } else {
                                                                reportIndexResult.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight());
                                                                reportIndexResult2.setIndexScore(-100 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            }
                                                            reportIndexResult.setScoreType(1);
                                                        } else if (indexConfig3.get(j).getIndexCode().equals("10070")) {
                                                            reportIndexResult.setScoreType(0);
                                                            reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                            reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                        }
                                                        this.save(reportIndexResult);
                                                    }
                                                    if (indexConfig3.get(j).getSeniorIndex().equals(22) || indexConfig3.get(j).getSeniorIndex().equals(23)) {
                                                        if (indexConfig3.get(j).getIndexCode().equals("10071")) {
                                                            reportIndexResult.setIndexData(String.valueOf(list13.size()));
                                                            reportIndexResult.setIndexScore(-100 * list13.size() * indexConfig3.get(j).getIndexWeight());
                                                            reportIndexResult2.setIndexScore(-100 * list13.size() * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            reportIndexResult.setScoreType(1);
                                                        } else {
                                                            reportIndexResult.setIndexScore(0 * indexConfig3.get(j).getIndexWeight());
                                                            reportIndexResult2.setIndexScore(0 * indexConfig3.get(j).getIndexWeight()* indexConfig2.get(k).getIndexWeight());
                                                            reportIndexResult.setScoreType(0);
                                                        }
                                                        this.save(reportIndexResult);
                                                    }
                                                }
                                            }
                                        }
                                        this.save(reportIndexResult2);
                                        if (indexConfig1.get(l).getId().equals(5)||indexConfig1.get(l).getId().equals(6)){
                                            if (reportIndexResult1.getIndexScore()!=null){
                                                reportIndexResult1.setIndexScore(reportIndexResult2.getIndexScore()* indexConfig1.get(l).getIndexWeight()+reportIndexResult1.getIndexScore());
                                            }else {
                                                reportIndexResult1.setIndexScore(100*indexConfig1.get(l).getIndexWeight()+reportIndexResult2.getIndexScore()* indexConfig1.get(l).getIndexWeight());
                                            }
                                        }else {
                                            if (reportIndexResult1.getIndexScore()!=null){
                                                reportIndexResult1.setIndexScore(reportIndexResult2.getIndexScore()* indexConfig1.get(l).getIndexWeight()+reportIndexResult1.getIndexScore());
                                            }else {
                                                reportIndexResult1.setIndexScore(reportIndexResult2.getIndexScore()* indexConfig1.get(l).getIndexWeight());
                                            }
                                        }
                                    }
                                }
                            }
                            this.save(reportIndexResult1);
                            if (reportResult.getOverallScore()!=null){
                                reportResult.setOverallScore(reportIndexResult1.getIndexScore()+reportResult.getOverallScore());
                            }else {
                                reportResult.setOverallScore(reportIndexResult1.getIndexScore());
                            }
                        }
                    }
                    if (reportResult.getOverallScore()!=null){
                        if (reportResult.getOverallScore()>=90){
                            demReportDataVo.setOverallRating("低风险");
                        }else if (reportResult.getOverallScore()>=80){
                            demReportDataVo.setOverallRating("一般风险");
                        }else if (reportResult.getOverallScore()>=60){
                            demReportDataVo.setOverallRating("较高风险");
                        }else {
                            demReportDataVo.setOverallRating("高风险");
                        }
                    }
                    this.generatePDF(document,demReportDataVo);
                    document.close();
                    reportResultService.save(reportResult);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 定义全局的字体静态变量
    private static Font titlefont;
    private static Font headfont;
    private static Font keyfont;
    private static Font textfont;
    // 最大宽度
    private static int maxWidth = 520;
    // 静态代码块
    static {
        try {
// 不同字体（这里定义为同一种字体：包含不同字号、不同style）
            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            titlefont = new Font(bfChinese, 16, Font.BOLD);
            headfont = new Font(bfChinese, 14, Font.BOLD);
            keyfont = new Font(bfChinese, 10, Font.BOLD);
            textfont = new Font(bfChinese, 10, Font.NORMAL);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 生成PDF文件
    public void generatePDF(Document document,DemReportDataVo demReportDataVo) throws Exception {

// 段落
        Paragraph paragraph = new Paragraph(demReportDataVo.getCompanyName()+"消防安全数字化管理综合分析报告", titlefont);
        paragraph.setAlignment(1); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph.setIndentationLeft(12); //设置左缩进
        paragraph.setIndentationRight(12); //设置右缩进
        paragraph.setFirstLineIndent(24); //设置首行缩进
        paragraph.setLeading(20f); //行间距
        paragraph.setSpacingBefore(5f); //设置段落上空白
        paragraph.setSpacingAfter(20f); //设置段落下空白

        Paragraph paragraph1 = new Paragraph(demReportDataVo.getCompanyName()+":", textfont);
        paragraph1.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右

        Paragraph paragraph2 =
                new Paragraph("本次综合分析是通过贵单位在"+demReportDataVo.getLastMonthFirstTime()+"-"+demReportDataVo.getLastMonthEndTime()+
                "日期间消防设施状况、消防自主管理状况、监督执法情况、火灾风险指数和建筑整体指数进行综合评估，现将综合分析报告如下：", textfont);
        paragraph2.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph2.setFirstLineIndent(24); //设置首行缩进
        paragraph2.setLeading(20f); //行间距
        paragraph2.setSpacingBefore(5f); //设置段落上空白
        paragraph2.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph3 = new Paragraph("一、整体评价", headfont);
        paragraph3.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph3.setFirstLineIndent(24); //设置首行缩进

        Paragraph paragraph4 = new Paragraph("贵单位在期间消防安全管理指数评价为："+demReportDataVo.getOverallRating(), textfont);
        paragraph4.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph4.setFirstLineIndent(24); //设置首行缩进
        paragraph4.setLeading(20f); //行间距
        paragraph4.setSpacingBefore(5f); //设置段落上空白
        paragraph4.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph5 = new Paragraph("二、测评范围", headfont);
        paragraph5.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph5.setFirstLineIndent(24); //设置首行缩进

        Paragraph paragraph6 = new Paragraph("包含消防设施系统（火灾报警系统；消防水系统；防排烟系统；维保单位履职情况等  如实显示，没有的就不显示）、消防自主管理状况（组织制度落实情况；日常值班、巡检情况；预案、培训落实情况；微站实体化运行情况）、监督执法情况（双随机检查情况；处罚情况；投诉举报情况；重大隐患挂牌情况）和火灾风险指数（当年度火灾情况；上年度火灾情况）等项目进行综合测评。", textfont);
        paragraph6.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph6.setFirstLineIndent(24); //设置首行缩进
        paragraph6.setLeading(20f); //行间距
        paragraph6.setSpacingBefore(5f); //设置段落上空白
        paragraph6.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph7 = new Paragraph("三、主要风险及问题", headfont);
        paragraph7.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph7.setFirstLineIndent(24); //设置首行缩进

        Paragraph paragraph8 = new Paragraph("（一）消防设施问题", textfont);
        paragraph8.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph8.setFirstLineIndent(24); //设置首行缩进
        paragraph8.setLeading(20f); //行间距
        paragraph8.setSpacingBefore(5f); //设置段落上空白
        paragraph8.setSpacingAfter(10f); //设置段落下空白

        String fireText = "暂无问题";
        if (demReportDataVo.getFireDeviceNum().equals(0)){
            fireText = "暂无数据";
        }else {
            if (demReportDataVo.getFireOnlineRate()<0.95 && demReportDataVo.getFireFaultRate()>0.05 && demReportDataVo.getFireUnhandled()>0){
                fireText="在线率低于95%，故障率高于5%，存在未处理告警"+demReportDataVo.getFireUnhandled()+"条；";
            }else if (demReportDataVo.getFireOnlineRate()<0.95 && demReportDataVo.getFireFaultRate()>0.05){
                fireText="在线率低于95%，故障率高于5%；";
            }else if (demReportDataVo.getFireOnlineRate()<0.95 && demReportDataVo.getFireUnhandled()>0){
                fireText="在线率低于95%，存在未处理告警"+demReportDataVo.getFireUnhandled()+"条；";
            }else if (demReportDataVo.getFireFaultRate()>0.05 && demReportDataVo.getFireUnhandled()>0){
                fireText="故障率高于5%，存在未处理告警"+demReportDataVo.getFireUnhandled()+"条；";
            }else if (demReportDataVo.getFireOnlineRate()<0.95){
                fireText="在线率低于95%；";
            }else if (demReportDataVo.getFireFaultRate()>0.05){
                fireText="故障率高于5%；";
            }else if (demReportDataVo.getFireUnhandled()>0){
                fireText="存在未处理告警"+demReportDataVo.getFireUnhandled()+"条；";
            }
        }
        Paragraph paragraph9 = new Paragraph("火灾报警系统："+fireText, textfont);
        paragraph9.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph9.setFirstLineIndent(24); //设置首行缩进
        paragraph9.setLeading(20f); //行间距
        paragraph9.setSpacingBefore(5f); //设置段落上空白
        paragraph9.setSpacingAfter(10f); //设置段落下空白

        String waterText = "暂无问题";
        if (demReportDataVo.getWaterDeviceNum().equals(0)){
            waterText = "暂无数据";
        }else {
            if (demReportDataVo.getWaterOnlineRate()<0.95 && demReportDataVo.getWaterFaultRate()>0.05 && demReportDataVo.getWaterUnhandled()>0){
                waterText="在线率低于95%，故障率高于5%，存在未处理告警"+demReportDataVo.getWaterUnhandled()+"条；";
            }else if (demReportDataVo.getWaterOnlineRate()<0.95 && demReportDataVo.getWaterFaultRate()>0.05){
                waterText="在线率低于95%，故障率高于5%；";
            }else if (demReportDataVo.getWaterOnlineRate()<0.95 && demReportDataVo.getWaterUnhandled()>0){
                waterText="在线率低于95%，存在未处理告警"+demReportDataVo.getWaterUnhandled()+"条；";
            }else if (demReportDataVo.getWaterFaultRate()>0.05 && demReportDataVo.getWaterUnhandled()>0){
                waterText="故障率高于5%，存在未处理告警"+demReportDataVo.getWaterUnhandled()+"条；";
            }else if (demReportDataVo.getWaterOnlineRate()<0.95){
                waterText="在线率低于95%；";
            }else if (demReportDataVo.getWaterFaultRate()>0.05){
                waterText="故障率高于5%；";
            }else if (demReportDataVo.getWaterUnhandled()>0){
                waterText="存在未处理告警"+demReportDataVo.getWaterUnhandled()+"条；";
            }
        }

        Paragraph paragraph26 = new Paragraph("消防水系统："+waterText, textfont);
        paragraph26.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph26.setFirstLineIndent(24); //设置首行缩进
        paragraph26.setLeading(20f); //行间距
        paragraph26.setSpacingBefore(5f); //设置段落上空白
        paragraph26.setSpacingAfter(10f); //设置段落下空白

        String smokeText = "暂无问题";
        if (demReportDataVo.getSmokeDeviceNum().equals(0)){
            smokeText="暂无数据";
        }else {
            if (demReportDataVo.getSmokeOnlineRate()<0.95 && demReportDataVo.getSmokeFaultRate()>0.05 && demReportDataVo.getSmokeUnhandled()>0){
                smokeText="在线率低于95%，故障率高于5%，存在未处理告警"+demReportDataVo.getSmokeUnhandled()+"条；";
            }else if (demReportDataVo.getSmokeOnlineRate()<0.95 && demReportDataVo.getSmokeFaultRate()>0.05){
                smokeText="在线率低于95%，故障率高于5%；";
            }else if (demReportDataVo.getSmokeOnlineRate()<0.95 && demReportDataVo.getSmokeUnhandled()>0){
                smokeText="在线率低于95%，存在未处理告警"+demReportDataVo.getSmokeUnhandled()+"条；";
            }else if (demReportDataVo.getSmokeFaultRate()>0.05 && demReportDataVo.getSmokeUnhandled()>0){
                smokeText="故障率高于5%，存在未处理告警"+demReportDataVo.getSmokeUnhandled()+"条；";
            }else if (demReportDataVo.getSmokeOnlineRate()<0.95){
                smokeText="在线率低于95%；";
            }else if (demReportDataVo.getSmokeFaultRate()>0.05){
                smokeText="故障率高于5%；";
            }else if (demReportDataVo.getSmokeUnhandled()>0){
                smokeText="存在未处理告警"+demReportDataVo.getSmokeUnhandled()+"条；";
            }
        }

        Paragraph paragraph10 = new Paragraph("防排烟系统："+smokeText, textfont);
        paragraph10.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph10.setFirstLineIndent(24); //设置首行缩进
        paragraph10.setLeading(20f); //行间距
        paragraph10.setSpacingBefore(5f); //设置段落上空白
        paragraph10.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph11 = new Paragraph("维保单位履职情况：暂无数据。", textfont);
        paragraph11.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph11.setFirstLineIndent(24); //设置首行缩进
        paragraph11.setLeading(20f); //行间距
        paragraph11.setSpacingBefore(5f); //设置段落上空白
        paragraph11.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph12 = new Paragraph("（二）消防自主管理问题", textfont);
        paragraph12.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph12.setFirstLineIndent(24); //设置首行缩进
        paragraph12.setLeading(20f); //行间距
        paragraph12.setSpacingBefore(5f); //设置段落上空白
        paragraph12.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph13 = new Paragraph("组织制度落实情况：暂无数据；", textfont);
        paragraph13.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph13.setFirstLineIndent(24); //设置首行缩进
        paragraph13.setLeading(20f); //行间距
        paragraph13.setSpacingBefore(5f); //设置段落上空白
        paragraph13.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph14 = new Paragraph("消防档案：暂无数据；", textfont);
        paragraph14.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph14.setFirstLineIndent(24); //设置首行缩进
        paragraph14.setLeading(20f); //行间距
        paragraph14.setSpacingBefore(5f); //设置段落上空白
        paragraph14.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph15 = new Paragraph("消防重点部位：暂无数据。", textfont);
        paragraph15.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph15.setFirstLineIndent(24); //设置首行缩进
        paragraph15.setLeading(20f); //行间距
        paragraph15.setSpacingBefore(5f); //设置段落上空白
        paragraph15.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph16 = new Paragraph("（三）监督执法情况", textfont);
        paragraph16.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph16.setFirstLineIndent(24); //设置首行缩进
        paragraph16.setLeading(20f); //行间距
        paragraph16.setSpacingBefore(5f); //设置段落上空白
        paragraph16.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph17 =
                new Paragraph("上述时间段内监督检查发现隐患"+demReportDataVo.getDoubleRandomNum()+"处，"+"发现处罚"+demReportDataVo.getPunishNum()+
                        "起，"+"发现举报投诉"+demReportDataVo.getReportComplaintNum()+"起；",
                textfont);
        paragraph17.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph17.setFirstLineIndent(24); //设置首行缩进
        paragraph17.setLeading(20f); //行间距
        paragraph17.setSpacingBefore(5f); //设置段落上空白
        paragraph17.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph18 = new Paragraph("（四）火灾情况", textfont);
        paragraph18.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph18.setFirstLineIndent(24); //设置首行缩进
        paragraph18.setLeading(20f); //行间距
        paragraph18.setSpacingBefore(5f); //设置段落上空白
        paragraph18.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph19 =
                new Paragraph("上一年度发生"+demReportDataVo.getGeneralFireNum()+"起火灾，造成"+demReportDataVo.getMajorFireNum()+
                "名人员伤亡，造成直接财产损失" +demReportDataVo.getFireDisasterNum()+
                "万元。", textfont);
        paragraph19.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph19.setFirstLineIndent(24); //设置首行缩进
        paragraph19.setLeading(20f); //行间距
        paragraph19.setSpacingBefore(5f); //设置段落上空白
        paragraph19.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph20 = new Paragraph("四、防范对策及建议", headfont);
        paragraph20.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph20.setFirstLineIndent(24); //设置首行缩进

        Paragraph paragraph21 = new Paragraph("1、建议联系消防设施维保单位对本单位开展一次全面维护保养，对损坏、故障的设施要及时修复，确保消防设施完整好用；", textfont);
        paragraph21.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph21.setFirstLineIndent(24); //设置首行缩进
        paragraph21.setLeading(20f); //行间距
        paragraph21.setSpacingBefore(5f); //设置段落上空白
        paragraph21.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph22 = new Paragraph("2、建议对照重点单位消防档案管理办法，进一步完善员工安全培训记录、明确消防重点部位等内容；", textfont);
        paragraph22.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph22.setFirstLineIndent(24); //设置首行缩进
        paragraph22.setLeading(20f); //行间距
        paragraph22.setSpacingBefore(5f); //设置段落上空白
        paragraph22.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph23 = new Paragraph("3、建议对单位重点部位开展一轮全面自查，落实值班、巡查以及应急处置工作职责，确保“实名制”管理工作制度落实到位；", textfont);
        paragraph23.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph23.setFirstLineIndent(24); //设置首行缩进
        paragraph23.setLeading(20f); //行间距
        paragraph23.setSpacingBefore(5f); //设置段落上空白
        paragraph23.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph24 = new Paragraph("4、建议充分利用场所自身有利条件，在电子屏、明显位置循环播放宣传视频、张贴海报等形式加强消防安全提示。定期对单位员工开展消防安全教育和重点岗位专题培训，持续提高员工消防安全“一懂三会”基本能力。", textfont);
        paragraph24.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph24.setFirstLineIndent(24); //设置首行缩进
        paragraph24.setLeading(20f); //行间距
        paragraph24.setSpacingBefore(5f); //设置段落上空白
        paragraph24.setSpacingAfter(10f); //设置段落下空白

        Paragraph paragraph25 = new Paragraph("五、具体问题清单", headfont);
        paragraph25.setAlignment(0); //设置文字居中 0靠左 1，居中 2，靠右
        paragraph25.setFirstLineIndent(24); //设置首行缩进

// 直线
//        Paragraph p1 = new Paragraph();
//        p1.add(new Chunk(new LineSeparator()));

// 点线
//        Paragraph p2 = new Paragraph();
//        p2.add(new Chunk(new DottedLineSeparator()));

// 超链接
//        Anchor anchor = new Anchor("baidu");
//        anchor.setReference("www.baidu.com");

// 定位
//        Anchor gotoP = new Anchor("goto");
//        gotoP.setReference("#top");

// 添加图片
        Image image = Image.getInstance("https://img-blog.csdn.net/20180801174617455?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zNzg0ODcxMA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70");
        image.setAlignment(Image.ALIGN_CENTER);
        image.scalePercent(40); //依照比例缩放

// 表格
        PdfPTable table = createTable(new float[] { 40, 120, 120, 120, 80, 80 });
        table.addCell(createCell("美好的一天", headfont, Element.ALIGN_LEFT, 6, false));
        table.addCell(createCell("早上9:00", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("中午11:00", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("中午13:00", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("下午15:00", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("下午17:00", keyfont, Element.ALIGN_CENTER));
        table.addCell(createCell("晚上19:00", keyfont, Element.ALIGN_CENTER));
        Integer totalQuantity = 0;
        for (int i = 0; i < 5; i++) {
            table.addCell(createCell("起床", textfont));
            table.addCell(createCell("吃午饭", textfont));
            table.addCell(createCell("午休", textfont));
            table.addCell(createCell("下午茶", textfont));
            table.addCell(createCell("回家", textfont));
            table.addCell(createCell("吃晚饭", textfont));
            totalQuantity ++;
        }
        table.addCell(createCell("总计", keyfont));
        table.addCell(createCell("", textfont));
        table.addCell(createCell("", textfont));
        table.addCell(createCell("", textfont));
        table.addCell(createCell(String.valueOf(totalQuantity) + "件事", textfont));
        table.addCell(createCell("", textfont));

        document.add(paragraph);
        document.add(paragraph1);
        document.add(paragraph2);
        document.add(paragraph3);
        document.add(paragraph4);
        document.add(paragraph5);
        document.add(paragraph6);
        document.add(paragraph7);
        document.add(paragraph8);
        document.add(paragraph9);
        document.add(paragraph26);
        document.add(paragraph10);
        document.add(paragraph11);
        document.add(paragraph12);
        document.add(paragraph13);
        document.add(paragraph14);
        document.add(paragraph15);
        document.add(paragraph16);
        document.add(paragraph17);
        document.add(paragraph18);
        document.add(paragraph19);
        document.add(paragraph20);
        document.add(paragraph21);
        document.add(paragraph22);
        document.add(paragraph23);
        document.add(paragraph24);
        document.add(paragraph25);
//        document.add(anchor);
//        document.add(p2);
//        document.add(gotoP);
//        document.add(p1);
        document.add(table);
//        document.add(image);
    }


/**------------------------创建表格单元格的方法start----------------------------*/
    /**
     * 创建单元格(指定字体)
     * @param value
     * @param font
     * @return
     */
    public PdfPCell createCell(String value, Font font) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }
    /**
     * 创建单元格（指定字体、水平..）
     * @param value
     * @param font
     * @param align
     * @return
     */
    public PdfPCell createCell(String value, Font font, int align) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }
    /**
     * 创建单元格（指定字体、水平居..、单元格跨x列合并）
     * @param value
     * @param font
     * @param align
     * @param colspan
     * @return
     */
    public PdfPCell createCell(String value, Font font, int align, int colspan) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }
    /**
     * 创建单元格（指定字体、水平居..、单元格跨x列合并、设置单元格内边距）
     * @param value
     * @param font
     * @param align
     * @param colspan
     * @param boderFlag
     * @return
     */
    public PdfPCell createCell(String value, Font font, int align, int colspan, boolean boderFlag) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setPhrase(new Phrase(value, font));
        cell.setPadding(3.0f);
        if (!boderFlag) {
            cell.setBorder(0);
            cell.setPaddingTop(15.0f);
            cell.setPaddingBottom(8.0f);
        } else if (boderFlag) {
            cell.setBorder(0);
            cell.setPaddingTop(0.0f);
            cell.setPaddingBottom(15.0f);
        }
        return cell;
    }
    /**
     * 创建单元格（指定字体、水平..、边框宽度：0表示无边框、内边距）
     * @param value
     * @param font
     * @param align
     * @param borderWidth
     * @param paddingSize
     * @param flag
     * @return
     */
    public PdfPCell createCell(String value, Font font, int align, float[] borderWidth, float[] paddingSize, boolean flag) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setPhrase(new Phrase(value, font));
        cell.setBorderWidthLeft(borderWidth[0]);
        cell.setBorderWidthRight(borderWidth[1]);
        cell.setBorderWidthTop(borderWidth[2]);
        cell.setBorderWidthBottom(borderWidth[3]);
        cell.setPaddingTop(paddingSize[0]);
        cell.setPaddingBottom(paddingSize[1]);
        if (flag) {
            cell.setColspan(2);
        }
        return cell;
    }
/**------------------------创建表格单元格的方法end----------------------------*/


/**--------------------------创建表格的方法start------------------- ---------*/
    /**
     * 创建默认列宽，指定列数、水平(居中、右、左)的表格
     * @param colNumber
     * @param align
     * @return
     */
    public PdfPTable createTable(int colNumber, int align) {
        PdfPTable table = new PdfPTable(colNumber);
        try {
            table.setTotalWidth(maxWidth);
            table.setLockedWidth(true);
            table.setHorizontalAlignment(align);
            table.getDefaultCell().setBorder(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return table;
    }
    /**
     * 创建指定列宽、列数的表格
     * @param widths
     * @return
     */
    public PdfPTable createTable(float[] widths) {
        PdfPTable table = new PdfPTable(widths);
        try {
            table.setTotalWidth(maxWidth);
            table.setLockedWidth(true);
            table.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.getDefaultCell().setBorder(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return table;
    }
    /**
     * 创建空白的表格
     * @return
     */
    public PdfPTable createBlankTable() {
        PdfPTable table = new PdfPTable(1);
        table.getDefaultCell().setBorder(0);
        table.addCell(createCell("", keyfont));
        table.setSpacingAfter(20.0f);
        table.setSpacingBefore(20.0f);
        return table;
    }

    @Override
    public List<IndexResultVo> indexResultSelect(Integer id, String createDate) {
        List<IndexResultVo> list = new ArrayList<>();
        List<IndexResult1Vo> list2 = new ArrayList<>();
        LambdaQueryWrapper<ReportResult> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.select(ReportResult::getId,ReportResult::getObjectId,ReportResult::getCreateDate,
                ReportResult::getOverallScore)
                .eq(ReportResult::getId,id);
        List<ReportResult> list1 = reportResultService.list(queryWrapper);
        IndexResultVo indexResultVo = new IndexResultVo();
        if (CollectionUtils.isNotEmpty(list1)) {
            indexResultVo.setCreateDate(list1.get(0).getCreateDate());
            indexResultVo.setId(list1.get(0).getId());
            indexResultVo.setOverallScore(list1.get(0).getOverallScore());
            LambdaQueryWrapper<ReportIndexResult> queryWrapper1 = Wrappers.lambdaQuery();
            queryWrapper1
                    .eq(ReportIndexResult::getObjectId,list1.get(0).getObjectId())
                    .eq(ReportIndexResult::getCreateDate,list1.get(0).getCreateDate());
            List<ReportIndexResult> list3 = this.list(queryWrapper1);
            if (CollectionUtils.isNotEmpty(list3)) {
                List<String> indexIdList = new ArrayList<>();
                for (int i = 0; i < list3.size(); i++) {
                    indexIdList.add(list3.get(i).getIndexCode());
                }
                LambdaQueryWrapper<ReportIndexConfig> queryWrapper2 = Wrappers.lambdaQuery();
                queryWrapper2
                        .in(ReportIndexConfig::getIndexCode,indexIdList);
//                        .eq(ReportIndexConfig::getIndexGrade,1);
                List<ReportIndexConfig> list4 = reportIndexConfigService.list(queryWrapper2);
                for (int j = 0; j < list3.size(); j++) {
                    IndexResult1Vo indexResult1Vo = new IndexResult1Vo();
                    if (CollectionUtils.isNotEmpty(list4)){
                        for (int k = 0; k < list4.size(); k++) {
                            if (list3.get(j).getIndexCode().equals(list4.get(k).getIndexCode()) && list4.get(k).getIndexGrade().equals(1)){
                                indexResult1Vo.setId(list3.get(j).getId());
                                indexResult1Vo.setIndexData(list3.get(j).getIndexData());
                                indexResult1Vo.setIndexName(list3.get(j).getIndexName());
                                indexResult1Vo.setIndexScore(list3.get(j).getIndexScore());
                                indexResult1Vo.setIndexWeight(list4.get(k).getIndexWeight());
                                indexResult1Vo.setScoreDesc(list3.get(j).getScoreDesc());
                                indexResult1Vo.setScoreType(list3.get(j).getScoreType());
                                List<IndexResult2Vo> list5 = new ArrayList<>();
                                for (int m = 0; m < list4.size(); m++) {
                                    if (list4.get(m).getSeniorIndex().equals(list4.get(k).getId()) && list4.get(m).getIndexGrade().equals(2)) {
                                        for (int l = 0; l < list3.size(); l++) {
                                            if (list3.get(l).getIndexCode().equals(list4.get(m).getIndexCode())) {
                                                IndexResult2Vo indexResult2Vo = new IndexResult2Vo();
                                                indexResult2Vo.setId(list3.get(l).getId());
                                                indexResult2Vo.setIndexData(list3.get(l).getIndexData());
                                                indexResult2Vo.setIndexName(list3.get(l).getIndexName());
                                                indexResult2Vo.setIndexScore(list3.get(l).getIndexScore());
                                                indexResult2Vo.setIndexWeight(list4.get(m).getIndexWeight());
                                                indexResult2Vo.setScoreDesc(list3.get(l).getScoreDesc());
                                                indexResult2Vo.setScoreType(list3.get(l).getScoreType());
                                                List<IndexResult3Vo> list6 = new ArrayList<>();
                                                for (int o = 0; o < list4.size(); o++) {
                                                    if (list4.get(o).getSeniorIndex().equals(list4.get(m).getId()) && list4.get(o).getIndexGrade().equals(3)) {
                                                        for (int n = 0; n < list3.size(); n++) {
                                                            if (list3.get(n).getIndexCode().equals(list4.get(o).getIndexCode())) {
                                                                IndexResult3Vo indexResult3Vo = new IndexResult3Vo();
                                                                indexResult3Vo.setId(list3.get(n).getId());
                                                                indexResult3Vo.setIndexData(list3.get(n).getIndexData());
                                                                indexResult3Vo.setIndexName(list3.get(n).getIndexName());
                                                                indexResult3Vo.setIndexScore(list3.get(n).getIndexScore());
                                                                indexResult3Vo.setIndexWeight(list4.get(o).getIndexWeight());
                                                                indexResult3Vo.setScoreDesc(list3.get(n).getScoreDesc());
                                                                indexResult3Vo.setScoreType(list3.get(n).getScoreType());
                                                                list6.add(indexResult3Vo);
                                                            }
                                                        }
                                                    }
                                                }
                                                indexResult2Vo.setIndexResult1List(list6);
                                                list5.add(indexResult2Vo);
                                            }
                                        }
                                    }
                                }
                                indexResult1Vo.setIndexResult1List(list5);
                                list2.add(indexResult1Vo);
                            }
                        }
                    }
                }
            }
            indexResultVo.setIndexResult1List(list2);
            list.add(indexResultVo);
        }

        return list;
    }

    @Override
    public List<Object> reportContrast(ReportResultVO reportResultVO) {
        List<Object> list = new ArrayList<>();
        List<Object> list2 = new ArrayList<>();
        List<Object> list3 = new ArrayList<>();
        LambdaQueryWrapper<ReportResult> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.select(ReportResult::getId,ReportResult::getObjectType,ReportResult::getObjectId,
                ReportResult::getReportObject,
                ReportResult::getCreateDate, ReportResult::getOverallScore)
                .in(ReportResult::getId,reportResultVO.getReportId());
        List<ReportResult> list1 = reportResultService.list(queryWrapper);
        Map<String, Object> map1 = new HashMap<>();
        if (CollectionUtils.isNotEmpty(list1)) {
            for (int i = 0; i < list1.size(); i++) {
                List<Object> list8 = new ArrayList<>();
                LambdaQueryWrapper<ReportIndexResult> queryWrapper1 = Wrappers.lambdaQuery();
                queryWrapper1
                        .eq(ReportIndexResult::getObjectId,list1.get(i).getObjectId())
                        .eq(ReportIndexResult::getCreateDate,list1.get(i).getCreateDate());
                List<ReportIndexResult> list4 = this.list(queryWrapper1);
                List<String> indexIdList = new ArrayList<>();
                if (CollectionUtils.isNotEmpty(list4)) {
                    for (int a = 0; a < list4.size(); a++) {
                        indexIdList.add(list4.get(a).getIndexCode());
                    }
                    LambdaQueryWrapper<ReportIndexConfig> queryWrapper2 = Wrappers.lambdaQuery();
                    queryWrapper2
                            .in(ReportIndexConfig::getIndexCode, indexIdList);
                    List<ReportIndexConfig> list5 = reportIndexConfigService.list(queryWrapper2);
                    Map<String, Object> map = new HashMap<>();
                    map.put("objectType", list1.get(i).getObjectType().equals(1)?"重点单位":"其他");
                    map.put("reportObject", list1.get(i).getReportObject());
                    map.put("overallScore", list1.get(i).getOverallScore());
                    map.put("createDate", list1.get(i).getCreateDate());
                    map.put("associationField", "indexScore" + i);
                    list2.add(map);
                    for (int j = 0; j < list4.size(); j++) {
                        if (CollectionUtils.isNotEmpty(list5)) {
                            for (int k = 0; k < list5.size(); k++) {
                                if (list4.get(j).getIndexCode().equals(list5.get(k).getIndexCode()) && list5.get(k).getIndexGrade().equals(1)) {
                                    Map<String, Object> map2 = new HashMap<>();
                                    map2.put("id", list5.get(k).getId());
                                    map2.put("indexName", list4.get(j).getIndexName());
                                    map2.put("indexWeight", list5.get(k).getIndexWeight());
                                    map2.put("scoreDesc", list4.get(j).getScoreDesc());
                                    map2.put("indexScore", list4.get(j).getIndexScore());
                                    List<Object> list6 = new ArrayList<>();
                                    for (int m = 0; m < list5.size(); m++) {
                                        if (list5.get(m).getSeniorIndex().equals(list5.get(k).getId()) && list5.get(m).getIndexGrade().equals(2)) {
                                            for (int l = 0; l < list4.size(); l++) {
                                                if (list4.get(l).getIndexCode().equals(list5.get(m).getIndexCode())) {
                                                    Map<String, Object> map3 = new HashMap<>();
                                                    map3.put("id", list5.get(m).getId());
                                                    map3.put("indexName", list4.get(l).getIndexName());
                                                    map3.put("indexWeight", list5.get(m).getIndexWeight());
                                                    map3.put("scoreDesc", list4.get(l).getScoreDesc());
                                                    map3.put("indexScore", list4.get(l).getIndexScore());
                                                    List<Object> list7 = new ArrayList<>();
                                                    for (int o = 0; o < list5.size(); o++) {
                                                        if (list5.get(o).getSeniorIndex().equals(list5.get(m).getId()) && list5.get(o).getIndexGrade().equals(3)) {
                                                            for (int n = 0; n < list4.size(); n++) {
                                                                if (list4.get(n).getIndexCode().equals(list5.get(o).getIndexCode())) {
                                                                    Map<String, Object> map4 = new HashMap<>();
                                                                    map4.put("id", list5.get(o).getId());
                                                                    map4.put("indexName", list4.get(n).getIndexName());
                                                                    map4.put("indexWeight", list5.get(o).getIndexWeight());
                                                                    map4.put("scoreDesc", list4.get(n).getScoreDesc());
                                                                    map4.put("indexScore", list4.get(n).getIndexScore());
                                                                    list7.add(map4);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    map3.put("children",list7);
                                                    list6.add(map3);
                                                }
                                            }
                                        }
                                    }
                                    map2.put("children",list6);
                                    list8.add(map2);
                                }
                            }
                        }
                    }

                }
                map1.put("indexScore"+i, list8);
            }
            map1.put("objectInfo", list2);
        }
        list.add(map1);
        return list;
    }

    @Override
    public List<ResultStatisticsVO> resultStatistic(Integer id, String createDate) {
        List<ResultStatisticsVO> list = new ArrayList<>();
        ResultStatisticsVO resultStatisticsVO = new ResultStatisticsVO();
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        String formattedDate = currentDate.format(formatter);
        resultStatisticsVO.setHighRisk(getReportCountByScoreRange(0, 60, formattedDate).size());
        resultStatisticsVO.setMildHighRisk(getReportCountByScoreRange(60, 69, formattedDate).size());
        resultStatisticsVO.setNormalRisk(getReportCountByScoreRange(69, 70, formattedDate).size());
        resultStatisticsVO.setLowRisk(getReportCountByScoreRange(70, 100, formattedDate).size());
        list.add(resultStatisticsVO);
        return list;
    }

    private List<ReportResult> getReportCountByScoreRange(int startScore, int endScore, String createDate) {
        LambdaQueryWrapper<ReportResult> wrapper = new LambdaQueryWrapper<>();
        wrapper.ge(ReportResult::getOverallScore, startScore).le(ReportResult::getOverallScore, endScore)
                .like(ReportResult::getCreateDate, createDate);
        return reportResultService.list(wrapper);
    }

    @Override
    public List<Object> riskGradeScatter(Integer riskGrade) {
        List<Object> list10 = new ArrayList<>();
        String streetTown = "";
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        String formattedDate = currentDate.format(formatter);
        List<ReportResult> highRiskList = new ArrayList<>();
        if (riskGrade.equals(1)) {
            highRiskList = getReportCountByScoreRange(0, 60, formattedDate);
        }else if (riskGrade.equals(2)){
            highRiskList = getReportCountByScoreRange(60, 69, formattedDate);
        }else if (riskGrade.equals(3)){
            highRiskList = getReportCountByScoreRange(69, 70, formattedDate);
        }else if (riskGrade.equals(4)){
            highRiskList = getReportCountByScoreRange(70, 100, formattedDate);
        }
        if (CollectionUtils.isNotEmpty(highRiskList)) {
            List<Integer> idList = new ArrayList<>();
            for (int a = 0; a < highRiskList.size(); a++) {
                idList.add(highRiskList.get(a).getObjectId());
            }
            List<String> streetTownList = new ArrayList<>();
            streetTownList.add("华漕镇");
            streetTownList.add("新虹街道");
            streetTownList.add("七宝镇");
            streetTownList.add("虹桥镇");
            streetTownList.add("古美路街道");
            streetTownList.add("莘庄镇");
            streetTownList.add("梅陇镇");
            streetTownList.add("颛桥镇");
            streetTownList.add("马桥镇");
            streetTownList.add("江川路街道");
            streetTownList.add("吴泾镇");
            streetTownList.add("浦锦街道");
            streetTownList.add("浦江镇");
            List<Object> list = new ArrayList<>();
            IPage<BaseCompany> page = new Page<>(1, 3000);
            LambdaQueryWrapper<BaseCompany> queryWrapper = Wrappers.lambdaQuery();
            queryWrapper.select(BaseCompany::getId, BaseCompany::getCompanyId, BaseCompany::getCompanyName,
                    BaseCompany::getCompanyType, BaseCompany::getLinkPhone, BaseCompany::getAddress, BaseCompany::getStreetTown)
                    .eq(BaseCompany::getEnable, 0)
                    .eq(BaseCompany::getCompanyType, 1)
                    .in(BaseCompany::getId, idList);
            page = baseCompanyService.page(page, queryWrapper);
            List<BaseCompany> list1 = page.getRecords();
            if (CollectionUtils.isNotEmpty(list1)) {
                List<String> companyIdList = new ArrayList<>();
                for (int i = 0; i < list1.size(); i++) {
                    companyIdList.add(list1.get(i).getCompanyId());
                }
                LambdaQueryWrapper<BaseCompanyAttach1> queryWrapper1 = Wrappers.lambdaQuery();
                queryWrapper1.select(BaseCompanyAttach1::getId, BaseCompanyAttach1::getCompanyId, BaseCompanyAttach1::getLongitude,
                        BaseCompanyAttach1::getLatitude,BaseCompanyAttach1::getRefugeFloorPosition,
                        BaseCompanyAttach1::getRemarks,BaseCompanyAttach1::getPlanName,BaseCompanyAttach1::getPlanUrl
                        ,BaseCompanyAttach1::getBuildNum,BaseCompanyAttach1::getSuperiorFireJurisdiction)
                        .in(BaseCompanyAttach1::getCompanyId, companyIdList);
                List<BaseCompanyAttach1> list2 = baseCompanyAttach1Service.list(queryWrapper1);
                for (int i = 0; i < list1.size(); i++) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("id", list1.get(i).getId());
                    map.put("companyName", list1.get(i).getCompanyName());
                    String companyTypeName = null;
                    if (StringUtils.isNotBlank(list1.get(i).getCompanyType())) {
                        if (list1.get(i).getCompanyType().equals("1")) {
                            companyTypeName = "重点单位";
                        } else if (list1.get(i).getCompanyType().equals("2")) {
                            companyTypeName = "一般单位";
                        } else if (list1.get(i).getCompanyType().equals("3")) {
                            companyTypeName = "九小场所";
                        } else if (list1.get(i).getCompanyType().equals("9")) {
                            companyTypeName = "其他单位";
                        }
                    }

                    map.put("companyTypeName", companyTypeName);
                    map.put("companyId", list1.get(i).getCompanyId());
                    map.put("linkPhone", list1.get(i).getLinkPhone());
                    map.put("address", list1.get(i).getAddress());
                    map.put("longitude", null);
                    map.put("latitude", null);
                    map.put("streetTown", null);
                    for (int j = 0; j < list2.size(); j++) {
                        if (list1.get(i).getCompanyId().equals(list2.get(j).getCompanyId())) {
                            String longitude = null;
                            String latitude = null;
                            if ((StringUtils.isBlank(list2.get(j).getLongitude()) && StringUtils.isNotBlank(list1.get(i).getAddress()))) {
                                List<LocateInfo> lonLat = OnlineMethod.getLonLat(list1.get(i).getAddress());
                                if (CollectionUtils.isNotEmpty(lonLat)) {
                                    if (StringUtils.isBlank(list2.get(j).getLongitude()) && StringUtils.isBlank(list2.get(j).getLatitude())) {
                                        longitude = "" + lonLat.get(0).getLongitude();
                                        latitude = "" + lonLat.get(0).getLatitude();
                                    } else {
                                        longitude = list2.get(j).getLongitude();
                                        latitude = list2.get(j).getLatitude();
                                    }
                                    String location = longitude + "," + latitude;
                                    String streetTown2 = OnlineMethod.getStreetTown(location);
                                    if (StringUtils.isBlank(list1.get(i).getStreetTown())) {
                                        streetTown = streetTown2;
                                    } else {
                                        streetTown = list1.get(i).getStreetTown();
                                    }
                                    baseCompanyService.updateCompany1(list1.get(i).getId(), list2.get(j).getId(), longitude, latitude, streetTown);
                                }
                            } else {
                                longitude = list2.get(j).getLongitude();
                                latitude = list2.get(j).getLatitude();
                                streetTown = list1.get(i).getStreetTown();
                            }
                            map.put("streetTown", streetTown);
                            map.put("longitude", longitude);
                            map.put("latitude", latitude);
                            map.put("person1", list2.get(j).getRefugeFloorPosition());
                            map.put("phone1", list2.get(j).getRemarks());
                            map.put("person2", list2.get(j).getPlanName());
                            map.put("phone2", list2.get(j).getPlanUrl());
                            map.put("person3", list2.get(j).getBuildNum());
                            map.put("phone3", list2.get(j).getSuperiorFireJurisdiction());
                        }
                    }
                    if (map.get("longitude") != null && map.get("latitude") != null && map.get("streetTown") != null) {
                        String streetTown1 = map.get("streetTown").toString();
                        if (streetTownList.contains(streetTown1)) {
                            if (StringUtils.isNotBlank(streetTown)) {
                                if (streetTown.equals(map.get("streetTown").toString())) {
                                    list10.add(map);
                                }
                            } else {
                                list10.add(map);
                            }
                        }
                    }
                }
            }
        }
        return list10;
    }

}
