package com.yonge.cooleshow.cms.service.impl;

import java.util.List;

import com.yonge.toolset.mybatis.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonge.cooleshow.cms.dal.dao.HelpCenterCatalogDao;
import com.yonge.cooleshow.cms.dal.entity.HelpCenterCatalog;
import com.yonge.cooleshow.cms.service.HelpCenterCatalogService;
import com.yonge.cooleshow.cms.service.HelpCenterContentService;
import com.yonge.toolset.mybatis.dal.BaseDAO;
import org.springframework.transaction.annotation.Transactional;

@Service
public class HelpCenterCatalogServiceImpl extends BaseServiceImpl<Long, HelpCenterCatalog> implements HelpCenterCatalogService {

	@Autowired
	private HelpCenterCatalogDao helpCenterCatalogDao;

	@Autowired
	private HelpCenterContentService helpCenterContentService;

	@Override
	public BaseDAO<Long, HelpCenterCatalog> getDAO() {

		return helpCenterCatalogDao;
	}

	@Override
	public List<HelpCenterCatalog> queryByParentId(Long parentId, Integer status) {

		List<HelpCenterCatalog> dataList = helpCenterCatalogDao.queryByParentId(parentId, status);
		if (dataList != null) {
			for (HelpCenterCatalog sub : dataList) {
				sub.setChildren(queryByParentId(sub.getId(), status));
			}
		}
		return dataList;
	}

	@Transactional
	public boolean updateCatalog(HelpCenterCatalog catalog) {
		return helpCenterCatalogDao.update(catalog) > 0 && helpCenterContentService.updateContentByCatalog(catalog.getId(), catalog.getStatus());
	}

	@Override
	@Transactional
	public boolean deleteCatalog(Long id) {
		return helpCenterCatalogDao.delete(id) > 0 && helpCenterContentService.deleteContentByCatalog(id);
	}

}
