package com.gyee.frame.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.base.BaseService;
import com.gyee.frame.common.spring.InitialRunner;
import com.gyee.frame.common.support.Convert;
import com.gyee.frame.mapper.auto.Windturbineinfoday3Mapper;
import com.gyee.frame.model.auto.*;
import com.gyee.frame.model.custom.SingleAnalysisVo;
import com.gyee.frame.model.custom.Tablepar;
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.util.*;

/**
 * 风机信息表 Windturbineinfoday3Service
 *
 * @Title: Windturbineinfoday3Service.java 
 * @Package com.gyee.frame.service 
 **/
@Service
public class Windturbineinfoday3Service implements BaseService<Windturbineinfoday3, Windturbineinfoday3Example> {
    @Resource
    private Windturbineinfoday3Mapper windturbineinfoday3Mapper;


    /**
     * 分页查询
     *
     * @param tablepar
     * @param name
     * @return
     */
    public PageInfo<Windturbineinfoday3> list(Tablepar tablepar, String name) {
        Windturbineinfoday3Example testExample = new Windturbineinfoday3Example();
        testExample.setOrderByClause("id ASC");
        if (name != null && !"".equals(name)) {
//	        	testExample.createCriteria().and.andCodeLike("%"+name+"%");
        }

        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
        List<Windturbineinfoday3> list = windturbineinfoday3Mapper.selectByExample(testExample);
        PageInfo<Windturbineinfoday3> pageInfo = new PageInfo<Windturbineinfoday3>(list);
        return pageInfo;
    }

    @Override
    public int deleteByPrimaryKey(String ids) {

        List<Integer> lista = Convert.toIntArrayList(ids);
        Windturbineinfoday3Example example = new Windturbineinfoday3Example();
        example.createCriteria().andIdIn(lista);
        return windturbineinfoday3Mapper.deleteByExample(example);


    }


    @Override
    public Windturbineinfoday3 selectByPrimaryKey(String id) {

        if (StringUtils.isNotEmpty(id)) {
            return windturbineinfoday3Mapper.selectByPrimaryKey(Integer.valueOf(id));

        }
        return new Windturbineinfoday3();

    }


    @Override
    public int updateByPrimaryKeySelective(Windturbineinfoday3 record) {
        return windturbineinfoday3Mapper.updateByPrimaryKeySelective(record);
    }


    /**
     * 添加
     */
    @Override
    public int insertSelective(Windturbineinfoday3 record) {

//		//添加雪花主键id
//		record.setId(SnowflakeIdWorker.getUUID());


        return windturbineinfoday3Mapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(Windturbineinfoday3 record, Windturbineinfoday3Example example) {

        return windturbineinfoday3Mapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(Windturbineinfoday3 record, Windturbineinfoday3Example example) {

        return windturbineinfoday3Mapper.updateByExample(record, example);
    }

    @Override
    public List<Windturbineinfoday3> selectByExample(Windturbineinfoday3Example example) {

        return windturbineinfoday3Mapper.selectByExample(example);
    }


    @Override
    public long countByExample(Windturbineinfoday3Example example) {

        return windturbineinfoday3Mapper.countByExample(example);
    }


    @Override
    public int deleteByExample(Windturbineinfoday3Example example) {

        return windturbineinfoday3Mapper.deleteByExample(example);
    }

    public List<Windturbineinfoday3> getWindturbineinfo(Date beginDate, Date endDate, String wtId) {


        List<Windturbineinfoday3> list = null;

        if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            Windturbineinfoday3Example example = new Windturbineinfoday3Example();
            example.setOrderByClause("recorddate DESC");

            if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {


                example.createCriteria().andWindpowerstationidLike("%FDC").andWindturbineidEqualTo(wtId).andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);
                list = windturbineinfoday3Mapper.selectByExample(example);
            } else {
                list = new ArrayList<>();
            }

        }
        return list;

    }


    public List<Windturbineinfoday3> getWindturbineinfo(String wpIds, String pjIds, String lineIds, Date beginDate,
                                                        Date endDate, String sortName, String sortOrder) {
        List<Windturbineinfoday3> ls = null;
		List<Windturbineinfoday3> vos = new ArrayList<Windturbineinfoday3>();
		List<Windturbineinfoday3> vosapp = new ArrayList<Windturbineinfoday3>();
        if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            Windturbineinfoday3Example example = new Windturbineinfoday3Example();
            example.setOrderByClause("recorddate DESC");

            Windturbineinfoday3Example.Criteria criteia = example.createCriteria();
            if (StringUtils.isNotEmpty(wpIds)) {

                criteia.andWindpowerstationidEqualTo(wpIds).andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);
                if (StringUtils.isNotEmpty(pjIds)) {
                    String[] projectarr = pjIds.split(",");
                    List<String> projectls = Arrays.asList(projectarr);
                    criteia.andProjectidIn(projectls);
                }

                if (StringUtils.isNotEmpty(lineIds)) {
                    String[] linearr = lineIds.split(",");
                    List<String> linels = Arrays.asList(linearr);
                    criteia.andLineidIn(linels);
                }

            } else {
                criteia.andWindpowerstationidLike("%FDC%").andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);

            }

            ls = windturbineinfoday3Mapper.selectByExample(example);


            long num = 0;
            if (!ls.isEmpty()) {
                Map<String, Windturbineinfoday3> map = new TreeMap<String, Windturbineinfoday3>();

                for (int i = 0; i < ls.size(); i++) {

                    if (map.containsKey(ls.get(i).getWindturbineid())) {
                        Windturbineinfoday3 oldwd = map.get(ls.get(i).getWindturbineid());
                        num++;
                        double sfdl = null != ls.get(i).getDaydl2() ? StringUtils.round(ls.get(i).getDaydl2(), 2) : 0.0;
                        double yfdl = null != ls.get(i).getDaynhdl() ? ls.get(i).getDaynhdl() : 0.0;
                        double gzzdl = null != ls.get(i).getDaynhgzssdl() ? ls.get(i).getDaynhgzssdl() : 0.0;
                        double whdl = null != ls.get(i).getDaynhwhssdl() ? ls.get(i).getDaynhwhssdl() : 0.0;
                        double xddl = null != ls.get(i).getDaynhxdssdl() ? ls.get(i).getDaynhxdssdl() : 0.0;
                        double qfdl = null != ls.get(i).getDaynhqfdl() ? ls.get(i).getDaynhqfdl() : 0.0;
                        double dayspeed = null != ls.get(i).getDayspeed() ? ls.get(i).getDayspeed() : 0.0;
                        double cfdl = null != ls.get(i).getDaynhcfdl() ? ls.get(i).getDaynhcfdl() : 0.0;

                        oldwd.setDaydl2(oldwd.getDaydl2() + StringUtils.round(sfdl, 4));
                        oldwd.setDaynhdl(oldwd.getDaynhdl() + StringUtils.round(yfdl, 4));
                        oldwd.setDaynhgzssdl(oldwd.getDaynhgzssdl() + StringUtils.round(gzzdl, 4));
                        oldwd.setDaynhwhssdl(oldwd.getDaynhwhssdl() + StringUtils.round(whdl, 4));
                        oldwd.setDaynhxdssdl(oldwd.getDaynhxdssdl() + StringUtils.round(xddl, 4));
                        oldwd.setDaynhqfdl(oldwd.getDaynhqfdl() + StringUtils.round(qfdl, 4));
                        oldwd.setDaynhcfdl(oldwd.getDaynhcfdl() + StringUtils.round(cfdl, 4));
                        oldwd.setDayspeed((oldwd.getDayspeed() * (num - 1) + dayspeed) / num);
                        oldwd.setWindpowerstationid(ls.get(i).getWindpowerstationid());
                        oldwd.setProjectid(ls.get(i).getProjectid());
                        oldwd.setLineid(ls.get(i).getLineid());
                        map.put(ls.get(i).getWindturbineid(), oldwd);
                    } else {
                        num = 1;
                        Windturbineinfoday3 oldwd = new Windturbineinfoday3();
                        oldwd.setWtName(ls.get(i).getWindturbineid());
                        oldwd.setWtId(ls.get(i).getWindturbineid());
                        oldwd.setDaydl2(null != ls.get(i).getDaydl2() ? StringUtils.round(ls.get(i).getDaydl2(), 2) : 0.0);
                        oldwd.setDaynhdl(
                                null != ls.get(i).getDaynhdl2() ? StringUtils.round(ls.get(i).getDaynhdl(), 4) : 0.0);
                        oldwd.setDaynhgzssdl(null != ls.get(i).getDaynhgzssdl()
                                ? StringUtils.round(ls.get(i).getDaynhgzssdl(), 4) : 0.0);
                        oldwd.setDaynhwhssdl(null != ls.get(i).getDaynhwhssdl()
                                ? StringUtils.round(ls.get(i).getDaynhwhssdl(), 4) : 0.0);
                        oldwd.setDaynhxdssdl(null != ls.get(i).getDaynhxdssdl()
                                ? StringUtils.round(ls.get(i).getDaynhxdssdl(), 4) : 0.0);
                        oldwd.setDaynhqfdl(null != ls.get(i).getDaynhqfdl()
                                ? StringUtils.round(ls.get(i).getDaynhqfdl(), 4) : 0.0);
                        oldwd.setDayspeed(
                                null != ls.get(i).getDayspeed() ? StringUtils.round(ls.get(i).getDayspeed(), 2) : 0.0);
                        oldwd.setDaynhcfdl(null != ls.get(i).getDaynhcfdl()
                                ? StringUtils.round(ls.get(i).getDaynhcfdl(), 4) : 0.0);
                        oldwd.setWindpowerstationid(ls.get(i).getWindpowerstationid());
                        oldwd.setProjectid(ls.get(i).getProjectid());
                        oldwd.setLineid(ls.get(i).getLineid());
                        map.put(ls.get(i).getWindturbineid(), oldwd);
                    }
                }
                Set<Map.Entry<String, Windturbineinfoday3>> set = map.entrySet();
                for (Iterator<Map.Entry<String, Windturbineinfoday3>> it = set.iterator(); it.hasNext(); ) {
                    Map.Entry<String, Windturbineinfoday3> entry = (Map.Entry<String, Windturbineinfoday3>) it.next();

                    Windturbineinfoday3 wi = entry.getValue();
                    String temp1 = wi.getWtId();
                    formatWi(wi);
                    wi.setTotal(wi.getDaydl2() + wi.getDaynhgzssdl() + wi.getDaynhwhssdl() + wi.getDaynhxdssdl()
                            + wi.getDaynhqfdl() + wi.getDaynhcfdl());
                    wi.setTotal(new BigDecimal(wi.getTotal()).multiply(new BigDecimal(100))
                            .divide(new BigDecimal(100), 4, RoundingMode.HALF_EVEN).doubleValue());
                    double temp2 = wi.getTotal();
                    if (temp2 == 0) {
                        temp2 = 1.0;
                    }
                    double temp = new BigDecimal(wi.getDaynhdl()).subtract(new BigDecimal(wi.getTotal()))
                            .divide(new BigDecimal(temp2), 4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100))
                            .doubleValue();
                    wi.setPercentage(temp);
                    double lyl = new BigDecimal(wi.getDaydl2()).divide(new BigDecimal(temp2), 4, RoundingMode.HALF_EVEN)
                            .multiply(new BigDecimal(100)).doubleValue();
                    wi.setLyl(lyl > 100 ? 100.00 : lyl);

                    if (InitialRunner.wtmap.containsKey(wi.getWtId())) {
                        Windturbine wt = InitialRunner.wtmap.get(wi.getWtId());
                        wi.setWtName(wt.getCode());
                        wi.setWtId("");
                    }
                    if (StringUtils.isNumeric(temp1.substring(temp1.length() - 3, temp1.length()))) {
                        vosapp.add(wi);
                    } else {

                        vos.add(wi);
                    }

                }

            }
            double fdl = 0.0;
            double gzss = 0.0;
            double whss = 0.0;
            double xnss = 0.0;
            double xdss = 0.0;
            double slss = 0.0;
            double llfdl = 0.0;
            double lyl = 0.0;
            double dayspeed = 0.0;
            long count = 0;

            if(!vosapp.isEmpty())
            {
                vos.addAll(vosapp);

                for (Windturbineinfoday3 wi : vos) {
                    count++;
                    fdl = StringUtils.round(wi.getDaydl2(), 4) + StringUtils.round(fdl, 4);
                    gzss = StringUtils.round(wi.getDaynhgzssdl(), 4) + StringUtils.round(gzss, 4);
                    whss = StringUtils.round(wi.getDaynhwhssdl(), 4) + StringUtils.round(whss, 4);
                    xdss = StringUtils.round(wi.getDaynhxdssdl(), 4) + StringUtils.round(xdss, 4);
                    xnss = StringUtils.round(wi.getDaynhqfdl(), 4) + StringUtils.round(xnss, 4);
                    dayspeed = StringUtils.round(wi.getDayspeed(), 2) + StringUtils.round(dayspeed, 2);
                    slss = StringUtils.round(wi.getDaynhcfdl(), 4) + StringUtils.round(slss, 4);

                    // wi.setTotal(new BigDecimal(wi.getTotal()).divide(new
                    // BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue());
                }
                llfdl = StringUtils.round(fdl + whss + gzss + xnss + xdss + slss, 4);
                if (llfdl != 0) {
                    // llfdl=StringUtils.round(llfdl, 2);
                    // fdl=StringUtils.round(fdl, 2);
                    lyl = StringUtils.round(fdl / llfdl * 100, 2);
                    // lyl = new BigDecimal(fdl).divide(new BigDecimal(llfdl), 2,
                    // RoundingMode.HALF_EVEN).multiply(new
                    // BigDecimal(100)).doubleValue();
                }
                getSortData(sortName, sortOrder, vos);

                Windturbineinfoday3 wi = new Windturbineinfoday3();
                wi.setWtName("合计");
                wi.setDaydl2(StringUtils.round(fdl, 4));
                wi.setDaynhgzssdl(StringUtils.round(gzss, 4));
                wi.setDaynhwhssdl(StringUtils.round(whss, 4));
                wi.setDaynhcfdl(StringUtils.round(slss, 4));
                wi.setDaynhxdssdl(StringUtils.round(xdss, 4));
                wi.setDaynhqfdl(StringUtils.round(xnss, 4));
                wi.setTotal(StringUtils.round(llfdl, 4));
                wi.setLyl(lyl > 100 ? 100.00 : lyl);
                wi.setDayspeed(dayspeed / count);
                vos.add(wi);
            }

        }


        return vos;
    }

    private void getSortData(String sortName, String sortOrder, List<Windturbineinfoday3> vos) {
        if (StringUtils.notEmp(sortName) && sortName.equals("daydl2")) {

            if (sortOrder.equals("asc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o1.getDaydl2().compareTo(o2.getDaydl2());
                    }

                });
            } else if (sortOrder.equals("desc")) {
                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o2.getDaydl2().compareTo(o1.getDaydl2());
                    }

                });
            }

        } else if (StringUtils.notEmp(sortName) && sortName.equals("daynhgzssdl")) {

            if (sortOrder.equals("asc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o1.getDaynhgzssdl().compareTo(o2.getDaynhgzssdl());
                    }

                });
            } else if (sortOrder.equals("desc")) {
                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o2.getDaynhgzssdl().compareTo(o1.getDaynhgzssdl());
                    }

                });
            }

        } else if (StringUtils.notEmp(sortName) && sortName.equals("daynhwhssdl")) {

            if (sortOrder.equals("asc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o1.getDaynhwhssdl().compareTo(o2.getDaynhwhssdl());
                    }

                });
            } else if (sortOrder.equals("desc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o2.getDaynhwhssdl().compareTo(o1.getDaynhwhssdl());
                    }

                });
            }

        } else if (StringUtils.notEmp(sortName) && sortName.equals("dayspeed")) {

            if (sortOrder.equals("asc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o1.getDayspeed().compareTo(o2.getDayspeed());
                    }

                });
            } else if (sortOrder.equals("desc")) {
                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o2.getDayspeed().compareTo(o1.getDayspeed());
                    }

                });
            }

        } else if (StringUtils.notEmp(sortName) && sortName.equals("daynhxdssdl")) {

            if (sortOrder.equals("asc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o1.getDaynhxdssdl().compareTo(o2.getDaynhxdssdl());
                    }

                });
            } else if (sortOrder.equals("desc")) {
                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o2.getDaynhxdssdl().compareTo(o1.getDaynhxdssdl());
                    }

                });
            }

        } else if (StringUtils.notEmp(sortName) && sortName.equals("daynhqfdl")) {

            if (sortOrder.equals("asc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o1.getDaynhqfdl().compareTo(o2.getDaynhqfdl());
                    }

                });
            } else if (sortOrder.equals("desc")) {
                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o2.getDaynhqfdl().compareTo(o1.getDaynhqfdl());
                    }

                });
            }

        } else if (StringUtils.notEmp(sortName) && sortName.equals("total")) {

            if (sortOrder.equals("asc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o1.getTotal().compareTo(o2.getTotal());
                    }

                });
            } else if (sortOrder.equals("desc")) {
//				Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
//					public int compare(Windturbineinfoday3 arg0, Windturbineinfoday3 arg1) {
//						int result = 0;
//						if (arg0.getTotal() < arg1.getTotal())
//							result = 1;
//						else
//							result = 0;
//						return result;
//					}
//				});

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o2.getTotal().compareTo(o1.getTotal());
                    }

                });
            }

        } else if (StringUtils.notEmp(sortName) && sortName.equals("lyl")) {

            if (sortOrder.equals("asc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o1.getLyl().compareTo(o2.getLyl());
                    }

                });
            } else if (sortOrder.equals("desc")) {
                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o2.getLyl().compareTo(o1.getLyl());
                    }

                });
            }

        } else if (StringUtils.notEmp(sortName) && sortName.equals("wtName")) {

            if (sortOrder.equals("asc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o1.getWtName().compareTo(o2.getWtName());
                    }

                });
            } else if (sortOrder.equals("desc")) {
                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o2.getWtName().compareTo(o1.getWtName());
                    }

                });
            }

        } else if (StringUtils.notEmp(sortName) && sortName.equals("dayspeed")) {

            if (sortOrder.equals("asc")) {

                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o1.getDayspeed().compareTo(o2.getDayspeed());
                    }

                });
            } else if (sortOrder.equals("desc")) {
                Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                    // 升序排序
                    public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                        return o2.getDayspeed().compareTo(o1.getDayspeed());
                    }

                });


            }

        }
    }

    private void formatWi(Windturbineinfoday3 wi) {
        // formatWi(wi);
        double sfdl = new BigDecimal(wi.getDaydl2()).divide(new BigDecimal(10000), 4, RoundingMode.HALF_EVEN)
                .doubleValue();
        double yfdl = new BigDecimal(wi.getDaynhdl()).divide(new BigDecimal(10000), 4, RoundingMode.HALF_EVEN)
                .doubleValue();
        double gzzdl = new BigDecimal(wi.getDaynhgzssdl()).divide(new BigDecimal(10000), 4, RoundingMode.HALF_EVEN)
                .doubleValue();
        double whdl = new BigDecimal(wi.getDaynhwhssdl()).divide(new BigDecimal(10000), 4, RoundingMode.HALF_EVEN)
                .doubleValue();
        double xddl = new BigDecimal(wi.getDaynhxdssdl()).divide(new BigDecimal(10000), 4, RoundingMode.HALF_EVEN)
                .doubleValue();
        double qfdl = new BigDecimal(wi.getDaynhqfdl()).divide(new BigDecimal(10000), 4, RoundingMode.HALF_EVEN)
                .doubleValue();
        double cfdl = new BigDecimal(wi.getDaynhcfdl()).divide(new BigDecimal(10000), 4, RoundingMode.HALF_EVEN)
                .doubleValue();
        double dayspeed = wi.getDayspeed();

        wi.setDaydl2(sfdl);
        wi.setDaynhdl(yfdl);
        wi.setDaynhgzssdl(gzzdl);
        wi.setDaynhwhssdl(whdl);
        wi.setDaynhxdssdl(xddl);
        wi.setDaynhqfdl(qfdl);
        wi.setDayspeed(dayspeed);
        wi.setDaynhcfdl(cfdl);
    }


    public Map<String, List<String>> getWindturbineinfoJson(String wpIds, String pjIds, String lineIds, Date beginDate,
                                                            Date endDate) {
        Map<String, List<String>> resultmap = new HashMap<String, List<String>>();

        if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            List<Windturbineinfoday3> ls = null;

                Windturbineinfoday3Example example = new Windturbineinfoday3Example();
                example.setOrderByClause("windturbineid asc");

                if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {


                  Windturbineinfoday3Example.Criteria criteria= example.createCriteria();
                    if (StringUtils.notEmp(wpIds) && !wpIds.equals("undefined")) {
                        criteria.andWindpowerstationidEqualTo(wpIds);
                    }

                    if (StringUtils.notEmp(pjIds) && !pjIds.equals("undefined")) {
                        criteria.andProjectidEqualTo(pjIds);
                    }

                    if (StringUtils.notEmp(lineIds) && !lineIds.equals("undefined")) {
                        criteria.andLineidEqualTo(lineIds);
                    }
                    criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);
                    ls = windturbineinfoday3Mapper.selectByExample(example);
                } else {
                    ls = new ArrayList<>();
                }

            List<String> names = new ArrayList<String>();
            List<String> names2 = new ArrayList<String>();
            List<String> yfdl = new ArrayList<String>();
            ;
            List<String> sfdl = new ArrayList<String>();
            List<String> gzdl = new ArrayList<String>();
            List<String> whdl = new ArrayList<String>();
            List<String> xddl = new ArrayList<String>();
            List<String> qfdl = new ArrayList<String>();
            List<String> sldl = new ArrayList<String>();
            List<String> lyl = new ArrayList<String>();

            List<String> namesapp = new ArrayList<String>();
            List<String> names2app = new ArrayList<String>();
            List<String> yfdlapp = new ArrayList<String>();
            ;
            List<String> sfdlapp = new ArrayList<String>();
            List<String> gzdlapp = new ArrayList<String>();
            List<String> whdlapp = new ArrayList<String>();
            List<String> xddlapp = new ArrayList<String>();
            List<String> qfdlapp = new ArrayList<String>();
            List<String> sldlapp = new ArrayList<String>();
            List<String> lylapp = new ArrayList<String>();
            if (!ls.isEmpty()) {
                Map<String, Windturbineinfoday3> map = new TreeMap<String, Windturbineinfoday3>();
                for (Windturbineinfoday3 wd : ls) {


                    if (map.containsKey(wd.getWindturbineid())) {
                        Windturbineinfoday3 oldwd = map.get(wd.getWindturbineid());
                        double sfdld = null != wd.getDaydl2() ? wd.getDaydl2() : 0.0;
                        double yfdld = null != wd.getDaynhdl2() ? wd.getDaynhdl2() : 0.0;
                        double gzzdld = null != wd.getDaynhgzssdl2() ? wd.getDaynhgzssdl2() : 0.0;
                        double whdld = null != wd.getDaynhwhssdl2() ? wd.getDaynhwhssdl2() : 0.0;
                        double xddld = null != wd.getDaynhxdssdl2() ? wd.getDaynhxdssdl2() : 0.0;
                        double qfdld = null != wd.getDaynhqfdl2() ? wd.getDaynhqfdl2() : 0.0;

                        oldwd.setDaydl2(oldwd.getDaydl2() + sfdld);
                        oldwd.setDaynhdl2(oldwd.getDaynhdl2() + yfdld);
                        oldwd.setDaynhgzssdl2(oldwd.getDaynhgzssdl2() + gzzdld);
                        oldwd.setDaynhwhssdl2(oldwd.getDaynhwhssdl2() + whdld);
                        oldwd.setDaynhxdssdl2(oldwd.getDaynhxdssdl2() + xddld);
                        oldwd.setDaynhqfdl2(oldwd.getDaynhqfdl2() + qfdld);
                        oldwd.setDayspeed(0.0);
                        map.put(wd.getWindturbineid(), oldwd);
                    } else {
                        Windturbineinfoday3 oldwd = new Windturbineinfoday3();
                        oldwd.setWindturbineid(wd.getWindturbineid());
                        oldwd.setDaydl2(null != wd.getDaydl2() ? wd.getDaydl2() : 0.0);
                        oldwd.setDaynhdl2(null != wd.getDaynhdl2() ? wd.getDaynhdl2() : 0.0);
                        oldwd.setDaynhgzssdl2(null != wd.getDaynhgzssdl2() ? wd.getDaynhgzssdl2() : 0.0);
                        oldwd.setDaynhwhssdl2(null != wd.getDaynhwhssdl2() ? wd.getDaynhwhssdl2() : 0.0);
                        oldwd.setDaynhxdssdl2(null != wd.getDaynhxdssdl2() ? wd.getDaynhxdssdl2() : 0.0);
                        oldwd.setDaynhqfdl2(null != wd.getDaynhqfdl2() ? wd.getDaynhqfdl2() : 0.0);
                        oldwd.setDayspeed(0.0);

                        map.put(wd.getWindturbineid(), oldwd);
                    }
                }

                Set<Map.Entry<String, Windturbineinfoday3>> set = map.entrySet();
                for (Iterator<Map.Entry<String, Windturbineinfoday3>> it = set.iterator(); it.hasNext();) {
                    Map.Entry<String, Windturbineinfoday3> entry = (Map.Entry<String, Windturbineinfoday3>) it.next();
                    Windturbineinfoday3 wd = entry.getValue();
                    String temp = wd.getWindturbineid();
                    if (StringUtils.isNumeric(temp.substring(temp.length() - 3, temp.length()))) {

                        if (InitialRunner.wtmap.containsKey(wd.getWindturbineid())) {
                            Windturbine wt = InitialRunner.wtmap.get(wd.getWindturbineid());
                            // wi.setWtName(wt.getName());
                            namesapp.add(wt.getName());
                        }
                        // names.add(wd.getWindturbineid());
                        names2app.add("");
                        double fdl = new BigDecimal(wd.getDaydl2())
                                .divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue();
                        double xd = new BigDecimal(wd.getDaynhxdssdl2())
                                .divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue();
                        double gz = new BigDecimal(wd.getDaynhgzssdl2())
                                .divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue();
                        double jx = new BigDecimal(wd.getDaynhwhssdl2())
                                .divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue();
                        double qf = new BigDecimal(wd.getDaynhqfdl2())
                                .divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue();
                        double result = fdl + xd + gz + jx + qf;
                        yfdlapp.add(String.valueOf(StringUtils.round(result, 2)));
                        sfdlapp.add(String.valueOf(fdl));
                        gzdlapp.add(String.valueOf(gz));
                        whdlapp.add(String.valueOf(jx));
                        xddlapp.add(String.valueOf(xd));
                        qfdlapp.add(String.valueOf(qf));
                        sldlapp.add(String.valueOf(wd.getDayspeed()));
                        if (result == 0) {
                            result = 1;
                        }
                        wd.setLyl(new BigDecimal(fdl).divide(new BigDecimal(result), 4, RoundingMode.HALF_EVEN)
                                .multiply(new BigDecimal(100)).doubleValue());

                        lylapp.add(String.valueOf(wd.getLyl()));
                    } else {

                        if (InitialRunner.wtmap.containsKey(wd.getWindturbineid())) {
                            Windturbine wt = InitialRunner.wtmap.get(wd.getWindturbineid());
                            // wi.setWtName(wt.getName());
                            names.add(wt.getName());
                        }
                        // names.add(wd.getWindturbineid());
                        names2.add("");
                        double fdl = new BigDecimal(wd.getDaydl2())
                                .divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue();
                        double total = 1.0;
                        double gzss = new BigDecimal(wd.getDaynhgzssdl2())
                                .divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue();
                        double whss = new BigDecimal(wd.getDaynhwhssdl2())
                                .divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue();
                        double xdss = new BigDecimal(wd.getDaynhxdssdl2())
                                .divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue();
                        double qdss = new BigDecimal(wd.getDaynhqfdl2())
                                .divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue();
                        total = fdl + gzss + whss + xdss + qdss;
                        yfdl.add(String.valueOf(StringUtils.round(total, 2)));
                        sfdl.add(String.valueOf(fdl));
                        gzdl.add(String.valueOf(gzss));
                        whdl.add(String.valueOf(whss));
                        xddl.add(String.valueOf(xdss));
                        qfdl.add(String.valueOf(qdss));
                        sldl.add(String.valueOf(wd.getDayspeed()));
                        if (total == 0) {
                            total = 1;
                        }
                        wd.setLyl(new BigDecimal(fdl).divide(new BigDecimal(total), 4, RoundingMode.HALF_EVEN)
                                .multiply(new BigDecimal(100)).doubleValue());


                        lyl.add(String.valueOf(wd.getLyl()));
                    }
                }
                names.addAll(namesapp);
                names2.addAll(names2app);
                sfdl.addAll(sfdlapp);
                yfdl.addAll(yfdlapp);
                gzdl.addAll(gzdlapp);
                whdl.addAll(whdlapp);
                xddl.addAll(xddlapp);
                qfdl.addAll(qfdlapp);
                sldl.addAll(sldlapp);

                resultmap.put("names", names);
                resultmap.put("names2", names2);
                resultmap.put("sfdl", sfdl);
                resultmap.put("yfdl", yfdl);
                resultmap.put("gzdl", gzdl);
                resultmap.put("whdl", whdl);
                resultmap.put("xddl", xddl);
                resultmap.put("qfdl", qfdl);
                resultmap.put("sldl", sldl);
                resultmap.put("lyl", lyl);
            }

        }
        return resultmap;

    }

    public List<Windturbineinfoday3> getWindturbineinfoday3(String wpId,String wtId, Date beginDate, Date endDate) {


        List<Windturbineinfoday3> list=new ArrayList<>();

        Windturbineinfoday3Example example=new Windturbineinfoday3Example();
        example.setOrderByClause("windpowerstationid ASC");

        Windturbineinfoday3Example.Criteria criteria =example.createCriteria();

        if(StringUtils.isNotEmpty(wpId))
        {
            criteria.andWindpowerstationidEqualTo(wpId);
        }
        List<String> wtids = new ArrayList<String>();
        if (StringUtils.notEmp(wtId)) {
            if (wtId.indexOf(",") != -1) {
                String[] strs = wtId.split(",");
                if (strs.length > 0) {
                    for (int i = 0; i < strs.length; i++) {
                        wtids.add(strs[i]);
                    }
                }
            } else {
                wtids.add(wtId);
            }
        }

        if (!wtids.isEmpty()) {
            criteria.andWindturbineidIn(wtids);
        }
        if(beginDate!=null && endDate!=null ){
            criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);
        }


        list= windturbineinfoday3Mapper.selectByExample(example);
        return list;

    }


    public List<Windturbineinfoday3> utilizationList( Tablepar tablepar,String wpId,Date beginDate, Date endDate,String type) {

        List<Windturbineinfoday3> vos=new ArrayList<>();
        List<Windturbineinfoday3> ls = null;

        if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            Windturbineinfoday3Example example = new Windturbineinfoday3Example();
            example.setOrderByClause("recorddate DESC");

            Windturbineinfoday3Example.Criteria criteria=example.createCriteria();

            if(StringUtils.notEmp(wpId))
            {
                criteria.andWindpowerstationidEqualTo(wpId);
            }
            if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {


                criteria.andWindpowerstationidLike("%FDC").andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);
                ls = windturbineinfoday3Mapper.selectByExample(example);
            } else {
                ls = new ArrayList<>();
            }

            Map<String, Windturbineinfoday3> map = new TreeMap<String, Windturbineinfoday3>();
            switch (type) {
                case "0":
                    if (!ls.isEmpty()) {
                        setWpMap(map, ls);
                    }
                    break;
                case "1":
                    setPjMap(map, ls);

                    break;
                case "2":
                    setLnMap(map, ls);

                    break;
                case "3":
                    setWtMap(map, ls);

                default:
                    if (!ls.isEmpty()) {
                        setWpMap(map, ls);
                    }
                    break;
            }

            Set<Map.Entry<String, Windturbineinfoday3>> set = map.entrySet();
            for (Iterator<Map.Entry<String, Windturbineinfoday3>> it = set.iterator(); it.hasNext();) {
                Map.Entry<String, Windturbineinfoday3> entry = (Map.Entry<String, Windturbineinfoday3>) it.next();
                Windturbineinfoday3 wi=entry.getValue();
                wi.setDaydl2(new BigDecimal(wi.getDaydl2()).divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue());
                wi.setDaylldl(new BigDecimal(wi.getDaylldl()).divide(new BigDecimal(10000), 2, RoundingMode.HALF_EVEN).doubleValue());
                double temp=1.0;
                if(wi.getDaylldl()!=0)
                {
                    temp=wi.getDaylldl();
                }

                double fdlyl=new BigDecimal(wi.getDaydl2()).divide(new BigDecimal(temp), 4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();
                wi.setDayspeed(fdlyl);
                vos.add(wi);
            }

            Collections.sort(vos,new Comparator<Windturbineinfoday3>(){
                public int compare(Windturbineinfoday3 arg0, Windturbineinfoday3 arg1) {
                    int result=0;

                    if (StringUtils.notEmp(tablepar.getOrderByColumn()) && tablepar.getOrderByColumn().equals("daydl2")) {

                        if (tablepar.getIsAsc().equals("asc")) {

                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o1.getDaydl2().compareTo(o2.getDaydl2());
                                }

                            });
                        } else  {
                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o2.getDaydl2().compareTo(o1.getDaydl2());
                                }

                            });
                        }

                    }

                    else 	if (StringUtils.notEmp(tablepar.getOrderByColumn()) && tablepar.getOrderByColumn().equals("daylldl")) {

                        if (tablepar.getIsAsc().equals("asc")) {

                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o1.getDaylldl().compareTo(o2.getDaylldl());
                                }

                            });
                        } else    {
                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o2.getDaylldl().compareTo(o1.getDaylldl());
                                }

                            });
                        }

                    }

                    else 	if (StringUtils.notEmp(tablepar.getOrderByColumn()) && tablepar.getOrderByColumn().equals("dayspeed")) {

                        if (tablepar.getIsAsc().equals("asc")) {

                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o1.getDayspeed().compareTo(o2.getDayspeed());
                                }

                            });
                        } else   {
                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o2.getDayspeed().compareTo(o1.getDayspeed());
                                }

                            });
                        }

                    }


                    return result;

                }
            });
            int i=1;
            for(Windturbineinfoday3 vo:vos)
            {
                vo.setId(i);
                i++;
            }
        }
        return vos;

    }



    public List<Windturbineinfoday3> lossList( Tablepar tablepar,String wpId,Date beginDate, Date endDate,String type) {

        List<Windturbineinfoday3> vos=new ArrayList<>();
        List<Windturbineinfoday3> ls = null;

        if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            Windturbineinfoday3Example example = new Windturbineinfoday3Example();
            example.setOrderByClause("recorddate DESC");

            Windturbineinfoday3Example.Criteria criteria =example.createCriteria();

            if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {


                criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);

            }
            if(StringUtils.notEmp(wpId))
            {
                criteria.andWindpowerstationidEqualTo(wpId);

            }

            criteria.andWindpowerstationidLike("%FDC");

            ls = windturbineinfoday3Mapper.selectByExample(example);

            Map<String, Windturbineinfoday3> map = new TreeMap<String, Windturbineinfoday3>();
            switch (type) {
                case "0":
                    if (!ls.isEmpty()) {
                        setWpLossMap(map, ls);
                    }
                    break;
                case "1":
                    setPjLossMap(map, ls);

                    break;
                case "2":
                    setLnLossMap(map, ls);

                    break;
                case "3":
                    setWtLossMap(map, ls);

                default:
                    if (!ls.isEmpty()) {
                        setWpMap(map, ls);
                    }
                    break;
            }

            Set<Map.Entry<String, Windturbineinfoday3>> set = map.entrySet();
            for (Iterator<Map.Entry<String, Windturbineinfoday3>> it = set.iterator(); it.hasNext();) {
                Map.Entry<String, Windturbineinfoday3> entry = (Map.Entry<String, Windturbineinfoday3>) it.next();
                Windturbineinfoday3 wi = entry.getValue();
                double temp = 1.0;
                if (StringUtils.notEmp(wi.getDaydl2()) && wi.getDaydl2() != 0) {
                    temp = wi.getDaydl2();
                }

                double gzssdl=null!=wi.getDaynhgzssdl2()?wi.getDaynhgzssdl2():0.0;
                double whssdl=null!=wi.getDaynhwhssdl2()?wi.getDaynhwhssdl2():0.0;
                double xdssdl=null!=wi.getDaynhxdssdl2()?wi.getDaynhxdssdl2():0.0;
                wi.setDaynhgzssdl2(new BigDecimal(gzssdl).divide(new BigDecimal(temp), 4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
                wi.setDaynhwhssdl2(new BigDecimal(whssdl).divide(new BigDecimal(temp), 4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
                wi.setDaynhxdssdl2(new BigDecimal(xdssdl).divide(new BigDecimal(temp), 4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());

                wi.setDayspeed(0.0);
                vos.add(wi);
            }

            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                public int compare(Windturbineinfoday3 arg0, Windturbineinfoday3 arg1) {
                    int result = 0;
                    if (StringUtils.notEmp(tablepar.getOrderByColumn()) && tablepar.getOrderByColumn().equals("daynhgzssdl2")) {

                        if (tablepar.getIsAsc().equals("asc")) {

                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o1.getDaynhgzssdl2().compareTo(o2.getDaynhgzssdl2());
                                }

                            });
                        } else   {
                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o2.getDaynhgzssdl2().compareTo(o1.getDaynhgzssdl2());
                                }

                            });
                        }

                    }

                    else if (StringUtils.notEmp(tablepar.getOrderByColumn()) && tablepar.getOrderByColumn().equals("daynhwhssdl2")) {

                        if (tablepar.getIsAsc().equals("asc")) {

                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o1.getDaynhwhssdl2().compareTo(o2.getDaynhwhssdl2());
                                }

                            });
                        } else   {
                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o2.getDaynhwhssdl2().compareTo(o1.getDaynhwhssdl2());
                                }

                            });
                        }

                    } else if (StringUtils.notEmp(tablepar.getOrderByColumn()) && tablepar.getOrderByColumn().equals("daynhxdssdl2")) {

                        if (tablepar.getIsAsc().equals("asc")) {

                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o1.getDaynhxdssdl2().compareTo(o2.getDaynhxdssdl2());
                                }

                            });
                        } else  {
                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o2.getDaynhxdssdl2().compareTo(o1.getDaynhxdssdl2());
                                }

                            });
                        }

                    }

                    else if (StringUtils.notEmp(tablepar.getOrderByColumn()) && tablepar.getOrderByColumn().equals("dayspeed")) {

                        if (tablepar.getIsAsc().equals("asc")) {

                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o1.getDayspeed().compareTo(o2.getDayspeed());
                                }

                            });
                        } else   {
                            Collections.sort(vos, new Comparator<Windturbineinfoday3>() {
                                // 升序排序
                                public int compare(Windturbineinfoday3 o1, Windturbineinfoday3 o2) {
                                    return o2.getDayspeed().compareTo(o1.getDayspeed());
                                }

                            });
                        }

                    }

                    return result;

                }
            });
            int i = 1;
            for (Windturbineinfoday3 vo : vos) {
                vo.setId(i);
                i++;
            }
        }
        return vos;

    }

    private void setWpMap(Map<String, Windturbineinfoday3> map, List<Windturbineinfoday3> ls) {
        for (Windturbineinfoday3 wd : ls) {

            if (map.containsKey(wd.getWindpowerstationid())) {
                Windturbineinfoday3 oldwd=map.get(wd.getWindpowerstationid());

                double sfdl=null!=wd.getDaydl2()?wd.getDaydl2():0.0;
                double llfdl=null!=wd.getDaylldl()?wd.getDaylldl():0.0;


                oldwd.setDaydl2(oldwd.getDaydl2()+sfdl);
                oldwd.setDaylldl(oldwd.getDaylldl()+llfdl);
                oldwd.setDayspeed(0.0);
                map.put(wd.getWindpowerstationid(), oldwd);
            }else
            {
                Windturbineinfoday3 oldwd=new Windturbineinfoday3();

                if(InitialRunner.wpmap.containsKey(wd.getWindpowerstationid()))
                {
                    Windpowerstation wp=InitialRunner.wpmap.get(wd.getWindpowerstationid());
                    oldwd.setWindturbineid(wp.getName());
                }
                oldwd.setDaydl2(null!=wd.getDaydl2()?wd.getDaydl2():0.0);
                oldwd.setDaylldl(null!=wd.getDaylldl()?wd.getDaylldl():0.0);
                oldwd.setDayspeed(0.0);
                map.put(wd.getWindpowerstationid(), oldwd);
            }

        }
    }

    private void setPjMap(Map<String, Windturbineinfoday3> map, List<Windturbineinfoday3> ls) {
        for (Windturbineinfoday3 wd : ls) {

            if (map.containsKey(wd.getProjectid())) {
                Windturbineinfoday3 oldwd=map.get(wd.getProjectid());

                double sfdl=null!=wd.getDaydl2()?wd.getDaydl2():0.0;
                double llfdl=null!=wd.getDaylldl()?wd.getDaylldl():0.0;


                oldwd.setDaydl2(oldwd.getDaydl2()+sfdl);
                oldwd.setDaylldl(oldwd.getDaylldl()+llfdl);
                oldwd.setDayspeed(0.0);
                map.put(wd.getProjectid(), oldwd);
            }else
            {
                Windturbineinfoday3 oldwd=new Windturbineinfoday3();

                if(InitialRunner.pjmap.containsKey(wd.getProjectid()))
                {
                    Project pj=InitialRunner.pjmap.get(wd.getProjectid());
                    oldwd.setWindturbineid(pj.getName());
                }
                oldwd.setDaydl2(null!=wd.getDaydl2()?wd.getDaydl2():0.0);
                oldwd.setDaylldl(null!=wd.getDaylldl()?wd.getDaylldl():0.0);
                oldwd.setDayspeed(0.0);
                map.put(wd.getProjectid(), oldwd);
            }

        }
    }

    private void setLnMap(Map<String, Windturbineinfoday3> map, List<Windturbineinfoday3> ls) {
        for (Windturbineinfoday3 wd : ls) {

            if (map.containsKey(wd.getLineid())) {
                Windturbineinfoday3 oldwd=map.get(wd.getLineid());

                double sfdl=null!=wd.getDaydl2()?wd.getDaydl2():0.0;
                double llfdl=null!=wd.getDaylldl()?wd.getDaylldl():0.0;


                oldwd.setDaydl2(oldwd.getDaydl2()+sfdl);
                oldwd.setDaylldl(oldwd.getDaylldl()+llfdl);
                oldwd.setDayspeed(0.0);
                map.put(wd.getLineid(), oldwd);
            }else
            {
                Windturbineinfoday3 oldwd=new Windturbineinfoday3();

                if(InitialRunner.lnmap.containsKey(wd.getLineid()))
                {
                    Line ln=InitialRunner.lnmap.get(wd.getLineid());
                    oldwd.setWindturbineid(ln.getName());
                }
                oldwd.setDaydl2(null!=wd.getDaydl2()?wd.getDaydl2():0.0);
                oldwd.setDaylldl(null!=wd.getDaylldl()?wd.getDaylldl():0.0);
                oldwd.setDayspeed(0.0);
                map.put(wd.getLineid(), oldwd);
            }

        }
    }
    private void setWtMap(Map<String, Windturbineinfoday3> map, List<Windturbineinfoday3> ls) {
        for (Windturbineinfoday3 wd : ls) {

            if (map.containsKey(wd.getWindturbineid())) {
                Windturbineinfoday3 oldwd=map.get(wd.getWindturbineid());

                double sfdl=null!=wd.getDaydl2()?wd.getDaydl2():0.0;
                double llfdl=null!=wd.getDaylldl()?wd.getDaylldl():0.0;


                oldwd.setDaydl2(oldwd.getDaydl2()+sfdl);
                oldwd.setDaylldl(oldwd.getDaylldl()+llfdl);
                oldwd.setDayspeed(0.0);
                map.put(wd.getWindturbineid(), oldwd);
            }else
            {
                Windturbineinfoday3 oldwd=new Windturbineinfoday3();

                oldwd.setWindturbineid(wd.getWindturbineid());
                oldwd.setDaydl2(null!=wd.getDaydl2()?wd.getDaydl2():0.0);
                oldwd.setDaylldl(null!=wd.getDaylldl()?wd.getDaylldl():0.0);
                oldwd.setDayspeed(0.0);
                map.put(wd.getWindturbineid(), oldwd);
            }

        }
    }





    private void setWpLossMap(Map<String, Windturbineinfoday3> map, List<Windturbineinfoday3> ls) {
        for (Windturbineinfoday3 wd : ls) {

            if (map.containsKey(wd.getWindpowerstationid())) {
                Windturbineinfoday3 oldwd = map.get(wd.getWindpowerstationid());

                double sfdl = null != wd.getDaydl2() ? wd.getDaydl2() : 0.0;
                double gzfdl = null != wd.getDaynhgzssdl2() ? wd.getDaynhgzssdl2() : 0.0;
                double whfdl = null != wd.getDaynhwhssdl2() ? wd.getDaynhwhssdl2() : 0.0;
                double xdfdl = null != wd.getDaynhxdssdl2() ? wd.getDaynhxdssdl2() : 0.0;

                oldwd.setDaydl2(oldwd.getDaydl2() + sfdl);
                oldwd.setDaynhgzssdl2(oldwd.getDaynhgzssdl2() + gzfdl);
                oldwd.setDaynhwhssdl2(oldwd.getDaynhwhssdl2() + whfdl);
                oldwd.setDaynhxdssdl2(oldwd.getDaynhxdssdl2() + xdfdl);

                oldwd.setDayspeed(0.0);
                map.put(wd.getWindpowerstationid(), oldwd);
            } else {
                Windturbineinfoday3 oldwd = new Windturbineinfoday3();

                if (InitialRunner.wpmap.containsKey(wd.getWindpowerstationid())) {
                    Windpowerstation wp = InitialRunner.wpmap.get(wd.getWindpowerstationid());
                    oldwd.setWindturbineid(wp.getName());
                }
                oldwd.setDaydl2(null != wd.getDaydl2() ? wd.getDaydl2() : 0.0);
                oldwd.setDaynhgzssdl2(null != wd.getDaynhgzssdl2() ? wd.getDaynhgzssdl2() : 0.0);
                oldwd.setDaynhwhssdl2(null != wd.getDaynhwhssdl2() ? wd.getDaynhwhssdl2() : 0.0);
                oldwd.setDaynhxdssdl2(null != wd.getDaynhxdssdl2() ? wd.getDaynhxdssdl2() : 0.0);

                oldwd.setDayspeed(0.0);
                map.put(wd.getWindpowerstationid(), oldwd);
            }

        }
    }

    private void setPjLossMap(Map<String, Windturbineinfoday3> map, List<Windturbineinfoday3> ls) {
        for (Windturbineinfoday3 wd : ls) {

            if (map.containsKey(wd.getProjectid())) {
                Windturbineinfoday3 oldwd = map.get(wd.getProjectid());

                double sfdl = null != wd.getDaydl2() ? wd.getDaydl2() : 0.0;
                double gzfdl = null != wd.getDaynhgzssdl2() ? wd.getDaynhgzssdl2() : 0.0;
                double whfdl = null != wd.getDaynhwhssdl2() ? wd.getDaynhwhssdl2() : 0.0;
                double xdfdl = null != wd.getDaynhxdssdl2() ? wd.getDaynhxdssdl2() : 0.0;

                oldwd.setDaydl2(oldwd.getDaydl2() + sfdl);
                oldwd.setDaynhgzssdl2(oldwd.getDaynhgzssdl2() + gzfdl);
                oldwd.setDaynhwhssdl2(oldwd.getDaynhwhssdl2() + whfdl);
                oldwd.setDaynhxdssdl2(oldwd.getDaynhxdssdl2() + xdfdl);

                oldwd.setDayspeed(0.0);
                map.put(wd.getProjectid(), oldwd);
            } else {
                Windturbineinfoday3 oldwd = new Windturbineinfoday3();

                if (InitialRunner.pjmap.containsKey(wd.getProjectid())) {
                    Project pj = InitialRunner.pjmap.get(wd.getProjectid());
                    oldwd.setWindturbineid(pj.getName());
                }
                oldwd.setDaydl2(null != wd.getDaydl2() ? wd.getDaydl2() : 0.0);
                oldwd.setDaynhgzssdl2(null != wd.getDaynhgzssdl2() ? wd.getDaynhgzssdl2() : 0.0);
                oldwd.setDaynhwhssdl2(null != wd.getDaynhwhssdl2() ? wd.getDaynhwhssdl2() : 0.0);
                oldwd.setDaynhxdssdl2(null != wd.getDaynhxdssdl2() ? wd.getDaynhxdssdl2() : 0.0);
                oldwd.setDayspeed(0.0);
                map.put(wd.getProjectid(), oldwd);
            }

        }
    }

    private void setLnLossMap(Map<String, Windturbineinfoday3> map, List<Windturbineinfoday3> ls) {
        for (Windturbineinfoday3 wd : ls) {

            if (map.containsKey(wd.getLineid())) {
                Windturbineinfoday3 oldwd = map.get(wd.getLineid());

                double sfdl = null != wd.getDaydl2() ? wd.getDaydl2() : 0.0;
                double gzfdl = null != wd.getDaynhgzssdl2() ? wd.getDaynhgzssdl2() : 0.0;
                double whfdl = null != wd.getDaynhwhssdl2() ? wd.getDaynhwhssdl2() : 0.0;
                double xdfdl = null != wd.getDaynhxdssdl2() ? wd.getDaynhxdssdl2() : 0.0;

                oldwd.setDaydl2(oldwd.getDaydl2() + sfdl);
                oldwd.setDaynhgzssdl2(oldwd.getDaynhgzssdl2() + gzfdl);
                oldwd.setDaynhwhssdl2(oldwd.getDaynhwhssdl2() + whfdl);
                oldwd.setDaynhxdssdl2(oldwd.getDaynhxdssdl2() + xdfdl);

                oldwd.setDayspeed(0.0);
                map.put(wd.getLineid(), oldwd);
            } else {
                Windturbineinfoday3 oldwd = new Windturbineinfoday3();

                if (InitialRunner.lnmap.containsKey(wd.getLineid())) {
                    Line ln = InitialRunner.lnmap.get(wd.getLineid());
                    oldwd.setWindturbineid(ln.getName());
                }
                oldwd.setDaydl2(null != wd.getDaydl2() ? wd.getDaydl2() : 0.0);
                oldwd.setDaynhgzssdl2(null != wd.getDaynhgzssdl2() ? wd.getDaynhgzssdl2() : 0.0);
                oldwd.setDaynhwhssdl2(null != wd.getDaynhwhssdl2() ? wd.getDaynhwhssdl2() : 0.0);
                oldwd.setDaynhxdssdl2(null != wd.getDaynhxdssdl2() ? wd.getDaynhxdssdl2() : 0.0);
                oldwd.setDayspeed(0.0);
                map.put(wd.getLineid(), oldwd);
            }

        }
    }

    private void setWtLossMap(Map<String, Windturbineinfoday3> map, List<Windturbineinfoday3> ls) {
        for (Windturbineinfoday3 wd : ls) {

            if (map.containsKey(wd.getWindturbineid())) {
                Windturbineinfoday3 oldwd = map.get(wd.getWindturbineid());

                double sfdl = null != wd.getDaydl2() ? wd.getDaydl2() : 0.0;
                double gzfdl = null != wd.getDaynhgzssdl2() ? wd.getDaynhgzssdl2() : 0.0;
                double whfdl = null != wd.getDaynhwhssdl2() ? wd.getDaynhwhssdl2() : 0.0;
                double xdfdl = null != wd.getDaynhxdssdl2() ? wd.getDaynhxdssdl2() : 0.0;

                oldwd.setDaydl2(oldwd.getDaydl2() + sfdl);
                oldwd.setDaynhgzssdl2(oldwd.getDaynhgzssdl2() + gzfdl);
                oldwd.setDaynhwhssdl2(oldwd.getDaynhwhssdl2() + whfdl);
                oldwd.setDaynhxdssdl2(oldwd.getDaynhxdssdl2() + xdfdl);

                oldwd.setDayspeed(0.0);
                map.put(wd.getWindturbineid(), oldwd);
            } else {
                Windturbineinfoday3 oldwd = new Windturbineinfoday3();

                oldwd.setWindturbineid(wd.getWindturbineid());
                oldwd.setDaydl2(null != wd.getDaydl2() ? wd.getDaydl2() : 0.0);
                oldwd.setDaynhgzssdl2(null != wd.getDaynhgzssdl2() ? wd.getDaynhgzssdl2() : 0.0);
                oldwd.setDaynhwhssdl2(null != wd.getDaynhwhssdl2() ? wd.getDaynhwhssdl2() : 0.0);
                oldwd.setDaynhxdssdl2(null != wd.getDaynhxdssdl2() ? wd.getDaynhxdssdl2() : 0.0);
                oldwd.setDayspeed(0.0);
                map.put(wd.getWindturbineid(), oldwd);
            }

        }
    }

    public List<Windturbineinfoday3> getWindturbineinfoday3List(String wpId, Date beginDate, Date endDate) {


        List<Windturbineinfoday3> list=new ArrayList<>();

        if (StringUtils.notEmp(wpId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            Windturbineinfoday3Example example=new Windturbineinfoday3Example();
            example.setOrderByClause("recorddate DESC");

            Windturbineinfoday3Example.Criteria criteria =example.createCriteria();

            criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);

            criteria.andWindpowerstationidEqualTo(wpId);
            list= windturbineinfoday3Mapper.selectByExample(example);

        }
        return list;

    }

    public List<Windturbineinfoday3> getWindturbineinfoday3ListBywtId(String wtId, Date beginDate, Date endDate) {


        List<Windturbineinfoday3> list=new ArrayList<>();

        if (StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            Windturbineinfoday3Example example=new Windturbineinfoday3Example();
            example.setOrderByClause("recorddate asc");

            Windturbineinfoday3Example.Criteria criteria =example.createCriteria();

            criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);

            criteria.andWindturbineidEqualTo(wtId);
            list= windturbineinfoday3Mapper.selectByExample(example);

        }
        return list;

    }


    public List<List<Object>> getWtDay3ListBywtId(String wtId, Date beginDate, Date endDate) {


        List<List<Object>> list=new ArrayList<>();

        if (StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

            Windturbineinfoday3Example example=new Windturbineinfoday3Example();
            example.setOrderByClause("recorddate asc");

            Windturbineinfoday3Example.Criteria criteria =example.createCriteria();

            criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);

            criteria.andWindturbineidEqualTo(wtId);
            List<Windturbineinfoday3> ls= windturbineinfoday3Mapper.selectByExample(example);

            if(!ls.isEmpty())
            {
                for(Windturbineinfoday3 w3:ls)
                {
                    if(w3.getDaydl2()==null||w3.getDaynhqfdl2()==null){
                        continue;
                    }
                    List<Object> lit=new ArrayList<>();
                    lit.add(w3.getRecorddate().getTime());
                    double dou=0.0;
                    if((w3.getDaydl2()+w3.getDaynhqfdl2())!=0.0){
                        dou=StringUtils.round(w3.getDaynhqfdl2()/(w3.getDaydl2()+w3.getDaynhqfdl2()),4)*100;
                    }
                    lit.add(StringUtils.round(dou,2));
                    list.add(lit);
                }
            }
        }
        return list;

    }

    public List<SingleAnalysisVo>  getWindTurbineInfoDay3Mapper(String wpId,Date beginDate,Date endDate) {

        List<SingleAnalysisVo>   list =  new ArrayList<>();


        if (StringUtils.notEmp(wpId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {


            list = windturbineinfoday3Mapper.getWindTurbineInfoDay3(wpId,beginDate,endDate);


        }
        return list;

    }


    public List<SingleAnalysisVo>  getWindTurbineInfoDayMapper3ByWtId(String wtId, Date beginDate, Date endDate) {

        List<SingleAnalysisVo>   list =  new ArrayList<>();


        if (StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {


            list = windturbineinfoday3Mapper.getWindTurbineInfoDay3ByWtId(wtId,beginDate,endDate);


        }
        return list;

    }
}
