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.WindTurbineTestingPointAi2Mapper;
import com.gyee.frame.model.auto.WindTurbineTestingPointAi2;
import com.gyee.frame.model.auto.WindTurbineTestingPointAi2Example;
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.List;

/**
 * 风机AI测点 WindTurbineTestingPointAiService
 * @Title: WindTurbineTestingPointAiService.java 
 * @Package com.gyee.frame.service 
 * @author gyee_自动生成
 * @email 1@qq.com
 * @date 2019-12-31 14:58:09  
 **/
@Service
public class WindTurbineTestingPointAiService implements BaseService<WindTurbineTestingPointAi2, WindTurbineTestingPointAi2Example> {
	@Resource
	private WindTurbineTestingPointAi2Mapper windTurbineTestingPointAi2Mapper;
	
      	   	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param tablepar
	 * @param name
	 * @return
	 */
	 public PageInfo<WindTurbineTestingPointAi2> list(Tablepar tablepar, String name){
	        WindTurbineTestingPointAi2Example testExample=new WindTurbineTestingPointAi2Example();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andCodeLike("%"+name+"%");
	        }

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

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

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

	
	@Override
	public int updateByExample(WindTurbineTestingPointAi2 record, WindTurbineTestingPointAi2Example example) {
		
		return windTurbineTestingPointAi2Mapper.updateByExample(record, example);
	}

	@Override
	public List<WindTurbineTestingPointAi2> selectByExample(WindTurbineTestingPointAi2Example example) {
		
		return windTurbineTestingPointAi2Mapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WindTurbineTestingPointAi2Example example) {
		
		return windTurbineTestingPointAi2Mapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WindTurbineTestingPointAi2Example example) {
		
		return windTurbineTestingPointAi2Mapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param windTurbineTestingPointAi
	 * @return
	 */
	public int checkNameUnique(WindTurbineTestingPointAi2 windTurbineTestingPointAi){
		WindTurbineTestingPointAi2Example example=new WindTurbineTestingPointAi2Example();
		example.createCriteria().andCodeEqualTo(windTurbineTestingPointAi.getCode());
		List<WindTurbineTestingPointAi2> list=windTurbineTestingPointAi2Mapper.selectByExample(example);
		return list.size();
	}

	public WindTurbineTestingPointAi2 getWindTurbineTestingPointAi2(String wtId, String unicode)  {

		WindTurbineTestingPointAi2 point=new WindTurbineTestingPointAi2();
		WindTurbineTestingPointAi2Example example=new WindTurbineTestingPointAi2Example();

		if(StringUtils.isNotEmpty(wtId) &&  StringUtils.isNotEmpty(unicode)){


			example.createCriteria().andWindturbineidEqualTo(wtId).andUniformcodeEqualTo(unicode);
			List<WindTurbineTestingPointAi2> list= windTurbineTestingPointAi2Mapper.selectByExample(example);

			if(!list.isEmpty())
			{
				point=list.get(0);
			}
		}

		return point;
	}
}
