Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions admin/src/main/resources/templates/system/apiConfig/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,22 @@
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-post-edit" th:object="${apiConfig}">
<input id="postId" name="id" type="hidden" th:field="*{id}"/>
<!-- <div class="form-group">-->
<!-- <label class="col-sm-3 control-label is-required">dbConfigId:</label>-->
<!-- <div class="col-sm-8">-->
<!-- <input class="form-control" type="text" name="dbConfigId" id="dbConfigId" th:field="*{dbConfigId}" required>-->
<!-- </div>-->
<!-- </div>-->

<div class="form-group">
<label class="col-sm-3 control-label is-required">apiName:</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="apiName" id="apiName" th:field="*{apiName}" onblur="apiPathFun()" disabled="disabled" required>
<input class="form-control" type="text" name="apiName" id="apiName" th:field="*{apiName}" onblur="apiPathFun()" required>
</div>
</div>

<div class="form-group">
<label class="col-sm-3 control-label is-required">apiPath:</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="apiPath" id="apiPath" th:field="*{apiPath}" disabled="disabled" required>
</div>
</div>




<div class="form-group">
<label class="col-sm-3 control-label is-required">dbConfig:</label>
<div class="col-sm-8">
<!-- th:text="${dbConfig.connectName}"-->
<select class="form-control" name="dbConfig" id="dbConfig" th:field="*{dbConfigId}" required>
<option value="">--请选择数据源--</option>
<option th:each="dblist:${dbList}" th:value="${dblist.id}" th:text="${dblist.connectName}"></option>
Expand Down Expand Up @@ -62,20 +50,14 @@
<option value="get">get</option>
<option value="post">post</option>
</select>

</div>
</div>



<div class="form-group">
<label class="col-sm-3 control-label is-required">qps:</label>
<div class="col-sm-8">
<input class="form-control" type="text" name="qps" id="qps" th:field="*{qps}" required>
</div>
</div>


<div class="form-group">
<label class="col-sm-3 control-label is-required">timeOut:</label>
<div class="col-sm-8">
Expand All @@ -90,8 +72,6 @@
<textarea class="form-control" name="apiSql" id="apiSql" style="height: 300px"
th:field="*{apiSql}" required onblur="paramFun()"></textarea>
</div>
<!--onblur="paramFun()"-->

</div>
<div class="form-group">
<label class="col-sm-3 control-label is-required">请求参数:</label>
Expand All @@ -113,6 +93,7 @@
function apiPathFun() {
$("#apiPath").val($("#apiName").val());
}

function paramFun() {
var paraHtml = "<div class=\"form-group\">\n" +
" <label class=\"col-sm-3\"></label>\n" +
Expand Down Expand Up @@ -156,7 +137,6 @@
function submitHandler() {
$.operate.save(prefix + "/edit", $('#form-post-edit').serialize());
}
window.onload = function(){this.paramFun()}
</script>
</body>
</html>
21 changes: 19 additions & 2 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
</description>

<dependencies>
<!-- 阿里JSON解析器 -->
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.20</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<!-- <version>1.18.12</version>-->
</dependency>

<!-- Spring框架基本的核心工具 -->
<dependency>
Expand All @@ -34,7 +45,7 @@
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
</dependency>

<!-- Shiro使用EhCache缓存框架 -->
<dependency>
<groupId>org.apache.shiro</groupId>
Expand Down Expand Up @@ -143,7 +154,13 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.15</version>
<scope>compile</scope>
</dependency>

</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.vince.xq.common.datasource.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
* druid 配置属性
*
* @author ruoyi
*/
@Configuration
public class DruidPropertie
{
@Value("${spring.datasource.druid.initialSize}")
private int initialSize;

@Value("${spring.datasource.druid.minIdle}")
private int minIdle;

@Value("${spring.datasource.druid.maxActive}")
private int maxActive;

@Value("${spring.datasource.druid.maxWait}")
private int maxWait;

@Value("${spring.datasource.druid.timeBetweenEvictionRunsMillis}")
private int timeBetweenEvictionRunsMillis;

@Value("${spring.datasource.druid.minEvictableIdleTimeMillis}")
private int minEvictableIdleTimeMillis;

@Value("${spring.datasource.druid.maxEvictableIdleTimeMillis}")
private int maxEvictableIdleTimeMillis;

@Value("${spring.datasource.druid.validationQuery}")
private String validationQuery;

@Value("${spring.datasource.druid.testWhileIdle}")
private boolean testWhileIdle;

@Value("${spring.datasource.druid.testOnBorrow}")
private boolean testOnBorrow;

@Value("${spring.datasource.druid.testOnReturn}")
private boolean testOnReturn;

public DruidDataSource dataSource(String url, String username, String password, String driverClassName)
{
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(url);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
/**失败不重试*/
datasource.setBreakAfterAcquireFailure(true);
/** 配置初始化大小、最小、最大 */
datasource.setInitialSize(initialSize);
datasource.setMaxActive(maxActive);
datasource.setMinIdle(minIdle);

/** 配置获取连接等待超时的时间 */
datasource.setMaxWait(maxWait);

/** 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 */
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);

/** 配置一个连接在池中最小、最大生存的时间,单位是毫秒 */
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis);

/**
* 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用。
*/
datasource.setValidationQuery(validationQuery);
/** 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 */
datasource.setTestWhileIdle(testWhileIdle);
/** 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */
datasource.setTestOnBorrow(testOnBorrow);
/** 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */
datasource.setTestOnReturn(testOnReturn);
return datasource;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

package com.vince.xq.common.datasource.dao.entity;


import lombok.Data;

/**
* @description 数据源 entity
* @author Raod
* @date 2021-03-18 12:09:57.728203200
**/

@Data
public class DataSource {
private String sourceCode;
private String sourceName;
private String sourceDesc;
private String sourceType;
private String sourceConfig;
private Integer enableFlag;
private Integer deleteFlag;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

package com.vince.xq.common.datasource.dto;

import lombok.Data;

import java.io.Serializable;
import java.util.Map;


/**
*
* @description 数据源 dto
* @author sgx
* @date 2023
**/
@Data
public class DataSourceDto implements Serializable {
/** 数据源id */
private Long id;
/** 数据源编码 */
private String sourceCode;

/** 数据源名称 */
private String sourceName;

/** 数据源描述 */
private String sourceDesc;

/** 数据源类型 DIC_NAME=SOURCE_TYPE; mysql,orace,sqlserver,elasticsearch,接口,javaBean,数据源类型字典中item-extend动态生成表单 */
private String sourceType;

/** 数据源连接配置json:关系库{ jdbcUrl:'', username:'', password:'','driverName':''}ES-sql{ apiUrl:'http://127.0.0.1:9092/_xpack/sql?format=json','method':'POST','body':'{"query":"select 1"}' } 接口{ apiUrl:'http://ip:port/url', method:'' } javaBean{ beanNamw:'xxx' } */
private String sourceConfig;

/** 0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG */
private Integer enableFlag;

/** 0--未删除 1--已删除 DIC_NAME=DELETE_FLAG */
private Integer deleteFlag;

/**************************************************************/
/**关系型数据库jdbcUrl */
private String jdbcUrl;

/** 关系型数据库用户名 */
private String username;

/** 关系型数据库密码 */
private String password;

/** 关系型数据库驱动类 */
private String driverName;

/** 关系型数据库sql */
private String sql;

/** http requestUrl */
private String apiUrl;

/** http method */
private String method;

/** http header */
private String header;

/** http 请求体 */
private String body;

/** 动态查询sql或者接口中的请求体 */
private String dynSentence;

/** 传入的自定义参数,解决url中存在的动态参数*/
private Map<String, Object> contextData;
/**分页的页号*/
private Integer pnum;
/**单页的数量*/
private Integer psize;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.vince.xq.common.datasource.service;

import com.alibaba.fastjson2.JSONObject;
import com.vince.xq.common.datasource.dto.DataSourceDto;


import java.util.List;

public interface IDataSourceService {


/**
* 执行sql
* @param dto
* @return
*/
List<JSONObject> execute(DataSourceDto dto);

long mysqlTotal(DataSourceDto sourceDto);
List<JSONObject> executeRelationalDb(DataSourceDto dto);
/**
* 关系型数据库 测试连接
*
* @param dto
*/
Boolean testRelationalDb(DataSourceDto dto);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.vince.xq.common.datasource.service;




import com.vince.xq.common.datasource.dto.DataSourceDto;
import java.sql.Connection;
import java.sql.SQLException;

/**
* @Copyright (c) 2023, SGX COMPANY.
* @Author: sgx
* @Description:
**/
public interface IJdbcService {

void test(Long id);

/**
* 删除数据库连接池
*
* @param id
*/
void removeJdbcConnectionPool(Long id);


/**
* 获取连接
*
* @param dataSource
* @return
* @throws SQLException
*/
Connection getPooledConnection(DataSourceDto dataSource) throws SQLException;

/**
* 测试数据库连接 获取一个连接
*
* @param dataSource
* @return
* @throws ClassNotFoundException driverName不正确
* @throws SQLException
*/
Connection getUnPooledConnection(DataSourceDto dataSource) throws SQLException;
}
Loading