261007_01_ENH: 컨택 결과 갱신 api호출 시 log남기고 api 결과가 다 도착한 경우만 다음 페이지로 이동
This commit is contained in:
161
module/survey.js
161
module/survey.js
@@ -99,52 +99,34 @@ kon.survey = (function () {
|
||||
}
|
||||
sessionStorage.setItem("N_PAGE_"+kon.survey.IDKEY, nextinput.val());
|
||||
|
||||
if(nextinput.val() == "END"){
|
||||
/////박준성 여기서 KART를 호출해서 파생변수 반들기
|
||||
var apiWaits = [];
|
||||
if (nextinput.val() === "END") {
|
||||
var isKiwi = 1;
|
||||
$.ajax({
|
||||
url: "https://rapi.kric.com/api/v1/project/derived/"+isKiwi+"/"+kon.survey.PKEY+"/"+kon.survey.IDKEY,
|
||||
type: "POST",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
cache: false,
|
||||
async: true,
|
||||
//success: function (data) {},
|
||||
error: function (x, h, r) {
|
||||
console.log(x);
|
||||
console.log(h);
|
||||
console.log(r);
|
||||
}
|
||||
});
|
||||
var kartRequestUrl = "https://rapi.kric.com/api/v1/project/derived/"+isKiwi+"/"+kon.survey.PKEY+"/"+kon.survey.IDKEY;
|
||||
apiWaits.push(callLoggedApi(kartRequestUrl, "DERIVED", kon.survey.IDKEY, "", ""));
|
||||
}
|
||||
|
||||
if(surveyType == "LIST"){
|
||||
if (surveyType === "LIST") {
|
||||
var contactMappingList = ajax_returnData("/include/ajax_contact.asp", {
|
||||
"CRUD": "SELECT",
|
||||
"COMMAND": "CONTACT_SURVEY",
|
||||
"PKEY": kon.survey.PKEY
|
||||
});
|
||||
|
||||
if(contactMappingList.length > 0){
|
||||
if(pagename == "INDEX"){
|
||||
callContactStatusApi(contactMappingList, kon.survey.IDKEY, "start")
|
||||
}
|
||||
if (Array.isArray(contactMappingList) && contactMappingList.length > 0) {
|
||||
var statuses = [];
|
||||
if (pagename === "INDEX") statuses.push("start");
|
||||
if (["PREV", "END"].includes(nextinput.val())) statuses.push("complete");
|
||||
else if (nextinput.val() === "SCREEN") statuses.push("screen");
|
||||
else if (nextinput.val() === "QUOTA") statuses.push("quota");
|
||||
|
||||
if(["PREV","END", "SCREEN", "QUOTA"].includes(nextinput.val())){
|
||||
var status = "complete"
|
||||
|
||||
if(nextinput.val() == "SCREEN"){
|
||||
status = "screen"
|
||||
}
|
||||
else if(nextinput.val() == "QUOTA"){
|
||||
status = "quota"
|
||||
}
|
||||
|
||||
callContactStatusApi(contactMappingList, kon.survey.IDKEY, status)
|
||||
if (statuses.length > 0) {
|
||||
apiWaits.push(callContactStatusApi(contactMappingList, kon.survey.IDKEY, statuses));
|
||||
}
|
||||
}
|
||||
}
|
||||
form.attr("onsubmit", "");
|
||||
form.submit();
|
||||
|
||||
submitNextPage(form, apiWaits);
|
||||
}, error: function (x, h, r) {
|
||||
console.log(x);
|
||||
console.log(h);
|
||||
@@ -154,8 +136,71 @@ kon.survey = (function () {
|
||||
})
|
||||
}
|
||||
|
||||
function callContactStatusApi(contactMappingList, idkey, status) {
|
||||
var contactRouteUrl = "/api/external/";
|
||||
function submitNextPage(form, waits) {
|
||||
var remaining = waits.length;
|
||||
if (remaining === 0) {
|
||||
form.attr("onsubmit", "");
|
||||
form.submit();
|
||||
return;
|
||||
}
|
||||
waits.forEach(function (wait) {
|
||||
wait.always(function () {
|
||||
remaining--;
|
||||
if (remaining === 0) {
|
||||
form.attr("onsubmit", "");
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function logExternalApi(apiName, idkey, psidx, result, message) {
|
||||
ajax_call("/include/ajax_contact.asp", {
|
||||
"CRUD": "INSERT",
|
||||
"COMMAND": "EXTERNAL_API_LOG",
|
||||
"API_NAME": apiName,
|
||||
"PKEY": kon.survey.PKEY,
|
||||
"IDKEY": idkey,
|
||||
"PSIDX": psidx == null ? "" : psidx,
|
||||
"RESULT": result,
|
||||
"HTTP_MESSAGE": message || ""
|
||||
});
|
||||
}
|
||||
|
||||
function apiErrorMessage(x, h, r) {
|
||||
return "HTTP " + x.status + " | " + (r || h) + " | " + (x.responseText || "");
|
||||
}
|
||||
|
||||
function callLoggedApi(url, apiName, idkey, psidx, message) {
|
||||
var prefix = message ? message + " | " : "";
|
||||
logExternalApi(apiName, idkey, psidx, "REQUEST", message);
|
||||
return $.ajax({
|
||||
url: url,
|
||||
type: "POST",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
cache: false,
|
||||
async: true,
|
||||
timeout: 30000,
|
||||
success: function (data, h, x) {
|
||||
logExternalApi(apiName, idkey, psidx, "SUCCESS", prefix + "HTTP " + x.status);
|
||||
},
|
||||
error: function (x, h, r) {
|
||||
logExternalApi(apiName, idkey, psidx, "FAIL", prefix + apiErrorMessage(x, h, r));
|
||||
console.log(x);
|
||||
console.log(h);
|
||||
console.log(r);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function callContactStatusApi(contactMappingList, idkey, statuses) {
|
||||
var allRequestsDone = $.Deferred();
|
||||
var mappingsLeft = contactMappingList.length;
|
||||
|
||||
function finishMapping() {
|
||||
mappingsLeft--;
|
||||
if (mappingsLeft === 0) allRequestsDone.resolve();
|
||||
}
|
||||
|
||||
contactMappingList.forEach(function (mapping) {
|
||||
var targetSystem = String(mapping.TARGET_SYSTEM || "").toUpperCase();
|
||||
@@ -165,42 +210,54 @@ kon.survey = (function () {
|
||||
case "PROD":
|
||||
contactBaseUrl = "https://contact.kric.com";
|
||||
break;
|
||||
|
||||
case "DEV":
|
||||
contactBaseUrl = "https://test-contact.kric.com";
|
||||
break;
|
||||
|
||||
case "LOCAL":
|
||||
contactBaseUrl = "http://localhost:4000";
|
||||
break;
|
||||
|
||||
default:
|
||||
console.error("지원하지 않는 TARGET_SYSTEM:", mapping.TARGET_SYSTEM);
|
||||
finishMapping();
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: contactBaseUrl + contactRouteUrl + status
|
||||
+ "?psidx=" + encodeURIComponent(mapping.PSIDX)
|
||||
+ "&sid=" + encodeURIComponent(idkey),
|
||||
type: "POST",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
cache: false,
|
||||
async: true,
|
||||
error: function (x, h, r) {
|
||||
console.log(x);
|
||||
console.log(h);
|
||||
console.log(r);
|
||||
var nextStatusIndex = 0;
|
||||
|
||||
// 같은 매핑의 상태는 start 다음 complete 순서로 호출한다.
|
||||
function sendNextStatus() {
|
||||
if (nextStatusIndex >= statuses.length) {
|
||||
finishMapping();
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
var status = statuses[nextStatusIndex];
|
||||
nextStatusIndex++;
|
||||
|
||||
var contactApiUrl = contactBaseUrl + "/api/external/" + status
|
||||
+ "?psidx=" + encodeURIComponent(mapping.PSIDX)
|
||||
+ "&sid=" + encodeURIComponent(idkey);
|
||||
|
||||
callLoggedApi(
|
||||
contactApiUrl,
|
||||
"CONTACT_" + status.toUpperCase(),
|
||||
idkey,
|
||||
mapping.PSIDX,
|
||||
"TARGET_SYSTEM=" + targetSystem
|
||||
).always(sendNextStatus);
|
||||
}
|
||||
|
||||
sendNextStatus();
|
||||
});
|
||||
|
||||
return allRequestsDone.promise();
|
||||
}
|
||||
|
||||
function serializeform(form,arr) { /* 폼 데이터 정렬 */
|
||||
var data = {}
|
||||
var inputdata = {}
|
||||
/* 기본 인풋 제외 */
|
||||
var basis_info = ["USEPREV", "PAGENAME", "NEXTPAGE", "PCODE", "IDKEY", "SURVEYTYPE", "QNUMBER", "PCOLOR", "ROTATION","GLOBALVARIABLE","GLOBALSURVEY","CAMPAIGNID","TK","SPRINGID"];
|
||||
var basis_info = ["USEPREV", "PAGENAME", "NEXTPAGE", "PCODE", "IDKEY", "SURVEYTYPE", "QNUMBER", "PCOLOR", "ROTATION","GLOBALVARIABLE","GLOBALSURVEY","CAMPAIGNID","TK","SPRINGID", "CONTACTPID"];
|
||||
|
||||
if(arr) {
|
||||
if(typeof(arr) === "string") arr = [arr];
|
||||
|
||||
Reference in New Issue
Block a user