2026-04-21 22:07:29 +08:00
|
|
|
package com.xuqm.tenant.controller;
|
|
|
|
|
|
|
|
|
|
import com.xuqm.common.model.ApiResponse;
|
|
|
|
|
import com.xuqm.tenant.entity.FeatureServiceEntity;
|
2026-04-24 20:53:48 +08:00
|
|
|
import com.xuqm.tenant.entity.ServiceActivationRequestEntity;
|
2026-04-21 22:07:29 +08:00
|
|
|
import com.xuqm.tenant.service.AppService;
|
|
|
|
|
import com.xuqm.tenant.service.FeatureServiceManager;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|
|
|
|
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.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
2026-04-28 16:08:07 +08:00
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
2026-04-21 22:07:29 +08:00
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
2026-04-28 16:08:07 +08:00
|
|
|
import java.util.Map;
|
2026-04-21 22:07:29 +08:00
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/apps/{appId}/services")
|
|
|
|
|
public class FeatureServiceController {
|
|
|
|
|
|
|
|
|
|
private final FeatureServiceManager featureServiceManager;
|
|
|
|
|
private final AppService appService;
|
|
|
|
|
|
|
|
|
|
public FeatureServiceController(FeatureServiceManager featureServiceManager, AppService appService) {
|
|
|
|
|
this.featureServiceManager = featureServiceManager;
|
|
|
|
|
this.appService = appService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping
|
|
|
|
|
public ResponseEntity<ApiResponse<List<FeatureServiceEntity>>> list(
|
|
|
|
|
@PathVariable String appId, @AuthenticationPrincipal String tenantId) {
|
|
|
|
|
appService.getById(appId, tenantId);
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(featureServiceManager.listByApp(appId)));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-24 20:53:48 +08:00
|
|
|
/** Disable a service (enable=false only; enabling requires ops approval via request-activation). */
|
2026-04-21 22:07:29 +08:00
|
|
|
@PostMapping("/toggle")
|
|
|
|
|
public ResponseEntity<ApiResponse<FeatureServiceEntity>> toggle(
|
|
|
|
|
@PathVariable String appId,
|
|
|
|
|
@RequestParam FeatureServiceEntity.Platform platform,
|
|
|
|
|
@RequestParam FeatureServiceEntity.ServiceType serviceType,
|
|
|
|
|
@RequestParam boolean enable,
|
|
|
|
|
@AuthenticationPrincipal String tenantId) {
|
|
|
|
|
appService.getById(appId, tenantId);
|
2026-04-24 20:53:48 +08:00
|
|
|
if (enable) {
|
|
|
|
|
throw new com.xuqm.common.exception.BusinessException(400, "开启服务请通过 request-activation 申请");
|
|
|
|
|
}
|
2026-04-21 22:07:29 +08:00
|
|
|
return ResponseEntity.ok(ApiResponse.success(
|
2026-04-24 20:53:48 +08:00
|
|
|
featureServiceManager.disable(appId, platform, serviceType)));
|
2026-04-21 22:07:29 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-28 16:08:07 +08:00
|
|
|
@PutMapping("/config")
|
|
|
|
|
public ResponseEntity<ApiResponse<FeatureServiceEntity>> updateConfig(
|
|
|
|
|
@PathVariable String appId,
|
|
|
|
|
@RequestParam FeatureServiceEntity.Platform platform,
|
|
|
|
|
@RequestParam FeatureServiceEntity.ServiceType serviceType,
|
|
|
|
|
@RequestParam boolean allowStrangerMessage,
|
|
|
|
|
@AuthenticationPrincipal String tenantId) {
|
|
|
|
|
appService.getById(appId, tenantId);
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(featureServiceManager.updateConfig(
|
|
|
|
|
appId,
|
|
|
|
|
platform,
|
|
|
|
|
serviceType,
|
|
|
|
|
featureServiceManager.buildAllowStrangerConfig(allowStrangerMessage)
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-24 20:53:48 +08:00
|
|
|
/** Submit an activation request for ops approval. */
|
|
|
|
|
@PostMapping("/request-activation")
|
|
|
|
|
public ResponseEntity<ApiResponse<ServiceActivationRequestEntity>> requestActivation(
|
2026-04-21 22:07:29 +08:00
|
|
|
@PathVariable String appId,
|
2026-04-24 20:53:48 +08:00
|
|
|
@RequestParam FeatureServiceEntity.Platform platform,
|
|
|
|
|
@RequestParam FeatureServiceEntity.ServiceType serviceType,
|
|
|
|
|
@RequestParam(required = false) String applyReason,
|
2026-04-21 22:07:29 +08:00
|
|
|
@AuthenticationPrincipal String tenantId) {
|
|
|
|
|
appService.getById(appId, tenantId);
|
2026-04-24 20:53:48 +08:00
|
|
|
return ResponseEntity.ok(ApiResponse.success(
|
|
|
|
|
featureServiceManager.submitActivationRequest(appId, platform, serviceType, applyReason)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/requests")
|
|
|
|
|
public ResponseEntity<ApiResponse<List<ServiceActivationRequestEntity>>> listRequests(
|
|
|
|
|
@PathVariable String appId, @AuthenticationPrincipal String tenantId) {
|
|
|
|
|
appService.getById(appId, tenantId);
|
|
|
|
|
return ResponseEntity.ok(ApiResponse.success(featureServiceManager.listRequestsByApp(appId)));
|
2026-04-21 22:07:29 +08:00
|
|
|
}
|
|
|
|
|
}
|