Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        public static void DoJob()
        {
            var shopsModel_TR = DalShopStatistics.GetShopStatisticsByTR(); //统计出来的数据
            var shopsModel_MR = DalShopStatistics.GetShopStatisticsByMR(); //统计出来的数据
            var shopsModel_FW = DalShopStatistics.GetShopStatisticsByFW(); //统计出来的数据
            var shopsModel_PQ = DalShopStatistics.GetShopStatisticsByPQ(); //统计出来的数据
            var shopsModel_BY = DalShopStatistics.GetShopStatisticsByBY(); //统计出来的数据

            Task.WaitAll(shopsModel_TR, shopsModel_MR, shopsModel_FW, shopsModel_PQ, shopsModel_BY);
            var shopsModel = new List <ShopStatisticsModel>();

            shopsModel.AddRange(shopsModel_TR.Result);
            shopsModel.AddRange(shopsModel_MR.Result);
            shopsModel.AddRange(shopsModel_FW.Result);
            shopsModel.AddRange(shopsModel_PQ.Result);
            shopsModel.AddRange(shopsModel_BY.Result);

            var shopsModel_ALL = new List <ShopStatisticsModel>();

            shopsModel.GroupBy(g => g.ShopID).ForEach(f =>
            {
                shopsModel_ALL.Add(new ShopStatisticsModel()
                {
                    ShopID            = f.Key,
                    Type              = "ALL",
                    InstallQuantity   = (f.ToList()?.Sum(e => e.InstallQuantity) ?? 0),
                    CommentR1         = (f.ToList()?.Sum(e => e.CommentR1) ?? 0),
                    CommentR2         = (f.ToList()?.Sum(e => e.CommentR2) ?? 0),
                    CommentR3         = (f.ToList()?.Sum(e => e.CommentR3) ?? 0),
                    CommentR4         = (f.ToList()?.Sum(e => e.CommentR4) ?? 0),
                    CommentTimes      = (f.ToList()?.Sum(e => e.CommentTimes) ?? 0),
                    ApplyCommentRate1 = (f.ToList()?.Sum(e => e.ApplyCommentRate1) ?? 0),
                    ApplyCommentRate2 = (f.ToList()?.Sum(e => e.ApplyCommentRate2) ?? 0),
                    ApplyCommentRate3 = (f.ToList()?.Sum(e => e.ApplyCommentRate3) ?? 0),
                    ApplyCommentRate4 = (f.ToList()?.Sum(e => e.ApplyCommentRate4) ?? 0),
                    ApplyCommentTimes = (f.ToList()?.Sum(e => e.ApplyCommentTimes) ?? 0)
                });
            });
            shopsModel.AddRange(shopsModel_ALL);
            int index = 0;

            if (shopsModel != null && shopsModel.Any())
            {
                Parallel.ForEach(shopsModel.GroupBy(g => g.ShopID), new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 5
                }, e =>
                                 //shopsModel.GroupBy(g => g.ShopID).ForEach(e =>
                {
                    try
                    {
                        var dbShopsModel = DalShopStatistics.GetShopStatisticByShopIds(e.Key);  //数据库ShopStatistic表里的数据
                        e.ToList()?.ForEach(f =>
                        {
                            var temp = dbShopsModel.Where(w => w.ShopID == f.ShopID && w.Type == f.Type).FirstOrDefault();
                            if (temp != null)  //更新
                            {
                                temp.CommentR1         = f.CommentR1;
                                temp.CommentR2         = f.CommentR2;
                                temp.CommentR3         = f.CommentR3;
                                temp.CommentR4         = f.CommentR4;
                                temp.CommentTimes      = f.CommentTimes;
                                temp.InstallQuantity   = f.InstallQuantity;
                                temp.ApplyCommentTimes = f.ApplyCommentTimes;
                                temp.ApplyCommentRate1 = f.ApplyCommentRate1 / (f.ApplyCommentTimes <= 0 ? 1 : f.ApplyCommentTimes);
                                temp.ApplyCommentRate2 = f.ApplyCommentRate2 / (f.ApplyCommentTimes <= 0 ? 1 : f.ApplyCommentTimes);
                                temp.ApplyCommentRate3 = f.ApplyCommentRate3 / (f.ApplyCommentTimes <= 0 ? 1 : f.ApplyCommentTimes);
                                temp.ApplyCommentRate4 = f.ApplyCommentRate4 / (f.ApplyCommentTimes <= 0 ? 1 : f.ApplyCommentTimes);
                                if (!DalShopStatistics.UpdateShopStatistic(temp))
                                {
                                    UpdateShopStatisticsLogger.Warn($"门店评分统计更新失败:ShopId={f.ShopID};Type={f.Type}");
                                }
                            }
                            else  //新增
                            {
                                f.CommentR1         = f.CommentR1;
                                f.CommentR2         = f.CommentR2;
                                f.CommentR3         = f.CommentR3;
                                f.CommentR4         = f.CommentR4;
                                f.CommentTimes      = f.CommentTimes;
                                f.InstallQuantity   = f.InstallQuantity;
                                f.ApplyCommentTimes = f.ApplyCommentTimes;
                                f.ApplyCommentRate1 = f.ApplyCommentRate1 / (f.ApplyCommentTimes <= 0 ? 1 : f.ApplyCommentTimes);
                                f.ApplyCommentRate2 = f.ApplyCommentRate2 / (f.ApplyCommentTimes <= 0 ? 1 : f.ApplyCommentTimes);
                                f.ApplyCommentRate3 = f.ApplyCommentRate3 / (f.ApplyCommentTimes <= 0 ? 1 : f.ApplyCommentTimes);
                                f.ApplyCommentRate4 = f.ApplyCommentRate4 / (f.ApplyCommentTimes <= 0 ? 1 : f.ApplyCommentTimes);
                                if (!DalShopStatistics.InsertShopStatistic(f))
                                {
                                    UpdateShopStatisticsLogger.Warn($"门店评分统计插入失败:Data={f}");
                                }
                            }
                        });
                        index++;
                        UpdateShopStatisticsLogger.Info($"门店评分统计更新:第{index}个门店ShopId={e.Key}数据更新完成");
                    }
                    catch (Exception ex)
                    {
                        UpdateShopStatisticsLogger.Error($"门店评分统计更新异常:ShopId={e.Key};Exception={ex}");
                    }
                });
                #region 重新统计评论总分
                //try
                //{
                //    var setResult = DalShopStatistics.SetTotalPoints();
                //    UpdateShopStatisticsLogger.Info($"门店评分统计更新:设置{setResult}个门店的总评分");
                //}
                //catch (Exception ex)
                //{
                //    UpdateShopStatisticsLogger.Error("门店评分总分统计异常", ex);
                //}
                #endregion
            }
        }
Ejemplo n.º 3
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);
            }
        }