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.InputoroutputspeedtotalMapper;
import com.gyee.frame.model.auto.Inputoroutputspeedtotal;
import com.gyee.frame.model.auto.InputoroutputspeedtotalExample;
import com.gyee.frame.model.custom.SingleAnalysisVo;
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 InputoroutputspeedtotalService implements BaseService<Inputoroutputspeedtotal, InputoroutputspeedtotalExample> {
	@Resource
	private InputoroutputspeedtotalMapper inputoroutputspeedtotalMapper;
	

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

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

				
		return inputoroutputspeedtotalMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Inputoroutputspeedtotal record, InputoroutputspeedtotalExample example) {
		
		return inputoroutputspeedtotalMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Inputoroutputspeedtotal record, InputoroutputspeedtotalExample example) {
		
		return inputoroutputspeedtotalMapper.updateByExample(record, example);
	}

	@Override
	public List<Inputoroutputspeedtotal> selectByExample(InputoroutputspeedtotalExample example) {
		
		return inputoroutputspeedtotalMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(InputoroutputspeedtotalExample example) {
		
		return inputoroutputspeedtotalMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(InputoroutputspeedtotalExample example) {
		
		return inputoroutputspeedtotalMapper.deleteByExample(example);
	}

	public List<Inputoroutputspeedtotal> getInputoroutputspeedtotal(Tablepar tablepar, String wpId, Date recorddate) {


		List<Inputoroutputspeedtotal> list = null;

		if (StringUtils.notEmp(wpId) && StringUtils.notEmp(recorddate)) {

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

			if (StringUtils.notEmp(wpId) && StringUtils.notEmp(recorddate)) {

				InputoroutputspeedtotalExample.Criteria criteria =example.createCriteria();
				criteria.andWindpowerstationidEqualTo(wpId);

				Date endDate= DateUtils.addDays(recorddate,1);
				criteria.andRecorddateGreaterThanOrEqualTo(recorddate).andRecorddateLessThan(endDate);
				list = inputoroutputspeedtotalMapper.selectByExample(example);

			} else {
				list = new ArrayList<>();
			}

		}
		return list;

	}
	public List<Inputoroutputspeedtotal> getInputoroutputspeedtotal(String wtId,Date recorddate) {


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

		if (StringUtils.notEmp(wtId) && StringUtils.notEmp(recorddate)) {

			InputoroutputspeedtotalExample example = new InputoroutputspeedtotalExample();
			example.setOrderByClause("windturbineid asc");

			if (StringUtils.notEmp(wtId) && StringUtils.notEmp(recorddate)) {

				InputoroutputspeedtotalExample.Criteria criteria =example.createCriteria();
				criteria.andWindturbineidEqualTo(wtId);
				Date endDate= DateUtils.addDays(recorddate,1);
				criteria.andRecorddateGreaterThanOrEqualTo(recorddate).andRecorddateLessThan(endDate);
				list = inputoroutputspeedtotalMapper.selectByExample(example);

			} else {
				list = new ArrayList<>();
			}

		}
		return list;

	}

	public List<Inputoroutputspeedtotal> getInputoroutputspeedtotal(String wpId,Date beginDate,Date endDate) {


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

		if (StringUtils.notEmp(wpId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

			InputoroutputspeedtotalExample example = new InputoroutputspeedtotalExample();
			example.setOrderByClause(" windturbineid asc");

			InputoroutputspeedtotalExample.Criteria criteria =example.createCriteria();
			criteria.andWindpowerstationidEqualTo(wpId);

			criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);
			list = inputoroutputspeedtotalMapper.selectByExample(example);


		}
		return list;

	}

	public List<Inputoroutputspeedtotal> getInputoroutputspeedtotalbyWtId(String wtId,Date beginDate,Date endDate) {


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

		if (StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

			InputoroutputspeedtotalExample example = new InputoroutputspeedtotalExample();
			example.setOrderByClause(" recorddate  asc");

			InputoroutputspeedtotalExample.Criteria criteria =example.createCriteria();
			criteria.andWindturbineidEqualTo(wtId);

			criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);
			list = inputoroutputspeedtotalMapper.selectByExample(example);


		}
		return list;

	}

	public List<Inputoroutputspeedtotal> getInputoroutputspeedtotal(Tablepar tablepar,String wpId,String wtId,Date beginDate,Date endDate) {


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

		if (StringUtils.notEmp(wpId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

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

			InputoroutputspeedtotalExample.Criteria criteria =example.createCriteria();
			criteria.andWindpowerstationidEqualTo(wpId);

			if(StringUtils.notEmp(wtId))
			{
				criteria.andWindturbineidEqualTo(wtId);
			}

			criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);
			list = inputoroutputspeedtotalMapper.selectByExample(example);


		}
		return list;

	}

	public List<SingleAnalysisVo>  getInputoroutputspeedtotalMapper(String wpId,Date beginDate,Date endDate) {

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


		if (StringUtils.notEmp(wpId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {


			list = inputoroutputspeedtotalMapper.getInputoroutputspeedtotal(wpId,beginDate,endDate);


		}
		return list;

	}


	public List<SingleAnalysisVo>  getInputoroutputspeedtotalMapperByWtId(String wtId,Date beginDate,Date endDate) {

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


		if (StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {


			list = inputoroutputspeedtotalMapper.getInputoroutputspeedtotalByWtId(wtId,beginDate,endDate);


		}
		return list;

	}


}
