49 行
1.7 KiB
Java
49 行
1.7 KiB
Java
package com.xuqm.license.controller;
|
|
|
|
import com.xuqm.common.model.ApiResponse;
|
|
import com.xuqm.license.entity.AppLicenseEntity;
|
|
import com.xuqm.license.entity.DeviceEntity;
|
|
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 {
|
|
|
|
private final AppLicenseService appLicenseService;
|
|
private final DeviceService deviceService;
|
|
|
|
public LicenseAdminController(AppLicenseService appLicenseService, DeviceService deviceService) {
|
|
this.appLicenseService = appLicenseService;
|
|
this.deviceService = deviceService;
|
|
}
|
|
|
|
@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<>();
|
|
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());
|
|
}
|
|
|
|
}
|