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.Windturbineinfodaytop3Mapper;
import com.gyee.frame.model.auto.Windturbineinfodaytop3;
import com.gyee.frame.model.auto.Windturbineinfodaytop3Example;
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;

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


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

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

	@Override
	public int deleteByPrimaryKey(String ids) {

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


	}


	@Override
	public Windturbineinfodaytop3 selectByPrimaryKey(String id) {

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

		}
	 	return new Windturbineinfodaytop3();

	}


	@Override
	public int updateByPrimaryKeySelective(Windturbineinfodaytop3 record) {
		return windturbineinfodaytop3Mapper.updateByPrimaryKeySelective(record);
	}


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

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


		return windturbineinfodaytop3Mapper.insertSelective(record);
	}


	@Override
	public int updateByExampleSelective(Windturbineinfodaytop3 record, Windturbineinfodaytop3Example example) {

		return windturbineinfodaytop3Mapper.updateByExampleSelective(record, example);
	}


	@Override
	public int updateByExample(Windturbineinfodaytop3 record, Windturbineinfodaytop3Example example) {

		return windturbineinfodaytop3Mapper.updateByExample(record, example);
	}

	@Override
	public List<Windturbineinfodaytop3> selectByExample(Windturbineinfodaytop3Example example) {

		return windturbineinfodaytop3Mapper.selectByExample(example);
	}


	@Override
	public long countByExample(Windturbineinfodaytop3Example example) {

		return windturbineinfodaytop3Mapper.countByExample(example);
	}


	@Override
	public int deleteByExample(Windturbineinfodaytop3Example example) {

		return windturbineinfodaytop3Mapper.deleteByExample(example);
	}


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

		Windturbineinfodaytop3Example example=new Windturbineinfodaytop3Example();

		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= windturbineinfodaytop3Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}
		PageInfo<Windturbineinfodaytop3> pageInfo = new PageInfo<Windturbineinfodaytop3>(list);

		return pageInfo;
	}


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

		Windturbineinfodaytop3Example example=new Windturbineinfodaytop3Example();
		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= windturbineinfodaytop3Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}

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

		return pageInfo;
	}


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

		Windturbineinfodaytop3Example example=new Windturbineinfodaytop3Example();
		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= windturbineinfodaytop3Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}
		PageInfo<Windturbineinfodaytop3> pageInfo = new PageInfo<Windturbineinfodaytop3>(list);

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

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

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


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


		return list;
	}

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

		Windturbineinfodaytop3Example example=new Windturbineinfodaytop3Example();
		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= windturbineinfodaytop3Mapper.selectByExample(example);
		}else
		{
			list=new ArrayList<>();
		}


		return list;
	}

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

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

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


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


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


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

			Windturbineinfodaytop3 wtd = windturbineinfodaytop3Mapper.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);

			}

		return	vos;

		}

		return new ArrayList<>();
	}

	
}
