|
|
@@ -12,6 +12,8 @@ import com.pharmacopoeia.repository.KnowledgePointRepository;
|
|
|
import com.pharmacopoeia.repository.QuestionRepository;
|
|
|
import com.pharmacopoeia.repository.QuickAskAuditLogRepository;
|
|
|
import com.pharmacopoeia.repository.QuickAskRepository;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import jakarta.persistence.criteria.Predicate;
|
|
|
import com.pharmacopoeia.util.IpUtils;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
@@ -422,16 +424,8 @@ public class AdminKnowledgeService {
|
|
|
String startDate, String endDate) {
|
|
|
var pageable = PageRequest.of(page - 1, pageSize);
|
|
|
|
|
|
- Instant startTime = startDate != null && !startDate.isBlank()
|
|
|
- ? LocalDate.parse(startDate).atStartOfDay(ZoneOffset.UTC).toInstant()
|
|
|
- : null;
|
|
|
- Instant endTime = endDate != null && !endDate.isBlank()
|
|
|
- ? LocalDate.parse(endDate).plusDays(1).atStartOfDay(ZoneOffset.UTC).toInstant()
|
|
|
- : null;
|
|
|
-
|
|
|
- var result = auditLogRepository.findByFilters(
|
|
|
- action != null && !action.isBlank() ? action : null,
|
|
|
- startTime, endTime, pageable);
|
|
|
+ var spec = buildAuditLogSpec(action, startDate, endDate);
|
|
|
+ var result = auditLogRepository.findAll(spec, pageable);
|
|
|
|
|
|
return Map.of(
|
|
|
"items", result.getContent(),
|
|
|
@@ -442,6 +436,27 @@ public class AdminKnowledgeService {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ private Specification<QuickAskAuditLog> buildAuditLogSpec(String action, String startDate, String endDate) {
|
|
|
+ return (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new java.util.ArrayList<>();
|
|
|
+
|
|
|
+ if (action != null && !action.isBlank()) {
|
|
|
+ predicates.add(cb.equal(root.get("action"), action));
|
|
|
+ }
|
|
|
+ if (startDate != null && !startDate.isBlank()) {
|
|
|
+ predicates.add(cb.greaterThanOrEqualTo(root.get("createdAt"),
|
|
|
+ java.time.LocalDate.parse(startDate).atStartOfDay(java.time.ZoneOffset.UTC).toInstant()));
|
|
|
+ }
|
|
|
+ if (endDate != null && !endDate.isBlank()) {
|
|
|
+ predicates.add(cb.lessThan(root.get("createdAt"),
|
|
|
+ java.time.LocalDate.parse(endDate).plusDays(1).atStartOfDay(java.time.ZoneOffset.UTC).toInstant()));
|
|
|
+ }
|
|
|
+
|
|
|
+ query.orderBy(cb.desc(root.get("createdAt")));
|
|
|
+ return cb.and(predicates.toArray(new Predicate[0]));
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
// ==================== Helpers ====================
|
|
|
|
|
|
/** 从 SecurityContext 获取当前操作员标识 */
|