package com.xuqm.tenant.controller; import com.xuqm.common.model.ApiResponse; import com.xuqm.tenant.entity.TenantEntity; import com.xuqm.tenant.service.OpsService; import jakarta.validation.constraints.NotBlank; 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; public OpsController(OpsService opsService) { this.opsService = opsService; } @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/statistics") @PreAuthorize("hasAuthority('ROLE_OPS')") public ResponseEntity>> statistics() { return ResponseEntity.ok(ApiResponse.success(opsService.statistics())); } }