package com.gyee.frame.service;

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

import com.gyee.frame.model.enumeration.Messagetype;
import com.gyee.frame.netty.websocket.util.SocketToolService;
import com.gyee.frame.util.DateUtils;
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.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.SnowflakeIdWorker;

/**
 *  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 WeatherfdService extends SocketToolService implements BaseService<Weatherfd, WeatherfdExample>{
	@Autowired
	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;
	 }




	/**
	 *@author:Wang Jiawen
	 *
	 *@description: 查询今天的按天预测数据，用于推送给矩阵
	 *
	 *@param:[]
	 *
	 *@return:java.util.List<com.gyee.frame.model.auto.Weatherfd>
	 *
	 *@createTime:2020/1/8
	 *
	 */
	public void listProphet1() 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).andRecodedataLessThan(recodedateend);
		}
		List<Weatherfd> list= weatherfdMapper.selectByExample(testExample);
		this.pushToWeb("pageNumber_2","functionNumber_1",list, Messagetype.MESSAGE);
	}
	
	/**
	 * 
		 *@author:Li Miao
		 *
		 *@description: 查询从今天开始到未来7天的按天预测数据，用于推送给矩阵，包含当日
		 *		
		 *@date:2020年2月11日
		 *
	 */
	public void listProphet7() 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,7);
		WeatherfdExample testExample=new WeatherfdExample();
		testExample.setOrderByClause("id ASC");
		if(name!=null&&!"".equals(name)){
			testExample.createCriteria().andRecodedataGreaterThanOrEqualTo(recodedate).andRecodedataLessThan(recodedateend);
		}
		List<Weatherfd> list= weatherfdMapper.selectByExample(testExample);
		this.pushToWeb("pageNumber_3","functionNumber_1",list, Messagetype.MESSAGE);
	}
	
	/**
	 *@author:Li Zaixen
	 *
	 *@description: 查询从今天开始到未来8~15天的按天预测数据，用于推送给矩阵，包含当日
	 *
	 *@createTime:2020/2/13
	 *
	 */
	public void listProphet8_15() throws ParseException {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String name =  sdf.format(DateUtils.getNowDate());
		Date recodedate = sdf.parse(name);
		Date recodedatebegin = DateUtils.addDays(recodedate,8);
		Date recodedateend = DateUtils.addDays(recodedate,15);
		WeatherfdExample testExample=new WeatherfdExample();
		testExample.setOrderByClause("id ASC");
		if(name!=null&&!"".equals(name)){
			testExample.createCriteria().andRecodedataGreaterThanOrEqualTo(recodedatebegin).andRecodedataLessThanOrEqualTo(recodedateend);
		}
		List<Weatherfd> list= weatherfdMapper.selectByExample(testExample);
		this.pushToWeb("pageNumber_4","functionNumber_1",list, Messagetype.MESSAGE);
	
	}
	
	/**
	 *
	 *@author:Liu Zhuochen
	 *
	 *@description: 查询从今天开始到未来40天的按天预测数据，用于推送给矩阵，包含当日
	 *
	 *@date:2020年2月13日
	 *
	 */
	public void listProphet40() 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,40);
		WeatherfdExample testExample=new WeatherfdExample();
		testExample.setOrderByClause("id ASC");
		if(name!=null&&!"".equals(name)){
			testExample.createCriteria().andRecodedataGreaterThanOrEqualTo(recodedate).andRecodedataLessThan(recodedateend);
		}
		List<Weatherfd> list= weatherfdMapper.selectByExample(testExample);
		this.pushToWeb("pageNumber_5","functionNumber_1",list, Messagetype.MESSAGE);
	}
	


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



	@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);
	}
	
	/**
	 * 检查name
	 * @param weatherfd
	 * @return
	 */
	public int checkNameUnique(Weatherfd weatherfd){
		WeatherfdExample example=new WeatherfdExample();
		example.createCriteria().andRecodedataEqualTo(weatherfd.getRecodedata());
		List<Weatherfd> list=weatherfdMapper.selectByExample(example);
		return list.size();
	}


	/**
	 *@author:Liu Zhuochen
	 *
	 *@description: 气象信息转换为图标名称
	 *
	 *@param:[weatherInformation]气象信息文字描述数组
	 *
	 *@return:java.util.List<java.lang.String>
	 *
	 *@createTime:2020/2/20
	 *
	 */
	public List<String> weatherInformationChangePictureName(String[] weatherInformation) {
		List<String> list = new ArrayList<>();
		for (int i = 0; i < weatherInformation.length; i++) {
			String weatherInformationString = weatherInformation[i];
			if (weatherInformationString.contains("晴") && weatherInformationString.contains("云")) {
				list.add("taiYangYun");
			} else if (weatherInformationString.contains("晴")) {
				list.add("taiYang");
			}else if (weatherInformationString.contains("阴")) {
				list.add("yunYun");
			} else if (weatherInformationString.contains("云") && weatherInformationString.contains("多")) {
				list.add("yunYun");
			} else if (weatherInformationString.contains("晴") && weatherInformationString.contains("云") && weatherInformationString.contains("水")) {
				list.add("taiYangYunShui");
			} else if (weatherInformationString.contains("晴") && weatherInformationString.contains("电") && weatherInformationString.contains("水")) {
				list.add("taiYangShanDianShui");
			} else if (weatherInformationString.contains("雷") && weatherInformationString.contains("雨")) {
				list.add("yunShanDianShuiShui");
			} else if (weatherInformationString.contains("雷") && weatherInformationString.contains("水")) {
				list.add("yunShanDianShuiShui");
			}else if (weatherInformationString.contains("云") && weatherInformationString.contains("水") && weatherInformationString.contains("雪")) {
				list.add("yunShuiXue");
			} else if (weatherInformationString.contains("云") && weatherInformationString.contains("雨") && weatherInformationString.contains("雪")) {
				list.add("yunShuiXue");
			}else if (weatherInformationString.contains("云") && weatherInformationString.contains("水 ")) {
				list.add("yunShui");
			}else if (weatherInformationString.contains("云") && weatherInformationString.contains("雨")) {
				list.add("yunShui");
			}   else if (weatherInformationString.contains("晴") && weatherInformationString.contains("云") && weatherInformationString.contains("雪")) {
				list.add("taiYangYunXueXue");
			} else if (weatherInformationString.contains("云") && weatherInformationString.contains("雪")) {
				list.add("yunXue");
			} else if (weatherInformationString.contains("云") && weatherInformationString.contains("雪") && weatherInformationString.contains("雪")) {
				list.add("yunXueXue");
			} else if (weatherInformationString.contains("云") && weatherInformationString.contains("雪") && weatherInformationString.contains("雪") && weatherInformationString.contains("雪")) {
				list.add("yunSanXue");
			} else if (weatherInformationString.contains("云")  && weatherInformationString.contains("雪")) {
				list.add("yunYunXueXue");
			}  else if (weatherInformationString.contains("晚")) {
				list.add("yueLiang");
			} else if (weatherInformationString.contains("晚") && weatherInformationString.contains("云")) {
				list.add("yueLiangYun");
			} else if (weatherInformationString.contains("云") && weatherInformationString.contains("晚") && weatherInformationString.contains("云")) {
				list.add("yunYueLiangYun");
			} else if (weatherInformationString.contains("晚") && weatherInformationString.contains("云") && weatherInformationString.contains("水")) {
				list.add("yueLiangYunShui");
			} else if (weatherInformationString.contains("云") && weatherInformationString.contains("电") && weatherInformationString.contains("水")) {
				list.add("yunShanDianShui");
			} else if (weatherInformationString.contains("云") && weatherInformationString.contains("水") && weatherInformationString.contains("雪")) {
				list.add("yunShuiXue");
			} else if (weatherInformationString.contains("晚") && weatherInformationString.contains("云") && weatherInformationString.contains("雪")) {
				list.add("yueLiangYunXueXue");
			}else if (weatherInformationString.contains("雨") && weatherInformationString.contains("雪")) {
				list.add("yunShuiXue");
			}else if (weatherInformationString.contains("雨")) {
				list.add("yunShui");
			}else if (weatherInformationString.contains("水") && weatherInformationString.contains("雪")) {
				list.add("yunShuiXue");
			}else{
				list.add("taiYang");
			}

		}
		return list;
	}
	/**
	 *@author:Liu Zhuochen
	 *
	 *@description: 风向信息转换为图标名称
	 *
	 *@param:[windDirection]风向信息文字描述数组
	 *
	 *@return:java.util.List<java.lang.String>
	 *
	 *@createTime:2020/2/20
	 *
	 */
	public List<String> windDirectionChangePictureName(String[] windDirection) {
		List<String> list = new ArrayList<>();
		for (int i = 0; i < windDirection.length; i++) {
			String windDirectionString = windDirection[i];
			if (windDirectionString.contains("北") && windDirectionString.contains("东")) {
				list.add("beiDong");
			}else if (windDirectionString.contains("东") && windDirectionString.contains("南")) {
				list.add("dongNan");
			}else if (windDirectionString.contains("南") && windDirectionString.contains("西")) {
				list.add("nanXi");
			}else if (windDirectionString.contains("西") && windDirectionString.contains("北")) {
				list.add("xiBei");
			}else if (windDirectionString.contains("无")) {
				list.add("wuFeng");
			}else if (windDirectionString.contains("北")) {
				list.add("bei");
			}else if (windDirectionString.contains("东")) {
				list.add("dong");
			}else if (windDirectionString.contains("南")) {
				list.add("nan");
			}else if (windDirectionString.contains("西")) {
				list.add("xi");
			}else {
				list.add("bei");
			}

		}
		return list;
	}




}