package cn.com.liandisys.ycjt.ggcx.admin.service.cms;

import java.util.List;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.com.liandisys.ycjt.ggcx.admin.dao.cms.CategoryDao;
import cn.com.liandisys.ycjt.ggcx.admin.model.cms.Category;

/**
 * 文章栏目service
 * @author jiangchao
 * @version 2016-11-29
 */
@Service
@Transactional(readOnly = true)
public class CategoryService {
	
	@Autowired
	private CategoryDao categoryDao;
	
	public Category findOne(String id){
		return categoryDao.findOne(id);
	}
	
	public List<Category> findAll(Sort sort){
		return categoryDao.findAll(sort);
	}

	@Transactional(readOnly = false)
	public void save(Category category) {
		if (StringUtils.isNotBlank(category.getViewConfig())){
            category.setViewConfig(StringEscapeUtils.unescapeHtml4(category.getViewConfig()));
        }
		categoryDao.save(category);
	}

	@Transactional(readOnly = false)
	public void delete(Category category) {
		categoryDao.delete(category);
	}

	public List<Category> findByParentId(String id) {
		return categoryDao.findByParentId(id);
	}
	public List<Category> findByParentIdByArticle(String id) {
		return categoryDao.findByParentIdByArticle(id);
	}

}
