//------------------------------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------------------------------- /// <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 DoMailing(object p_args) { MailingArgs _args = (MailingArgs)p_args; _args.noInvoicee = _args.noSending; _args.noSending = 0; try { int _toprow = 800; var _sqlstr = "SELECT a.issueId, a.document, a.securityId, b.issueDate, b.typeCode, b.invoiceeKind, " + " b.chargeTotal, b.taxTotal, b.grandTotal, b.description, a.isMailSending, " + " b.invoicerId, b.invoicerEMail, b.invoicerName, b.invoicerPerson, b.invoicerPhone, " + " a.isInvoiceeMail, b.invoiceeId, b.invoiceeEMail1 as invoiceeEMail, b.invoiceeName, " + " b.invoiceePerson, b.invoiceePhone1 as invoiceePhone, a.isProviderMail, a.providerId, " + " a.providerEMail, a.sendMailCount, a.mailSendingDate " + " FROM TB_eTAX_ISSUING a INNER JOIN TB_eTAX_INVOICE b " + " ON a.issueId=b.issueId " + " WHERE a.isMailSending=@isMailSendingX " // to avoid infinite loop, do check isMailSending here. + " 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) " + " ) " + _args.where + " ORDER BY a.providerEMail" + " LIMIT " + _toprow; { _args.dbps.Add("@isMailSendingX", NpgsqlDbType.Varchar, "X"); _args.dbps.Add("@invoicerId", NpgsqlDbType.Varchar, _args.invoicerId); } //if (LogCommands == true) // ELogger.SNG.WriteLog(String.Format("begin: invoicerId->'{0}', noInvoicee->{1}", _args.invoicerId, _args.noInvoicee)); var _random = new Random(); // 만약 InsertDeltaSet을 처리하는 중에 오류가 발생하면 무한 loop를 발생 하게 되므로, // 'X'로 marking한 레코드의 총 갯수를 감소하여 '0'보다 큰 경우에만 반복한다. while (_args.noInvoicee > 0) { IssuingTbl.Clear(); ResultTbl.Clear(); var _workingSet = LSQLHelper.SelectDataSet(UAppHelper.ConnectionString, _sqlstr, _args.dbps); if (LSQLHelper.IsNullOrEmpty(_workingSet) == true) { break; } var _rows = _workingSet.Tables[0].Rows; var _doneEvents = new ThreadPoolWait[_rows.Count]; for (int i = 0; i < _rows.Count; i++) { if (String.IsNullOrEmpty(Convert.ToString(_rows[i]["securityId"])) == true) { _rows[i]["securityId"] = Convert.ToString(_random.Next(100000, 999999)); } if (_args.reSending == true) { _rows[i]["invoiceeEMail"] = _args.invoiceeEMail; } _doneEvents[i] = new ThreadPoolWait(); AsyncWorker _worker = new AsyncWorker(IssuingTbl, ResultTbl); _doneEvents[i].QueueUserWorkItem(_worker.MailerCallback, _rows[i]); if (Environment.UserInteractive == true) { _doneEvents[i].WaitOne(); } } ThreadPoolWait.WaitForAll(_doneEvents); // 처리된 레코드가 한개 이하 인 경우는 종료한다. (문제가 있는 경우로 보여 짐) if (_rows.Count < 1) { break; } //if (LogCommands == true) // ELogger.SNG.WriteLog(String.Format("loop: invoicerId->'{0}', noInvoicee->{1}, noSending->{2}", _args.invoicerId, _args.noInvoicee, _rows.Count)); _args.noInvoicee -= _rows.Count; _args.noSending += IssuingTbl.Rows.Count; LDltaHelper.InsertDeltaSet(UAppHelper.ConnectionString, IssuingSet); } } catch (MailerException ex) { ELogger.SNG.WriteLog(ex); } catch (Exception ex) { ELogger.SNG.WriteLog(ex); } finally { if (LogCommands == true) { ELogger.SNG.WriteLog(String.Format("end: invoicerId->'{0}', noInvoicee->{1}, noSending->{2}", _args.invoicerId, _args.noInvoicee, _args.noSending)); } int _noClearing = ClearXFlag(_args.invoicerId); if (_noClearing > 0) { if (LogCommands == true) { ELogger.SNG.WriteLog(String.Format("clearX: invoicerId->'{0}', noClear->{1}", _args.invoicerId, _noClearing)); } } } }