KnowledgeApi.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package nju.seec.helper.sys.bok.api;
  2. import lombok.AllArgsConstructor;
  3. import lombok.Data;
  4. import nju.seec.helper.sys.bok.vo.KnowledgeNodeVO;
  5. import nju.seec.helper.util.RestRequestUtil;
  6. import nju.seec.helper.util.cache.BaseCacheUtils;
  7. import org.springframework.beans.factory.annotation.Value;
  8. import org.springframework.boot.context.properties.ConfigurationProperties;
  9. import org.springframework.stereotype.Component;
  10. import java.util.List;
  11. /**
  12. * @author cst
  13. */
  14. @Component
  15. @ConfigurationProperties("bok.knowledge")
  16. @Data
  17. public class KnowledgeApi {
  18. @Value("${bok.knowledge-cache-name}")
  19. private String bokKnowledgeCacheName;
  20. private final RestRequestUtil restRequestUtil;
  21. private final BaseCacheUtils cacheUtils;
  22. private String url;
  23. @SuppressWarnings("unchecked")
  24. public List<KnowledgeNodeVO> getAllKnowledgeNodes() {
  25. Object cache = cacheUtils.get(bokKnowledgeCacheName, "all");
  26. if (cache instanceof List) {
  27. return (List<KnowledgeNodeVO>) cache;
  28. }
  29. List<KnowledgeNodeVO> knowledgeNodeVOList = restRequestUtil.sendGetRequest(url, List.class);
  30. cacheUtils.set(bokKnowledgeCacheName, "all", knowledgeNodeVOList);
  31. return knowledgeNodeVOList;
  32. }
  33. @AllArgsConstructor(staticName = "of")
  34. @Data
  35. private static class KnowledgeGetDTO {
  36. private String name;
  37. private String relation;
  38. }
  39. }