public void SynInvnetoryQty() { if (!IsActive) { throw new Exception("当前线程已终止,请调用Start()重新启动。"); } ThirdPartInventoryArgs args = new ThirdPartInventoryArgs(); //CommonConst commonConst = new CommonConst(); int batchNumber = Common.BatchNumber; int batch = (batchNumber > ThirdPartInventory.Count) ? 1 : (ThirdPartInventory.Count % batchNumber == 0 ? ThirdPartInventory.Count / batchNumber : (ThirdPartInventory.Count / batchNumber + 1)); List <ThirdPartInventoryEntity> qtylist; for (int i = 0; i < batch; i++) { qtylist = ThirdPartInventory.Skip(i * batchNumber).Take(batchNumber).ToList(); args.ThirdPartInventoryList = qtylist; try { OnRunningBefor(this, args); if (!IsActive) { break; } On_Running(this, args); if (!IsActive) { break; } OnRunningAfter(this, args); if (!IsActive) { break; } } catch (Exception ex) { ThirdPartInventoryErrorArgs errorArgs = new ThirdPartInventoryErrorArgs(); errorArgs.Exception = ex; errorArgs.ThirdPartInventoryList = qtylist; OnError(this, errorArgs); if (!IsActive) { break; } } } }
private void ModifyLocalQty(object sender, ThirdPartInventoryArgs args) { List <ThirdPartInventoryEntity> list = args.ThirdPartInventoryList; foreach (ThirdPartInventoryEntity entity in list) { int synInventoryQty = Addapter.CalculateInventoryQty.CalculateQty(entity); int inventoryQty = entity.InventoryOnlineQty - (entity.SynInventoryQty + entity.OldInventoryAlamQty); if (entity.InventoryAlamQty.HasValue)//如果库存预警为空,则证明该数据尚未被初始化 { ThirdPartInventoryDA.Modify(inventoryQty, synInventoryQty, entity.ProductMappingSysno, Common); } else//初始化数据 { //synInventoryQty += 1; ThirdPartInventoryDA.Insert(inventoryQty, synInventoryQty, entity.ProductMappingSysno, Common); } } WriteLog("本批次数据同步成功。\r\n", true); }
private void WriteDataLog(object sender, ThirdPartInventoryArgs args) { if (args.ThirdPartInventoryList.Count == 0) { ThirdPartInventoryBPBase bp = sender as ThirdPartInventoryBPBase; if (bp != null) { bp.Abort(); return; } } p++; WriteLog(string.Format("正在同步第{0}批数据,本批次数据量:{1}条……", p, args.ThirdPartInventoryList.Count), true); StringBuilder sb = new StringBuilder(); sb.Append("ProductMappingSysno_ProductSysNo_AlamQty["); foreach (ThirdPartInventoryEntity entity in args.ThirdPartInventoryList) { sb.AppendFormat("{0}_{1}_{2} ", entity.ProductMappingSysno, entity.ProductSysNo, entity.InventoryAlamQty ?? Common.InventoryAlarmQty); } sb.Append("]\r\n"); WriteLog(sb.ToString()); }
protected override void On_Running(object sender, ThirdPartInventoryArgs args) { List <ThirdPartInventoryEntity> qtyList = args.ThirdPartInventoryList; List <TaoBaoSKUMsg> list = new List <TaoBaoSKUMsg>(); foreach (ThirdPartInventoryEntity entity in qtyList) { TaoBaoSKUMsg skuMsg = new TaoBaoSKUMsg(); int qty = Addapter.CalculateInventoryQty.CalculateSynQty(entity); #region 2011-10-26 Midify by Kilin 新商品同步库存时,淘宝库存默认为一个 if (!entity.InventoryAlamQty.HasValue) { qty -= 1; } #endregion skuMsg.Quantity = qty.ToString(); skuMsg.Type = "2"; skuMsg.SKU = entity.SKU; list.Add(skuMsg); } SynInvnetoryQty(list); }
protected virtual void On_RunningAfter(object sender, ThirdPartInventoryArgs args) { }
protected abstract void On_Running(object sender, ThirdPartInventoryArgs args);