|
|
@@ -38,9 +38,9 @@ public class NotionServiceImpl implements INotionService {
|
|
|
private String tokenV2;
|
|
|
private ExecutorService executor;
|
|
|
|
|
|
- /** 月度容器页缓存: "2026-08" -> pageId,避免所有页面堆积在同一父页面下导致内容超限 */
|
|
|
- private final ConcurrentHashMap<String, String> monthlyContainers = new ConcurrentHashMap<>();
|
|
|
- private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
+ /** 当日容器页缓存: "2026-08-10" -> pageId,避免所有页面堆积在同一父页面下导致内容超限 */
|
|
|
+ private final ConcurrentHashMap<String, String> dailyContainers = new ConcurrentHashMap<>();
|
|
|
+ private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
@@ -62,7 +62,8 @@ public class NotionServiceImpl implements INotionService {
|
|
|
private synchronized boolean initParentPage() {
|
|
|
if (parentPageId != null) return true;
|
|
|
|
|
|
- try (NotionClient client = new NotionClient(notionConfig.getApiKey())) {
|
|
|
+ try (NotionClient client = new NotionClient(notionConfig.getApiKey(),
|
|
|
+ notionConfig.getRetryCount(), notionConfig.getRetryBaseDelayMs())) {
|
|
|
JsonNode result = client.search("");
|
|
|
JsonNode results = result.get("results");
|
|
|
if (results != null && results.size() > 0) {
|
|
|
@@ -92,19 +93,20 @@ public class NotionServiceImpl implements INotionService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取或创建当前月份的容器页,将页面分散到月度子目录下,避免父页面内容超限
|
|
|
+ * 获取或创建当日的容器页,将页面分散到日子目录下,避免父页面内容超限
|
|
|
*/
|
|
|
- private String getOrCreateMonthlyContainer() {
|
|
|
- String monthKey = LocalDate.now().format(MONTH_FORMATTER);
|
|
|
- return monthlyContainers.computeIfAbsent(monthKey, k -> {
|
|
|
- try (NotionClient client = new NotionClient(notionConfig.getApiKey())) {
|
|
|
+ private String getOrCreateDailyContainer() {
|
|
|
+ String dayKey = LocalDate.now().format(DAY_FORMATTER);
|
|
|
+ return dailyContainers.computeIfAbsent(dayKey, k -> {
|
|
|
+ try (NotionClient client = new NotionClient(notionConfig.getApiKey(),
|
|
|
+ notionConfig.getRetryCount(), notionConfig.getRetryBaseDelayMs())) {
|
|
|
JsonNode page = client.createPageUnderPage(parentPageId, k);
|
|
|
String containerId = page.get("id").asText();
|
|
|
- log.info("[Notion] 创建月度容器页: {} -> {}", k, containerId);
|
|
|
+ log.info("[Notion] 创建当日容器页: {} -> {}", k, containerId);
|
|
|
return containerId;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("[Notion] 创建月度容器页失败: {}", k, e);
|
|
|
- throw new RuntimeException("创建月度容器页失败: " + e.getMessage(), e);
|
|
|
+ log.error("[Notion] 创建当日容器页失败: {}", k, e);
|
|
|
+ throw new RuntimeException("创建当日容器页失败: " + e.getMessage(), e);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -185,7 +187,8 @@ public class NotionServiceImpl implements INotionService {
|
|
|
throw new IllegalStateException("父页面未初始化,请确保 Integration 已关联页面");
|
|
|
}
|
|
|
|
|
|
- NotionClient client = new NotionClient(notionConfig.getApiKey());
|
|
|
+ NotionClient client = new NotionClient(notionConfig.getApiKey(),
|
|
|
+ notionConfig.getRetryCount(), notionConfig.getRetryBaseDelayMs());
|
|
|
NotionInternalClient ic = (tokenV2 != null) ? new NotionInternalClient(tokenV2) : null;
|
|
|
|
|
|
try {
|
|
|
@@ -198,8 +201,8 @@ public class NotionServiceImpl implements INotionService {
|
|
|
embedBlock.put("embed", Collections.singletonMap("url", iframeUrl));
|
|
|
List<Map<String, Object>> children = Collections.singletonList(embedBlock);
|
|
|
|
|
|
- // 获取当月容器页,避免所有页面堆积在同一父页面下导致内容超限
|
|
|
- String containerPageId = getOrCreateMonthlyContainer();
|
|
|
+ // 获取当日容器页,避免所有页面堆积在同一父页面下导致内容超限
|
|
|
+ String containerPageId = getOrCreateDailyContainer();
|
|
|
|
|
|
// 创建页面
|
|
|
JsonNode page = client.createPageWithChildren(containerPageId, title, children);
|