| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package nju.seec.helper.sys.bok.api;
- import lombok.AllArgsConstructor;
- import lombok.Data;
- import nju.seec.helper.sys.bok.vo.KnowledgeNodeVO;
- import nju.seec.helper.util.RestRequestUtil;
- import nju.seec.helper.util.cache.BaseCacheUtils;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.boot.context.properties.ConfigurationProperties;
- import org.springframework.stereotype.Component;
- import java.util.List;
- /**
- * @author cst
- */
- @Component
- @ConfigurationProperties("bok.knowledge")
- @Data
- public class KnowledgeApi {
- @Value("${bok.knowledge-cache-name}")
- private String bokKnowledgeCacheName;
- private final RestRequestUtil restRequestUtil;
- private final BaseCacheUtils cacheUtils;
- private String url;
- @SuppressWarnings("unchecked")
- public List<KnowledgeNodeVO> getAllKnowledgeNodes() {
- Object cache = cacheUtils.get(bokKnowledgeCacheName, "all");
- if (cache instanceof List) {
- return (List<KnowledgeNodeVO>) cache;
- }
- List<KnowledgeNodeVO> knowledgeNodeVOList = restRequestUtil.sendGetRequest(url, List.class);
- cacheUtils.set(bokKnowledgeCacheName, "all", knowledgeNodeVOList);
- return knowledgeNodeVOList;
- }
- @AllArgsConstructor(staticName = "of")
- @Data
- private static class KnowledgeGetDTO {
- private String name;
- private String relation;
- }
- }
|