瀏覽代碼

租户关联数据源

xuezizhuo 1 年之前
父節點
當前提交
da57fc1f7d

+ 13 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java

@@ -2,6 +2,9 @@ package com.ruoyi.web.controller.system;
 
 import java.util.List;
 import java.util.Set;
+
+import com.ruoyi.common.core.domain.entity.SysTenant;
+import com.ruoyi.system.service.impl.SysTenantServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -17,6 +20,8 @@ import com.ruoyi.framework.web.service.SysLoginService;
 import com.ruoyi.framework.web.service.SysPermissionService;
 import com.ruoyi.system.service.ISysMenuService;
 
+import javax.annotation.Resource;
+
 /**
  * 登录验证
  * 
@@ -34,6 +39,9 @@ public class SysLoginController
     @Autowired
     private SysPermissionService permissionService;
 
+    @Resource
+    private SysTenantServiceImpl sysTenantService;
+
     /**
      * 登录方法
      * 
@@ -68,6 +76,11 @@ public class SysLoginController
         ajax.put("user", user);
         ajax.put("roles", roles);
         ajax.put("permissions", permissions);
+        //租户信息
+        if(user.getTenantId() != null){
+            SysTenant sysTenant = sysTenantService.selectSysTenantByTenantId(user.getTenantId());
+            ajax.put("tenant",sysTenant);
+        }
         return ajax;
     }
 

+ 16 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysTenant.java

@@ -44,6 +44,9 @@ public class SysTenant extends BaseEntity
     @Excel(name = "是否删除(0:未删除,1已删除)")
     private String isDel;
 
+    /** 数据源id */
+    private Long datasourceId;
+
     public Long getTenantId() {
         return tenantId;
     }
@@ -103,6 +106,14 @@ public class SysTenant extends BaseEntity
         this.isDel = isDel;
     }
 
+    public Long getDatasourceId() {
+        return datasourceId;
+    }
+
+    public void setDatasourceId(Long datasourceId) {
+        this.datasourceId = datasourceId;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -117,6 +128,11 @@ public class SysTenant extends BaseEntity
             .append("createTime", getCreateTime())
             .append("updateBy", getUpdateBy())
             .append("updateTime", getUpdateTime())
+            .append("datasourceId",getTenantId())
             .toString();
     }
+
+
+
+
 }

+ 6 - 1
ruoyi-system/src/main/resources/mapper/system/SysTenantMapper.xml

@@ -14,10 +14,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="createBy"    column="create_by"    />
         <result property="createTime"    column="create_time"    />
         <result property="isDel"    column="is_del"    />
+        <result property="datasourceId" column="datasource_id"/>
+
     </resultMap>
 
     <sql id="selectSysTenantVo">
-        select tenant_id, tenant_name, tenant_code, owner, contact_info, address, create_by, create_time, is_del from sys_tenant
+        select tenant_id, tenant_name, tenant_code, owner, contact_info, address, create_by, create_time, is_del,datasource_id from sys_tenant
     </sql>
 
     <select id="selectSysTenantList" parameterType="SysTenant" resultMap="SysTenantResult">
@@ -48,6 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createBy != null and createBy != ''">create_by,</if>
             <if test="createTime != null">create_time,</if>
             <if test="isDel != null and isDel != ''">is_del,</if>
+            <if test="datasourceId != null">datasource_id,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="tenantName != null and tenantName != ''">#{tenantName},</if>
@@ -58,6 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createBy != null and createBy != ''">#{createBy},</if>
             <if test="createTime != null">#{createTime},</if>
             <if test="isDel != null and isDel != ''">#{isDel},</if>
+            <if test="datasourceId != null">#{datasourceId},</if>
          </trim>
     </insert>
 
@@ -72,6 +76,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="isDel != null and isDel != ''">is_del = #{isDel},</if>
+            <if test="datasourceId != null">datasource_id = #{datasourceId},</if>
         </trim>
         where tenant_id = #{tenantId}
     </update>

+ 9 - 1
ruoyi-ui/src/store/modules/user.js

@@ -7,7 +7,8 @@ const user = {
     name: '',
     avatar: '',
     roles: [],
-    permissions: []
+    permissions: [],
+    tenant:{}
   },
 
   mutations: {
@@ -25,6 +26,9 @@ const user = {
     },
     SET_PERMISSIONS: (state, permissions) => {
       state.permissions = permissions
+    },
+    SET_TENANT: (state, tenant) => {
+      state.tenant = tenant
     }
   },
 
@@ -58,6 +62,9 @@ const user = {
           } else {
             commit('SET_ROLES', ['ROLE_DEFAULT'])
           }
+          if(res.tenant != null){
+            commit('SET_TENANT',res.tenant)
+          }
           commit('SET_NAME', user.userName)
           commit('SET_AVATAR', avatar)
           resolve(res)
@@ -74,6 +81,7 @@ const user = {
           commit('SET_TOKEN', '')
           commit('SET_ROLES', [])
           commit('SET_PERMISSIONS', [])
+          commit('SET_TENANT', {})
           removeToken()
           resolve()
         }).catch(error => {