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.WeatherfdMapper;
import com.gyee.frame.model.auto.Weatherfd;
import com.gyee.frame.model.auto.WeatherfdExample;
import com.gyee.frame.util.SnowflakeIdWorker;
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 WeatherfdService implements BaseService<Weatherfd, WeatherfdExample> {
	@Resource
	private WeatherfdMapper weatherfdMapper;
	

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=Convert.toListStrArray(ids);
			WeatherfdExample example=new WeatherfdExample();
			example.createCriteria().andIdIn(lista);
			return weatherfdMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public Weatherfd selectByPrimaryKey(String id) {
				
			return weatherfdMapper.selectByPrimaryKey(id);
				
	}

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

	
	@Override
	public int updateByExample(Weatherfd record, WeatherfdExample example) {
		
		return weatherfdMapper.updateByExample(record, example);
	}

	@Override
	public List<Weatherfd> selectByExample(WeatherfdExample example) {
		
		return weatherfdMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WeatherfdExample example) {
		
		return weatherfdMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WeatherfdExample example) {
		
		return weatherfdMapper.deleteByExample(example);
	}

	public List<Weatherfd> findWeatherfd(Date beginDate, Date endDate, String wpId) {

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

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

			WeatherfdExample example=new WeatherfdExample();
			example.setOrderByClause("recodedata DESC");

			WeatherfdExample.Criteria criteria =example.createCriteria();

			criteria.andRecodedataGreaterThanOrEqualTo(beginDate).andRecodedataLessThan(endDate);

			criteria.andWindpowerstationidEqualTo(wpId);
			criteria.andWindpowerstationidLike("%FDC");

			list= weatherfdMapper.selectByExample(example);

		}
		return list;

	}
}
