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.SysDictionaryMapper;
import com.ssm.model.system.SysDictionary;
import com.ssm.service.system.SysDictionaryService;
import com.ssm.util.page.BeanUtil;
import com.ssm.util.page.PagedResult;

@Service
public class SysDictionaryServiceImpl implements SysDictionaryService{
	
	@Autowired
	private SysDictionaryMapper sysDictionaryMapper;
	
	@Override
	public List<SysDictionary> selectByNamespace(String namespace) {
		return sysDictionaryMapper.selectByNamespace(namespace);
	}
	
	@Override
	public List<SysDictionary> selectByEnabledNamespace(String namespace) {
		return sysDictionaryMapper.selectByEnabledNamespace(namespace);
	}
	
	@Override
	public List<SysDictionary> selectConstCategory() {
		return sysDictionaryMapper.selectConstCategory();
	}
	
	/**
	 * 分页查询字典
	 */
	@Override
	public PagedResult<SysDictionary> findByCondition(SysDictionary record,
			Integer pageNo, Integer pageSize) {
		pageNo = pageNo == null ? 1 : pageNo;
		pageSize = pageSize == null ? 10 : pageSize;
		PageHelper.startPage(pageNo, pageSize);
		List<SysDictionary> list = sysDictionaryMapper.selectByCondition(record);
		PagedResult<SysDictionary>  pageresult = BeanUtil.toPagedResult(list);
		return pageresult;
	}

	@Override
	public PagedResult<SysDictionary> selectByCondition(SysDictionary record,
			Integer pageNo, Integer pageSize) {
		pageNo = pageNo == null ? 1 : pageNo;
		pageSize = pageSize == null ? 10 : pageSize;
		PageHelper.startPage(pageNo, pageSize);
		List<SysDictionary> list = sysDictionaryMapper.selectByCondition2(record);
		PagedResult<SysDictionary>  pageresult = BeanUtil.toPagedResult(list);
		return pageresult;
	}

	@Override
	public SysDictionary selectByNamespaceAndValue(String namespace,
			String value) {
		return sysDictionaryMapper.selectByNamespaceAndValue(namespace, value);
	}

	@Override
	public int saveSysDictionary(SysDictionary record) {
		return sysDictionaryMapper.insertSelective(record);
	}

	@Override
	public SysDictionary selectById(Integer id) {
		return sysDictionaryMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateSysDictionary(SysDictionary record) {
		return sysDictionaryMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public List<SysDictionary> selectByAllKeyword(String parseResumeSkill) {
		
		return sysDictionaryMapper.selectByEnabledNamespace(parseResumeSkill);
	}

}
