liuchengsen 3 veckor sedan
förälder
incheckning
1c2793dcb1

+ 3 - 2
backend-java/src/main/java/com/pharmacopoeia/controller/AdminKnowledgeController.java

@@ -243,8 +243,9 @@ public class AdminKnowledgeController {
     @GetMapping("/quick-asks/audit-log")
     public ResponseEntity<Map<String, Object>> listQuickAskAuditLog(
             @RequestParam(defaultValue = "1") int page,
-            @RequestParam(defaultValue = "20") int pageSize) {
-        return ResponseEntity.ok(service.listQuickAskAuditLog(page, pageSize));
+            @RequestParam(defaultValue = "20") int pageSize,
+            @RequestParam(required = false) String action) {
+        return ResponseEntity.ok(service.listQuickAskAuditLog(page, pageSize, action));
     }
 
    // ==================== 品牌管理 ====================

+ 6 - 0
backend-java/src/main/java/com/pharmacopoeia/repository/QuickAskAuditLogRepository.java

@@ -10,4 +10,10 @@ import org.springframework.stereotype.Repository;
 public interface QuickAskAuditLogRepository extends JpaRepository<QuickAskAuditLog, Long> {
 
     Page<QuickAskAuditLog> findAllByOrderByCreatedAtDesc(Pageable pageable);
+
+    /**
+     * 按操作类型筛选审计日志(action = CREATE / UPDATE / DELETE)
+     * 前端 auditLog 接口可传 action 参数,后端自动使用此方法查询
+     */
+    Page<QuickAskAuditLog> findByActionOrderByCreatedAtDesc(String action, Pageable pageable);
 }

+ 8 - 2
backend-java/src/main/java/com/pharmacopoeia/service/AdminKnowledgeService.java

@@ -13,6 +13,7 @@ import com.pharmacopoeia.repository.QuestionRepository;
 import com.pharmacopoeia.repository.QuickAskAuditLogRepository;
 import com.pharmacopoeia.repository.QuickAskRepository;
 import com.pharmacopoeia.util.IpUtils;
+import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.security.core.context.SecurityContextHolder;
@@ -415,9 +416,14 @@ public class AdminKnowledgeService {
         return "unknown";
     }
 
-    public Map<String, Object> listQuickAskAuditLog(int page, int pageSize) {
+    public Map<String, Object> listQuickAskAuditLog(int page, int pageSize, String action) {
         var pageable = org.springframework.data.domain.PageRequest.of(page - 1, pageSize);
-        var result = auditLogRepository.findAllByOrderByCreatedAtDesc(pageable);
+        Page<QuickAskAuditLog> result;
+        if (action != null && !action.isBlank()) {
+            result = auditLogRepository.findByActionOrderByCreatedAtDesc(action, pageable);
+        } else {
+            result = auditLogRepository.findAllByOrderByCreatedAtDesc(pageable);
+        }
         return Map.of(
                 "items", result.getContent(),
                 "page", page,