Quellcode durchsuchen

fix: CORS放行111.228.6.214; 实现/article/updated-since增量查询接口

- WebConfig: 添加111.228.6.214到CORS白名单,新增接口加入JWT放行
- ArticleController: POST /api/articles/updated-since 支持since+status过滤
- ArticleService: getUpdatedSince() 按updatedAt+status查询已发布文章
Xiaogang Liao vor 1 Monat
Ursprung
Commit
efa89c2683

+ 2 - 1
cfc-backend/src/main/java/com/etotem/cfc/config/WebConfig.java

@@ -38,7 +38,7 @@ public class WebConfig implements WebMvcConfigurer {
     @Override
     public void addCorsMappings(CorsRegistry registry) {
         registry.addMapping("/**")
-                .allowedOriginPatterns("https://cfc.etotem.com.cn", "http://cfc.etotem.com.cn", "https://www.etotem.com.cn", "http://www.etotem.com.cn", "https://cf-club.iwintrue.com", "http://cf-club.iwintrue.com", "https://www.cf-club.com", "http://www.cf-club.com", "https://cfc.cf-club.com", "http://cfc.cf-club.com", "http://localhost:*", "http://127.0.0.1:*")
+                .allowedOriginPatterns("https://cfc.etotem.com.cn", "http://cfc.etotem.com.cn", "https://www.etotem.com.cn", "http://www.etotem.com.cn", "https://cf-club.iwintrue.com", "http://cf-club.iwintrue.com", "https://www.cf-club.com", "http://www.cf-club.com", "https://cfc.cf-club.com", "http://cfc.cf-club.com", "https://111.228.6.214", "http://111.228.6.214", "http://localhost:*", "http://127.0.0.1:*")
                 .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                 .allowedHeaders("*")
                 .allowCredentials(true)
@@ -108,6 +108,7 @@ public class WebConfig implements WebMvcConfigurer {
                 "/api/articles/categories",
                 "/api/articles/featured",
                 "/api/articles/record-read",
+                "/api/articles/updated-since",
                 "/api/activity/list",
                 "/api/activity/detail",
                 "/api/ai/context",

+ 21 - 1
cfc-backend/src/main/java/com/etotem/cfc/controller/content/ArticleController.java

@@ -13,6 +13,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -195,9 +197,27 @@ public class ArticleController {
 
     @PostMapping("/my-posts")
     public Result<Page<Article>> myPosts(@RequestBody Map<String, Object> body,
-                                          @RequestAttribute("userId") Long userId) {
+                                           @RequestAttribute("userId") Long userId) {
         int page = body.get("page") != null ? Integer.parseInt(body.get("page").toString()) : 1;
         int size = body.get("size") != null ? Integer.parseInt(body.get("size").toString()) : 20;
         return Result.success(articleService.getMyPosts(userId, page, size));
     }
+
+    @Operation(summary = "增量查询文章(RAG)")
+    @PostMapping("/updated-since")
+    public Result<List<Article>> updatedSince(@RequestBody Map<String, Object> body) {
+        String since = (String) body.get("since");
+        String status = (String) body.get("status");
+        if (since == null || since.trim().isEmpty()) {
+            return Result.error("since 参数不能为空");
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+        Date sinceDate;
+        try {
+            sinceDate = sdf.parse(since);
+        } catch (Exception e) {
+            return Result.error("since 格式无效,请使用 ISO 8601 格式");
+        }
+        return Result.success(articleService.getUpdatedSince(sinceDate, status));
+    }
 }

+ 13 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/ArticleService.java

@@ -735,6 +735,19 @@ public class ArticleService {
         return articleMapper.selectPage(new Page<>(page, size), wrapper);
     }
 
+    /**
+     * 增量查询:获取指定时间之后更新的文章(供 LangGraph RAG 使用)
+     */
+    public List<Article> getUpdatedSince(Date since, String status) {
+        LambdaQueryWrapper<Article> wrapper = new LambdaQueryWrapper<Article>()
+                .ge(Article::getUpdatedAt, since)
+                .orderByDesc(Article::getUpdatedAt);
+        if (status != null && !status.trim().isEmpty()) {
+            wrapper.eq(Article::getStatus, status.trim());
+        }
+        return articleMapper.selectList(wrapper);
+    }
+
     /**
      * 管理员审核文章
      */