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 getAllKnowledgeNodes() { Object cache = cacheUtils.get(bokKnowledgeCacheName, "all"); if (cache instanceof List) { return (List) cache; } List 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; } }