Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
3316e2db
Commit
3316e2db
authored
Jul 03, 2020
by
张云飞
Browse files
Options
Browse Files
Download
Plain Diff
zyf
parents
be8b56b8
0b3ecdc0
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
211 additions
and
122 deletions
+211
-122
center-taskexecutor/app/base/utils/GT.pdf
+0
-0
center-taskexecutor/app/base/utils/GT.xlsx
+0
-0
center-taskexecutor/app/base/utils/ITQ.pdf
+0
-0
center-taskexecutor/app/base/utils/ITY.pdf
+0
-0
center-taskexecutor/app/base/utils/ST.pdf
+0
-0
center-taskexecutor/app/base/utils/execClient.js
+211
-94
center-taskexecutor/app/base/utils/test.js
+0
-28
center-taskexecutor/app/base/utils/tmpl.zip
+0
-0
center-taskexecutor/app/base/utils/tmpl2.zip
+0
-0
No files found.
center-taskexecutor/app/base/utils/GT.pdf
deleted
100644 → 0
View file @
be8b56b8
File deleted
center-taskexecutor/app/base/utils/GT.xlsx
deleted
100644 → 0
View file @
be8b56b8
File deleted
center-taskexecutor/app/base/utils/ITQ.pdf
deleted
100644 → 0
View file @
be8b56b8
File deleted
center-taskexecutor/app/base/utils/ITY.pdf
deleted
100644 → 0
View file @
be8b56b8
File deleted
center-taskexecutor/app/base/utils/ST.pdf
deleted
100644 → 0
View file @
be8b56b8
File deleted
center-taskexecutor/app/base/utils/execClient.js
View file @
3316e2db
var
childproc
=
require
(
'child_process'
);
const
util
=
require
(
'util'
);
const
exec
=
util
.
promisify
(
require
(
'child_process'
).
exec
);
class
ExecClient
{
constructor
()
{
this
.
cmdPostPattern
=
"curl -k -H 'Content-type: application/json' -d '{data}' {url}"
;
this
.
cmdGetPattern
=
"curl -G -X GET '{url}'"
;
this
.
cmdPostPattern3
=
"curl -k -H 'Content-type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJvcnpaWmhXRXBKNVVFZzRZUU5uUmlyVEJXa1FQbnZ6UyIsImlhdCI6MTU5MjcwOTYzNn0.TWk_F6Tz3fRMqspoG24VSt5RiC4ldFembFYcLcAbowE' -H 'XAPPKEY: 647a68c9-da01-40d3-9763-1ffa0f64cf3f' -d '{data}' {url}"
;
}
async
exec
(
cmd
)
{
//await后面表达式返回的promise对象,是then的语法糖,await返回then函数的返回值
//异常需要try/catch自己捕获或外部catch捕获
const
{
stdout
,
stderr
}
=
await
exec
(
cmd
);
return
{
stdout
,
stderr
};
}
async
exec2
(
cmd
)
{
return
exec
(
cmd
,
{
encoding
:
"base64"
});
}
FetchPostCmd
(
subData
,
url
)
{
var
data
=
JSON
.
stringify
(
subData
);
var
cmd
=
this
.
cmdPostPattern
.
replace
(
/
\{
data
\}
/g
,
data
).
replace
(
/
\{
url
\}
/g
,
url
);
console
.
log
(
cmd
);
return
cmd
;
}
async
execPost
(
subData
,
url
)
{
let
cmd
=
this
.
FetchPostCmd
(
subData
,
url
);
var
result
=
await
this
.
exec
(
cmd
);
return
result
;
}
FetchPostCmd3
(
subData
,
url
)
{
var
data
=
JSON
.
stringify
(
subData
);
var
cmd
=
this
.
cmdPostPattern3
.
replace
(
/
\{
data
\}
/g
,
data
).
replace
(
/
\{
url
\}
/g
,
url
);
console
.
log
(
cmd
);
return
cmd
;
}
async
execPost3
(
subData
,
url
)
{
let
cmd
=
this
.
FetchPostCmd3
(
subData
,
url
);
var
result
=
await
this
.
exec
(
cmd
);
return
result
;
}
async
execPost2
(
subData
,
url
)
{
let
cmd
=
this
.
FetchPostCmd
(
subData
,
url
);
var
result
=
await
this
.
exec2
(
cmd
);
return
result
;
}
FetchGetCmd
(
subData
,
url
)
{
var
cmd
=
this
.
cmdGetPattern
.
replace
(
/
\{
data
\}
/g
,
subData
).
replace
(
/
\{
url
\}
/g
,
url
);
console
.
log
(
cmd
);
return
cmd
;
}
async
execGet
(
subData
,
url
)
{
let
cmd
=
this
.
FetchGetCmd
(
subData
,
url
);
console
.
log
(
cmd
);
var
result
=
await
this
.
exec
(
cmd
);
return
result
;
}
async
execGet2
(
subData
,
url
)
{
let
cmd
=
this
.
FetchGetCmd
(
subData
,
url
);
console
.
log
(
cmd
);
var
result
=
await
this
.
exec2
(
cmd
);
return
result
;
}
async
execGetTimeOut
(
subData
,
url
,
timeOut
=
5000
)
{
//timeOut,单位是毫秒
let
cmd
=
this
.
FetchGetCmd
(
subData
,
url
);
var
options
=
{
timeout
:
timeOut
,
};
const
{
stdout
,
stderr
}
=
await
exec
(
cmd
,
options
);
return
{
stdout
,
stderr
};
}
}
module
.
exports
=
ExecClient
;
// var x=new RestClient();
// x.execGet("","http://www.163.com").then(function(r){
// console.log(r.stdout);
// console.log(r.stderr);
// });
var
childproc
=
require
(
'child_process'
);
const
system
=
require
(
"../system"
);
const
util
=
require
(
'util'
);
const
exec
=
util
.
promisify
(
require
(
'child_process'
).
exec
);
const
settings
=
require
(
"../../../app/config/settings"
);
const
axios
=
require
(
'axios'
);
const
moment
=
require
(
'moment'
);
const
uuid
=
require
(
'uuid'
);
class
ExecClient
{
constructor
()
{
this
.
cmdGetPattern
=
"curl -G -X GET '{url}'"
;
this
.
cmdPostPattern
=
"curl -k -H 'Content-type: application/json' -d '{data}' {url}"
;
// this.cmdPushDataPostPattern = "curl -k -H 'Content-type: application/json' -H 'token:{tk}' -H 'request-id:{requestId}' -d '{data}' {url}";
}
/**
* 带超时时间的post请求
* @param {*} execFile 执行文件
* @param {*} params 请求数据-json格式
* @param {*} url 请求地址
* @param {*} ContentType 请求头类型,默认application/json
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} timeOut 超时时间设置,单位秒
*/
async
execPostTimeOutByBusiness
(
execFile
,
params
,
url
,
ContentType
,
headData
,
timeOut
=
5000
)
{
var
rtn
=
null
;
var
reqResult
=
null
;
try
{
//方式二
rtn
=
await
this
.
execPostTimeOut
(
params
,
url
,
ContentType
,
headData
,
timeOut
);
if
(
!
rtn
||
!
rtn
.
stdout
)
{
reqResult
=
system
.
getResult
(
null
,
"execPostTimeOut data is empty"
);
}
else
{
var
result
=
JSON
.
parse
(
rtn
.
stdout
);
reqResult
=
system
.
getResultSuccess
(
result
);
}
reqResult
.
requestId
=
uuid
.
v1
();
return
reqResult
;
}
catch
(
error
)
{
var
stackStr
=
error
.
stack
?
error
.
stack
:
JSON
.
stringify
(
error
);
console
.
log
(
stackStr
,
".....execPostTimeOutByBusiness........."
);
reqResult
=
system
.
getResultFail
(
-
200
,
execFile
+
"执行execPostByTimeOut存在异常"
);
reqResult
.
requestId
=
uuid
.
v1
();
return
reqResult
;
}
}
/**
* get请求
* @param {*} params 提交的数据-格式JSON
* @param {*} url
* @param {*} headData 请求信息,JSON格式
*/
async
execGet
(
params
,
url
,
headData
)
{
let
cmd
=
this
.
FetchGetCmd
(
params
,
url
,
headData
);
var
result
=
await
this
.
exec
(
cmd
);
return
result
;
}
/**
*
* @param {*} params 提交的数据JSON格式
* @param {*} url
* @param {*} headData 请求信息,JSON格式
* @param {*} timeOut 超时时间
*/
async
execGetTimeOut
(
params
,
url
,
headData
,
timeOut
=
5000
)
{
//timeOut,单位是毫秒
let
cmd
=
this
.
FetchGetCmd
(
params
,
url
,
headData
);
var
options
=
{
timeout
:
timeOut
,
};
const
{
stdout
,
stderr
}
=
await
exec
(
cmd
,
options
);
return
{
stdout
,
stderr
};
}
/**
* 带超时时间的post请求
* @param {*} params 请求数据-json格式
* @param {*} url 请求地址
* @param {*} ContentType 请求头类型,默认application/json
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
*/
async
execPost
(
params
,
url
,
ContentType
,
headData
)
{
if
(
!
ContentType
)
{
ContentType
=
"application/json"
;
}
let
cmd
=
this
.
FetchPostCmd
(
params
,
url
,
ContentType
,
headData
);
var
options
=
{
maxBuffer
:
1024
*
1024
*
15
};
var
result
=
await
this
.
exec
(
cmd
,
options
,
headData
);
return
result
;
}
/**
* 带超时时间的post请求
* @param {*} params 请求数据-json格式
* @param {*} url 请求地址
* @param {*} ContentType 请求头类型,默认application/json
* @param {*} headData 请求头内容-json格式,如:请求头中传递token,格式:{token:"9098902q849q0434q09439"}
* @param {*} timeOut 超时时间设置,单位秒
*/
async
execPostTimeOut
(
params
,
url
,
ContentType
,
headData
,
timeOut
=
5000
)
{
if
(
!
ContentType
)
{
ContentType
=
"application/json"
;
}
let
cmd
=
this
.
FetchPostCmd
(
params
,
url
,
ContentType
,
headData
);
var
options
=
{
timeout
:
timeOut
,
maxBuffer
:
1024
*
1024
*
15
};
var
result
=
await
this
.
exec
(
cmd
,
options
);
return
result
;
}
//--------------------------------------------------辅助方法start-----------------
async
exec
(
cmd
)
{
//await后面表达式返回的promise对象,是then的语法糖,await返回then函数的返回值
//异常需要try/catch自己捕获或外部catch捕获
const
{
stdout
,
stderr
}
=
await
exec
(
cmd
);
return
{
stdout
,
stderr
};
}
FetchGetCmd
(
params
,
url
,
headData
)
{
var
cmd
=
this
.
cmdGetPattern
.
replace
(
/
\{
data
\}
/g
,
params
).
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
}
FetchPostCmd
(
params
,
url
,
ContentType
,
headData
)
{
if
(
!
ContentType
)
{
ContentType
=
"application/json"
;
}
var
data
=
null
;
if
(
typeof
params
===
'object'
)
{
// 声明cache变量,便于匹配是否有循环引用的情况
var
cache
=
[];
data
=
JSON
.
stringify
(
params
,
function
(
key
,
value
)
{
if
(
typeof
value
===
'object'
&&
value
!==
null
)
{
if
(
cache
.
indexOf
(
value
)
!==
-
1
)
{
// 移除
return
;
}
// 收集所有的值
cache
.
push
(
value
);
}
return
value
;
});
cache
=
null
;
// 清空变量,便于垃圾回收机制回收
}
else
{
data
=
params
;
}
var
cmdStr
=
"curl -k -H 'Content-type:"
+
ContentType
+
"'"
;
if
(
headData
)
{
var
headDataKeys
=
Object
.
keys
(
headData
);
if
(
headDataKeys
.
length
>
0
)
{
for
(
let
index
=
0
;
index
<
headDataKeys
.
length
;
index
++
)
{
const
indexKey
=
headDataKeys
[
index
];
var
headValue
=
headData
[
indexKey
];
if
(
indexKey
&&
headValue
)
{
cmdStr
=
cmdStr
+
" -H '"
+
indexKey
+
":"
+
headValue
+
"'"
;
}
}
}
}
cmdStr
=
cmdStr
+
" -d '"
+
data
+
"' "
+
url
;
console
.
log
(
cmdStr
,
":cmdStr................."
);
return
cmdStr
;
}
/**
* 返回20位业务订单号
* @param {*} prefix 业务前缀
*/
async
getBusUid
(
prefix
)
{
prefix
=
(
prefix
||
""
);
if
(
prefix
)
{
prefix
=
prefix
.
toUpperCase
();
}
var
prefixlength
=
prefix
.
length
;
var
subLen
=
8
-
prefixlength
;
var
uidStr
=
""
;
if
(
subLen
>
0
)
{
uidStr
=
await
this
.
getUidInfo
(
subLen
,
60
);
}
var
timStr
=
moment
().
format
(
"YYYYMMDDHHmm"
);
return
prefix
+
timStr
+
uidStr
;
}
/**
* 返回指定长度的字符串
* @param {*} len 返回长度
* @param {*} radix 参与计算的长度,最大为62
*/
async
getUidInfo
(
len
,
radix
)
{
var
chars
=
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
.
split
(
''
);
//长度62,到yz长度为长36
var
uuid
=
[],
i
;
radix
=
radix
||
chars
.
length
;
if
(
len
)
{
for
(
i
=
0
;
i
<
len
;
i
++
)
uuid
[
i
]
=
chars
[
0
|
Math
.
random
()
*
radix
];
}
else
{
var
r
;
uuid
[
8
]
=
uuid
[
13
]
=
uuid
[
18
]
=
uuid
[
23
]
=
'-'
;
uuid
[
14
]
=
'4'
;
for
(
i
=
0
;
i
<
36
;
i
++
)
{
if
(
!
uuid
[
i
])
{
r
=
0
|
Math
.
random
()
*
16
;
uuid
[
i
]
=
chars
[(
i
==
19
)
?
(
r
&
0x3
)
|
0x8
:
r
];
}
}
}
return
uuid
.
join
(
''
);
}
//--------------------------------------------------辅助方法end-----------------
}
module
.
exports
=
ExecClient
;
center-taskexecutor/app/base/utils/test.js
deleted
100644 → 0
View file @
be8b56b8
// var excel = require('exceljs');
// async function readxls(path) {
// var promise = new Promise((resv, rej) => {
// var workbook = new excel.Workbook();
// workbook.properties.date1904 = true;
// workbook.xlsx.readFile(path)
// .then(function () {
// return resv(workbook);
// }).catch(function (e) {
// return rej(e);
// });
// });
// return promise;
// }
// (async ()=>{
// var wb= await readxls("/tmp/f2b9b12ea5bf4bc79568acc5aa907f83.xlsx");
// var sheet = wb.getWorksheet(1);
// // sheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
// // if(rowNumber>=10 && rowNumber<=10){
// // row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
// // if(colNumber==28){
// // var sval=cell.value?(typeof cell.value=="object"?cell.value.result:cell.value):"0";
// // console.log(sval);
// // }
// // });
// // }
// // });
// })()
center-taskexecutor/app/base/utils/tmpl.zip
deleted
100644 → 0
View file @
be8b56b8
File deleted
center-taskexecutor/app/base/utils/tmpl2.zip
deleted
100644 → 0
View file @
be8b56b8
File deleted
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment