|
|
@@ -0,0 +1,92 @@ |
|
|
|
package com.yuexiu.secp.read.model.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.google.common.collect.Iterables; |
|
|
|
import com.yuexiu.secp.read.model.dao.ArticlePreviewDao; |
|
|
|
import com.yuexiu.secp.read.model.entities.readonly.ArticlePreview; |
|
|
|
import com.yuexiu.secp.read.dto.ArticlePreviewDto; |
|
|
|
import com.yuexiu.secp.read.model.service.IArticlePreviewService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class ArticlePreviewService implements IArticlePreviewService { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private StringRedisTemplate redisTemplate; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ArticlePreviewDao articlePreviewDao; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public String findRecommendedAndPast(ArticlePreviewDto articlePreviewDto) { |
|
|
|
//项目的集合信息 |
|
|
|
List<ArticlePreview> projectList = new ArrayList<>(); |
|
|
|
|
|
|
|
//城市的集合信息 |
|
|
|
List<ArticlePreview> articlePreviewList = new ArrayList<>(); |
|
|
|
|
|
|
|
List<ArticlePreview> dataList = new ArrayList<>(); |
|
|
|
|
|
|
|
//查询是否有最新推荐 |
|
|
|
int count = articlePreviewDao.findRecommend(); |
|
|
|
if (count < 1) { |
|
|
|
return "为空"; |
|
|
|
} |
|
|
|
//获取当前登录用户 |
|
|
|
|
|
|
|
//获取我已推荐的文章 |
|
|
|
Set<String> recommendIdList = redisTemplate.opsForSet().members("sie:recommend:1"); |
|
|
|
//获取所有文章的信息 |
|
|
|
Map<Object, Object> entries = redisTemplate.opsForHash().entries("sie:read:article"); |
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
//剔除我已推荐文章 |
|
|
|
for (String recommendId : recommendIdList) { |
|
|
|
entries.remove(recommendId); |
|
|
|
} |
|
|
|
Collection<Object> values = entries.values(); |
|
|
|
|
|
|
|
//判断是否有房产 |
|
|
|
if (true) { |
|
|
|
for (Object value : values) { |
|
|
|
//匹配项目,任务状态为已发布 , 推广状态为有效 |
|
|
|
ArticlePreview articlePreview = objectMapper.convertValue(value,ArticlePreview.class); |
|
|
|
if(articlePreview.getPromotionStatus() == articlePreviewDto.getPromotionStatus() && |
|
|
|
articlePreview.getTaskStatus() == articlePreviewDto.getTaskStatus()){ |
|
|
|
//往城市里的集合塞数据 |
|
|
|
projectList.add(articlePreview); |
|
|
|
} |
|
|
|
System.out.println(value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (Object value : values) { |
|
|
|
//匹配城市,任务状态为已发布 , 推广状态为有效 |
|
|
|
ArticlePreview articlePreview = objectMapper.convertValue(value,ArticlePreview.class); |
|
|
|
if(articlePreview.getPromotionStatus() == articlePreviewDto.getPromotionStatus() && |
|
|
|
articlePreview.getTaskStatus() == articlePreviewDto.getTaskStatus()){ |
|
|
|
//往城市里的集合塞数据 |
|
|
|
articlePreviewList.add(articlePreview); |
|
|
|
} |
|
|
|
System.out.println(value); |
|
|
|
} |
|
|
|
|
|
|
|
//如果项目类型不为空,合并项目和城市 |
|
|
|
if(!CollectionUtils.isEmpty(projectList)){ |
|
|
|
Iterables.addAll(dataList, projectList); |
|
|
|
Iterables.addAll(dataList, articlePreviewList); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return "不为空"; |
|
|
|
} |
|
|
|
} |