/// <summary> /// 解析流水页面 /// </summary> /// <param name="html"></param> /// <param name="result"></param> /// <returns></returns> private bool ParseAutoBillHtmlPage(HtmlDocument html, ref SBillTaskResult result, SBillTaskInfo info) { try { var nodes = html.DocumentNode.SelectSingleNode("./table/tbody"); if (nodes == null) { LOGGER.INFO("未找到有效流水数据,可能已经查到最后一页"); return(false); } var items = nodes.SelectNodes("./tr"); if (items == null) { LOGGER.INFO("未找到有效流水数据,可能已经查到最后一页"); return(false); } if (items.Count == 0) { LOGGER.INFO("未找到有效流水数据,可能已经查到最后一页"); return(false); } foreach (var node in nodes.SelectNodes("./tr")) { SBillTaskResult.SBankBillInfo billItem = new SBillTaskResult.SBankBillInfo(); // 解析单一流水对象 if (ParseOneBillHtmlPage(node, ref billItem) == false) { continue; } // citic明细没有时间,一律不过滤 /*if (ResultFilter.TimeFilter(info, billItem.submitTime)) * { * result.billsList.Add(billItem); * }*/ result.billsList.Add(billItem); } result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_Successed; } catch (Exception e) { result.msg = "CITIC解析返回html错误"; result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_AutoProcessFailed; LOGGER.WARN($"CITIC解析返回html错误:{e.Message}"); return(false); } return(true); }
/// <summary> /// 解析流水页面 /// </summary> /// <param name="html"></param> /// <param name="result"></param> /// <returns></returns> private bool ParseAutoBillHtmlPage(HtmlDocument html, ref SBillTaskResult result, SBillTaskInfo info) { try { var nodes = html.DocumentNode.SelectSingleNode("//body/form").SelectSingleNode("//table"); var items = nodes.SelectNodes("//tr[@class='td_span']"); // 当获取的数据为空时仍然有一个td_span 但是里面的数据为空 if (items.Count == 1) { if (items[0].GetAttributeValue("zcsr", "") == "|") { return(false); } } foreach (var node in nodes.SelectNodes("//tr[@class='td_span']")) { SBillTaskResult.SBankBillInfo billItem = new SBillTaskResult.SBankBillInfo(); // 解析单一流水对象 if (ParseOneBillHtmlPage(node, ref billItem) == false) { continue; } if (ResultFilter.TimeFilter(info, billItem.submitTime)) { result.billsList.Add(billItem); } } result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_Successed; } catch (Exception e) { result.msg = "CCB解析返回html错误"; result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_AutoProcessFailed; LOGGER.WARN($"CCB解析返回html错误:{e.Message}"); return(false); } return(true); }
/// <summary> /// 解析XLS文件 /// </summary> /// <param name="filename"></param> /// <param name="result"></param> /// <returns></returns> private bool parseXlsContent(string filename, ref SBillTaskResult result, SBillTaskInfo info) { ExcelReader reader = ExcelReader.CreateReader(filename); try { List <object> recordList = new List <object>(); int i = 0; while (reader.Read(1, ++i, ref recordList)) { // 跳过前三行(标题 本账号信息 列表头) if (i <= 3) { recordList.Clear(); continue; } /* * 交易日期 交易时间 交易金额 本次余额 对方户名 对方账号 交易行 交易渠道 交易类型 交易用途 交易摘要 * 20160828 102524 +270.00 284.91 罗春波 6228270921220010475 江西省分行9999行 网上银行 转账 网银转账 */ SBillTaskResult.SBankBillInfo billItem = new SBillTaskResult.SBankBillInfo(); string date = (string)recordList.ElementAt(0); string time = (string)recordList.ElementAt(1); if (string.IsNullOrEmpty(time)) { time = "000000"; } string dateTime = $"{date}-{time}"; billItem.submitTime = GetTradeTime(dateTime); // 时间不为空的需要过滤 为空总是返回 防止漏掉 if (!string.IsNullOrEmpty((string)recordList.ElementAt(1))) { if (!ResultFilter.TimeFilter(info, billItem.submitTime)) { recordList.Clear(); continue; } } //billItem.amount = Double.Parse($"{(string)recordList.ElementAt(2)}"); //billItem.balance = Double.Parse($"{(string)recordList.ElementAt(3)}"); billItem.amount = ($"{(string)recordList.ElementAt(2)}"); billItem.balance = ($"{(string)recordList.ElementAt(3)}"); billItem.accountName = $"{(string)recordList.ElementAt(4)}"; billItem.accountNumber = $"{(string)recordList.ElementAt(5)}"; billItem.accountBankName = $"{(string)recordList.ElementAt(6)}"; billItem.tradeChannel = $"{(string)recordList.ElementAt(7)}"; billItem.digest = $"{(string)recordList.ElementAt(10)}"; billItem.tradeType = TransformTradeTypeFromSummary($"{(string)recordList.ElementAt(10)}", $"{(string)recordList.ElementAt(2)}"); billItem.tradeUsage = $"{(string)recordList.ElementAt(9)}"; billItem.additionalComment = $"{(string)recordList.ElementAt(10)}"; // 明细未提供 // billItem.currency = ? result.billsList.Add(billItem); recordList.Clear(); } } catch (Exception e) { LOGGER.ERROR($"解析 XLS 文件失败, Error = {e.ToString()}"); result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_AutoProcessFailed; result.msg = "解析 XLS 文件失败."; return(false); } finally { reader.Close(); } result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_Successed; result.msg = "Successed"; return(true); }
/// <summary> /// 从Node中解析一条流水 /// </summary> /// <param name="node"></param> /// <param name="billItem"></param> private bool ParseOneBillHtmlPage(HtmlNode node, ref SBillTaskResult.SBankBillInfo billItem) { try { // 交易卡号全是 -- string accountNumber = System.Net.WebUtility.HtmlDecode(node.SelectSingleNode("./td[2]").InnerHtml).Trim(); billItem.accountNumber = accountNumber; // 日期 string date = System.Net.WebUtility.HtmlDecode(node.SelectSingleNode("./td[3]").InnerHtml).Trim(); billItem.submitTime = GetTradeTime(date); // 支出 string outMoney = System.Net.WebUtility.HtmlDecode(node.SelectSingleNode("./td[4]").InnerHtml).Trim(); // 收入 string inMoney = System.Net.WebUtility.HtmlDecode(node.SelectSingleNode("./td[5]").InnerHtml).Trim(); if (outMoney == "--" && inMoney == "--") { return(false); } if (outMoney != "--") { billItem.amount = "-" + outMoney; } else if (inMoney != "--") { billItem.amount = inMoney; } // 余额 string balance = System.Net.WebUtility.HtmlDecode(node.SelectSingleNode("./td[6]").InnerHtml).Trim(); if (balance == "--") { return(false); } billItem.balance = balance; // 对方 格式 ==>招商银行 尾号3085 李欢<== string info = System.Net.WebUtility.HtmlDecode(node.SelectSingleNode("./td[7]").InnerHtml).Trim(); // 受理机构 具体银行 string bank = System.Net.WebUtility.HtmlDecode(node.SelectSingleNode("./td[8]").InnerHtml).Trim(); billItem.accountBankName = bank; var infoArr = info.Split(' '); if (infoArr.Length >= 1) { if (bank == "--") { billItem.accountBankName = infoArr[0]; } } if (infoArr.Length >= 2) { if (accountNumber == "--") { billItem.accountNumber = infoArr[1]; } } if (infoArr.Length >= 3) { billItem.accountName = infoArr[2]; } // 摘要 客户填写的附言 string summary = System.Net.WebUtility.HtmlDecode(node.SelectSingleNode("./td[9]").InnerHtml).Trim(); billItem.additionalComment = summary; // 状态 ==>完成<== string status = System.Net.WebUtility.HtmlDecode(node.SelectSingleNode("./td[10]").InnerHtml).Trim(); billItem.digest = info + " " + status; } catch (Exception e) { LOGGER.WARN($"Parser CITIC one bill failed. Error = {e.ToString()}"); return(false); } LOGGER.DEBUG($"Get one bill, info = {billItem.ToString()}"); return(true); }
private bool ParseAutoBillRegex(string content, ref SBillTaskResult result, SBillTaskInfo info) { Regex reg = new Regex($"\\{{stdessvldt=(?<date>.*?), " + $"stdes2bref=(?<sumary>.*?), " + $"stdes1opna=(?<stdes1opna>.*?), " + $"stdsumtrsq=(?<serialnumber>.*?), " + $"equipmentNO=(?<ignore2>.*?), " + $"stdessrvfg=(?<stdessrvfg>.*?), " + $"std400desc=(?<std400desc>.*?), " + $"stdesstrno=(?<stdesstrno>.*?), " + $"stdes2opid=(?<stdes2opid>.*?), " + $"stdessdcfg=(?<stdessdcfg>.*?), " + $"stdes2bfcd=(?<stdes2bfcd>.*?), " + $"stdessctfg=(?<stdessctfg>.*?), " + $"stdes2opna=(?<stdes2opna>.*?), " + $"stdesstrdt=(?<stdesstrdt>.*?), " + $"stdoppacna=(?<username>.*?), " + $"stdesstram=(?<amount>.*?), " + $"stdessfnfg=(?<stdessfnfg>.*?), " + $"stdes1bfcd=(?<stdes1bfcd>.*?), " + $"stdessacbl=(?<balance>.*?), " + $"stdesstrtm=(?<time>.*?), " + $"stdes1opid=(?<stdes1opid>.*?), " + $"stdesstrcd=(?<stdesstrcd>.*?), " + $"fndoppacno=(?<cardnumber>.*?), " + $"stdoppbrna=(?<bankname>.*?)" + $"\\}}" + $""); var matches = reg.Matches(content); if (matches.Count == 0) { LOGGER.INFO("未找到有效流水数据,可能已经查到最后一页"); return(false); } foreach (Match one in matches) { SBillTaskResult.SBankBillInfo billItem = new SBillTaskResult.SBankBillInfo(); // 解析单一流水对象 billItem.submitTime = GetRegexTradeTime($"{one.Groups["date"].Value}-{one.Groups["time"].Value}"); billItem.serialNo = one.Groups["serialnumber"].Value; if (billItem.serialNo == "null") { billItem.serialNo = ""; } billItem.accountBankName = one.Groups["bankname"].Value; if (billItem.accountBankName == "null") { billItem.accountBankName = ""; } billItem.accountName = one.Groups["username"].Value; if (billItem.accountName == "null") { billItem.accountName = ""; } billItem.additionalComment = one.Groups["sumary"].Value; if (billItem.additionalComment == "null") { billItem.additionalComment = ""; } billItem.balance = one.Groups["balance"].Value; if (billItem.balance == "null") { billItem.balance = ""; } billItem.amount = one.Groups["amount"].Value; if (billItem.amount == "null") { billItem.amount = "0.0"; } billItem.accountNumber = one.Groups["cardnumber"].Value; var inOrOut = one.Groups["stdessdcfg"].Value; if (inOrOut == "C") { billItem.amount = "+" + billItem.amount; } else if (inOrOut == "D") { billItem.amount = "-" + billItem.amount; } else { LOGGER.ERROR($"未知存取类型[{inOrOut}]"); continue; } billItem.tradeType = TransformTradeTypeFromSummary(one.Groups["stdes2bfcd"].Value, inOrOut); if (ResultFilter.TimeFilter(info, billItem.submitTime)) { result.billsList.Add(billItem); } } return(true); }
/// <summary> /// 从Node中解析一条流水 /// </summary> /// <param name="node"></param> /// <param name="billItem"></param> private bool ParseOneBillHtmlPage(HtmlNode node, ref SBillTaskResult.SBankBillInfo billItem) { try { billItem.submitTime = GetTradeTime(node.SelectSingleNode("./td[2]").InnerHtml.Trim()); if (string.IsNullOrEmpty(billItem.submitTime)) { LOGGER.ERROR("交易时间为空"); return(false); } // 支出cny string outMoney = GetTradeAmount(node.SelectSingleNode("./td[3]").InnerHtml.Trim()); // 收入cny string inMoney = GetTradeAmount(node.SelectSingleNode("./td[4]").InnerHtml.Trim()); if (string.IsNullOrEmpty(inMoney) && string.IsNullOrEmpty(outMoney)) { LOGGER.ERROR("收入支出项同时为空"); return(false); } if (string.IsNullOrEmpty(outMoney) && !string.IsNullOrEmpty(inMoney)) { //billItem.amount = Double.Parse(inMoney); billItem.amount = (inMoney); } else if (string.IsNullOrEmpty(inMoney) && !string.IsNullOrEmpty(outMoney)) { //billItem.amount = -Double.Parse(outMoney); billItem.amount = "-" + (outMoney); } else { LOGGER.INFO($"进出账同时为空[{inMoney}][{outMoney}]"); return(false); } // 余额cny string balance = GetTradeAmount(node.SelectSingleNode("./td[5]").InnerHtml.Trim()); //billItem.balance = Double.Parse(balance); billItem.balance = (balance); // 对方账号 billItem.accountNumber = GetBankCardNumber(node.SelectSingleNode("./script").InnerHtml.Trim()); // 对方用户名 billItem.accountName = GetUserName(node.SelectSingleNode("./td[6]").InnerHtml.Trim()); // 币种 string currency = GetCurrency(node.SelectSingleNode("./td[7]").InnerHtml.Trim()); billItem.currency = TransformCurrencyTypeFromString(currency); // 摘要 string summary = GetTradeSummary(node.SelectSingleNode("./td[8]").InnerHtml.Trim()); billItem.digest = summary; // 交易类型 billItem.tradeType = TransformTradeTypeFromSummary(summary, billItem.amount); // 附言 billItem.additionalComment = GetAdditionalComment(node.SelectSingleNode("./td[9]").InnerHtml.Trim()); } catch (Exception e) { LOGGER.WARN($"Parser CCB one bill failed. Error = {e.ToString()}"); return(false); } LOGGER.DEBUG($"Get one bill, info = {billItem.ToString()}"); return(true); }