public void Execute(IJobExecutionContext context) { int totalCount = GroupBuyingDal.SelectProductCount(); int pageNum = (totalCount + MaxSyncCount - 1) / MaxSyncCount; Logger.Info($"同步拼团已开团数开始.一共{totalCount}个产品.一共{pageNum}批次."); int maxPkid = 0; if (totalCount > 0) { var sbMsg = new StringBuilder(); for (int index = 0; index <= pageNum; index++) { var products = GroupBuyingDal.SelectProducts(MaxSyncCount, ref maxPkid); if (products != null && products.Any()) { foreach (var item in products) { item.CurrentPGroupCount = GroupBuyingDal .GetCurrentGroupCount(item.ProductGroupId, item.Pid); if (GroupBuyingDal.UpdateGroupCount(item)) { if (item.CurrentPGroupCount >= item.TotalPGroupCount && item.TotalPGroupCount != 0) { sbMsg.AppendLine($"{item.ProductGroupId} {item.Pid} 到达开团上限," + $"已开团数:{item.CurrentPGroupCount},限开团数:{item.TotalPGroupCount}"); } } } } Logger.Info($"结束刷新第{index}批次,一共{pageNum}批次.MaxPkid:{maxPkid}"); } if (sbMsg.Length > 0) { Logger.Info(sbMsg.ToString()); PinTuanServiceProxy.NotifyEmployee( new Service.PinTuan.Models.NotifyEmployeeRequest { ErrorMessage = sbMsg.ToString() }); } } Logger.Info($"同步拼团已开团数结束."); }
public void Execute(IJobExecutionContext context) { int totalCount = GroupBuyingDal.SelectProductGroupCount(); int pageNum = (totalCount + MaxSyncCount - 1) / MaxSyncCount; Logger.Info($"同步拼团产品ES数据开始.一共{totalCount}个团.一共{pageNum}批次."); int maxPkid = 0; for (int index = 0; index <= pageNum; index++) { var groups = GroupBuyingDal.SelectProductGroups(MaxSyncCount, ref maxPkid); if (groups != null && groups.Any()) { foreach (var item in groups) { // 比较ES与DB的数据,然后删除ES中多余(DB不存在)的数据 var dbProductIds = GroupBuyingDal.SelectGroupBuyingProducts(item.ProductGroupId).Select(x => x.Pid); var esProductIds = GetESGroupBuyingProducts(item.ProductGroupId).Select(x => x.PID); var pids = esProductIds.Except(dbProductIds).ToList(); if (pids.Any()) { var products = pids.Select(pid => new ESGroupBuyingProduct { PID = pid, ProductGroupId = item.ProductGroupId, ProductIndex = $"{item.ProductGroupId}/{pid}" }).ToList(); DeleteESGroupBuyingProducts(products); } } } Logger.Info($"结束刷新第{index}批次,一共{pageNum}批次.MaxPkid:{maxPkid}"); } }