|
|
@@ -69,14 +69,23 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public CloudConfigResponse saveConfig(CloudConfigSaveRequest request, String operator, String requestIp) {
|
|
|
+ Integer tenantId = SecurityUtils.getTenantId();
|
|
|
+
|
|
|
+ if (!request.getTenantId().equals(tenantId)) {
|
|
|
+ throw new BusinessException("输入租户ID与登录租户不一致,请确认后重试!");
|
|
|
+ }
|
|
|
+
|
|
|
+ String userName = SecurityUtils.getUsername();
|
|
|
+
|
|
|
IssueCloudConfig existing = findActiveConfig();
|
|
|
if (existing == null) {
|
|
|
IssueCloudConfig created = new IssueCloudConfig();
|
|
|
- created.setTenantId(Integer.valueOf(request.getTenantId()));
|
|
|
+ created.setTenantId(request.getTenantId());
|
|
|
created.setCredentialKey(aesGcmCipher.encrypt(request.getCredentialKey()));
|
|
|
created.setStatus(1);
|
|
|
created.setConnectionStatus(0);
|
|
|
- created.setVersion(0);
|
|
|
+ created.setVersion(1);
|
|
|
+ created.setCreateBy(userName);
|
|
|
CloudEntitySupport.fillOnInsert(created);
|
|
|
configMapper.insert(created);
|
|
|
initSyncStatusRows(created.getId());
|
|
|
@@ -85,19 +94,21 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
"新建配置 tenantId=" + request.getTenantId(), operator, requestIp);
|
|
|
return toResponse(created);
|
|
|
}
|
|
|
- if (request.getVersion() != null && !request.getVersion().equals(existing.getVersion())) {
|
|
|
+ Integer version = existing.getVersion();
|
|
|
+ if (request.getVersion() != null && !request.getVersion().equals(version)) {
|
|
|
throw new BusinessException("配置版本冲突,请刷新后重试");
|
|
|
}
|
|
|
- existing.setTenantId(Integer.valueOf(request.getTenantId()));
|
|
|
+ existing.setTenantId(request.getTenantId());
|
|
|
existing.setCredentialKey(aesGcmCipher.encrypt(request.getCredentialKey()));
|
|
|
existing.setStatus(1);
|
|
|
+ existing.setVersion(version + 1);
|
|
|
CloudEntitySupport.fillOnUpdate(existing);
|
|
|
int updated = configMapper.updateById(existing);
|
|
|
if (updated == 0) {
|
|
|
throw new BusinessException("配置版本冲突,请刷新后重试");
|
|
|
}
|
|
|
operationLogService.log(existing.getId(), CloudIntegrationConstants.OPERATION_SAVE_CONFIG,
|
|
|
- "更新配置 tenantId=" + CredentialMaskUtil.mask(request.getTenantId()), operator, requestIp);
|
|
|
+ "更新配置 tenantId=" + CredentialMaskUtil.mask(String.valueOf(request.getTenantId())), operator, requestIp);
|
|
|
return toResponse(configMapper.selectById(existing.getId()));
|
|
|
}
|
|
|
|
|
|
@@ -105,9 +116,10 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public CloudConnectionTestResponse testConnection(String operator, String requestIp) {
|
|
|
IssueCloudConfig config = requireActiveConfig();
|
|
|
+ config.setToken(SecurityUtils.getToken());
|
|
|
boolean ok = cloudPlatformClient.testConnection(config);
|
|
|
config.setConnectionStatus(ok ? 1 : 2);
|
|
|
- config.setLastTestAt(LocalDateTime.now());
|
|
|
+ config.setLastTestTime(LocalDateTime.now());
|
|
|
CloudEntitySupport.fillOnUpdate(config);
|
|
|
configMapper.updateById(config);
|
|
|
operationLogService.log(config.getId(), CloudIntegrationConstants.OPERATION_TEST_CONNECTION,
|
|
|
@@ -163,7 +175,7 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
TaskStatusEnum.PENDING.getCode(), TaskStatusEnum.RUNNING.getCode()));
|
|
|
for (IssueSyncTask task : running) {
|
|
|
task.setTaskStatus(TaskStatusEnum.CANCELLED.getCode());
|
|
|
- task.setFinishedAt(LocalDateTime.now());
|
|
|
+ task.setFinishTime(LocalDateTime.now());
|
|
|
task.setErrorSummary("集成已禁用,任务终止");
|
|
|
CloudEntitySupport.fillOnUpdate(task);
|
|
|
syncTaskMapper.updateById(task);
|
|
|
@@ -211,8 +223,11 @@ public class CloudConfigServiceImpl implements CloudConfigService {
|
|
|
resp.setStatus(config.getStatus());
|
|
|
resp.setConnectionStatus(config.getConnectionStatus());
|
|
|
resp.setVersion(config.getVersion());
|
|
|
- resp.setLastTestAt(config.getLastTestAt());
|
|
|
- resp.setUpdatedAt(config.getUpdatedAt());
|
|
|
+ resp.setLastTestTime(config.getLastTestTime());
|
|
|
+ resp.setUpdatedTime(config.getUpdateTime());
|
|
|
+ resp.setUpdatedBy(config.getUpdateBy());
|
|
|
+ resp.setCreateTime(config.getCreateTime());
|
|
|
+ resp.setCreateBy(config.getCreateBy());
|
|
|
return resp;
|
|
|
}
|
|
|
}
|