Przeglądaj źródła

feat(mind): add getAdminAlerts method to EmotionAlertService for admin page pagination

Xiaogang Liao 2 miesięcy temu
rodzic
commit
e43fad16f4

+ 21 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/EmotionAlertService.java

@@ -138,6 +138,27 @@ public class EmotionAlertService {
                 .stream().map(this::toVO).collect(Collectors.toList());
     }
 
+    /**
+     * 管理员获取所有告警列表(分页)
+     */
+    public Map<String, Object> getAdminAlerts(int page, int size, Boolean resolved) {
+        LambdaQueryWrapper<EmotionAlert> wrapper = new LambdaQueryWrapper<EmotionAlert>()
+                .eq(resolved != null, EmotionAlert::getResolved, resolved)
+                .orderByDesc(EmotionAlert::getCreatedAt);
+        List<EmotionAlert> all = emotionAlertMapper.selectList(wrapper);
+        int total = all.size();
+        int fromIndex = (page - 1) * size;
+        int toIndex = Math.min(fromIndex + size, total);
+        List<EmotionAlert> pageList = fromIndex >= total ? Collections.emptyList() : all.subList(fromIndex, toIndex);
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("list", pageList.stream().map(this::toVO).collect(Collectors.toList()));
+        result.put("total", total);
+        result.put("page", page);
+        result.put("size", size);
+        return result;
+    }
+
     public void resolveAlert(Long alertId) {
         EmotionAlert alert = emotionAlertMapper.selectById(alertId);
         if (alert != null) {