/** 
 * @Title: KeysWordSerivceImpl.java 
 * @Package com.zhiweidata.bjfzxWebapp.mongoSerivce.impl 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author xuyimeng 
 * @date 2018年2月6日 上午10:59:51 
 * @version V1.0 
 */ /**
 * 
 */
package com.zhiweidata.bjfzxWebapp.service.Impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.zhiweidata.bjfzxWebapp.entity.Keyword;
import com.zhiweidata.bjfzxWebapp.exception.ZhiweiException;
import com.zhiweidata.bjfzxWebapp.mongoDao.KeysWordDAO;
import com.zhiweidata.bjfzxWebapp.service.KeysWordSerivce;

/** 
 * @ClassName: KeysWordSerivceImpl 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author xuyimeng 
 * @date 2018年2月6日 上午10:59:51  
 */
@Service
public class KeysWordSerivceImpl implements KeysWordSerivce{
	@Resource
	KeysWordDAO keysWordDAO;
	private static Logger log = LoggerFactory.getLogger(KeysWordSerivceImpl.class);
	@Override
	public List<Keyword> findNoShieldList() {
		try 
		{
			Query query = new Query();
			query.addCriteria(Criteria.where("isShield").is(0));
			return keysWordDAO.find(query);
		} 
		catch (ZhiweiException e) 
		{
			log.warn("获取非隐藏关键字出错："+e.getMessage());
			return null;
		}
	}

	@Override
	public List<Keyword> findNoShieldListByGroup(String group) {
		try 
		{
			return keysWordDAO.findNoShieldListByGroup(group);
		} 
		catch (ZhiweiException e) 
		{
			log.warn("获取非隐藏关键字出错："+e.getMessage());
			return null;
		}
	}
	
	@Override
	public List<String> findAllKeyByGroup(String group) {
		try 
		{	
			List<String> result = new ArrayList<>();
			List<Keyword> list = keysWordDAO.findNoShieldListByGroup(group);
			
			for (Keyword keyword : list)
			{
				result.add(keyword.getKeyword());
			}
			return result;
		} 
		catch (ZhiweiException e) 
		{
			log.warn("获取非隐藏关键字出错："+e.getMessage());
			return null;
		}
	}
}
