2026-05-05 23:17:57 +08:00
|
|
|
package com.xuqm.push.controller;
|
|
|
|
|
|
|
|
|
|
import com.xuqm.common.model.ApiResponse;
|
|
|
|
|
import com.xuqm.push.entity.DeviceLoginLogEntity;
|
|
|
|
|
import com.xuqm.push.service.PushDiagnosticsService;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
2026-05-09 14:53:42 +08:00
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
2026-05-05 23:17:57 +08:00
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/push/admin")
|
2026-05-09 14:53:42 +08:00
|
|
|
@PreAuthorize("hasAnyAuthority('ROLE_OPS', 'ROLE_TENANT', 'ROLE_ADMIN')")
|
2026-05-05 23:17:57 +08:00
|
|
|
public class PushManagementController {
|
|
|
|
|
|
|
|
|
|
private final PushDiagnosticsService diagnosticsService;
|
|
|
|
|
|
|
|
|
|
public PushManagementController(PushDiagnosticsService diagnosticsService) {
|
|
|
|
|
this.diagnosticsService = diagnosticsService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/user-status")
|
|
|
|
|
public ResponseEntity<ApiResponse<PushDiagnosticsService.PushTokenDiagnostics>> userStatus(
|
2026-05-07 19:39:42 +08:00
|
|
|
@RequestParam String appKey,
|
2026-05-05 23:17:57 +08:00
|
|
|
@RequestParam String userId) {
|
2026-05-07 19:39:42 +08:00
|
|
|
return ResponseEntity.ok(ApiResponse.success(diagnosticsService.searchByUserId(appKey, userId)));
|
2026-05-05 23:17:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/device-logs")
|
|
|
|
|
public ResponseEntity<ApiResponse<Map<String, Object>>> deviceLogs(
|
2026-05-07 19:39:42 +08:00
|
|
|
@RequestParam String appKey,
|
2026-05-05 23:17:57 +08:00
|
|
|
@RequestParam String userId,
|
|
|
|
|
@RequestParam(defaultValue = "0") int page,
|
|
|
|
|
@RequestParam(defaultValue = "20") int size) {
|
2026-05-07 19:39:42 +08:00
|
|
|
Page<DeviceLoginLogEntity> result = diagnosticsService.deviceLogs(appKey, userId, page, size);
|
2026-05-05 23:17:57 +08:00
|
|
|
return ResponseEntity.ok(ApiResponse.success(Map.of(
|
|
|
|
|
"content", result.getContent(),
|
|
|
|
|
"total", result.getTotalElements(),
|
|
|
|
|
"totalPages", result.getTotalPages()
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/test-offline")
|
|
|
|
|
public ResponseEntity<ApiResponse<PushDiagnosticsService.TestPushResult>> testOffline(
|
|
|
|
|
@RequestBody TestOfflineRequest request) {
|
|
|
|
|
PushDiagnosticsService.TestPushResult result = diagnosticsService.sendTestOfflineMessage(
|
2026-05-07 19:39:42 +08:00
|
|
|
request.appKey(),
|
2026-05-05 23:17:57 +08:00
|
|
|
request.userId(),
|
|
|
|
|
request.title(),
|
|
|
|
|
request.body(),
|
|
|
|
|
request.payload());
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(result));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public record TestOfflineRequest(
|
2026-05-07 19:39:42 +08:00
|
|
|
String appKey,
|
2026-05-05 23:17:57 +08:00
|
|
|
String userId,
|
|
|
|
|
String title,
|
|
|
|
|
String body,
|
|
|
|
|
String payload
|
|
|
|
|
) {}
|
|
|
|
|
}
|