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.mapper.auto.WindpowerinfodayMapper;
import com.gyee.frame.model.auto.Windpowerinfoday;
import com.gyee.frame.model.auto.WindpowerinfodayExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.netty.websocket.util.SocketToolService;
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 
 * @author Wang Jiawen_自动生成
 * @email 1@qq.com
 * @date 2020-01-07 16:13:24  
 **/
@Service
public class WindpowerinfodayService extends SocketToolService implements BaseService<Windpowerinfoday, WindpowerinfodayExample>{
	@Resource
	private WindpowerinfodayMapper windpowerinfodayMapper;
	
      	   	      	      	      	      	      	      	      	      	      	      	      	      	      	      	      	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param windpowerstationid
	 * @return
	 */
	 public PageInfo<Windpowerinfoday> list(Tablepar tablepar,String name,String windpowerstationid) throws ParseException {
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		    Date recodedate = sdf.parse(name);
	        WindpowerinfodayExample testExample=new WindpowerinfodayExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
				testExample.createCriteria().andRecorddateEqualTo(recodedate);
	        }

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


	/**
	 *
	 * @return
	 * @throws ParseException
	 */
	public Windpowerinfoday findListByDate(String wpid,Date recorddate) throws ParseException {

		Windpowerinfoday wpi=null;

		if(recorddate!=null&&!"".equals(recorddate) && wpid!=null&&!"".equals(wpid)){


			Date recodedatebegin =recorddate;
			Date recodedateend = DateUtils.addDays(recodedatebegin,1);
			WindpowerinfodayExample testExample=new WindpowerinfodayExample();
			testExample.setOrderByClause("id ASC");
			testExample.createCriteria().andForeignkeyidEqualTo(wpid).andRecorddateBetween(recodedatebegin,recodedateend);
			List<Windpowerinfoday> list= windpowerinfodayMapper.selectByExample(testExample);

			if(!list.isEmpty())
			{
				wpi=list.get(0);
			}
		}
		return wpi;
	
	}
	

	


    @Override
	public String convertmessage(Object message){
		return "123456";
	}



	@Override
	public int deleteByPrimaryKey(String ids) {
				
		
			return -1;
			
				
	}
	
	
	@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) {
				
		
			
				
		return -1;
	}
	
	
	@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);
	}
	
	/**
	 * 检查name
	 * @param windpowerinfoday
	 * @return
	 */
	public int checkNameUnique(Windpowerinfoday windpowerinfoday){
		WindpowerinfodayExample example=new WindpowerinfodayExample();
		example.createCriteria().andRecorddateEqualTo(windpowerinfoday.getRecorddate());
		List<Windpowerinfoday> list=windpowerinfodayMapper.selectByExample(example);
		return list.size();
	}




}