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.WeatherfdMapper;
import com.gyee.frame.model.auto.Weatherfd;
import com.gyee.frame.model.auto.WeatherfdExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *  WeatherfdService
 * @Title: WeatherfdService.java 
 * @Package com.gyee.frame.service 
 * @date 2020-01-07 16:13:24  
 **/
@Service
public class WeatherfdService  implements BaseService<Weatherfd, WeatherfdExample>{
	@Resource
	private WeatherfdMapper weatherfdMapper;


	/**
	 * 分页查询
	 * @param windpowerstationid
	 * @return
	 */
	public PageInfo<Weatherfd> list(Tablepar tablepar,String name,String windpowerstationid) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date recodedate = sdf.parse(name);
		WeatherfdExample testExample=new WeatherfdExample();
		testExample.setOrderByClause("id ASC");
		if(name!=null&&!"".equals(name)){
			testExample.createCriteria().andRecodedataLike(recodedate);
		}

		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
		List<Weatherfd> list= weatherfdMapper.selectByExample(testExample);
		for(Weatherfd weatherfd:list){
			String windpowerstationid1 = weatherfd.getWindpowerstationid();
			if(windpowerstationid1.equalsIgnoreCase(windpowerstationid)){
				list.remove(weatherfd);
			}
		}
		PageInfo<Weatherfd> pageInfo = new PageInfo<Weatherfd>(list);
		return  pageInfo;
	}



	/**
	 *
	 *@description: 查询今天的按天预测数据
	 *
	 *@param:[]
	 *
	 *@return:java.util.List<com.gyee.frame.model.auto.Weatherfd>
	 *
	 *
	 */
	public List<Weatherfd> listProphet() throws ParseException {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String name =  sdf.format(DateUtils.getNowDate());
		Date recodedate = sdf.parse(name);
		Date recodedateend = DateUtils.addDays(recodedate,1);
		WeatherfdExample testExample=new WeatherfdExample();
		testExample.setOrderByClause("id ASC");
		if(name!=null&&!"".equals(name)){
			testExample.createCriteria().andRecodedataGreaterThanOrEqualTo(recodedate);
		}
		List<Weatherfd> list= weatherfdMapper.selectByExample(testExample);

		return list;
	}


	public int deleteDays() throws ParseException {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String name =  sdf.format(DateUtils.getNowDate());
		Date recodedate = sdf.parse(name);

		WeatherfdExample example=new WeatherfdExample();
		example.createCriteria().andRecodedataGreaterThanOrEqualTo(recodedate);
		return weatherfdMapper.deleteByExample(example);


	}

	@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) {



		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);
	}





}