package com.yeshi.buwan.service.imp.news;
|
|
import com.yeshi.buwan.dao.news.FoundNewsDao;
|
import com.yeshi.buwan.dao.news.NewsDao;
|
import com.yeshi.buwan.dao.news.NewsTypeDao;
|
import com.yeshi.buwan.dao.news.SuperFoundNewsDao;
|
import com.yeshi.buwan.domain.news.FoundNews;
|
import com.yeshi.buwan.domain.news.News;
|
import com.yeshi.buwan.domain.news.NewsType;
|
import com.yeshi.buwan.domain.news.SuperFoundNews;
|
import com.yeshi.buwan.util.Constant;
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.io.Serializable;
|
import java.util.List;
|
|
@Service
|
public class NewsService {
|
@Resource
|
private NewsDao newsDao;
|
@Resource
|
private NewsTypeDao newsTypeDao;
|
@Resource
|
private FoundNewsDao foundNewsDao;
|
@Resource
|
private SuperFoundNewsDao superFoundNewsDao;
|
|
|
// 获取发现页面的图文数据
|
@Cacheable(value = "foundCache",key="'getNewsOnMain'+'-'+#detailSystemId")
|
public List<FoundNews> getNewsOnMain(String detailSystemId) {
|
return foundNewsDao.list("select sf.foundNews from SuperFoundNews sf where sf.detailSystem.id=" + detailSystemId
|
+ " order by sf.foundNews.orderby desc");
|
}
|
|
// 获取图文分类
|
@Cacheable(value="newsCache",key="'getNewsTypeList'")
|
public List<NewsType> getNewsTypeList() {
|
return newsTypeDao.list("from NewsType nt where nt.parent.id=1");
|
}
|
|
// 获取发现页面的图文数据
|
@Cacheable(value="newsCache",key="'getNewsList'+'-'+#type+'-'+#pageIndex")
|
public List<News> getNewsList(int type, int pageIndex) {
|
return newsDao.list(
|
"select ntc.content from NewsTypeContent ntc where ntc.type.id=? order by FROM_UNIXTIME(ntc.content.createtime/1000) desc",
|
(pageIndex - 1) * Constant.pageCount, Constant.pageCount, new Serializable[] { type + "" });
|
}
|
|
public Serializable addFoundNews(FoundNews news) {
|
return foundNewsDao.save(news);
|
}
|
|
public void addSuperFoundNews(SuperFoundNews superFoundNews) {
|
superFoundNewsDao.create(superFoundNews);
|
}
|
|
}
|