| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package com.goafanti.news.service;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.cache.annotation.CacheEvict;
- import org.springframework.cache.annotation.CachePut;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.goafanti.common.dao.NewsMapper;
- import com.goafanti.common.model.News;
- import com.goafanti.common.utils.LoggerUtils;
- import com.goafanti.core.mybatis.BaseMybatisDao;
- import com.goafanti.news.bo.NewsSummary;
- @Service
- @Transactional
- public class NewsService extends BaseMybatisDao<NewsMapper> {
- @Autowired
- NewsMapper newsMapper;
- private static final Logger logger = LoggerFactory.getLogger(NewsService.class);
- @Cacheable(value = "NewsCache", key = "'News:'+#id")
- public News selectById(Long id) {
- return newsMapper.selectByPrimaryKey(id);
- }
- @Cacheable(value = "NewsListCache", key = "'NewsList:Page:'+#pageNo+'Type:'+#type+'Size:'+#pageSize")
- public List<NewsSummary> findNewsList(Integer pageNo, Integer type, Integer pageSize) {
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("type", type);
- params.put("pageSize", pageSize);
- params.put("pageNo", pageNo);
- return newsMapper.findList(params);
- }
- @CacheEvict(value = "NewsListCache", allEntries = true)
- public void cleanList() {
- LoggerUtils.debug(logger, "清除新闻列表缓存");
- }
- @CacheEvict(value = "NewsCache", key = "'News:'+#id")
- public void clean(String id) {
- LoggerUtils.debug(logger, "清除新闻缓存:[%s]", id);
- }
- @CachePut(value = "NewsCache", key = "'News:'+#id")
- public News save(Long id, News news) {
- news.setId(id);
- newsMapper.insert(news);
- return news;
- }
- }
|