package mobi.cangol.web.project.cms.service;

import java.util.List;

import mobi.cangol.web.common.search.Page;
import mobi.cangol.web.common.search.PageSearchEntity;
import mobi.cangol.web.common.service.BaseService;
import mobi.cangol.web.project.cms.dao.CategoryDao;
import mobi.cangol.web.project.cms.entity.Category;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class CategoryService implements BaseService<Category>{
	@Autowired
	private CategoryDao categoryDao;
	@Override
	public Category get(String id) {
		return categoryDao.get(id);
	}

	@Override
	public void delete(String id) throws Exception {
		categoryDao.deleteByKey(id);
	}

	@Override
	public void deleteAll(List<Category> list) throws Exception {
		categoryDao.deleteAll(list);
	}

	@Override
	public Page findPage(PageSearchEntity pEntity, int pageNo, int pageSize)
			throws Exception {
		return categoryDao.findByEntity(pEntity, pageNo, pageSize);
	}

	@Override
	public List<Category> getList(PageSearchEntity pEntity) throws Exception {
		return categoryDao.findListByEntity(pEntity);
	}

	@Override
	public void save(Category t) throws Exception {
		if (StringUtils.isBlank(t.getId())){
			categoryDao.save(t);
		}else{
			categoryDao.update(t);
		}
	}
	public List<Category> findByCategoryId(String categoryId) {
		PageSearchEntity pEntity=new PageSearchEntity();
		pEntity.addSearch("parentCategoryId", categoryId, "=");
		List<Category> list= categoryDao.findListByEntity(pEntity);
		return list;
	}
}
