数据接入

master
Saisai Liu 2024-04-21 18:01:09 +08:00
parent 3cf6d5a4a4
commit dc69c82be1
5 changed files with 31 additions and 14 deletions

View File

@ -72,6 +72,12 @@ public class BasicConfigInfo extends BaseEntity
@Excel(name ="连接参数") @Excel(name ="连接参数")
private String connectionParams; private String connectionParams;
@Excel(name ="用户名")
private String username;
@Excel(name ="密码")
private String password;
private String createBy; private String createBy;
private String updateBy; private String updateBy;
private Date createTime; private Date createTime;

View File

@ -12,6 +12,7 @@ import com.muyu.etl.service.BasicConfigInfoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
@ -99,10 +100,10 @@ public class BasicConfigInfoController extends BaseController
/** /**
* *
*/ */
@RequiresPermissions("etl:info:remove") @RequiresPermissions("etl:info:test")
@Log(title = "基础信息", businessType = BusinessType.DELETE) @Log(title = "测试连接")
@PostMapping("/connectionTest") @PostMapping("/connectionTest")
public Result connectionTest(BasicConfigInfo basicConfigInfo){ public Result connectionTest(@RequestBody BasicConfigInfo basicConfigInfo) throws ServletException {
return toAjax(basicConfigInfoService.connectionTest(basicConfigInfo)); return toAjax(basicConfigInfoService.connectionTest(basicConfigInfo));
} }
} }

View File

@ -3,6 +3,7 @@ package com.muyu.etl.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.etl.domain.BasicConfigInfo; import com.muyu.etl.domain.BasicConfigInfo;
import javax.servlet.ServletException;
import java.util.List; import java.util.List;
/** /**
@ -61,5 +62,5 @@ public interface BasicConfigInfoService extends IService<BasicConfigInfo>
*/ */
public int deleteBasicConfigInfoById(Long id); public int deleteBasicConfigInfoById(Long id);
boolean connectionTest(BasicConfigInfo basicConfigInfo); boolean connectionTest(BasicConfigInfo basicConfigInfo) throws ServletException;
} }

View File

@ -7,6 +7,7 @@ import com.muyu.etl.service.BasicConfigInfoService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.ServletException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
@ -99,23 +100,23 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMapp
} }
@Override @Override
public boolean connectionTest(BasicConfigInfo basicConfigInfo) { public boolean connectionTest(BasicConfigInfo basicConfigInfo) throws ServletException {
//定义下面需要的对象 //定义下面需要的对象
String host = basicConfigInfo.getHost(); String host = basicConfigInfo.getHost();
String port = basicConfigInfo.getPort(); String port = basicConfigInfo.getPort();
String databaseName = basicConfigInfo.getDatabaseName(); String databaseName = basicConfigInfo.getDatabaseName();
String databaseType = basicConfigInfo.getDatabaseType();
String url = "jdbc:mysql://localhost:3306/yourDatabase"; String url = "jdbc:"+databaseType+"://"+host+":"+port+"/"+databaseName+"";
String user = "yourUsername"; String user = basicConfigInfo.getUsername();
String password = "yourPassword"; String password = basicConfigInfo.getPassword();
Connection conn= null;
try { try {
Connection conn = DriverManager.getConnection(url, user, password); conn = DriverManager.getConnection(url, user, password);
System.out.println("Connected to the MySQL server successfully."); System.out.println("Connected to the MySQL server successfully.");
conn.close();
} catch (SQLException e) { } catch (SQLException e) {
System.out.println("Connection to MySQL failed: " + e.getMessage()); throw new ServletException("连接失败");
} }
return false; return true;
} }
} }

View File

@ -21,7 +21,7 @@
</resultMap> </resultMap>
<sql id="selectBasicConfigInfoVo"> <sql id="selectBasicConfigInfoVo">
select id, data_resource_name, data_sources_system_name, host, port, database_type, database_name, init_link_num, max_link_num, max_wait_time, max_wait_times,connection_params, remark from basic_config_info select id, data_resource_name,username,password, data_sources_system_name, host, port, database_type, database_name, init_link_num, max_link_num, max_wait_time, max_wait_times,connection_params, remark from basic_config_info
</sql> </sql>
<select id="selectBasicConfigInfoList" parameterType="com.muyu.etl.domain.BasicConfigInfo" resultMap="BasicConfigInfoResult"> <select id="selectBasicConfigInfoList" parameterType="com.muyu.etl.domain.BasicConfigInfo" resultMap="BasicConfigInfoResult">
@ -33,6 +33,8 @@
<if test="port != null and port != ''"> and port = #{port}</if> <if test="port != null and port != ''"> and port = #{port}</if>
<if test="databaseType != null and databaseType != ''"> and database_type = #{databaseType}</if> <if test="databaseType != null and databaseType != ''"> and database_type = #{databaseType}</if>
<if test="databaseName != null and databaseName != ''"> and database_name like concat('%', #{databaseName}, '%')</if> <if test="databaseName != null and databaseName != ''"> and database_name like concat('%', #{databaseName}, '%')</if>
<if test="username != null "> and username = #{username}</if>
<if test="password != null "> and password = #{password}</if>
<if test="initLinkNum != null "> and init_link_num = #{initLinkNum}</if> <if test="initLinkNum != null "> and init_link_num = #{initLinkNum}</if>
<if test="maxLinkNum != null "> and max_link_num = #{maxLinkNum}</if> <if test="maxLinkNum != null "> and max_link_num = #{maxLinkNum}</if>
<if test="maxWaitTime != null "> and max_wait_time = #{maxWaitTime}</if> <if test="maxWaitTime != null "> and max_wait_time = #{maxWaitTime}</if>
@ -55,6 +57,8 @@
<if test="port != null">port,</if> <if test="port != null">port,</if>
<if test="databaseType != null">database_type,</if> <if test="databaseType != null">database_type,</if>
<if test="databaseName != null">database_name,</if> <if test="databaseName != null">database_name,</if>
<if test="username != null">username,</if>
<if test="password != null">password,</if>
<if test="initLinkNum != null">init_link_num,</if> <if test="initLinkNum != null">init_link_num,</if>
<if test="maxLinkNum != null">max_link_num,</if> <if test="maxLinkNum != null">max_link_num,</if>
<if test="maxWaitTime != null">max_wait_time,</if> <if test="maxWaitTime != null">max_wait_time,</if>
@ -68,6 +72,8 @@
<if test="dataSourcesSystemName != null">#{dataSourcesSystemName},</if> <if test="dataSourcesSystemName != null">#{dataSourcesSystemName},</if>
<if test="host != null">#{host},</if> <if test="host != null">#{host},</if>
<if test="port != null">#{port},</if> <if test="port != null">#{port},</if>
<if test="username != null">#{username},</if>
<if test="password != null">#{password},</if>
<if test="databaseType != null">#{databaseType},</if> <if test="databaseType != null">#{databaseType},</if>
<if test="databaseName != null">#{databaseName},</if> <if test="databaseName != null">#{databaseName},</if>
<if test="initLinkNum != null">#{initLinkNum},</if> <if test="initLinkNum != null">#{initLinkNum},</if>
@ -88,6 +94,8 @@
<if test="port != null">port = #{port},</if> <if test="port != null">port = #{port},</if>
<if test="databaseType != null">database_type = #{databaseType},</if> <if test="databaseType != null">database_type = #{databaseType},</if>
<if test="databaseName != null">database_name = #{databaseName},</if> <if test="databaseName != null">database_name = #{databaseName},</if>
<if test="username != null">username = #{username},</if>
<if test="password != null">password = #{password},</if>
<if test="initLinkNum != null">init_link_num = #{initLinkNum},</if> <if test="initLinkNum != null">init_link_num = #{initLinkNum},</if>
<if test="maxLinkNum != null">max_link_num = #{maxLinkNum},</if> <if test="maxLinkNum != null">max_link_num = #{maxLinkNum},</if>
<if test="maxWaitTime != null">max_wait_time = #{maxWaitTime},</if> <if test="maxWaitTime != null">max_wait_time = #{maxWaitTime},</if>