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");
        }
Exemplo n.º 2
0
        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("结束刷新");
        }