예제 #1
0
 private static void Done(List <int> data)
 {
     if (data.Any())
     {
         var       num = 1;
         Stopwatch sw  = new Stopwatch();
         sw.Start();
         foreach (var item in data)
         {
             using (var client = new OrderQueryClient())
             {
                 var dat = client.GetRelatedSplitOrderIDs(item, SplitQueryType.Full);
                 if (dat.Success && dat.Result.Count() == 1)
                 {
                     using (var client2 = new ShopCommentClient())
                     {
                         var result = client2.SetShopCommentStatus(item);
                         if (result.Success == false || result.Result == false)
                         {
                             OrderDataLogger.Warn($"重置订单号为{item}的数据失败");
                         }
                     }
                 }
             }
             if (num % 20 == 0)
             {
                 sw.Stop();
                 OrderDataLogger.Info($"重置异常订单第{num - 20}到{num}条,共{data.Count},用时{sw.ElapsedMilliseconds}");
                 sw.Reset();
                 sw.Start();
             }
             num += 1;
         }
     }
 }
예제 #2
0
 public JsonResult ResetCommentStatus(int orderId)
 {
     using (var client = new ShopCommentClient())
     {
         var result = client.SetShopCommentStatus(orderId);
         if (result.Success && result.Result)
         {
             return(Json($"重置成功{result.Success},{orderId}", JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json($"失败{result.Success},{orderId}", JsonRequestBehavior.AllowGet));
         }
     }
 }
예제 #3
0
        private static void BatchUpdate(int pageIndex, int pageSize, DateTime start, DateTime end)
        {
            List <ShopCommentDataModel> comments = DalShopCommentSync.GetShopCommentsPage(pageIndex, pageSize, start.ToString("yyyy-MM-dd"), end.AddDays(1).ToString("yyyy-MM-dd")).ToList();

            #region 批量更新
            using (var client = new ShopCommentClient())
            {
                var result = client.BatchGetShopCommentType(comments.Select(p => p.OrderId).ToList());
                if (result.Success && result.Result.Any())
                {
                    Logger.Info($"更新门店评论的类型 BatchGetShopCommentType pageIndex ={pageIndex} 有效的 shoptype 数目 ={result.Result.Where(p => !string.IsNullOrWhiteSpace(p.ShopType)).Count()} time={result.ElapsedMilliseconds} ");
                    foreach (var item in comments)
                    {
                        try
                        {
                            if (result.Success && result.Result.Any())
                            {
                                string ShopType = result.Result.Where(p => p.OrderId == item.OrderId).FirstOrDefault()?.ShopType;
                                if (!string.IsNullOrWhiteSpace(ShopType))
                                {
                                    if (DalShopCommentSync.UpdateShopCommentShopType(item.CommentId ?? 0, ShopType))
                                    {
                                        //logger.Info($"更新门店评论的类型 更新  完成 CommentId={item.CommentId}& ShopType={ShopType}");
                                    }
                                    else
                                    {
                                        Logger.Error($"更新门店评论的类型 UpdateShopCommentShopType 更新失败 CommentId={item.CommentId}& ShopType={ShopType} ");
                                    }
                                }
                                else
                                {
                                    //logger.Info($"更新门店评论的类型 BatchGetShopCommentType 更新 失败 CommentId={item.CommentId}& ShopType={ShopType}");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Info($"更新门店评论的类型 BatchGetShopCommentType 更新 失败 CommentId={item.CommentId}& ex={ex.Message}");
                        }
                    }
                }
                else
                {
                    Logger.Info($"更新门店评论的类型  更新失败 BatchGetShopCommentType 异常 message={result.ErrorMessage} & count ={result.Result.Count()}");
                }
            }
            #endregion
        }
예제 #4
0
        public void Execute(IJobExecutionContext context)
        {
            //分页读取技师信息
            //从Tuhu_comment..TechnicianComment 里统计每个技师的平均分
            //写入到 Tuhu_comment..TechnicianStatistics 里
            try
            {
                Logger.Info("开始执行");
                int pageIndex = 1;
                int pageSize  = 1000;
                int total     = DalShopStatistics.GetTechsCount();
                int pageTotal = (total - 1) / pageSize + 1;

                for (; pageIndex <= pageTotal; pageIndex++)
                {
                    var techs = DalShopStatistics.GetTechsPage(pageIndex, pageSize);
                    techs.ForEach((item) =>
                    {
                        //查询门店里的美容团购订单
                        var statistics = DalShopCommentSync.GetTechCommentStatistics(item.PKID);

                        Parallel.ForEach(statistics, new ParallelOptions()
                        {
                            MaxDegreeOfParallelism = 3
                        }, s =>
                        {
                            DalShopCommentSync.SyncTechCommentStatistics(s.ShopId, s.TechnicianId, s);
                        });
                    });
                }

                using (var client = new ShopCommentClient()) {
                    client.RefreshCommentStatisticsCache(1);
                }
                Logger.Info("执行结束");
            }
            catch (Exception e)
            {
                Logger.Error("执行异常", e);
            }
        }
예제 #5
0
        public void Execute(IJobExecutionContext context)
        {
            //分页读取门店信息
            //分页获取美容团购订单,对已经统计过的产品-shopid,不在统计,对没统计过的产品,进行统计
            //把统计的结果写入到 Tuhu_comment..ShopCommentStatistics

            try
            {
                logger.Info("开始执行");
                int pageIndex = 1;
                int pageSize  = 1000;
                int total     = DalShopStatistics.GetShopsCount();
                int pageTotal = (total - 1) / pageSize + 1;

                for (; pageIndex <= pageTotal; pageIndex++)
                {
                    logger.Info($"门店页码 {pageIndex}/{pageTotal}");
                    var shops = DalShopStatistics.GetShopsPage(pageIndex, pageSize);
                    shops.ForEach((item) =>
                    {
                        //查询门店里的美容团购订单
                        int shopPageIndex = 1;
                        int shopPageSize  = 1000;
                        int shopTotal     = DalShopCommentSync.GetShopCommentOrderCount(item.PKID);
                        int shopPageTotal = (shopTotal - 1) / shopPageSize + 1;
                        for (; shopPageIndex <= shopPageTotal; shopPageIndex++)
                        {
                            logger.Info($"门店评论页码 shopId:{item.PKID} {shopPageIndex}/{shopPageTotal}");
                            var orders = DalShopCommentSync.GetShopCommentOrder(shopPageIndex, shopPageSize, item.PKID);
                            var index  = shopPageIndex;
                            Parallel.ForEach(orders, new ParallelOptions()
                            {
                                MaxDegreeOfParallelism = 5
                            }, order =>
                            {
                                //获取这个订单下的所有产品
                                var orderProducts = DalShopCommentSync.GetShopOrderProduct(order.OrderId);
                                logger.Info($"门店评论页码 shopId:{item.PKID} {index}/{shopPageTotal} orderid:{order.OrderId}");
                                foreach (var product in orderProducts)
                                {
                                    using (var client =
                                               CacheHelper.CreateCounterClient(typeof(ShopCommentStatisticsJob).FullName,
                                                                               TimeSpan.FromHours(12)))
                                    {
                                        var response = client.Increment(item.PKID + product.Pid);
                                        if (response.Success && response.Value > 1)
                                        {
                                            continue;
                                        }
                                    }

                                    //获取这个门店下这个产品对应的所有订单号
                                    var productOrders =
                                        DalShopCommentSync.GetShopProductOrder(item.PKID, product.Pid);
                                    //根据这个产品的所有订单号统计评论的平均分,写入到这个产品下
                                    var statistics = DalShopCommentSync.GetShopCommentStatistics(item.PKID, product.Pid,
                                                                                                 productOrders.Select(x => x.CommentId));

                                    foreach (var s in statistics)
                                    {
                                        DalShopCommentSync.SyncShopCommentStatistics(s.ShopId, s);
                                    }
                                }
                            });
                            logger.Info($"门店评论页码 shopId:{item.PKID} {shopPageIndex}/{shopPageTotal} 执行结束");
                        }
                    });
                    logger.Info($"门店页码 {pageIndex}/{pageTotal} 执行结束");
                }
                using (var client = new ShopCommentClient())
                {
                    client.RefreshCommentStatisticsCache(2);
                }
                logger.Info("执行结束");
            }
            catch (Exception e)
            {
                logger.Error("执行异常", e);
            }
        }