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.WindturbinecurvefittingmonthMapper;
import com.gyee.frame.model.auto.Windturbinecurvefittingmonth;
import com.gyee.frame.model.auto.WindturbinecurvefittingmonthExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

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


@Service
public class WindturbinecurvefittingmonthService implements BaseService<Windturbinecurvefittingmonth, WindturbinecurvefittingmonthExample> {
	@Resource
	private WindturbinecurvefittingmonthMapper windturbinecurvefittingmonthMapper;
	

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<Integer> lista=Convert.toIntArrayList(ids);
			WindturbinecurvefittingmonthExample example=new WindturbinecurvefittingmonthExample();
			example.createCriteria().andIdIn(lista);
			return windturbinecurvefittingmonthMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public Windturbinecurvefittingmonth selectByPrimaryKey(String id) {
				
			return windturbinecurvefittingmonthMapper.selectByPrimaryKey(Integer.valueOf(id));
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(Windturbinecurvefittingmonth record) {
		return windturbinecurvefittingmonthMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(Windturbinecurvefittingmonth record) {
				

			
				
		return windturbinecurvefittingmonthMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Windturbinecurvefittingmonth record, WindturbinecurvefittingmonthExample example) {
		
		return windturbinecurvefittingmonthMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Windturbinecurvefittingmonth record, WindturbinecurvefittingmonthExample example) {
		
		return windturbinecurvefittingmonthMapper.updateByExample(record, example);
	}

	@Override
	public List<Windturbinecurvefittingmonth> selectByExample(WindturbinecurvefittingmonthExample example) {
		
		return windturbinecurvefittingmonthMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WindturbinecurvefittingmonthExample example) {
		
		return windturbinecurvefittingmonthMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WindturbinecurvefittingmonthExample example) {
		
		return windturbinecurvefittingmonthMapper.deleteByExample(example);
	}

	public List<Windturbinecurvefittingmonth> compareMonthChat(String windturbineid, Date date)  {


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

		WindturbinecurvefittingmonthExample example=new WindturbinecurvefittingmonthExample();
		example.setOrderByClause("speed ASC");

		WindturbinecurvefittingmonthExample.Criteria criteria =example.createCriteria();

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

		String[] strs = windturbineid.split(",");

		for (int i = 0; i < strs.length; i++) {
			idls.add(strs[i]);
		}

		criteria.andWindturbineidIn(idls);

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

		criteria.andYearEqualTo(String.valueOf(cal.get(Calendar.YEAR)));
		criteria.andMonthEqualTo(String.valueOf(cal.get(Calendar.MONTH)+1));


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

	}
	public List<Windturbinecurvefittingmonth> compareYearChat(String windturbineid, Date date)  {


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

		WindturbinecurvefittingmonthExample example=new WindturbinecurvefittingmonthExample();
		example.setOrderByClause("speed ASC");

		WindturbinecurvefittingmonthExample.Criteria criteria =example.createCriteria();

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

		String[] strs = windturbineid.split(",");

		for (int i = 0; i < strs.length; i++) {
			idls.add(strs[i]);
		}

		criteria.andWindturbineidIn(idls);

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

		criteria.andYearEqualTo(String.valueOf(cal.get(Calendar.YEAR)));

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

	}

	public List<Windturbinecurvefittingmonth> getWindturbinecurvefittingmonthList(String wpIps,Date endDate)  {


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

		WindturbinecurvefittingmonthExample example=new WindturbinecurvefittingmonthExample();
		example.setOrderByClause("speed ASC");

		WindturbinecurvefittingmonthExample.Criteria criteria =example.createCriteria();


//		if(StringUtils.notEmp(wpIps))
//		{
//			if(InitialRunner.wp_wtmap.containsKey(wpIps))
//			{
//				List<Windturbine> ls=InitialRunner.wp_wtmap.get(wpIps);
//				List<String> wtls=new ArrayList<>();
//				for (Windturbine wt : ls) {
//					wtls.add(wt.getId());
//				}
//				criteria.andWindturbineidIn(wtls);
//			}
//
//		}
		Calendar c= Calendar.getInstance();
		c.setTime(endDate);

		int year=c.get(Calendar.YEAR);
		int month=c.get(Calendar.MONTH)+1;
		criteria.andYearEqualTo(String.valueOf(year));
		criteria.andMonthEqualTo(String.valueOf(month));



		list= windturbinecurvefittingmonthMapper.selectByExample(example);


		return list;

	}

	public List<Windturbinecurvefittingmonth> getWindturbinecurvefittingmonthList(String windturbineid,String year,String month)  {


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

		WindturbinecurvefittingmonthExample example=new WindturbinecurvefittingmonthExample();
		example.setOrderByClause("speed ASC");

		WindturbinecurvefittingmonthExample.Criteria criteria =example.createCriteria();

		criteria.andWindturbineidEqualTo(windturbineid);
		criteria.andYearEqualTo(year);
		criteria.andMonthEqualTo(String.valueOf(Integer.valueOf(month)));

		list= windturbinecurvefittingmonthMapper.selectByExample(example);


		return list;

	}

	public PageInfo<Windturbinecurvefittingmonth> getWindturbinecurvefittingmonthList(Tablepar tablepar, String windturbineid, String year, String month)  {


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

		WindturbinecurvefittingmonthExample example=new WindturbinecurvefittingmonthExample();

		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("speed ASC");
		}
		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());

		WindturbinecurvefittingmonthExample.Criteria criteria =example.createCriteria();

		criteria.andWindturbineidEqualTo(windturbineid);
		criteria.andYearEqualTo(year);
		criteria.andMonthEqualTo(month);

		list= windturbinecurvefittingmonthMapper.selectByExample(example);

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

		return pageInfo;

	}
}
