//------------------------------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------------------------------- /// <summary> /// 국세청으로 부터 전달 된 메시지를 기반으로 ISSUING, RESPONSE, RESULT 테이블을 Update 합니다. /// </summary> /// <param name="p_xmldoc"></param> /// <param name="p_request_date"></param> /// <param name="o_error"></param> /// <returns></returns> public bool DoSaveRequestAck(XmlDocument p_xmldoc, DateTime p_request_date, out string o_error) { var _result = false; o_error = ""; try { IssuingTbl.Clear(); ResponseTbl.Clear(); ResultTbl.Clear(); XmlNamespaceManager _nsmgr = new XmlNamespaceManager(p_xmldoc.NameTable); _nsmgr.AddNamespace("etax", XSignature.SNG.SignNameCollections[""]); XPathExpression _xexpr = XPathExpression.Compile("//etax:TaxInvoiceResponse/etax:ResultDocument"); _xexpr.SetContext(_nsmgr); DataRow _responseRow = ResponseTbl.NewRow(); { _responseRow["totalCount"] = 0; _responseRow["successCount"] = 0; _responseRow["failCount"] = 0; } XPathNavigator _nav = p_xmldoc.CreateNavigator().SelectSingleNode(_xexpr); if (_nav.MoveToChild(XPathNodeType.Element) == true) { do { if (_nav.Name == "ValidationDocument") { DataRow _resultRow = ResultTbl.NewRow(); { XPathNodeIterator _iter = _nav.SelectChildren(XPathNodeType.Element); while (_iter.MoveNext() == true) { string _name = _iter.Current.Name; { if (_name == "IssueID") { _name = "issueId"; } else if (_name == "ResultStatusCode") { _name = "resultStatus"; } } if (_resultRow.Table.Columns.IndexOf(_name) >= 0) { string _value = _iter.Current.Value; if (_resultRow.Table.Columns[_name].DataType == typeof(DateTime)) { _resultRow[_name] = DateTime.ParseExact(_value, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); } else { _resultRow[_name] = _value; } } } _resultRow["isDone"] = "F"; _resultRow["created"] = p_request_date; ResultTbl.Rows.Add(_resultRow); } var _issuingRow = IssuingTbl.NewRow(); { // row.RowState Add상태를 제거하기 위해서 Temp자료를 넣는다. _issuingRow["issueId"] = _resultRow["issueId"]; _issuingRow["isNTSConfirm"] = "X"; _issuingRow["isNTSSuccess"] = "X"; _issuingRow["ntsConfirmDate"] = DateTime.MinValue; IssuingTbl.Rows.Add(_issuingRow); _issuingRow.AcceptChanges(); _issuingRow["isNTSConfirm"] = "T"; _issuingRow["isNTSSuccess"] = "F"; string _status = Convert.ToString(_resultRow["resultStatus"]); if (_status == "SUC001" || _status == "SYN003") { _issuingRow["isNTSSuccess"] = "T"; _resultRow["isDone"] = "T"; } _issuingRow["ntsConfirmDate"] = p_request_date; } } else { string _name = _nav.Name; { if (_name == "RefSubmitID") { _name = "submitId"; } else if (_name == "ReceiptID") { _name = "receiptId"; } else if (_name == "TypeCode") { _name = "typeCode"; } else if (_name == "ResponseDateTime") { _name = "responseTime"; } else if (_name == "ProcessStatusCode") { _name = "processStatus"; } else if (_name == "FailReasonStatusCode") { _name = "failReason"; } else if (_name == "TotalCountQuantity") { _name = "totalCount"; } else if (_name == "SuccessCountQuantity") { _name = "successCount"; } else if (_name == "FailCountQuantity") { _name = "failCount"; } } if (_responseRow.Table.Columns.IndexOf(_name) >= 0) { string _value = _nav.Value; if (_responseRow.Table.Columns[_name].DataType == typeof(DateTime)) { _responseRow[_name] = DateTime.ParseExact(_value, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); } else { _responseRow[_name] = _value; } } } }while (_nav.MoveToNext(XPathNodeType.Element)); ResponseTbl.Rows.Add(_responseRow); LDltaHelper.InsertDeltaSet(UAppHelper.ConnectionString, ResponseSet); } o_error = String.Format("Update result deltaSet: {0}, {1} record(s)", ResponseTbl.Rows[0]["submitId"], ResultTbl.Rows.Count); _result = true; } catch (Exception ex) { if (ex.InnerException != null) { o_error = ex.InnerException.Message; } else { o_error = ex.Message; } } return(_result); }
private void DoReporting(object p_args) { ReportArgs _args = (ReportArgs)p_args; _args.noIssuing = _args.noReporting; _args.noReporting = 0; try { int _toprow = 100; int _chunkCount = _args.noIssuing / _toprow + 1; if (_chunkCount > UAppHelper.NoThreadOfReporter) { _chunkCount = UAppHelper.NoThreadOfReporter; } string _issueid = ""; var _sqlstr = "SELECT a.issueId, a.document, a.rvalue " + " FROM TB_eTAX_ISSUING a INNER JOIN TB_eTAX_INVOICE b " + " ON a.issueId=b.issueId " + " WHERE a.isNTSSending=@isNTSSendingX " + " AND ( " + " (RIGHT(b.typeCode, 2) IN ('01', '02', '04') AND b.invoicerId=@invoicerId) " + " OR " + " (RIGHT(b.typeCode, 2) IN ('03', '05') AND b.brokerId=@invoicerId) " + " ) " + " AND a.issueId > @issueId " + _args.where + " ORDER BY a.issueId" + " LIMIT " + _toprow; { _args.dbps.Add("@isNTSSendingX", NpgsqlDbType.Varchar, "X"); _args.dbps.Add("@invoicerId", NpgsqlDbType.Varchar, _args.invoicerId); } //if (LogCommands == true) // ELogger.SNG.WriteLog(String.Format("begin: invoicerId->'{0}', noIssuing->{1}", _args.invoicerId, _args.noIssuing)); // 만약 InsertDeltaSet을 처리하는 중에 오류가 발생하면 무한 loop를 발생 하게 되므로, // 'X'로 marking한 레코드의 총 갯수를 감소하여 '0'보다 큰 경우에만 반복한다. while (_args.noIssuing > 0) { int _rowsCount = 0; IssuingTbl.Clear(); ResponseTbl.Clear(); var _doneEvents = new ThreadPoolWait[_chunkCount]; for (int i = 0; i < _chunkCount; i++) { _args.dbps.Add("@issueId", NpgsqlDbType.Varchar, _issueid); // 100건 까지를 한 묶음으로 전송하기 위해 기준이 되는 승인번호 var _workingSet = LSQLHelper.SelectDataSet(UAppHelper.ConnectionString, _sqlstr, _args.dbps); if (LSQLHelper.IsNullOrEmpty(_workingSet) == true) { break; } var _rows = _workingSet.Tables[0].Rows; _issueid = Convert.ToString(_rows[_rows.Count - 1]["issueId"]); // 다음 100건의 기준 (>) 승인번호 _doneEvents[i] = new ThreadPoolWait(); Updater _worker = new Updater(IssuingTbl, ResponseTbl); _doneEvents[i].QueueUserWorkItem(_worker.ReporterCallback, _rows); if (Environment.UserInteractive == true) { _doneEvents[i].WaitOne(); } _rowsCount += _rows.Count; } ThreadPoolWait.WaitForAll(_doneEvents); // 처리된 레코드가 한개 이하 인 경우는 종료한다. (문제가 있는 경우로 보여 짐) if (_rowsCount < 1) { break; } //if (LogCommands == true) // ELogger.SNG.WriteLog(String.Format("loop: invoicerId->'{0}', noIssuing->{1}, noReporting->{2}", _args.invoicerId, _args.noIssuing, _rowsCount)); _args.noIssuing -= _rowsCount; _args.noReporting += IssuingTbl.Rows.Count; LDltaHelper.InsertDeltaSet(UAppHelper.ConnectionString, ResponseSet); } } catch (ReporterException ex) { ELogger.SNG.WriteLog(ex); } catch (Exception ex) { ELogger.SNG.WriteLog(ex); } finally { if (LogCommands == true) { ELogger.SNG.WriteLog(String.Format("end: invoicerId->'{0}', noIssuing->{1}, noReporting->{2}", _args.invoicerId, _args.noIssuing, _args.noReporting)); } int _noClearing = ClearXFlag(_args.invoicerId); if (_noClearing > 0) { if (LogCommands == true) { ELogger.SNG.WriteLog(String.Format("clearX: invoicerId->'{0}', noClear->{1}", _args.invoicerId, _noClearing)); } } } }