Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        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);
        }