admin
2021-03-01 d73687bc6115007145b4aab050e4e29ff87fd8ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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);
    }
 
}