예제 #1
0
 public bool DeleteProductStock(string productNumber)
 {
     try
     {
         using (StockProvider database = new StockProvider())
         {
             ProductStockData productStockData = RetrieveProductStock(productNumber);
             if (productStockData == null)
             {
                 return(false);
             }
             else
             {
                 var context = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)database).ObjectContext;
                 context.ExecuteStoreCommand("DELETE FROM ProductStocks WHERE Number= {0}", productNumber);
                 database.SaveChanges();
             }
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
        public override global::System.Data.DataSet Clone()
        {
            ProductStockData cln = ((ProductStockData)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
예제 #3
0
 private StockEntityModel.ProductStock ParseProductStockDataToProductStock(ProductStockData productStockData)
 {
     StockEntityModel.ProductStock productStock = new StockEntityModel.ProductStock()
     {
         Number      = productStockData.Number,
         Name        = productStockData.Name,
         Description = productStockData.Description,
         Amount      = productStockData.Amount
     };
     return(productStock);
 }
예제 #4
0
        private ProductStockData ParseProductStockToProductStockData(StockEntityModel.ProductStock productStock)
        {
            ProductStockData productStockData = new ProductStockData()
            {
                Number      = productStock.Number,
                Name        = productStock.Name,
                Description = productStock.Description,
                Amount      = productStock.Amount
            };

            return(productStockData);
        }
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            ProductStockData ds = new ProductStockData();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
예제 #6
0
        public async void SyncProductStockToAssist(int shopid, string code, int quantity)
        {
            var productStockData = new ProductStockData
            {
                sd_id     = shopid.ToString(),
                goods_sn  = code,
                stock_num = quantity.ToString()
            };
            //处理SSL问题
            var httpClientHandler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true
            };

            using (var http = new HttpClient(httpClientHandler))
            {
                var content  = new StringContent(productStockData.ToJson(), System.Text.Encoding.UTF8, "application/json");
                var postUrl  = _configuration.GetSection("OrderAssistOmsApi")["domain"] + "/ProductStockFeed";
                var response = http.PostAsync(postUrl, content).Result;
                var result   = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var data = JsonMapper.ToObject <StockFeedbackResponse>(result);
                    if (data.state)
                    {
                        var orderNotificationResults = data.resp_data.feedback_result_list;
                        var noSuccNotific            = new List <StockFeedBackResult>();
                        if (orderNotificationResults != null && orderNotificationResults.Count > 0)
                        {
                            noSuccNotific = orderNotificationResults.Where(r => r.result != "1").ToList();
                        }
                        if (noSuccNotific != null && noSuccNotific.Count() > 0)
                        {
                            var order_snStr = string.Empty;
                            foreach (var item in noSuccNotific)
                            {
                                order_snStr += string.Format("商铺Id:{0},商品Id{1};", item.sd_id, item.goods_sn);
                            }

                            _logService.Error(string.Format("OMS库存变更通知信息异常:{0}", order_snStr));
                        }
                    }
                    else
                    {
                        _logService.Error(string.Format("OMS库存更新通知信息异常,商品编码:{0},错误信息:{1}", code, data.message));
                    }
                }
            }
        }
예제 #7
0
 public int RetrieveProductStockAmount(string productNumber)
 {
     try
     {
         ProductStockData productStockData = RetrieveProductStock(productNumber);
         if (productStockData != null)
         {
             return(productStockData.Amount);
         }
     }
     catch
     {
         //TODO: Should be implemented in future
     }
     return(0);
 }
예제 #8
0
        public ProductStockData RetrieveProductStock(string productNumber)
        {
            ProductStockData productStockData = null;

            try
            {
                using (StockProvider database = new StockProvider())
                {
                    StockEntityModel.ProductStock productStock = database.ProductsStock.First(
                        p => String.Compare(p.Number, productNumber) == 0);
                    productStockData = ParseProductStockToProductStockData(productStock);
                }
            }
            catch
            {
                //TODO: Should be implemented in future
            }
            return(productStockData);
        }
예제 #9
0
        public IActionResult SyncListProductsStock([FromBody] List <ProductStockFeedData> productStockFeedDatas)
        {
            if (productStockFeedDatas != null)
            {
                var errorCount = 0;
                var errorMsg   = "";
                List <SyncProductStockModel> syncProductStockModels = new List <SyncProductStockModel>();
                try
                {
                    //OMS库存同步成功之后,再把库存同步到商城
                    var productStockDataList = new List <ProductStockData>();
                    foreach (var productStockFeedData in productStockFeedDatas)
                    {
                        var saleProduct = _productService.GetSaleProduct(productStockFeedData.ProductId);
                        var product     = _productService.GetProductById(productStockFeedData.ProductId);
                        var saleProductWareHouseStock = _productService.GetSPHStockByWareHouseCodeAndProduct(productStockFeedData.WareHouseCode, productStockFeedData.ProductId);
                        if (saleProduct == null)
                        {
                            errorCount++;
                            errorMsg += string.Format("未找到可售商品, 商品Id:{0},商品名为:{1};  ", productStockFeedData.ProductId, product.Name);
                            continue;
                        }

                        if (saleProductWareHouseStock == null)
                        {
                            errorCount++;
                            errorMsg += string.Format("未找到可售商品仓库库存信息, 商品Id:{0},商品名为:{1},仓库编码{2};  ", productStockFeedData.ProductId, product.Name, productStockFeedData.WareHouseCode);
                            continue;
                        }
                        //销售商品总库存信息
                        saleProduct.Stock          = productStockFeedData.Quantity;
                        saleProduct.LockStock      = saleProduct.LockStock - productStockFeedData.ShopQuantity;
                        saleProduct.AvailableStock = saleProduct.Stock - saleProduct.LockStock;
                        //当前对应的仓库库存信息
                        saleProductWareHouseStock.Stock     = productStockFeedData.WareHouseStock;
                        saleProductWareHouseStock.LockStock = saleProductWareHouseStock.LockStock - productStockFeedData.ShopQuantity;

                        _omsAccessor.Update(saleProduct);
                        _omsAccessor.Update(saleProductWareHouseStock);
                        _logService.Error(string.Format("商品Id为{0},商品名为:{4},WMS到OMS同步库存为{1},可用库存为{2},锁定库存为{3},仓库{5}的库存为{6},锁定库存为{7}", productStockFeedData.ProductId, productStockFeedData.Quantity, saleProduct.AvailableStock, saleProduct.LockStock, product.Name, productStockFeedData.WareHouseCode, saleProductWareHouseStock.Stock, saleProductWareHouseStock.LockStock));
                        //更新商品库存到商城
                        var xuniStock        = _productService.GetXuniStocks(saleProduct.Id);
                        var productStockData = new ProductStockData
                        {
                            sd_id             = productStockFeedData.ShopId.ToString(),
                            goods_sn          = product.Code,
                            stock_num         = (saleProduct.AvailableStock - (xuniStock.Sum(r => r.Stock) - xuniStock.Sum(r => r.LockStock))).ToString(),
                            stock_detail_list = _productService.GetSaleProductWareHouseStocksByProductCode(product.Code)
                        };
                        productStockDataList.Add(productStockData);
                    }
                    if (errorCount > 0)
                    {
                        return(Json(new { isSucc = false, msg = "同步库存失败,原因:" + errorMsg }));
                    }
                    _omsAccessor.SaveChanges();

                    //更新商品到商城
                    _productService.SyncMoreProductStockToAssist(productStockDataList);

                    return(Json(new { isSucc = true, msg = "成功" }));
                }
                catch (Exception ex)
                {
                    return(Json(new { isSucc = false, msg = "同步库存失败,原因:" + ex.Message }));
                }
            }
            else
            {
                return(Json(new { isSucc = false, msg = "no data" }));
            }
        }
예제 #10
0
        /// <summary>
        /// 同步所有商品的库存到商城
        /// </summary>
        public void OMSToShopAllProductsStock()
        {
            try
            {
                #region  商品编码批量更新
                //string[] arr = { };
                //var productStockDataList = new List<ProductStockData>();
                //for (int n = 0; n < arr.Length; n++)
                //{
                //    var product = _omsAccessor.Get<Product>().Where(x => x.Code == arr[n].ToString() && x.Isvalid).FirstOrDefault();
                //    if (product != null)
                //    {
                //        var sp = _omsAccessor.Get<SaleProduct>().Where(x => x.Isvalid && x.ProductId == product.Id).FirstOrDefault();
                //        if (sp!=null) {
                //            var productStockData = new ProductStockData
                //            {
                //                sd_id = "501",
                //                goods_sn = product.Code,
                //                stock_num = sp.AvailableStock.ToString(),
                //                stock_detail_list = _productService.GetSaleProductWareHouseStocksByProductCode(product.Code)
                //            };
                //            productStockDataList.Add(productStockData);
                //        }

                //    }
                //}

                //_productService.SyncMoreProductStockToAssist(productStockDataList);
                #endregion
                //查出所有的销售商品
                var productStockDataList = new List <ProductStockData>();
                var allSaleProducts      = _omsAccessor.Get <SaleProduct>().Include(x => x.Product).Where(x => x.Isvalid && x.AvailableStock > 0 && x.Channel == 94).OrderByDescending(r => r.Id).ToList();
                var i  = 0;
                var ii = 1;
                foreach (var item in allSaleProducts)
                {
                    var xuniStock        = _productService.GetXuniStocks(item.Id);
                    var productStockData = new ProductStockData
                    {
                        sd_id     = "501",
                        goods_sn  = item.Product.Code,
                        stock_num = (item.AvailableStock - (xuniStock.Sum(r => r.Stock) - xuniStock.Sum(r => r.LockStock))).ToString(),
                    };
                    var proStockDetail = _productService.GetSaleProductWareHouseStocksByProductCode(item.Product.Code);
                    if (proStockDetail.Count() > 0)
                    {
                        productStockData.stock_detail_list = proStockDetail;
                        productStockDataList.Add(productStockData);
                    }
                    if (productStockDataList.Count % 100 == 0)
                    {
                        _logService.Info("当前更新库存页数:" + (ii = i % 100));
                        Thread.Sleep(100);
                        i += 100;
                        //更新库存到商城
                        _productService.SyncMoreProductStockToAssist(productStockDataList);
                        productStockDataList = new List <ProductStockData>();
                    }
                    if ((i + 100) > allSaleProducts.Count() && productStockDataList.Count == (allSaleProducts.Count() - i))
                    {
                        //更新库存到商城
                        _productService.SyncMoreProductStockToAssist(productStockDataList);
                        _logService.Info("当前更新库存页数:" + ii + 1);
                    }
                }
            }
            catch (Exception ex)
            {
                _logService.Error("同步库存到商城错误:" + ex.Message);
            }
        }
            public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs)
            {
                global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
                global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
                ProductStockData ds = new ProductStockData();

                global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "stocktblDataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
                if (xs.Contains(dsSchema.TargetNamespace))
                {
                    global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                    global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                    try {
                        global::System.Xml.Schema.XmlSchema schema = null;
                        dsSchema.Write(s1);
                        for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                        {
                            schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                            s2.SetLength(0);
                            schema.Write(s2);
                            if ((s1.Length == s2.Length))
                            {
                                s1.Position = 0;
                                s2.Position = 0;
                                for (; ((s1.Position != s1.Length) &&
                                        (s1.ReadByte() == s2.ReadByte()));)
                                {
                                    ;
                                }
                                if ((s1.Position == s1.Length))
                                {
                                    return(type);
                                }
                            }
                        }
                    }
                    finally {
                        if ((s1 != null))
                        {
                            s1.Close();
                        }
                        if ((s2 != null))
                        {
                            s2.Close();
                        }
                    }
                }
                xs.Add(dsSchema);
                return(type);
            }