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.WindturbineMapper;
import com.gyee.frame.model.auto.Windturbine;
import com.gyee.frame.model.auto.WindturbineExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.SnowflakeIdWorker;
import org.springframework.stereotype.Service;

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

/**
 * 风机信息表 WindturbineService
 * @Title: WindturbineService.java 
 * @Package com.gyee.frame.service 
 * @author gyee_自动生成
 * @email 1@qq.com
 * @date 2019-12-30 17:00:04  
 **/
@Service
public class WindturbineService implements BaseService<Windturbine, WindturbineExample>{
	@Resource
	private WindturbineMapper windturbineMapper;
	
      	   	      	      	      	      	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param tablepar
	 * @param name
	 * @return
	 */
	 public PageInfo<Windturbine> list(Tablepar tablepar,String name){
	        WindturbineExample testExample=new WindturbineExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andCodeLike("%"+name+"%");
	        }

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

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

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

	
	@Override
	public int updateByExample(Windturbine record, WindturbineExample example) {
		
		return windturbineMapper.updateByExample(record, example);
	}

	@Override
	public List<Windturbine> selectByExample(WindturbineExample example) {
		
		return windturbineMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WindturbineExample example) {
		
		return windturbineMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WindturbineExample example) {
		
		return windturbineMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param windturbine
	 * @return
	 */
	public int checkNameUnique(Windturbine windturbine){
		WindturbineExample example=new WindturbineExample();
		example.createCriteria().andCodeEqualTo(windturbine.getCode());
		List<Windturbine> list=windturbineMapper.selectByExample(example);
		return list.size();
	}


}
