Skip to content

Commit 13e4551

Browse files
committed
Java:MultiDataSource 更新 APIAuto
1 parent 65dd817 commit 13e4551

File tree

4 files changed

+84
-48
lines changed

4 files changed

+84
-48
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/apijson/CodeUtil.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6420,6 +6420,8 @@ var CodeUtil = {
64206420
return isWarning ? ' ' : '...';
64216421
}
64226422

6423+
var isTSQL = ['ORACLE', 'DAMENG'].indexOf(database) >= 0;
6424+
64236425
var item;
64246426

64256427
var table;
@@ -6429,20 +6431,20 @@ var CodeUtil = {
64296431
item = tableList[i];
64306432

64316433
//Table
6432-
table = item == null ? null : (database != 'SQLSERVER' ? item.Table : item.SysTable);
6434+
table = item == null ? null : (isTSQL ? item.AllTable : (database != 'SQLSERVER' ? item.Table : item.SysTable));
64336435
if (table == null || tableName != CodeUtil.getModelName(table.table_name)) {
64346436
continue;
64356437
}
64366438
log('getDoc [] for i=' + i + ': table = \n' + format(JSON.stringify(table)));
64376439

64386440
if (StringUtil.isEmpty(columnName)) {
64396441
return /*没必要,常识,太占地方,而且自动生成代码就有 CodeUtil.getType4Object(language) + ', ' + */ (
6440-
database == 'POSTGRESQL'
6442+
isTSQL ? (item.AllTableComment || {}).table_comment : (database == 'POSTGRESQL'
64416443
? (item.PgClass || {}).table_comment
64426444
: (database == 'SQLSERVER'
64436445
? (item.ExtendedProperty || {}).table_comment
64446446
: table.table_comment
6445-
)
6447+
))
64466448
);
64476449
}
64486450

@@ -6666,7 +6668,7 @@ var CodeUtil = {
66666668
var name;
66676669
var columnNames = []
66686670
for (var j = 0; j < columnList.length; j++) {
6669-
column = (columnList[j] || {}).Column;
6671+
column = (columnList[j] || {})[isTSQL ? 'AllColumn' : 'Column'];
66706672
name = column == null ? null : column.column_name;
66716673
if (name == null || key != name) {
66726674
if (name != null) {
@@ -6679,12 +6681,12 @@ var CodeUtil = {
66796681
+ (fun.length <= 0 ? '' : fun + ' < ')
66806682
+ (logic.length <= 0 ? '' : logic + ' < ');
66816683

6682-
var o = database == 'POSTGRESQL'
6684+
var o = isTSQL ? (columnList[j] || {}).AllColumnComment : (database == 'POSTGRESQL'
66836685
? (columnList[j] || {}).PgAttribute
66846686
: (database == 'SQLSERVER'
66856687
? (columnList[j] || {}).ExtendedProperty
66866688
: column
6687-
);
6689+
));
66886690

66896691
column.column_type = CodeUtil.getColumnType(column, database);
66906692
var t = CodeUtil.getType4Language(language, column.column_type, true);

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/apijson/JSONResponse.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if (typeof window == 'undefined') {
2222
eval(`
2323
var StringUtil = require("./StringUtil");
2424
var JSONObject = require("./JSONObject");
25+
var CodeUtil = require("./CodeUtil");
2526
`)
2627
} catch (e) {
2728
console.log(e)

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/js/main.js

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
(function () {
3-
const DEBUG = true
3+
const DEBUG = false // true
44
const IS_NODE = typeof window == 'undefined'
55
const IS_BROWSER = typeof window == 'object'
66

@@ -793,7 +793,7 @@
793793
language: CodeUtil.LANGUAGE_KOTLIN,
794794
header: {},
795795
page: 0,
796-
count: 100,
796+
count: 50,
797797
search: '',
798798
testCasePage: 0,
799799
testCaseCount: 50,
@@ -3050,11 +3050,11 @@
30503050
var testCases = this.testCases
30513051
var allCount = testCases == null ? 0 : testCases.length
30523052
App.allCount = allCount
3053-
if (allCount > 0) {
3053+
if (IS_BROWSER && allCount > 0) {
30543054
var accountIndex = (this.accounts[this.currentAccountIndex] || {}).isLoggedIn ? this.currentAccountIndex : -1
30553055
this.currentAccountIndex = accountIndex //解决 onTestResponse 用 -1 存进去, handleTest 用 currentAccountIndex 取出来为空
30563056

3057-
var tests = this.tests[String(accountIndex)] || {}
3057+
var tests = this.tests[String(accountIndex)]
30583058
if (tests != null && JSONObject.isEmpty(tests) != true) {
30593059
for (var i = 0; i < allCount; i++) {
30603060
var item = testCases[i]
@@ -3097,7 +3097,8 @@
30973097
'standard{}': this.isMLEnabled ? (this.database == 'SQLSERVER' ? 'len(standard)>2' : 'length(standard)>2') : null //用 MySQL 5.6 '@having': this.isMLEnabled ? 'json_length(standard)>0' : null
30983098
}
30993099
},
3100-
'@role': IS_NODE ? null : 'LOGIN'
3100+
'@role': IS_NODE ? null : 'LOGIN',
3101+
key: IS_NODE ? this.key : undefined // 突破常规查询数量限制
31013102
}
31023103

31033104
if (IS_BROWSER) {
@@ -3193,7 +3194,8 @@
31933194
'@order': 'date-'
31943195
}
31953196
}
3196-
}
3197+
},
3198+
key: IS_NODE ? this.key : undefined // 突破常规查询数量限制
31973199
}
31983200

31993201
if (IS_BROWSER) {
@@ -3328,12 +3330,15 @@
33283330

33293331
const req = {
33303332
type: 0, // 登录方式,非必须 0-密码 1-验证码
3333+
// asDBAccount: ! isAdminOperation, // 直接 /execute 接口传 account, password
33313334
phone: this.account,
33323335
password: this.password,
33333336
version: 1, // 全局默认版本号,非必须
33343337
remember: vRemember.checked,
33353338
format: false,
3336-
defaults: isAdminOperation ? undefined : {
3339+
defaults: isAdminOperation ? {
3340+
key: IS_NODE ? this.key : undefined // 突破常规查询数量限制
3341+
} : {
33373342
'@database': StringUtil.isEmpty(this.database, true) ? undefined : this.database,
33383343
'@schema': StringUtil.isEmpty(this.schema, true) ? undefined : this.schema
33393344
}
@@ -3350,7 +3355,7 @@
33503355
})
33513356
}
33523357
else {
3353-
if (callback == null) {
3358+
if (IS_BROWSER && callback == null) {
33543359
var item
33553360
for (var i in this.accounts) {
33563361
item = this.accounts[i]
@@ -3697,7 +3702,6 @@
36973702
var w = isSingle || this.isEditResponse ? '' : StringUtil.trim(CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m, this.database, this.language, this.isEditResponse != true, standardObj, null, true, isAPIJSONRouter));
36983703
var c = isSingle ? '' : StringUtil.trim(CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m, this.database, this.language, this.isEditResponse != true, standardObj, null, null, isAPIJSONRouter));
36993704

3700-
37013705
//TODO 统计行数,补全到一致 vInput.value.lineNumbers
37023706
if (isSingle != true) {
37033707
if (afterObj.tag == null) {
@@ -4010,7 +4014,7 @@
40104014

40114015

40124016
if (IS_NODE) {
4013-
console.log('req = ' + JSON.stringify(req, null, ' '))
4017+
log('req = ' + JSON.stringify(req, null, ' '))
40144018
// 低版本 node 报错 cannot find module 'node:url' ,高版本报错 TypeError: axiosCookieJarSupport is not a function
40154019
// const axiosCookieJarSupport = require('axios-cookiejar-support').default;
40164020
// const tough = require('tough-cookie');
@@ -4115,10 +4119,12 @@
41154119
if (res == null) {
41164120
res = {}
41174121
}
4118-
log('onResponse url = ' + url + '\nerr = ' + err + '\nreq = \n'
4119-
+ (res.request == null || res.request.data == null ? 'null' : JSON.stringify(res.request.data))
4120-
+ '\n\nres = \n' + (res.data == null ? 'null' : JSON.stringify(res.data))
4121-
)
4122+
if (DEBUG) {
4123+
log('onResponse url = ' + url + '\nerr = ' + err + '\nreq = \n'
4124+
+ (res.request == null || res.request.data == null ? 'null' : JSON.stringify(res.request.data))
4125+
+ '\n\nres = \n' + (res.data == null ? 'null' : JSON.stringify(res.data))
4126+
)
4127+
}
41224128

41234129
if (err != null) {
41244130
if (IS_BROWSER) {
@@ -5352,6 +5358,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
53525358
}
53535359

53545360
App.compareResponse(allCount, list, index, item, res.data, true, App.currentAccountIndex, false, err, null, isCross, callback)
5361+
return true
53555362
})
53565363
}
53575364
}
@@ -5477,7 +5484,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
54775484
config: vRandom.value
54785485
}
54795486
},
5480-
this.type, this.getUrl(), this.getRequest(vInput.value, {}), this.getHeader(vHeader.value), callback
5487+
this.type, this.getUrl(), this.getRequest(vInput.value, {}), this.getHeader(vHeader.value), false, callback
54815488
)
54825489
}
54835490
catch (e) {
@@ -5999,8 +6006,12 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
59996006
var bdt = tr.duration || 0
60006007
it.durationBeforeShowStr = bdt <= 0 ? '' : (bdt < 1000 ? bdt + 'ms' : (bdt < 1000*60 ? (bdt/1000).toFixed(1) + 's' : (bdt <= 1000*60*60 ? (bdt/1000/60).toFixed(1) + 'm' : '>1h')))
60016008
try {
6002-
var durationInfo = response['time:start|duration|end|parse|sql']
6009+
var durationInfo = response == null ? null : response['time:start|duration|end|parse|sql']
60036010
it.durationInfo = durationInfo
6011+
if (durationInfo == null) {
6012+
throw new Error("response['time:start|duration|end|parse|sql'] is null!");
6013+
}
6014+
60046015
var di = durationInfo.substring(durationInfo.indexOf('\|') + 1)
60056016
it.duration = di.substring(0, di.indexOf('\|') || di.length) || 0
60066017
var dt = + it.duration
@@ -6014,7 +6025,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
60146025
: (dt > max ? '有点慢:比以往 [' + min + 'ms, ' + max + 'ms] 最慢还更慢' : '正常:在以往 [' + min + 'ms, ' + max + 'ms] 最快和最慢之间')))
60156026
}
60166027
catch (e) {
6017-
log(e)
6028+
// log(e)
60186029
it.durationShowStr = it.durationShowStr || it.duration
60196030
it.durationHint = it.durationHint || '最外层缺少字段 "time:start|duration|end|parse|sql",无法对比耗时'
60206031
}
@@ -6142,8 +6153,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
61426153
// this.showTestCase(true)
61436154

61446155
if (doneCount >= allCount) { // 导致不继续测试 App.doneCount == allCount) {
6145-
if (callback != null) {
6146-
callback(isRandom, allCount)
6156+
if (callback != null && callback(isRandom, allCount)) {
61476157
return
61486158
}
61496159

@@ -6154,7 +6164,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
61546164
if (isRandom != true && deepAllCount > 0) { // 自动给非 红色 报错的接口跑参数注入
61556165
App.deepDoneCount = 0;
61566166
this.startRandomTest4Doc(list, this.toTestDocIndexes, 0, deepAllCount, accountIndex, isCross)
6157-
} else if (isCross && doneCount == allCount) {
6167+
} else if (isCross && doneCount == allCount && accountIndex <= this.accounts.length) {
61586168
this.test(false, accountIndex + 1, isCross)
61596169
}
61606170
}
@@ -6164,8 +6174,9 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
61646174
const accInd = accountIndex
61656175
var callback = function (isRandom, allCount) {
61666176
if (App.randomDoneCount < App.randomAllCount) {
6167-
return
6177+
return true
61686178
}
6179+
61696180
App.randomDoneCount = 0
61706181
// App.randomAllCount = 0
61716182

@@ -6186,7 +6197,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
61866197
if (deepDoneCount < deepAllCount) {
61876198
setTimeout(function () {
61886199
App.startRandomTest4Doc(list, indexes, position + 1, deepAllCount, accInd, isCross)
6189-
}, IS_NODE ? 1000 : 1000)
6200+
}, IS_NODE ? 200 : 1000)
61906201
} else {
61916202
App.testRandomProcess = ''
61926203
if (isCross) {
@@ -6202,17 +6213,21 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
62026213
}
62036214
}
62046215
}
6205-
}, IS_NODE ? 1000 : 1000)
6216+
}, IS_NODE ? 200 : 1000)
6217+
6218+
return true
62066219
}
62076220

62086221
try {
62096222
var index = indexes[position]
62106223
var it = list[index] || {}
62116224

6212-
try {
6213-
document.getElementById('docItem' + index).scrollIntoView()
6214-
} catch (e) {
6215-
console.log(e)
6225+
if (IS_BROWSER) {
6226+
try {
6227+
document.getElementById('docItem' + index).scrollIntoView()
6228+
} catch (e) {
6229+
console.log(e)
6230+
}
62166231
}
62176232

62186233
this.restoreRemote(index, it, false)
@@ -6705,7 +6720,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
67056720
this.$refs[(isRandom ? (toId <= 0 ? 'testRandomResult' : 'testRandomSubResult') : 'testResult') + (isDuration ? 'Duration' : '') + 'Buttons'][index].setAttribute('data-hint', h || '');
67066721
},
67076722

6708-
handleTestArg(hasTestArg, rawReq, delayTime, callback) {
6723+
handleTestArg: function(hasTestArg, rawReq, delayTime, callback) {
67096724
if (hasTestArg && IS_BROWSER) {
67106725
vUrlComment.value = ""
67116726
vComment.value = ""
@@ -6742,7 +6757,6 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
67426757

67436758
autoTest: function(callback, delayTime, isTest, rawReq, setting) {
67446759
this.autoTestCallback = callback
6745-
this.currentAccountIndex = -1
67466760

67476761
if (delayTime == null) {
67486762
delayTime = 0
@@ -6773,9 +6787,9 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
67736787
isRandomSubListShow: false,
67746788
isMLEnabled: true,
67756789
isCrossEnabled: true,
6776-
testCaseCount: 100,
6790+
// testCaseCount: 100,
67776791
testCasePage: 0,
6778-
randomCount: 100,
6792+
// randomCount: 100,
67796793
randomPage: 0,
67806794
}
67816795
}
@@ -6789,11 +6803,15 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
67896803
this.isRandomSubListShow = setting.isRandomSubListShow
67906804
this.isMLEnabled = setting.isMLEnabled
67916805
this.isCrossEnabled = setting.isCrossEnabled
6792-
this.testCaseCount = setting.testCaseCount
6806+
// this.testCaseCount = setting.testCaseCount
67936807
this.testCasePage = setting.testCasePage
6794-
this.randomCount = setting.randomCount
6808+
// this.randomCount = setting.randomCount
67956809
this.randomPage = setting.randomPage
6796-
this.server = this.getBaseUrl()
6810+
this.server = 'http://localhost:8080' // this.getBaseUrl()
6811+
6812+
// if (this.isCrossEnabled) {
6813+
// this.currentAccountIndex = -1
6814+
// }
67976815

67986816
this.login(true, function (url, res, err) {
67996817
if (setting.isRandomShow && setting.isRandomListShow) {
@@ -6823,6 +6841,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
68236841

68246842
App.showTestCase(true, setting.isLocalShow, function (url, res, err) {
68256843
App.onTestCaseListResponse(IS_BROWSER, url, res, err)
6844+
App.isTestCaseShow = true
68266845
App.handleTestArg(isTest, rawReq, delayTime, callback)
68276846
})
68286847
}
@@ -7135,12 +7154,12 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
71357154
}
71367155
else {
71377156
var data = App.data
7138-
if (data instanceof Object && data instanceof Array == false) {
7157+
if (data instanceof Object && (data instanceof Array == false)) {
71397158
App = Object.assign(App, data)
71407159
}
71417160

71427161
var methods = App.methods
7143-
if (methods instanceof Object && methods instanceof Array == false) {
7162+
if (methods instanceof Object && (methods instanceof Array == false)) {
71447163
App = Object.assign(App, methods)
71457164
}
71467165

0 commit comments

Comments
 (0)