package com.gyee.frame.service;

import com.gyee.frame.common.base.BaseService;
import com.gyee.frame.common.support.Convert;
import com.gyee.frame.mapper.auto.WindturbineanalysisdayMapper;
import com.gyee.frame.model.auto.Windturbineanalysisday;
import com.gyee.frame.model.auto.WindturbineanalysisdayExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

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


@Service
public class WindturbineanalysisdayService implements BaseService<Windturbineanalysisday, WindturbineanalysisdayExample> {
	@Resource
	private WindturbineanalysisdayMapper windturbineanalysisdayMapper;
	

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

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

				
		return windturbineanalysisdayMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Windturbineanalysisday record, WindturbineanalysisdayExample example) {
		
		return windturbineanalysisdayMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Windturbineanalysisday record, WindturbineanalysisdayExample example) {
		
		return windturbineanalysisdayMapper.updateByExample(record, example);
	}

	@Override
	public List<Windturbineanalysisday> selectByExample(WindturbineanalysisdayExample example) {
		
		return windturbineanalysisdayMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WindturbineanalysisdayExample example) {
		
		return windturbineanalysisdayMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WindturbineanalysisdayExample example) {
		
		return windturbineanalysisdayMapper.deleteByExample(example);
	}


	public List<Windturbineanalysisday> comparelist(String windturbineid,Date date)  {


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

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

		WindturbineanalysisdayExample.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= windturbineanalysisdayMapper.selectByExample(example);
		return list;

	}

	public List<Windturbineanalysisday> goodhistorylist(Tablepar tablepar,String windturbineid, Date beginDate, Date endDate)  {


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

		WindturbineanalysisdayExample example=new WindturbineanalysisdayExample();
		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");
		}


		WindturbineanalysisdayExample.Criteria criteria =example.createCriteria();


		criteria.andWindturbineidEqualTo(windturbineid);


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


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

	}

}
