package com.ssm.service.impl.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.ssm.mapper.system.SysDepartmentMapper;
import com.ssm.model.system.SysDepartment;
import com.ssm.service.system.SysDepartmentService;
import com.ssm.util.page.BeanUtil;
import com.ssm.util.page.PagedResult;

@Service
public class SysDepartmentServiceImpl implements SysDepartmentService{
	
	@Autowired
	private SysDepartmentMapper sysDapartmentMapper;
	
	@Override
	public List<SysDepartment> findAll() {
		return sysDapartmentMapper.selectAll();
	}
	
	@Override
	public List<SysDepartment> getDepartmentList() {
		// TODO Auto-generated method stub
		return sysDapartmentMapper.sysDepartmentList();
	}

	/**
	 * 职位查询
	 * */
	@Override
	public PagedResult<SysDepartment> sysDepartmentQuery(
			SysDepartment sysDepartment, Integer pageNo, Integer pageSize) {
		// TODO Auto-generated method stub
		
		// TODO Auto-generated method stub
		pageNo = pageNo == null?1:pageNo;  
	    pageSize = pageSize == null?10:pageSize;
	    PageHelper.startPage(pageNo,pageSize);  //startPage是告诉拦截器说我要开始分页了。分页参数是这两个。  
	    List<SysDepartment> list = sysDapartmentMapper.sysDepartmentQuery(sysDepartment);
/*	    for (SysDepartment sysDepartment2 : list) {
	    	if(sysDepartment2.getDeptrolecode()!=null ){
	    		String[] aa=sysDepartment2.getDeptrolecode().split("\\.");
	    		if(aa.length==0 || aa.length==1){
	    			sysDepartment2.setLevel(1);
				}else if(aa.length==2){
	    			sysDepartment2.setLevel(2);
				}else{
	    			sysDepartment2.setLevel(3);
				}
	    	}else{
    			sysDepartment2.setLevel(1);
	    	}
	    	
		}*/
		PagedResult<SysDepartment> pagedResult = BeanUtil.toPagedResult(list);  
		return pagedResult;
	}

	@Override
	public void updateByPrimaryKeySelective(SysDepartment record) {
		// TODO Auto-generated method stub
		this.sysDapartmentMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public void insertSelective(SysDepartment sysDepartment) {
		// TODO Auto-generated method stub
		this.sysDapartmentMapper.insertSelective(sysDepartment);
	}

	@Override
	public SysDepartment selectByPrimaryKey(Integer depid) {
		// TODO Auto-generated method stub
		return sysDapartmentMapper.selectByPrimaryKey(depid);
	}

	@Override
	public int countByExample() {
		// TODO Auto-generated method stub
		return sysDapartmentMapper.countByExample(null);
	}

	@Override
	public SysDepartment sysDepartmentParentid(Integer parentid) {
		// TODO Auto-generated method stub
		return sysDapartmentMapper.sysDepartmentParentid(parentid);
	}

	@Override
	public Integer selectParentid(Integer parentid) {
		// TODO Auto-generated method stub
		return sysDapartmentMapper.selectParentid(parentid);
	}

	@Override
	public Integer selectMaxParentid(Integer parentid) {
		// TODO Auto-generated method stub
		return sysDapartmentMapper.selectMaxParentid(parentid);
	}
}
