Prechádzať zdrojové kódy

修复创建租户时,如果数据库存在删除库的bug

yh 2 mesiacov pred
rodič
commit
8f95e15773

+ 6 - 1
fs-service/src/main/java/com/fs/tenant/service/impl/TenantInfoServiceImpl.java

@@ -2,7 +2,10 @@ package com.fs.tenant.service.impl;
 
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fs.common.core.domain.R;
+import com.fs.common.core.domain.entity.SysMenu;
 import com.fs.common.enums.DataSourceType;
 import com.fs.common.enums.DataSourceType;
+import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.DateUtils;
 import com.fs.tenant.domain.TenantInfo;
 import com.fs.tenant.domain.TenantInfo;
 import com.fs.tenant.mapper.TenantInfoMapper;
 import com.fs.tenant.mapper.TenantInfoMapper;
@@ -67,7 +70,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
             conn = TenantUtils.getConnection(tenantInfo.getDbIp(),tenantInfo.getDbPort(),"mysql",tenantInfo.getDbAccount(),tenantInfo.getDbPwd());
             conn = TenantUtils.getConnection(tenantInfo.getDbIp(),tenantInfo.getDbPort(),"mysql",tenantInfo.getDbAccount(),tenantInfo.getDbPwd());
             // 1. 判断是否存在
             // 1. 判断是否存在
             if (TenantUtils.databaseExists(conn, tenantInfo.getDbName())) {
             if (TenantUtils.databaseExists(conn, tenantInfo.getDbName())) {
-                throw new RuntimeException("数据库已存在");
+                throw new CustomException("数据库已存在");
             }
             }
 
 
             // 2. 创建数据库
             // 2. 创建数据库
@@ -83,6 +86,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
             tenantAsyncService.asyncInit(tenantInfo);
             tenantAsyncService.asyncInit(tenantInfo);
             return result;
             return result;
 
 
+        } catch (CustomException  e) {
+            throw e;
         } catch (Exception e) {
         } catch (Exception e) {
             try {
             try {
                 // 删除租户数据库
                 // 删除租户数据库