Commit 50ad7d6d61f1df4a07737d617d894ac489ae5034
1 parent
53004544
Exists in
master
and in
1 other branch
update get vizcard get customer
Showing
7 changed files
with
125 additions
and
57 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | +{ | |
| 2 | + // Use IntelliSense to learn about possible attributes. | |
| 3 | + // Hover to view descriptions of existing attributes. | |
| 4 | + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
| 5 | + "version": "0.2.0", | |
| 6 | + "configurations": [ | |
| 7 | + { | |
| 8 | + "type": "node", | |
| 9 | + "request": "launch", | |
| 10 | + "name": "Launch Program", | |
| 11 | + "program": "${workspaceFolder}/index.js" | |
| 12 | + }, | |
| 13 | + { | |
| 14 | + "type": "node", | |
| 15 | + "request": "attach", | |
| 16 | + "name": "Attach by Process ID", | |
| 17 | + "processId": "${command:PickProcess}" | |
| 18 | + } | |
| 19 | + ] | |
| 20 | +} | |
| 0 | 21 | \ No newline at end of file | ... | ... |
ais-structure/src/modules/customer/customer.ctrl.js
| ... | ... | @@ -7,21 +7,25 @@ var log = require('../helper/log.js'); |
| 7 | 7 | exports.customer = async function (req, res, next) { |
| 8 | 8 | var getCmd = "Customer"; |
| 9 | 9 | var sendCmd = "Customer"; |
| 10 | + var sacf = "SACF"; | |
| 11 | + var d01 = "D01" | |
| 10 | 12 | |
| 11 | 13 | log.startlog(getCmd,req); |
| 12 | - log.logDetail.addInput("Client",getCmd,"Request",req); | |
| 14 | + log.logDetail.addInput(sacf,getCmd,"Request",req,req.body); | |
| 13 | 15 | |
| 14 | 16 | var err = validator(req,getCmd); |
| 15 | 17 | |
| 16 | 18 | if(err.length > 0) |
| 17 | 19 | { |
| 18 | - console.log(err); | |
| 20 | + log.log(err,'error'); | |
| 19 | 21 | var response = responseMsg.error(req,getCmd,40300); |
| 20 | 22 | // res.status(200).json(response); |
| 21 | 23 | }else |
| 22 | 24 | { |
| 23 | 25 | var objectData = req.query; |
| 26 | + log.logDetail.addOutput(d01,sendCmd,"Request",req.url,req.body); | |
| 24 | 27 | const result = await connection.requestJsonToD01(objectData,sendCmd,"GET"); |
| 28 | + log.logDetail.addInput(d01,sendCmd,"Response",result,result.resultData); | |
| 25 | 29 | if(typeof result.err === 'undefined'){ |
| 26 | 30 | // console.log(result.response); |
| 27 | 31 | var resultObj = result.response; |
| ... | ... | @@ -30,22 +34,25 @@ exports.customer = async function (req, res, next) { |
| 30 | 34 | if(resultObj.resultData && resultObj.resultData.length>0) |
| 31 | 35 | { |
| 32 | 36 | var response = responseMsg.success(req,getCmd,resultObj); |
| 37 | + log.addSuccessSummary(sacf,sendCmd,response); | |
| 33 | 38 | }else |
| 34 | 39 | { |
| 35 | 40 | var response = responseMsg.error(req,getCmd,40300); |
| 41 | + log.addErrorSummary(sacf,sendCmd,response); | |
| 36 | 42 | } |
| 37 | 43 | } |
| 38 | 44 | } else { |
| 39 | 45 | response = responseMsg.direct(req,getCmd,result.response); |
| 46 | + log.addErrorSummary(sacf,sendCmd,response); | |
| 40 | 47 | } |
| 41 | 48 | } |
| 42 | 49 | |
| 43 | - if(!response) | |
| 50 | + if(!response){ | |
| 44 | 51 | var response = responseMsg.error(req,getCmd,50000); |
| 52 | + stats.receiveResponse(sacf,sendCmd,"Error"); | |
| 53 | + } | |
| 45 | 54 | |
| 46 | - log.logDetail.addOutput("Client",getCmd,"Response",response,response); | |
| 47 | - // log.logDetail.write(); | |
| 48 | - log.logSummary(); | |
| 55 | + log.logDetail.addOutput(sacf,getCmd,"Response",response,response); | |
| 49 | 56 | res.status(200).json(response); |
| 50 | 57 | next(); |
| 51 | 58 | }; |
| ... | ... | @@ -67,9 +74,9 @@ function validator(req,api) |
| 67 | 74 | } |
| 68 | 75 | |
| 69 | 76 | if(err.length > 0) |
| 70 | - stats.reciveRequest(req.method,api,false); | |
| 77 | + stats.receiveRequest(req.method,api,false); | |
| 71 | 78 | else |
| 72 | - stats.reciveRequest(req.method,api,true); | |
| 79 | + stats.receiveRequest(req.method,api,true); | |
| 73 | 80 | |
| 74 | 81 | return err; |
| 75 | 82 | } | ... | ... |
ais-structure/src/modules/helper/connection.js
| ... | ... | @@ -18,11 +18,34 @@ connection.requestSoapToSACF = async function (soap,cmd,myMethod) { |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | stats.sendSACFRequest(cfg.service.SACF.Name,cmd) |
| 21 | - log.logDetail.addOutput(cfg.service.SACF.Name,cmd,"Request",params.body,soap); | |
| 22 | - log.logDetail.write(); | |
| 21 | + log.logDetail.addOutput(cfg.service.SACF.Name,cmd,"Request",params.body,soap); | |
| 23 | 22 | |
| 24 | - return asyncRequest(params,cmd,cfg.service.SACF.Name); | |
| 23 | + var result = await asyncRequest(params,cmd,cfg.service.SACF.Name); | |
| 24 | + | |
| 25 | + if(result.err) | |
| 26 | + { | |
| 27 | + result.response = {}; | |
| 28 | + result.response.resultCode = "50000"; | |
| 29 | + | |
| 30 | + //ETIMEDOUT = timeout | |
| 31 | + //ECONNREFUSED = servercode | |
| 32 | + | |
| 33 | + if(result.err.code == 'ETIMEDOUT'){ | |
| 34 | + result.response.resultCode = "50003"; | |
| 35 | + result.response.resultDescription = "Timeout"; | |
| 36 | + } else if(result.err.code == 'ECONNREFUSED'){ | |
| 37 | + result.response.resultCode = "50002"; | |
| 38 | + result.response.resultDescription = "Reject"; | |
| 39 | + } else { | |
| 40 | + result.response.resultCode = "50000"; | |
| 41 | + result.response.resultDescription = "System error"; | |
| 42 | + } | |
| 43 | + stats.receiveResponse(cfg.service.SACF.Name,cmd,"Error"); | |
| 44 | + } | |
| 45 | + | |
| 46 | + return result; | |
| 25 | 47 | }; |
| 48 | + | |
| 26 | 49 | connection.requestJsonToD01 = async function (obj,cmd,myMethod) { |
| 27 | 50 | |
| 28 | 51 | var service = cfg.service.D01; |
| ... | ... | @@ -157,7 +180,7 @@ connection.requestJsonToD01 = async function (obj,cmd,myMethod) { |
| 157 | 180 | if(result.response.resultCode == "40300"){ |
| 158 | 181 | stats.receiveBadRestResponse(service.Name,params.method,cmd); |
| 159 | 182 | } else { |
| 160 | - stats.reciveResponse(service.Name,cmd,"Error"); | |
| 183 | + stats.receiveResponse(service.Name,cmd,"Error"); | |
| 161 | 184 | } |
| 162 | 185 | |
| 163 | 186 | |
| ... | ... | @@ -184,7 +207,7 @@ async function parallelRequest(multiParams,cmd,node) |
| 184 | 207 | for(var i=0;i<res.length;i++) |
| 185 | 208 | { |
| 186 | 209 | if(!res[i].err) |
| 187 | - stats.reciveResponse(node,cmd,"Success"); | |
| 210 | + stats.receiveResponse(node,cmd,"Success"); | |
| 188 | 211 | |
| 189 | 212 | } |
| 190 | 213 | |
| ... | ... | @@ -208,7 +231,7 @@ function asyncRequest (params = {},cmd,node) { |
| 208 | 231 | }); |
| 209 | 232 | } else { |
| 210 | 233 | |
| 211 | - // stats.reciveResponse(node,cmd,"Success"); | |
| 234 | + // stats.receiveResponse(node,cmd,"Success"); | |
| 212 | 235 | resolve({ |
| 213 | 236 | 'body' : body, |
| 214 | 237 | 'response' : response | ... | ... |
ais-structure/src/modules/helper/log.js
| ... | ... | @@ -101,7 +101,7 @@ logger.logSummary = function (response) |
| 101 | 101 | log.addErrorBlock(row.node,row.cmd,row.resultCode,row.resultDesc); |
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | - | |
| 104 | + | |
| 105 | 105 | if(response){ |
| 106 | 106 | log.end(response.resultCode,response.developerMessage) |
| 107 | 107 | } else { |
| ... | ... | @@ -120,7 +120,7 @@ var addlogDetailData = function(inputType,node,cmd,type,rawData,data){ |
| 120 | 120 | params : rawData.params |
| 121 | 121 | }; |
| 122 | 122 | } else { |
| 123 | - var raw = { | |
| 123 | + var raw = { | |
| 124 | 124 | }; |
| 125 | 125 | } |
| 126 | 126 | |
| ... | ... | @@ -144,20 +144,24 @@ var addlogDetailData = function(inputType,node,cmd,type,rawData,data){ |
| 144 | 144 | data : data |
| 145 | 145 | }; |
| 146 | 146 | |
| 147 | + var log = logg.detail(start.session, start.cmd, start.identity); | |
| 148 | + log.addInput( detail.input.node, detail.input.cmd, detail.input.type, detail.input.rawData, detail.input.data ); | |
| 149 | + log.addOutput( detail.output.node, detail.output.cmd, detail.output.type, detail.output.rawData, detail.output.data ); | |
| 150 | + log.end(); | |
| 147 | 151 | // console.log(detail.output); |
| 148 | 152 | } |
| 149 | 153 | } |
| 150 | 154 | |
| 151 | 155 | var logDetailData = { |
| 152 | 156 | addInput : function(node,cmd,type,rawData,data){addlogDetailData('input',node,cmd,type,rawData,data)}, |
| 153 | - addOutput : function(node,cmd,type,rawData,data){addlogDetailData('output',node,cmd,type,rawData,data)}, | |
| 154 | - write : function () | |
| 155 | - { | |
| 156 | - var log = logg.detail(start.session, start.cmd, start.identity); | |
| 157 | - log.addInput( detail.input.node, detail.input.cmd, detail.input.type, detail.input.rawData, detail.input.data ); | |
| 158 | - log.addOutput( detail.output.node, detail.output.cmd, detail.output.type, detail.output.rawData, detail.output.data ); | |
| 159 | - log.end(); | |
| 160 | - } | |
| 157 | + addOutput : function(node,cmd,type,rawData,data){addlogDetailData('output',node,cmd,type,rawData,data)} | |
| 158 | + // write : function () | |
| 159 | + // { | |
| 160 | + // var log = logg.detail(start.session, start.cmd, start.identity); | |
| 161 | + // log.addInput( detail.input.node, detail.input.cmd, detail.input.type, detail.input.rawData, detail.input.data ); | |
| 162 | + // log.addOutput( detail.output.node, detail.output.cmd, detail.output.type, detail.output.rawData, detail.output.data ); | |
| 163 | + // log.end(); | |
| 164 | + // } | |
| 161 | 165 | }; |
| 162 | 166 | |
| 163 | 167 | logger.logDetail = logDetailData; | ... | ... |
ais-structure/src/modules/helper/messageSOAP.js
| ... | ... | @@ -37,11 +37,12 @@ soap.soapToArray = function(req,resultSoap) |
| 37 | 37 | |
| 38 | 38 | // console.log(resultSet); |
| 39 | 39 | |
| 40 | - | |
| 40 | + var rawDataArr = []; | |
| 41 | 41 | |
| 42 | 42 | for(var i=0;i<resultSet.length;i++) |
| 43 | 43 | { |
| 44 | 44 | var data = {} |
| 45 | + var rawData = {} | |
| 45 | 46 | for(var key in resultSet[i]){ |
| 46 | 47 | var keyObj = capitalizeFirstLetter(key.replace('tem:','')) |
| 47 | 48 | // console.log(keyObj+' : '+resultSet[i][key]['_text']); |
| ... | ... | @@ -52,13 +53,13 @@ soap.soapToArray = function(req,resultSoap) |
| 52 | 53 | } else { |
| 53 | 54 | data[keyObj] = resultSet[i][key]['_text']; |
| 54 | 55 | } |
| 56 | + rawData[keyObj] = resultSet[i][key]['_text']; | |
| 55 | 57 | } |
| 58 | + rawDataArr.push(rawData); | |
| 56 | 59 | returnData.push(data); |
| 57 | 60 | } |
| 58 | 61 | |
| 59 | - console.log(resultSet) | |
| 60 | - | |
| 61 | - return { returnData : returnData, rawDataJson : resultSet}; | |
| 62 | + return { returnData : returnData, rawDataJson : rawDataArr}; | |
| 62 | 63 | }; |
| 63 | 64 | |
| 64 | 65 | function getBodySOAP(objectData) | ... | ... |
ais-structure/src/modules/helper/stats.js
| ... | ... | @@ -10,21 +10,21 @@ stat.sendSACFRequest = function (toNode,cmd){ |
| 10 | 10 | writeStats(nodeName+" Send "+toNode+" OutRedirect SPW_"+cmd+" Request"); |
| 11 | 11 | }; |
| 12 | 12 | |
| 13 | -stat.reciveSACFResponse = function (fromNode,cmd,result){ | |
| 14 | - writeStats(nodeName+" Recive "+fromNode+" OutRedirect SPW_"+cmd+" Response "+result); | |
| 13 | +stat.receiveSACFResponse = function (fromNode,cmd,result){ | |
| 14 | + writeStats(nodeName+" Receive "+fromNode+" OutRedirect SPW_"+cmd+" Response "+result); | |
| 15 | 15 | }; |
| 16 | 16 | |
| 17 | -stat.reciveSACFBadResponse = function (fromNode,cmd){ | |
| 18 | - writeStats(nodeName+" Recive "+fromNode+" Bad OutRedirect SPW_"+cmd+" Response"); | |
| 17 | +stat.receiveSACFBadResponse = function (fromNode,cmd){ | |
| 18 | + writeStats(nodeName+" Receive "+fromNode+" Bad OutRedirect SPW_"+cmd+" Response"); | |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | 21 | //client => CMF |
| 22 | -stat.reciveRequest = function (method,cmd){ | |
| 23 | - writeStats(nodeName+" Recive "+method+" "+cmd+" Request"); | |
| 22 | +stat.receiveRequest = function (method,cmd){ | |
| 23 | + writeStats(nodeName+" Receive "+method+" "+cmd+" Request"); | |
| 24 | 24 | }; |
| 25 | 25 | |
| 26 | -stat.reciveBadRequest = function (method,cmd){ | |
| 27 | - writeStats(nodeName+" Recive Bad "+method+" "+cmd+" Request"); | |
| 26 | +stat.receiveBadRequest = function (method,cmd){ | |
| 27 | + writeStats(nodeName+" Receive Bad "+method+" "+cmd+" Request"); | |
| 28 | 28 | }; |
| 29 | 29 | |
| 30 | 30 | stat.sendResponse = function (method,cmd,result){ |
| ... | ... | @@ -49,12 +49,12 @@ stat.sendRequest = function (toNode,cmd){ |
| 49 | 49 | writeStats(nodeName+" Send "+toNode+" "+cmd+" Request"); |
| 50 | 50 | }; |
| 51 | 51 | |
| 52 | -stat.reciveResponse = function (fromNode,cmd,result){ | |
| 53 | - writeStats(nodeName+" Recive "+fromNode+" "+cmd+" Response "+result); | |
| 52 | +stat.receiveResponse = function (fromNode,cmd,result){ | |
| 53 | + writeStats(nodeName+" Receive "+fromNode+" "+cmd+" Response "+result); | |
| 54 | 54 | }; |
| 55 | 55 | |
| 56 | -stat.reciveBadResponse = function (fromNode,cmd,result){ | |
| 57 | - writeStats(nodeName+" Recive "+fromNode+" Bad "+cmd+" Response "); | |
| 56 | +stat.receiveBadResponse = function (fromNode,cmd,result){ | |
| 57 | + writeStats(nodeName+" Receive "+fromNode+" Bad "+cmd+" Response "); | |
| 58 | 58 | }; |
| 59 | 59 | |
| 60 | 60 | ... | ... |
ais-structure/src/modules/vizcard/vizCard.ctrl.js
| ... | ... | @@ -19,9 +19,9 @@ exports.vizcard = async function (req, res, next) { |
| 19 | 19 | |
| 20 | 20 | if(err.length > 0) |
| 21 | 21 | { |
| 22 | - log.log(err); | |
| 22 | + log.log(err,'error'); | |
| 23 | 23 | var response = responseMsg.error(req,getCmd,40300); |
| 24 | - res.status(200).json(response); | |
| 24 | + // res.status(200).json(response); | |
| 25 | 25 | }else |
| 26 | 26 | { |
| 27 | 27 | |
| ... | ... | @@ -41,30 +41,43 @@ exports.vizcard = async function (req, res, next) { |
| 41 | 41 | // console.log(result.err) |
| 42 | 42 | |
| 43 | 43 | if(typeof result.err === 'undefined'){ |
| 44 | - stats.reciveSACFResponse(sacf,sendCmd,"Success"); | |
| 45 | 44 | |
| 46 | - var resultSoap = parseJson.xml2json(result.body, {compact: true, spaces: 4}) | |
| 47 | - resultSoap = JSON.parse(resultSoap) | |
| 48 | - resultSoap = resultSoap['soap:Envelope']['soap:Body']['tem:SearchCustomerResponse']['tem:SearchCustomerResult']['tem:CustomerSearchResult']; | |
| 45 | + try { | |
| 46 | + var resultSoap = parseJson.xml2json(result.body, {compact: true, spaces: 4}) | |
| 47 | + resultSoap = JSON.parse(resultSoap) | |
| 48 | + resultSoap = resultSoap['soap:Envelope']['soap:Body']['tem:SearchCustomerResponse']['tem:SearchCustomerResult']['tem:CustomerSearchResult']; | |
| 49 | + | |
| 50 | + var resultSet = messageSOAP.soapToArray(req,resultSoap); | |
| 51 | + stats.receiveSACFResponse(sacf,sendCmd,"Success"); | |
| 52 | + var response = responseMsg.success(req,getCmd,{resultData:resultSet.returnData,rowCount:resultSet.returnData.length}); | |
| 53 | + | |
| 54 | + log.addSuccessSummary(sacf,sendCmd,response); | |
| 55 | + // log.addErrorSummary("ABCD","EFGH",{resultCode : '50000',developerMessage : "error"}); | |
| 56 | + } | |
| 57 | + catch(error) { | |
| 58 | + result.response.resultCode = "50000"; | |
| 59 | + result.response.resultDescription = "Bad Response"; | |
| 49 | 60 | |
| 50 | - var resultSet = messageSOAP.soapToArray(req,resultSoap); | |
| 51 | - var response = responseMsg.success(req,getCmd,{resultData:resultSet.returnData,rowCount:resultSet.returnData.length}); | |
| 61 | + stats.receiveSACFBadResponse(sacf,sendCmd); | |
| 62 | + log.addErrorSummary(sacf,sendCmd,response); | |
| 52 | 63 | |
| 53 | - log.addSuccessSummary(sacf,sendCmd,response); | |
| 54 | - // log.addErrorSummary("ABCD","EFGH",{resultCode : '50000',developerMessage : "error"}); | |
| 64 | + response = responseMsg.direct(req,getCmd,result.response); | |
| 65 | + var resultSet = {rawDataJson : ""} | |
| 66 | + } | |
| 55 | 67 | |
| 68 | + } else { | |
| 69 | + response = responseMsg.direct(req,getCmd,result.response); | |
| 70 | + var resultSet = {rawDataJson : ""} | |
| 56 | 71 | } |
| 57 | 72 | |
| 58 | - log.logDetail.addInput(sacf,getCmd,"Response",result,resultSet.rawDataJson); | |
| 73 | + log.logDetail.addInput(sacf,sendCmd,"Response",result,resultSet.rawDataJson); | |
| 59 | 74 | |
| 60 | 75 | if(!response){ |
| 61 | 76 | var response = responseMsg.error(req,getCmd,50000); |
| 62 | - stats.reciveResponse(sacf,"SPW_"+sendCmd,"Error"); | |
| 77 | + stats.receiveSACFResponse(sacf,sendCmd,"Error"); | |
| 63 | 78 | } |
| 64 | 79 | |
| 65 | - log.logDetail.addOutput(sacf,sendCmd,"Response",response,response); | |
| 66 | - log.logDetail.write(); | |
| 67 | - log.logSummary(response); | |
| 80 | + log.logDetail.addOutput(sacf,getCmd,"Response",response,response); | |
| 68 | 81 | res.status(200).json(response); |
| 69 | 82 | next(); |
| 70 | 83 | } |
| ... | ... | @@ -83,9 +96,9 @@ function validator(req,cmd) |
| 83 | 96 | |
| 84 | 97 | var err = validatorHelper(req,list); |
| 85 | 98 | if(err.length > 0) |
| 86 | - stats.reciveRequest(req.method,cmd,false); | |
| 99 | + stats.receiveRequest(req.method,cmd,false); | |
| 87 | 100 | else |
| 88 | - stats.reciveRequest(req.method,cmd,true); | |
| 101 | + stats.receiveRequest(req.method,cmd,true); | |
| 89 | 102 | |
| 90 | 103 | return err; |
| 91 | 104 | } | ... | ... |