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.LineMapper;
import com.gyee.frame.model.auto.Line;
import com.gyee.frame.model.auto.LineExample;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线路 LineService
 * @Title: LineService.java 
 * @Package com.gyee.frame.service 
 * @author gyee_自动生成
 * @email 1@qq.com
 * @date 2019-12-31 14:58:09  
 **/
@Service
public class LineService implements BaseService<Line, LineExample> {
	@Autowired
	private LineMapper lineMapper;
	
      	   	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<Line> list(Tablepar tablepar, String name){
	        LineExample testExample=new LineExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andCodeLike("%"+name+"%");
	        }

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

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

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

	
	@Override
	public int updateByExample(Line record, LineExample example) {
		
		return lineMapper.updateByExample(record, example);
	}

	@Override
	public List<Line> selectByExample(LineExample example) {
		
		return lineMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(LineExample example) {
		
		return lineMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(LineExample example) {
		
		return lineMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param line
	 * @return
	 */
	public int checkNameUnique(Line line){
		LineExample example=new LineExample();
		example.createCriteria().andCodeEqualTo(line.getCode());
		List<Line> list=lineMapper.selectByExample(example);
		return list.size();
	}


}
