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.WindTurbineTestingPointDi2Mapper;
import com.gyee.frame.model.auto.WindTurbineTestingPointDi2;
import com.gyee.frame.model.auto.WindTurbineTestingPointDi2Example;
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;

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

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

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

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

	
	@Override
	public int updateByExample(WindTurbineTestingPointDi2 record, WindTurbineTestingPointDi2Example example) {
		
		return windTurbineTestingPointDi2Mapper.updateByExample(record, example);
	}

	@Override
	public List<WindTurbineTestingPointDi2> selectByExample(WindTurbineTestingPointDi2Example example) {
		
		return windTurbineTestingPointDi2Mapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WindTurbineTestingPointDi2Example example) {
		
		return windTurbineTestingPointDi2Mapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WindTurbineTestingPointDi2Example example) {
		
		return windTurbineTestingPointDi2Mapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param windTurbineTestingPointDi
	 * @return
	 */
	public int checkNameUnique(WindTurbineTestingPointDi2 windTurbineTestingPointDi){
		WindTurbineTestingPointDi2Example example=new WindTurbineTestingPointDi2Example();
		example.createCriteria().andCodeEqualTo(windTurbineTestingPointDi.getCode());
		List<WindTurbineTestingPointDi2> list=windTurbineTestingPointDi2Mapper.selectByExample(example);
		return list.size();
	}

	public WindTurbineTestingPointDi2 getWindTurbineTestingPointDi2(String wtId, String unicode)  {

		WindTurbineTestingPointDi2 point=new WindTurbineTestingPointDi2();
		if(StringUtils.notEmp(wtId) && StringUtils.notEmp(unicode) )
		{
			WindTurbineTestingPointDi2Example example=new WindTurbineTestingPointDi2Example();
			example.setOrderByClause("id ASC");
			WindTurbineTestingPointDi2Example.Criteria criteria =example.createCriteria();
			criteria.andWindturbineidEqualTo(wtId);
			criteria.andUniformcodeEqualTo(unicode);
			List<WindTurbineTestingPointDi2> list= windTurbineTestingPointDi2Mapper.selectByExample(example);
			if(!list.isEmpty())
			{
				point=list.get(0);
			}
		}

		return point;
	}

	public List<WindTurbineTestingPointDi2> getWindTurbineTestingPointDi2List(String wtId,List<String> unicoadels)  {

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


		if(StringUtils.notEmp(wtId)  && StringUtils.notEmp(unicoadels))
		{
			WindTurbineTestingPointDi2Example example=new WindTurbineTestingPointDi2Example();
			example.setOrderByClause("id ASC");
			example.isDistinct();
			WindTurbineTestingPointDi2Example.Criteria criteria =example.createCriteria();
			criteria.andWindturbineidEqualTo(wtId);
			criteria.andUniformcodeIn(unicoadels);
			list= windTurbineTestingPointDi2Mapper.selectByExample(example);

		}

		return list;
	}


}
