package com.ym.mec.cms.service.impl;

import java.util.List;

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

import com.ym.mec.cms.dal.dao.SysNewsTypeDao;
import com.ym.mec.cms.dal.entity.SysNewsType;
import com.ym.mec.cms.dal.entity.SysNewsTypeTree;
import com.ym.mec.cms.service.SysNewsTypeService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;

@Service
public class SysNewsTypeServiceImpl extends BaseServiceImpl<Integer, SysNewsType>  implements SysNewsTypeService {
	
	@Autowired
	private SysNewsTypeDao sysNewsTypeDao;

	@Override
	public BaseDAO<Integer, SysNewsType> getDAO() {
		return sysNewsTypeDao;
	}

	@Override
	public List<SysNewsTypeTree> queryTree(Integer parentId) {
		if(parentId == null){
			parentId = 0 ;
		}
		List<SysNewsTypeTree> sysNewsTypeList = queryByParentId(parentId);
		if(sysNewsTypeList != null && sysNewsTypeList.size() > 0){
			for(SysNewsTypeTree type : sysNewsTypeList){
				type.setSubTypeList(queryTree(type.getId()));
			}
		}
		
		return sysNewsTypeList;
	}

	@Override
	public List<SysNewsTypeTree> queryByParentId(Integer parentId) {
		if(parentId == null){
			parentId = 0 ;
		}
		return sysNewsTypeDao.queryByParentId(parentId);
	}
	
}