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.WindpowerinfodayMapper;
import com.gyee.frame.model.auto.Windpowerinfoday;
import com.gyee.frame.model.auto.WindpowerinfodayExample;
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;


@Service
public class WindpowerinfodayService implements BaseService<Windpowerinfoday, WindpowerinfodayExample> {
	@Resource
	private WindpowerinfodayMapper windpowerinfodayMapper;
	

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

	
	@Override
	public int updateByPrimaryKeySelective(Windpowerinfoday record) {
		return windpowerinfodayMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(Windpowerinfoday record) {
				
//		//添加雪花主键id
//		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return windpowerinfodayMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Windpowerinfoday record, WindpowerinfodayExample example) {
		
		return windpowerinfodayMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Windpowerinfoday record, WindpowerinfodayExample example) {
		
		return windpowerinfodayMapper.updateByExample(record, example);
	}

	@Override
	public List<Windpowerinfoday> selectByExample(WindpowerinfodayExample example) {
		
		return windpowerinfodayMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WindpowerinfodayExample example) {
		
		return windpowerinfodayMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WindpowerinfodayExample example) {
		
		return windpowerinfodayMapper.deleteByExample(example);
	}

	public List<Windpowerinfoday> getWindpowerinfodayList(String wpId, Date beginDate,Date endDate) {


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

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

			WindpowerinfodayExample example=new WindpowerinfodayExample();
			example.setOrderByClause("recorddate DESC");

			WindpowerinfodayExample.Criteria criteria =example.createCriteria();


			criteria.andWindpowerstationidEqualTo(wpId);
			criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);
			criteria.andLocationEqualTo("windpower");
			list= windpowerinfodayMapper.selectByExample(example);

		}
		return list;

	}

	public List<Windpowerinfoday> getWindpowerinfodayList(String wpId, Date recorddate) {


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

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

			WindpowerinfodayExample example=new WindpowerinfodayExample();
			example.setOrderByClause("recorddate DESC");

			WindpowerinfodayExample.Criteria criteria =example.createCriteria();


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

			criteria.andForeignkeyidEqualTo(wpId);

			list= windpowerinfodayMapper.selectByExample(example);

		}
		return list;

	}
}
