public static void DoJob() { int pageIndex = 1; int totalCount = DalProductStatistics.SelectAdditionCommentCount(); Logger.Info($"更新 {jobName} SelectAdditionCommentCount => count={totalCount}"); int pageTotal = (totalCount - 1) / pageSize + 1; List <int> pageIndexList = new List <int>(); for (; pageIndex <= pageTotal; pageIndex++) { pageIndexList.Add(pageIndex); } Parallel.ForEach(pageIndexList, new ParallelOptions() { MaxDegreeOfParallelism = 5 }, i => { var sw = new Stopwatch(); sw.Start(); ExecuteByPage(i, pageSize); Logger.Info($"更新 追评评论 {jobName} 第{i}页 页数={pageSize} 更新完成 time={sw.ElapsedMilliseconds}ms"); sw.Stop(); }); }
public static void DoJob() { DateTime start = new DateTime(2016, 1, 1); DateTime end = DateTime.Now; int pageIndex = 1; int pageSize = 500; int maxID = DalProductStatistics.SelectCommentsMaxID(); int pageTotal = (maxID - 1) / pageSize + 1; List <int> pageIndexList = new List <int>(); for (; pageIndex <= pageTotal; pageIndex++) { pageIndexList.Add(pageIndex); } Parallel.ForEach(pageIndexList, new ParallelOptions() { MaxDegreeOfParallelism = 5 }, f => { var sw = new Stopwatch(); sw.Start(); BatchUpdateProductCommentLabel(f, pageSize); Logger.Info($"更新门店评论的类型 第{f}页 页数={pageSize} 更新完成 time={sw.ElapsedMilliseconds}ms"); sw.Stop(); }); }
public void Execute(IJobExecutionContext context) { var watcher = new Stopwatch(); watcher.Start(); UpdateProductStatisticsLogger.Info($"产品评分统计更新开始"); int index = 1; try { var allProductComments = DalProductStatistics.GetProductStatisticsByPage(); if (allProductComments != null && allProductComments.Any()) { allProductComments.GroupBy(g => g.ProductID).ForEach(f => { try { var mergeResult = DalProductStatistics.MergeIntoProductStatistics(f.ToList()); if (!mergeResult) { UpdateProductStatisticsLogger.Error($"MergeIntoProductStatistics-->产品评分统计更新失败:ProductId={f.Key}"); } //var dbProductStatistics = DalProductStatistics.GetProductStatisticsByProductId(f.Key); //dbProductStatistics.Split(100).ForEach(oneList => { // var mergeResult = DalProductStatistics.MergeIntoProductStatistics(oneList?.ToList()); // if (!mergeResult) // { // UpdateProductStatisticsLogger.Error($"MergeIntoProductStatistics-->产品评分统计更新失败:ProductId={f.Key}"); // } //}); } catch (Exception ex) { UpdateProductStatisticsLogger.Info($"产品评分统计更新异常:ProductId={f.Key};{ex}"); } index++; UpdateProductStatisticsLogger.Info($"产品评分统计更新:第{index}个商品ProductId={f.Key}数据更新完成"); }); if (!DalProductStatistics.UpdatetCarPAR_CatalogProducts())//更新CarPAR_CatalogProducts中的OrderQuantity,SalesQuantity数据 { UpdateProductStatisticsLogger.Info($"产品评分统计更新:OrderQuantity,SalesQuantity更新失败"); } } } catch (Exception ex) { UpdateProductStatisticsLogger.Info($"产品评分统计更新异常:{ex}"); } watcher.Stop(); UpdateProductStatisticsLogger.Info($"产品评分统计更新结束 time= {watcher.ElapsedMilliseconds}ms"); }
public void Execute(IJobExecutionContext context) { Logger.Info("开始刷新"); var allProductComments = DalProductStatistics.GetProductStatisticsByPage(); if (allProductComments != null && allProductComments.Any()) { var groupResult = allProductComments.GroupBy(g => g.ProductID); Dictionary <string, int> commentTimes = new Dictionary <string, int>(); var productIds = groupResult.Select(x => x.Key).Split(50); try { foreach (var items in productIds) { if (items != null && items.Any()) { using (var clientComment = new ProductCommentClient()) { var productComment = clientComment.GetCommentStatisticCount(items.ToList()); if (productComment.Success && productComment.Result != null) { foreach (var kvp in productComment.Result) { if (kvp.Value != 0) { commentTimes[kvp.Key] = kvp.Value; } } } else { Logger.Error($"comment服务异常.ex:{productComment.Exception}.msg:{productComment.ErrorMessage}"); } } } } if (commentTimes != null && commentTimes.Any()) { var issuccess = DalProductStatistics.UpdateShowCommentTimes(commentTimes); Logger.Info($"结束刷新.result:{issuccess}"); } } catch (System.Exception ex) { Logger.Error(ex); } } Logger.Info("结束刷新"); }
/// <summary> /// 分批执行 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> private static void ExecuteByPage(int pageIndex, int pageSize) { #region 批量更新 List <int> commentIDs = DalProductStatistics.SelectAdditionComment_Page(pageIndex, pageSize).ToList(); if (commentIDs == null || !commentIDs.Any()) { return; } using (var client = new ProductCommentClient()) { var result = client.RefreshCommentToESByCommentIds(commentIDs); if (result.Success && result.Result) { exeCount += commentIDs.Count; Logger.Info($"更新 追评评论 成功 pageIndex ={pageIndex} & exeCount{exeCount}"); } else { Logger.Info($"更新 追评评论 失败 pageIndex ={pageIndex} 异常 message={result.ErrorMessage} & maxid={commentIDs.Max()}&minid={commentIDs.Min()} "); } } #endregion }
private static void BatchUpdateProductCommentLabel(int pageIndex, int pageSize) { #region 批量更新 List <EsProductCommentModel> comments = DalProductStatistics.SelectCommentsByPage(pageIndex, pageSize).Result.ToList(); count += comments.Count; if (comments == null || !comments.Any()) { return; } using (var client = new ProductCommentClient()) { var result = client.RefreshCommentToESByCommentIds(comments.Select(p => p.Id).ToList()); if (result.Success && result.Result) { Logger.Info($"更新 产品评论的标签 BatchUpdateProductCommentLabel pageIndex ={pageIndex} 有效的 comment 数目 ={comments.Count()} & 总次数count{count}"); } else { Logger.Info($"更新 产品评论的标签 更新失败 BatchUpdateProductCommentLabel pageIndex ={pageIndex} 异常 message={result.ErrorMessage} & ={comments.Count()}"); } } #endregion }