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.CurvefittingmonthmainMapper;
import com.gyee.frame.model.auto.Curvefittingmonthmain;
import com.gyee.frame.model.auto.CurvefittingmonthmainExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.SnowflakeIdWorker;
import com.gyee.frame.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;


@Service
public class CurvefittingmonthmainService implements BaseService<Curvefittingmonthmain, CurvefittingmonthmainExample> {
	@Autowired
	private CurvefittingmonthmainMapper curvefittingmonthmainMapper;
	

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

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

	
	@Override
	public int updateByExample(Curvefittingmonthmain record, CurvefittingmonthmainExample example) {
		
		return curvefittingmonthmainMapper.updateByExample(record, example);
	}

	@Override
	public List<Curvefittingmonthmain> selectByExample(CurvefittingmonthmainExample example) {
		
		return curvefittingmonthmainMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(CurvefittingmonthmainExample example) {
		
		return curvefittingmonthmainMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(CurvefittingmonthmainExample example) {
		
		return curvefittingmonthmainMapper.deleteByExample(example);
	}

	public List<Curvefittingmonthmain> getCurvefittingmonthmainList(Tablepar tablepar, List<String> wtIds, String year, String month)  {

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

		if(StringUtils.notEmp(wtIds) && StringUtils.notEmp(year) && StringUtils.notEmp(month))
		{
			CurvefittingmonthmainExample example=new CurvefittingmonthmainExample();
			example.setOrderByClause(" deviationrate2 DESC");


			CurvefittingmonthmainExample.Criteria criteria =example.createCriteria();

			criteria.andWindturbineidIn(wtIds);
			criteria.andYearEqualTo(year);
			criteria.andMonthEqualTo(month);

			list=curvefittingmonthmainMapper.selectByExample(example);

			list=sortCurvefittingmonthmainList(tablepar, list);
		}


		return list;

	}

	public  List<Curvefittingmonthmain> sortCurvefittingmonthmainList(Tablepar tablepar,List<Curvefittingmonthmain> ls)
	{

		if (null !=tablepar && StringUtils.notEmp(tablepar.getOrderByColumn())) {

			switch (tablepar.getOrderByColumn()) {
				case "windturbineid":
					if (tablepar.getIsAsc().equals("asc")) {

						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o1.getWindturbineid().compareTo(o2.getWindturbineid());
							}

						});
					} else   {
						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o2.getWindturbineid().compareTo(o1.getWindturbineid());
							}

						});
					}
					break;
				case "monthdeviationrate":
					if (tablepar.getIsAsc().equals("asc")) {

						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o1.getMonthdeviationrate().compareTo(o2.getMonthdeviationrate());
							}

						});
					} else   {
						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o2.getMonthdeviationrate().compareTo(o1.getMonthdeviationrate());
							}

						});
					}
					break;
				case "yeardeviationrate":
					if (tablepar.getIsAsc().equals("asc")) {

						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o1.getYeardeviationrate().compareTo(o2.getYeardeviationrate());
							}

						});
					} else   {
						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o2.getYeardeviationrate().compareTo(o1.getYeardeviationrate());
							}

						});
					}
					break;
				case "standarddeviationrate":
					if (tablepar.getIsAsc().equals("asc")) {

						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o1.getStandarddeviationrate().compareTo(o2.getStandarddeviationrate());
							}

						});
					} else   {
						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o2.getStandarddeviationrate().compareTo(o1.getStandarddeviationrate());
							}

						});
					}
					break;
				case "deviationrate1":
					if (tablepar.getIsAsc().equals("asc")) {

						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o1.getDeviationrate1().compareTo(o2.getDeviationrate1());
							}

						});
					} else   {
						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o2.getDeviationrate1().compareTo(o1.getDeviationrate1());
							}

						});
					}
					break;
				case "deviationrate2":
					if (tablepar.getIsAsc().equals("asc")) {

						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o1.getDeviationrate2().compareTo(o2.getDeviationrate2());
							}

						});
					} else   {
						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o2.getDeviationrate2().compareTo(o1.getDeviationrate2());
							}

						});
					}
					break;
				case "deviationrate3":
					if (tablepar.getIsAsc().equals("asc")) {

						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o1.getDeviationrate3().compareTo(o2.getDeviationrate3());
							}

						});
					} else   {
						Collections.sort(ls, new Comparator<Curvefittingmonthmain>() {
							// 升序排序
							public int compare(Curvefittingmonthmain o1, Curvefittingmonthmain o2) {
								return o2.getDeviationrate3().compareTo(o1.getDeviationrate3());
							}

						});
					}
					break;
				default:

					break;
			}

		}
		return ls;
	}
}
