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.support.Convert;
import com.gyee.frame.mapper.auto.Windturbineinfodaytop2Mapper;
import com.gyee.frame.model.auto.Windturbineinfodaytop2;
import com.gyee.frame.model.auto.Windturbineinfodaytop2Example;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.model.custom.ValueVo;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 风机信息表 Windturbineinfodaytop2Service
 * @Title: Windturbineinfodaytop2Service.java 
 * @Package com.gyee.frame.service 
 * @author gyee_自动生成
 * @email 1@qq.com
 * @date 2019-12-30 17:00:04  
 **/
@Service
public class Windturbineinfodaytop2Service implements BaseService<Windturbineinfodaytop2, Windturbineinfodaytop2Example> {
	@Resource
	private Windturbineinfodaytop2Mapper windturbineinfodaytop2Mapper;


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

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

	@Override
	public int deleteByPrimaryKey(String ids) {

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


	}


	@Override
	public Windturbineinfodaytop2 selectByPrimaryKey(String id) {

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

		}
	 	return new Windturbineinfodaytop2();

	}


	@Override
	public int updateByPrimaryKeySelective(Windturbineinfodaytop2 record) {
		return windturbineinfodaytop2Mapper.updateByPrimaryKeySelective(record);
	}


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

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


		return windturbineinfodaytop2Mapper.insertSelective(record);
	}


	@Override
	public int updateByExampleSelective(Windturbineinfodaytop2 record, Windturbineinfodaytop2Example example) {

		return windturbineinfodaytop2Mapper.updateByExampleSelective(record, example);
	}


	@Override
	public int updateByExample(Windturbineinfodaytop2 record, Windturbineinfodaytop2Example example) {

		return windturbineinfodaytop2Mapper.updateByExample(record, example);
	}

	@Override
	public List<Windturbineinfodaytop2> selectByExample(Windturbineinfodaytop2Example example) {

		return windturbineinfodaytop2Mapper.selectByExample(example);
	}


	@Override
	public long countByExample(Windturbineinfodaytop2Example example) {

		return windturbineinfodaytop2Mapper.countByExample(example);
	}


	@Override
	public int deleteByExample(Windturbineinfodaytop2Example example) {

		return windturbineinfodaytop2Mapper.deleteByExample(example);
	}


	public PageInfo<Windturbineinfodaytop2> gadaylistByPage(Tablepar tablepar,String wpId, Date recorddate)  {
		List<Windturbineinfodaytop2> list=null;

		Windturbineinfodaytop2Example example=new Windturbineinfodaytop2Example();

		if(StringUtils.isNotEmpty(tablepar.getOrderByColumn()))
		{
			StringBuilder sb=new StringBuilder();
			sb.append(" ").append(tablepar.getOrderByColumn());
			if(StringUtils.isNotEmpty(tablepar.getIsAsc()))
			{
				sb.append(" ").append(tablepar.getIsAsc());
			}else
			{
				sb.append(" asc ");
			}
			example.setOrderByClause(String.valueOf(sb));
		}else {
			example.setOrderByClause("windturbineid ASC");
		}


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

		if(recorddate!=null &&  StringUtils.isNotEmpty(wpId)){


			example.createCriteria().andWindpowerstationidEqualTo(wpId).andTypeEqualTo(1).andRecorddateGreaterThanOrEqualTo(recorddate).andRecorddateLessThan(DateUtils.addDays(recorddate,1));
			list= windturbineinfodaytop2Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}
		PageInfo<Windturbineinfodaytop2> pageInfo = new PageInfo<Windturbineinfodaytop2>(list);

		return pageInfo;
	}


	public PageInfo<Windturbineinfodaytop2> gamonthlistByPage(Tablepar tablepar,String wpId, String year,String month)  {
		List<Windturbineinfodaytop2> list=null;

		Windturbineinfodaytop2Example example=new Windturbineinfodaytop2Example();
		if(StringUtils.isNotEmpty(tablepar.getOrderByColumn()))
		{
			StringBuilder sb=new StringBuilder();
			sb.append(" ").append(tablepar.getOrderByColumn());
			if(StringUtils.isNotEmpty(tablepar.getIsAsc()))
			{
				sb.append(" ").append(tablepar.getIsAsc());
			}else
			{
				sb.append(" asc ");
			}
			example.setOrderByClause(String.valueOf(sb));
		}else {
			example.setOrderByClause("windturbineid ASC");
		}

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

		if(StringUtils.isNotEmpty(year) && StringUtils.isNotEmpty(month) &&  StringUtils.isNotEmpty(wpId)){


			example.createCriteria().andWindpowerstationidEqualTo(wpId).andTypeEqualTo(2).andYearEqualTo(Integer.valueOf(year)).andMonthEqualTo(Integer.valueOf(month));
			list= windturbineinfodaytop2Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}

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

		return pageInfo;
	}


	public PageInfo<Windturbineinfodaytop2> gayearlistByPage(Tablepar tablepar,String wpId,String year)  {
		List<Windturbineinfodaytop2> list=null;

		Windturbineinfodaytop2Example example=new Windturbineinfodaytop2Example();
		if(StringUtils.isNotEmpty(tablepar.getOrderByColumn()))
		{
			StringBuilder sb=new StringBuilder();
			sb.append(" ").append(tablepar.getOrderByColumn());
			if(StringUtils.isNotEmpty(tablepar.getIsAsc()))
			{
				sb.append(" ").append(tablepar.getIsAsc());
			}else
			{
				sb.append(" asc ");
			}
			example.setOrderByClause(String.valueOf(sb));
		}else {
			example.setOrderByClause("windturbineid ASC");
		}

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

		if(StringUtils.isNotEmpty(wpId) &&  StringUtils.isNotEmpty(year)){


			example.createCriteria().andWindpowerstationidEqualTo(wpId).andTypeEqualTo(3).andYearEqualTo(Integer.valueOf(year));
			list= windturbineinfodaytop2Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}
		PageInfo<Windturbineinfodaytop2> pageInfo = new PageInfo<Windturbineinfodaytop2>(list);

		return pageInfo;
	}
	/******************************************************************************************************************/
	public List<Windturbineinfodaytop2> gadaylist(String wpId, Date recorddate)  {
		List<Windturbineinfodaytop2> list=null;

		Windturbineinfodaytop2Example example=new Windturbineinfodaytop2Example();
		example.setOrderByClause("windturbineid ASC");

		if(recorddate!=null &&  StringUtils.isNotEmpty(wpId)){


			example.createCriteria().andWindpowerstationidEqualTo(wpId).andTypeEqualTo(1).andRecorddateGreaterThanOrEqualTo(recorddate).andRecorddateLessThan(DateUtils.addDays(recorddate,1));
			list= windturbineinfodaytop2Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}


		return list;
	}

	public List<Windturbineinfodaytop2> gamonthlist(String wpId, String year,String month)  {
		List<Windturbineinfodaytop2> list=null;

		Windturbineinfodaytop2Example example=new Windturbineinfodaytop2Example();
		example.setOrderByClause("windturbineid ASC");

		if(StringUtils.isNotEmpty(year) && StringUtils.isNotEmpty(month) &&  StringUtils.isNotEmpty(wpId)){


			example.createCriteria().andWindpowerstationidEqualTo(wpId).andTypeEqualTo(2).andYearEqualTo(Integer.valueOf(year)).andMonthEqualTo(Integer.valueOf(month));
			list= windturbineinfodaytop2Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}


		return list;
	}

	public List<Windturbineinfodaytop2> gayearlist(String wpId, String year)  {
		List<Windturbineinfodaytop2> list=null;

		Windturbineinfodaytop2Example example=new Windturbineinfodaytop2Example();
		example.setOrderByClause("windturbineid ASC");

		if(StringUtils.isNotEmpty(wpId) &&  StringUtils.isNotEmpty(year)){


			example.createCriteria().andWindpowerstationidEqualTo(wpId).andTypeEqualTo(3).andYearEqualTo(Integer.valueOf(year));
			list= windturbineinfodaytop2Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}


		return list;
	}


	public List<Windturbineinfodaytop2> gamonthlistByWtId(String wtId, String year,String month)  {
		List<Windturbineinfodaytop2> list=null;

		Windturbineinfodaytop2Example example=new Windturbineinfodaytop2Example();
		example.setOrderByClause("windturbineid ASC");

		if(StringUtils.isNotEmpty(year) && StringUtils.isNotEmpty(month) &&  StringUtils.isNotEmpty(wtId)){


			example.createCriteria().andWindturbineidEqualTo(wtId).andTypeEqualTo(2).andYearEqualTo(Integer.valueOf(year)).andMonthEqualTo(Integer.valueOf(month));
			list= windturbineinfodaytop2Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}


		return list;
	}
	/******************************************************************************************************************/
	public List<ValueVo> wtchart(String gaid) {


		if (StringUtils.isNotEmpty(gaid)) {
			List<ValueVo> vos = new ArrayList<ValueVo>();

			Windturbineinfodaytop2 wtd = windturbineinfodaytop2Mapper.selectByPrimaryKey(Integer.valueOf(gaid));

			for (int i = 0; i < 10; i++) {
				ValueVo vo = new ValueVo();

				switch (i) {
					case 0:
						// vo.setName("N("+winfo.getN4()+"/"+winfo.getN()+")");
						vo.setName("平均切入风速");
						// vo.setData1(wtd.getMonthxfqr());
						vo.setData1(wtd.getYearxfqr());
						break;
					case 1:
						// vo.setName("NNE("+winfo.getNne4()+"/"+winfo.getNne()+")");
						vo.setName("性能损失电量");
						// vo.setData1(wtd.getMonthxnssdl());
						vo.setData1(wtd.getYearxnssdl());
						break;
					case 2:
						// vo.setName("NE("+winfo.getNe4()+"/"+winfo.getNe()+")");
						vo.setName("拟合优度");
						// vo.setData1(wtd.getMonthnhyd());
						vo.setData1(wtd.getYearnhyd());
						break;
					case 3:
						// vo.setName("ENE("+winfo.getEne4()+"/"+winfo.getEne()+")");
						vo.setName("功率一致性系数");
						// vo.setData1(wtd.getMonthglyzxxs());
						vo.setData1(wtd.getYearglyzxxs());
						break;
					case 4:
						// vo.setName("E("+winfo.getE4()+"/"+winfo.getE()+")");
						vo.setName("利用小时");
						// vo.setData1(wtd.getMonthlyxs());
						vo.setData1(wtd.getYearlyxs());
						break;
					case 5:
						// vo.setName("ESE("+winfo.getEse()+"/"+winfo.getEse()+")");
						vo.setName("设备可利用率");
						// vo.setData1(wtd.getMonthsbklyl());
						vo.setData1(wtd.getYearsbklyl());
						break;
					case 6:
						// vo.setName("ESE("+winfo.getEse()+"/"+winfo.getEse()+")");
						vo.setName("等效可利用系数");
						// vo.setData1(wtd.getMonthdxkyxs());
						vo.setData1(wtd.getYeardxkyxs());
						break;
					case 7:
						// vo.setName("ESE("+winfo.getEse()+"/"+winfo.getEse()+")");
						vo.setName("有效风时数");
						// vo.setData1(wtd.getMonthyxfss());
						vo.setData1(wtd.getYearyxfss());
						break;
					case 8:
						// vo.setName("ESE("+winfo.getEse()+"/"+winfo.getEse()+")");
						vo.setName("平均风速");
						// vo.setData1(wtd.getMonthdxkyxs());
						vo.setData1(wtd.getYeardxkyxs());
						break;
					case 9:
						// vo.setName("ESE("+winfo.getEse()+"/"+winfo.getEse()+")");
						vo.setName("静风频率");
						// vo.setData1(wtd.getMonthdxkyxs());
						vo.setData1(wtd.getYeardxkyxs());
						break;
					default:
						break;
				}

				vos.add(vo);

			}

			ValueVo vo1 = new ValueVo();
			vo1.setName(wtd.getWindturbineid());
			vos.add(vo1);
		return	vos;

		}

		return new ArrayList<>();
	}

	public List<ValueVo> wtchart(Windturbineinfodaytop2 wtd) {


		if (StringUtils.notEmp(wtd)) {
			List<ValueVo> vos = new ArrayList<ValueVo>();


			for (int i = 0; i < 10; i++) {
				ValueVo vo = new ValueVo();

				switch (i) {
					case 0:
						// vo.setName("N("+winfo.getN4()+"/"+winfo.getN()+")");
						vo.setName("平均切入风速");
						// vo.setData1(wtd.getMonthxfqr());
						vo.setData1(wtd.getYearxfqr());
						break;
					case 1:
						// vo.setName("NNE("+winfo.getNne4()+"/"+winfo.getNne()+")");
						vo.setName("性能损失电量");
						// vo.setData1(wtd.getMonthxnssdl());
						vo.setData1(wtd.getYearxnssdl());
						break;
					case 2:
						// vo.setName("NE("+winfo.getNe4()+"/"+winfo.getNe()+")");
						vo.setName("拟合优度");
						// vo.setData1(wtd.getMonthnhyd());
						vo.setData1(wtd.getYearnhyd());
						break;
					case 3:
						// vo.setName("ENE("+winfo.getEne4()+"/"+winfo.getEne()+")");
						vo.setName("功率一致性系数");
						// vo.setData1(wtd.getMonthglyzxxs());
						vo.setData1(wtd.getYearglyzxxs());
						break;
					case 4:
						// vo.setName("E("+winfo.getE4()+"/"+winfo.getE()+")");
						vo.setName("利用小时");
						// vo.setData1(wtd.getMonthlyxs());
						vo.setData1(wtd.getYearlyxs());
						break;
					case 5:
						// vo.setName("ESE("+winfo.getEse()+"/"+winfo.getEse()+")");
						vo.setName("设备可利用率");
						// vo.setData1(wtd.getMonthsbklyl());
						vo.setData1(wtd.getYearsbklyl());
						break;
					case 6:
						// vo.setName("ESE("+winfo.getEse()+"/"+winfo.getEse()+")");
						vo.setName("等效可利用系数");
						// vo.setData1(wtd.getMonthdxkyxs());
						vo.setData1(wtd.getYeardxkyxs());
						break;
					case 7:
						// vo.setName("ESE("+winfo.getEse()+"/"+winfo.getEse()+")");
						vo.setName("有效风时数");
						// vo.setData1(wtd.getMonthyxfss());
						vo.setData1(wtd.getYearyxfss());
						break;
					case 8:
						// vo.setName("ESE("+winfo.getEse()+"/"+winfo.getEse()+")");
						vo.setName("平均风速");
						// vo.setData1(wtd.getMonthdxkyxs());
						vo.setData1(wtd.getYeardxkyxs());
						break;
					case 9:
						// vo.setName("ESE("+winfo.getEse()+"/"+winfo.getEse()+")");
						vo.setName("静风频率");
						// vo.setData1(wtd.getMonthdxkyxs());
						vo.setData1(wtd.getYeardxkyxs());
						break;
					default:
						break;
				}

				vos.add(vo);

			}
			ValueVo vo1 = new ValueVo();
			vo1.setName(wtd.getWindturbineid());
			vos.add(vo1);
			return	vos;

		}

		return new ArrayList<>();
	}

	public  List<Windturbineinfodaytop2> getWindturbineinfodaytop2List(String wpId,int year,int month)
	{
		List<Windturbineinfodaytop2> vos=new ArrayList<>();

		if(StringUtils.notEmp(year) && StringUtils.notEmp(month))
		{
			PageHelper.startPage(1, 5);
			vos=windturbineinfodaytop2Mapper.getWindturbineinfodaytop2List(wpId,year,month);
			PageInfo<Windturbineinfodaytop2> pageInfo = new PageInfo<Windturbineinfodaytop2>(vos);
			vos=pageInfo.getList();
		}

		return vos;
	}
}
