package com.gyee.frame.service.goodness;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.spring.Constant;
import com.gyee.frame.mapper.auto.WindturbinegoodnessMapper;
import com.gyee.frame.model.auto.WindTurbineTestingPointAi;
import com.gyee.frame.model.auto.Windturbinegoodness;
import com.gyee.frame.model.auto.WindturbinegoodnessExample;
import com.gyee.frame.model.custom.DataVo;
import com.gyee.frame.model.custom.EchartDataVo;
import com.gyee.frame.model.custom.PointData;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.service.WindTurbineTestingPointAiService;
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.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @ClassName : WindturbinegoodnessService
 * @Author : xieshengjie
 * @Date: 2021/2/20 20:35
 * @Description : 单机性能总览service
 */
@Service
public class WindturbinegoodnessService {
    @Resource
    private WindturbinegoodnessMapper windturbinegoodnessMapper;

    @Resource
    private WindTurbineTestingPointAiService windTurbineTestingPointAiService;

    IRealTimeDataBaseUtil realApiUtil = RealTimeDataBaseFactory.createRealTimeDataBase();

    public PageInfo<Windturbinegoodness> windturbinegoodnessList(Tablepar tablepar, String wpId, String recorddate) {

        WindturbinegoodnessExample example = new WindturbinegoodnessExample();

        if(StringUtils.isNotEmpty(tablepar.getOrderByColumn()))
        {
            StringBuilder sb=new StringBuilder();
            sb.append(" ").append(tablepar.getOrderByColumn());

            example.setOrderByClause(String.valueOf(sb));
        }else {
            example.setOrderByClause("windturbineid");

        }
        StringBuilder sb1=new StringBuilder();
        if(StringUtils.isNotEmpty(tablepar.getIsAsc()))
        {
            sb1.append(" ").append(tablepar.getIsAsc());
            example.setIsAsc(String.valueOf(sb1));
        }else
        {
            example.setIsAsc("asc");
        }



        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());

        WindturbinegoodnessExample.Criteria criteria = example.createCriteria();
        if (StringUtils.notEmp(recorddate) && !recorddate.equals("undefined")) {
            Date date = DateUtils.parseStrtoDate(recorddate);
            Date endDate = DateUtils.addDays(date, 1);
            criteria.andRecorddateGreaterThanOrEqualTo(date).andRecorddateLessThan(endDate);
        }
        if (StringUtils.notEmp(wpId) && !wpId.equals("undefined")) {
            criteria.andWindtpowerstationidEqualTo(wpId);
        }
        List<Windturbinegoodness> list = windturbinegoodnessMapper.selectByExample(example);

        PageInfo<Windturbinegoodness> pageInfo = new PageInfo<Windturbinegoodness>(list);

        return pageInfo;
    }

    /**
     * 初始化折线图数据
     *
     * @return
     */

    public List<DataVo> findWtRealPowerChar(String wtId, Date recorddate) throws Exception {
        List<DataVo> vos = new ArrayList<DataVo>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date endDate = sdfs.parse(sdf.format(DateUtils.addDays(recorddate, 1)) + " 01:00:00");
        Date beginDate = sdfs.parse(sdf.format(recorddate) + " 00:00:00");

        int length = 25;
        for (int i = 0; i < length; i++) {
            DataVo vo = new DataVo();

            vo.setValue1(0.0);// 实发功率
            vo.setValue2(0.0);// 保证功率
            vo.setValue3(0.0);// 风速
            vo.setValue4(0.0);// 状态
            vos.add(vo);
        }



        WindTurbineTestingPointAi sjgl = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.TPOINT_WT_FJGL);
        WindTurbineTestingPointAi bzgl = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.TPOINT_WT_YFGL);
        WindTurbineTestingPointAi pjfs = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.TPOINT_WT_FJSSFS);


       // WindTurbineTestingPointAi2 fs = map.get(Constant.TPOINT_WT_PJFS);

        if (null != sjgl) {
            List<PointData> sjglls = realApiUtil.getHistoryDatasSnap(sjgl, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 3600L);
            int count = 0;
            double temp = 0;
            for (int i = 0; i < vos.size(); i++) {
                vos.get(i).setTime(sjglls.get(i ).getPointTime() * 1000);

                if (i < sjglls.size() && StringUtils.notEmp(sjglls.get(i ).getPointTime())) {

                    if (vos.get(i).getTime() <= DateUtils.now().getTime()) {
                        temp = sjglls.get(i ).getPointValueInDouble();
                        if (Math.abs(temp) < 10000) {
                            vos.get(i).setValue1(StringUtils.round(temp, 2));// 实际功率
                        }

                        count++;
                    } else {
                        vos.get(i).setValue1(0d);// 实际功率
                    }

                }
            }

        }

        if (null != bzgl) {
            List<PointData> bzglls = realApiUtil.getHistoryDatasSnap(bzgl, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 3600L);
            int count = 0;
            double temp = 0;
            for (int i = 0; i < vos.size(); i++) {
                // vos.get(i).setTime(bzglls.get(i).getPointTime() * 1000);
                if (i < bzglls.size() && StringUtils.notEmp(bzglls.get(i ).getPointTime())) {

                    if (vos.get(i).getTime() <= DateUtils.now().getTime()) {
                        temp = bzglls.get(i ).getPointValueInDouble();
                        if (Math.abs(temp) < 10000) {
                            vos.get(i).setValue2(StringUtils.round(temp, 2));// 保证功率
                        }

                        count++;
                    } else {
                        vos.get(i).setValue2(0d);// 保证功率
                    }

                }
            }

        }

        if (null != pjfs) {
            List<PointData> pjfsls = realApiUtil.getHistoryDatasSnap(pjfs, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 3600L);

            int count = 0;
            double temp = 0;
            for (int i = 0; i < vos.size(); i++) {
                vos.get(i).setTime(pjfsls.get(i ).getPointTime() * 1000);
                if (i < pjfsls.size() && StringUtils.notEmp(pjfsls.get(i ).getPointTime())) {

                    if (vos.get(i).getTime() <= DateUtils.now().getTime()) {
                        temp = pjfsls.get(i ).getPointValueInDouble();
                        vos.get(i).setValue3(StringUtils.round(temp, 2));// 风速
                        count++;
                    } else {
                        vos.get(i).setValue3(0d);// 实际功率
                    }

                }
            }

        }

        // if (null != fjzt) {
        // List<PointData> fjztls = ednaApiUtil.getHistoryDatasSnap(fjzt,
        // beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length,
        // 3600L);
        // int count = 0;
        // double temp = 0;
        // for (int i = 0; i < vos.size(); i++) {
        // vos.get(i).setTime(fjztls.get(i).getPointTime() * 1000);
        // if (i < fjztls.size() &&
        // StringUtils.notEmp(fjztls.get(i).getPointTime())) {
        //
        // if (vos.get(i).getTime() <= DateUtils.now().getTime()) {
        // temp = fjztls.get(i).getPointValueInDouble();
        // if (Math.abs(temp) < 10000) {
        // vos.get(i).setValue4(StringUtils.round(temp, 2));// 风机状态
        // }
        //
        // count++;
        // } else {
        // vos.get(i).setValue4(0d);// 风机状态
        // }
        //
        // }
        // }
        //
        // }

        // ////////////////////////////////////////////////

        return vos;
    }
    public List<List<EchartDataVo>> getplotBands(String wtId, Date recorddate) throws Exception {

        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Calendar c = Calendar.getInstance();
        c.setTime(recorddate);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND,0);


        Date beginDate = c.getTime();
        c.add(Calendar.DAY_OF_MONTH, 1);
        Date endDate = c.getTime();



        List<String> xtime=new ArrayList<>();
        List<EchartDataVo> vos=new ArrayList<>();
        List<List<EchartDataVo>> resultvos=new ArrayList<>();
        Map<String,String> map=new HashMap<>();
        int length = 240;
        String plotBands = null;
        StringBuilder sb = new StringBuilder("");

        WindTurbineTestingPointAi fjzt = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.FJZT);

        String beginTime=null;
        String endTime=null;
        String time=null;

            if (null != fjzt) {
                List<PointData> fjztls = realApiUtil.getHistoryDatasSnap(fjzt, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 360L);


                int zt = 0;
                for (int i = 0; i < fjztls.size(); i++) {
                    if (i < fjztls.size()) {

                        PointData pd=fjztls.get(i);
                        int zttemp = Double.valueOf(pd.getPointValueInDouble()).intValue();
                        Date resultDate = new Date(pd.getPointTime() * 1000);
                        beginTime = sdf.format(resultDate);
                        time=sdf2.format(resultDate);
                        xtime.add(beginTime);
                        if (i == 0) {
                            zt = zttemp;
                            EchartDataVo vo = new EchartDataVo();
                            vo.setxAxis(beginTime);
                            vo.setTime1(time);
                            vo.setName(judgeSatte(zttemp));

                            EchartDataVo.ItemStyle item= vo.new ItemStyle();
                            item.setColor(judgeColor(zttemp));
                            vo.setItemStyle(item);

                            vos.add(vo);
                        } else {
                            if (zt != zttemp) {
                                zt = zttemp;
                                c = Calendar.getInstance();
                                c.setTime(resultDate);
//                                c.add(Calendar.MINUTE, -6);
                                endTime = sdf.format(c.getTime());
                                time=sdf2.format(c.getTime());

                                vos.get(0).setTime2(time);
                                EchartDataVo vo = new EchartDataVo();
                                vo.setxAxis(endTime);
                                vos.add(vo);


                                if (vos.size() == 2) {
                                    resultvos.add(vos);
                                    vos = new ArrayList<>();
                                    vo = new EchartDataVo();
                                    vo.setxAxis(beginTime);
                                    vo.setTime1(sdf2.format(resultDate));
                                    vo.setName(judgeSatte(zttemp));
                                    EchartDataVo.ItemStyle item= vo.new ItemStyle();
                                    item.setColor(judgeColor(zttemp));
                                    vo.setItemStyle(item);
                                    vos.add(vo);
                                }
                            }else if(i==fjztls.size()-1)
                            {
                                zt = zttemp;
                                c = Calendar.getInstance();
                                c.setTime(resultDate);
//                                c.add(Calendar.MINUTE, -6);
                                endTime = sdf.format(c.getTime());
                                time=sdf2.format(c.getTime());

                                vos.get(0).setTime2(time);
                                EchartDataVo vo = new EchartDataVo();
                                vo.setxAxis(endTime);
                                vos.add(vo);
                                resultvos.add(vos);
                            }

                        }

                    }

                }
            }
        return resultvos;
    }

    private  String judgeSatte(int zt)
    {
        String ztname=null;
        switch ( zt ) {
            case 0:
                ztname= "待机";
                break;
            case 1:
                ztname= "运行";
                break;
            case 2:
                ztname= "故障";
                break;
            case 3:
                ztname= "中断";
                break;
            case 4:
                ztname= "维护";
                break;
            case 5:
                ztname= "限电停机";
                break;
            case 6:
                ztname= "限电出力";
                break;
            default:

        }
        return ztname;
    }
//    运行 #08FCF0 待机 #34A90A  维护 #FD7D1C 故障 #FD0100 限电 #D201D8 离线 #A6A6A6
    private  String judgeColor(int zt)
    {
        String ztname=null;
        switch ( zt ) {
            case 0:
                ztname= "#BFFFDF";
                break;
            case 1:
                ztname= "#E7FFFF";
                break;
            case 2:
                ztname= "#FFBFBF";
                break;
            case 3:
                ztname= "#DDDDDD";
                break;
            case 4:
                ztname= "#FFDFBF";
                break;
            case 5:
                ztname= "#FFDFFF";
                break;
            case 6:
                ztname= "#FFDFFF";
                break;
            default:

        }
        return ztname;
    }

    public Map<String, String> getPlotBand(String wtId , String begin, String end) throws Exception {
        WindTurbineTestingPointAi fdlAi =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.TPOINT_WT_RFDL);
        WindTurbineTestingPointAi fsAi = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.TPOINT_WT_FJSSFS);
        WindTurbineTestingPointAi llfdlAi =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.TPOINT_WT_RFDLBZ);
        WindTurbineTestingPointAi glAi = windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.TPOINT_WT_FJGL);
        WindTurbineTestingPointAi fjztAi =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.FJZT);
         String sdf = "yyyy-MM-dd HH:mm";
        Date begindate=DateUtils.parseStrtoDate(begin,sdf);
        Date enddate=DateUtils.parseStrtoDate(end,sdf);
        Map<String, String> tempmap = new HashMap<String, String>();

        // 发电量
        double beginfdl = 0.0;
        double endfdl = 0.0;
        double fdl = 0.0;

//        String[] id=new String[1];
//        DNAVal[] val= realApiUtil.getHistMatrix(id,begindate.getTime() / 1000);
//        beginfdl=val[0].DValue;
//        val= realApiUtil.getHistMatrix(id,enddate.getTime() / 1000);
//        endfdl=val[0].DValue;
        List<PointData> beginfdlls = realApiUtil.getHistoryDatasSnap(fdlAi,
                begindate.getTime() / 1000, begindate.getTime() / 1000,
                (long) 1, 3600L);
        if (!beginfdlls.isEmpty()) {
            beginfdl = beginfdlls.get(0).getPointValueInDouble();
        }
        List<PointData> endfdlls = realApiUtil.getHistoryDatasSnap(fdlAi,
                enddate.getTime() / 1000, enddate.getTime() / 1000, (long) 1,
                3600L);
        if (!endfdlls.isEmpty()) {
            endfdl = endfdlls.get(0).getPointValueInDouble();
        }
        fdl = endfdl - beginfdl;

        tempmap.put("fdl", String.valueOf(StringUtils.round(fdl, 2)));
        // 理论电量
        double beginllfdl = 0.0;
        double endllfdl = 0.0;
        double llfdl = 0.0;
        List<PointData> beginllfdls = realApiUtil.getHistoryDatasSnap(llfdlAi,
                begindate.getTime() / 1000, begindate.getTime() / 1000,
                (long) 1, 3600L);
        if (!beginllfdls.isEmpty()) {
            beginllfdl = beginllfdls.get(0).getPointValueInDouble();
        }
        List<PointData> endllfdls = realApiUtil.getHistoryDatasSnap(llfdlAi,
                enddate.getTime() / 1000, enddate.getTime() / 1000, (long) 1,
                3600L);
        if (!endllfdls.isEmpty()) {
            endllfdl = endllfdls.get(0).getPointValueInDouble();
        }
        llfdl = endllfdl - beginllfdl;
        // llfdl=new BigDecimal(llfdl).multiply(new
        // BigDecimal(10000)).doubleValue();

        tempmap.put("llfdl", String.valueOf(StringUtils.round(llfdl, 2)));

        // 风机状态
        int fjzt = 0;
        List<PointData> fjztls = realApiUtil.getHistoryDatasSnap(fjztAi,
                begindate.getTime() / 1000, enddate.getTime() / 1000, (long) 1,
                3600L);
        if (!fjztls.isEmpty()) {
            fjzt =  Double.valueOf(fjztls.get(0).getPointValueInDouble()).intValue();

            tempmap.put("fjzt", judgeSatte(fjzt));

        }

        // 风速
        double fs = 0.0;
        Double time1 = new BigDecimal(DateUtils.minutesDiff(begindate, enddate))
                .divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN)
                .doubleValue();

        List<PointData> fsls = realApiUtil.getHistoryDatasSnap(fsAi,
                begindate.getTime() / 1000, enddate.getTime() / 1000,
                (long) time1.longValue(), 3600L);
        if (!fsls.isEmpty()) {
            for (PointData po : fsls) {
                fs = fs + po.getPointValueInDouble();
            }
            if (time1 == 0) {
                time1 = 1.0;
            }
            double fstemp = new BigDecimal(fs).divide(
                    new BigDecimal(time1.doubleValue()), 2,
                    RoundingMode.HALF_EVEN).doubleValue();
            tempmap.put("fs", String.valueOf(StringUtils.round(fstemp, 2)));
        }
        // 功率
        double gl = 0.0;
        Double time2 = new BigDecimal(DateUtils.minutesDiff(begindate, enddate))
                .divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN)
                .doubleValue();
        List<PointData> glls = realApiUtil.getHistoryDatasSnap(glAi,
                begindate.getTime() / 1000, enddate.getTime() / 1000,
                (long) time2.longValue(), 3600L);
        if (!glls.isEmpty()) {
            for (PointData po : glls) {
                gl = gl + po.getPointValueInDouble();
            }
            if (time2 == 0) {
                time2 = 1.0;
            }
            double gltemp = new BigDecimal(gl).divide(
                    new BigDecimal(time2.doubleValue()), 2,
                    RoundingMode.HALF_EVEN).doubleValue();
            tempmap.put("gl", String.valueOf(StringUtils.round(gltemp, 2)));
        }
        // 时长
        tempmap.put("sc", String.valueOf(StringUtils.round(DateUtils.hoursDiff2(begindate, enddate), 2)));

        // 损失电量

        if (fjzt != 1) {
            fdl = 0.0;
            tempmap.put("fdl", "0.0");
            tempmap.put("gl", "0.0");
        }
        tempmap.put("ssdl", String.valueOf(StringUtils.round(llfdl - fdl, 2)));
        tempmap.put("ks", begin);
        tempmap.put("js", end);
        return tempmap;
    }

    private String getColor(StringBuilder temp, Integer zt) {
        if (StringUtils.notEmp(zt)) {
            switch (zt) {
                case 0:
                    temp.setLength(0);
                    temp.append("color: '#BFFFDF',");
                    break;
                case 1:
                    temp.setLength(0);
                    temp.append("color: '#E7FFFF',");
                    break;
                case 2:
                    temp.setLength(0);
                    temp.append("color: '#FFBFBF',");
                    break;
                case 3:
                    temp.setLength(0);
                    temp.append("color: '#DDDDDD',");
                    break;
                case 4:
                    temp.setLength(0);
                    temp.append("color: '#FFDFBF',");
                    break;
                case 5:
                    temp.setLength(0);
                    temp.append("color: '#FFDFFF',");
                    break;
                case 6:
                    temp.setLength(0);
                    temp.append("color: '#FFDFFF',");
                    break;
                default:
                    break;
            }
        }
        return String.valueOf(temp);
    }

    public List<DataVo> findRealPowerCharBy24(String wtId, Date recorddate) throws Exception {
        List<DataVo> vos = new ArrayList<DataVo>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date endDate = sdfs.parse(sdf.format(DateUtils.addDays(recorddate, 1)) + " 00:0:00");
        Date beginDate = sdfs.parse(sdf.format(recorddate) + " 00:00:00");

        int length = 24;
        for (int i = 0; i < length; i++) {
            DataVo vo = new DataVo();

            vo.setValue1(0.0);// scada发电量
            vo.setValue2(0.0);// 维护损失
            vo.setValue3(0.0);// 故障损失
            vo.setValue4(0.0);// 限电损失
            vo.setValue5(0.0);// 欠发损失
            vo.setValue6(0.0);// 风速

            vos.add(vo);
        }



        WindTurbineTestingPointAi fdl =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.TPOINT_WT_RFDL);
        WindTurbineTestingPointAi whss =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.RJXSSDL);
        WindTurbineTestingPointAi gzss =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.RGZSSDL);
        WindTurbineTestingPointAi xdss =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.RXDSSDL);
        WindTurbineTestingPointAi qfss =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.RQFSSDL);
        WindTurbineTestingPointAi fs =windTurbineTestingPointAiService.getWindTurbineTestingPointAi2(wtId,Constant.TPOINT_WT_FJSSFS);

        try {
            if (null != fdl) {
                List<PointData> fdlls = realApiUtil.getHistoryDatasSnap(fdl, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 3600L);

                int count = 0;
                double temp1 = 0;
                for (int i = 0; i < length; i++) {

                    if (i < fdlls.size() && StringUtils.notEmp(fdlls.get(i + 1).getPointTime())) {
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        vos.get(i).setTime(fdlls.get(i + 1).getPointTime() * 1000);
                        if (vos.get(i).getTime() <= DateUtils.now().getTime()) {

                            if (i != 0) {
                                temp1 = fdlls.get(i + 1).getPointValueInDouble();
                                double temp2 = fdlls.get(i).getPointValueInDouble();
                                temp1 = temp1 - temp2;
                                vos.get(i).setValue1(StringUtils.round(temp1, 2));// 发电量

                            } else {
                                temp1 = fdlls.get(i + 1).getPointValueInDouble();
                                vos.get(i).setValue1(StringUtils.round(temp1, 2));// 发电量
                            }
                            // temp1 = new BigDecimal(temp1).divide(new
                            // BigDecimal(10000), 2,
                            // RoundingMode.HALF_EVEN).doubleValue();

                            // temp1 = new BigDecimal(temp1).divide(
                            // new BigDecimal(100000), 2,
                            // RoundingMode.HALF_EVEN).multiply(
                            // new BigDecimal(100)).doubleValue();

                            count++;
                        } else {
                            vos.get(i).setTime(fdlls.get(i).getPointTime() * 1000);
                            vos.get(i).setValue1(0d);// 发电量
                        }

                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        /*
         * 维护损失
         */
        try {
            if (null != whss) {
                List<PointData> whssls = realApiUtil.getHistoryDatasSnap(whss, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 3600L);

                int count = 0;
                double temp1 = 0;
                for (int i = 0; i < length; i++) {

                    if (i < whssls.size() && StringUtils.notEmp(whssls.get(i + 1).getPointTime())) {
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        vos.get(i).setTime(whssls.get(i + 1).getPointTime() * 1000);
                        if (vos.get(i).getTime() <= DateUtils.now().getTime()) {
                            if (i != 0) {
                                temp1 = whssls.get(i + 1).getPointValueInDouble();
                                double temp2 = whssls.get(i).getPointValueInDouble();
                                temp1 = temp1 - temp2;

                                // temp1 = new BigDecimal(temp1).divide(new
                                // BigDecimal(10000), 2,
                                // RoundingMode.HALF_EVEN).doubleValue();
                                vos.get(i).setValue2(StringUtils.round(temp1, 2));// 维护损失电量

                                count++;

                            } else {
                                temp1 = whssls.get(i + 1).getPointValueInDouble();
                                vos.get(i).setValue2(StringUtils.round(temp1, 2));// 维护损失电量
                            }

                            // temp1 = new BigDecimal(temp1).divide(
                            // new BigDecimal(100000), 2,
                            // RoundingMode.HALF_EVEN).multiply(
                            // new BigDecimal(100)).doubleValue();

                        } else {
                            // vos.get(i-1).setTime(whssls.get(i).getPointTime()*1000);
                            vos.get(i).setValue2(0d);// 维护损失电量
                        }

                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        /*
         * 故障损失
         */
        try {
            if (null != gzss) {
                List<PointData> gzssls = realApiUtil.getHistoryDatasSnap(gzss, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 3600L);

                int count = 0;
                double temp1 = 0;
                for (int i = 0; i < length; i++) {

                    if (i < gzssls.size() && StringUtils.notEmp(gzssls.get(i + 1).getPointTime())) {
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        vos.get(i).setTime(gzssls.get(i + 1).getPointTime() * 1000);
                        if (vos.get(i).getTime() <= DateUtils.now().getTime()) {
                            if (i != 0) {
                                temp1 = gzssls.get(i + 1).getPointValueInDouble();
                                double temp2 = gzssls.get(i).getPointValueInDouble();
                                temp1 = temp1 - temp2;

                                // temp1 = new BigDecimal(temp1).divide(new
                                // BigDecimal(10000), 2,
                                // RoundingMode.HALF_EVEN).doubleValue();

                                // temp1 = new BigDecimal(temp1).divide(
                                // new BigDecimal(100000), 2,
                                // RoundingMode.HALF_EVEN).multiply(
                                // new BigDecimal(100)).doubleValue();

                                vos.get(i).setValue3(StringUtils.round(temp1, 2));// 维护损失电量

                                count++;

                            } else {
                                temp1 = gzssls.get(i + 1).getPointValueInDouble();
                                vos.get(i).setValue3(StringUtils.round(temp1, 2));// 维护损失电量
                            }

                        } else {
                            // vos.get(i-1).setTime(gzssls.get(i).getPointTime()*1000);
                            vos.get(i).setValue3(0d);// 维护损失电量
                        }

                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        /*
         * 限电损失
         */
        try {
            if (null != xdss) {
                List<PointData> xdssls = realApiUtil.getHistoryDatasSnap(xdss, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 3600L);

                int count = 0;
                double temp1 = 0;
                for (int i = 0; i < length; i++) {

                    if (i < xdssls.size() && StringUtils.notEmp(xdssls.get(i + 1).getPointTime())) {
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        vos.get(i).setTime(xdssls.get(i + 1).getPointTime() * 1000);
                        if (vos.get(i).getTime() <= DateUtils.now().getTime()) {
                            if (i != 0) {
                                temp1 = xdssls.get(i + 1).getPointValueInDouble();
                                double temp2 = xdssls.get(i).getPointValueInDouble();
                                temp1 = temp1 - temp2;

                                // temp1 = new BigDecimal(temp1).divide(new
                                // BigDecimal(10000), 2,
                                // RoundingMode.HALF_EVEN).doubleValue();

                                // temp1 = new BigDecimal(temp1).divide(
                                // new BigDecimal(100000), 2,
                                // RoundingMode.HALF_EVEN).multiply(
                                // new BigDecimal(100)).doubleValue();

                                vos.get(i).setValue4(StringUtils.round(temp1, 2));// 限电损失电量

                                count++;

                            } else {
                                temp1 = xdssls.get(i + 1).getPointValueInDouble();
                                vos.get(i).setValue4(StringUtils.round(temp1, 2));// 限电损失电量
                            }

                        } else {
                            // vos.get(i).setTime(xdssls.get(i).getPointTime()*1000);
                            vos.get(i).setValue4(0d);// 限电损失电量
                        }

                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        /*
         * 欠发损失
         */
        try {
            if (null != qfss) {
                List<PointData> qfssls = realApiUtil.getHistoryDatasSnap(qfss, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 3600L);

                int count = 0;
                double temp1 = 0;
                for (int i = 0; i < length; i++) {

                    if (i < qfssls.size() && StringUtils.notEmp(qfssls.get(i + 1).getPointTime())) {
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        vos.get(i).setTime(qfssls.get(i + 1).getPointTime() * 1000);
                        if (vos.get(i).getTime() <= DateUtils.now().getTime()) {
                            if (i != 0) {
                                temp1 = qfssls.get(i + 1).getPointValueInDouble();
                                double temp2 = qfssls.get(i).getPointValueInDouble();
                                temp1 = temp1 - temp2;

                                // temp1 = new BigDecimal(temp1).divide(new
                                // BigDecimal(10000), 2,
                                // RoundingMode.HALF_EVEN).doubleValue();

                                // temp1 = new BigDecimal(temp1).divide(
                                // new BigDecimal(100000), 2,
                                // RoundingMode.HALF_EVEN).multiply(
                                // new BigDecimal(100)).doubleValue();

                                vos.get(i).setValue5(StringUtils.round(temp1, 2));// 欠发损失电量

                                count++;

                            } else {
                                temp1 = qfssls.get(i + 1).getPointValueInDouble();
                                vos.get(i).setValue5(StringUtils.round(temp1, 2));// 欠发损失电量
                            }

                        } else {
                            // vos.get(i-1).setTime(qfssls.get(i).getPointTime()*1000);
                            vos.get(i).setValue5(0d);// 欠发损失电量
                        }

                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        /*
         * 风速
         */
        try {
            if (null != fs) {
                List<PointData> fsls = realApiUtil.getHistoryDatasSnap(fs, beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 3600L);

                int count = 0;
                double temp1 = 0;
                for (int i = 0; i < 24; i++) {

                    if (i < fsls.size() && StringUtils.notEmp(fsls.get(i + 1).getPointTime())) {
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        vos.get(i).setTime(fsls.get(i + 1).getPointTime() * 1000);
                        if (vos.get(i).getTime() <= DateUtils.now().getTime()) {

                            temp1 = fsls.get(i + 1).getPointValueInDouble();
                            // double temp2
                            // =fsls.get(i-1).getPointValueInDouble();
                            // temp1=temp1-temp2;

                            // temp1 = new BigDecimal(temp1).divide(new
                            // BigDecimal(1), 2,
                            // RoundingMode.HALF_EVEN).doubleValue();

                            // temp1 = new BigDecimal(temp1).divide(
                            // new BigDecimal(100000), 2,
                            // RoundingMode.HALF_EVEN).multiply(
                            // new BigDecimal(100)).doubleValue();

                            vos.get(i).setValue6(StringUtils.round(temp1, 2));// 风速
                            count++;

                            // else
                            // {
                            // temp1 = qfssls.get(i).getPointValueInDouble();
                            // }

                        } else {
                            // vos.get(i-1).setTime(qfssls.get(i).getPointTime()*1000);
                            vos.get(i).setValue6(0d);// 风速
                        }

                    }
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        // ////////////////////////////////////////////////

        return vos;
    }
}
