Commit a1f044d9a798ad21389d0eb455ccc6cefe8ca12b
1 parent
9354f8c5
Exists in
master
and in
1 other branch
update parallel
Showing
4 changed files
with
155 additions
and
22 deletions
Show diff stats
ais-structure/src/config/config.js
ais-structure/src/modules/customer/customer.ctrl.js
| @@ -19,8 +19,8 @@ exports.customer = async function (req, res, next) { | @@ -19,8 +19,8 @@ exports.customer = async function (req, res, next) { | ||
| 19 | var objectData = req.query; | 19 | var objectData = req.query; |
| 20 | const result = await connection.requestJsonToD01(objectData,sendCmd,"GET"); | 20 | const result = await connection.requestJsonToD01(objectData,sendCmd,"GET"); |
| 21 | if(typeof result.err === 'undefined'){ | 21 | if(typeof result.err === 'undefined'){ |
| 22 | - // console.log(result.response.body); | ||
| 23 | - var resultObj = JSON.parse(result.response.body); | 22 | + // console.log(result.response); |
| 23 | + var resultObj = result.response; | ||
| 24 | if(resultObj.resultCode == "20000") | 24 | if(resultObj.resultCode == "20000") |
| 25 | { | 25 | { |
| 26 | if(resultObj.resultData && resultObj.resultData.length>0) | 26 | if(resultObj.resultData && resultObj.resultData.length>0) |
ais-structure/src/modules/helper/connection.js
| @@ -26,36 +26,141 @@ connection.requestJsonToD01 = async function (obj,cmd,myMethod) { | @@ -26,36 +26,141 @@ connection.requestJsonToD01 = async function (obj,cmd,myMethod) { | ||
| 26 | 26 | ||
| 27 | if(params.method == "GET") | 27 | if(params.method == "GET") |
| 28 | { | 28 | { |
| 29 | - params.url = getUrl(params); | ||
| 30 | - delete params.body; | ||
| 31 | - }else if(params.method == "POST") | ||
| 32 | - { | ||
| 33 | - params.body = JSON.stringify(params.body); | ||
| 34 | - } | 29 | + var genUrl = getUrl(params); |
| 30 | + genUrl.push(genUrl[0]); | ||
| 31 | + if(genUrl.length > 1) | ||
| 32 | + { | ||
| 33 | + // console.log("multi Send"); | ||
| 34 | + var multiSend = []; | ||
| 35 | + var loopData = {}; | ||
| 36 | + for(var i=0;i<genUrl.length;i++) | ||
| 37 | + { | ||
| 38 | + loopData.url = genUrl[i]; | ||
| 39 | + loopData.method = params.method; | ||
| 40 | + multiSend.push(loopData); | ||
| 35 | 41 | ||
| 36 | - var result = await asyncRequest(params,cmd,cfg.service.D01.Name); | 42 | + // console.log("Url["+i+"] : "+loopData.url); |
| 43 | + } | ||
| 37 | 44 | ||
| 45 | + parallelRequest(multiSend,cmd,cfg.service.D01.Name); | ||
| 38 | 46 | ||
| 39 | - // console.log(result); | ||
| 40 | - if(result.response) | ||
| 41 | - { | ||
| 42 | - var data = JSON.parse(result.response.body); | 47 | + var dataRes = {}; |
| 48 | + for(var i=0;i<multiSend.length;i++) | ||
| 49 | + { | ||
| 50 | + // console.log("start loop"); | ||
| 51 | + // var loopRes = await asyncRequest(multiSend[i],cmd,cfg.service.D01.Name); | ||
| 52 | + | ||
| 53 | + // var loopRes = parallelRequest(multiSend[i],cmd,cfg.service.D01.Name); | ||
| 54 | + | ||
| 55 | + if(loopRes.response) | ||
| 56 | + { | ||
| 57 | + var data = JSON.parse(loopRes.response.body); | ||
| 58 | + dataRes[i] = {}; | ||
| 59 | + | ||
| 60 | + if(!data.resultCode) | ||
| 61 | + dataRes[i].err = "Miss resultCode"; | ||
| 62 | + | ||
| 63 | + if(!data.resultDescription) | ||
| 64 | + dataRes[i].err = "Miss resultDescription" | ||
| 65 | + | ||
| 66 | + | ||
| 67 | + dataRes[i].data = data.resultData; | ||
| 68 | + | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + var result = {}; | ||
| 74 | + result.response = {}; | ||
| 75 | + result.response.resultData = []; | ||
| 76 | + | ||
| 77 | + for (var i = 0; i < multiSend.length; i++) { | ||
| 78 | + | ||
| 79 | + result.response.resultData = result.response.resultData.concat(dataRes[i].data); | ||
| 80 | + if(dataRes[i].err) | ||
| 81 | + result.err = dataRes[i].err; | ||
| 82 | + } | ||
| 43 | 83 | ||
| 44 | - if(!data.resultCode) | ||
| 45 | - result.err = "Miss resultCode"; | 84 | + if(!result.err) |
| 85 | + { | ||
| 86 | + result.response.resultCode = "20000"; | ||
| 87 | + result.response.developerMessage = "Success"; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + | ||
| 91 | + }else | ||
| 92 | + { | ||
| 93 | + // console.log("single Send"); | ||
| 94 | + params.url = genUrl[0]; | ||
| 95 | + delete params.body; | ||
| 96 | + | ||
| 97 | + var result = await asyncRequest(params,cmd,cfg.service.D01.Name); | ||
| 98 | + | ||
| 99 | + // console.log(result); | ||
| 100 | + if(result.response) | ||
| 101 | + { | ||
| 102 | + var data = JSON.parse(result.response.body); | ||
| 103 | + result.response = data; | ||
| 104 | + | ||
| 105 | + if(!data.resultCode) | ||
| 106 | + result.err = "Miss resultCode"; | ||
| 107 | + | ||
| 108 | + if(!data.resultDescription) | ||
| 109 | + result.err = "Miss resultDescription"; | ||
| 110 | + } | ||
| 111 | + } | ||
| 46 | 112 | ||
| 47 | - if(!data.resultDescription) | ||
| 48 | - result.err = "Miss resultDescription" | 113 | + |
| 114 | + }else if(params.method == "POST") | ||
| 115 | + { | ||
| 116 | + params.body = JSON.stringify(params.body); | ||
| 49 | } | 117 | } |
| 118 | + | ||
| 50 | 119 | ||
| 120 | + delete result.body; | ||
| 121 | + // console.log(result); | ||
| 51 | return result; | 122 | return result; |
| 52 | 123 | ||
| 53 | 124 | ||
| 54 | }; | 125 | }; |
| 55 | 126 | ||
| 127 | + | ||
| 128 | +function parallelRequest(multiParams,cmd,node) | ||
| 129 | +{ | ||
| 130 | + for(var i=0;i<multiParams.length;i++) | ||
| 131 | + { | ||
| 132 | + stats.sendRequest(node,cmd); | ||
| 133 | + console.log("Start "+i+" Url : "+multiParams[i].url); | ||
| 134 | + console.log("Start "+i+"Time : "+new Date().toISOString()); | ||
| 135 | + request(multiParams[i], function (error, response, body) { | ||
| 136 | + if (error) { | ||
| 137 | + console.log("error"); | ||
| 138 | + console.log("End : "+new Date().toISOString()); | ||
| 139 | + stats.reciveResponse(node,cmd,"Error"); | ||
| 140 | + // resolve({ | ||
| 141 | + // 'body' : body, | ||
| 142 | + // 'err' : error | ||
| 143 | + // }); | ||
| 144 | + // console.log(error); | ||
| 145 | + } else { | ||
| 146 | + console.log("normal"); | ||
| 147 | + console.log("End "+i+" : "+new Date().toISOString()); | ||
| 148 | + // stats.reciveResponse(node,cmd,"Success"); | ||
| 149 | + // resolve({ | ||
| 150 | + // 'body' : body, | ||
| 151 | + // 'response' : response | ||
| 152 | + // }); | ||
| 153 | + | ||
| 154 | + // console.log(response); | ||
| 155 | + } | ||
| 156 | + }); | ||
| 157 | + } | ||
| 158 | +} | ||
| 159 | + | ||
| 56 | function asyncRequest (params = {},cmd,node) { | 160 | function asyncRequest (params = {},cmd,node) { |
| 57 | 161 | ||
| 58 | // console.log(params); | 162 | // console.log(params); |
| 163 | + console.log("Start : "+new Date().toISOString()); | ||
| 59 | return new Promise((resolve, reject) => { | 164 | return new Promise((resolve, reject) => { |
| 60 | request(params, function (error, response, body) { | 165 | request(params, function (error, response, body) { |
| 61 | 166 | ||
| @@ -63,13 +168,15 @@ function asyncRequest (params = {},cmd,node) { | @@ -63,13 +168,15 @@ function asyncRequest (params = {},cmd,node) { | ||
| 63 | 168 | ||
| 64 | if (error) { | 169 | if (error) { |
| 65 | // console.log("error"); | 170 | // console.log("error"); |
| 171 | + console.log("Start : "+new Date()); | ||
| 66 | stats.reciveResponse(node,cmd,"Error"); | 172 | stats.reciveResponse(node,cmd,"Error"); |
| 67 | resolve({ | 173 | resolve({ |
| 68 | 'body' : body, | 174 | 'body' : body, |
| 69 | 'err' : error | 175 | 'err' : error |
| 70 | }); | 176 | }); |
| 71 | } else { | 177 | } else { |
| 72 | - // console.log("normal"); | 178 | + // console.log("normal"); |
| 179 | + console.log("End : "+new Date().toISOString()); | ||
| 73 | // stats.reciveResponse(node,cmd,"Success"); | 180 | // stats.reciveResponse(node,cmd,"Success"); |
| 74 | resolve({ | 181 | resolve({ |
| 75 | 'body' : body, | 182 | 'body' : body, |
| @@ -82,6 +189,7 @@ function asyncRequest (params = {},cmd,node) { | @@ -82,6 +189,7 @@ function asyncRequest (params = {},cmd,node) { | ||
| 82 | 189 | ||
| 83 | function getUrl(params) | 190 | function getUrl(params) |
| 84 | { | 191 | { |
| 192 | + var returnData = []; | ||
| 85 | var url = params.url; | 193 | var url = params.url; |
| 86 | var fields = ""; | 194 | var fields = ""; |
| 87 | var filter = ""; | 195 | var filter = ""; |
| @@ -104,13 +212,37 @@ function getUrl(params) | @@ -104,13 +212,37 @@ function getUrl(params) | ||
| 104 | } | 212 | } |
| 105 | 213 | ||
| 106 | if(filter != "") | 214 | if(filter != "") |
| 107 | - filter = "?filter=(&"+filter+")"; | 215 | + { |
| 216 | + var maxFilterLength = cfg.Uri_length - url.length - fields.length + "?filter=(&)".length; | ||
| 217 | + | ||
| 218 | + if(maxFilterLength > filter.length) | ||
| 219 | + { | ||
| 220 | + returnData.push(url+"?filter=(&"+filter+")"+fields); | ||
| 221 | + | ||
| 222 | + }else | ||
| 223 | + { | ||
| 224 | + // while(maxFilterLength < filter.length) | ||
| 225 | + // { | ||
| 226 | + | ||
| 227 | + // returnData.push(url+"?filter=(&"+filter+")"+fields); | ||
| 228 | + // } | ||
| 229 | + | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + | ||
| 235 | + | ||
| 236 | + | ||
| 237 | + | ||
| 238 | + | ||
| 239 | + | ||
| 108 | 240 | ||
| 109 | // console.log(url); | 241 | // console.log(url); |
| 110 | // console.log(filter); | 242 | // console.log(filter); |
| 111 | // console.log(fields); | 243 | // console.log(fields); |
| 112 | 244 | ||
| 113 | - return url+filter+fields; | 245 | + return returnData; |
| 114 | } | 246 | } |
| 115 | 247 | ||
| 116 | function getFields(fields,first) | 248 | function getFields(fields,first) |
ais-structure/src/modules/helper/responseMsg.js
| @@ -32,7 +32,7 @@ responseMsg.success = function (req,cmd,data){ | @@ -32,7 +32,7 @@ responseMsg.success = function (req,cmd,data){ | ||
| 32 | resultCode : "20000", | 32 | resultCode : "20000", |
| 33 | developerMessage : "Success", | 33 | developerMessage : "Success", |
| 34 | resultData : data.resultData, | 34 | resultData : data.resultData, |
| 35 | - rowCount : data.rowCount | 35 | + rowCount : data.resultData.length |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | stats.sendResponse(req.method,cmd,"Success"); | 38 | stats.sendResponse(req.method,cmd,"Success"); |