xuezizhuo 1 жил өмнө
parent
commit
524c0d09dd

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

@@ -3,8 +3,10 @@ package com.ruoyi.web.controller.system;
 import java.util.List;
 import java.util.Set;
 
+import com.ruoyi.common.core.domain.entity.DataSource;
 import com.ruoyi.common.core.domain.entity.SysTenant;
 import com.ruoyi.common.utils.http.HttpUtils;
+import com.ruoyi.system.service.IDataSourceService;
 import com.ruoyi.system.service.impl.SysTenantServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -43,6 +45,9 @@ public class SysLoginController
     @Resource
     private SysTenantServiceImpl sysTenantService;
 
+    @Resource
+    private IDataSourceService dataSourceService;
+
 
 
     /**
@@ -84,6 +89,9 @@ public class SysLoginController
             //租户信息
             SysTenant sysTenant = sysTenantService.selectSysTenantByTenantId(user.getTenantId());
             ajax.put("tenant",sysTenant);
+            //数据源信息
+            DataSource dataSource = dataSourceService.selectById(sysTenant.getDatasourceId());
+            ajax.put("dataSource",dataSource);
             //调用数据引擎服务切换数据源接口
             String param = "id="+sysTenant.getDatasourceId();
             String data = HttpUtils.sendGet("http://localhost:8081/dataSource/changeDataSource",param);

+ 0 - 5
ruoyi-common/pom.xml

@@ -126,11 +126,6 @@
             <artifactId>javax.servlet-api</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>com.baomidou</groupId>
-            <artifactId>mybatis-plus-boot-starter</artifactId>
-        </dependency>
-
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>

+ 0 - 5
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/DataSource.java

@@ -1,8 +1,5 @@
 package com.ruoyi.common.core.domain.entity;
 
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
@@ -10,7 +7,6 @@ import java.io.Serializable;
 
 @Data
 @Accessors(chain = true)
-@TableName("data_source")
 public class DataSource implements Serializable {
 
     private static final long serialVersionUID = 1L;
@@ -18,7 +14,6 @@ public class DataSource implements Serializable {
     /**
      * 字典编码
      */
-    @TableId(value = "id", type = IdType.AUTO)
     private Long id;
 
     /**

+ 15 - 2
ruoyi-system/src/main/java/com/ruoyi/system/mapper/DataSourceMapper.java

@@ -1,10 +1,17 @@
 package com.ruoyi.system.mapper;
 
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.common.core.domain.entity.DataSource;
 import org.apache.ibatis.annotations.Param;
 
-public interface DataSourceMapper extends BaseMapper<DataSource> {
+import java.util.List;
+
+public interface DataSourceMapper {
+
+    /**
+     * 查询数据源列表
+     *
+     */
+    public List<DataSource> selectDataSourceList(DataSource dataSource);
 
     /**
      * 查询同一数据源下数据库是否存在
@@ -15,4 +22,10 @@ public interface DataSourceMapper extends BaseMapper<DataSource> {
      * 新增数据源
      */
     int insertDataSource(DataSource dataSource);
+
+    /**
+     * 根据编号查询数据源
+     */
+    DataSource selectById(Long id);
+
 }

+ 6 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/IDataSourceService.java

@@ -1,9 +1,8 @@
 package com.ruoyi.system.service;
 
-import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.entity.DataSource;
 
-public interface IDataSourceService extends IService<DataSource> {
+public interface IDataSourceService {
 
     /**
      * 查询同一数据源下数据库是否存在
@@ -15,4 +14,9 @@ public interface IDataSourceService extends IService<DataSource> {
      */
     int insertDataSource(DataSource dataSource,Long tenantId);
 
+    /**
+     * 根据编号查询数据源
+     */
+    DataSource selectById(Long id);
+
 }

+ 6 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DataSourceServiceImpl.java

@@ -1,7 +1,6 @@
 package com.ruoyi.system.service.impl;
 
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.core.domain.entity.DataSource;
 import com.ruoyi.common.core.domain.entity.SysTenant;
 import com.ruoyi.system.mapper.DataSourceMapper;
@@ -12,7 +11,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 
 @Service
-public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSource> implements IDataSourceService {
+public class DataSourceServiceImpl implements IDataSourceService {
 
     @Resource
     private DataSourceMapper dataSourceMapper;
@@ -35,4 +34,9 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
         return sysTenantService.updateSysTenant(sysTenant);
     }
 
+    @Override
+    public DataSource selectById(Long id) {
+        return dataSourceMapper.selectById(id);
+    }
+
 }

+ 31 - 0
ruoyi-system/src/main/resources/mapper/system/DataSourceMapper.xml

@@ -4,6 +4,32 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.system.mapper.DataSourceMapper">
 
+    <resultMap type="DataSource" id="DataSourceResult">
+        <result property="id"    column="id"    />
+        <result property="databaseName"    column="database_name"    />
+        <result property="databaseIp"    column="database_ip"    />
+        <result property="username"    column="username"    />
+        <result property="password"    column="password"    />
+        <result property="portNumber"    column="port_number"    />
+        <result property="databaseType"    column="database_type"    />
+    </resultMap>
+
+    <sql id="selectDataSourceVo">
+        select id, database_name, database_ip, username, password, port_number, database_type from data_source
+    </sql>
+
+    <select id="selectDataSourceList" parameterType="DataSource" resultMap="DataSourceResult">
+        <include refid="selectDataSourceVo"/>
+        <where>
+            <if test="databaseName != null  and databaseName != ''"> and database_name like concat('%', #{databaseName}, '%')</if>
+            <if test="databaseIp != null  and databaseIp != ''"> and database_ip = #{databaseIp}</if>
+            <if test="username != null  and username != ''"> and username like concat('%', #{username}, '%')</if>
+            <if test="password != null  and password != ''"> and password = #{password}</if>
+            <if test="portNumber != null "> and port_number = #{portNumber}</if>
+            <if test="databaseType != null  and databaseType != ''"> and database_type = #{databaseType}</if>
+        </where>
+    </select>
+
     <select id="selectDatabaseExist" resultType="int">
         select count(1) from data_source where database_ip = #{databaseIp} and database_name = #{databaseName} and port_number = #{portNumber}
     </select>
@@ -13,5 +39,10 @@
         values (#{databaseName},#{databaseIp},#{username},#{password},#{portNumber},#{databaseType})
     </insert>
 
+    <select id="selectById" resultMap="DataSourceResult">
+        <include refid="selectDataSourceVo"/>
+        where id = #{id}
+    </select>
+
 
 </mapper>