package com.xuqm.tenant.controller; import com.xuqm.common.model.ApiResponse; import com.xuqm.tenant.entity.AppEntity; import com.xuqm.tenant.entity.FeatureServiceEntity; import com.xuqm.tenant.entity.OperationLogEntity; import com.xuqm.tenant.entity.ServiceActivationRequestEntity; import com.xuqm.tenant.entity.TenantEntity; import com.xuqm.tenant.service.FeatureServiceManager; import com.xuqm.tenant.service.OpsService; import org.springframework.data.domain.Page; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; 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 public class OpsController { private final OpsService opsService; private final FeatureServiceManager featureServiceManager; public OpsController(OpsService opsService, FeatureServiceManager featureServiceManager) { this.opsService = opsService; this.featureServiceManager = featureServiceManager; } @PostMapping("/api/auth/ops/login") public ResponseEntity>> opsLogin(@RequestBody Map body) { String token = opsService.login(body.get("username"), body.get("password")); return ResponseEntity.ok(ApiResponse.success(Map.of("token", token))); } @GetMapping("/api/ops/tenants") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity>> listTenants( @RequestParam(defaultValue = "") String keyword, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size) { Page result = opsService.listTenants(keyword, page, size); return ResponseEntity.ok(ApiResponse.success(Map.of( "content", result.getContent(), "total", result.getTotalElements(), "totalPages", result.getTotalPages() ))); } @PostMapping("/api/ops/tenants/{id}/toggle-status") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity> toggleStatus(@PathVariable String id) { opsService.toggleStatus(id); return ResponseEntity.ok(ApiResponse.ok()); } @GetMapping("/api/ops/tenants/{id}") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity>> getTenantDetail(@PathVariable String id) { return ResponseEntity.ok(ApiResponse.success(opsService.getTenantDetail(id))); } @GetMapping("/api/ops/tenants/{id}/apps") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity>> listTenantApps(@PathVariable String id) { return ResponseEntity.ok(ApiResponse.success(opsService.listTenantApps(id))); } @GetMapping("/api/ops/statistics") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity>> statistics() { return ResponseEntity.ok(ApiResponse.success(opsService.statistics())); } @GetMapping("/api/ops/service-requests") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity>> listServiceRequests( @RequestParam(required = false) String status, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size) { Page result = opsService.listServiceRequests(status, page, size); return ResponseEntity.ok(ApiResponse.success(Map.of( "content", result.getContent(), "total", result.getTotalElements(), "totalPages", result.getTotalPages() ))); } @PostMapping("/api/ops/service-requests/{requestId}/approve") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity> approveRequest( @PathVariable String requestId, @RequestBody(required = false) Map body) { String reviewNote = body != null ? body.getOrDefault("reviewNote", "") : ""; return ResponseEntity.ok(ApiResponse.success( featureServiceManager.approveRequest(requestId, reviewNote))); } @PostMapping("/api/ops/service-requests/{requestId}/reject") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity> rejectRequest( @PathVariable String requestId, @RequestBody(required = false) Map body) { String reviewNote = body != null ? body.getOrDefault("reviewNote", "") : ""; return ResponseEntity.ok(ApiResponse.success( featureServiceManager.rejectRequest(requestId, reviewNote))); } @GetMapping("/api/ops/apps") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity>> listApps( @RequestParam(defaultValue = "") String keyword, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size) { Page result = opsService.listApps(keyword, page, size); return ResponseEntity.ok(ApiResponse.success(Map.of( "content", result.getContent(), "total", result.getTotalElements(), "totalPages", result.getTotalPages() ))); } @GetMapping("/api/ops/apps/{id}") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity>> getAppDetail(@PathVariable String id) { return ResponseEntity.ok(ApiResponse.success(opsService.getAppDetail(id))); } @GetMapping("/api/ops/apps/{id}/services") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity>> listAppServices(@PathVariable String id) { return ResponseEntity.ok(ApiResponse.success(opsService.listAppServices(id))); } @GetMapping("/api/ops/operation-logs") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity>> listOperationLogs( @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size) { Page result = opsService.listOperationLogs(page, size); return ResponseEntity.ok(ApiResponse.success(Map.of( "content", result.getContent(), "total", result.getTotalElements(), "totalPages", result.getTotalPages() ))); } }