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.WindTurbineTestingPointDiMapper;
import com.gyee.frame.model.auto.WindTurbineTestingPointDi;
import com.gyee.frame.model.auto.WindTurbineTestingPointDiExample;
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<WindTurbineTestingPointDi, WindTurbineTestingPointDiExample> {
	@Resource
	private WindTurbineTestingPointDiMapper windTurbineTestingPointDi2Mapper;
	
      	   	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param tablepar
	 * @param name
	 * @return
	 */
	 public PageInfo<WindTurbineTestingPointDi> list(Tablepar tablepar, String name){
	        WindTurbineTestingPointDiExample testExample=new WindTurbineTestingPointDiExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andCodeLike("%"+name+"%");
	        }

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

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

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

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

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

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

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

	public WindTurbineTestingPointDi getWindTurbineTestingPointDi2(String wtId, String unicode)  {

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

		return point;
	}

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

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


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

		}

		return list;
	}

	public List<WindTurbineTestingPointDi> getWindTurbineTestingPointDi2List(String wtId)  {

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


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

		}

		return list;
	}
}
