Commit e7f32ce3 authored by 李尚科's avatar 李尚科

huayuan paas callOut fix

parent daef6bc3
Pipeline #12602 passed with stage
in 24 seconds
...@@ -22,8 +22,13 @@ class HomeController extends Controller { ...@@ -22,8 +22,13 @@ class HomeController extends Controller {
async getAccessToken() { async getAccessToken() {
const { ctx } = this; 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 url = 'http://221.194.132.83:7780/paas/accreditation';
const result = await ctx.helper.send_request(url, { clientId, clientScr }); const result = await ctx.helper.send_request(url, { clientId, clientScr });
const ret = result.data; const ret = result.data;
...@@ -71,6 +76,43 @@ class HomeController extends Controller { ...@@ -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) { async callIn(accessToken) {
const { ctx } = this; const { ctx } = this;
...@@ -135,7 +177,7 @@ class HomeController extends Controller { ...@@ -135,7 +177,7 @@ class HomeController extends Controller {
let start_time = '2019-01-01 00:00:00'; let start_time = '2019-01-01 00:00:00';
let end_time = '2019-01-30 23:59:59'; let end_time = '2019-01-30 23:59:59';
const start = 0; let start = 0;
const limit = 10000; const limit = 10000;
const now_time = moment().format('YYYY-MM-DD HH:mm:ss'); const now_time = moment().format('YYYY-MM-DD HH:mm:ss');
...@@ -149,7 +191,11 @@ class HomeController extends Controller { ...@@ -149,7 +191,11 @@ class HomeController extends Controller {
break; break;
} }
const result = await ctx.curl(url, { method: 'POST', contentType: 'json', dataType: 'json', timing: true, timeout: 300000, data: { start_time, end_time, start, limit } }); 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; const ret = result.data;
if (ret.status != 0 || !ret.message || ret.count == 0) { if (ret.status != 0 || !ret.message || ret.count == 0) {
continue; continue;
...@@ -158,28 +204,64 @@ class HomeController extends Controller { ...@@ -158,28 +204,64 @@ class HomeController extends Controller {
const list = message.data; const list = message.data;
const count = message.count; const count = message.count;
console.info(count); console.info(count);
const insert_data = await this.format(list); if (!list || list.length === 0) break;
const insert_data = this.format_callout(list);
await ctx.prometheusModel.HuayunPaasCallOut.bulkCreate(insert_data, { ignoreDuplicates: true }); await ctx.prometheusModel.HuayunPaasCallOut.bulkCreate(insert_data, { ignoreDuplicates: true });
if (count <= limit) {
continue;
} }
// if (count <= limit) {
// continue;
// }
continue;
//分页查询 //分页查询
const page = Math.ceil(count / limit); const page = Math.ceil(count / limit);
const p_result2 = [];
for (let j = 1; j <= page - 1; j++) { 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; let start2 = j * limit;
console.info(j, start_time, end_time, start2, 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 } }); p_result2[j] = ctx.curl(url, { method: 'POST', contentType: 'json', dataType: 'json', timing: true, timeout: 1000000, data: { start_time, end_time, start2, limit } });
const ret2 = result2.data; }
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) { if (ret2.status != 0 || !ret2.message || ret2.count == 0) {
continue; continue;
} }
const message2 = ret2.message; const message2 = ret2.message;
const list2 = message2.data; const list2 = message2.data;
const insert_data2 = await this.format(list2); console.info(message2.count);
await ctx.prometheusModel.HuayunPaasCallOut.bulkCreate(insert_data2, { ignoreDuplicates: true }); 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 { ...@@ -187,7 +269,8 @@ class HomeController extends Controller {
async huayunCall() { async huayunCall() {
const { ctx } = this; const { ctx } = this;
const accessToken = await this.getAccessToken(); // const accessToken = await this.getAccessToken();
const accessToken = 'b762900b54e633ce70c2111172c1df78';
// this.callIn(accessToken); // this.callIn(accessToken);
// this.callOut(accessToken); // this.callOut(accessToken);
ctx.success({ status: true }); ctx.success({ status: true });
...@@ -196,16 +279,20 @@ class HomeController extends Controller { ...@@ -196,16 +279,20 @@ class HomeController extends Controller {
async huayunCallTest() { async huayunCallTest() {
const { ctx } = this; const { ctx } = this;
let start_time = '2019-07-30 10:06:49'; let start_time = '2019-08-01 00:00:00';
// let end_time = moment(start_time).add(30, 'days').format('YYYY-MM-DD HH:mm:ss'); // 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'; let end_time = '2019-08-30 23:40:00';
const accessToken = '8091d5922082e808c601c424bad0b9f2'; // const accessToken = '8df0df02d9417a85bbadb3c3df1f6a03';
const start = 0; const accessToken = await this.getAccessToken();
console.info(accessToken);
const start = 100;
const limit = 100; const limit = 100;
const url = `http://221.194.132.83:7780/paas/Interface/${accessToken}/CallIn`; // const session_id = '4421788439580105110';
const result2 = await ctx.curl(url, { method: 'POST', contentType: 'json', dataType: 'json', timing: true, timeout: 50000, data: { start_time, end_time, start, limit } }); 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']] }); // 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() }); // ctx.success({ status: await this.getAccessToken() });
} }
} }
......
...@@ -35,21 +35,20 @@ class HuaYunPaas extends Subscription { ...@@ -35,21 +35,20 @@ class HuaYunPaas extends Subscription {
} }
} }
async logic(){ async logic() {
const { ctx } = this; const { ctx } = this;
const accessToken = await this.getAccessToken(); this.callIn();
this.callIn(accessToken); this.callOut();
this.callOut(accessToken);
return true; return true;
} }
async callIn(accessToken) { async callIn() {
const { ctx } = this; const { ctx } = this;
ctx.logger.info('in logic'); ctx.logger.info('in logic callIn');
// const accessToken = await this.getAccessToken(); const accessToken = await this.getAccessToken('callIn');
const url = `http://221.194.132.83:7780/paas/Interface/${accessToken}/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 lastOne = await ctx.prometheusModel.HuayunPaasCallin.findOne({ order: [['end_time', 'desc']] });
const start = 0; const start = 0;
...@@ -60,14 +59,14 @@ class HuaYunPaas extends Subscription { ...@@ -60,14 +59,14 @@ class HuaYunPaas extends Subscription {
start_time = lastOne.end_time; start_time = lastOne.end_time;
} }
ctx.logger.info(JSON.stringify({ start_time, now_time, start, limit })); 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: 300000, data: { start_time, end_time: now_time, start, limit } }); const result = await ctx.curl(url, { method: 'POST', contentType: 'json', dataType: 'json', timing: true, timeout: 500000, data: { start_time, end_time: now_time, start, limit } });
const ret = result.data; const ret = result.data;
// ctx.logger.info(JSON.stringify({ ret })); // 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) { if (ret.status != 0 || !ret.message || ret.count == 0) {
return; return;
} }
ctx.logger.info('in add'); ctx.logger.info('in add callIn');
const message = ret.message; const message = ret.message;
const list = message.data; const list = message.data;
ctx.logger.info(message.count); ctx.logger.info(message.count);
...@@ -76,11 +75,11 @@ class HuaYunPaas extends Subscription { ...@@ -76,11 +75,11 @@ class HuaYunPaas extends Subscription {
} }
async callOut(accessToken) { async callOut() {
const { ctx } = this; const { ctx } = this;
ctx.logger.info('in logic'); ctx.logger.info('in logic callOut');
// const accessToken = await this.getAccessToken(); const accessToken = await this.getAccessToken('callOut');
const url = `http://221.194.132.83:7780/paas/Interface/${accessToken}/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 lastOne = await ctx.prometheusModel.HuayunPaasCallOut.findOne({ order: [['end_time', 'desc']] });
const start = 0; const start = 0;
...@@ -91,14 +90,14 @@ class HuaYunPaas extends Subscription { ...@@ -91,14 +90,14 @@ class HuaYunPaas extends Subscription {
start_time = lastOne.end_time; start_time = lastOne.end_time;
} }
ctx.logger.info(JSON.stringify({ start_time, now_time, start, limit })); 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: 300000, data: { start_time, end_time: now_time, start, limit } }); const result = await ctx.curl(url, { method: 'POST', contentType: 'json', dataType: 'json', timing: true, timeout: 500000, data: { start_time, end_time: now_time, start, limit } });
const ret = result.data; const ret = result.data;
// ctx.logger.info(JSON.stringify({ ret })); // 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) { if (ret.status != 0 || !ret.message || ret.count == 0) {
return; return;
} }
ctx.logger.info('in add'); ctx.logger.info('in add callOut');
const message = ret.message; const message = ret.message;
const list = message.data; const list = message.data;
ctx.logger.info(message.count); ctx.logger.info(message.count);
...@@ -107,11 +106,17 @@ class HuaYunPaas extends Subscription { ...@@ -107,11 +106,17 @@ class HuaYunPaas extends Subscription {
} }
async getAccessToken() { async getAccessToken(type = 'callIn') {
const { ctx } = this; 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 url = 'http://221.194.132.83:7780/paas/accreditation';
const result = await ctx.helper.send_request(url, { clientId, clientScr }); const result = await ctx.helper.send_request(url, { clientId, clientScr });
const ret = result.data; const ret = result.data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment