package com.gyee.frame.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Arrays;

import com.gyee.frame.model.auto.Weatherfd;
import com.gyee.frame.model.auto.WeatherfdExample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.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.WeatherfhMapper;
import com.gyee.frame.model.auto.Weatherfh;
import com.gyee.frame.model.auto.WeatherfhExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.model.enumeration.Messagetype;
import com.gyee.frame.netty.websocket.util.SocketToolService;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.SnowflakeIdWorker;

/**
 *  WeatherfhService
 * @Title: WeatherfhService.java 
 * @Package com.gyee.frame.service 
 * @author Wang Jiawen_自动生成
 * @email 1@qq.com
 * @date 2020-01-07 16:14:18  
 **/
@Service
public class WeatherfhService extends SocketToolService implements BaseService<Weatherfh, WeatherfhExample>{
	@Autowired
	private WeatherfhMapper weatherfhMapper;
	
      	   	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @param windpowerstationid
	 * @return
	 */
	 public PageInfo<Weatherfh> list(Tablepar tablepar,String name,String windpowerstationid) throws ParseException {
		 	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		 	Date recodedate = sdf.parse(name);
	        WeatherfhExample testExample=new WeatherfhExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andDateLike(recodedate);
	        }

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<Weatherfh> list= weatherfhMapper.selectByExample(testExample);
			 for(Weatherfh weatherfh:list){
				 String windpowerstationid1 = weatherfh.getWindpowerstationid();
				 if(windpowerstationid1.equalsIgnoreCase(windpowerstationid)){
					 list.remove(weatherfh);
				 }
			 }
	        PageInfo<Weatherfh> pageInfo = new PageInfo<Weatherfh>(list);
	        return  pageInfo;
	 }
	 /**
	  * 
	 	 *@author:Li Miao
	 	 *
	 	 *@description: 查询从当前小时开始到未来16小时的按小时预测数据，用于推送给矩阵，包含当前小时
	 	 *
	 	 *@date:2020年2月19日
	 	 *
	  */
	 
	 public void listProphet7Day_17Hour() throws ParseException {

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
			String name =  sdf.format(DateUtils.getNowDate());
			Date recodedate = sdf.parse(name);
			Date recodedateend = DateUtils.addHours(recodedate, 16);
			WeatherfhExample testExample=new WeatherfhExample();
			testExample.setOrderByClause("id ASC");
			if(name!=null&&!"".equals(name)){
				testExample.createCriteria().andDateGreaterThanOrEqualTo(recodedate).andDateLessThanOrEqualTo(recodedateend);
			}
			List<Weatherfh> list= weatherfhMapper.selectByExample(testExample);
			this.pushToWeb("pageNumber_3","functionNumber_2",list, Messagetype.MESSAGE);
		}

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = Convert.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			WeatherfhExample example=new WeatherfhExample();
			example.createCriteria().andIdIn(stringB);
			return weatherfhMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public Weatherfh selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return weatherfhMapper.selectByPrimaryKey(id1);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(Weatherfh record) {
		return weatherfhMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(Weatherfh record) {
				
		record.setId(null);
		
				
		return weatherfhMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Weatherfh record, WeatherfhExample example) {
		
		return weatherfhMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Weatherfh record, WeatherfhExample example) {
		
		return weatherfhMapper.updateByExample(record, example);
	}

	@Override
	public List<Weatherfh> selectByExample(WeatherfhExample example) {
		
		return weatherfhMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WeatherfhExample example) {
		
		return weatherfhMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WeatherfhExample example) {
		
		return weatherfhMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param weatherfh
	 * @return
	 */
	public int checkNameUnique(Weatherfh weatherfh){
		WeatherfhExample example=new WeatherfhExample();
		example.createCriteria().andDateEqualTo(weatherfh.getDate());
		List<Weatherfh> list=weatherfhMapper.selectByExample(example);
		return list.size();
	}


}
