package cn.gyee.tamplate.service.analysis;

import cn.gyee.tamplate.controller.ProjectController;
import cn.gyee.tamplate.init.CacheContext;
import cn.gyee.tamplate.model.auto.*;
import cn.gyee.tamplate.model.vo.*;
import cn.gyee.tamplate.service.*;
import cn.gyee.tamplate.util.ClassUtil;
import cn.gyee.tamplate.util.CopyUtils;
import cn.gyee.tamplate.util.DateUtils;
import cn.gyee.tamplate.util.DoubleUtils;
import cn.gyee.tamplate.util.common.StringUtils;
import cn.gyee.tamplate.util.golden.StringUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.apache.juli.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import sun.misc.Cache;

import javax.annotation.Resource;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @ClassName : AnalysisService
 * @Author : xieshengjie
 * @Date: 2021/3/5 8:58
 * @Description : 统计分析service
 */
@Service
public class AnalysisService {

    private Logger logger = LoggerFactory.getLogger(AnalysisService.class);
    @Resource
    private IMeterpointvalueService meterpointvalueService;
    @Resource
    private IAnalysistablebottomService analysistablebottomService;
    @Resource
    private IWindpowerinfodayService windpowerinfodayService;
    @Resource
    private IShutdownevent2Service shutdownevent2Service;
    @Resource
    private IWindpowerinfoday3Service windpowerinfoday3Service;
    @Resource
    private IInputoroutputspeedtotalService inputoroutputspeedtotalService;
    @Resource
    private IAnalysiswindprojectcannotService analysiswindprojectcannotService;
    @Resource
    private IAnalysiswindprojectcanService analysiswindprojectcanService;
    @Resource
    private IAnalysiswindstationService analysiswindstationService;
    @Resource
    private IAnalysispvprojectcanService analysispvprojectcanService;
    @Resource
    private IAnalysispvprojectcannotService analysispvprojectcannotService;
    @Resource
    private IAnalysispvstationService analysispvstationService;

    /**
     * 表底存储
     *
     * @param beginDate
     * @param endDate
     */
    public void toblebottomtask(String beginDate, String endDate) {


        List<String> days = null;
        if (StringUtils.isNotEmpty(beginDate) && StringUtils.isNotEmpty(endDate)) {
            days = DateUtils.getDays(beginDate, endDate);
        } else {
            days = new ArrayList<>();
            days.add(DateUtils.getYesterdayStr("yyyy-MM-dd"));
        }
        for (String day : days) {

            Map<String, Object> params = new HashMap<>();
            params.put("recorddate", DateUtils.parseDate(day));
            Map<String, Object> params1 = new HashMap<>();
            params1.put("theday", DateUtils.parseDate(day));
            analysistablebottomService.removeByMap(params1);
            List<Meterpointvalue> yestdayBdzList = meterpointvalueService.listByMap(params);
            yestdayBdzList.stream().forEach(i -> {
                Analysistablebottom atb = new Analysistablebottom();
                atb.setMeterid(i.getMeterid());
                atb.setTheday(i.getRecorddate());
                atb.setStopcode(i.getNow());
                atb.setStopcodemodify(i.getNow());
                atb.setDayvalue(i.getDayvalue());
                atb.setDayvaluemodify(i.getDayvalue());
                analysistablebottomService.save(atb);
            });
        }


    }

    /**
     * 风电项目存储
     *
     * @param beginDate
     * @param endDate
     * @throws Exception
     */
    public void analysiswindprojecttask(String beginDate, String endDate) throws Exception {
        List<String> days = null;

        if (StringUtils.isNotEmpty(beginDate) && StringUtils.isNotEmpty(endDate)) {
            days = DateUtils.getDays(beginDate, endDate);
        } else {
            days = new ArrayList<>();
            days.add(DateUtils.getYesterdayStr("yyyy-MM-dd"));
        }
        for (String day : days) {
            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("theday", DateUtils.parseDate(day));
            analysiswindprojectcanService.removeByMap(deleteparam);
            analysiswindprojectcannotService.removeByMap(deleteparam);
            for (Project project : CacheContext.projects) {
                if (project.getWindpowerstationid().endsWith("GDC")) {
                    continue;
                }
                logger.info(day + " " + project.getId() + "开始");
                Analysiswindprojectcannot projectcannot = new Analysiswindprojectcannot();
                Analysiswindprojectcan projectcan = new Analysiswindprojectcan();
                projectcannot.setProjectid(project.getId());
                projectcannot.setWindpowerstationid(project.getWindpowerstationid());
                projectcannot.setTheday(DateUtils.parseDate(day));
                projectcannot.setCapacity(project.getCapacity() / 10);
                projectcannot.setAveragegenecapacity(project.getCapacity() / 10);
                projectcannot.setInstalledunits(project.getQuantity());


                Map<String, Object> params = new HashMap<>();
                params.put("recorddate", DateUtils.parseDate(day));
                params.put("foreignkeyid", project.getId());
                List<Windpowerinfoday> windpowerinfodays = windpowerinfodayService.listByMap(params);
                Map<String, Object> wind3 = new HashMap<>();
                wind3.put("recorddate", DateUtils.parseDate(day));
                wind3.put("foreignkeyid", project.getId());
                List<Windpowerinfoday3> windpowerinfoday3s = windpowerinfoday3Service.listByMap(wind3);
                Map<String, Object> shutparams = new HashMap<>();
                shutparams.put("stoptime", DateUtils.parseDate(day));
                shutparams.put("projectid", project.getId());
                //shutparams.put("statuscode",4);
                List<Shutdownevent2> shutdownevent2s = shutdownevent2Service.listByMap(shutparams);

                Map<String, Object> inputparam = new HashMap<>();
                inputparam.put("recorddate", DateUtils.parseDate(day));
                inputparam.put("projectid", project.getId());
                List<Inputoroutputspeedtotal> inputoroutputspeedtotals = inputoroutputspeedtotalService.listByMap(inputparam);
                if (StringUtils.isNotEmpty(inputoroutputspeedtotals)) {
                    OptionalDouble average = inputoroutputspeedtotals.stream().filter(i -> i.getDayinputsmall() != null).mapToDouble(Inputoroutputspeedtotal::getDayinputsmall).average();
                    if (average.isPresent()) {
                        projectcannot.setAvecutspeed(average.getAsDouble());
                    } else {
                        projectcannot.setAvecutspeed(0.0);
                    }


                }

                if (StringUtils.isNotEmpty(windpowerinfodays)) {
                    Windpowerinfoday windpowerinfoday = windpowerinfodays.get(0);
                    projectcannot.setMaxpower(windpowerinfoday.getMaxpower() / 10);
                    projectcannot.setMinpower(windpowerinfoday.getMinpower() / 10);
                    projectcannot.setMainstoptimes(windpowerinfoday.getMaintaintime());
                    projectcannot.setEquipmaintime(windpowerinfoday.getMaintaintime());
                    projectcannot.setEquipfaulttimes(windpowerinfoday.getFaulttime());
                    projectcannot.setRuntime(windpowerinfoday.getRuntime());
                    projectcannot.setGeneratingcapacityscada(windpowerinfoday.getGeneratingcapacity());
                    projectcannot.setGeneratingcapacity(windpowerinfoday.getGeneratingcapacity2());
                    projectcannot.setGridgeneratingcapacity(windpowerinfoday.getGridelectricity());
                    projectcannot.setGwelectricitypurchase(windpowerinfoday.getBuyelectricity());
                    projectcannot.setNwelectricitypurchase(windpowerinfoday.getBuyagricultureelectricity());
                    projectcannot.setAvespeed(windpowerinfoday.getSpeed());
                    projectcannot.setAvepower(windpowerinfoday.getPower());
                    projectcannot.setStationofgenerating(windpowerinfoday.getFieldelectricity());
                    //projectcannot.setAvecutspeed();
                }
                if (StringUtils.isNotEmpty(windpowerinfoday3s)) {
                    Windpowerinfoday3 windpowerinfoday3 = windpowerinfoday3s.get(0);
                    projectcannot.setDaynhqfdl(windpowerinfoday3.getDaynhqfdl() / 10000);
                    projectcannot.setDaynhxdssdl(windpowerinfoday3.getDaynhxdssdl() / 10000);
                    projectcannot.setDaynhgzssdl(windpowerinfoday3.getDaynhgzssdl() / 10000);
                    projectcannot.setDaynhwhssdl(windpowerinfoday3.getDaynhwhssdl() / 10000);
                    projectcannot.setDaynhcfdl(windpowerinfoday3.getDaynhcfdl() / 10000);

                }
                if (StringUtils.isNotEmpty(shutdownevent2s)) {
                    projectcannot.setMainstopcount(shutdownevent2s.stream().filter(i -> i.getStatuscode() == 4).collect(Collectors.toList()).size());
                    projectcannot.setUnmainstopcount(shutdownevent2s.stream().filter(i -> i.getStatuscode() == 5).collect(Collectors.toList()).size());
                    projectcannot.setWtfaultcount(shutdownevent2s.stream().filter(i -> i.getStatuscode() == 2).collect(Collectors.toList()).size());
                    projectcannot.setEquipfaultcount(shutdownevent2s.size());
                }
                projectcannot.setThegenerating(projectcannot.getGeneratingcapacity() + projectcannot.getDaynhgzssdl() + projectcannot.getDaynhwhssdl() + projectcannot.getDaynhxdssdl() + projectcannot.getDaynhqfdl() + projectcannot.getDaynhcfdl());
                projectcannot.setThegeneratingscada(projectcannot.getGeneratingcapacityscada() + projectcannot.getDaynhgzssdl() + projectcannot.getDaynhwhssdl() + projectcannot.getDaynhxdssdl() + projectcannot.getDaynhqfdl() + projectcannot.getDaynhcfdl());

                projectcannot.setTryrungenerating(0.0);
                projectcannot.setTryrungridgenerating(0.0);
                projectcannot.setEndcapactiy(0.0);
                projectcannot.setStandbyhour(0.0);
                projectcannot.setTerminalputforth(0.0);
                projectcannot.setNewcapactiy(0.0);
                projectcannot.setGridtariff(0.0);
                projectcannot.setWithinbase(0.0);
                projectcannot.setReplacedsales(0.0);
                projectcannot.setUnivalent(0.0);
                projectcannot.setOnehindercount(0.0);
                projectcannot.setSyzfaultloss(0.0);
                projectcannot.setSyzmainloss(0.0);
                projectcannot.setAveragespeed(0.0);
                projectcannot.setAveairdensity(0.0);
                projectcannot.setSyzmainstoptime(0.0);
                projectcannot.setFaulthandletime(0.0);
                projectcannot.setSyzfaultstoptime(0.0);
                projectcannot.setUnplanoutagetime(0.0);
                projectcannot.setUnitstartuptimes(0.0);
                projectcannot.setUnitstoptimes(0.0);
                projectcannot.setStationinstoptime(0.0);
                projectcannot.setStaitoninmainstoptime(0.0);

                projectcannot.setStationoutstoptime(0.0);
                projectcannot.setEliminationrate(0.0);
                projectcannot.setDaynhxdsj(0.0);
                projectcannot.setGridfaultstoptime(0.0);
                projectcannot.setGridmainstoptime(0.0);
                projectcannot.setGridmainssdl(0.0);
                projectcannot.setGridfaultssdl(0.0);
                projectcannot.setStationpower(0.0);
                projectcannot.setStationrate(0.0);
                projectcannot.setAqts(1.0);
                projectcannot.setCalendarhours(24.0);
                projectcannot.setPlangenerating(0.0);
                //风机故障停运时间+升压站故障停运时间+电网故障影响停运时间target21089,+,target25046,+,target25078
                projectcannot.setStoptime(projectcannot.getEquipfaulttimes() + projectcannot.getSyzfaultstoptime() + projectcannot.getGridfaultstoptime());
                projectcannot.setBuygenerating(projectcannot.getGwelectricitypurchase() + projectcannot.getNwelectricitypurchase());
                projectcannot.setLossgenerating(projectcannot.getDaynhgzssdl() + projectcannot.getDaynhwhssdl() + projectcannot.getDaynhxdssdl() + projectcannot.getDaynhqfdl() + projectcannot.getDaynhcfdl());
                projectcannot.setMultiplegenerating(projectcannot.getGeneratingcapacity() + projectcannot.getBuygenerating() - projectcannot.getGridgeneratingcapacity());
                projectcannot.setMultiplerate(projectcannot.getGeneratingcapacity()!=0.0?projectcannot.getMultiplegenerating() / projectcannot.getGeneratingcapacity() * 100:0.0);
                projectcannot.setMultiplegeneratingscada(projectcannot.getGeneratingcapacityscada() + projectcannot.getBuygenerating() - projectcannot.getGridgeneratingcapacity());
                projectcannot.setMultipleratescada(projectcannot.getGeneratingcapacityscada()!=0.0?projectcannot.getMultiplegeneratingscada() / projectcannot.getGeneratingcapacityscada()*100:0.0);
                //target21032,/,target21105
                projectcannot.setAveutilizationhour(projectcannot.getGeneratingcapacity() / projectcannot.getCapacity());
                projectcannot.setAveutilizationhourscada(projectcannot.getGeneratingcapacityscada() / projectcannot.getCapacity());
                //(,target26002,*,target21111,-,target21088,),/,target21111
                projectcannot.setNofaulthours((projectcannot.getCalendarhours() * projectcannot.getInstalledunits() - projectcannot.getEquipfaulttimes()) / projectcannot.getInstalledunits());
                //(,target21112,*,target26002,-,target21116,-,target21117,),/,target21112
                projectcannot.setAdjustablehour((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipfaulttimes() - projectcannot.getEquipmaintime()) / projectcannot.getInstalledunits());
                //(,target21112,*,target26002,-,target21117,-,target21089,),/,target21112
                projectcannot.setEffectivehour((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipmaintime() - projectcannot.getEquipfaulttimes()) / projectcannot.getInstalledunits());
                //(,target21112,*,target26002,-,target21116,-,target21117,),/,(,target21112,*,target26002,),*,100
                projectcannot.setEquivalent((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipfaulttimes() - projectcannot.getEquipmaintime()) / (projectcannot.getInstalledunits() * projectcannot.getCalendarhours()) * 100);
                projectcannot.setLoadrate(projectcannot.getMaxpower()!=0.0?projectcannot.getAvepower() / projectcannot.getMaxpower() * 100:0.0);
                projectcannot.setMainlossrate(projectcannot.getThegenerating()!=0.0?projectcannot.getDaynhwhssdl() / projectcannot.getThegenerating() * 100:0.0);
                projectcannot.setFaultlossrate(projectcannot.getThegeneratingscada() !=0.0?projectcannot.getDaynhgzssdl() / projectcannot.getThegeneratingscada() * 100:0.0);
                //(,target21112,*,target26002,-,target21116,),/,(,target21112,*,target26002,),*,100
                projectcannot.setEquipavailability((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipfaulttimes()) / (projectcannot.getInstalledunits() * projectcannot.getCalendarhours()) * 100);
                //target21052,+,target25020,+,target25090
                projectcannot.setFaultloss(projectcannot.getDaynhgzssdl() + projectcannot.getSyzfaultloss() + projectcannot.getGridfaultssdl());
                //target21060,+,target25020,+,target25086
                projectcannot.setMainloss(projectcannot.getDaynhwhssdl() + projectcannot.getSyzmainloss() + projectcannot.getGridmainssdl());
                //target25042,/,target21112
                projectcannot.setAvefaulttime(projectcannot.getFaulthandletime() / projectcannot.getInstalledunits());
                //target21081,+,target25041,+,target25082
                projectcannot.setMainstoptime(projectcannot.getMainstoptimes() + projectcannot.getSyzmainstoptime() + projectcannot.getGridmainstoptime());
                //target21116,/,target21112
                projectcannot.setEquipfaultavestoptime(projectcannot.getEquipfaulttimes() / projectcannot.getInstalledunits());
                projectcannot.setWtfaultavestoptimeedit(projectcannot.getEquipfaulttimes() / projectcannot.getInstalledunits());
                projectcannot.setSyzfaultavestoptime(projectcannot.getSyzfaultstoptime() / projectcannot.getInstalledunits());
                projectcannot.setPowergridfaultavestoptime(projectcannot.getGridfaultstoptime() / projectcannot.getInstalledunits());
                projectcannot.setMainavestoptime(projectcannot.getMainstoptime() / projectcannot.getInstalledunits());
                projectcannot.setFjdjmainavestoptime(projectcannot.getEquipmaintime() / projectcannot.getInstalledunits());
                projectcannot.setSyzmainavestoptime(projectcannot.getSyzmainstoptime() / projectcannot.getInstalledunits());
                projectcannot.setPowergridmainavestoptime(projectcannot.getGridmainstoptime() / projectcannot.getInstalledunits());
                projectcannot.setAveruntime(projectcannot.getRuntime() / projectcannot.getInstalledunits());
                CopyUtils.copy(projectcannot, projectcan);
                analysiswindprojectcannotService.save(projectcannot);
                analysiswindprojectcanService.save(projectcan);
            }


        }
    }

    /**
     * 光伏项目存储
     *
     * @param beginDate
     * @param endDate
     * @throws Exception
     */
    public void analysispvprojecttask(String beginDate, String endDate) throws Exception {
        List<String> days = null;

        if (StringUtils.isNotEmpty(beginDate) && StringUtils.isNotEmpty(endDate)) {
            days = DateUtils.getDays(beginDate, endDate);
        } else {
            days = new ArrayList<>();
            days.add(DateUtils.getYesterdayStr("yyyy-MM-dd"));
        }
        for (String day : days) {
            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("theday", DateUtils.parseDate(day));
            analysispvprojectcanService.removeByMap(deleteparam);
            analysispvprojectcannotService.removeByMap(deleteparam);
            for (Project project : CacheContext.projects) {
                if (project.getWindpowerstationid().endsWith("FDC")) {
                    continue;
                }
                logger.info(day + " " + project.getId() + "开始");
                Analysispvprojectcannot projectcannot = new Analysispvprojectcannot();
                Analysispvprojectcan projectcan = new Analysispvprojectcan();
                projectcannot.setProjectid(project.getId());
                projectcannot.setWindpowerstationid(project.getWindpowerstationid());
                projectcannot.setTheday(DateUtils.parseDate(day));
                projectcannot.setCapacity(project.getCapacity() / 10);
                projectcannot.setInstalledunits(project.getQuantity());


                Map<String, Object> params = new HashMap<>();
                params.put("recorddate", DateUtils.parseDate(day));
                params.put("foreignkeyid", project.getId());
                List<Windpowerinfoday> windpowerinfodays = windpowerinfodayService.listByMap(params);
                Map<String, Object> wind3 = new HashMap<>();
                wind3.put("recorddate", DateUtils.parseDate(day));
                wind3.put("foreignkeyid", project.getId());
                List<Windpowerinfoday3> windpowerinfoday3s = windpowerinfoday3Service.listByMap(wind3);
                Map<String, Object> shutparams = new HashMap<>();
                shutparams.put("stoptime", DateUtils.parseDate(day));
                shutparams.put("projectid", project.getId());
                //shutparams.put("statuscode",4);
                List<Shutdownevent2> shutdownevent2s = shutdownevent2Service.listByMap(shutparams);

                Map<String, Object> inputparam = new HashMap<>();
                inputparam.put("recorddate", DateUtils.parseDate(day));
                inputparam.put("projectid", project.getId());
                List<Inputoroutputspeedtotal> inputoroutputspeedtotals = inputoroutputspeedtotalService.listByMap(inputparam);


                if (StringUtils.isNotEmpty(windpowerinfoday3s)) {
                    Windpowerinfoday3 windpowerinfoday3 = windpowerinfoday3s.get(0);
                    projectcannot.setDaynhxdssdl(windpowerinfoday3.getDaynhxdssdl() / 10000);
                    projectcannot.setDaynhgzssdl(windpowerinfoday3.getDaynhgzssdl() / 10000);
                    projectcannot.setDaynhwhssdl(windpowerinfoday3.getDaynhwhssdl() / 10000);
                    projectcannot.setDaynhcfdl(windpowerinfoday3.getDaynhcfdl() / 10000);
                    projectcannot.setEquipwhssdl(windpowerinfoday3.getDaynhwhssdl() / 10000);
                    projectcannot.setEquipfaultloss(windpowerinfoday3.getDaynhgzssdl() / 10000);
                } else {
                    projectcannot.setDaynhxdssdl(0.0);
                    projectcannot.setDaynhgzssdl(0.0);
                    projectcannot.setDaynhwhssdl(0.0);
                    projectcannot.setDaynhcfdl(0.0);
                    projectcannot.setEquipwhssdl(0.0);
                    projectcannot.setEquipfaultloss(0.0);
                }

                if (StringUtils.isNotEmpty(windpowerinfodays)) {
                    Windpowerinfoday windpowerinfoday = windpowerinfodays.get(0);
                    projectcannot.setMinoutput(windpowerinfoday.getMinpower() / 10);
                    projectcannot.setEquipmaintime(windpowerinfoday.getMaintaintime());
                    projectcannot.setEquipfaultstoptime(windpowerinfoday.getFaulttime());
                    projectcannot.setGeneratingcapacityscada(windpowerinfoday.getGeneratingcapacity());
                    projectcannot.setGeneratingcapacity(windpowerinfoday.getGeneratingcapacity2());
                    projectcannot.setGridgeneratingcapacity(windpowerinfoday.getGridelectricity());
                    projectcannot.setGwbuygeneratingcapacity(windpowerinfoday.getBuyelectricity());
                    projectcannot.setNwbuygeneratingcapacity(windpowerinfoday.getBuyagricultureelectricity());
                    projectcannot.setAvepower(windpowerinfoday.getPower());
                    projectcannot.setStationofgenerating(windpowerinfoday.getFieldelectricity());
                    projectcannot.setMaxlight(windpowerinfoday.getMaxspeed());
                    //projectcannot.setAvecutspeed();
                }

                projectcannot.setAccidentcount(0.0);
                projectcannot.setAccidentsituation("");
                projectcannot.setSyzfaultloss(0.0);
                projectcannot.setRainandsnow(0.0);
                projectcannot.setStationinmainloss(0.0);
                projectcannot.setStationinfaultloss(0.0);
                projectcannot.setStationoutfaultloss(0.0);
                projectcannot.setStationinstoptime(0.0);
                projectcannot.setEquipmainstoptime(0.0);
                projectcannot.setStationinmainstoptime(0.0);
                projectcannot.setStaitonoutstoptime(0.0);
                projectcannot.setTotalradiation(0.0);
                projectcannot.setSunshinehours(0.0);
                projectcannot.setSunnyday(0.0);
                projectcannot.setSunnyovercast(0.0);
                projectcannot.setDaynhxdsj(0.0);
                projectcannot.setGridmainssdl(0.0);
                projectcannot.setGridfaultssdl(0.0);

                projectcannot.setAqts(1.0);
                projectcannot.setCalendarhours(24.0);
                projectcannot.setPlangenerating(0.0);
                //风机故障停运时间+升压站故障停运时间+电网故障影响停运时间target21089,+,target25046,+,target25078
                projectcannot.setBuygenerating(projectcannot.getGwbuygeneratingcapacity() + projectcannot.getNwbuygeneratingcapacity());
                projectcannot.setLossgenerating(projectcannot.getDaynhgzssdl() + projectcannot.getDaynhwhssdl() + projectcannot.getDaynhxdssdl() + projectcannot.getDaynhcfdl());
                projectcannot.setMultiplegenerating(projectcannot.getGeneratingcapacity() + projectcannot.getBuygenerating() - projectcannot.getGridgeneratingcapacity());
                projectcannot.setMultiplerate(projectcannot.getGeneratingcapacity() != 0 ? projectcannot.getMultiplegenerating() / projectcannot.getGeneratingcapacity() * 100 : 0.0);
                projectcannot.setMultiplegeneratingscada(projectcannot.getGeneratingcapacityscada() + projectcannot.getBuygenerating() - projectcannot.getGridgeneratingcapacity());
                //target21032,/,target21105
                projectcannot.setEquiputilhour(projectcannot.getGeneratingcapacity() / projectcannot.getCapacity());

                projectcannot.setEquivalent((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipfaultstoptime() - projectcannot.getEquipmaintime()) / (projectcannot.getInstalledunits() * projectcannot.getCalendarhours()) * 100);
                projectcannot.setMainlossrate(projectcannot.getGeneratingcapacity() != 0 ? projectcannot.getDaynhwhssdl() / projectcannot.getGeneratingcapacity() * 100 : 0.0);
                projectcannot.setFaultlossrate(projectcannot.getGeneratingcapacity() != 0 ? projectcannot.getDaynhgzssdl() / projectcannot.getGeneratingcapacity() * 100 : 0.0);
                //(,target21112,*,target26002,-,target21116,),/,(,target21112,*,target26002,),*,100
                projectcannot.setEquipavailability((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipfaultstoptime()) / (projectcannot.getInstalledunits() * projectcannot.getCalendarhours()) * 100);
                //target21052,+,target25020,+,target25090
                projectcannot.setFaultloss(projectcannot.getDaynhgzssdl() + projectcannot.getSyzfaultloss() + projectcannot.getGridfaultssdl());
                //target21060,+,target25020,+,target25086
                projectcannot.setMainloss(projectcannot.getDaynhwhssdl() + projectcannot.getGridmainssdl());


                projectcannot.setStationofrate(projectcannot.getGeneratingcapacity() != 0 ? projectcannot.getStationofgenerating() / projectcannot.getGeneratingcapacity() * 100 : 0.0);
                CopyUtils.copy(projectcannot, projectcan);
                analysispvprojectcannotService.save(projectcannot);
                analysispvprojectcanService.save(projectcan);
            }


        }
    }

    /**
     * 风电场站存储
     *
     * @param beginDate
     * @param endDate
     */
    public void analysiswindstationtask(String beginDate, String endDate) {
        List<String> days = null;
        if (StringUtils.isNotEmpty(beginDate) && StringUtils.isNotEmpty(endDate)) {
            days = DateUtils.getDays(beginDate, endDate);
        } else {
            days = new ArrayList<>();
            days.add(DateUtils.getYesterdayStr("yyyy-MM-dd"));
        }
        for (String day : days) {
            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("theday", DateUtils.parseDate(day));
            analysiswindstationService.removeByMap(deleteparam);
            for (Windpowerstation wp : CacheContext.stations) {
                if (wp.getId().endsWith("GDC")) {
                    continue;
                }
                Analysiswindstation station = new Analysiswindstation();
                station.setWindpowerstationid(wp.getId());
                station.setTheday(DateUtils.parseDate(day));

                Map<String, Object> params = new HashMap<>();
                params.put("theday", DateUtils.parseDate(day));
                params.put("windpowerstationid", wp.getId());
                List<Analysiswindprojectcan> prodatas = analysiswindprojectcanService.listByMap(params);

                station.setMaxpower(prodatas.stream().map(Analysiswindprojectcan::getMaxpower).reduce(DoubleUtils::max).get());
                station.setMinpower(prodatas.stream().map(Analysiswindprojectcan::getMaxpower).reduce(DoubleUtils::min).get());
                station.setMainstopcount(prodatas.stream().map(Analysiswindprojectcan::getMainstopcount).reduce(DoubleUtils::sum).get());
                station.setMainstoptimes(prodatas.stream().map(Analysiswindprojectcan::getMainstoptimes).reduce(DoubleUtils::sum).get());

                station.setEquipmaintime(prodatas.stream().map(Analysiswindprojectcan::getEquipmaintime).reduce(DoubleUtils::sum).get());
                station.setUnmainstopcount(prodatas.stream().map(Analysiswindprojectcan::getUnmainstopcount).reduce(DoubleUtils::sum).get());
                station.setWtfaultcount(prodatas.stream().map(Analysiswindprojectcan::getWtfaultcount).reduce(DoubleUtils::sum).get());
                station.setEquipfaultcount(prodatas.stream().map(Analysiswindprojectcan::getEquipfaultcount).reduce(DoubleUtils::sum).get());
                station.setEquipfaulttimes(prodatas.stream().map(Analysiswindprojectcan::getEquipfaulttimes).reduce(DoubleUtils::sum).get());
                station.setRuntime(prodatas.stream().map(Analysiswindprojectcan::getRuntime).reduce(DoubleUtils::sum).get());
                station.setDaynhgzssdl(prodatas.stream().map(Analysiswindprojectcan::getDaynhgzssdl).reduce(DoubleUtils::sum).get());
                station.setDaynhwhssdl(prodatas.stream().map(Analysiswindprojectcan::getDaynhwhssdl).reduce(DoubleUtils::sum).get());
                station.setDaynhxdssdl(prodatas.stream().map(Analysiswindprojectcan::getDaynhxdssdl).reduce(DoubleUtils::sum).get());
                station.setDaynhqfdl(prodatas.stream().map(Analysiswindprojectcan::getDaynhqfdl).reduce(DoubleUtils::sum).get());
                station.setDaynhcfdl(prodatas.stream().map(Analysiswindprojectcan::getDaynhcfdl).reduce(DoubleUtils::sum).get());
                station.setGeneratingcapacity(prodatas.stream().map(Analysiswindprojectcan::getGeneratingcapacity).reduce(DoubleUtils::sum).get());
                station.setGeneratingcapacityscada(prodatas.stream().map(Analysiswindprojectcan::getGeneratingcapacityscada).reduce(DoubleUtils::sum).get());
                station.setGridgeneratingcapacity(prodatas.stream().map(Analysiswindprojectcan::getGridgeneratingcapacity).reduce(DoubleUtils::sum).get());
                station.setGwelectricitypurchase(prodatas.stream().map(Analysiswindprojectcan::getGwelectricitypurchase).reduce(DoubleUtils::sum).get());
                station.setNwelectricitypurchase(prodatas.stream().map(Analysiswindprojectcan::getNwelectricitypurchase).reduce(DoubleUtils::sum).get());
                station.setAvecutspeed(prodatas.stream().map(Analysiswindprojectcan::getAvecutspeed).reduce(DoubleUtils::ave).get());
                station.setAvespeed(prodatas.stream().map(Analysiswindprojectcan::getAvespeed).reduce(DoubleUtils::ave).get());
                station.setCapacity(prodatas.stream().map(Analysiswindprojectcan::getCapacity).reduce(DoubleUtils::sum).get());
                station.setAveragegenecapacity(prodatas.stream().map(Analysiswindprojectcan::getAveragegenecapacity).reduce(DoubleUtils::sum).get());
                station.setInstalledunits(prodatas.stream().map(Analysiswindprojectcan::getInstalledunits).reduce(DoubleUtils::sum).get());
                station.setThegenerating(prodatas.stream().map(Analysiswindprojectcan::getThegenerating).reduce(DoubleUtils::sum).get());
                station.setThegeneratingscada(prodatas.stream().map(Analysiswindprojectcan::getThegeneratingscada).reduce(DoubleUtils::sum).get());
                station.setAvepower(prodatas.stream().map(Analysiswindprojectcan::getAvepower).reduce(DoubleUtils::ave).get());
                station.setStationofgenerating(prodatas.stream().map(Analysiswindprojectcan::getStationofgenerating).reduce(DoubleUtils::sum).get());
                station.setStoptime(prodatas.stream().map(Analysiswindprojectcan::getStoptime).reduce(DoubleUtils::sum).get());
                station.setBuygenerating(prodatas.stream().map(Analysiswindprojectcan::getBuygenerating).reduce(DoubleUtils::sum).get());
                station.setLossgenerating(prodatas.stream().map(Analysiswindprojectcan::getLossgenerating).reduce(DoubleUtils::sum).get());
                station.setMultiplegenerating(prodatas.stream().map(Analysiswindprojectcan::getMultiplegenerating).reduce(DoubleUtils::sum).get());
                station.setMultiplegeneratingscada(prodatas.stream().map(Analysiswindprojectcan::getMultiplegeneratingscada).reduce(DoubleUtils::sum).get());
                station.setTryrungenerating(prodatas.stream().map(Analysiswindprojectcan::getTryrungenerating).reduce(DoubleUtils::sum).get());
                station.setTryrungridgenerating(prodatas.stream().map(Analysiswindprojectcan::getTryrungridgenerating).reduce(DoubleUtils::sum).get());
                station.setEndcapactiy(prodatas.stream().map(Analysiswindprojectcan::getEndcapactiy).reduce(DoubleUtils::sum).get());
                station.setStandbyhour(prodatas.stream().map(Analysiswindprojectcan::getStandbyhour).reduce(DoubleUtils::sum).get());
                station.setTerminalputforth(prodatas.stream().map(Analysiswindprojectcan::getTerminalputforth).reduce(DoubleUtils::sum).get());
                station.setNewcapactiy(prodatas.stream().map(Analysiswindprojectcan::getNewcapactiy).reduce(DoubleUtils::sum).get());
                station.setGridtariff(prodatas.stream().map(Analysiswindprojectcan::getGridtariff).reduce(DoubleUtils::sum).get());
                station.setWithinbase(prodatas.stream().map(Analysiswindprojectcan::getWithinbase).reduce(DoubleUtils::sum).get());
                station.setReplacedsales(prodatas.stream().map(Analysiswindprojectcan::getReplacedsales).reduce(DoubleUtils::sum).get());
                station.setUnivalent(prodatas.stream().map(Analysiswindprojectcan::getUnivalent).reduce(DoubleUtils::sum).get());
                station.setOnehindercount(prodatas.stream().map(Analysiswindprojectcan::getOnehindercount).reduce(DoubleUtils::sum).get());
                station.setSyzfaultloss(prodatas.stream().map(Analysiswindprojectcan::getSyzfaultloss).reduce(DoubleUtils::sum).get());
                station.setSyzmainloss(prodatas.stream().map(Analysiswindprojectcan::getSyzmainloss).reduce(DoubleUtils::sum).get());
                station.setAveragespeed(prodatas.stream().map(Analysiswindprojectcan::getAveragespeed).reduce(DoubleUtils::ave).get());
                station.setAveairdensity(prodatas.stream().map(Analysiswindprojectcan::getAveairdensity).reduce(DoubleUtils::ave).get());
                station.setSyzmainstoptime(prodatas.stream().map(Analysiswindprojectcan::getSyzmainstoptime).reduce(DoubleUtils::sum).get());
                station.setFaulthandletime(prodatas.stream().map(Analysiswindprojectcan::getFaulthandletime).reduce(DoubleUtils::sum).get());
                station.setSyzfaultstoptime(prodatas.stream().map(Analysiswindprojectcan::getSyzfaultstoptime).reduce(DoubleUtils::sum).get());
                station.setUnplanoutagetime(prodatas.stream().map(Analysiswindprojectcan::getUnplanoutagetime).reduce(DoubleUtils::sum).get());
                station.setUnitstartuptimes(prodatas.stream().map(Analysiswindprojectcan::getUnitstartuptimes).reduce(DoubleUtils::sum).get());
                station.setUnitstoptimes(prodatas.stream().map(Analysiswindprojectcan::getUnitstoptimes).reduce(DoubleUtils::sum).get());
                station.setStationinstoptime(prodatas.stream().map(Analysiswindprojectcan::getStationinstoptime).reduce(DoubleUtils::sum).get());
                station.setStaitoninmainstoptime(prodatas.stream().map(Analysiswindprojectcan::getStaitoninmainstoptime).reduce(DoubleUtils::sum).get());
                station.setStationoutstoptime(prodatas.stream().map(Analysiswindprojectcan::getStationoutstoptime).reduce(DoubleUtils::sum).get());
                station.setEliminationrate(prodatas.stream().map(Analysiswindprojectcan::getEliminationrate).reduce(DoubleUtils::ave).get());
                station.setDaynhxdsj(prodatas.stream().map(Analysiswindprojectcan::getDaynhxdsj).reduce(DoubleUtils::sum).get());
                station.setGridfaultstoptime(prodatas.stream().map(Analysiswindprojectcan::getGridfaultstoptime).reduce(DoubleUtils::sum).get());
                station.setGridmainstoptime(prodatas.stream().map(Analysiswindprojectcan::getGridmainstoptime).reduce(DoubleUtils::sum).get());
                station.setGridmainssdl(prodatas.stream().map(Analysiswindprojectcan::getGridmainssdl).reduce(DoubleUtils::sum).get());
                station.setGridfaultssdl(prodatas.stream().map(Analysiswindprojectcan::getGridfaultssdl).reduce(DoubleUtils::sum).get());
                station.setStationpower(prodatas.stream().map(Analysiswindprojectcan::getStationpower).reduce(DoubleUtils::sum).get());
                station.setStationrate(prodatas.stream().map(Analysiswindprojectcan::getStationrate).reduce(DoubleUtils::ave).get());
                station.setPlangenerating(prodatas.stream().map(Analysiswindprojectcan::getPlangenerating).reduce(DoubleUtils::sum).get());
                station.setAqts(1.0);
                station.setCalendarhours(24.0);
                station.setPlangenerating(0.0);
                station.setMultiplerate(station.getGeneratingcapacity() !=0.0?station.getMultiplegenerating() / station.getGeneratingcapacity() * 100:0.0);
                station.setMultipleratescada(station.getGeneratingcapacityscada()!=0.0?station.getMultiplegeneratingscada() / station.getGeneratingcapacityscada()*100:0.0);
                station.setAveutilizationhour(station.getGeneratingcapacity() / station.getCapacity());
                station.setAveutilizationhourscada(station.getGeneratingcapacityscada() / station.getCapacity());
                station.setNofaulthours((station.getCalendarhours() * station.getInstalledunits() - station.getEquipfaulttimes()) / station.getInstalledunits());
                station.setAdjustablehour((station.getInstalledunits() * station.getCalendarhours() - station.getEquipfaulttimes() - station.getEquipmaintime()) / station.getInstalledunits());
                //(,target21112,*,target26002,-,target21117,-,target21089,),/,target21112
                station.setEffectivehour((station.getInstalledunits() * station.getCalendarhours() - station.getEquipmaintime() - station.getEquipfaulttimes()) / station.getInstalledunits());
                //(,target21112,*,target26002,-,target21116,-,target21117,),/,(,target21112,*,target26002,),*,100
                station.setEquivalent((station.getInstalledunits() * station.getCalendarhours() - station.getEquipfaulttimes() - station.getEquipmaintime()) / (station.getInstalledunits() * station.getCalendarhours()) * 100);
                station.setLoadrate(station.getMaxpower()!=0.0?station.getAvepower() / station.getMaxpower() * 100:0.0);
                station.setMainlossrate(station.getThegenerating() !=0.0?station.getDaynhwhssdl() / station.getThegenerating() * 100:0.0);
                station.setFaultlossrate(station.getThegeneratingscada()!=0.0?station.getDaynhgzssdl() / station.getThegeneratingscada() * 100:0.0);
                //(,target21112,*,target26002,-,target21116,),/,(,target21112,*,target26002,),*,100
                station.setEquipavailability((station.getInstalledunits() * station.getCalendarhours() - station.getEquipfaulttimes()) / (station.getInstalledunits() * station.getCalendarhours()) * 100);
                //target21052,+,target25020,+,target25090
                station.setFaultloss(station.getDaynhgzssdl() + station.getSyzfaultloss() + station.getGridfaultssdl());
                //target21060,+,target25020,+,target25086
                station.setMainloss(station.getDaynhwhssdl() + station.getSyzmainloss() + station.getGridmainssdl());
                //target25042,/,target21112
                station.setAvefaulttime(station.getFaulthandletime() / station.getInstalledunits());
                //target21081,+,target25041,+,target25082
                station.setMainstoptime(station.getMainstoptimes() + station.getSyzmainstoptime() + station.getGridmainstoptime());
                //target21116,/,target21112
                station.setEquipfaultavestoptime(station.getEquipfaulttimes() / station.getInstalledunits());
                station.setWtfaultavestoptimeedit(station.getEquipfaulttimes() / station.getInstalledunits());
                station.setSyzfaultavestoptime(station.getSyzfaultstoptime() / station.getInstalledunits());
                station.setPowergridfaultavestoptime(station.getGridfaultstoptime() / station.getInstalledunits());
                station.setMainavestoptime(station.getMainstoptime() / station.getInstalledunits());
                station.setFjdjmainavestoptime(station.getEquipmaintime() / station.getInstalledunits());
                station.setSyzmainavestoptime(station.getSyzmainstoptime() / station.getInstalledunits());
                station.setPowergridmainavestoptime(station.getGridmainstoptime() / station.getInstalledunits());
                station.setAveruntime(station.getRuntime() / station.getInstalledunits());
                station.setIscommit(0);

                analysiswindstationService.save(station);


            }
        }
    }


    /**
     * 光伏场站存储
     *
     * @param beginDate
     * @param endDate
     */
    public void analysispvstationtask(String beginDate, String endDate) {
        List<String> days = null;
        if (StringUtils.isNotEmpty(beginDate) && StringUtils.isNotEmpty(endDate)) {
            days = DateUtils.getDays(beginDate, endDate);
        } else {
            days = new ArrayList<>();
            days.add(DateUtils.getYesterdayStr("yyyy-MM-dd"));
        }
        for (String day : days) {
            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("theday", DateUtils.parseDate(day));
            analysispvstationService.removeByMap(deleteparam);
            for (Windpowerstation wp : CacheContext.stations) {
                if (wp.getId().endsWith("FDC")) {
                    continue;
                }
                Analysispvstation station = new Analysispvstation();
                station.setWindpowerstationid(wp.getId());
                station.setTheday(DateUtils.parseDate(day));

                Map<String, Object> params = new HashMap<>();
                params.put("theday", DateUtils.parseDate(day));
                params.put("windpowerstationid", wp.getId());
                List<Analysispvprojectcan> prodatas = analysispvprojectcanService.listByMap(params);
                Optional<Double> daynhxdssdl = prodatas.stream().map(Analysispvprojectcan::getDaynhxdssdl).reduce(DoubleUtils::sum);
                station.setDaynhxdssdl(daynhxdssdl.isPresent() ? daynhxdssdl.get() : 0.0);

                station.setGeneratingcapacity(prodatas.stream().map(Analysispvprojectcan::getGeneratingcapacity).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getGeneratingcapacity).reduce(DoubleUtils::sum).get() : 0.0);
                station.setGwbuygeneratingcapacity(prodatas.stream().map(Analysispvprojectcan::getGwbuygeneratingcapacity).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getGwbuygeneratingcapacity).reduce(DoubleUtils::sum).get() : 0.0);
                station.setNwbuygeneratingcapacity(prodatas.stream().map(Analysispvprojectcan::getNwbuygeneratingcapacity).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getNwbuygeneratingcapacity).reduce(DoubleUtils::sum).get() : 0.0);
                station.setGridgeneratingcapacity(prodatas.stream().map(Analysispvprojectcan::getGridgeneratingcapacity).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getGridgeneratingcapacity).reduce(DoubleUtils::sum).get() : 0.0);
                station.setDaynhgzssdl(prodatas.stream().map(Analysispvprojectcan::getDaynhgzssdl).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getDaynhgzssdl).reduce(DoubleUtils::sum).get() : 0.0);
                station.setDaynhwhssdl(prodatas.stream().map(Analysispvprojectcan::getDaynhwhssdl).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getDaynhwhssdl).reduce(DoubleUtils::sum).get() : 0.0);
                station.setEquipwhssdl(prodatas.stream().map(Analysispvprojectcan::getEquipwhssdl).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getEquipwhssdl).reduce(DoubleUtils::sum).get() : 0.0);
                station.setGeneratingcapacityscada(prodatas.stream().map(Analysispvprojectcan::getGeneratingcapacityscada).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getGeneratingcapacityscada).reduce(DoubleUtils::sum).get() : 0.0);
                station.setMinoutput(prodatas.stream().map(Analysispvprojectcan::getMinoutput).reduce(DoubleUtils::min).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getMinoutput).reduce(DoubleUtils::min).get() : 0.0);
                station.setCapacity(prodatas.stream().map(Analysispvprojectcan::getCapacity).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getCapacity).reduce(DoubleUtils::sum).get() : 0.0);
                station.setMaxlight(prodatas.stream().map(Analysispvprojectcan::getMaxlight).reduce(DoubleUtils::max).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getMaxlight).reduce(DoubleUtils::max).get() : 0.0);
                station.setInstalledunits(prodatas.stream().map(Analysispvprojectcan::getInstalledunits).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getInstalledunits).reduce(DoubleUtils::sum).get() : 0.0);
                station.setEquipfaultstoptime(prodatas.stream().map(Analysispvprojectcan::getEquipfaultstoptime).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getEquipfaultstoptime).reduce(DoubleUtils::sum).get() : 0.0);
                station.setEquipmaintime(prodatas.stream().map(Analysispvprojectcan::getEquipmaintime).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getEquipmaintime).reduce(DoubleUtils::sum).get() : 0.0);
                station.setAvepower(prodatas.stream().map(Analysispvprojectcan::getAvepower).reduce(DoubleUtils::ave).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getAvepower).reduce(DoubleUtils::ave).get() : 0.0);
                station.setStationofgenerating(prodatas.stream().map(Analysispvprojectcan::getStationofgenerating).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getStationofgenerating).reduce(DoubleUtils::sum).get() : 0.0);
                station.setBuygenerating(prodatas.stream().map(Analysispvprojectcan::getBuygenerating).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getBuygenerating).reduce(DoubleUtils::sum).get() : 0.0);
                station.setMultiplegenerating(prodatas.stream().map(Analysispvprojectcan::getMultiplegenerating).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getMultiplegenerating).reduce(DoubleUtils::sum).get() : 0.0);
                station.setLossgenerating(prodatas.stream().map(Analysispvprojectcan::getLossgenerating).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getLossgenerating).reduce(DoubleUtils::sum).get() : 0.0);
                station.setMultiplegeneratingscada(prodatas.stream().map(Analysispvprojectcan::getMultiplegeneratingscada).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getMultiplegeneratingscada).reduce(DoubleUtils::sum).get() : 0.0);
                station.setFaultloss(prodatas.stream().map(Analysispvprojectcan::getFaultloss).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getFaultloss).reduce(DoubleUtils::sum).get() : 0.0);
                station.setMainloss(prodatas.stream().map(Analysispvprojectcan::getMainloss).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getMainloss).reduce(DoubleUtils::sum).get() : 0.0);
                station.setAccidentcount(prodatas.stream().map(Analysispvprojectcan::getAccidentcount).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getAccidentcount).reduce(DoubleUtils::sum).get() : 0.0);
                station.setAccidentsituation(prodatas.stream().filter(i -> i.getAccidentsituation() != null).map(Analysispvprojectcan::getAccidentsituation).reduce(DoubleUtils::hb).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getAccidentsituation).reduce(DoubleUtils::hb).get() : "");
                station.setSyzfaultloss(prodatas.stream().map(Analysispvprojectcan::getSyzfaultloss).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getSyzfaultloss).reduce(DoubleUtils::sum).get() : 0.0);
                station.setRainandsnow(prodatas.stream().map(Analysispvprojectcan::getRainandsnow).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getRainandsnow).reduce(DoubleUtils::sum).get() : 0.0);
                station.setEquipfaultloss(prodatas.stream().map(Analysispvprojectcan::getEquipfaultloss).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getEquipfaultloss).reduce(DoubleUtils::sum).get() : 0.0);
                station.setStationinmainloss(prodatas.stream().map(Analysispvprojectcan::getStationinmainloss).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getStationinmainloss).reduce(DoubleUtils::sum).get() : 0.0);
                station.setStationinfaultloss(prodatas.stream().map(Analysispvprojectcan::getStationinfaultloss).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getStationinfaultloss).reduce(DoubleUtils::sum).get() : 0.0);
                station.setStationoutfaultloss(prodatas.stream().map(Analysispvprojectcan::getStationoutfaultloss).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getStationoutfaultloss).reduce(DoubleUtils::sum).get() : 0.0);
                station.setStationinstoptime(prodatas.stream().map(Analysispvprojectcan::getStationinstoptime).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getStationinstoptime).reduce(DoubleUtils::sum).get() : 0.0);
                station.setEquipmainstoptime(prodatas.stream().map(Analysispvprojectcan::getEquipmainstoptime).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getEquipmainstoptime).reduce(DoubleUtils::sum).get() : 0.0);
                station.setStationinmainstoptime(prodatas.stream().map(Analysispvprojectcan::getStationinmainstoptime).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getStationinmainstoptime).reduce(DoubleUtils::sum).get() : 0.0);
                station.setStaitonoutstoptime(prodatas.stream().map(Analysispvprojectcan::getStaitonoutstoptime).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getStaitonoutstoptime).reduce(DoubleUtils::sum).get() : 0.0);
                station.setTotalradiation(prodatas.stream().map(Analysispvprojectcan::getTotalradiation).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getTotalradiation).reduce(DoubleUtils::sum).get() : 0.0);
                station.setSunshinehours(prodatas.stream().map(Analysispvprojectcan::getSunshinehours).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getSunshinehours).reduce(DoubleUtils::sum).get() : 0.0);
                station.setSunnyday(prodatas.stream().map(Analysispvprojectcan::getSunnyday).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getSunnyday).reduce(DoubleUtils::sum).get() : 0.0);
                station.setSunnyovercast(prodatas.stream().map(Analysispvprojectcan::getSunnyovercast).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getSunnyovercast).reduce(DoubleUtils::sum).get() : 0.0);
                station.setDaynhcfdl(prodatas.stream().map(Analysispvprojectcan::getDaynhcfdl).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getDaynhcfdl).reduce(DoubleUtils::sum).get() : 0.0);
                station.setDaynhxdsj(prodatas.stream().map(Analysispvprojectcan::getDaynhxdsj).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getDaynhxdsj).reduce(DoubleUtils::sum).get() : 0.0);
                station.setGridmainssdl(prodatas.stream().map(Analysispvprojectcan::getGridmainssdl).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getGridmainssdl).reduce(DoubleUtils::sum).get() : 0.0);
                station.setGridfaultssdl(prodatas.stream().map(Analysispvprojectcan::getGridfaultssdl).reduce(DoubleUtils::sum).isPresent() ? prodatas.stream().map(Analysispvprojectcan::getGridfaultssdl).reduce(DoubleUtils::sum).get() : 0.0);
                station.setAqts(1.0);
                station.setCalendarhours(24.0);
                station.setPlangenerating(0.0);
                station.setEquivalent((station.getInstalledunits() * station.getCalendarhours() - station.getEquipfaultstoptime() - station.getEquipmaintime()) / (station.getInstalledunits() * station.getCalendarhours()) * 100);
                station.setMainlossrate(station.getGeneratingcapacity() != 0 ? station.getDaynhwhssdl() / station.getGeneratingcapacity() * 100 : 0.0);
                station.setFaultlossrate(station.getGeneratingcapacity() != 0 ? station.getDaynhgzssdl() / station.getGeneratingcapacity() * 100 : 0.0);
                station.setEquipavailability((station.getInstalledunits() * station.getCalendarhours() - station.getEquipfaultstoptime()) / (station.getInstalledunits() * station.getCalendarhours()) * 100);
                station.setMultiplerate(station.getGeneratingcapacity() != 0 ? station.getMultiplegenerating() / station.getGeneratingcapacity() * 100 : 0.0);
                station.setStationofrate(station.getGeneratingcapacity() != 0 ? station.getStationofgenerating() / station.getGeneratingcapacity() * 100 : 0.0);
                station.setEquiputilhour(station.getGeneratingcapacity() / station.getCapacity());
                station.setIscommit(0);

                analysispvstationService.save(station);


            }
        }
    }

    /**
     * 首页list
     *
     * @param beginDate
     * @param endDate
     * @return
     */
    public List<AnalysisMainVo> analysismainlist(String beginDate, String endDate) {
        Map<String, String> wpmap = CacheContext.wpmap;

        List<AnalysisMainVo> resultList = new ArrayList<>();
        Date begin = DateUtils.parseDate(beginDate);
        Date end = DateUtils.parseDate(endDate);
        QueryWrapper<Analysiswindstation> queryWind = new QueryWrapper<>();
        queryWind.ge("theday", begin).le("theday", end);
        QueryWrapper<Analysispvstation> queryPv = new QueryWrapper<>();
        queryPv.ge("theday", begin).le("theday", end);
        List<Analysiswindstation> windlist = analysiswindstationService.list(queryWind);
        List<Analysispvstation> pvlist = analysispvstationService.list(queryPv);
        if (StringUtils.isNotEmpty(windlist)) {
            for (Analysiswindstation analysiswindstation : windlist) {
                AnalysisMainVo vo = new AnalysisMainVo();
                String wpid = analysiswindstation.getWindpowerstationid();
                vo.setTheday(DateUtils.toDate(analysiswindstation.getTheday()));
                vo.setWpid(wpid);
                vo.setWpname(wpmap.get(wpid));
                vo.setIsConfirm(analysiswindstation.getIscommit());
                resultList.add(vo);
            }
        }
        if (StringUtils.isNotEmpty(pvlist)) {
            for (Analysispvstation analysiswindstation : pvlist) {
                AnalysisMainVo vo = new AnalysisMainVo();
                String wpid = analysiswindstation.getWindpowerstationid();
                vo.setTheday(DateUtils.toDate(analysiswindstation.getTheday()));
                vo.setWpid(wpid);
                vo.setWpname(wpmap.get(wpid));
                vo.setIsConfirm(analysiswindstation.getIscommit());
                resultList.add(vo);
            }
        }
        return resultList;
    }

    /**
     * 表底查询
     *
     * @param theday
     * @param wpid
     */
    public List<Object> bdzlist(String theday, String wpid) throws Exception {
        List<Object> resltList = new ArrayList<>();

        List<Meterpoint2> meterpoint2s = CacheContext.wpmeterMap.get(wpid);
        Map<String, Meterpoint2> meterMap = CacheContext.meterMap;

        List<String> collect = meterpoint2s.stream().filter(i->(
                    i.getMetersort().equals("主") && (i.getUniformcode().equals("ZXYG") || (i.getUniformcode().equals("FXYG"))) &&  i.getMetercode()!=null
                ))
                .map(i -> i.getId())
                .collect(Collectors.toList());
        //---------------------------倍率赋值开始-----------------------------
        DeskObject blObject = new DeskObject();
        blObject.setName("倍率");
        try {
            LinkedHashMap addMap = new LinkedHashMap();
            LinkedHashMap addValMap = new LinkedHashMap();

            for (String meterid : collect) {
                addMap.put(meterMap.get(meterid).getName(), Class.forName("java.math.BigDecimal"));
                addValMap.put(meterMap.get(meterid).getName(), meterMap.get(meterid).getMagnification());
            }
            Object blo = new ClassUtil().dynamicClass(blObject, addMap, addValMap);
            resltList.add(blo);
            System.out.println(JSON.toJSONString(blo));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //---------------------------起码赋值开始-----------------------------
        DeskObject qmObject = new DeskObject();
        qmObject.setDate(DateUtils.parseDate(theday));
        qmObject.setName("起码");

        QueryWrapper<Analysistablebottom> queryYestmonth = new QueryWrapper<>();
        queryYestmonth.eq("theday", DateUtils.getYestday(DateUtils.parseDate(theday))).in("meterid", collect);
        List<Analysistablebottom> yesterdaybdzlist = analysistablebottomService.list(queryYestmonth);

        try {
            LinkedHashMap addMap = new LinkedHashMap();
            LinkedHashMap addValMap = new LinkedHashMap();

            for (String meterid : collect) {
                addMap.put(meterMap.get(meterid).getName(), Class.forName("java.math.BigDecimal"));
                addValMap.put(meterMap.get(meterid).getName(), yesterdaybdzlist.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? yesterdaybdzlist.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getStopcodemodify() : BigDecimal.ZERO);
            }
            Object blo = new ClassUtil().dynamicClass(qmObject, addMap, addValMap);
            resltList.add(blo);
            System.out.println(JSON.toJSONString(blo));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //-------------------------------止码赋值开始-------------------------------------------

        QueryWrapper<Analysistablebottom> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("theday", DateUtils.parseDate(theday)).in("meterid", collect);
        List<Analysistablebottom> bdzlist = analysistablebottomService.list(queryWrapper);

        DeskObject zmObject = new DeskObject();
        zmObject.setDate(DateUtils.parseDate(theday));
        zmObject.setName("止码");


        try {
            LinkedHashMap addMap = new LinkedHashMap();
            LinkedHashMap addValMap = new LinkedHashMap();

            for (String meterid : collect) {
                addMap.put(meterMap.get(meterid).getName(), Class.forName("java.math.BigDecimal"));
                addValMap.put(meterMap.get(meterid).getName(), bdzlist.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getStopcodemodify());
            }
            Object blo = new ClassUtil().dynamicClass(zmObject, addMap, addValMap);
            resltList.add(blo);
            System.out.println(JSON.toJSONString(blo));
        } catch (Exception e) {
            e.printStackTrace();
        }

        DeskObject dlObject = new DeskObject();
        dlObject.setDate(DateUtils.parseDate(theday));
        dlObject.setName("电量");

        try {
            LinkedHashMap addMap = new LinkedHashMap();
            LinkedHashMap addValMap = new LinkedHashMap();

            for (String meterid : collect) {
                addMap.put(meterMap.get(meterid).getName(), Class.forName("java.math.BigDecimal"));
                addValMap.put(meterMap.get(meterid).getName(), bdzlist.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify());
            }
            Object blo = new ClassUtil().dynamicClass(dlObject, addMap, addValMap);
            resltList.add(blo);
            System.out.println(JSON.toJSONString(blo));
        } catch (Exception e) {
            e.printStackTrace();
        }

        return resltList;

    }

    /**
     * 修改表底
     *
     * @param bdzVo
     */
    public void updateBdz(List<BdzVo> bdzVo) {

        Map<String, Meterpoint2> meterMap = CacheContext.meterMap;
        Map<String, List<Meterpoint2>> wpmeterMap = CacheContext.wpmeterMap;
        BdzVo bdzVo1 = bdzVo.get(0);
        String wpid = bdzVo1.getWpid();
        Date date = DateUtils.parseDate(bdzVo1.getDate());
        List<Project> projects = CacheContext.projects.stream().filter(i -> i.getWindpowerstationid().equals(wpid)).collect(Collectors.toList());
        Map<String, Object> fcparam = new HashMap<>();
        fcparam.put("theday", date);
        fcparam.put("windpowerstationid", wpid);
        for (BdzVo vo : bdzVo) {
            String meterid = getKey(meterMap, vo.getName());
            QueryWrapper<Analysistablebottom> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("theday", DateUtils.parseDate(vo.getDate()));
            queryWrapper.eq("meterid", meterid);
            Analysistablebottom analysistablebottom = analysistablebottomService.getOne(queryWrapper);
            UpdateWrapper<Analysistablebottom> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("id",analysistablebottom.getId());
            updateWrapper.set("stopcodemodify", vo.getZm());
            updateWrapper.set("dayvaluemodify", (vo.getZm() - vo.getQm()) * meterMap.get(meterid).getMagnification().doubleValue());
            analysistablebottomService.update(null, updateWrapper);
        }
        Analysiswindstation analysiswindstation = analysiswindstationService.listByMap(fcparam).stream().findFirst().get();

            Map<String, Object> bdparam = new HashMap<>();
            bdparam.put("theday", date);
            List<String> fcfdlmeterids = wpmeterMap.get(wpid).stream()
                    .filter(i -> (
                            i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                    )).map(i -> i.getId()).collect(Collectors.toList());
            List<Analysistablebottom> fcfdls = analysistablebottomService.listByMap(bdparam);
            double fcfdl = 0.0;
            for (String meterid : fcfdlmeterids) {
                fcfdl += fcfdls.stream().filter(i->i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue();
            }
            //-------------------------------------------------------------------------------------------------------------------------------------------------
            List<String> fcswmeterids = wpmeterMap.get(wpid).stream()
                    .filter(i -> (
                            i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("正向有功")
                    )).map(i -> i.getId()).collect(Collectors.toList());
            double fcswfdl = 0.0;
            for (String meterid : fcswmeterids) {
                fcswfdl += fcfdls.stream().filter(i->i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue();
            }
            //-------------------------------------------------------------------------------------------------------------------------------------------------
            List<String> fcgwmeterids = wpmeterMap.get(wpid).stream()
                    .filter(i -> (
                            i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("反向有功")
                    )).map(i -> i.getId()).collect(Collectors.toList());
            double fcgwfdl = 0.0;
            for (String meterid : fcgwmeterids) {
                fcgwfdl += fcfdls.stream().filter(i->i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue();
            }
            //-------------------------------------------------------------------------------------------------------------------------------------------------
            List<String> fczybmeterids = wpmeterMap.get(wpid).stream()
                    .filter(i -> (
                            i.getMetersort().equals("主") && i.getMetertype().equals("站用变") && i.getDisplaytype().equals("正向有功")
                    )).map(i -> i.getId()).collect(Collectors.toList());
            double fczyb = 0.0;
            for (String meterid : fczybmeterids) {
                fczyb += fcfdls.stream().filter(i->i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue();
            }

        if (wpid.endsWith("FDC")) {
            for (Project project : projects) {
                Map<String, Object> param = new HashMap<>();
                param.put("theday", date);
                param.put("projectid", project.getId());
                Analysiswindprojectcan projectcan = analysiswindprojectcanService.listByMap(param).stream().findFirst().get();
                //select * from meterpoint2 where projectid='QS03_GC' AND METERSORT = '主' AND METERTYPE='进线' and displaytype='正向有功'
                List<String> fdls = wpmeterMap.get(wpid).stream()
                        .filter(i-> (
                            i.getProjectid().equals(project.getId()) && i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                param.remove("projectid");
                double generatingcapacity = 0;
                for (String meterid : fdls) {
                    generatingcapacity += fcfdls.stream().filter(i->i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue();
                }
                projectcan.setGeneratingcapacity(generatingcapacity/10000);
                projectcan.setGridgeneratingcapacity((generatingcapacity/fcfdl*fcswfdl)/10000);
                projectcan.setGwelectricitypurchase((generatingcapacity/fcfdl*fcgwfdl)/10000);
                projectcan.setBuygenerating(projectcan.getGwelectricitypurchase() + projectcan.getNwelectricitypurchase());
                projectcan.setStationofgenerating((generatingcapacity/fcfdl*fczyb)/10000);
                projectcan.setMultiplegenerating(projectcan.getGeneratingcapacity()+projectcan.getGwelectricitypurchase()-projectcan.getGridgeneratingcapacity());
                projectcan.setThegenerating(projectcan.getGeneratingcapacity() + projectcan.getDaynhgzssdl() + projectcan.getDaynhwhssdl() + projectcan.getDaynhxdssdl() + projectcan.getDaynhqfdl() + projectcan.getDaynhcfdl());
                projectcan.setMultiplegenerating(projectcan.getGeneratingcapacity() + projectcan.getBuygenerating() - projectcan.getGridgeneratingcapacity());
                projectcan.setMultiplerate(projectcan.getMultiplegenerating() / projectcan.getGeneratingcapacity() * 100);
                projectcan.setAveutilizationhour(projectcan.getGeneratingcapacity() / projectcan.getCapacity());
                projectcan.setMultiplegeneratingscada(projectcan.getGeneratingcapacityscada() + projectcan.getBuygenerating() - projectcan.getGridgeneratingcapacity());
                analysiswindprojectcanService.updateById(projectcan);

            }
            analysiswindstationtask(DateUtils.toDate(date), DateUtils.toDate(date));
        }else{
            for (Project project : projects) {
                Map<String, Object> param = new HashMap<>();
                param.put("theday", date);
                param.put("projectid", project.getId());
                Analysispvprojectcan projectcan = analysispvprojectcanService.listByMap(param).stream().findFirst().get();
                //select * from meterpoint2 where projectid='QS03_GC' AND METERSORT = '主' AND METERTYPE='进线' and displaytype='正向有功'
                List<String> fdls = wpmeterMap.get(wpid).stream()
                        .filter(i-> (
                                i.getProjectid().equals(project.getId()) && i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                param.remove("projectid");
                double generatingcapacity = 0;
                for (String meterid : fdls) {
                    generatingcapacity += fcfdls.stream().filter(i->i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue();
                }
                projectcan.setGeneratingcapacity(generatingcapacity/10000);
                projectcan.setGridgeneratingcapacity((generatingcapacity/fcfdl*fcswfdl)/10000);
                projectcan.setGwbuygeneratingcapacity((generatingcapacity/fcfdl*fcgwfdl)/10000);
                projectcan.setBuygenerating(projectcan.getGwbuygeneratingcapacity() + projectcan.getNwbuygeneratingcapacity());
                projectcan.setStationofgenerating((generatingcapacity/fcfdl*fczyb)/10000);
                projectcan.setMultiplegenerating(projectcan.getGeneratingcapacity()+projectcan.getGwbuygeneratingcapacity()-projectcan.getGridgeneratingcapacity());
                projectcan.setMultiplegenerating(projectcan.getGeneratingcapacity() + projectcan.getBuygenerating() - projectcan.getGridgeneratingcapacity());
                projectcan.setMultiplerate(projectcan.getMultiplegenerating() / projectcan.getGeneratingcapacity() * 100);
                projectcan.setEquiputilhour(projectcan.getGeneratingcapacity() / projectcan.getCapacity());
                projectcan.setMultiplegeneratingscada(projectcan.getGeneratingcapacityscada() + projectcan.getBuygenerating() - projectcan.getGridgeneratingcapacity());
                analysispvprojectcanService.updateById(projectcan);

            }
            analysispvstationtask(DateUtils.toDate(date), DateUtils.toDate(date));
        }

    }

    /**
     * 统计分析list
     *
     * @param theday
     * @param wpid
     */
    public List<Object> tjfxlist(String theday, String wpid, Integer identity) {
        List<Object> resultList = new ArrayList<>();
        Date date = DateUtils.parseDate(theday);
        List<Project> projects = CacheContext.projects.stream().filter(i -> i.getWindpowerstationid().equals(wpid)).collect(Collectors.toList());
        Windpowerstation windpowerstation = CacheContext.stations.stream().filter(i -> i.getId().equals(wpid)).findFirst().get();
        Map<String, Object> params = new HashMap<>();
        params.put("theday", date);
        params.put("windpowerstationid", wpid);
        if (identity == 0) {
            List<Analysiswindstation> windstation = analysiswindstationService.listByMap(params);
            List<Analysiswindprojectcannot> windprojectcannots = analysiswindprojectcannotService.listByMap(params);
            List<Analysiswindprojectcan> windprojectcans = analysiswindprojectcanService.listByMap(params);
            List<Analysiswindtarget> targetlist = CacheContext.targetlist.stream().filter(i -> i.getWindorpv().equals("风电"))
                    .sorted(Comparator.comparing(Analysiswindtarget::getOrderno)).collect(Collectors.toList());

            //-------------------------------------------------------------------------------------------------------------
            for (Analysiswindtarget target : targetlist) {
                AnalysisSubVo sub = new AnalysisSubVo();
                sub.setId(target.getId());
                sub.setName(target.getName());
                try {
                    LinkedHashMap addMap = new LinkedHashMap();
                    LinkedHashMap addValMap = new LinkedHashMap();
                    for (Project project : projects) {
                        Map<String, Object> map = new HashMap<>();
                        Analysiswindprojectcannot analysiswindprojectcannot = windprojectcannots.stream().filter(i -> i.getProjectid().equals(project.getId())).findFirst().get();
                        Class<? extends Analysiswindprojectcannot> aClass = analysiswindprojectcannot.getClass();
                        Field field = aClass.getDeclaredField(target.getId());
                        PropertyDescriptor pd = new PropertyDescriptor(field.getName(), aClass);
                        map.put("当日值(只读)", pd.getReadMethod().invoke(analysiswindprojectcannot));

                        Analysiswindprojectcan analysiswindprojectcan = windprojectcans.stream().filter(i -> i.getProjectid().equals(project.getId())).findFirst().get();
                        Class<? extends Analysiswindprojectcan> bClass = analysiswindprojectcan.getClass();
                        Field fieldb = bClass.getDeclaredField(target.getId());
                        PropertyDescriptor pdb = new PropertyDescriptor(fieldb.getName(), bClass);
                        map.put("当日值(编辑)", pdb.getReadMethod().invoke(analysiswindprojectcan));

                        addMap.put(project.getName(), Class.forName("java.util.Map"));
                        addValMap.put(project.getName(), map);
                    }
                    Analysiswindstation analysiswindstation = windstation.stream().filter(i -> i.getWindpowerstationid().equals(wpid)).findFirst().get();
                    Class<? extends Analysiswindstation> Class = analysiswindstation.getClass();
                    Field fiel = Class.getDeclaredField(target.getId());
                    PropertyDescriptor pd = new PropertyDescriptor(fiel.getName(), Class);
                    addMap.put(windpowerstation.getName(), Class.forName("java.lang.Object"));
                    addValMap.put(windpowerstation.getName(), pd.getReadMethod().invoke(analysiswindstation));


                    Object blo = new ClassUtil().dynamicClass(sub, addMap, addValMap);
                    resultList.add(blo);
                    System.out.println(JSON.toJSONString(blo));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (identity == 1) {
            List<Analysispvstation> windstation = analysispvstationService.listByMap(params);
            List<Analysispvprojectcannot> windprojectcannots = analysispvprojectcannotService.listByMap(params);
            List<Analysispvprojectcan> windprojectcans = analysispvprojectcanService.listByMap(params);
            List<Analysiswindtarget> targetlist = CacheContext.targetlist.stream().filter(i -> i.getWindorpv().equals("光伏"))
                    .sorted(Comparator.comparing(Analysiswindtarget::getOrderno)).collect(Collectors.toList());

            //-------------------------------------------------------------------------------------------------------------
            for (Analysiswindtarget target : targetlist) {
                AnalysisSubVo sub = new AnalysisSubVo();
                sub.setId(target.getId());
                sub.setName(target.getName());
                try {
                    LinkedHashMap addMap = new LinkedHashMap();
                    LinkedHashMap addValMap = new LinkedHashMap();
                    for (Project project : projects) {
                        Map<String, Object> map = new HashMap<>();
                        Analysispvprojectcannot analysiswindprojectcannot = windprojectcannots.stream().filter(i -> i.getProjectid().equals(project.getId())).findFirst().get();
                        Class<? extends Analysispvprojectcannot> aClass = analysiswindprojectcannot.getClass();
                        Field field = aClass.getDeclaredField(target.getId());
                        PropertyDescriptor pd = new PropertyDescriptor(field.getName(), aClass);
                        map.put("当日值(只读)", pd.getReadMethod().invoke(analysiswindprojectcannot));

                        Analysispvprojectcan analysiswindprojectcan = windprojectcans.stream().filter(i -> i.getProjectid().equals(project.getId())).findFirst().get();
                        Class<? extends Analysispvprojectcan> bClass = analysiswindprojectcan.getClass();
                        Field fieldb = bClass.getDeclaredField(target.getId());
                        PropertyDescriptor pdb = new PropertyDescriptor(fieldb.getName(), bClass);
                        map.put("当日值(编辑)", pdb.getReadMethod().invoke(analysiswindprojectcan));

                        addMap.put(project.getName(), Class.forName("java.util.Map"));
                        addValMap.put(project.getName(), map);
                    }
                    Analysispvstation analysiswindstation = windstation.stream().filter(i -> i.getWindpowerstationid().equals(wpid)).findFirst().get();
                    Class<? extends Analysispvstation> Class = analysiswindstation.getClass();
                    Field fiel = Class.getDeclaredField(target.getId());
                    PropertyDescriptor pd = new PropertyDescriptor(fiel.getName(), Class);
                    addMap.put(windpowerstation.getName(), Class.forName("java.lang.Object"));
                    addValMap.put(windpowerstation.getName(), pd.getReadMethod().invoke(analysiswindstation));


                    Object blo = new ClassUtil().dynamicClass(sub, addMap, addValMap);
                    resultList.add(blo);
                    System.out.println(JSON.toJSONString(blo));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return resultList;
    }


    /**
     * 根据map的value获取map的key
     *
     * @param meterMap
     * @param value
     * @return
     */
    private static String getKey(Map<String, Meterpoint2> meterMap, String value) {

        String key = "";
        for (Map.Entry<String, Meterpoint2> entry : meterMap.entrySet()) {
            if (value.equals(entry.getValue().getName())) {
                key = entry.getKey();
            }
        }
        return key;
    }

    /**
     * 修改统计分析内容
     *
     * @param vos
     */
    public void updateTjfx(List<AnalsisUpdateVo> vos) {
        List<Project> projects = CacheContext.projects;
        AnalsisUpdateVo analsisUpdateVo = vos.get(0);
        String windpowerstationid = projects.stream().filter(i -> i.getName().equals(analsisUpdateVo.getProjectname())).findFirst().get().getWindpowerstationid();
        String date = analsisUpdateVo.getDate();
        Map<String, Object> map = new HashMap<>();
        map.put("theday", DateUtils.parseDate(date));
        map.put("windpowerstationid", windpowerstationid);


        if (windpowerstationid.endsWith("FDC")) {
            for (AnalsisUpdateVo vo : vos) {
                Project project = projects.stream().filter(i -> i.getName().equals(vo.getProjectname())).findFirst().get();
                Map<String, Object> params = new HashMap<>();
                params.put("theday", DateUtils.parseDate(vo.getDate()));
                params.put("projectid", project.getId());
                Analysiswindprojectcan analysiswindprojectcan = analysiswindprojectcanService.listByMap(params).stream().findFirst().get();
                UpdateWrapper<Analysiswindprojectcan> updateWrapper = new UpdateWrapper<>();
                updateWrapper.eq("id",analysiswindprojectcan.getId()).set(vo.getId(), vo.getValue());
                analysiswindprojectcanService.update(null, updateWrapper);
            }
            List<Analysiswindprojectcan> analysiswindprojectcans = analysiswindprojectcanService.listByMap(map);
            for (Analysiswindprojectcan projectcannot : analysiswindprojectcans) {
                projectcannot.setThegenerating(projectcannot.getGeneratingcapacity() + projectcannot.getDaynhgzssdl() + projectcannot.getDaynhwhssdl() + projectcannot.getDaynhxdssdl() + projectcannot.getDaynhqfdl() + projectcannot.getDaynhcfdl());
                projectcannot.setThegeneratingscada(projectcannot.getGeneratingcapacityscada() + projectcannot.getDaynhgzssdl() + projectcannot.getDaynhwhssdl() + projectcannot.getDaynhxdssdl() + projectcannot.getDaynhqfdl() + projectcannot.getDaynhcfdl());
                //风机故障停运时间+升压站故障停运时间+电网故障影响停运时间target21089,+,target25046,+,target25078
                projectcannot.setStoptime(projectcannot.getEquipfaulttimes() + projectcannot.getSyzfaultstoptime() + projectcannot.getGridfaultstoptime());
                projectcannot.setBuygenerating(projectcannot.getGwelectricitypurchase() + projectcannot.getNwelectricitypurchase());
                projectcannot.setLossgenerating(projectcannot.getDaynhgzssdl() + projectcannot.getDaynhwhssdl() + projectcannot.getDaynhxdssdl() + projectcannot.getDaynhqfdl() + projectcannot.getDaynhcfdl());
                projectcannot.setMultiplegenerating(projectcannot.getGeneratingcapacity() + projectcannot.getBuygenerating() - projectcannot.getGridgeneratingcapacity());
                projectcannot.setMultiplerate(projectcannot.getMultiplegenerating() / projectcannot.getGeneratingcapacity() * 100);
                projectcannot.setMultiplegeneratingscada(projectcannot.getGeneratingcapacityscada() + projectcannot.getBuygenerating() - projectcannot.getGridgeneratingcapacity());
                projectcannot.setMultipleratescada(projectcannot.getMultiplegeneratingscada() / projectcannot.getGeneratingcapacityscada());
                //target21032,/,target21105
                projectcannot.setAveutilizationhour(projectcannot.getGeneratingcapacity() / projectcannot.getCapacity());
                projectcannot.setAveutilizationhourscada(projectcannot.getGeneratingcapacityscada() / projectcannot.getCapacity());
                //(,target26002,*,target21111,-,target21088,),/,target21111
                projectcannot.setNofaulthours((projectcannot.getCalendarhours() * projectcannot.getInstalledunits() - projectcannot.getEquipfaulttimes()) / projectcannot.getInstalledunits());
                //(,target21112,*,target26002,-,target21116,-,target21117,),/,target21112
                projectcannot.setAdjustablehour((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipfaulttimes() - projectcannot.getEquipmaintime()) / projectcannot.getInstalledunits());
                //(,target21112,*,target26002,-,target21117,-,target21089,),/,target21112
                projectcannot.setEffectivehour((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipmaintime() - projectcannot.getEquipfaulttimes()) / projectcannot.getInstalledunits());
                //(,target21112,*,target26002,-,target21116,-,target21117,),/,(,target21112,*,target26002,),*,100
                projectcannot.setEquivalent((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipfaulttimes() - projectcannot.getEquipmaintime()) / (projectcannot.getInstalledunits() * projectcannot.getCalendarhours()) * 100);
                projectcannot.setLoadrate(projectcannot.getAvepower() / projectcannot.getMaxpower() * 100);
                projectcannot.setMainlossrate(projectcannot.getDaynhwhssdl() / projectcannot.getThegenerating() * 100);
                projectcannot.setFaultlossrate(projectcannot.getDaynhgzssdl() / projectcannot.getThegeneratingscada() * 100);
                //(,target21112,*,target26002,-,target21116,),/,(,target21112,*,target26002,),*,100
                projectcannot.setEquipavailability((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipfaulttimes()) / (projectcannot.getInstalledunits() * projectcannot.getCalendarhours()) * 100);
                //target21052,+,target25020,+,target25090
                projectcannot.setFaultloss(projectcannot.getDaynhgzssdl() + projectcannot.getSyzfaultloss() + projectcannot.getGridfaultssdl());
                //target21060,+,target25020,+,target25086
                projectcannot.setMainloss(projectcannot.getDaynhwhssdl() + projectcannot.getSyzmainloss() + projectcannot.getGridmainssdl());
                //target25042,/,target21112
                projectcannot.setAvefaulttime(projectcannot.getFaulthandletime() / projectcannot.getInstalledunits());
                //target21081,+,target25041,+,target25082
                projectcannot.setMainstoptime(projectcannot.getMainstoptimes() + projectcannot.getSyzmainstoptime() + projectcannot.getGridmainstoptime());
                //target21116,/,target21112
                projectcannot.setEquipfaultavestoptime(projectcannot.getEquipfaulttimes() / projectcannot.getInstalledunits());
                projectcannot.setWtfaultavestoptimeedit(projectcannot.getEquipfaulttimes() / projectcannot.getInstalledunits());
                projectcannot.setSyzfaultavestoptime(projectcannot.getSyzfaultstoptime() / projectcannot.getInstalledunits());
                projectcannot.setPowergridfaultavestoptime(projectcannot.getGridfaultstoptime() / projectcannot.getInstalledunits());
                projectcannot.setMainavestoptime(projectcannot.getMainstoptime() / projectcannot.getInstalledunits());
                projectcannot.setFjdjmainavestoptime(projectcannot.getEquipmaintime() / projectcannot.getInstalledunits());
                projectcannot.setSyzmainavestoptime(projectcannot.getSyzmainstoptime() / projectcannot.getInstalledunits());
                projectcannot.setPowergridmainavestoptime(projectcannot.getGridmainstoptime() / projectcannot.getInstalledunits());
                projectcannot.setAveruntime(projectcannot.getRuntime() / projectcannot.getInstalledunits());
                analysiswindprojectcanService.updateById(projectcannot);
            }
            analysiswindstationtask(date, date);
        } else {
            for (AnalsisUpdateVo vo : vos) {
                Project project = projects.stream().filter(i -> i.getName().equals(vo.getProjectname())).findFirst().get();
                Map<String, Object> params = new HashMap<>();
                params.put("theday", DateUtils.parseDate(vo.getDate()));
                params.put("projectid", project.getId());
                Analysispvprojectcan analysiswindprojectcan = analysispvprojectcanService.listByMap(params).stream().findFirst().get();
                UpdateWrapper<Analysispvprojectcan> updateWrapper = new UpdateWrapper<>();
                updateWrapper.eq("id",analysiswindprojectcan.getId()).set(vo.getId(), vo.getValue());
                analysispvprojectcanService.update(null, updateWrapper);
            }
            List<Analysispvprojectcan> analysispvprojectcans = analysispvprojectcanService.listByMap(map);
            for (Analysispvprojectcan projectcannot : analysispvprojectcans) {
                //风机故障停运时间+升压站故障停运时间+电网故障影响停运时间target21089,+,target25046,+,target25078
                projectcannot.setBuygenerating(projectcannot.getGwbuygeneratingcapacity() + projectcannot.getNwbuygeneratingcapacity());
                projectcannot.setLossgenerating(projectcannot.getDaynhgzssdl() + projectcannot.getDaynhwhssdl() + projectcannot.getDaynhxdssdl() + projectcannot.getDaynhcfdl());
                projectcannot.setMultiplegenerating(projectcannot.getGeneratingcapacity() + projectcannot.getBuygenerating() - projectcannot.getGridgeneratingcapacity());
                projectcannot.setMultiplerate(projectcannot.getGeneratingcapacity() != 0 ? projectcannot.getMultiplegenerating() / projectcannot.getGeneratingcapacity() * 100 : 0.0);
                projectcannot.setMultiplegeneratingscada(projectcannot.getGeneratingcapacityscada() + projectcannot.getBuygenerating() - projectcannot.getGridgeneratingcapacity());
                //target21032,/,target21105
                projectcannot.setEquiputilhour(projectcannot.getGeneratingcapacity() / projectcannot.getCapacity());

                projectcannot.setEquivalent((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipfaultstoptime() - projectcannot.getEquipmaintime()) / (projectcannot.getInstalledunits() * projectcannot.getCalendarhours()) * 100);
                projectcannot.setMainlossrate(projectcannot.getGeneratingcapacity() != 0 ? projectcannot.getDaynhwhssdl() / projectcannot.getGeneratingcapacity() * 100 : 0.0);
                projectcannot.setFaultlossrate(projectcannot.getGeneratingcapacity() != 0 ? projectcannot.getDaynhgzssdl() / projectcannot.getGeneratingcapacity() * 100 : 0.0);
                //(,target21112,*,target26002,-,target21116,),/,(,target21112,*,target26002,),*,100
                projectcannot.setEquipavailability((projectcannot.getInstalledunits() * projectcannot.getCalendarhours() - projectcannot.getEquipfaultstoptime()) / (projectcannot.getInstalledunits() * projectcannot.getCalendarhours()) * 100);
                //target21052,+,target25020,+,target25090
                projectcannot.setFaultloss(projectcannot.getDaynhgzssdl() + projectcannot.getSyzfaultloss() + projectcannot.getGridfaultssdl());
                //target21060,+,target25020,+,target25086
                projectcannot.setMainloss(projectcannot.getDaynhwhssdl() + projectcannot.getGridmainssdl());


                projectcannot.setStationofrate(projectcannot.getGeneratingcapacity() != 0 ? projectcannot.getStationofgenerating() / projectcannot.getGeneratingcapacity() * 100 : 0.0);

                analysispvprojectcanService.updateById(projectcannot);
            }
            analysispvstationtask(date, date);

        }


    }
}
