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.WindturbinepowercurvefittingMapper;
import com.gyee.frame.model.auto.Windturbinepowercurvefitting;
import com.gyee.frame.model.auto.WindturbinepowercurvefittingExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.SnowflakeIdWorker;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class WindturbinepowercurvefittingService implements BaseService<Windturbinepowercurvefitting, WindturbinepowercurvefittingExample> {
	@Resource
	private WindturbinepowercurvefittingMapper windturbinepowercurvefittingMapper;
	
      	   	      	      	      	      	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param tablepar
	 * @param name
	 * @return
	 */
	 public PageInfo<Windturbinepowercurvefitting> list(Tablepar tablepar, String name){
	        WindturbinepowercurvefittingExample testExample=new WindturbinepowercurvefittingExample();
	        testExample.setOrderByClause("id ASC");

	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<Windturbinepowercurvefitting> list= windturbinepowercurvefittingMapper.selectByExample(testExample);
	        PageInfo<Windturbinepowercurvefitting> pageInfo = new PageInfo<Windturbinepowercurvefitting>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista= Convert.toListStrArray(ids);
			WindturbinepowercurvefittingExample example=new WindturbinepowercurvefittingExample();
			example.createCriteria().andIdIn(lista);
			return windturbinepowercurvefittingMapper.deleteByExample(example);
			
				
	}


	@Override
	public Windturbinepowercurvefitting selectByPrimaryKey(String id) {
				
			return windturbinepowercurvefittingMapper.selectByPrimaryKey(id);
				
	}


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

	
	@Override
	public int updateByExample(Windturbinepowercurvefitting record, WindturbinepowercurvefittingExample example) {
		
		return windturbinepowercurvefittingMapper.updateByExample(record, example);
	}

	@Override
	public List<Windturbinepowercurvefitting> selectByExample(WindturbinepowercurvefittingExample example) {
		
		return windturbinepowercurvefittingMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WindturbinepowercurvefittingExample example) {
		
		return windturbinepowercurvefittingMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WindturbinepowercurvefittingExample example) {
		
		return windturbinepowercurvefittingMapper.deleteByExample(example);
	}

	public PageInfo<Windturbinepowercurvefitting>  getWindturbinepowercurvefitting(Tablepar tablepar, String wtId)  {


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

		WindturbinepowercurvefittingExample example=new WindturbinepowercurvefittingExample();
		if(StringUtils.isNotEmpty(tablepar.getOrderByColumn()))
		{
			StringBuilder sb=new StringBuilder();
			sb.append(" ").append(tablepar.getOrderByColumn());
			if(StringUtils.isNotEmpty(tablepar.getIsAsc()))
			{
				sb.append(" ").append(tablepar.getIsAsc());
			}else
			{
				sb.append(" asc ");
			}
			example.setOrderByClause(String.valueOf(sb));
		}else {
			example.setOrderByClause("speed ASC");
		}
		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());

		WindturbinepowercurvefittingExample.Criteria criteria =example.createCriteria();
		criteria.andWindturbineidEqualTo(wtId);
		list= windturbinepowercurvefittingMapper.selectByExample(example);

		PageInfo<Windturbinepowercurvefitting> pageInfo = new PageInfo<Windturbinepowercurvefitting>(list);
		return pageInfo;

	}

	public List<Windturbinepowercurvefitting> getWindturbinepowercurvefittingByWtId(String windturbineid)  {


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

		if(StringUtils.notEmp(windturbineid))
		{
			WindturbinepowercurvefittingExample example=new WindturbinepowercurvefittingExample();
			example.setOrderByClause("speed ASC");
			WindturbinepowercurvefittingExample.Criteria criteria =example.createCriteria();
			criteria.andWindturbineidEqualTo(windturbineid);
			list= windturbinepowercurvefittingMapper.selectByExample(example);
		}

		return list;

	}
}
