package com.gyee.runeconomy.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.runeconomy.init.CacheContext;
import com.gyee.runeconomy.model.auto.ProEconEquipmentDeviatPower;
import com.gyee.runeconomy.model.auto.ProEconEquipmentDeviatSpeed;
import com.gyee.runeconomy.model.auto.ProEconEquipmentInfoDay4;
import com.gyee.runeconomy.model.vo.DeviatPowerVo;
import com.gyee.runeconomy.model.vo.DeviatSpeedVo;
import com.gyee.runeconomy.model.vo.DeviatValueVo;
import com.gyee.runeconomy.model.vo.ProEconEquipmentInfoDay4Vo;
import com.gyee.runeconomy.service.auto.IProEconEquipmentDeviatPowerService;
import com.gyee.runeconomy.service.auto.IProEconEquipmentDeviatSpeedService;
import com.gyee.runeconomy.service.auto.IProEconEquipmentInfoDay4Service;
import com.gyee.runeconomy.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class WindDeviationService {

    @Resource
    private IProEconEquipmentDeviatSpeedService proEconEquipmentDeviatSpeedService;
    @Resource
    private IProEconEquipmentDeviatPowerService proEconEquipmentDeviatPowerService;
    @Resource
    private IProEconEquipmentInfoDay4Service proEconEquipmentInfoDay4Service;

    /**
     * 保存对风偏差率描述
     */
    public Map<String, Object> getDeviationValue(String wtId, String date) {


        Map<String, Object> resultMap = new HashMap<>();

        if (StringUtils.notEmp(wtId) && StringUtils.notEmp(date)) {

            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

            Date recorddate = null;

            try {
                recorddate = df.parse(date);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            QueryWrapper<ProEconEquipmentDeviatSpeed> windqueryWrapper = new QueryWrapper<>();
            windqueryWrapper.eq("record_date", recorddate);
            windqueryWrapper.eq("windturbine_id", wtId);
            List<ProEconEquipmentDeviatSpeed> speedCollect = proEconEquipmentDeviatSpeedService.list(windqueryWrapper);

            QueryWrapper<ProEconEquipmentDeviatPower> powerqueryWrapper = new QueryWrapper<>();
            powerqueryWrapper.eq("record_date", recorddate);
            powerqueryWrapper.eq("windturbine_id", wtId);
            List<ProEconEquipmentDeviatPower> powerCollect = proEconEquipmentDeviatPowerService.list(powerqueryWrapper);

            List<DeviatValueVo> resultList = new ArrayList<>();

            if (!speedCollect.isEmpty()) {
                for (int i = -50; i < 51; i++) {
                    int bhg = 0;
                    DeviatValueVo vo = new DeviatValueVo();
                    vo.setWtid(wtId);
                    switch (i) {
                        case -50:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP50).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -49:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP49).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -48:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP48).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -47:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP47).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -46:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP46).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -45:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP45).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -44:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP44).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -43:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP43).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -42:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP42).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -41:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP41).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -40:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP40).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -39:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP39).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -38:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP38).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -37:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP37).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -36:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP36).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -35:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP35).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -34:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP34).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -33:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP33).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -32:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP32).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -31:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP31).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -30:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP30).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -29:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP29).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -28:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP28).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -27:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP27).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -26:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP26).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -25:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP25).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -24:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP24).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -23:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP23).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -22:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP22).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -21:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP21).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -20:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP20).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -19:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP19).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -18:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP18).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -17:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP17).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -16:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP16).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -15:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP15).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -14:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP14).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -13:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP13).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -12:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP12).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -11:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP11).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -10:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP10).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -9:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP9).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -8:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP8).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -7:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP7).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -6:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP6).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -5:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP5).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -4:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP4).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -3:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP3).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -2:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP2).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -1:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP1).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case -0:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getP0).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 1:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN1).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 2:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN2).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 3:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN3).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 4:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN4).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 5:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN5).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 6:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN6).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 7:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN7).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 8:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN8).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 9:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN9).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 10:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN10).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 11:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN11).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 12:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN12).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 13:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN13).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 14:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN14).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 15:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN15).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 16:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN16).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 17:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN17).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 18:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN18).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 19:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN19).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 20:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN20).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 21:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN21).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 22:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN22).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 23:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN23).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 24:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN24).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 25:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN25).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 26:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN26).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 27:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN27).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 28:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN28).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 29:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN29).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 30:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN30).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 31:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN31).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 32:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN32).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 33:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN33).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 34:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN34).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 35:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN35).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 36:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN36).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 37:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN37).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 38:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN38).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 39:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN39).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 40:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN40).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 41:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN41).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 42:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN42).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 43:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN43).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 44:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN44).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 45:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN45).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 46:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN46).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 47:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN47).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 48:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN48).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 49:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN49).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                        case 50:
                            bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getN50).sum();
                            vo.setValue(i);
                            vo.setBhg(bhg);
                            break;
                    }

                    resultList.add(vo);
                }

            }

            resultMap.put("deviationls", resultList);
            int hg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getQualified).sum();
            int bhg = speedCollect.stream().mapToInt(ProEconEquipmentDeviatSpeed::getUnqualified).sum();

            int sum = hg + bhg;

            Double dfpcl = 0.0;
            if (sum != 0) {
                dfpcl = new BigDecimal(bhg).divide(new BigDecimal(sum), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();

            }
            resultMap.put("hg", hg);
            resultMap.put("bhg", bhg);
            resultMap.put("dfpcl", dfpcl);

            int threehg = speedCollect.stream().filter(i -> i.getSpeed() >= 3 && i.getSpeed() < 5).mapToInt(ProEconEquipmentDeviatSpeed::getQualified).sum();
            int threebhg = speedCollect.stream().filter(i -> i.getSpeed() >= 3 && i.getSpeed() < 5).mapToInt(ProEconEquipmentDeviatSpeed::getUnqualified).sum();
            int threesum = threehg + threebhg;

            double threedfpcl = 0.0;

            if (threesum != 0) {
                threedfpcl = new BigDecimal(threebhg).divide(new BigDecimal(threesum), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();

            }
            resultMap.put("threedfpcl", threedfpcl);
            double fivedfpcl = 0.0;
            int fivehg = speedCollect.stream().filter(i -> i.getSpeed() >= 5 && i.getSpeed() < 11).mapToInt(ProEconEquipmentDeviatSpeed::getQualified).sum();
            int fivebhg = speedCollect.stream().filter(i -> i.getSpeed() >= 5 && i.getSpeed() < 11).mapToInt(ProEconEquipmentDeviatSpeed::getUnqualified).sum();
            int fivesum = fivehg + fivebhg;
            if (fivesum != 0) {
                fivedfpcl = new BigDecimal(fivebhg).divide(new BigDecimal(fivesum), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();

            }
            resultMap.put("fivedfpcl", fivedfpcl);
            double eledfpcl = 0.0;

            int elehg = speedCollect.stream().filter(i -> i.getSpeed() >= 11).mapToInt(ProEconEquipmentDeviatSpeed::getQualified).sum();
            int elebhg = speedCollect.stream().filter(i -> i.getSpeed() >= 11).mapToInt(ProEconEquipmentDeviatSpeed::getUnqualified).sum();
            int elesum = elehg + elebhg;

            if (elesum != 0) {
                eledfpcl = new BigDecimal(elebhg).divide(new BigDecimal(elesum), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();

            }
            resultMap.put("eledfpcl", eledfpcl);

            List<DeviatPowerVo> powerresultList = new ArrayList<>();
            List<DeviatSpeedVo> speedresultList = new ArrayList<>();

            if (powerCollect != null && powerCollect.size() > 0) {
                List<Double> powercollect = powerCollect.stream().map(i -> (double) i.getPower()).distinct().collect(Collectors.toList());
                Collections.sort(powercollect);

                for (Double aDouble : powercollect) {
                    DeviatPowerVo powerVo = new DeviatPowerVo();
                    powerVo.setWtid(wtId);
                    powerVo.setPower(aDouble);

                    int xhg = powerCollect.stream().filter(i -> (double) i.getPower() == aDouble).mapToInt(ProEconEquipmentDeviatPower::getQualified).sum();
                    int xbhg = powerCollect.stream().filter(i -> (double) i.getPower() == aDouble).mapToInt(ProEconEquipmentDeviatPower::getUnqualified).sum();
                    int xsum = xhg + xbhg;

                    double xbdfpcl = 0.0;
                    if (xsum != 0) {
                        xbdfpcl = new BigDecimal(fivebhg).divide(new BigDecimal(xsum), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();

                    }
                    powerVo.setDfpcl(xbdfpcl);
                    powerresultList.add(powerVo);

                }

            }

            resultMap.put("powerresultList", powerresultList);

            if (speedCollect != null && speedCollect.size() > 0) {
                List<Double> speedcollect = speedCollect.stream().map(i -> (double) i.getSpeed()).distinct().collect(Collectors.toList());
                Collections.sort(speedcollect);
                for (Double aDouble : speedcollect) {
                    DeviatSpeedVo speedVo = new DeviatSpeedVo();

                    speedVo.setWtid(wtId);
                    speedVo.setSpeed(aDouble);

                    int xhg = speedCollect.stream().filter(i -> (double) i.getSpeed() == aDouble).mapToInt(ProEconEquipmentDeviatSpeed::getQualified).sum();
                    int xbhg = speedCollect.stream().filter(i -> (double) i.getSpeed() == aDouble).mapToInt(ProEconEquipmentDeviatSpeed::getUnqualified).sum();
                    int xsum = xhg + xbhg;
                    double xbdfpcl = 0.0;
                    if (xsum != 0) {
                        xbdfpcl = new BigDecimal(fivebhg).divide(new BigDecimal(xsum), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();

                    }
                    speedVo.setDfpcl(xbdfpcl);
                    speedresultList.add(speedVo);
                }
            }

            resultMap.put("speedresultList", speedresultList);
        }

        return resultMap;

    }

    public List<ProEconEquipmentInfoDay4Vo> queryEquipmentInfoDay4(String wpId, String date) {

        List<ProEconEquipmentInfoDay4Vo> vos = new ArrayList<>();

        if (StringUtils.notEmp(wpId) && StringUtils.notEmp(date)) {

            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

            Date recordDate = null;

            try {
                recordDate = df.parse(date);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }


            List<ProEconEquipmentInfoDay4> iostls = null;
            if (com.gyee.common.model.StringUtils.notEmp(wpId)) {
                QueryWrapper<ProEconEquipmentInfoDay4> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("record_date", recordDate)
                        .eq("windpowerstation_id", wpId);

                iostls = proEconEquipmentInfoDay4Service.list(queryWrapper);
            }

            for (ProEconEquipmentInfoDay4 day4 : iostls) {
                ProEconEquipmentInfoDay4Vo vo = new ProEconEquipmentInfoDay4Vo();

                vo.setWtId(day4.getWindturbineId());

                if (CacheContext.wtmap.containsKey(day4.getWindturbineId())) {
                    vo.setNemCode(CacheContext.wtmap.get(day4.getWindturbineId()).getNemCode());
                }
                vo.setY11mycqxpcl(day4.getY11mycqxpcl());
                vo.setY35mqxpcl(day4.getY35mqxpcl());
                vo.setY511mqxpcl(day4.getY511mqxpcl());
                vos.add(vo);
            }

        }

        return vos;
    }

}
