public void Execute(IJobExecutionContext context) { ILog log = LogManager.GetLogger(this.GetType()); var totalCount = 0; Query( orders => totalCount = orders.Count()); int cursor = 0; int successCount = 0; int size = JobConfig.DEFAULT_PAGE_SIZE; int lastCursor = 0; log.Info("begin job:SaleProductNoPicSyncOneTime"); Stopwatch sw = new Stopwatch(); sw.Start(); while (cursor < totalCount) { List<ProductMapEntity> oneTimeList = null; Query(orders => { oneTimeList = orders.Where(a => a.Id > lastCursor).OrderBy(a => a.Id).Take(size).ToList(); }); foreach (var order in oneTimeList) { try { IEnumerable<PRO_PICTURE> pics = null; using (var erp = new ErpContext()) { pics= erp.PRO_PICTURE.Where(p => p.PRODUCT_SID == order.ChannelPId).ToList(); } if (pics == null || pics.Count() <= 0) continue; bool isSuccess = false; foreach (var pic in pics) isSuccess = ProductPicSyncJob.SyncOne(pic); if (isSuccess) successCount++; } catch (Exception ex) { log.Info(ex); } } cursor += size; if (oneTimeList !=null && oneTimeList.Count()> 0) lastCursor = oneTimeList.Max(o => o.Id); } sw.Stop(); log.Info(string.Format("total no pic products :{0},{1} synced products in {2} => {3} docs/s", totalCount, successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds)); log.Info("end job:SaleProductNoPicSyncOneTime"); }
private void DoQuery(Expression<Func<SUPPLY_MIN_PRICE, bool>> whereCondition, Action<IQueryable<SUPPLY_MIN_PRICE>> callback) { using (var context = new ErpContext()) { var linq = context.SUPPLY_MIN_PRICE.AsQueryable(); if (whereCondition != null) linq = linq.Where(whereCondition); if (callback != null) callback(linq); } }
private void DoQuery(Expression<Func<PRO_CLASS_DICT, bool>> whereCondition, Action<IQueryable<PRO_CLASS_DICT>> callback) { using (var context = new ErpContext()) { var linq = context.PRO_CLASS_DICT.Where(l=>l.PRO_CLASS_BIT==1); if (whereCondition != null) linq = linq.Where(whereCondition); if (callback != null) callback(linq); } }
private void DoQuery(Expression<Func<BRAND,bool>> whereCondition, Action<IQueryable<BRAND>> callback) { using (var context = new ErpContext()) { var linq = context.BRANDs.AsQueryable(); if (whereCondition != null) linq = linq.Where( whereCondition); if (callback != null) callback(linq); } }
private static void EnsureProductContext(SUPPLY_MIN_PRICE product) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var exBrand = db.Set<BrandEntity>().Where(b => b.ChannelBrandId == product.BRAND_SID).FirstOrDefault(); if (null == exBrand) { using (var erpDb = new ErpContext()) { var brand = erpDb.Set<BRAND>().Find(product.BRAND_SID); if (null != brand) BrandSyncJob.SyncOne(brand); } } var exCat = db.Set<CategoryEntity>().Where(c => c.ExCatId == product.PRO_CLASS_SID).FirstOrDefault(); if (null == exCat) { using (var erpDb = new ErpContext()) { var cat = erpDb.Set<PRO_CLASS_DICT>().Find(product.PRO_CLASS_SID); if (null != cat) CategorySyncJob.SyncOne(cat); } } var exStore = db.Set<StoreEntity>().Where(c => c.ExStoreId == product.SHOP_SID).FirstOrDefault(); if (null == exStore) { using (var erpDb = new ErpContext()) { var store = erpDb.Set<SHOP_INFO>().Find(product.SHOP_SID); if (null != store) StoreSyncJob.SyncOne(store); } } } }
private bool EnsureProductContext(PRO_PICTURE product) { using(var erpDb= new ErpContext()) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var colorEntity = db.Set<ProductPropertyValueEntity>().Where(ppv => ppv.ChannelValueId == product.PRO_COLOR_SID) .Join(db.Set<ProductPropertyEntity>().Join(db.Set<ProductMapEntity>().Where(pm=>pm.ChannelPId==product.PRODUCT_SID),o=>o.ProductId,i=>i.ProductId,(o,i)=>o), o=>o.PropertyId,i=>i.Id,(o,i)=>o).FirstOrDefault(); if (colorEntity == null) { var exProduct = erpDb.Set<SUPPLY_MIN_PRICE_MX>().Where(ep => ep.PRODUCT_SID == product.PRODUCT_SID && ep.PRO_COLOR_SID == product.PRO_COLOR_SID).FirstOrDefault(); if (exProduct == null) { Log.Error(string.Format("product sid:{0} has no inventory record for color_sid:{1}",product.PRODUCT_SID,product.PRO_COLOR_SID)); return false; } return ProductPropertySyncJob.SyncOne(exProduct.PRODUCT_SID, exProduct.PRO_STAN_SID ?? 0, exProduct.PRO_STAN_NAME, exProduct.PRO_COLOR_SID ?? 0, exProduct.PRO_COLOR); } } } return true; }
private static void syncRelatedPics(SUPPLY_MIN_PRICE product) { IEnumerable<PRO_PICTURE> pics = null; using (var erp = new ErpContext()) { pics = erp.PRO_PICTURE.Where(p => p.PRODUCT_SID == product.PRODUCT_SID).ToList(); } foreach (var pic in pics) { ProductPicSyncJob.SyncOne(pic); } }
private static bool EnsureProductContext(decimal pid) { using (var db = new YintaiHangzhouContext("YintaiHangzhouContext")) { var productEntity = db.Set<ProductMapEntity>().Where(b => b.ChannelPId == pid).FirstOrDefault(); if (null == productEntity) { using (var erpDb = new ErpContext()) { var exProduct = erpDb.Set<SUPPLY_MIN_PRICE>().Where(ep => ep.PRODUCT_SID == pid).FirstOrDefault(); if (null != exProduct) return ProductSyncJob.SyncOne(exProduct); } } return true; } }