浏览代码

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

yh 2 月之前
父节点
当前提交
8f95e15773
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      fs-service/src/main/java/com/fs/tenant/service/impl/TenantInfoServiceImpl.java

+ 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.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.exception.CustomException;
 import com.fs.common.utils.DateUtils;
 import com.fs.tenant.domain.TenantInfo;
 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());
             // 1. 判断是否存在
             if (TenantUtils.databaseExists(conn, tenantInfo.getDbName())) {
-                throw new RuntimeException("数据库已存在");
+                throw new CustomException("数据库已存在");
             }
 
             // 2. 创建数据库
@@ -83,6 +86,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
             tenantAsyncService.asyncInit(tenantInfo);
             return result;
 
+        } catch (CustomException  e) {
+            throw e;
         } catch (Exception e) {
             try {
                 // 删除租户数据库