Example #1
0
        private AppXmlExecResult Do_NextDay_Cancel_Process(EaiContext context, string correlationID, string txID, HostTxDef txDef, XmlDocument requestXml)
        {
            try
            {
                string mbRs  = string.Empty;
                string msgId = "IB.INCOPR.TFR";
                #region 擷取撤銷電文欄位
                string C_FT_RefNo = string.Empty;
                string IntAcctNo  = string.Empty;
                string DebAcctNo  = string.Empty;
                string CoCode     = string.Empty;
                #endregion 擷取撤銷電文欄位
                #region 要從IBNextIntTrans取的欄位
                string RecId     = string.Empty;
                string Status    = string.Empty;
                string ValueDate = string.Empty;
                string MSMQ_BTID = string.Empty;
                #endregion 要從IBNextIntTrans取的欄位
                #region 扣帳交易Rsponse欄位
                string RsRecId     = string.Empty;
                string RsDebCusNo  = string.Empty;
                string RsDebAcctNo = string.Empty;
                string RsCreAcctNo = string.Empty;
                string RsDebCur    = string.Empty;
                string RsAmt       = string.Empty;
                string RsValueDate = string.Empty;
                string RsReference = string.Empty;
                string RsTransGate = string.Empty;
                #endregion 扣帳交易回傳值
                #region 交易結果回覆&錯誤訊息
                string RtSuccCode = "E-000000";
                string RtFailCode = "E-005000";
                string RtFailMsg  = "FAIL";
                string RtSuccMsg  = "SUCC";
                string RtFailMsg1 = "撤销失败,状态不可撤销";
                string RtFailMsg2 = "撤销失败,帐务交易不成功";
                string RtFailMsg3 = "撤销失败,系统错误";
                #endregion 交易結果回覆&錯誤訊息

                XmlHelper xmlHelper = XmlHelper.GetInstance(requestXml);
                xmlHelper.SetMultipleXPath(requestXml, "//MsgId", msgId);                // 將轉帳撤銷MsgId做轉換

                C_FT_RefNo = xmlHelper.GetXPath(requestXml, "//C_ORG_FT_REF_NO").Trim(); //此欄會帶之前扣帳的流水號
                IntAcctNo  = xmlHelper.GetXPath(requestXml, "//CREDIT_ACCT_NO").Trim();  //CNY1406100010002
                DebAcctNo  = xmlHelper.GetXPath(requestXml, "//C_PAYER_ACCT_NO").Trim(); //000281000012504
                CoCode     = xmlHelper.GetXPath(requestXml, "//SIGN_ON_BRH").Trim();

                DataSet dataSet = DBLog.SelectIBNextIntTransAll(C_FT_RefNo);
                List <Dictionary <string, string> > nextDayDataRowList = DatasetToDiclist(dataSet);
                Dictionary <string, string>         nextDayDataRow     = new Dictionary <string, string>();
                if (nextDayDataRowList.Count > 0)
                {
                    nextDayDataRow = nextDayDataRowList[0];
                }

                nextDayDataRow.TryGetValue("RecId", out RecId);
                nextDayDataRow.TryGetValue("Status", out Status);
                nextDayDataRow.TryGetValue("ValueDate", out ValueDate);
                nextDayDataRow.TryGetValue("MSMQ_BTID", out MSMQ_BTID);
                int tbStatus = Convert.ToInt32(Status);

                #region 判斷IBNextIntTrans之Status為0或1(0:繼續流程/1:回覆撤銷失敗訊息1)
                if (tbStatus == (int)IBNextIntTransStatus.ALLOW_REVERSE)
                {
                    #region 1.將Status由0改為1,若更新失敗(updateSuccess = 0)則回覆訊息3
                    int updateIBNextStatus = DBLog.UpdateNextIntTransStatus((int)IBNextIntTransStatus.NOT_REVERSE, RecId);
                    int updateMSMQStatus   = DBLog.UpdateNextDayMSMQStatus((int)NextDayMSMQStatus.CANCEL, MSMQ_BTID);
                    if (updateIBNextStatus == 0 || updateMSMQStatus == 0)
                    {
                        //回覆撤銷失敗,系統錯誤(訊息3)
                        mbRs = GetNextDayCancelRS(RtFailMsg, RtFailCode, RtFailMsg3);
                        XmlDocument responseXml = base.TransformCommMsg("0", "Info", "交易完成", mbRs);
                        return(base.BuildExecResult(context, responseXml));
                    }
                    #endregion

                    #region 2.將原電文欄位調整後送T24扣帳
                    xmlHelper.SetMultipleXPath(requestXml, "//MsgId", msgId);
                    xmlHelper.SetMultipleXPath(requestXml, "//DEBIT_ACCT_NO", IntAcctNo);
                    xmlHelper.SetMultipleXPath(requestXml, "//CREDIT_ACCT_NO", DebAcctNo);

                    string strT24DataXmlRQ = RemoveNamespace(xmlHelper.SelectSingleNode(requestXml, "//T24_DATA").OuterXml);
                    m_log.Info("Do_NextDay_Cancel_Process>>>>>>IB.INCOPR.TFR>>>>>>strT24DataXmlRQ : {0} ", strT24DataXmlRQ);

                    AppXmlExecResult t24_result     = SendMsgToEAIProcess(context, strT24DataXmlRQ, msgId, true);
                    XmlHelper        xmlHelperT24RS = XmlHelper.GetInstance(t24_result.ResponseXml);

                    string rs_Code  = xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//ITF_RETURN_CODE");
                    string rs_Msg   = xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//ITF_RETURN_MSG");
                    string proc_ret = xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//RSP_PROC_RET");

                    XmlNodeList xNodeT24DataRS  = t24_result.ResponseXml.GetElementsByTagName("T24_DATA");
                    string      strT24DataXmlRS = (xNodeT24DataRS.Count > 0) ? xNodeT24DataRS[0].InnerXml : string.Empty;
                    m_log.Info("Do_NextDay_Cancel_Process>>>>>>IB.INCOPR.TFR>>>>>>strT24DataXmlRS : {0} ", strT24DataXmlRS);

                    #region a.扣帳成功,依交易日期判斷是否發限額限筆
                    if (rs_Code == "E-000000" && proc_ret == "SUCC")
                    {
                        RsValueDate = xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//DEBIT_VALUE_DATE"); //扣帳回覆之交易日期

                        #region a-1.若扣帳RS的交易日期與表中ValueDate為同日,需另發限額限筆
                        if (ValueDate == RsValueDate)
                        {
                            RsReference = xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//RSP_TXN_ID").Trim(); //扣帳回覆之FT流水號
                            RsDebCusNo  = xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//DEBIT_CUSTOMER").Trim();
                            RsDebAcctNo = xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//DEBIT_ACCT_NO").Trim();
                            RsCreAcctNo = xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//CREDIT_ACCT_NO").Trim();
                            RsAmt       = xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//DEBIT_AMOUNT").Trim();
                            RsDebCur    = xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//DEBIT_CURRENCY").Trim();
                            RsTransGate = GetTransGateMapping(xmlHelperT24RS.GetXPath(t24_result.ResponseXml, "//L_TRANS_GATE").Trim());
                            RsRecId     = string.Format("{0}.{1}.{2}", RsDebAcctNo, RsValueDate, RsReference); //限額限筆紀錄的RECID

                            //組ESCN.BP.DEBIT.LIMIT(限額限筆)報文
                            string t24DataXmlDebLimRQ = GetT24_DebLim_Content(CoCode, "I", RsRecId, RsDebCusNo, RsDebAcctNo, RsCreAcctNo, RsDebCur, RsAmt, RsValueDate, RsReference, RsTransGate);
                            m_log.Info("ESCN.BP.DEBIT.LIMIT報文 : {0} ", t24DataXmlDebLimRQ);

                            #region 發送限額限筆紀錄
                            AppXmlExecResult t24_DebLimResult     = SendMsgToEAIProcess(context, t24DataXmlDebLimRQ, "ESCN.BP.DEBIT.LIMIT", true);
                            XmlHelper        xmlHelperT24DebLimRS = XmlHelper.GetInstance(t24_DebLimResult.ResponseXml);
                            string           debLim_RsCode        = xmlHelperT24DebLimRS.GetXPath(t24_DebLimResult.ResponseXml, "//ITF_RETURN_CODE");
                            string           debLim_RsMsg         = xmlHelperT24DebLimRS.GetXPath(t24_DebLimResult.ResponseXml, "//ITF_RETURN_MSG");
                            string           debLim_ProcRet       = xmlHelperT24DebLimRS.GetXPath(t24_DebLimResult.ResponseXml, "//RSP_PROC_RET");

                            if (debLim_RsCode != "E-000000" && debLim_ProcRet != "SUCC")
                            {
                                //寄信 SendErrorMail
                                new SendMail().Send(string.Format("{0} Do_NextDay_Cancel_Process >>>>>> Do ESCN.BP.DEBIT.LIMIT Error", txID), "", string.Format("{0} Error, PLS Check RQ:[{1}]", txID, context.RequestXml.OuterXml));
                                m_log.Error("Do_NextDay_Cancel_Process Fail >>>>>> Do ESCN.BP.DEBIT.LIMIT Error!!! debLim_RsCode=[{0}] debLim_ProcRet=[{1}]", debLim_RsCode, debLim_ProcRet);
                            }
                            #endregion
                            //回覆撤銷成功
                            mbRs = GetNextDayCancelRS(RtSuccMsg, RtSuccCode, RtSuccMsg);
                            XmlDocument responseXml = base.TransformCommMsg("0", "Info", "交易完成", mbRs);
                            return(base.BuildExecResult(context, responseXml));
                        }
                        #endregion

                        #region a-2.無須限額限筆,直接回覆撤銷成功
                        else
                        {
                            //回覆撤銷成功
                            mbRs = GetNextDayCancelRS(RtSuccMsg, RtSuccCode, RtSuccMsg);
                            XmlDocument responseXml = base.TransformCommMsg("0", "Info", "交易完成", mbRs);
                            return(base.BuildExecResult(context, responseXml));
                        }
                        #endregion 無須限額限筆,直接回覆撤銷成功
                    }
                    #endregion a.扣帳成功,依交易日期判斷是否發限額限筆

                    #region b.扣帳失敗,無須發限額限筆(將Status從1改回0)
                    else
                    {
                        //1.將IBNextIntTrans>Status由1改為0,BroadcastMSMQTalk>Status由990改為999,回覆撤銷失敗,帳務交易不成功(訊息2)
                        updateIBNextStatus = DBLog.UpdateNextIntTransStatus((int)IBNextIntTransStatus.ALLOW_REVERSE, RecId);
                        updateMSMQStatus   = DBLog.UpdateNextDayMSMQStatus((int)NextDayMSMQStatus.TRANS, MSMQ_BTID);
                        mbRs = GetNextDayCancelRS(RtFailMsg, RtFailCode, RtFailMsg2);
                        if (updateIBNextStatus == 0 || updateMSMQStatus == 0)
                        {
                            //交易失敗且Status更新失敗
                            new SendMail().Send(string.Format("{0} Do_NextDay_Cancel_Process >>>>>> IB.INCOPR.TFR & UpdateTable Error", txID), "", string.Format("{0} Error, PLS Check RQ:[{1}]", txID, context.RequestXml.OuterXml));
                            m_log.Error("Do_NextDay_Cancel_Process Fail >>>>>> IB.INCOPR.TFR & UpdateTable Error!!! updateIBNextStatus=[{0}] updateMSMQStatus=[{1}]", updateIBNextStatus, updateMSMQStatus);
                            mbRs = GetNextDayCancelRS(RtFailMsg, RtFailCode, RtFailMsg3);
                        }
                        XmlDocument responseXml = base.TransformCommMsg("0", "Info", "交易完成", mbRs);
                        return(base.BuildExecResult(context, responseXml));
                    }
                    #endregion b.扣帳失敗,無須發限額限筆(將Status從1改回0)

                    #endregion 2.將原電文欄位調整後送T24扣帳
                }
                else
                {
                    //查回的Status已經為1,回覆撤銷失敗,系統錯誤(訊息1)
                    mbRs = GetNextDayCancelRS(RtFailMsg, RtFailCode, RtFailMsg1);
                    XmlDocument responseXml = base.TransformCommMsg("0", "Info", "交易完成", mbRs);
                    return(base.BuildExecResult(context, responseXml));
                }
                #endregion 判斷IBNextIntTrans之Status為0或1(0:繼續流程/1:回覆撤銷失敗訊息1)
            }
            catch (Exception ex)
            {
                m_log.ErrorException(string.Format("Do_NextDay_Cancel_Process Error ! TXID=[{0}] ", txID) + ex.ToString(), ex);
                XmlDocument responseXml = base.TransformCommMsg("99999", "Error", ex.Message, "");
                return(base.BuildExecResult(context, responseXml));
            }
        }