XuqmGroup-Server/license-service/src/main/java/com/xuqm/license/controller/LicenseAdminController.java

49 行
1.7 KiB
Java

package com.xuqm.license.controller;
import com.xuqm.common.model.ApiResponse;
2026-05-15 21:42:10 +08:00
import com.xuqm.license.entity.AppLicenseEntity;
import com.xuqm.license.entity.DeviceEntity;
2026-05-15 21:42:10 +08:00
import com.xuqm.license.service.AppLicenseService;
import com.xuqm.license.service.DeviceService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/license/admin")
public class LicenseAdminController {
2026-05-15 21:42:10 +08:00
private final AppLicenseService appLicenseService;
private final DeviceService deviceService;
2026-05-15 21:42:10 +08:00
public LicenseAdminController(AppLicenseService appLicenseService, DeviceService deviceService) {
this.appLicenseService = appLicenseService;
this.deviceService = deviceService;
}
2026-05-15 21:42:10 +08:00
@GetMapping("/apps/{appKey}")
public ResponseEntity<ApiResponse<Map<String, Object>>> getAppLicense(@PathVariable String appKey) {
AppLicenseEntity license = appLicenseService.getByAppKey(appKey);
List<DeviceEntity> devices = deviceService.listByApp(appKey);
Map<String, Object> data = new java.util.LinkedHashMap<>();
2026-05-15 21:42:10 +08:00
data.put("license", license);
data.put("devices", devices);
return ResponseEntity.ok(ApiResponse.success(data));
}
@DeleteMapping("/devices/{id}")
public ResponseEntity<ApiResponse<Void>> revokeDevice(@PathVariable String id) {
deviceService.revoke(id);
return ResponseEntity.ok(ApiResponse.ok());
}
@PutMapping("/devices/{id}/reactivate")
public ResponseEntity<ApiResponse<Void>> reactivateDevice(@PathVariable String id) {
deviceService.reactivate(id);
return ResponseEntity.ok(ApiResponse.ok());
}
}