package com.gyee.frame.service.websocket;


import com.gyee.frame.common.spring.Constant;
import com.gyee.frame.common.spring.InitialRunner;
import com.gyee.frame.model.auto.ProjectPlan;
import com.gyee.frame.model.auto.WindPowerStationTestingPoint;
import com.gyee.frame.model.auto.Windpowerstation;
import com.gyee.frame.model.custom.DataVo;
import com.gyee.frame.model.custom.PointData;
import com.gyee.frame.model.custom.resultVo;
import com.gyee.frame.service.ProjectPlanService;
import com.gyee.frame.service.ShutdowneventService;
import com.gyee.frame.service.WindPowerstationTestingPoint2Service;
import com.gyee.frame.service.WindpowerinfodayService;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.IRealTimeDataBaseUtil;
import com.gyee.frame.util.RealTimeDataBaseFactory;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

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

@Service
public class GenreSetPushDetailService {


    @Resource
    private WindPowerstationTestingPoint2Service windPowerstationTestingPoint2Service;
    @Resource
    private WindpowerinfodayService windpowerinfodayService;
    @Resource
    private ProjectPlanService projectPlanService;
    @Resource
    private RealPowerPushService realPowerPushService;
    @Resource
    private ShutdowneventService shutdowneventService;

    private final String QS = "0";
    private final String FD = "-1";
    private final String GF = "-2";

    private final String RFDL = "rfdl";
    private final String RGZSSDL = "rgzssdl";
    private final String RJXSSDL = "rjxssdl";
    private final String RXNSSDL = "rxnssdl";
    private final String RXDSSDL = "rxdssdl";
    private final String RSLSSDL = "rslssdl";

    private final String YFDL = "yfdl";
    private final String YGZSSDL = "ygzssdl";
    private final String YJXSSDL = "yjxssdl";
    private final String YXNSSDL = "yxnssdl";
    private final String YXDSSDL = "yxdssdl";
    private final String YSLSSDL = "yslssdl";

    private final String NFDL = "nfdl";
    private final String NGZSSDL = "ngzssdl";
    private final String NJXSSDL = "njxssdl";
    private final String NXNSSDL = "nxnssdl";
    private final String NXDSSDL = "nxdssdl";
    private final String NSLSSDL = "nslssdl";


    IRealTimeDataBaseUtil realApiUtil = RealTimeDataBaseFactory.createRealTimeDataBase();


    public Map<String, Object> genreSetMap() throws Exception {

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


        return map;

    }

    public Map<String, Object> findDayInfo(String wpId, String targetName) {

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

        Map<String, Double> summap = new TreeMap<String, Double>();

        List<String> datels = new ArrayList<String>();

        List<resultVo> resultls = new ArrayList<resultVo>();

        List<Windpowerstation> wpls = new ArrayList<Windpowerstation>();

        if (StringUtils.empty(wpId) || wpId.equals(FD)) {
            wpId = QS;
        }

        if (wpId.equals("") || wpId.equals(QS)) {
            if (targetName.equals(RFDL)) {
                for (Windpowerstation station : InitialRunner.wpallls) {
                    wpls.add(station);
                }
            } else {
                for (Windpowerstation station : InitialRunner.wpallls) {
                    if (station.getId().endsWith("FDC")) {
                        wpls.add(station);
                    }
                }
            }

        } else if (wpId.equals(FD)) {
            for (Windpowerstation station : InitialRunner.wpallls) {
                if (station.getId().endsWith("FDC")) {
                    wpls.add(station);
                }
            }
        } else if (wpId.equals(GF)) {
            for (Windpowerstation station : InitialRunner.wpallls) {
                if (station.getId().endsWith("GDC")) {
                    wpls.add(station);
                }
            }
        }

        if (!wpls.isEmpty()) {
            Calendar c = Calendar.getInstance();
            c.add(Calendar.DAY_OF_MONTH, 2);
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);

            Date endDate = c.getTime();
            c.add(Calendar.DAY_OF_MONTH, -8);
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            Date beginDate = c.getTime();

            Calendar cal = Calendar.getInstance();
            cal.setTime(beginDate);

            for (int i = 0; i < 7; i++) {

                datels.add(DateUtils.format(cal.getTime()));
                cal.add(Calendar.DAY_OF_MONTH, 1);
            }
            map.put("datels", datels);
            long num = DateUtils.daysDiff(beginDate, endDate) + 1;
            for (Windpowerstation wp : wpls) {
                resultVo vo = new resultVo();

                // public static final String RQFSSDL = "RQFSSDL"; // 日欠发损失电量
                // public static final String RGZSSDL = "RGZSSDL"; // 日故障损失电量
                // public static final String RJXSSDL = "RJXSSDL"; // 日检修损失电量
                // public static final String RXDSSDL = "RXDSSDL"; // 日限电损失电量
                // public static final String RLZSSDL = "RLZSSDL"; // 日场内受累检修
                // public static final String RSZSSDL = "RSZSSDL"; // 日场内受累故障
                // public static final String RWZSSDL = "RWZSSDL"; // 日场外受累电网
                // public static final String RTZSSDL = "RTZSSDL"; // 日场外受累天气
                if (targetName.equals(RFDL)) {
                    WindPowerStationTestingPoint rfdlai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.TPOINT_WP_RFDL);// 日发电量

                    List<PointData> rfdls = new ArrayList<PointData>();
                    try {
                        rfdls = realApiUtil.getHistoryDatasSnap(rfdlai, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    setPointValueFdl(wp, vo, rfdls, summap);
                } else if (targetName.equals(RXDSSDL)) {
                    WindPowerStationTestingPoint xdai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RXDSSDL);
                    List<PointData> xdls = new ArrayList<PointData>();
                    try {
                        xdls = realApiUtil.getHistoryDatasSnap(xdai, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    setPointValue(wp, vo, xdls, summap);
                } else if (targetName.equals(RXNSSDL)) {

                    WindPowerStationTestingPoint qfai1 = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RSDJZSDL);
                    WindPowerStationTestingPoint qfai2 = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RSSTZSDL);
                    WindPowerStationTestingPoint qfai3 = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RXNZSDL);
                    WindPowerStationTestingPoint qfai4 = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RSQXZSDL);

                    List<PointData> qfls1 = new ArrayList<PointData>();
                    List<PointData> qfls2 = new ArrayList<PointData>();
                    List<PointData> qfls3 = new ArrayList<PointData>();
                    List<PointData> qfls4 = new ArrayList<PointData>();
                    List<PointData> qfls = new ArrayList<PointData>();

                    try {
                        qfls1 = realApiUtil.getHistoryDatasSnap(qfai1, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                        qfls2 = realApiUtil.getHistoryDatasSnap(qfai2, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                        qfls3 = realApiUtil.getHistoryDatasSnap(qfai3, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                        qfls4 = realApiUtil.getHistoryDatasSnap(qfai4, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);

                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    if(qfls1.size()==qfls1.size() && qfls1.size()==qfls3.size() && qfls1.size()==qfls3.size())
                    {
                        for (int i = 0; i < qfls1.size(); i++)
                        {
                            PointData pd=new PointData();
                            pd.setEdnaId(qfls1.get(i).getEdnaId());
                            pd.setPointTime(qfls1.get(i).getPointTime());

                            double temp1=qfls1.get(i).getPointValueInDouble();
                            double temp2=qfls2.get(i).getPointValueInDouble();
                            double temp3=qfls3.get(i).getPointValueInDouble();
                            double temp4=qfls4.get(i).getPointValueInDouble();

                            pd.setPointValueInDouble(StringUtils.round(temp1+temp2+temp3+temp4, 2));
                            qfls.add(pd);
                        }

                        setPointValue(wp, vo, qfls, summap);
                    }

                } else if (targetName.equals(RGZSSDL)) {
                    WindPowerStationTestingPoint gzai =  windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RGZSSDL);
                    WindPowerStationTestingPoint gzslai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RSZSSDL);
                    List<PointData> gzls = new ArrayList<PointData>();
                    try {
                        gzls = realApiUtil.getHistoryDatasSnap(gzai, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    List<PointData> gzslls = new ArrayList<PointData>();
                    ;
                    try {
                        gzslls = realApiUtil.getHistoryDatasSnap(gzslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    setPointValue(wp, vo, gzls, gzslls, summap);
                } else if (targetName.equals(RJXSSDL)) {
                    WindPowerStationTestingPoint jxai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RJXSSDL);
                    WindPowerStationTestingPoint jxslai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RLZSSDL);
                    List<PointData> jxls = new ArrayList<PointData>();
                    try {
                        jxls = realApiUtil.getHistoryDatasSnap(jxai, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    List<PointData> jxslls = new ArrayList<PointData>();
                    try {
                        jxslls = realApiUtil.getHistoryDatasSnap(jxslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    setPointValue(wp, vo, jxls, jxslls, summap);
                } else if (targetName.equals(RSLSSDL)) {
                    WindPowerStationTestingPoint dwai =  windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RWZSSDL);
                    WindPowerStationTestingPoint tqai =  windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.RTZSSDL);
                    List<PointData> dwls = new ArrayList<PointData>();
                    try {
                        dwls = realApiUtil.getHistoryDatasSnap(dwai, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    List<PointData> tqls = new ArrayList<PointData>();
                    try {
                        tqls = realApiUtil.getHistoryDatasSnap(tqai, beginDate.getTime() / 1000, endDate.getTime() / 1000, num, 86400L);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    setPointValue(wp, vo, dwls, tqls, summap);
                }

                resultls.add(vo);
            }

        }
        setTotalValue(summap, resultls);

        map.put("result", resultls);

        // ///////////////////////////////////
        return map;
    }



    private void setTotalValue(Map<String, Double> summap, List<resultVo> resultls) {
        resultVo vo = new resultVo();
        vo.setValue1("合计");
        double value2 = StringUtils.round(summap.get("2"), 2);
        double value3 = StringUtils.round(summap.get("3"), 2);
        double value4 = StringUtils.round(summap.get("4"), 2);
        double value5 = StringUtils.round(summap.get("5"), 2);
        double value6 = StringUtils.round(summap.get("6"), 2);
        double value7 = StringUtils.round(summap.get("7"), 2);
        double value8 = StringUtils.round(summap.get("8"), 2);
        vo.setValue2(String.valueOf(value2));
        vo.setValue3(String.valueOf(value3));
        vo.setValue4(String.valueOf(value4));
        vo.setValue5(String.valueOf(value5));
        vo.setValue6(String.valueOf(value6));
        vo.setValue7(String.valueOf(value7));
        vo.setValue8(String.valueOf(value8));
        resultls.add(vo);
    }

    private void setPointValue(Windpowerstation wp, resultVo vo, List<PointData> ls, Map<String, Double> summap) {
        vo.setValue1(wp.getName());
        if (!ls.isEmpty()) {
            double value2 = StringUtils.round(new BigDecimal(ls.get(1).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value3 = StringUtils.round(new BigDecimal(ls.get(2).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value4 = StringUtils.round(new BigDecimal(ls.get(3).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value5 = StringUtils.round(new BigDecimal(ls.get(4).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value6 = StringUtils.round(new BigDecimal(ls.get(5).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value7 = StringUtils.round(new BigDecimal(ls.get(6).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value8 = StringUtils.round(new BigDecimal(ls.get(7).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);

            vo.setValue2(String.valueOf(value2));
            vo.setValue3(String.valueOf(value3));
            vo.setValue4(String.valueOf(value4));
            vo.setValue5(String.valueOf(value5));
            vo.setValue6(String.valueOf(value6));
            vo.setValue7(String.valueOf(value7));
            vo.setValue8(String.valueOf(value8));

            setSumValues(summap, value2, value3, value4, value5, value6, value7, value8);
        } else {
            double value2 = 0.0;
            double value3 = 0.0;
            double value4 = 0.0;
            double value5 = 0.0;
            double value6 = 0.0;
            double value7 = 0.0;
            double value8 = 0.0;

            vo.setValue2(String.valueOf(value2));
            vo.setValue3(String.valueOf(value3));
            vo.setValue4(String.valueOf(value4));
            vo.setValue5(String.valueOf(value5));
            vo.setValue6(String.valueOf(value6));
            vo.setValue7(String.valueOf(value7));
            vo.setValue8(String.valueOf(value8));

            setSumValues(summap, value2, value3, value4, value5, value6, value7, value8);
        }

    }

    private void setPointValueFdl(Windpowerstation wp, resultVo vo, List<PointData> ls, Map<String, Double> summap) {
        vo.setValue1(wp.getName());
        if (!ls.isEmpty()) {
            double value2 = StringUtils.round(new BigDecimal(ls.get(1).getPointValueInDouble()).divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value3 = StringUtils.round(new BigDecimal(ls.get(2).getPointValueInDouble()).divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value4 = StringUtils.round(new BigDecimal(ls.get(3).getPointValueInDouble()).divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value5 = StringUtils.round(new BigDecimal(ls.get(4).getPointValueInDouble()).divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value6 = StringUtils.round(new BigDecimal(ls.get(5).getPointValueInDouble()).divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value7 = StringUtils.round(new BigDecimal(ls.get(6).getPointValueInDouble()).divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value8 = StringUtils.round(new BigDecimal(ls.get(7).getPointValueInDouble()).divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);

            vo.setValue2(String.valueOf(value2));
            vo.setValue3(String.valueOf(value3));
            vo.setValue4(String.valueOf(value4));
            vo.setValue5(String.valueOf(value5));
            vo.setValue6(String.valueOf(value6));
            vo.setValue7(String.valueOf(value7));
            vo.setValue8(String.valueOf(value8));

            setSumValues(summap, value2, value3, value4, value5, value6, value7, value8);
        } else {
            double value2 = 0.0;
            double value3 = 0.0;
            double value4 = 0.0;
            double value5 = 0.0;
            double value6 = 0.0;
            double value7 = 0.0;
            double value8 = 0.0;

            vo.setValue2(String.valueOf(value2));
            vo.setValue3(String.valueOf(value3));
            vo.setValue4(String.valueOf(value4));
            vo.setValue5(String.valueOf(value5));
            vo.setValue6(String.valueOf(value6));
            vo.setValue7(String.valueOf(value7));
            vo.setValue8(String.valueOf(value8));

            setSumValues(summap, value2, value3, value4, value5, value6, value7, value8);
        }

    }


    private void setSumValues(Map<String, Double> summap, double value2, double value3, double value4, double value5, double value6, double value7, double value8) {
        if (summap.containsKey("2")) {
            double temp = summap.get("2");
            temp = temp + value2;
            summap.put("2", temp);
        } else {
            summap.put("2", value2);
        }
        if (summap.containsKey("3")) {
            double temp = summap.get("3");
            temp = temp + value3;
            summap.put("3", temp);
        } else {
            summap.put("3", value3);
        }
        if (summap.containsKey("4")) {
            double temp = summap.get("4");
            temp = temp + value4;
            summap.put("4", temp);
        } else {
            summap.put("4", value4);
        }
        if (summap.containsKey("5")) {
            double temp = summap.get("5");
            temp = temp + value5;
            summap.put("5", temp);
        } else {
            summap.put("5", value5);
        }
        if (summap.containsKey("6")) {
            double temp = summap.get("6");
            temp = temp + value6;
            summap.put("6", temp);
        } else {
            summap.put("6", value6);
        }
        if (summap.containsKey("7")) {
            double temp = summap.get("7");
            temp = temp + value7;
            summap.put("7", temp);
        } else {
            summap.put("7", value7);
        }
        if (summap.containsKey("8")) {
            double temp = summap.get("8");
            temp = temp + value8;
            summap.put("8", temp);
        } else {
            summap.put("8", value8);
        }
    }

    private void setPointValue(Windpowerstation wp, resultVo vo, List<PointData> ls, List<PointData> ls2, Map<String, Double> summap) {
        vo.setValue1(wp.getName());
        if (!ls.isEmpty() && !ls2.isEmpty()) {
            double value2 = StringUtils.round(new BigDecimal(ls.get(1).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value3 = StringUtils.round(new BigDecimal(ls.get(2).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value4 = StringUtils.round(new BigDecimal(ls.get(3).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value5 = StringUtils.round(new BigDecimal(ls.get(4).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value6 = StringUtils.round(new BigDecimal(ls.get(5).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value7 = StringUtils.round(new BigDecimal(ls.get(6).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value8 = StringUtils.round(new BigDecimal(ls.get(7).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);

            double value12 = StringUtils.round(new BigDecimal(ls2.get(1).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value13 = StringUtils.round(new BigDecimal(ls2.get(2).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value14 = StringUtils.round(new BigDecimal(ls2.get(3).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value15 = StringUtils.round(new BigDecimal(ls2.get(4).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value16 = StringUtils.round(new BigDecimal(ls2.get(5).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value17 = StringUtils.round(new BigDecimal(ls2.get(6).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);
            double value18 = StringUtils.round(new BigDecimal(ls2.get(7).getPointValueInDouble()).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue(), 2);

            value2 = value2 + value12;
            value3 = value3 + value13;
            value4 = value4 + value14;
            value5 = value5 + value15;
            value6 = value6 + value16;
            value7 = value7 + value17;
            value8 = value8 + value18;

            // double result = value2 + value3 + value4 + value5 + value6 +
            // value7 +
            // value8;
            vo.setValue2(String.valueOf(value2));
            vo.setValue3(String.valueOf(value3));
            vo.setValue4(String.valueOf(value4));
            vo.setValue5(String.valueOf(value5));
            vo.setValue6(String.valueOf(value6));
            vo.setValue7(String.valueOf(value7));
            vo.setValue8(String.valueOf(value8));

            setSumValues(summap, value2, value3, value4, value5, value6, value7, value8);
        } else if (!ls.isEmpty() && ls2.isEmpty()) {
            double value2 = StringUtils.round(ls.get(1).getPointValueInDouble(), 2);
            double value3 = StringUtils.round(ls.get(2).getPointValueInDouble(), 2);
            double value4 = StringUtils.round(ls.get(3).getPointValueInDouble(), 2);
            double value5 = StringUtils.round(ls.get(4).getPointValueInDouble(), 2);
            double value6 = StringUtils.round(ls.get(5).getPointValueInDouble(), 2);
            double value7 = StringUtils.round(ls.get(6).getPointValueInDouble(), 2);
            double value8 = StringUtils.round(ls.get(7).getPointValueInDouble(), 2);

            // double result = value2 + value3 + value4 + value5 + value6 +
            // value7 +
            // value8;
            vo.setValue2(String.valueOf(value2));
            vo.setValue3(String.valueOf(value3));
            vo.setValue4(String.valueOf(value4));
            vo.setValue5(String.valueOf(value5));
            vo.setValue6(String.valueOf(value6));
            vo.setValue7(String.valueOf(value7));
            vo.setValue8(String.valueOf(value8));

            setSumValues(summap, value2, value3, value4, value5, value6, value7, value8);
        } else if (ls.isEmpty() && !ls2.isEmpty()) {
            double value2 = StringUtils.round(ls2.get(1).getPointValueInDouble(), 2);
            double value3 = StringUtils.round(ls2.get(2).getPointValueInDouble(), 2);
            double value4 = StringUtils.round(ls2.get(3).getPointValueInDouble(), 2);
            double value5 = StringUtils.round(ls2.get(4).getPointValueInDouble(), 2);
            double value6 = StringUtils.round(ls2.get(5).getPointValueInDouble(), 2);
            double value7 = StringUtils.round(ls2.get(6).getPointValueInDouble(), 2);
            double value8 = StringUtils.round(ls2.get(7).getPointValueInDouble(), 2);

            // double result = value2 + value3 + value4 + value5 + value6 +
            // value7 +
            // value8;
            vo.setValue2(String.valueOf(value2));
            vo.setValue3(String.valueOf(value3));
            vo.setValue4(String.valueOf(value4));
            vo.setValue5(String.valueOf(value5));
            vo.setValue6(String.valueOf(value6));
            vo.setValue7(String.valueOf(value7));
            vo.setValue8(String.valueOf(value8));

            setSumValues(summap, value2, value3, value4, value5, value6, value7, value8);
        }
    }

    /***********************************************************************************************/


    public Map<String, Object> findMonthInfo(String wpId, String targetName) {

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

        Map<String, Double> summap = new TreeMap<String, Double>();

        List<String> datels = new ArrayList<String>();

        List<resultVo> resultls = new ArrayList<resultVo>();

        List<Windpowerstation> wpls = new ArrayList<Windpowerstation>();
        if (StringUtils.empty(wpId) || wpId.equals(FD)) {
            wpId = QS;
        }
        if (wpId.equals("") || wpId.equals(QS)) {
            if (targetName.equals(YFDL)) {
                for (Windpowerstation station : InitialRunner.wpallls) {
                    wpls.add(station);
                }
            } else {
                for (Windpowerstation station : InitialRunner.wpallls) {
                    if (station.getId().endsWith("FDC")) {
                        wpls.add(station);
                    }
                }
            }

        } else if (wpId.equals(FD)) {
            for (Windpowerstation station : InitialRunner.wpallls) {
                if (station.getId().endsWith("FDC")) {
                    wpls.add(station);
                }
            }
        } else if (wpId.equals(GF)) {
            for (Windpowerstation station : InitialRunner.wpallls) {
                if (station.getId().endsWith("GDC")) {
                    wpls.add(station);
                }
            }
        }

        if (!wpls.isEmpty()) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
            Calendar cal = Calendar.getInstance();
            for (int i = 0; i < 3; i++) {
                if (i == 0) {
                    cal.add(Calendar.MONTH, -2);
                } else {
                    cal.add(Calendar.MONTH, 1);
                }
                datels.add(df.format(cal.getTime()));
            }
            map.put("datels", datels);

            for (Windpowerstation wp : wpls) {
                resultVo vo = new resultVo();
                vo.setValue1(wp.getName());

                // public static final String YLZSSDL = "YLZSSDL"; // 月场内受累检修
                // public static final String YSZSSDL = "YSZSSDL"; // 月场内受累故障
                // public static final String YWZSSDL = "YWZSSDL"; // 月场外受累电网
                // public static final String YTZSSDL = "YTZSSDL"; // 月场外受累天气
                // public static final String YQFSSDL = "YQFSSDL"; // 月欠发损失电量
                // public static final String YGZSSDL = "YGZSSDL"; // 月故障损失电量
                // public static final String YJXSSDL = "YJXSSDL"; // 月检修损失电量
                // public static final String YXDSSDL = "YXDSSDL"; // 月限电损失电量
                Calendar c = Calendar.getInstance();
                c.add(Calendar.MONTH, -2);
                c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
                c.set(Calendar.HOUR_OF_DAY, 23);
                c.set(Calendar.MINUTE, 59);
                c.set(Calendar.SECOND, 59);
                Date endDate = c.getTime();
                Date beginDate = c.getTime();
                if (targetName.equals(YFDL)) {
                    WindPowerStationTestingPoint yfdlai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.TPOINT_WP_YFDL);// 月发电量
                    List<PointData> yfdls = new ArrayList<PointData>();
                    double value2 = 0.0;
                    double value3 = 0.0;
                    double value4 = 0.0;
                    vo.setValue1(wp.getName());
                    try {
                        yfdls = realApiUtil.getHistoryDatasSnap(yfdlai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!yfdls.isEmpty())
                        {
                            value2 = StringUtils.round(yfdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value2 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    c.add(Calendar.MONTH, 1);
                    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));

                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        yfdls = realApiUtil.getHistoryDatasSnap(yfdlai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!yfdls.isEmpty())
                        {
                            value3 = StringUtils.round(yfdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value3 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        yfdls = realApiUtil.getHistoryDatasSnap(yfdlai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!yfdls.isEmpty())
                        {
                            value4 = StringUtils.round(yfdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value4 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                } else if (targetName.equals(YXDSSDL)) {
                    WindPowerStationTestingPoint xdai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YXDSSDL);
                    List<PointData> xdls = new ArrayList<PointData>();
                    double value2 = 0.0;
                    double value3 = 0.0;
                    double value4 = 0.0;
                    vo.setValue1(wp.getName());
                    try {
                        xdls = realApiUtil.getHistoryDatasSnap(xdai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!xdls.isEmpty())
                        {
                            value2 = StringUtils.round(xdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value2 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    c.add(Calendar.MONTH, 1);
                    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        xdls = realApiUtil.getHistoryDatasSnap(xdai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!xdls.isEmpty())
                        {
                            value3 = StringUtils.round(xdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value3 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        xdls = realApiUtil.getHistoryDatasSnap(xdai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!xdls.isEmpty())
                        {
                            value4 = StringUtils.round(xdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value4 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value2 = new BigDecimal(value2).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value3 = new BigDecimal(value3).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value4 = new BigDecimal(value4).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                } else if (targetName.equals(YXNSSDL)) {
                    WindPowerStationTestingPoint qfai1 =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YSDJZSDL);
                    WindPowerStationTestingPoint qfai2 =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YSSTZSDL);
                    WindPowerStationTestingPoint qfai3 =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YXNZSDL);
                    WindPowerStationTestingPoint qfai4 =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YSQXZSDL);
                    List<PointData> qfls = new ArrayList<PointData>();

                    double value2 = 0.0;
                    double value3 = 0.0;
                    double value4 = 0.0;
                    vo.setValue1(wp.getName());
                    try {
                        qfls = realApiUtil.getHistoryDatasSnap(qfai1, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value2 = value2+StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai2, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value2 = value2+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai3, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value2 = value2+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai4, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value2 = value2+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    c.add(Calendar.MONTH, 1);
                    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));

                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        qfls = realApiUtil.getHistoryDatasSnap(qfai1, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value3 = value3+StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai2, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value3 = value3+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai3, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value3 = value3+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai4, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value3 = value3+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {

                        qfls = realApiUtil.getHistoryDatasSnap(qfai1, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value4 = value4+StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai2, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value4 = value4+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai3, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value4 = value4+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai4, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value4 = value4+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    value2 = new BigDecimal(value2).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value3 = new BigDecimal(value3).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value4 = new BigDecimal(value4).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                } else if (targetName.equals(YGZSSDL)) {
                    WindPowerStationTestingPoint gzai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YGZSSDL);
                    WindPowerStationTestingPoint gzslai =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YGZSSDL);
                    vo.setValue1(wp.getName());
                    double value2 = 0.0;
                    double value12 = 0.0;
                    double value3 = 0.0;
                    double value13 = 0.0;
                    double value4 = 0.0;
                    double value14 = 0.0;
                    List<PointData> gzls = new ArrayList<PointData>();
                    try {
                        gzls = realApiUtil.getHistoryDatasSnap(gzai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzls.isEmpty())
                        {
                            value2 = StringUtils.round(gzls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value2 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    List<PointData> gzslls = new ArrayList<PointData>();
                    try {
                        gzslls = realApiUtil.getHistoryDatasSnap(gzslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzslls.isEmpty())
                        {
                            value12 = StringUtils.round(gzslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value12 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value2 = value2 + value12;

                    c.add(Calendar.MONTH, 1);
                    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));

                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        gzls = realApiUtil.getHistoryDatasSnap(gzai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzls.isEmpty())
                        {
                            value3 = StringUtils.round(gzls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value3 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        gzslls = realApiUtil.getHistoryDatasSnap(gzslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzslls.isEmpty())
                        {
                            value13 = StringUtils.round(gzslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value13 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    value3 = value3 + value13;
                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        gzls = realApiUtil.getHistoryDatasSnap(gzai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzls.isEmpty())
                        {
                            value4 = StringUtils.round(gzls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value4 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        gzslls = realApiUtil.getHistoryDatasSnap(gzslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzslls.isEmpty())
                        {
                            value14 = StringUtils.round(gzslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value14 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    value4 = value4 + value14;

                    value2 = new BigDecimal(value2).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value3 = new BigDecimal(value3).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value4 = new BigDecimal(value4).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                } else if (targetName.equals(YJXSSDL)) {
                    WindPowerStationTestingPoint jxai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YJXSSDL);
                    WindPowerStationTestingPoint jxslai =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YLZSSDL);
                    vo.setValue1(wp.getName());
                    double value2 = 0.0;
                    double value12 = 0.0;
                    double value3 = 0.0;
                    double value13 = 0.0;
                    double value4 = 0.0;
                    double value14 = 0.0;
                    List<PointData> jxxls = new ArrayList<PointData>();
                    try {
                        jxxls = realApiUtil.getHistoryDatasSnap(jxai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxxls.isEmpty())
                        {
                            value2 = StringUtils.round(jxxls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value2 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    List<PointData> jxslls = new ArrayList<PointData>();
                    try {
                        jxslls = realApiUtil.getHistoryDatasSnap(jxslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxslls.isEmpty())
                        {
                            value12 = StringUtils.round(jxslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value12 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value2 = value2 + value12;
                    c.add(Calendar.MONTH, 1);
                    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));

                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        jxxls = realApiUtil.getHistoryDatasSnap(jxai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxxls.isEmpty())
                        {
                            value3 = StringUtils.round(jxxls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value3= 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        jxslls = realApiUtil.getHistoryDatasSnap(jxslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxslls.isEmpty())
                        {
                            value13 = StringUtils.round(jxslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value13 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value3 = value3 + value13;
                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        jxxls = realApiUtil.getHistoryDatasSnap(jxai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxxls.isEmpty())
                        {
                            value4 = StringUtils.round(jxxls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value4 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        jxslls = realApiUtil.getHistoryDatasSnap(jxslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxslls.isEmpty())
                        {
                            value14 = StringUtils.round(jxslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value14 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value4 = value4 + value14;

                    value2 = new BigDecimal(value2).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value3 = new BigDecimal(value3).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value4 = new BigDecimal(value4).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                } else if (targetName.equals(YSLSSDL)) {
                    WindPowerStationTestingPoint dwai =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YWZSSDL);
                    WindPowerStationTestingPoint tqai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.YTZSSDL);
                    vo.setValue1(wp.getName());
                    double value2 = 0.0;
                    double value12 = 0.0;
                    double value3 = 0.0;
                    double value13 = 0.0;
                    double value4 = 0.0;
                    double value14 = 0.0;
                    List<PointData> dwls = new ArrayList<PointData>();
                    try {
                        dwls = realApiUtil.getHistoryDatasSnap(dwai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!dwls.isEmpty())
                        {
                            value2 = StringUtils.round(dwls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value2 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    List<PointData> tqls = new ArrayList<PointData>();
                    try {
                        tqls = realApiUtil.getHistoryDatasSnap(tqai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!tqls.isEmpty())
                        {
                            value12 = StringUtils.round(tqls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value12 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    vo.setValue1(wp.getName());
                    value2 = value2 + value12;
                    c.add(Calendar.MONTH, 1);
                    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));

                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        dwls = realApiUtil.getHistoryDatasSnap(dwai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!dwls.isEmpty())
                        {
                            value3 = StringUtils.round(dwls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value3 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        tqls = realApiUtil.getHistoryDatasSnap(tqai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!tqls.isEmpty())
                        {
                            value13 = StringUtils.round(tqls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value13 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    value3 = value3 + value13;
                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        dwls = realApiUtil.getHistoryDatasSnap(dwai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!dwls.isEmpty())
                        {
                            value4 = StringUtils.round(dwls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value4 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        tqls = realApiUtil.getHistoryDatasSnap(tqai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!tqls.isEmpty())
                        {
                            value14 = StringUtils.round(tqls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value14 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value4 = value4 + value14;

                    value2 = new BigDecimal(value2).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value3 = new BigDecimal(value3).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value4 = new BigDecimal(value4).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                }

                resultls.add(vo);
            }

        }
        setTotalValueByTime(summap, resultls);

        map.put("result", resultls);

        // ///////////////////////////////////
        return map;
    }

    private void setTotalValueByTime(Map<String, Double> summap, List<resultVo> resultls) {
        resultVo vo = new resultVo();
        vo.setValue1("合计");
        if (summap.containsKey("2")) {
            double value2 = StringUtils.round(summap.get("2"), 2);
            vo.setValue2(String.valueOf(value2));
        }

        if (summap.containsKey("3")) {
            double value3 = StringUtils.round(summap.get("3"), 2);
            vo.setValue3(String.valueOf(value3));
        }

        if (summap.containsKey("4")) {
            double value4 = StringUtils.round(summap.get("4"), 2);
            vo.setValue4(String.valueOf(value4));
        }

        resultls.add(vo);
    }

    private void setSumValuesByTime(Map<String, Double> summap, double value2, double value3, double value4) {
        if (summap.containsKey("2")) {
            double temp = summap.get("2");
            temp = temp + value2;
            summap.put("2", temp);
        } else {
            summap.put("2", value2);
        }
        if (summap.containsKey("3")) {
            double temp = summap.get("3");
            temp = temp + value3;
            summap.put("3", temp);
        } else {
            summap.put("3", value3);
        }
        if (summap.containsKey("4")) {
            double temp = summap.get("4");
            temp = temp + value4;
            summap.put("4", temp);
        } else {
            summap.put("4", value4);
        }

    }
    /***********************************************************************************************************/


    public Map<String, Object> findYearInfo(String wpId, String targetName) {

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

        Map<String, Double> summap = new TreeMap<String, Double>();

        List<String> datels = new ArrayList<String>();

        List<resultVo> resultls = new ArrayList<resultVo>();

        List<Windpowerstation> wpls = new ArrayList<Windpowerstation>();
        if (StringUtils.empty(wpId) || wpId.equals(FD)) {
            wpId = QS;
        }
        if (wpId.equals("") || wpId.equals(QS)) {
            if (targetName.equals(NFDL)) {
                for (Windpowerstation station : InitialRunner.wpallls) {
                    wpls.add(station);
                }
            } else {
                for (Windpowerstation station : InitialRunner.wpallls) {
                    if (station.getId().endsWith("FDC")) {
                        wpls.add(station);
                    }
                }
            }

        } else if (wpId.equals(FD)) {
            for (Windpowerstation station : InitialRunner.wpallls) {
                if (station.getId().endsWith("FDC")) {
                    wpls.add(station);
                }
            }
        } else if (wpId.equals(GF)) {
            for (Windpowerstation station : InitialRunner.wpallls) {
                if (station.getId().endsWith("GDC")) {
                    wpls.add(station);
                }
            }
        }

        if (!wpls.isEmpty()) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy");
            Calendar cal = Calendar.getInstance();
            for (int i = 0; i < 3; i++) {
                if (i == 0) {
                    cal.add(Calendar.YEAR, -2);
                } else {
                    cal.add(Calendar.YEAR, 1);
                }
                datels.add(df.format(cal.getTime()));
            }
            map.put("datels", datels);

            for (Windpowerstation wp : wpls) {
                resultVo vo = new resultVo();
                vo.setValue1(wp.getName());


                // public static final String YLZSSDL = "YLZSSDL"; // 月场内受累检修
                // public static final String YSZSSDL = "YSZSSDL"; // 月场内受累故障
                // public static final String YWZSSDL = "YWZSSDL"; // 月场外受累电网
                // public static final String YTZSSDL = "YTZSSDL"; // 月场外受累天气
                // public static final String YQFSSDL = "YQFSSDL"; // 月欠发损失电量
                // public static final String YGZSSDL = "YGZSSDL"; // 月故障损失电量
                // public static final String YJXSSDL = "YJXSSDL"; // 月检修损失电量
                // public static final String YXDSSDL = "YXDSSDL"; // 月限电损失电量
                Calendar c = Calendar.getInstance();
                c.add(Calendar.YEAR, -1);
                c.set(Calendar.DAY_OF_YEAR, c.getActualMinimum(Calendar.DAY_OF_YEAR));
                c.set(Calendar.HOUR_OF_DAY, 0);
                c.set(Calendar.MINUTE, 0);
                c.set(Calendar.SECOND, 0);
                Date endDate = c.getTime();
                Date beginDate = c.getTime();
                if (targetName.equals(NFDL)) {
                    WindPowerStationTestingPoint yfdlai =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.TPOINT_WP_NFDL);
                    List<PointData> yfdls = new ArrayList<PointData>();
                    double value2 = 0.0;
                    double value3 = 0.0;
                    double value4 = 0.0;
                    vo.setValue1(wp.getName());
                    try {
                        yfdls = realApiUtil.getHistoryDatasSnap(yfdlai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!yfdls.isEmpty())
                        {
                            value2 = StringUtils.round(yfdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value2 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    c.add(Calendar.YEAR, 1);
//                    c.set(Calendar.DAY_OF_YEAR, c.getActualMinimum(Calendar.DAY_OF_YEAR));
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        yfdls = realApiUtil.getHistoryDatasSnap(yfdlai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!yfdls.isEmpty())
                        {
                            value3 = StringUtils.round(yfdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value3 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        yfdls = realApiUtil.getHistoryDatasSnap(yfdlai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!yfdls.isEmpty())
                        {
                            value4 = StringUtils.round(yfdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value4 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                } else if (targetName.equals(NXDSSDL)) {
                    WindPowerStationTestingPoint xdai =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NXDSSDL);
                    List<PointData> xdls = new ArrayList<PointData>();
                    double value2 = 0.0;
                    double value3 = 0.0;
                    double value4 = 0.0;
                    vo.setValue1(wp.getName());
                    try {
                        xdls = realApiUtil.getHistoryDatasSnap(xdai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!xdls.isEmpty())
                        {
                            value2 = StringUtils.round(xdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value2 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    c.add(Calendar.YEAR, 1);
//                    c.set(Calendar.DAY_OF_YEAR, c.getActualMaximum(Calendar.DAY_OF_YEAR));
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        xdls = realApiUtil.getHistoryDatasSnap(xdai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!xdls.isEmpty())
                        {
                            value3 = StringUtils.round(xdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value3 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        xdls = realApiUtil.getHistoryDatasSnap(xdai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!xdls.isEmpty())
                        {
                            value4 = StringUtils.round(xdls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value4 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    value2 = new BigDecimal(value2).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value3 = new BigDecimal(value3).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value4 = new BigDecimal(value4).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                } else if (targetName.equals(NXNSSDL)) {
                    WindPowerStationTestingPoint qfai1 =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NSDJZSDL);
                    WindPowerStationTestingPoint qfai2 = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NSSTZSDL);
                    WindPowerStationTestingPoint qfai3 =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NXNZSDL);
                    WindPowerStationTestingPoint qfai4 =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NSQXZSDL);
                    List<PointData> qfls = new ArrayList<PointData>();

                    double value2 = 0.0;
                    double value3 = 0.0;
                    double value4 = 0.0;
                    vo.setValue1(wp.getName());
                    try {
                        qfls = realApiUtil.getHistoryDatasSnap(qfai1, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value2 = value2+StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai2, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value2 = value2+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai3, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value2 = value2+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai4, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value2 = value2+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    c.add(Calendar.MONTH, 1);
                    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));

                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        qfls = realApiUtil.getHistoryDatasSnap(qfai1, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value3 = value3+StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai2, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value3 = value3+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai3, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value3 = value3+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai4, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value3 = value3+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {

                        qfls = realApiUtil.getHistoryDatasSnap(qfai1, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value4 = value4+StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai2, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value4 = value4+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai3, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value4 = value4+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                        qfls = realApiUtil.getHistoryDatasSnap(qfai4, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!qfls.isEmpty())
                        {
                            value4 = value4+ StringUtils.round(qfls.get(0).getPointValueInDouble(), 2);
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    value2 = new BigDecimal(value2).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value3 = new BigDecimal(value3).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value4 = new BigDecimal(value4).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                } else if (targetName.equals("ngzssdl")) {
                    WindPowerStationTestingPoint gzai =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NGZSSDL);
                    WindPowerStationTestingPoint gzslai =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NSZSSDL);
                    vo.setValue1(wp.getName());
                    double value2 = 0.0;
                    double value12 = 0.0;
                    double value3 = 0.0;
                    double value13 = 0.0;
                    double value4 = 0.0;
                    double value14 = 0.0;
                    List<PointData> gzls = new ArrayList<PointData>();
                    try {
                        gzls = realApiUtil.getHistoryDatasSnap(gzai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzls.isEmpty())
                        {
                            value2 = StringUtils.round(gzls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value2 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    List<PointData> gzslls = new ArrayList<PointData>();
                    try {
                        gzslls = realApiUtil.getHistoryDatasSnap(gzslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzslls.isEmpty())
                        {
                            value12 = StringUtils.round(gzslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value12 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value2 = value2 + value12;

                    c.add(Calendar.YEAR, 1);
//                    c.set(Calendar.DAY_OF_YEAR, c.getActualMaximum(Calendar.DAY_OF_YEAR));
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        gzls = realApiUtil.getHistoryDatasSnap(gzai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzls.isEmpty())
                        {
                            value3 = StringUtils.round(gzls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value3 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        gzslls = realApiUtil.getHistoryDatasSnap(gzslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzslls.isEmpty())
                        {
                            value13 = StringUtils.round(gzslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value13 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    value3 = value3 + value13;
                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        gzls = realApiUtil.getHistoryDatasSnap(gzai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzls.isEmpty())
                        {
                            value4 = StringUtils.round(gzls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value4 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        gzslls = realApiUtil.getHistoryDatasSnap(gzslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!gzslls.isEmpty())
                        {
                            value14 = StringUtils.round(gzslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value14 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    value4 = value4 + value14;

                    value2 = new BigDecimal(value2).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value3 = new BigDecimal(value3).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value4 = new BigDecimal(value4).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                } else if (targetName.equals(NJXSSDL)) {
                    WindPowerStationTestingPoint jxai =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NJXSSDL);
                    WindPowerStationTestingPoint jxslai =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NLZSSDL);
                    vo.setValue1(wp.getName());
                    double value2 = 0.0;
                    double value12 = 0.0;
                    double value3 = 0.0;
                    double value13 = 0.0;
                    double value4 = 0.0;
                    double value14 = 0.0;
                    List<PointData> jxxls = new ArrayList<PointData>();
                    try {
                        jxxls = realApiUtil.getHistoryDatasSnap(jxai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxxls.isEmpty())
                        {
                            value2 = StringUtils.round(jxxls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value2 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    List<PointData> jxslls = new ArrayList<PointData>();
                    try {
                        jxslls = realApiUtil.getHistoryDatasSnap(jxslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxslls.isEmpty())
                        {
                            value12 = StringUtils.round(jxslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value12 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value2 = value2 + value12;
                    c.add(Calendar.YEAR, 1);
//                    c.set(Calendar.DAY_OF_YEAR, c.getActualMaximum(Calendar.DAY_OF_YEAR));
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        jxxls = realApiUtil.getHistoryDatasSnap(jxai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxxls.isEmpty())
                        {
                            value3 = StringUtils.round(jxxls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value3 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        jxslls = realApiUtil.getHistoryDatasSnap(jxslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxslls.isEmpty())
                        {
                            value13 = StringUtils.round(jxslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value13 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value3 = value3 + value13;
                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        jxxls = realApiUtil.getHistoryDatasSnap(jxai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxxls.isEmpty())
                        {
                            value4 = StringUtils.round(jxxls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value4 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        jxslls = realApiUtil.getHistoryDatasSnap(jxslai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!jxslls.isEmpty())
                        {
                            value14 = StringUtils.round(jxslls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value14 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value4 = value4 + value14;

                    value2 = new BigDecimal(value2).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value3 = new BigDecimal(value3).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value4 = new BigDecimal(value4).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                } else if (targetName.equals(NSLSSDL)) {
                    WindPowerStationTestingPoint dwai =windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NWZSSDL);
                    WindPowerStationTestingPoint tqai = windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.NTZSSDL);
                    vo.setValue1(wp.getName());
                    double value2 = 0.0;
                    double value12 = 0.0;
                    double value3 = 0.0;
                    double value13 = 0.0;
                    double value4 = 0.0;
                    double value14 = 0.0;
                    List<PointData> dwls = new ArrayList<PointData>();
                    try {
                        dwls = realApiUtil.getHistoryDatasSnap(dwai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!dwls.isEmpty())
                        {
                            value2 = StringUtils.round(dwls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value2 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    List<PointData> tqls = new ArrayList<PointData>();
                    try {
                        tqls = realApiUtil.getHistoryDatasSnap(tqai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!tqls.isEmpty())
                        {
                            value12 = StringUtils.round(tqls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value12 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    vo.setValue1(wp.getName());
                    value2 = value2 + value12;
                    c.add(Calendar.YEAR, 1);
//                    c.set(Calendar.DAY_OF_YEAR, c.getActualMaximum(Calendar.DAY_OF_YEAR));
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        dwls = realApiUtil.getHistoryDatasSnap(dwai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!dwls.isEmpty())
                        {
                            value3 = StringUtils.round(dwls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value3 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        tqls = realApiUtil.getHistoryDatasSnap(tqai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!tqls.isEmpty())
                        {
                            value13 = StringUtils.round(tqls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value13 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    value3 = value3 + value13;
                    c = Calendar.getInstance();
                    endDate = c.getTime();
                    beginDate = c.getTime();
                    try {
                        dwls = realApiUtil.getHistoryDatasSnap(dwai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!dwls.isEmpty())
                        {
                            value4 = StringUtils.round(dwls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value4 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        tqls = realApiUtil.getHistoryDatasSnap(tqai, beginDate.getTime() / 1000, endDate.getTime() / 1000, 1l, 86400L);
                        if(!tqls.isEmpty())
                        {
                            value14 = StringUtils.round(tqls.get(0).getPointValueInDouble(), 2);
                        }else
                        {
                            value14 = 0.0;
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    value4 = value4 + value14;

                    value2 = new BigDecimal(value2).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value3 = new BigDecimal(value3).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
                    value4 = new BigDecimal(value4).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP).doubleValue();

                    setSumValuesByTime(summap, value2, value3, value4);
                    vo.setValue2(String.valueOf(value2));
                    vo.setValue3(String.valueOf(value3));
                    vo.setValue4(String.valueOf(value4));
                }

                resultls.add(vo);
            }

        }
        setTotalValueByTime(summap, resultls);

        map.put("result", resultls);

        // ///////////////////////////////////
        return map;
    }


    public List<DataVo> findProjectPlanPower(String id) throws Exception {



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

        Map<String, DataVo> vomap = new HashMap<String, DataVo>();

        Map<String, Windpowerstation> wpmap=new HashMap<>();

        for (Windpowerstation wp : InitialRunner.wpallls) {
            if (id.equals(FD)) {
                if (wp.getId().endsWith("FDC")) {
                    wpmap.put(wp.getId(),wp);
                }
            }else if (id.equals(GF)) {
                if (wp.getId().endsWith("GDC")) {
                    wpmap.put(wp.getId(),wp);
                }
            }else if (id.equals(QS)) {
                wpmap.put(wp.getId(),wp);
            }

        }

        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        int year = cal.get(Calendar.YEAR);

        List<ProjectPlan> planls = projectPlanService.getProjectPlanList(String.valueOf(year));

        int month = cal.get(Calendar.MONTH) + 1;

        for (ProjectPlan plan : planls) {

            double fdl = null != plan.getGeneratingcapacity() ? Double.valueOf(plan.getGeneratingcapacity()) : 0.0;

            if (StringUtils.notEmp(plan.getMonth())) {
                int planmonth = Integer.valueOf(plan.getMonth());


                if(wpmap.containsKey(plan.getWindpower()))
                {
                    if (planmonth == month) {
                        if (vomap.containsKey(plan.getWindpower())) {
                            DataVo vo = vomap.get(plan.getWindpower());
                            vo.setValue1(StringUtils.round(vo.getValue1() + fdl, 2));// 月计划发电量
                            vo.setValue2(StringUtils.round(vo.getValue2() + fdl, 2));// 月计划发电量
                            vomap.put(plan.getWindpower(), vo);
                        } else {
                            DataVo vo = new DataVo();
                            if (InitialRunner.wpmap.containsKey(plan.getWindpower())) {
                                Windpowerstation wp = InitialRunner.wpmap.get(plan.getWindpower());
                                vo.setName(wp.getName());
                            } else {
                                vo.setName(plan.getWindpower());
                            }
                            vo.setValue1(fdl);// 月计划发电量
                            vo.setValue2(fdl);// 年计划发电量
                            vomap.put(plan.getWindpower(), vo);
                        }
                    } else {
                        if (vomap.containsKey(plan.getWindpower())) {
                            DataVo vo = vomap.get(plan.getWindpower());
                            vo.setValue2(StringUtils.round(vo.getValue2() + fdl, 2));// 年计划发电量
                            vomap.put(plan.getWindpower(), vo);
                        }
                    }
                }

            }

        }
        Set<Map.Entry<String, DataVo>> set = vomap.entrySet();
        for (Iterator<Map.Entry<String, DataVo>> it = set.iterator(); it.hasNext();) {
            Map.Entry<String, DataVo> entry = (Map.Entry<String, DataVo>) it.next();
            DataVo vo = entry.getValue();

            WindPowerStationTestingPoint yfdlpoint=windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(entry.getKey(), Constant.TPOINT_WP_YFDL);
            WindPowerStationTestingPoint nfdlpoint=windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(entry.getKey(), Constant.TPOINT_WP_NFDL);
            double yfdl = realApiUtil.getRealData(yfdlpoint).getPointValueInDouble();
            double nfdl = realApiUtil.getRealData(nfdlpoint).getPointValueInDouble();

            vo.setValue3(StringUtils.round(yfdl, 2));
            vo.setValue4(StringUtils.round(nfdl, 2));
            vos.add(vo);


        }
        return vos;
    }
}


