Переглянути джерело

Z991239-6468 #comment feat: 优化卡库卡机和非接读卡异常信息上送

Signed-Off-By: commit-hook
刘文涛80174520 3 місяців тому
батько
коміт
51e28fba8f

+ 56 - 85
Module/mod_ContactlessCard/ContactlessFSM.cpp

@@ -993,27 +993,14 @@ int CContactlessCardFSM::AcceptCard(SpReqAnsContext<ContactlessCardService_Inser
 			}
 			if (retDetectAndRead < 0)
 			{
-				// -1和-2是上电或APDU交互失败,功能集循环调用
-				if (retDetectAndRead == -1){
-					
-					if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-						SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_ActiveContactlessICCard, "DevAdapter::ActiveContactlessICCard", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-					}
-					ctx->Answer(Error_Interact, GetAlarmDEC());
-				}
-				else if (retDetectAndRead == -2){
-					
-					if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-						SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-					}
-					ctx->Answer(Error_Interact, GetAlarmDEC());
-				}else if (retDetectAndRead == -3){
-					
-					if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-						SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-					}
-					ctx->Answer(Error_Interact, GetAlarmDEC());
+				DWORD dwDevApiCode = 0;
+				CSimpleStringA csDevApiName("");
+				GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+				if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
+					SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, "", "");
 				}
+				ctx->Answer(Error_Interact, GetAlarmDEC());
+
 				return 2;
 			}
 			ctx->Ans.t2Account = ctx->Ans.ICData = "";
@@ -1180,24 +1167,14 @@ int CContactlessCardFSM::PreOnline(SpReqAnsContext<ContactlessCardService_PreOnl
 	}
 	if (retDetectAndRead < 0)
 	{
-		// -1和-2是上电或APDU交互失败,功能集循环调用
-		if (retDetectAndRead == -1){
-			if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_ActiveContactlessICCard, "DevAdapter::ActiveContactlessICCard", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			}
-			ctx->Answer(Error_Interact, GetAlarmDEC());
-		}
-		else if (retDetectAndRead == -2){
-			if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			}
-			ctx->Answer(Error_Interact, GetAlarmDEC());
-		}else if (retDetectAndRead == -3){
-			if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			}
-			ctx->Answer(Error_Interact, GetAlarmDEC());
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
+			SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, "", "");
 		}
+		ctx->Answer(Error_Interact, GetAlarmDEC());
+
 		return 0;
 	}
 	m_pCardProcess->TermRiskManage();
@@ -1554,39 +1531,6 @@ bool CContactlessCardFSM::LoadCMBPrint(CSimpleStringA csBinPath)
 	return result;
 }
 
-void CContactlessCardFSM::GetCardProcessLastErr(ErrorCodeEnum& eErrCode, CSimpleStringA& ApiName, CSimpleStringA& alarmMsg, CSimpleStringA& csErrMsgWithReturnCode)
-{
-	if (m_pCardProcess == NULL) {
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetCardProcessLastErr m_pCardProcess is null");
-		eErrCode = Error_Null;
-		ApiName = "";
-		alarmMsg = "";
-		csErrMsgWithReturnCode = "";
-		return;
-	}
-
-	ErrorCodeEnum lastErrCode = Error_Succeed;
-	CSimpleStringA lastErrMsg = "";
-	CSimpleStringA lastApiName = "";
-	m_pCardProcess->getCardAssistLastErr(lastErrCode, lastErrMsg, lastApiName);
-
-	const CSimpleStringA alarmMsgStr = CSimpleStringA::Format("{\"Function\":\"%s\", \"DevApi\":\"%s\", \"ReturnCode\":\"%s\", \"Msg\":\"%s\", \"Context\":\"%s\"}"
-		, __FUNCTION__, lastApiName.GetData(), SpStrError(lastErrCode), lastErrMsg.GetData(), "");
-
-	std::map<std::string, std::string> msgInfo;
-	msgInfo["ReturnCode"] = SpStrError(lastErrCode);
-	msgInfo["ErrMsg"] = lastErrMsg.GetData();
-	msgInfo["Context"] = "";
-	std::pair<bool, std::string> strResult;
-	strResult = generateJsonStr(msgInfo);
-	CSimpleStringA csErrMsgWithReturnCodeStr = strResult.second.c_str();
-
-	eErrCode = lastErrCode;
-	ApiName = lastApiName;
-	alarmMsg = alarmMsgStr.GetData();
-	csErrMsgWithReturnCode = csErrMsgWithReturnCodeStr.GetData();
-}
-
 DWORD CContactlessCardFSM::GetFsmStateErrCode()
 {
 	int state = GetFSMState();
@@ -1807,10 +1751,10 @@ int CContactlessCardFSM::InternalAcceptCardJS()
 				LogEvent(Severity_Middle, LOG_EVT_CONTACTLESS_CARD_OP, "Contactless card op.");
 
 				int activeCardType;
-				l_beginTime = SP::Module::Comm::RVCGetTickCount();
-				bool bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_RFIC, m_hDevHelper, activeCardType);
+				l_beginTime = SP::Module::Comm::RVCGetTickCount();				 
+				int bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_RFIC, m_hDevHelper, activeCardType);
 				l_endTime = SP::Module::Comm::RVCGetTickCount();
-				if (bIC) {
+				if (bIC == 0) {
 					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("InternalAcceptCardJS::DetectIfICCard activeCardType=%d", activeCardType);
 					if (activeCardType == 'A' || activeCardType == 'B' || activeCardType == 'M') {
 						err = 0;//探测到IC卡
@@ -1900,18 +1844,13 @@ int CContactlessCardFSM::PreOnlineJS(SpReqAnsContext<ContactlessCardService_Read
 	if (retDetectAndRead < 0)
 	{
 		ctx->Ans.icState = 0;//调用失败
-		if (retDetectAndRead == -1) {
-			DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_ActiveContactlessICCard, "DevAdapter::ActiveContactlessICCard", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			ctx->Answer(Error_Exception, dwTmpUserErrCode);
-		}
-		else if (retDetectAndRead == -2) {
-			DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			ctx->Answer(Error_Exception, dwTmpUserErrCode);
-		}
-		else if (retDetectAndRead == -3) {
-			DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			ctx->Answer(Error_Exception, dwTmpUserErrCode);
-		}
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+
+		DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, "", "");
+		ctx->Answer(Error_Exception, dwTmpUserErrCode);
+
 		return -1;
 	}
 
@@ -2127,6 +2066,38 @@ int CContactlessCardFSM::PreOnlineJS(SpReqAnsContext<ContactlessCardService_Read
 
 }
 
+void CContactlessCardFSM::GetDevApiCodeAndName(int retValue, DWORD& dwDevApiCode, CSimpleStringA& csDevApiName)
+{
+	switch (retValue)
+	{
+	case -1:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ContactIC;
+		csDevApiName = "DevAdapter::ContactIC";
+		break;
+	case -2:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ActiveICCard;
+		csDevApiName = "DevAdapter::ActiveICCard";
+		break;
+	case -3:
+		dwDevApiCode = MEC_DEVAPI_RF_ActiveContactlessICCard;
+		csDevApiName = "DevAdapter::ActiveContactlessICCard";
+		break;
+	case -4:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ICCommand;
+		csDevApiName = "DevAdapter::ICCommand";
+		break;
+	case -5:
+		dwDevApiCode = MEC_DEVAPI_RF_RFTypeABCommand;
+		csDevApiName = "DevAdapter::RFTypeABCommand";
+		break;
+	default:
+		dwDevApiCode = DEC_NO_E_CARDISSUER_START;
+		csDevApiName = "DevAdapter::SthWrong";
+		break;
+	}
+	return;
+}
+
 void CContactlessCardFSM::OnStateTrans(int iSrcState, int iDstState)
 {
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("trans from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));

+ 2 - 2
Module/mod_ContactlessCard/ContactlessFSM.h

@@ -348,7 +348,7 @@ public:
 	void SetWaitMore(){m_bWaitAccepteMore = true;}
 	void SetExitFlag(bool bFlag=true){m_bExit = bFlag;}
 	bool LoadCMBPrint(CSimpleStringA csBinPath);
-	void GetCardProcessLastErr(ErrorCodeEnum& eErrCode, CSimpleStringA& lastApiName, CSimpleStringA& alarmMsg, CSimpleStringA& csErrMsgWithReturnCode);
+	
 
 	void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
 	{
@@ -378,7 +378,7 @@ public:
 		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("rtaMsg=%s",rtaMsg.GetData());
 		return rtaMsg;
 	}
-
+	void GetDevApiCodeAndName(int retValue, DWORD& dwDevApiCode, CSimpleStringA& csDevApiName);
 protected:
 	int m_iInsertTries;
 	int m_resetTries;

+ 170 - 500
Module/mod_cardissuerstore/CardIssuerStoreFSM.cpp

@@ -2878,30 +2878,23 @@ int CCardIssuerFSM::ReadCard_Contact(SpReqAnsContext<CardIssuerStoreService_Read
 		}
 		else//未访问户口系统或户口系统访问失败或户口未告知介质类型(包括插反卡)
 		{
-			int icRetryTimes = 0;
-			while (1)
-			{//for poor mag only card,we always retry...
-				l_beginTime = RVCGetTickCount();
-				bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
-				l_endTime = RVCGetTickCount();
-				if (!bIC)
-					icRetryTimes++;
-				else
-					break;
-				Sleep(500);
-				if (icRetryTimes >= m_ICRetryTimes)
-					break;
+
+			l_beginTime = RVCGetTickCount();
+			int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
+			l_endTime = RVCGetTickCount();
+
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<ReadCard::DetectIfICCard>, retDetect:%d", retDetect);
+			if (retDetect == 0) {
+				bIC = true;
 			}
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<ReadCard::DetectIfICCard>, bIC:%d", bIC);
-			if (!bIC) {
-				ErrorCodeEnum eErrCode = Error_Unexpect;
-				CSimpleStringA ApiName = "";
-				CSimpleStringA alarmMsg = "";
-				CSimpleStringA csErrMsgWithReturnCode = "";
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WCT")(csErrMsgWithReturnCode.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, 0x2200000a, alarmMsg.GetData());
+			else {
+				bIC = false;
+				CSimpleStringA csDevApi("");
+				DWORD dwDevApi = 0;
+				GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+				SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 			}
+
 			if (Error_Succeed == eMagReadErr && magTracks.track[1].eStatus == CI_DATA_OK)
 			{
 				if (bIC)
@@ -3159,30 +3152,24 @@ int CCardIssuerFSM::ReadCard_RF(SpReqAnsContext<CardIssuerStoreService_Read_Req,
 		}
 		else//未访问户口系统或户口系统访问失败(包括插反卡)
 		{
-			int icRetryTimes = 0;
-			while (1)
-			{//for poor mag only card,we always retry...
-				l_beginTime = RVCGetTickCount();
-				bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE_RF, m_hDevHelper, activeCardType);
-				l_endTime = RVCGetTickCount();
-				if (!bIC)
-					icRetryTimes++;
-				else
-					break;
-				Sleep(500);
-				if (icRetryTimes >= m_ICRetryTimes)
-					break;
+
+			l_beginTime = RVCGetTickCount();
+			int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE_RF, m_hDevHelper, activeCardType);
+			l_endTime = RVCGetTickCount();
+
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<ReadCard::DetectIfICCard>, retDetect:%d", retDetect);
+
+			if (retDetect == 0) {
+				bIC = true;
 			}
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<ReadCard::DetectIfICCard>, bIC:%d", bIC);
-			if (!bIC) {
-				ErrorCodeEnum eErrCode = Error_Unexpect;
-				CSimpleStringA ApiName = "";
-				CSimpleStringA alarmMsg = "";
-				CSimpleStringA csErrMsgWithReturnCode = "";
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WC6")(csErrMsgWithReturnCode.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, 0x22000017, alarmMsg.GetData());
+			else {
+				bIC = false;
+				CSimpleStringA csDevApi("");
+				DWORD dwDevApi = 0;
+				GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+				SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 			}
+
 			if (!(bIC && activeCardType == 'A'))
 				bIC = false;
 			if (Error_Succeed == eMagReadErr && magTracks.track[1].eStatus == CI_DATA_OK)
@@ -3517,138 +3504,32 @@ int CCardIssuerFSM::PreOnline_Contact(SpReqAnsContext<CardIssuerStoreService_Pre
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<PreOnline>, After invoke DetectAndReadICData, retDetectAndRead:%d, activeCardType:%d", retDetectAndRead, activeCardType);
 	if (retDetectAndRead < 0)
 	{
-		//if ((m_csMachineType.Compare("RVC.CardStore") == 0 || m_csMachineType.Compare("RVC.CardPrinter") == 0)
-		//	&& m_bCrossPreOnline) {
-		//	if (IfUseRf()) {
-		//		bContinue = true; //继续后面的非接流程
-		//	}
-		//	else {
-		//		AfterPreOnlineOnStore(Error_Unexpect, slot);
-		//	}
-		//}
-		CSimpleStringA xCardName("");
-		if (m_issueStatus && m_currentHopper - 1 >= 0)
-			xCardName = m_PsbNameEx[m_currentHopper - 1];
-
-
-		DWORD dwUserErrCode = 0;
-		if (retDetectAndRead == -1){
-
-			ErrorCodeEnum eErrCode = Error_Unexpect;
-			CSimpleStringA ApiName = "";
-			CSimpleStringA alarmMsg = "";
-			CSimpleStringA csErrMsgWithReturnCode = "";
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
 
-			if (m_issueStatus)
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("发卡时,检测卡片类型时上电失败");
-				if (!IfUseRf())
-				{
-					const DWORD dwCode(CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed);
-					if (IsInBusiness()) {
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222020").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, dwCode, alarmMsg.GetData());
-					}
-					else {
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222020").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, dwCode, alarmMsg.GetData());
-					}
-					dwUserErrCode = dwCode;
-					//ctx->Answer(Error_Unexpect, dwCode);
-				}
-				else {
-					//使用非接兜底
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222020").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-				}
-			}
-			else
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败");
-				if (!IfUseRf())
-				{
-					if (IsInBusiness())
-					{
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222003").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					else
-					{
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222003").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					dwUserErrCode = CardIssuerStore_UserErrorCode_ActiveICCard_Failed;
-					//ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed);
-				}
-				else {
-					//使用非接兜底
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222003").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-				}
-			}
+		//新的错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);
+		if (m_issueStatus) {
+			csLogCode = CardIssuerStoreService_LogCode_IssueEx;
 		}
-		else if (retDetectAndRead == -2){
-			
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-			if (!IfUseRf())
-			{
-				DWORD dwTmpUserErrCode = 0;
-				if (m_issueStatus) {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222020", "");
-				}
-				else {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222003", "");
-				}
-				dwUserErrCode = dwTmpUserErrCode;
-				//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-				
-			}
-			else {
-				//使用非接兜底
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222020", "");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222003", "");
-				}
-			}
+		else {
+			csLogCode = CardIssuerStoreService_LogCode_Read;
 		}
-		else if (retDetectAndRead == -3){
-
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-			if (!IfUseRf())
-			{
-				DWORD dwTmpUserErrCode = 0;
-				if (m_issueStatus) {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222020", "");
-				}
-				else {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222003", "");
-				}
-				dwUserErrCode = dwTmpUserErrCode;
-				//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-				
-			}
-			else {
-				//使用非接兜底
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222020", "");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222003", "");
-				}
-			}
 
+		DWORD dwUserErrCode = 0;
+		if (IfUseRf()) {
+			bContinue = true; //继续后面的非接流程
+			SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, csLogCode, csIssueContext);
 		}
+		else {
+			dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
 
-		if ((m_csMachineType.Compare("RVC.CardStore") == 0 || m_csMachineType.Compare("RVC.CardPrinter") == 0) && m_bCrossPreOnline) {
-			if (IfUseRf()) {
-				bContinue = true; //继续后面的非接流程
-			}
-			else {
+			//非接不兜底需要移回卡槽
+			if (m_bCrossPreOnline) {
 				AfterPreOnlineOnStore(Error_Unexpect, slot);
 			}
-		}
-		if (!IfUseRf()){
+
 			ctx->Answer(Error_Unexpect, dwUserErrCode);
 		}
 
@@ -3967,85 +3848,24 @@ int CCardIssuerFSM::PreOnline_RF(SpReqAnsContext<CardIssuerStoreService_PreOnlin
 	
 	if (retDetectAndRead < 0)
 	{
-		//非接兜底需要移回卡槽
-		//if ((m_csMachineType.Compare("RVC.CardStore") == 0 || m_csMachineType.Compare("RVC.CardPrinter") == 0) && m_bCrossPreOnline) {
-		//	AfterPreOnlineOnStore(Error_Unexpect, slot);//移回卡槽
-		//}
 
+		//新错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);
 
-		CSimpleStringA xCardName("");
-		if (m_issueStatus && m_currentHopper - 1 >= 0)
-			xCardName = m_PsbNameEx[m_currentHopper - 1];
-
-		DWORD dwUserErrCode = 0;
-		if (retDetectAndRead == -1) {
-
-			ErrorCodeEnum eErrCode = Error_Unexpect;
-			CSimpleStringA ApiName = "";
-			CSimpleStringA alarmMsg = "";
-			CSimpleStringA csErrMsgWithReturnCode = "";
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-			if (m_issueStatus)
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("发卡时检测卡片类型时上电失败(非接)");
-				if (IsInBusiness())
-				{
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222020").setResultCode("RTA2W27")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-				}
-				else
-				{
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222020").setResultCode("RTA2W27")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-				}
-				dwUserErrCode = CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed;
-				//ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed);
-			}
-			else
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败(非接)");
-				if (IsInBusiness())
-				{
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222003").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-				}
-				else
-				{
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222003").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-				}
-				dwUserErrCode = CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed;
-				//ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed);
-			}
+		if (m_issueStatus) {
+			csLogCode = CardIssuerStoreService_LogCode_IssueEx;
 		}
-		else if (retDetectAndRead == -2) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-			DWORD dwTmpUserErrCode = 0;
-			if (m_issueStatus) {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222020", "");
-			}
-			else {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222003", "");
-			}
-			dwUserErrCode = dwTmpUserErrCode;
-			//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-		}
-		else if (retDetectAndRead == -3) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-			DWORD dwTmpUserErrCode = 0;
-			if (m_issueStatus) {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222020", "");
-			}
-			else {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222003", "");
-			}
-			dwUserErrCode = dwTmpUserErrCode;
-			//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
+		else {
+			csLogCode = CardIssuerStoreService_LogCode_Read;
 		}
 
+		DWORD dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
+
 		//非接兜底需要移回卡槽
-		if ((m_csMachineType.Compare("RVC.CardStore") == 0 || m_csMachineType.Compare("RVC.CardPrinter") == 0) && m_bCrossPreOnline) {
+		if (m_bCrossPreOnline) {
 			AfterPreOnlineOnStore(Error_Unexpect, slot);//移回卡槽
 		}
 
@@ -4881,18 +4701,20 @@ bool CCardIssuerFSM::JustReadCardNo()
 	m_currCardNo = "";
 	bool bHasAccount = false;
 	int activeCardType;
+	bool bIC = false;
 	l_beginTime = RVCGetTickCount();
-	bool bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
+	int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
 	l_endTime = RVCGetTickCount();
-	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DetectIfICCard, bIC:%d, activeCardType:%d", bIC, activeCardType);
 
-	if (bIC)
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DetectIfICCard, retDetect:%d, activeCardType:%d", retDetect, activeCardType);
+
+	if (retDetect == 0)
 	{
 		//oilyang@20201014 add emv support
-		int bGetICData = m_pCardProcess->GetICDataFromCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, m_aidList);
-		if(bGetICData != 0)
+		bool bGetICData = m_pCardProcess->GetICDataFromCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, m_aidList);
+		if(!bGetICData)
 		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("<JustReadCardNo::GetICDataFromCard> faile(%d)", bGetICData);
+			SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime);
 		}
 		ICData track2(false, 0x57, 0x00);
 		string t2ICAccount(""), t2ICCardSerial(""), t2ICCVC(""), t2ICTrack2(""), cardType;
@@ -4945,14 +4767,12 @@ bool CCardIssuerFSM::JustReadCardNo()
 		}
 	}
 	else {
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
-		GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WCT")(csErrMsgWithReturnCode.GetData());
-		LogWarn(Severity_Middle, Error_Unexpect, 0x2200000a, alarmMsg.GetData());
+		CSimpleStringA csDevApi("");
+		DWORD dwDevApi = 0;
+		GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+		SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 	}
+
 	if (!bHasAccount)
 	{
 		MagTracks magTracks;
@@ -8754,6 +8574,38 @@ int CCardIssuerFSM::ReadJS(SpReqAnsContext<CardIssuerStoreService_ReadJS_Req, Ca
 	}
 }
 
+void CCardIssuerFSM::GetDevApiCodeAndName(int retValue, DWORD& dwDevApiCode, CSimpleStringA& csDevApiName)
+{
+	switch (retValue)
+	{
+	case -1:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ContactIC;
+		csDevApiName = "DevAdapter::ContactIC";
+		break;
+	case -2:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ActiveICCard;
+		csDevApiName = "DevAdapter::ActiveICCard";
+		break;
+	case -3:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ActiveContactlessICCard;
+		csDevApiName = "DevAdapter::ActiveContactlessICCard";
+		break;
+	case -4:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ICCommand;
+		csDevApiName = "DevAdapter::ICCommand";
+		break;
+	case -5:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_RFTypeABCommand;
+		csDevApiName = "DevAdapter::RFTypeABCommand";
+		break;
+	default:
+		dwDevApiCode = DEC_NO_E_CARDISSUER_START;
+		csDevApiName = "DevAdapter::SthWrong";
+		break;
+	}
+	return;
+}
+
 DWORD CCardIssuerFSM::GetFsmStateErrCode()
 {
 	int state = GetFSMState();
@@ -9080,30 +8932,21 @@ int CCardIssuerFSM::CheckCardType(CSimpleStringA cardNo, bool bReadMag, int& ICt
 			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<CheckCardType>, begin detect cardType");
 			//主动探测
 			int activeCardType;
-			int icRetryTimes = 0;
 			bool bIC(false);
-			while (1)
-			{//for poor mag only card,we always retry...
-				l_beginTime = RVCGetTickCount();
-				bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
-				l_endTime = RVCGetTickCount();
-				if (!bIC)
-					icRetryTimes++;
-				else
-					break;
-				Sleep(500);
-				if (icRetryTimes >= m_ICRetryTimes)
-					break;
+			l_beginTime = RVCGetTickCount();
+			int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
+			l_endTime = RVCGetTickCount();
+
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<CheckCardType::DetectIfICCard>, retDetect:%d", retDetect);
+			if (retDetect == 0) {
+				bIC = true;
 			}
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<CheckCardType::DetectIfICCard>, bIC:%d", bIC);
-			if (!bIC) {
-				ErrorCodeEnum eErrCode = Error_Unexpect;
-				CSimpleStringA ApiName = "";
-				CSimpleStringA alarmMsg = "";
-				CSimpleStringA csErrMsgWithReturnCode = "";
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WCT")(csErrMsgWithReturnCode.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, 0x2200000a, alarmMsg.GetData());
+			else {
+				bIC = false;
+				CSimpleStringA csDevApi("");
+				DWORD dwDevApi = 0;
+				GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+				SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 			}
 
 			//ic探测成功,0.无磁条IC 1.复合 2.磁条 3.纯IC 
@@ -9167,28 +9010,20 @@ int CCardIssuerFSM::CheckCardType(CSimpleStringA cardNo, bool bReadMag, int& ICt
 						DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DevAdapter::MoveCard").setCostTime(l_endTime - l_beginTime)("CheckCardType::MoveCard, (CI_MOVECARD_RF_POSITION)");
 					}
 
-					icRetryTimes = 0;
+					
 					bool bICRF(false);
-					while (1)
-					{//for poor mag only card,we always retry...
-						bICRF = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE_RF, m_hDevHelper, activeCardType);
-						if (!bICRF)
-							icRetryTimes++;
-						else
-							break;
-						Sleep(500);
-						if (icRetryTimes >= m_ICRetryTimes)
-							break;
-					}
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<CheckCardType::DetectIfICCard_RF>, bIC:%d", bICRF);
-					if (!bICRF) {
-						ErrorCodeEnum eErrCode = Error_Unexpect;
-						CSimpleStringA ApiName = "";
-						CSimpleStringA alarmMsg = "";
-						CSimpleStringA csErrMsgWithReturnCode = "";
-						GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WC6")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, 0x22000017, alarmMsg.GetData());
+
+					int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE_RF, m_hDevHelper, activeCardType);
+
+					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<CheckCardType::DetectIfICCard_RF>, retDetect:%d", retDetect);
+					if(retDetect == 0) {
+						bICRF = true;
+					}else{
+						bICRF = false;
+						CSimpleStringA csDevApi("");
+						DWORD dwDevApi = 0;
+						GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+						SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 					}
 
 					if (!(bICRF && activeCardType == 'A')) {
@@ -9301,74 +9136,24 @@ int CCardIssuerFSM::PreOnlineJS_Contact(SpReqAnsContext<CardIssuerStoreService_R
 
 	if (retDetectAndRead < 0)
 	{
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
 
+		//新的错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);//oiltmp
+		csLogCode = CardIssuerStoreService_LogCode_ReadJS;
+
+		DWORD dwUserErrCode = 0;
 		if (IfUseRf()) {
 			bContinue = true; //继续后面的非接流程
-			if (retDetectAndRead == -1) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败");
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-				if (m_issueStatus) {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed, alarmMsg.GetData());
-				}
-				else {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-				}
-			}
-			else if (retDetectAndRead == -2) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222040", "");
-			}
-			else if (retDetectAndRead == -3) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222040", "");
-			}
+			SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, csLogCode, csIssueContext);
 		}
 		else {
-			if (retDetectAndRead == -1) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败");
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-				if (m_issueStatus) {
-					if (IsInBusiness()) {
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					else {
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed);
-				}
-				else {
-					if (IsInBusiness()) {
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					else {
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed);
-				}
-			}
-			else if (retDetectAndRead == -2) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-				DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-				ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-			}
-			else if (retDetectAndRead == -3) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-				DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-				ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-			}
+			dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
+			ctx->Answer(Error_Unexpect, dwUserErrCode);
 		}
+
 		bICOK = false;
 		return 0;//上电读卡失败
 	}
@@ -9684,67 +9469,17 @@ int CCardIssuerFSM::PreOnlineJS_RF(SpReqAnsContext<CardIssuerStoreService_ReadJS
 
 	if (retDetectAndRead < 0)
 	{
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
-
-		if (retDetectAndRead == -1) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败(非接)");
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-			if (m_issueStatus) {
-				if (IsInBusiness())
-				{
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W27")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-				}
-				else {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W27")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-				}
-
-				ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed);
-			}
-			else {
-				if (IsInBusiness())
-				{
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-				}
-				else
-				{
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-				}
 
-				ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed);
-			}
-		}
-		else if (retDetectAndRead == -2) {
+		//新错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);//oiltmp
+		csLogCode = CardIssuerStoreService_LogCode_ReadJS;
 
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-			DWORD dwTmpUserErrCode = 0;
-			if (m_issueStatus) {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-			}
-			else {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-			}
-			ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-		}
-		else if (retDetectAndRead == -3) {
+		DWORD dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
+		ctx->Answer(Error_Unexpect, dwUserErrCode);
 
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-			DWORD dwTmpUserErrCode = 0;
-			if (m_issueStatus) {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-			}
-			else {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-			}
-			ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-		}
 		return 0;//上电读卡失败
 	}
 
@@ -10220,68 +9955,29 @@ int CCardIssuerFSM::PreOnlineCrossJS_Contact(SpReqAnsContext<CardIssuerStoreServ
 	
 	if (retDetectAndRead < 0)
 	{
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
+		//新的错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"reqSlot\":%d}", slot);//oiltmp
+		csLogCode = CardIssuerStoreService_LogCode_PreOnlineCrossJS;
 
+		DWORD dwUserErrCode = 0;
 		if (IfUseRf()) {
 			bContinue = true; //继续后面的非接流程
-			if (retDetectAndRead == -1) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机检测卡片类型时上电失败,slot:%d",slot);
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222052").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-			}
-			else if (retDetectAndRead == -2) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机读取IC数据失败,slot:%d", slot);
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222052", "");
-			}
-			else if (retDetectAndRead == -3) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机读取IC数据失败,slot:%d", slot);
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222052", "");
-			}
+			SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, csLogCode, csIssueContext);
 		}
 		else {
-			//CaptureResult = AfterPreOnlineCrossJS(slot, m_currCardNo);//执行移回操作
-			//m_findCard = 4;
-			//ctx->Ans.findCard = 4;
-			//ctx->Ans.cardPos = m_cardPos;
-			DWORD dwUserErrCode = 0;
-			if (retDetectAndRead == -1) {
-
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机检测卡片类型时上电失败,slot:%d", slot);
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-				if (IsInBusiness()) {
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222052").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-				}
-				else {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222052").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-				}
-				dwUserErrCode = CardIssuerStore_UserErrorCode_ActiveICCard_Failed;
-				//ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed);
-			}
-			else if (retDetectAndRead == -2) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机读取IC数据失败,slot:%d", slot);
-				dwUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222052", "");
-				//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-			}
-			else if (retDetectAndRead == -3) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机读取IC数据失败,slot:%d", slot);
-				dwUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222052", "");
-				//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-			}
+			dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
 
 			CaptureResult = AfterPreOnlineCrossJS(slot, m_currCardNo);//执行移回操作
 			m_findCard = 4;
 			ctx->Ans.findCard = 4;
 			ctx->Ans.cardPos = m_cardPos;
 
-			ctx->Answer(Error_Unexpect, dwUserErrCode);
+			ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
 		}
+
 		bICOK = false;
 		return 0;//上电读卡失败
 	}
@@ -10591,42 +10287,16 @@ int CCardIssuerFSM::PreOnlineCrossJS_RF(SpReqAnsContext<CardIssuerStoreService_P
 
 	if (retDetectAndRead < 0)
 	{
-		//CaptureResult = AfterPreOnlineCrossJS(slot, m_currCardNo);//执行移回操作
-		//m_findCard = 4;
-		//ctx->Ans.findCard = 4;
-		//ctx->Ans.cardPos = m_cardPos;
 
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
+		//新错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"reqSlot\":%d}", slot);//oiltmp
+		csLogCode = CardIssuerStoreService_LogCode_PreOnlineCrossJS;
 
-		DWORD dwUserErrCode = 0;
-		if (retDetectAndRead == -1) {	
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机非接检测卡片类型时上电失败,slot:%d", slot);
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
+		DWORD dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
 
-			if (IsInBusiness()) {
-				DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222052").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-				LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-			}
-			else {
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222052").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-			}
-			dwUserErrCode = CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed;
-			//ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed);		
-		}
-		else if (retDetectAndRead == -2) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机非接读取IC数据失败,slot:%d", slot);
-			dwUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222052", "");
-			//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-		}
-		else if (retDetectAndRead == -3) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机非接读取IC数据失败,slot:%d", slot);
-			dwUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222052", "");
-			//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-		}
 		CaptureResult = AfterPreOnlineCrossJS(slot, m_currCardNo);//执行移回操作
 		m_findCard = 4;
 		ctx->Ans.findCard = 4;

+ 3 - 0
Module/mod_cardissuerstore/CardIssuerStoreFSM.h

@@ -1470,6 +1470,7 @@ public:
 #pragma endregion JS接口具体实现方法
 
 #pragma region JS新增接口
+	void GetDevApiCodeAndName(int retValue, DWORD& dwDevApiCode, CSimpleStringA& csDevApiName);
 	DWORD GetFsmStateErrCode();
 	CSimpleStringA MaskCardno(const char* cardno);
 	int PostOnlineJS_Contact(SpReqAnsContext<CardIssuerStoreService_PostOnlineJS_Req, CardIssuerStoreService_PostOnlineJS_Ans>::Pointer ctx, bool& bICOK);
@@ -1508,6 +1509,8 @@ public:
 		result = CSimpleStringA::Format("{\"addition\": \"%s\"}", szMessage);
 		return  result;
 	}
+
+	
 #pragma endregion JS新增接口
 
 #pragma region JS新增字段