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.ProjectMapper;
import com.gyee.frame.model.auto.Project;
import com.gyee.frame.model.auto.ProjectExample;
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;

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

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

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

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

	
	@Override
	public int updateByExample(Project record, ProjectExample example) {
		
		return projectMapper.updateByExample(record, example);
	}

	@Override
	public List<Project> selectByExample(ProjectExample example) {
		
		return projectMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(ProjectExample example) {
		
		return projectMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(ProjectExample example) {
		
		return projectMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param project
	 * @return
	 */
	public int checkNameUnique(Project project){
		ProjectExample example=new ProjectExample();
		example.createCriteria().andCodeEqualTo(project.getCode());
		List<Project> list=projectMapper.selectByExample(example);
		return list.size();
	}


}
