package com.iamberry.wechat.service.news;

import java.util.List;

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

import com.iamberry.wechat.autiXSS.XSSHandler;
import com.iamberry.wechat.core.entity.news.News;
import com.iamberry.wechat.face.news.NewsService;
import com.iamberry.wechat.service.news.dao.NewsDao;

@Service
public class NewsServiceImpl implements NewsService {

	@Autowired
	private NewsDao newsDao;

	
	public List<News> listAll() {
		// TODO Auto-generated method stub
		List<News> news = newsDao.listAll();
		
		for (News obj : news) {
			obj.setNewsAuthor(XSSHandler.handle(obj.getNewsAuthor(), true, false, false));
			obj.setNewsDesc(XSSHandler.handle(obj.getNewsDesc(), true, false, false));
			obj.setNewsSource(XSSHandler.handle(obj.getNewsSource(), true, false, false));
			obj.setNewsSourceUrl(XSSHandler.handle(obj.getNewsSourceUrl(), true, false, false));
			obj.setNewsTitle(XSSHandler.handle(obj.getNewsTitle(), true, false, false));
			obj.setNewsImage(XSSHandler.handle(obj.getNewsImage(), true, false, false));
		}

		return news;
	}

	
	public List<News> listAll(boolean isScript) {
		// TODO Auto-generated method stub
		List<News> news = newsDao.listAll();
		
		for (News obj : news) {
			obj.setNewsAuthor(XSSHandler.handle(obj.getNewsAuthor(), true, false, false));
			obj.setNewsDesc(XSSHandler.handle(obj.getNewsDesc(), true, false, false));
			obj.setNewsSource(XSSHandler.handle(obj.getNewsSource(), true, false, false));
			obj.setNewsSourceUrl(XSSHandler.handle(obj.getNewsSourceUrl(), true, false, false));
			obj.setNewsTitle(XSSHandler.handle(obj.getNewsTitle(), true, false, false));
			obj.setNewsImage(XSSHandler.handle(obj.getNewsImage(), true, false, false));
		}
		
		return news;
	}

	
	public Integer addNews(News news) {
		// TODO Auto-generated method stub
		return newsDao.addNews(news);
	}

	
	public News getOne(Integer id) {
		// TODO Auto-generated method stub
		return newsDao.getOne(id);
	}

	
	public Integer updateOne(News news) {
		// TODO Auto-generated method stub
		return newsDao.updateOne(news);
	}

	
	public Integer updateAccess(Integer id) {
		// TODO Auto-generated method stub
		return newsDao.updateAccess(id);
	}

	
	public Integer updateShare(Integer id) {
		// TODO Auto-generated method stub
		return newsDao.updateShare(id);
	}
	
}
