commit
3312d62b39
9 changed files with 794 additions and 0 deletions
@ -0,0 +1,10 @@ |
|||||||
|
*.iml |
||||||
|
.idea/ |
||||||
|
lib/report/*.jar |
||||||
|
target/ |
||||||
|
.DS_Store |
||||||
|
.gradle |
||||||
|
build |
||||||
|
local.properties |
||||||
|
classes/ |
||||||
|
transform-classes/ |
@ -0,0 +1,132 @@ |
|||||||
|
|
||||||
|
apply plugin: 'java' |
||||||
|
|
||||||
|
|
||||||
|
ext { |
||||||
|
/** |
||||||
|
* 项目中依赖的jar的路径 |
||||||
|
* 1.如果依赖的jar需要打包到zip中,放置在lib根目录下 |
||||||
|
* 2.如果依赖的jar仅仅是编译时需要,防止在lib下子目录下即可 |
||||||
|
*/ |
||||||
|
libPath = "$projectDir/../webroot/WEB-INF/lib" |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否对插件的class进行加密保护,防止反编译 |
||||||
|
*/ |
||||||
|
guard = true |
||||||
|
|
||||||
|
def pluginInfo = getPluginInfo() |
||||||
|
pluginPre = "fine-plugin" |
||||||
|
pluginName = pluginInfo.id |
||||||
|
pluginVersion = pluginInfo.version |
||||||
|
|
||||||
|
outputPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/classes" |
||||||
|
} |
||||||
|
|
||||||
|
group = 'com.fr.plugin' |
||||||
|
version = '10.0' |
||||||
|
sourceCompatibility = '8' |
||||||
|
|
||||||
|
sourceSets { |
||||||
|
main { |
||||||
|
java.outputDir = file(outputPath) |
||||||
|
output.resourcesDir = file(outputPath) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ant.importBuild("encrypt.xml") |
||||||
|
//定义ant变量 |
||||||
|
ant.projectDir = projectDir |
||||||
|
ant.references["compile.classpath"] = ant.path { |
||||||
|
fileset(dir: libPath, includes: '**/*.jar') |
||||||
|
fileset(dir: ".",includes:"**/*.jar" ) |
||||||
|
} |
||||||
|
|
||||||
|
classes.dependsOn('clean') |
||||||
|
|
||||||
|
task copyFiles(type: Copy,dependsOn: 'classes'){ |
||||||
|
from outputPath |
||||||
|
into "$projectDir/classes" |
||||||
|
} |
||||||
|
|
||||||
|
task preJar(type:Copy,dependsOn: guard ? 'compile_encrypt_javas' : 'compile_plain_javas'){ |
||||||
|
from "$projectDir/classes" |
||||||
|
into "$projectDir/transform-classes" |
||||||
|
include "**/*.*" |
||||||
|
} |
||||||
|
jar.dependsOn("preJar") |
||||||
|
|
||||||
|
task makeJar(type: Jar,dependsOn: preJar){ |
||||||
|
from fileTree(dir: "$projectDir/transform-classes") |
||||||
|
baseName pluginPre |
||||||
|
appendix pluginName |
||||||
|
version pluginVersion |
||||||
|
destinationDir = file("$buildDir/libs") |
||||||
|
|
||||||
|
doLast(){ |
||||||
|
delete file("$projectDir/classes") |
||||||
|
delete file("$projectDir/transform-classes") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
task copyFile(type: Copy,dependsOn: ["makeJar"]){ |
||||||
|
from "$buildDir/libs" |
||||||
|
from("$projectDir/lib") { |
||||||
|
include "*.jar" |
||||||
|
} |
||||||
|
from "$projectDir/plugin.xml" |
||||||
|
into file("$buildDir/temp/plugin") |
||||||
|
} |
||||||
|
|
||||||
|
task zip(type:Zip,dependsOn:["copyFile"]){ |
||||||
|
from "$buildDir/temp/plugin" |
||||||
|
destinationDir file("$buildDir/install") |
||||||
|
baseName pluginPre |
||||||
|
appendix pluginName |
||||||
|
version pluginVersion |
||||||
|
} |
||||||
|
|
||||||
|
//控制build时包含哪些文件,排除哪些文件 |
||||||
|
processResources { |
||||||
|
// exclude everything |
||||||
|
// 用*.css没效果 |
||||||
|
// exclude '**/*.css' |
||||||
|
// except this file |
||||||
|
// include 'xx.xml' |
||||||
|
} |
||||||
|
|
||||||
|
/*读取plugin.xml中的version*/ |
||||||
|
def getPluginInfo(){ |
||||||
|
def xmlFile = file("plugin.xml") |
||||||
|
if (!xmlFile.exists()) { |
||||||
|
return ["id":"none", "version":"1.0.0"] |
||||||
|
} |
||||||
|
def plugin = new XmlParser().parse(xmlFile) |
||||||
|
def version = plugin.version[0].text() |
||||||
|
def id = plugin.id[0].text() |
||||||
|
return ["id":id,"version":version] |
||||||
|
} |
||||||
|
|
||||||
|
repositories { |
||||||
|
maven { |
||||||
|
allowInsecureProtocol = true |
||||||
|
url = uri('http://mvn.finedevelop.com/repository/maven-public/') |
||||||
|
} |
||||||
|
|
||||||
|
maven { |
||||||
|
url = uri('https://repo.maven.apache.org/maven2') |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
dependencies { |
||||||
|
//使用本地jar |
||||||
|
implementation fileTree(dir: 'lib', include: ['**/*.jar']) |
||||||
|
implementation fileTree(dir: libPath, include: ['**/*.jar']) |
||||||
|
testImplementation 'org.easymock:easymock:3.5.1' |
||||||
|
testImplementation 'org.powermock:powermock-module-junit4:1.7.1' |
||||||
|
testImplementation 'org.powermock:powermock-api-easymock:1.7.1' |
||||||
|
testImplementation 'junit:junit:4.12' |
||||||
|
//@SuppressStaticInitialization |
||||||
|
testImplementation 'org.powermock:powermock-module-junit4-rule-agent:1.7.1' |
||||||
|
} |
||||||
|
|
@ -0,0 +1,19 @@ |
|||||||
|
// 注:验证完后需立即禁用掉【BDP集成测试】插件 |
||||||
|
var data = JSON.stringify({ |
||||||
|
"sql": "xxx"// 要执行的SQL |
||||||
|
}); |
||||||
|
|
||||||
|
var xhr = new XMLHttpRequest(); |
||||||
|
xhr.withCredentials = true; |
||||||
|
|
||||||
|
xhr.addEventListener("readystatechange", function() { |
||||||
|
if(this.readyState === 4) { |
||||||
|
console.log(this.responseText); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
xhr.open("POST", "http://localhost:8080/webroot/decision/jd/bdp/test/sqlTest");// 替换为实际的地址 |
||||||
|
xhr.setRequestHeader("Content-Type", "application/json"); |
||||||
|
// xhr.setRequestHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwidGVuYW50SWQiOiJkZWZhdWx0IiwiaXNzIjoiZmFucnVhbiIsImRlc2NyaXB0aW9uIjoiMSgxKSIsImV4cCI6MTczOTMyOTU1OCwiaWF0IjoxNzM5MzI1OTU4LCJqdGkiOiJOaFF5aytGRnBGMTJlSFRVTVhCQWp2THp1TEpxb2JIQTN3VGFMOW5lcWpvcFVkSGQifQ.OVynKPOXATzl5zUm_1rflS5HkMC6goEa8g5OIWFdy6M"); |
||||||
|
// 在浏览器中执行,不需要单独传递token |
||||||
|
xhr.send(data); |
@ -0,0 +1,13 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||||
|
<project> |
||||||
|
<target name="compile_encrypt_javas" depends="copyFiles"> |
||||||
|
<echo message="加密文件"/> |
||||||
|
<echo message="${projectDir}"/> |
||||||
|
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask"> |
||||||
|
<classpath refid="compile.classpath"/> |
||||||
|
</taskdef> |
||||||
|
<pretreatment baseDir="${projectDir}"/> |
||||||
|
</target> |
||||||
|
<target name="compile_plain_javas" depends="copyFiles"> |
||||||
|
</target> |
||||||
|
</project> |
@ -0,0 +1,20 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||||
|
<plugin> |
||||||
|
<id>com.fr.plugin.gp.jd.integration.bdp.test</id> |
||||||
|
<name><![CDATA[BDP集成测试]]></name> |
||||||
|
<active>yes</active> |
||||||
|
<version>0.0.17</version> |
||||||
|
<env-version>11.0</env-version> |
||||||
|
<jartime>2024-08-01</jartime> |
||||||
|
<vendor>Roc</vendor> |
||||||
|
<description><![CDATA[BDP集成测试]]></description> |
||||||
|
<change-notes><![CDATA[ |
||||||
|
[1.0.0]BDP集成测试<br/> |
||||||
|
]]></change-notes> |
||||||
|
|
||||||
|
<function-recorder class="com.fr.plugin.gp.jd.integration.bdp.test.ControllerRegisterProvider"/> |
||||||
|
<extra-decision> |
||||||
|
<ControllerRegisterProvider class="com.fr.plugin.gp.jd.integration.bdp.test.ControllerRegisterProvider"/> |
||||||
|
</extra-decision> |
||||||
|
|
||||||
|
</plugin> |
File diff suppressed because one or more lines are too long
@ -0,0 +1,438 @@ |
|||||||
|
package com.fr.plugin.gp.jd.integration.bdp.test; |
||||||
|
|
||||||
|
import com.fr.decision.webservice.Response; |
||||||
|
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||||
|
import com.fr.decision.webservice.v10.login.TokenResource; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.plugin.gp.jd.integration.bdp.test.bean.SQLBean; |
||||||
|
import com.fr.third.springframework.stereotype.Controller; |
||||||
|
import com.fr.third.springframework.util.StopWatch; |
||||||
|
import com.fr.third.springframework.web.bind.annotation.RequestBody; |
||||||
|
import com.fr.third.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||||
|
import com.fr.third.springframework.web.bind.annotation.ResponseBody; |
||||||
|
import com.fr.web.core.cluster.ClusterStatusHelper; |
||||||
|
import com.jd.bdp.orca.jdbc.common.StringUtils; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
import java.sql.*; |
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
import static com.jd.bdp.orca.jdbc.proxy.transport.common.JdbcPropKeys.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Roc |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2025/1/6 |
||||||
|
* 测试JDBC连接执行的一些结果 |
||||||
|
*/ |
||||||
|
@Controller |
||||||
|
@LoginStatusChecker(required = true, tokenResource = TokenResource.COOKIE) |
||||||
|
@RequestMapping("/jd/bdp/test") |
||||||
|
public class BDPJDBCTestResource { |
||||||
|
|
||||||
|
private static final String CONN_URL = "jdbc:orca://gateway188-doris.orca.jd.local:2006/XYLgJedS0mWyC0W4QUho8lvy+92/AEl8m5dM1ddCp6vw5joj+3SNNWL/NjY1Svq5dNrOJFM80VoJAY7KqEhcCk/eutnRhkHkKkEPs7Fk4c8YJ+nbZ9irl5PWq1gL8m5QxzS97GiRjozoHam5gn/yWCnSYxRsmcqL8+gsmsNQffw8/UOUgUnuQj2AIYLK73ZKUtPVDabI9oavCGC6S3AYUg=="; |
||||||
|
private static final String DRIVER_NAME = "com.jd.bdp.orca.jdbc.Driver"; |
||||||
|
private static final String ERP_NAME = "defaultErp"; |
||||||
|
private static final String BDP_NAME = "defaultBdp"; |
||||||
|
|
||||||
|
@RequestMapping( |
||||||
|
value = {"/tableColumnInfo"}, |
||||||
|
method = {RequestMethod.GET} |
||||||
|
) |
||||||
|
@ResponseBody |
||||||
|
public Response clearCaches(HttpServletRequest req) { |
||||||
|
try { |
||||||
|
return Response.ok(tableColumnInfo()); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return Response.error("error", e.getMessage() + "--node:" + ClusterStatusHelper.getCurrentNodeId()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@RequestMapping( |
||||||
|
value = {"/connectionMetaData"}, |
||||||
|
method = {RequestMethod.GET} |
||||||
|
) |
||||||
|
@ResponseBody |
||||||
|
public Response connectionMetaData(HttpServletRequest req) { |
||||||
|
try { |
||||||
|
return Response.ok(connectionMetaData()); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return Response.error("error", e.getMessage() + "--node:" + ClusterStatusHelper.getCurrentNodeId()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@RequestMapping( |
||||||
|
value = {"/tablesInfo"}, |
||||||
|
method = {RequestMethod.GET} |
||||||
|
) |
||||||
|
@ResponseBody |
||||||
|
public Response tablesInfo(HttpServletRequest req) { |
||||||
|
try { |
||||||
|
return Response.ok(tablesInfo()); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return Response.error("error", e.getMessage() + "--node:" + ClusterStatusHelper.getCurrentNodeId()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@RequestMapping( |
||||||
|
value = {"/sqlResult"}, |
||||||
|
method = {RequestMethod.GET} |
||||||
|
) |
||||||
|
@ResponseBody |
||||||
|
public Response sqlResult(HttpServletRequest req) { |
||||||
|
try { |
||||||
|
return Response.ok(sqlResult()); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return Response.error("error", e.getMessage() + "--node:" + ClusterStatusHelper.getCurrentNodeId()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping( |
||||||
|
value = {"/longSql"}, |
||||||
|
method = {RequestMethod.GET} |
||||||
|
) |
||||||
|
@ResponseBody |
||||||
|
public Response longSql(HttpServletRequest req) { |
||||||
|
try { |
||||||
|
return Response.ok(longSql()); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return Response.error("error", e.getMessage() + "--node:" + ClusterStatusHelper.getCurrentNodeId()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@RequestMapping( |
||||||
|
value = {"/current_database"}, |
||||||
|
method = {RequestMethod.GET} |
||||||
|
) |
||||||
|
@ResponseBody |
||||||
|
public Response current_database(HttpServletRequest req) { |
||||||
|
try { |
||||||
|
return Response.ok(current_database()); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return Response.error("error", e.getMessage() + "--node:" + ClusterStatusHelper.getCurrentNodeId()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping( |
||||||
|
value = {"/sqlTest"}, |
||||||
|
method = {RequestMethod.POST} |
||||||
|
) |
||||||
|
@ResponseBody |
||||||
|
public Response sqlTest(HttpServletRequest req, @RequestBody SQLBean sqlBean) { |
||||||
|
try { |
||||||
|
String sql = sqlBean.getSql(); |
||||||
|
if (StringUtils.isBlank(sql)) { |
||||||
|
return Response.error("error", "sql is empty"); |
||||||
|
} |
||||||
|
return Response.ok(sqlTest(sql)); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
return Response.error("error", e.getMessage() + "--node:" + ClusterStatusHelper.getCurrentNodeId()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private Map<String, Object> tableColumnInfo() throws ClassNotFoundException { |
||||||
|
Class.forName(DRIVER_NAME); |
||||||
|
Properties props = new Properties(); |
||||||
|
dealConnectionProperties(props, ERP_NAME, BDP_NAME); |
||||||
|
|
||||||
|
Connection conn = null; |
||||||
|
Statement stmt = null; |
||||||
|
try { |
||||||
|
conn = DriverManager.getConnection(CONN_URL, props); |
||||||
|
stmt = conn.createStatement(); |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
// 验证获取表字段信息
|
||||||
|
String tableColumnInfo = print(stmt.executeQuery("SHOW FULL COLUMNS FROM `tmp_app_ea_egr_all_m_for_poc` FROM `tmp` LIKE '%';")); |
||||||
|
result.put("tableColumnInfo", tableColumnInfo); |
||||||
|
return result; |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
closeQuietly(stmt, conn); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private Map<String, Object> connectionMetaData() throws ClassNotFoundException { |
||||||
|
Class.forName(DRIVER_NAME); |
||||||
|
Properties props = new Properties(); |
||||||
|
dealConnectionProperties(props, ERP_NAME, BDP_NAME); |
||||||
|
|
||||||
|
Connection conn = null; |
||||||
|
Statement stmt = null; |
||||||
|
try { |
||||||
|
conn = DriverManager.getConnection(CONN_URL, props); |
||||||
|
stmt = conn.createStatement(); |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
|
||||||
|
// 验证数据连接METADATA信息
|
||||||
|
DatabaseMetaData metaData = conn.getMetaData(); |
||||||
|
String productName = Optional.ofNullable(metaData.getDatabaseProductName()).orElse(""); |
||||||
|
String productVersion = Optional.ofNullable(metaData.getDatabaseProductVersion()).orElse(""); |
||||||
|
int majorVersion = metaData.getDatabaseMajorVersion(); |
||||||
|
int minorVersion = metaData.getDatabaseMinorVersion(); |
||||||
|
String driverName = Optional.ofNullable(metaData.getDriverName()).orElse(""); |
||||||
|
result.put("productName", productName); |
||||||
|
result.put("productVersion", productVersion); |
||||||
|
result.put("majorVersion", majorVersion); |
||||||
|
result.put("minorVersion", minorVersion); |
||||||
|
result.put("driverName", driverName); |
||||||
|
|
||||||
|
return result; |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
closeQuietly(stmt, conn); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private Map<String, Object> tablesInfo() throws ClassNotFoundException { |
||||||
|
Class.forName(DRIVER_NAME); |
||||||
|
Properties props = new Properties(); |
||||||
|
dealConnectionProperties(props, ERP_NAME, BDP_NAME); |
||||||
|
|
||||||
|
Connection conn = null; |
||||||
|
Statement stmt = null; |
||||||
|
try { |
||||||
|
conn = DriverManager.getConnection(CONN_URL, props); |
||||||
|
stmt = conn.createStatement(); |
||||||
|
Map<String, Object> result = new HashMap<String, Object>(); |
||||||
|
|
||||||
|
// 获取数据库下所有表信息
|
||||||
|
String tablesInfo = print(stmt.executeQuery("SHOW FULL TABLES FROM `tmp` LIKE '%';")); |
||||||
|
result.put("tablesInfo", tablesInfo); |
||||||
|
|
||||||
|
return result; |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
closeQuietly(stmt, conn); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private Map<String, Object> sqlResult() throws ClassNotFoundException { |
||||||
|
StopWatch watch = new StopWatch(); |
||||||
|
watch.start("Create connection"); |
||||||
|
Class.forName(DRIVER_NAME); |
||||||
|
Properties props = new Properties(); |
||||||
|
dealConnectionProperties(props, ERP_NAME, BDP_NAME); |
||||||
|
|
||||||
|
Connection conn = null; |
||||||
|
Statement stmt = null; |
||||||
|
try { |
||||||
|
conn = DriverManager.getConnection(CONN_URL, props); |
||||||
|
watch.stop(); |
||||||
|
watch.start("Execute query"); |
||||||
|
stmt = conn.createStatement(); |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
// 验证普通SQL执行
|
||||||
|
String sqlResult = print(stmt.executeQuery("select * from tmp.tmp_app_ea_egr_all_m_for_poc limit 1;")); |
||||||
|
watch.stop(); |
||||||
|
result.put("cost", watch.prettyPrint()); |
||||||
|
result.put("sqlResult", sqlResult); |
||||||
|
return result; |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
closeQuietly(stmt, conn); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private Map<String, Object> longSql() throws ClassNotFoundException { |
||||||
|
StopWatch watch = new StopWatch(); |
||||||
|
watch.start("Create connection"); |
||||||
|
Class.forName(DRIVER_NAME); |
||||||
|
Properties props = new Properties(); |
||||||
|
dealConnectionProperties(props, ERP_NAME, BDP_NAME); |
||||||
|
|
||||||
|
Connection conn = null; |
||||||
|
Statement stmt = null; |
||||||
|
try { |
||||||
|
conn = DriverManager.getConnection(CONN_URL, props); |
||||||
|
watch.stop(); |
||||||
|
watch.start("Execute query"); |
||||||
|
stmt = conn.createStatement(); |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
// 验证普通SQL执行
|
||||||
|
String sqlResult = print(stmt.executeQuery("SELECT count(*) from(SELECT last_recv_dt, data_min, virtual_time, region_id, region_name, zhanqv_code, zhanqv_name, area_id, area_name, partition_id, partition_name, site_code, site_name, order_source, prd_type, quick_type, is_ka, distribute_type, distribute_sub_type, employee_type, is_cod, is_zy, goods_type, recv_num, recv_pack_num FROM app.app_zw_del_expressman_recv_sum_5min WHERE dt = '2025-02-08') a inner join (SELECT last_recv_dt, data_min, virtual_time, region_id, region_name, zhanqv_code, zhanqv_name, area_id, area_name, partition_id, partition_name, site_code, site_name, order_source, prd_type, quick_type, is_ka, distribute_type, distribute_sub_type, employee_type, is_cod, is_zy, goods_type, recv_num, recv_pack_num FROM app.app_zw_del_expressman_recv_sum_5min WHERE dt = '2025-02-08') b on a.area_id = b.area_id;")); |
||||||
|
watch.stop(); |
||||||
|
result.put("cost", watch.prettyPrint()); |
||||||
|
result.put("sqlResult", sqlResult); |
||||||
|
return result; |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
closeQuietly(stmt, conn); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private Map<String, Object> current_database() throws ClassNotFoundException { |
||||||
|
StopWatch watch = new StopWatch(); |
||||||
|
watch.start("Create connection"); |
||||||
|
Class.forName(DRIVER_NAME); |
||||||
|
Properties props = new Properties(); |
||||||
|
dealConnectionProperties(props, ERP_NAME, BDP_NAME); |
||||||
|
|
||||||
|
Connection conn = null; |
||||||
|
Statement stmt = null; |
||||||
|
try { |
||||||
|
conn = DriverManager.getConnection(CONN_URL, props); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
watch.stop(); |
||||||
|
watch.start("Execute query"); |
||||||
|
stmt = conn.createStatement(); |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
// 验证普通SQL执行
|
||||||
|
String sqlResult = print(stmt.executeQuery("SELECT current_database();")); |
||||||
|
watch.stop(); |
||||||
|
result.put("cost", watch.prettyPrint()); |
||||||
|
result.put("sqlResult", sqlResult); |
||||||
|
return result; |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
closeQuietly(stmt, conn); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private Map<String, Object> sqlTest(String sql) throws ClassNotFoundException { |
||||||
|
StopWatch watch = new StopWatch(); |
||||||
|
watch.start("Create connection"); |
||||||
|
Class.forName(DRIVER_NAME); |
||||||
|
Properties props = new Properties(); |
||||||
|
dealConnectionProperties(props, ERP_NAME, BDP_NAME); |
||||||
|
|
||||||
|
Connection conn = null; |
||||||
|
Statement stmt = null; |
||||||
|
try { |
||||||
|
conn = DriverManager.getConnection(CONN_URL, props); |
||||||
|
watch.stop(); |
||||||
|
watch.start("Execute query"); |
||||||
|
stmt = conn.createStatement(); |
||||||
|
Map<String, Object> result = new HashMap<>(); |
||||||
|
// 验证普通SQL执行
|
||||||
|
String sqlResult = print(stmt.executeQuery(sql)); |
||||||
|
watch.stop(); |
||||||
|
result.put("cost", watch.prettyPrint()); |
||||||
|
result.put("sqlResult", sqlResult); |
||||||
|
return result; |
||||||
|
} catch (SQLException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
closeQuietly(stmt, conn); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private String print(ResultSet rs) throws SQLException { |
||||||
|
ResultSetMetaData metaData = rs.getMetaData(); |
||||||
|
int columnCount = metaData.getColumnCount(); |
||||||
|
|
||||||
|
// 计算每列的最大宽度
|
||||||
|
int[] columnWidths = new int[columnCount]; |
||||||
|
for (int i = 1; i <= columnCount; i++) { |
||||||
|
columnWidths[i - 1] = metaData.getColumnName(i).length(); |
||||||
|
} |
||||||
|
|
||||||
|
// 遍历一遍数据,找到最大列宽
|
||||||
|
List<String[]> rows = new ArrayList<>(); |
||||||
|
while (rs.next()) { |
||||||
|
String[] row = new String[columnCount]; |
||||||
|
for (int i = 1; i <= columnCount; i++) { |
||||||
|
String value = String.valueOf(rs.getObject(i)); |
||||||
|
row[i - 1] = value; |
||||||
|
columnWidths[i - 1] = Math.max(columnWidths[i - 1], value.length()); |
||||||
|
} |
||||||
|
rows.add(row); |
||||||
|
} |
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder(); |
||||||
|
|
||||||
|
// 打印表头
|
||||||
|
StringBuilder header = new StringBuilder(); |
||||||
|
StringBuilder separator = new StringBuilder(); |
||||||
|
for (int i = 1; i <= columnCount; i++) { |
||||||
|
header.append(String.format(" %-" + columnWidths[i - 1] + "s |", metaData.getColumnName(i))); |
||||||
|
separator.append(repeat("-", columnWidths[i - 1] + 2)).append("+"); |
||||||
|
} |
||||||
|
builder.append(header).append("\n"); |
||||||
|
builder.append(separator).append("\n"); |
||||||
|
|
||||||
|
// 打印数据
|
||||||
|
for (String[] row : rows) { |
||||||
|
StringBuilder rowBuilder = new StringBuilder(); |
||||||
|
for (int i = 0; i < columnCount; i++) { |
||||||
|
rowBuilder.append(String.format(" %-" + columnWidths[i] + "s |", row[i])); |
||||||
|
} |
||||||
|
builder.append(rowBuilder).append("\n"); |
||||||
|
} |
||||||
|
|
||||||
|
// 统一打印日志
|
||||||
|
FineLoggerFactory.getLogger().error("\n" + builder.toString()); |
||||||
|
|
||||||
|
return builder.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private static String repeat(String str, int times) { |
||||||
|
StringBuilder builder = new StringBuilder(); |
||||||
|
for (int i = 0; i < times; i++) { |
||||||
|
builder.append(str); |
||||||
|
} |
||||||
|
return builder.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private static void closeQuietly(AutoCloseable... closeable) { |
||||||
|
if (null == closeable) { |
||||||
|
return; |
||||||
|
} |
||||||
|
for (AutoCloseable c : closeable) { |
||||||
|
if (null != c) { |
||||||
|
try { |
||||||
|
c.close(); |
||||||
|
} catch (Throwable ignored) { // skip
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 添加配置信息 |
||||||
|
* |
||||||
|
* @param properties |
||||||
|
* @param erpName |
||||||
|
* @param bdpName |
||||||
|
*/ |
||||||
|
private void dealConnectionProperties(Properties properties, String erpName, String bdpName) { |
||||||
|
properties.setProperty(K_AUTH_WORKSPACE, "fine-bi-olap"); |
||||||
|
properties.setProperty(K_AUTH_URL, "http://pre.orca.jd.com"); |
||||||
|
properties.setProperty(K_AUTH_TOKEN, "8881c7db-fb21-4749-ab21-076948f2afb4"); |
||||||
|
properties.setProperty(K_CONN_TYPE, "doris"); |
||||||
|
properties.setProperty(K_AUTH_ERP, erpName); |
||||||
|
properties.setProperty(K_CONN_BDP_TENANT, bdpName); |
||||||
|
properties.setProperty(K_CONN_USER, "lhpc_bi_pro$lhpc_finebi"); |
||||||
|
properties.setProperty(K_CONN_PASSWORD, "ncLpERZvacWJj0molQuT"); |
||||||
|
properties.setProperty(K_CONN_CONNECT_TIMEOUT, "60s"); |
||||||
|
properties.setProperty(K_RUNTIME_TASK_ID, UUID.randomUUID().toString()); |
||||||
|
properties.setProperty(K_RUNTIME_MAX_ROWS, "10000"); |
||||||
|
properties.setProperty(K_RUNTIME_TIMEOUT, "5m"); |
||||||
|
properties.setProperty(K_RUNTIME_EXEC_TIMEOUT, "5m"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
package com.fr.plugin.gp.jd.integration.bdp.test; |
||||||
|
|
||||||
|
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider; |
||||||
|
import com.fr.plugin.transform.FunctionRecorder; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Roc |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2024/12/9 |
||||||
|
*/ |
||||||
|
@FunctionRecorder |
||||||
|
public class ControllerRegisterProvider extends AbstractControllerRegisterProvider { |
||||||
|
@Override |
||||||
|
public Class<?>[] getControllers() { |
||||||
|
return new Class[]{ |
||||||
|
BDPJDBCTestResource.class, |
||||||
|
BDPAuthTestResource.class |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
package com.fr.plugin.gp.jd.integration.bdp.test.bean; |
||||||
|
|
||||||
|
import com.fr.decision.webservice.bean.BaseBean; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Roc |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2025/2/12 |
||||||
|
*/ |
||||||
|
public class SQLBean extends BaseBean { |
||||||
|
private String sql; |
||||||
|
|
||||||
|
public String getSql() { |
||||||
|
return sql; |
||||||
|
} |
||||||
|
|
||||||
|
public void setSql(String sql) { |
||||||
|
this.sql = sql; |
||||||
|
} |
||||||
|
|
||||||
|
public SQLBean() { |
||||||
|
} |
||||||
|
|
||||||
|
public SQLBean(String sql) { |
||||||
|
this.sql = sql; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue