|
|
@@ -8,6 +8,7 @@ import java.util.Map;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
import org.springframework.cache.annotation.CachePut;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
@@ -30,9 +31,11 @@ import com.goafanti.news.bo.NewsSummary;
|
|
|
public class NewsService extends BaseMybatisDao<NewsMapper> {
|
|
|
@Autowired
|
|
|
NewsMapper newsMapper;
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
+ private String env;
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(NewsService.class);
|
|
|
-
|
|
|
+
|
|
|
@Cacheable(value = "IndexNewsListCache", key = "'NewsList:Page:'+#pageNo+'Type:'+#type+'Size:'+#pageSize")
|
|
|
public List<NewsSummary> findIndexNewsList(Integer pageNo, Integer type, Integer pageSize) {
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
@@ -52,13 +55,19 @@ public class NewsService extends BaseMybatisDao<NewsMapper> {
|
|
|
return newsMapper.selectByPrimaryKey(id);
|
|
|
}
|
|
|
|
|
|
- @Cacheable(value = "NewsListCache", key = "'NewsList:Page:'+#pageNo+'Type:'+#type+'Size:'+#pageSize+'domainName:'+#domainName")
|
|
|
- public List<NewsSummary> findNewsList(Integer pageNo, Integer type, Integer pageSize,String domainName) {
|
|
|
+ @Cacheable(value = "NewsListCache", key = "'NewsList:Page:'+#pageNo+'Type:'+#type+'Size:'+#pageSize+'domainName:'+#domainName+'picReq:'+#picRequired")
|
|
|
+ public List<NewsSummary> findNewsList(Integer pageNo, Integer type, Integer pageSize, String domainName,
|
|
|
+ Boolean picRequired) {
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
params.put("type", type);
|
|
|
params.put("pageSize", pageSize);
|
|
|
params.put("pageNo", pageNo);
|
|
|
- params.put("website", domainName);
|
|
|
+ if (!StringUtils.equals(env, "dev") && !StringUtils.equals(env, "local")) {
|
|
|
+ params.put("website", domainName);
|
|
|
+ }
|
|
|
+ if (picRequired) {
|
|
|
+ params.put("picRequired", picRequired);
|
|
|
+ }
|
|
|
return newsMapper.findList(params);
|
|
|
}
|
|
|
|
|
|
@@ -78,7 +87,7 @@ public class NewsService extends BaseMybatisDao<NewsMapper> {
|
|
|
newsMapper.insert(news);
|
|
|
return news;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@CachePut(value = "NewsCache", key = "'News:'+#id")
|
|
|
public News update(long id, News news) {
|
|
|
newsMapper.updateByPrimaryKeyWithBLOBs(news);
|
|
|
@@ -118,8 +127,8 @@ public class NewsService extends BaseMybatisDao<NewsMapper> {
|
|
|
if (StringUtils.isNotBlank(source)) {
|
|
|
params.put("source", source);
|
|
|
}
|
|
|
-
|
|
|
- if (null != hot){
|
|
|
+
|
|
|
+ if (null != hot) {
|
|
|
params.put("hot", hot);
|
|
|
}
|
|
|
|
|
|
@@ -140,9 +149,9 @@ public class NewsService extends BaseMybatisDao<NewsMapper> {
|
|
|
public int batchDeleteByPrimaryKey(List<String> id) {
|
|
|
return newsMapper.batchDeleteByPrimaryKey(id);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Cacheable(value = "NewsPortalListCache", key = "'NewsPortalList:Page:'+#pageNo+'Type:'+#type+'Size:'+#pageSize+'domainName:'+#domainName")
|
|
|
- public List<NewsPortalList> findPortalList(Integer pSize, Integer pNo, Integer type,String domainName) {
|
|
|
+ public List<NewsPortalList> findPortalList(Integer pSize, Integer pNo, Integer type, String domainName) {
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
params.put("type", type);
|
|
|
params.put("pageSize", pSize);
|
|
|
@@ -150,14 +159,14 @@ public class NewsService extends BaseMybatisDao<NewsMapper> {
|
|
|
params.put("website", domainName);
|
|
|
return newsMapper.findPortalList(params);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@CacheEvict(value = "NewsPortalListCache", allEntries = true)
|
|
|
public void cleanPortalList() {
|
|
|
LoggerUtils.debug(logger, "清除门户端新闻列表缓存");
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public List<NewsSummary> findJmrhNewsList(String type){
|
|
|
+ public List<NewsSummary> findJmrhNewsList(String type) {
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
params.put("type", type);
|
|
|
return newsMapper.findJmrhNewsList(params);
|