Esempio n. 1
0
        public void Post(string templateFilePath)
        {
            ConfigData configData = ConfigDataProcessor.GetConfigData();

            if (configData == null)
            {
                throw new BusinessException("配置不存在,请先保存基础配置");
            }

            if (!File.Exists(templateFilePath))
            {
                throw new BusinessException("文件\"{0}\"不存在", templateFilePath);
            }
            string ext = Path.GetExtension(templateFilePath);

            if (string.Compare(ext, ".xlsx", true) != 0)
            {
                throw new BusinessException("结算账单模板文件格式错误");
            }

            List <int> docData = ReadDocumentToList(templateFilePath);

            if (docData == null || docData.Count <= 0)
            {
                return;
            }

            FEPBillPostRequestInfo contractInfo = new FEPBillPostRequestInfo()
            {
                SalesChannelCode = configData.SaleChannelSysNo,
                OrderIds         = docData.ToArray()
            };

            AsyncFEPBillPost(contractInfo, configData);
        }
        public void Import(string templateFilePath)
        {
            ConfigData configData = ConfigDataProcessor.GetConfigData();

            if (configData == null)
            {
                throw new BusinessException("配置不存在,请先保存基础配置");
            }

            if (!File.Exists(templateFilePath))
            {
                throw new BusinessException("文件\"{0}\"不存在", templateFilePath);
            }
            string ext = Path.GetExtension(templateFilePath);

            if (string.Compare(ext, ".xlsx", true) != 0)
            {
                throw new BusinessException("订单模板文件格式错误");
            }

            List <OrderImportRowData> docData = ReadDocumentToList(templateFilePath);

            OnOrderImportFileReadComplate(this, docData == null ? 0 : docData.Count);

            if (docData == null || docData.Count <= 0)
            {
                return;
            }


            string   frequencyCfg = ConfigurationManager.AppSettings["order.socreate.frequency"];
            double   frequencyValue;
            TimeSpan frequency = TimeSpan.FromSeconds(0);

            if (!string.IsNullOrWhiteSpace(frequencyCfg) && double.TryParse(frequencyCfg, out frequencyValue))
            {
                frequency = TimeSpan.FromSeconds(frequencyValue);
            }

            int    millisecondsDelay = (int)frequency.TotalMilliseconds;
            string errorMsg          = null;

            foreach (var item in docData)
            {
                if (!ValidateData(item, out errorMsg))
                {
                    OnOrderImportComplate(this, new OrderCreateResponseResult()
                    {
                        Code = -1,
                        Data = new OrderCreateResponseData()
                        {
                            MerchantOrderID = item.MerchantOrderID.Value
                        },
                        Desc = errorMsg
                    });
                }
                else
                {
                    SOCreateRequestInfo contractInfo = Convert2ContractInfo(item);
                    contractInfo.SaleChannelSysNo = configData.SaleChannelSysNo;
                    ImportOrder(contractInfo, configData);
                }
                Thread.Sleep(millisecondsDelay);
            }
        }