|
|
@@ -1,5 +1,6 @@
|
|
|
package com.usky.issue.service.impl;
|
|
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
@@ -27,6 +28,7 @@ import com.usky.issue.service.vo.CloudConnectionTestRequest;
|
|
|
import com.usky.issue.service.vo.CloudConnectionTestResponse;
|
|
|
import com.usky.issue.service.vo.CloudConnectionTestResult;
|
|
|
import com.usky.issue.service.vo.CloudDisableResponse;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -41,6 +43,8 @@ import java.util.List;
|
|
|
* @author fyc
|
|
|
* @date 2026-05-21
|
|
|
*/
|
|
|
+@DS("usky-cloud")
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
|
|
|
@@ -119,24 +123,35 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
String operator = CloudEntitySupport.resolveOperator();
|
|
|
String requestIp = CloudEntitySupport.resolveRequestIp();
|
|
|
Integer tenantId = request.getTenantId();
|
|
|
+ log.info("[连接测试] 开始 tenantId={}, cloudAddress={}, credentialKey={}",
|
|
|
+ tenantId, request.getCloudAddress(), CredentialMaskUtil.mask(request.getCredentialKey()));
|
|
|
+
|
|
|
Integer loginTenantId = SecurityUtils.getTenantId();
|
|
|
if (loginTenantId != null && !tenantId.equals(loginTenantId)) {
|
|
|
+ log.warn("[连接测试] 租户不一致 requestTenantId={}, loginTenantId={}", tenantId, loginTenantId);
|
|
|
throw new BusinessException("输入租户ID与登录租户不一致,请确认后重试!");
|
|
|
}
|
|
|
|
|
|
IssueCloudConfig config = findConfigByTenantId(tenantId);
|
|
|
if (config == null) {
|
|
|
+ log.warn("[连接测试] 配置不存在 tenantId={}", tenantId);
|
|
|
throw new BusinessException("云平台配置不存在,请先保存配置");
|
|
|
}
|
|
|
if (config.getStatus() != null && config.getStatus() == 0) {
|
|
|
+ log.warn("[连接测试] 集成已禁用 tenantId={}, configId={}", tenantId, config.getId());
|
|
|
throw new BusinessException("云平台集成已禁用");
|
|
|
}
|
|
|
validateCredentialKey(config, request.getCredentialKey());
|
|
|
+ log.info("[连接测试] 本地密钥校验通过 configId={}", config.getId());
|
|
|
|
|
|
CloudConnectionTestResult result = cloudPlatformClient.testConnection(
|
|
|
request.getCloudAddress(), request.getTenantId(), request.getCredentialKey(),
|
|
|
SecurityUtils.getToken());
|
|
|
|
|
|
+ log.info("[连接测试] 远程结果 success={}, networkReachable={}, authValid={}, tenantExists={}, message={}, costTime={}ms",
|
|
|
+ result.isSuccess(), result.isNetworkReachable(), result.isAuthValid(),
|
|
|
+ result.isTenantExists(), result.getMessage(), result.getCostTime());
|
|
|
+
|
|
|
config.setConnectionStatus(result.isSuccess() ? 1 : 2);
|
|
|
config.setLastTestTime(LocalDateTime.now());
|
|
|
CloudEntitySupport.fillOnUpdate(config);
|
|
|
@@ -150,11 +165,15 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
try {
|
|
|
String storedKey = aesGcmCipher.decrypt(config.getCredentialKey());
|
|
|
if (!storedKey.equals(requestKey)) {
|
|
|
+ log.warn("[连接测试] 密钥不一致 tenantId={}, configId={}, requestKey={}, storedKey={}",
|
|
|
+ config.getTenantId(), config.getId(),
|
|
|
+ CredentialMaskUtil.mask(requestKey), CredentialMaskUtil.mask(storedKey));
|
|
|
throw new BusinessException("凭证密钥与已保存配置不一致");
|
|
|
}
|
|
|
} catch (BusinessException ex) {
|
|
|
throw ex;
|
|
|
} catch (Exception ex) {
|
|
|
+ log.error("[连接测试] 密钥解密失败 tenantId={}, configId={}", config.getTenantId(), config.getId(), ex);
|
|
|
throw new BusinessException("凭证密钥校验失败");
|
|
|
}
|
|
|
}
|
|
|
@@ -163,6 +182,7 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
public CloudConnectionTestResponse validateTenantConnection(Integer tenantId) {
|
|
|
CloudConnectionTestResponse response = new CloudConnectionTestResponse();
|
|
|
if (tenantId == null) {
|
|
|
+ log.warn("[连接测试-租户校验] tenantId 为空");
|
|
|
response.setSuccess(false);
|
|
|
response.setConnectionStatus(2);
|
|
|
response.setMessage("租户ID不能为空");
|
|
|
@@ -174,6 +194,7 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
|
|
|
IssueCloudConfig config = findConfigByTenantId(tenantId);
|
|
|
if (config == null) {
|
|
|
+ log.warn("[连接测试-租户校验] 配置不存在 tenantId={}", tenantId);
|
|
|
response.setSuccess(false);
|
|
|
response.setConnectionStatus(2);
|
|
|
response.setMessage(CloudIntegrationConstants.MSG_TENANT_CONFIG_MISSING);
|
|
|
@@ -183,6 +204,7 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
return response;
|
|
|
}
|
|
|
if (config.getStatus() != null && config.getStatus() == 0) {
|
|
|
+ log.warn("[连接测试-租户校验] 配置已禁用 tenantId={}, configId={}", tenantId, config.getId());
|
|
|
response.setSuccess(false);
|
|
|
response.setConnectionStatus(2);
|
|
|
response.setMessage("租户配置已禁用");
|
|
|
@@ -198,6 +220,7 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
response.setNetworkReachable(true);
|
|
|
response.setAuthValid(true);
|
|
|
response.setTenantExists(true);
|
|
|
+ log.info("[连接测试-租户校验] 通过 tenantId={}, configId={}", tenantId, config.getId());
|
|
|
return response;
|
|
|
}
|
|
|
|