/**
 * 
 */
package org.ccpit.front;

import java.util.List;

import javax.transaction.Transactional;

import org.ccpit.base.utils.DateConvert;
import org.ccpit.business.newsManage.NewsInfo;
import org.ccpit.business.newsManage.NewsInfoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Company Name : 中贸促信息技术有限责任公司 Project Name:memberManageSys File
 * Name:DownloadFileController.java Package Name:ccpit.base.controller Date:
 * 2017年3月27日 上午9:03:47 Copyright (c) 2016, liyang@ccpit.org All Rights
 * Reserved.
 *
 */
@Transactional
@Service
public class IndexService {

	@Autowired
	private NewsInfoDao newsInfoDao;

	
	
	/**
	 * 头图查询
	 * 
	 * @return List<NewsInfo>
	 */
	public List<NewsInfo> fillHead () {
		String hql = "from NewsInfo where carousel = '是' ";
		String allNews  = "from NewsInfo where carousel = '否' and newsType = '1' "
				+ "order by createTime desc" ;
		List<NewsInfo> result = newsInfoDao.query(hql);
		result.addAll(newsInfoDao.query(allNews));
		return result ;
	}

	/**
	 * 中心要闻查询
	 * 
	 * @return List<NewsInfo>
	 */
	public List<NewsInfo> fillInCenterNews() {
		String hql = "from NewsInfo where newsType = '1' order by createTime desc";
		return newsInfoDao.query(hql);
	}

	/**
	 * 港澳新闻查询
	 * 
	 * @return List<NewsInfo>
	 */
	public List<NewsInfo> fillInGANews() {
		String hql = "from NewsInfo where newsType = '2' order by createTime desc";
		return newsInfoDao.query(hql);
	}

	
	/**
	 * @param substring
	 * @return
	 */
	private String newsInfoHtml(String id, StringBuffer s) {
		NewsInfo newsInfo = newsInfoDao.queryById(Long.parseLong(id));
		s.append("<div class='news-list'><dl><dt>");
		s.append("<a href='/front/news/");
		s.append(newsInfo.getId());
		s.append("'>");
		s.append("<img src='");
		s.append(newsInfo.getImagePath());
		s.append("'/></a>");
		s.append("</dt><dd><h3>");
		s.append("<a href='/front/news/");
		s.append(newsInfo.getId());
		s.append("'>");
		s.append(newsInfo.getTitle());
		s.append("</a></h3>");
		s.append("<div class='time'>");
		s.append(DateConvert.convertDateWithoutHms(newsInfo.getCreateTime()));
		s.append("</div>");
		s.append("<p class='txt'>");
		s.append(newsInfo.getNewsContent());
		s.append("</p>");
		s.append("</dd></dl></div>");
		return s.toString();
	}

	

	

}
