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.WindturbinecurvefittingMapper;
import com.gyee.frame.model.auto.Windturbinecurvefitting;
import com.gyee.frame.model.auto.WindturbinecurvefittingExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service
public class WindturbinecurvefittingService implements BaseService<Windturbinecurvefitting, WindturbinecurvefittingExample> {
	@Autowired
	private WindturbinecurvefittingMapper windturbinecurvefittingMapper;
	

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

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

			
				
		return windturbinecurvefittingMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Windturbinecurvefitting record, WindturbinecurvefittingExample example) {
		
		return windturbinecurvefittingMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Windturbinecurvefitting record, WindturbinecurvefittingExample example) {
		
		return windturbinecurvefittingMapper.updateByExample(record, example);
	}

	@Override
	public List<Windturbinecurvefitting> selectByExample(WindturbinecurvefittingExample example) {
		
		return windturbinecurvefittingMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WindturbinecurvefittingExample example) {
		
		return windturbinecurvefittingMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WindturbinecurvefittingExample example) {
		
		return windturbinecurvefittingMapper.deleteByExample(example);
	}

	public List<Windturbinecurvefitting> comparechatAjax(String windturbineid, Date date)  {


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

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

		WindturbinecurvefittingExample.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);

		Date endDate= DateUtils.addDays(date,1);
		criteria.andRecorddateGreaterThanOrEqualTo(date).andRecorddateLessThan(endDate);


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

	}

	public List<Windturbinecurvefitting> getWindturbinecurvefitting(String windturbineid)  {


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

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

		WindturbinecurvefittingExample.Criteria criteria =example.createCriteria();


		criteria.andWindturbineidEqualTo(windturbineid);

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

	}

	public List<Windturbinecurvefitting> getWindturbinecurvefittingByWtId(String windturbineid)  {


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

		if(StringUtils.notEmp(windturbineid))
		{
			list= windturbinecurvefittingMapper.getWindturbinecurvefittingByWtId(windturbineid);
		}

		return list;

	}

	public PageInfo<Windturbinecurvefitting>  getWindturbinecurvefitting(Tablepar tablepar, String wtId)  {


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

		WindturbinecurvefittingExample example=new WindturbinecurvefittingExample();
		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());

		WindturbinecurvefittingExample.Criteria criteria =example.createCriteria();
		criteria.andWindturbineidEqualTo(wtId);
		list= windturbinecurvefittingMapper.selectByExample(example);

		PageInfo<Windturbinecurvefitting> pageInfo = new PageInfo<Windturbinecurvefitting>(list);
		return pageInfo;

	}

	public PageInfo<Windturbinecurvefitting> comparechatAjax(Tablepar tablepar, String wtId, Date date)  {


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

		WindturbinecurvefittingExample example=new WindturbinecurvefittingExample();
		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());

		WindturbinecurvefittingExample.Criteria criteria =example.createCriteria();

		criteria.andWindturbineidEqualTo(wtId);
		Date endDate= DateUtils.addDays(date,1);
		criteria.andRecorddateGreaterThanOrEqualTo(date).andRecorddateLessThan(endDate);

		list= windturbinecurvefittingMapper.selectByExample(example);
		PageInfo<Windturbinecurvefitting> pageInfo = new PageInfo<Windturbinecurvefitting>(list);

		return pageInfo;

	}
	public List<Windturbinecurvefitting> comparechatAjax(List<String> wtIds, Date date)  {


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

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

		WindturbinecurvefittingExample.Criteria criteria =example.createCriteria();

		criteria.andWindturbineidIn(wtIds);

		Date endDate= DateUtils.addDays(date,1);
		criteria.andRecorddateGreaterThanOrEqualTo(date).andRecorddateLessThan(endDate);


		list= windturbinecurvefittingMapper.selectByExample(example);

		return list;

	}

}
