|
|
@@ -4,7 +4,9 @@ import com.tzld.longarticle.recommend.server.model.entity.longArticle.LongArticl
|
|
|
import com.tzld.longarticle.recommend.server.repository.longArticle.LongArticlesRootSourceIdRepository;
|
|
|
import com.tzld.longarticle.recommend.server.service.api.ApiService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
@@ -16,6 +18,9 @@ public class ApiServiceImpl implements ApiService {
|
|
|
@Autowired
|
|
|
LongArticlesRootSourceIdRepository longArticlesRootSourceIdRepository;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate<String, String> redisTemplate;
|
|
|
+
|
|
|
@Override
|
|
|
public String getGhIdByRootSourceId(String rootSourceId) {
|
|
|
LongArticlesRootSourceId longArticlesRootSourceId = longArticlesRootSourceIdRepository.getByRootSourceId(rootSourceId);
|
|
|
@@ -25,4 +30,18 @@ public class ApiServiceImpl implements ApiService {
|
|
|
return longArticlesRootSourceId.getGhId();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Boolean checkExistRootSourceId(String rootSourceId) {
|
|
|
+ String redisKey = "check_exist_root_source_id_" + rootSourceId;
|
|
|
+ String value = redisTemplate.opsForValue().get(redisKey);
|
|
|
+ if (StringUtils.isNotEmpty(value)) {
|
|
|
+ return Boolean.parseBoolean(value);
|
|
|
+ }
|
|
|
+ LongArticlesRootSourceId longArticlesRootSourceId = longArticlesRootSourceIdRepository.getByRootSourceId(rootSourceId);
|
|
|
+ boolean exists = Objects.nonNull(longArticlesRootSourceId);
|
|
|
+ // 缓存1小时
|
|
|
+ redisTemplate.opsForValue().set(redisKey, String.valueOf(exists), 60 * 60);
|
|
|
+ return exists;
|
|
|
+ }
|
|
|
+
|
|
|
}
|