Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
方斌
51business
Commits
e7f32ce3
Commit
e7f32ce3
authored
Aug 21, 2019
by
李尚科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
huayuan paas callOut fix
parent
daef6bc3
Pipeline
#12602
passed with stage
in 24 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
47 deletions
+139
-47
home.js
app/controller/home.js
+115
-28
HuaYunPaas.js
app/schedule/HuaYunPaas.js
+24
-19
No files found.
app/controller/home.js
View file @
e7f32ce3
...
...
@@ -22,8 +22,13 @@ class HomeController extends Controller {
async
getAccessToken
()
{
const
{
ctx
}
=
this
;
const
clientId
=
'961a170e-f939-4189-9163-c4c39051b586'
;
const
clientScr
=
'53ed566c-72b8-4ebf-b0bb-78147623be71'
;
// const clientId = '961a170e-f939-4189-9163-c4c39051b586';
// const clientScr = '53ed566c-72b8-4ebf-b0bb-78147623be71';
const
clientId
=
'c5e1bb68-207d-4164-852d-c206711dd431'
;
const
clientScr
=
'6c9836c1-38ec-44db-8ef5-0f55b7825276'
;
const
url
=
'http://221.194.132.83:7780/paas/accreditation'
;
const
result
=
await
ctx
.
helper
.
send_request
(
url
,
{
clientId
,
clientScr
});
const
ret
=
result
.
data
;
...
...
@@ -71,6 +76,43 @@ class HomeController extends Controller {
}
format_callout
(
data
)
{
if
(
!
Array
.
isArray
(
data
)
||
data
.
length
===
0
)
{
return
[];
}
// console.info(data);
const
ret
=
[];
const
time
=
moment
().
format
(
'YYYY-MM-DD HH:mm:ss'
);
data
.
forEach
(
item
=>
{
ret
.
push
({
session_id
:
item
.
sessionId
,
start_time
:
item
.
startTime
,
end_time
:
item
.
endTime
,
remote_url
:
item
.
remoteUrl
,
local_url
:
item
.
localUrl
,
duretion
:
item
.
duretion
,
end_type
:
item
.
end_type
,
agent_id
:
item
.
agentId
,
call_type
:
item
.
call_Type
,
r_start_time
:
item
.
r_startTime
,
r_end_time
:
item
.
r_endTime
,
path
:
item
.
path
,
c_ivr_key
:
item
.
cIvrKey
,
record_nama
:
item
.
record_Nama
,
created_at
:
time
,
});
});
for
(
let
i
in
data
)
{
// const item = data[i];
}
return
ret
;
}
async
callIn
(
accessToken
)
{
const
{
ctx
}
=
this
;
...
...
@@ -135,7 +177,7 @@ class HomeController extends Controller {
let
start_time
=
'2019-01-01 00:00:00'
;
let
end_time
=
'2019-01-30 23:59:59'
;
cons
t
start
=
0
;
le
t
start
=
0
;
const
limit
=
10000
;
const
now_time
=
moment
().
format
(
'YYYY-MM-DD HH:mm:ss'
);
...
...
@@ -149,37 +191,77 @@ class HomeController extends Controller {
break
;
}
const
result
=
await
ctx
.
curl
(
url
,
{
method
:
'POST'
,
contentType
:
'json'
,
dataType
:
'json'
,
timing
:
true
,
timeout
:
300000
,
data
:
{
start_time
,
end_time
,
start
,
limit
}
});
const
ret
=
result
.
data
;
if
(
ret
.
status
!=
0
||
!
ret
.
message
||
ret
.
count
==
0
)
{
continue
;
}
const
message
=
ret
.
message
;
const
list
=
message
.
data
;
const
count
=
message
.
count
;
console
.
info
(
count
);
const
insert_data
=
await
this
.
format
(
list
);
await
ctx
.
prometheusModel
.
HuayunPaasCallOut
.
bulkCreate
(
insert_data
,
{
ignoreDuplicates
:
true
});
if
(
count
<=
limit
)
{
continue
;
for
(
let
j
=
0
;
j
<=
20
;
j
++
)
{
start
=
j
*
limit
;
console
.
info
(
j
,
start_time
,
end_time
,
start
,
limit
);
const
result
=
await
ctx
.
curl
(
url
,
{
method
:
'POST'
,
contentType
:
'json'
,
dataType
:
'json'
,
timing
:
true
,
timeout
:
900000
,
data
:
{
start_time
,
end_time
,
start
,
limit
}
});
const
ret
=
result
.
data
;
if
(
ret
.
status
!=
0
||
!
ret
.
message
||
ret
.
count
==
0
)
{
continue
;
}
const
message
=
ret
.
message
;
const
list
=
message
.
data
;
const
count
=
message
.
count
;
console
.
info
(
count
);
if
(
!
list
||
list
.
length
===
0
)
break
;
const
insert_data
=
this
.
format_callout
(
list
);
await
ctx
.
prometheusModel
.
HuayunPaasCallOut
.
bulkCreate
(
insert_data
,
{
ignoreDuplicates
:
true
});
}
// if (count <= limit) {
// continue;
// }
continue
;
//分页查询
const
page
=
Math
.
ceil
(
count
/
limit
);
const
p_result2
=
[];
for
(
let
j
=
1
;
j
<=
page
-
1
;
j
++
)
{
// let start2 = j * limit;
// console.info(j, start_time, end_time, start2, limit);
// const result2 = await ctx.curl(url, { method: 'POST', contentType: 'json', dataType: 'json', timing: true, timeout: 900000, data: { start_time, end_time, start2, limit } });
// const ret2 = result2.data;
// if (ret2.status != 0 || !ret2.message || ret2.count == 0) {
// continue;
// }
// const message2 = ret2.message;
// const list2 = message2.data;
// console.info(message2.count);
// const insert_data2 = await this.format_callout(list2);
// await ctx.prometheusModel.HuayunPaasCallOut.bulkCreate(insert_data2, { ignoreDuplicates: true });
let
start2
=
j
*
limit
;
console
.
info
(
j
,
start_time
,
end_time
,
start2
,
limit
);
const
result2
=
await
ctx
.
curl
(
url
,
{
method
:
'POST'
,
contentType
:
'json'
,
dataType
:
'json'
,
timing
:
true
,
timeout
:
300000
,
data
:
{
start_time
,
end_time
,
start2
,
limit
}
});
const
ret2
=
result2
.
data
;
p_result2
[
j
]
=
ctx
.
curl
(
url
,
{
method
:
'POST'
,
contentType
:
'json'
,
dataType
:
'json'
,
timing
:
true
,
timeout
:
1000000
,
data
:
{
start_time
,
end_time
,
start2
,
limit
}
});
}
const
result2
=
await
Promise
.
all
(
p_result2
).
then
(
result
=>
{
//等待所有异步内容获取完成
return
result
;
}).
catch
(
error
=>
{
ctx
.
failed
(
error
);
});
// console.info(result2);
let
insert_data2
=
[];
for
(
let
k
in
result2
)
{
// console.info(result2[k]);
if
(
!
result2
[
k
])
continue
;
const
ret2
=
result2
[
k
].
data
;
if
(
ret2
.
status
!=
0
||
!
ret2
.
message
||
ret2
.
count
==
0
)
{
continue
;
}
const
message2
=
ret2
.
message
;
const
list2
=
message2
.
data
;
const
insert_data2
=
await
this
.
format
(
list2
);
await
ctx
.
prometheusModel
.
HuayunPaasCallOut
.
bulkCreate
(
insert_data2
,
{
ignoreDuplicates
:
true
});
console
.
info
(
message2
.
count
);
let
insert_data_temp
=
this
.
format_callout
(
list2
);
console
.
info
(
insert_data_temp
.
length
);
insert_data2
=
insert_data2
.
concat
(
insert_data_temp
);
}
// console.info(insert_data2.length);
// await ctx.prometheusModel.HuayunPaasCallOut.bulkCreate(insert_data2, { ignoreDuplicates: true });
console
.
info
(
insert_data2
.
length
);
}
}
...
...
@@ -187,7 +269,8 @@ class HomeController extends Controller {
async
huayunCall
()
{
const
{
ctx
}
=
this
;
const
accessToken
=
await
this
.
getAccessToken
();
// const accessToken = await this.getAccessToken();
const
accessToken
=
'b762900b54e633ce70c2111172c1df78'
;
// this.callIn(accessToken);
// this.callOut(accessToken);
ctx
.
success
({
status
:
true
});
...
...
@@ -196,16 +279,20 @@ class HomeController extends Controller {
async
huayunCallTest
()
{
const
{
ctx
}
=
this
;
let
start_time
=
'2019-0
7-30 10:06:49
'
;
let
start_time
=
'2019-0
8-01 00:00:00
'
;
// let end_time = moment(start_time).add(30, 'days').format('YYYY-MM-DD HH:mm:ss');
let
end_time
=
'2019-08-15 18:31:01'
;
const
accessToken
=
'8091d5922082e808c601c424bad0b9f2'
;
const
start
=
0
;
let
end_time
=
'2019-08-30 23:40:00'
;
// const accessToken = '8df0df02d9417a85bbadb3c3df1f6a03';
const
accessToken
=
await
this
.
getAccessToken
();
console
.
info
(
accessToken
);
const
start
=
100
;
const
limit
=
100
;
const
url
=
`http://221.194.132.83:7780/paas/Interface/
${
accessToken
}
/CallIn`
;
const
result2
=
await
ctx
.
curl
(
url
,
{
method
:
'POST'
,
contentType
:
'json'
,
dataType
:
'json'
,
timing
:
true
,
timeout
:
50000
,
data
:
{
start_time
,
end_time
,
start
,
limit
}
});
// const session_id = '4421788439580105110';
const
url
=
`http://221.194.132.83:7780/paas/Interface/
${
accessToken
}
/CallOut`
;
// const result2 = await ctx.curl(url, { method: 'POST', contentType: 'json', dataType: 'json', timing: true, timeout: 50000, data: { start_time, end_time, start, limit } });
// const last_one = await ctx.prometheusModel.HuayunPaasCallin.findOne({ order: [['id', 'desc']] });
ctx
.
success
({
status
:
result2
});
// const cpus = require('os').cpus();
ctx
.
success
({
status
:
accessToken
});
// ctx.success({ status: await this.getAccessToken() });
}
}
...
...
app/schedule/HuaYunPaas.js
View file @
e7f32ce3
...
...
@@ -35,21 +35,20 @@ class HuaYunPaas extends Subscription {
}
}
async
logic
(){
async
logic
()
{
const
{
ctx
}
=
this
;
const
accessToken
=
await
this
.
getAccessToken
();
this
.
callIn
(
accessToken
);
this
.
callOut
(
accessToken
);
this
.
callIn
();
this
.
callOut
();
return
true
;
}
async
callIn
(
accessToken
)
{
async
callIn
()
{
const
{
ctx
}
=
this
;
ctx
.
logger
.
info
(
'in logic'
);
// const accessToken = await this.getAccessToken(
);
ctx
.
logger
.
info
(
'in logic
callIn
'
);
const
accessToken
=
await
this
.
getAccessToken
(
'callIn'
);
const
url
=
`http://221.194.132.83:7780/paas/Interface/
${
accessToken
}
/CallIn`
;
const
lastOne
=
await
ctx
.
prometheusModel
.
HuayunPaasCallin
.
findOne
({
order
:
[[
'end_time'
,
'desc'
]]
});
const
start
=
0
;
...
...
@@ -60,14 +59,14 @@ class HuaYunPaas extends Subscription {
start_time
=
lastOne
.
end_time
;
}
ctx
.
logger
.
info
(
JSON
.
stringify
({
start_time
,
now_time
,
start
,
limit
}));
const
result
=
await
ctx
.
curl
(
url
,
{
method
:
'POST'
,
contentType
:
'json'
,
dataType
:
'json'
,
timing
:
true
,
timeout
:
3
00000
,
data
:
{
start_time
,
end_time
:
now_time
,
start
,
limit
}
});
const
result
=
await
ctx
.
curl
(
url
,
{
method
:
'POST'
,
contentType
:
'json'
,
dataType
:
'json'
,
timing
:
true
,
timeout
:
5
00000
,
data
:
{
start_time
,
end_time
:
now_time
,
start
,
limit
}
});
const
ret
=
result
.
data
;
// ctx.logger.info(JSON.stringify({ ret }));
ctx
.
logger
.
info
(
'get result'
);
ctx
.
logger
.
info
(
'get result
callIn
'
);
if
(
ret
.
status
!=
0
||
!
ret
.
message
||
ret
.
count
==
0
)
{
return
;
}
ctx
.
logger
.
info
(
'in add'
);
ctx
.
logger
.
info
(
'in add
callIn
'
);
const
message
=
ret
.
message
;
const
list
=
message
.
data
;
ctx
.
logger
.
info
(
message
.
count
);
...
...
@@ -76,11 +75,11 @@ class HuaYunPaas extends Subscription {
}
async
callOut
(
accessToken
)
{
async
callOut
()
{
const
{
ctx
}
=
this
;
ctx
.
logger
.
info
(
'in logic'
);
// const accessToken = await this.getAccessToken(
);
ctx
.
logger
.
info
(
'in logic
callOut
'
);
const
accessToken
=
await
this
.
getAccessToken
(
'callOut'
);
const
url
=
`http://221.194.132.83:7780/paas/Interface/
${
accessToken
}
/CallOut`
;
const
lastOne
=
await
ctx
.
prometheusModel
.
HuayunPaasCallOut
.
findOne
({
order
:
[[
'end_time'
,
'desc'
]]
});
const
start
=
0
;
...
...
@@ -91,14 +90,14 @@ class HuaYunPaas extends Subscription {
start_time
=
lastOne
.
end_time
;
}
ctx
.
logger
.
info
(
JSON
.
stringify
({
start_time
,
now_time
,
start
,
limit
}));
const
result
=
await
ctx
.
curl
(
url
,
{
method
:
'POST'
,
contentType
:
'json'
,
dataType
:
'json'
,
timing
:
true
,
timeout
:
3
00000
,
data
:
{
start_time
,
end_time
:
now_time
,
start
,
limit
}
});
const
result
=
await
ctx
.
curl
(
url
,
{
method
:
'POST'
,
contentType
:
'json'
,
dataType
:
'json'
,
timing
:
true
,
timeout
:
5
00000
,
data
:
{
start_time
,
end_time
:
now_time
,
start
,
limit
}
});
const
ret
=
result
.
data
;
// ctx.logger.info(JSON.stringify({ ret }));
ctx
.
logger
.
info
(
'get result'
);
ctx
.
logger
.
info
(
'get result
callOut
'
);
if
(
ret
.
status
!=
0
||
!
ret
.
message
||
ret
.
count
==
0
)
{
return
;
}
ctx
.
logger
.
info
(
'in add'
);
ctx
.
logger
.
info
(
'in add
callOut
'
);
const
message
=
ret
.
message
;
const
list
=
message
.
data
;
ctx
.
logger
.
info
(
message
.
count
);
...
...
@@ -107,11 +106,17 @@ class HuaYunPaas extends Subscription {
}
async
getAccessToken
()
{
async
getAccessToken
(
type
=
'callIn'
)
{
const
{
ctx
}
=
this
;
const
clientId
=
'961a170e-f939-4189-9163-c4c39051b586'
;
const
clientScr
=
'53ed566c-72b8-4ebf-b0bb-78147623be71'
;
let
clientId
=
'961a170e-f939-4189-9163-c4c39051b586'
;
let
clientScr
=
'53ed566c-72b8-4ebf-b0bb-78147623be71'
;
if
(
type
===
'callOut'
)
{
clientId
=
'c5e1bb68-207d-4164-852d-c206711dd431'
;
clientScr
=
'6c9836c1-38ec-44db-8ef5-0f55b7825276'
;
}
const
url
=
'http://221.194.132.83:7780/paas/accreditation'
;
const
result
=
await
ctx
.
helper
.
send_request
(
url
,
{
clientId
,
clientScr
});
const
ret
=
result
.
data
;
...
...
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