package com.gyee.frame.service;

import java.util.List;
import java.util.Arrays;
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.GyeeorganMapper;
import com.gyee.frame.model.auto.Gyeeorgan;
import com.gyee.frame.model.auto.GyeeorganExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.SnowflakeIdWorker;

/**
 *  GyeeorganService
 * @Title: GyeeorganService.java 
 * @Package com.gyee.frame.service 
 * @author gyee_自动生成
 * @email 1@qq.com
 * @date 2020-04-17 14:18:03  
 **/
@Service
public class GyeeorganService implements BaseService<Gyeeorgan, GyeeorganExample>{
	@Autowired
	private GyeeorganMapper gyeeorganMapper;
	
      	   	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<Gyeeorgan> list(Tablepar tablepar,String name){
	        GyeeorganExample testExample=new GyeeorganExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andDescribesLike("%"+name+"%");
	        }

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

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

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

	
	@Override
	public int updateByExample(Gyeeorgan record, GyeeorganExample example) {
		
		return gyeeorganMapper.updateByExample(record, example);
	}

	@Override
	public List<Gyeeorgan> selectByExample(GyeeorganExample example) {
		
		return gyeeorganMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(GyeeorganExample example) {
		
		return gyeeorganMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(GyeeorganExample example) {
		
		return gyeeorganMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param gyeeorgan
	 * @return
	 */
	public int checkNameUnique(Gyeeorgan gyeeorgan){
		GyeeorganExample example=new GyeeorganExample();
		example.createCriteria().andDescribesEqualTo(gyeeorgan.getDescribes());
		List<Gyeeorgan> list=gyeeorganMapper.selectByExample(example);
		return list.size();
	}
	
	/**
	 * 
		 *@author:Li Miao
		 *
		 *@description: 通过userid查询风场权限
		 *
		 *@param:userid
		 *
		 *@return:List<Gyeeorgan>
		 *
		 *@createTime:2020年4月17日
		 *
	 */
	public List<Gyeeorgan> queryOrganByUserId(String userid){
		return gyeeorganMapper.queryOrganByUserId(userid);
	}


}
