Example #1
0
        /// <summary>
        /// 更新任务
        /// </summary>
        private DateTime HandleUpdateTask(DateTime suggestEarlistUpdateTime, int nOprationType, string strBankCode)
        {
            if (DateTime.Compare(suggestEarlistUpdateTime, DateTime.Now) > 0)
            {
                // 还没到预期的刷新时间,什么都不做
                return(suggestEarlistUpdateTime);
            }

            if (nOprationType == 1)
            {
                int nBankType = MainForm.GetBillBankTypeIDByName(strBankCode);
                // 之前负责的是流水查询任务
                switch (nBankType)
                {
                case 1:
                    // 建设银行
                    CCB_AutoBill.Update();
                    return(suggestEarlistUpdateTime.AddSeconds(CCB_AutoBill.GetUpdateIdleSecond()));

                case 2:
                    // 交通银行
                    BCM_AutoBill.Update();
                    return(suggestEarlistUpdateTime.AddSeconds(BCM_AutoBill.GetUpdateIdleSecond()));

                case 3:
                    // 招商银行
                    CMB_AutoBill.Update();
                    return(suggestEarlistUpdateTime.AddSeconds(CMB_AutoBill.GetUpdateIdleSecond()));

                case 4:
                    // 招商银行
                    ABC_AutoBill.Update();
                    return(suggestEarlistUpdateTime.AddSeconds(ABC_AutoBill.GetUpdateIdleSecond()));

                case 5:
                    // 中信银行
                    CITIC_AutoBill.Update();
                    return(suggestEarlistUpdateTime.AddSeconds(CITIC_AutoBill.GetUpdateIdleSecond()));
                }
            }

            if (nOprationType == 2)
            {
                int nBankType = MainForm.GetOutBankTypeIDByName(strBankCode);
                switch (nBankType)
                {
                case 1:
                    // 民生银行
                    CMBC_AutoOut.Update();
                    return(suggestEarlistUpdateTime.AddSeconds(CMBC_AutoOut.GetUpdateIdleSecond()));
                }
            }

            return(DateTime.Now);
        }
        /// <summary>
        /// 实际自动处理一次流水查询
        /// </summary>
        /// <param name="info"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private bool AutomationBill(SBillTaskInfo info, ref SBillTaskResult result)
        {
            // 检查是否支持该银行
            int nBankTypeID = GetBillBankTypeIDByName(info.bankCode);

            if (nBankTypeID <= 0)
            {
                LOGGER.ERROR($"Auto bill failed: Unknown bank code - {info.bankCode}");
                result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_UnsupportBankCode;
                return(false);
            }
            // 检查重要参数是否合法
            if (string.IsNullOrEmpty(info.accountNumber) ||
                string.IsNullOrEmpty(info.username) ||
                string.IsNullOrEmpty(info.password))
            {
                result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_ArgumentInvalid;
                LOGGER.ERROR($"Auto bill failed: account info invalid");
                return(false);
            }
            // 先进行清理
            // 为保持长期登录状态,现不进行清理 - added by Frankie.W 2017-07-19
            //{
            //    FKWebAutomatic.FKWebDriver.GetInstance.FKClose();
            //    ForceShutdownIE();
            //    Thread.Sleep(1000);
            //}

            DateTime startTime = DateTime.Now;

            bool             bSuccessed = false;
            BankAutoBillBase imp        = null;

            try
            {
                switch (nBankTypeID)
                {
                case 1:
                    imp = new CCB_AutoBill();
                    break;

                case 2:
                    imp = new BCM_AutoBill();
                    break;

                case 3:
                    imp = new CMB_AutoBill();
                    break;

                case 4:
                    imp = new ABC_AutoBill();
                    break;

                case 5:
                    imp = new CITIC_AutoBill();
                    break;

                default:
                    break;
                }

                if (imp == null)
                {
                    LOGGER.ERROR($"Auto bill failed: imp not found");
                    result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_UnknownError;
                    bSuccessed    = false;
                }
                else
                {
                    LOGGER.INFO($"Auto bill start: id = {info.taskID}");
                    imp.Init();
                    bSuccessed = imp.AutoBill(info.taskID, info, ref result);
                    imp.Clear();
                    LOGGER.INFO($"Auto bill finish: id = {info.taskID}");
                }
            }
            catch (Exception e)
            {
                LOGGER.ERROR($"Auto bill error occured. Error = {e.ToString()}");
                result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_UnknownError;
                bSuccessed    = false;
            }
            DateTime endTime = DateTime.Now;
            TimeSpan span    = endTime - startTime;

            if (!bSuccessed)
            {
                //LOGGER.ERROR($"Auto bill failed: imp.AutoBill() return false");
                // 执行失败
                result.status = (int)SBillTaskResult.ENUM_BillActionStatus.eBillActionStatus_AutoProcessFailed;
            }

            // 无论成功与否,都要进行清理
            // 为保持长期登录状态,现不进行清理 - added by Frankie.W 2017-07-19
            //{
            //    FKWebAutomatic.FKWebDriver.GetInstance.FKClose();
            //    ForceShutdownIE();
            //}

            // 并记录到日志时间数据库,以便日志查询
            FKLog.FKSQLiteLogMgr.GetInstance.AddTaskTimeLog(info.taskID, DateTime.Now);

            return(bSuccessed);
        }