Ejemplo n.º 1
0
        public static List <User> GetUsersByIds(List <Guid> userIds)
        {
            List <User> results = null;

            using (var client = new UserAccountClient())
            {
                var serviceResult = client.GetUsersByIds(userIds);
                serviceResult.ThrowIfException(true);
                results = serviceResult.Result;
                return(results);
            }
        }
        private static List <Tuple <Guid, string> > GetGroupBuyingUserName(List <Guid> userLists)
        {
            var result = new List <Tuple <Guid, string> >();

            using (var client = new UserAccountClient())
            {
                var searchResule = client.GetUsersByIds(userLists);
                if (searchResule.Success && searchResule.Result.Any())
                {
                    foreach (var item in searchResule.Result)
                    {
                        result.Add(new Tuple <Guid, string>(item.UserId, item.Profile.NickName));
                    }
                }
                else
                {
                    Logger.Warn($"GetGroupBuyingUserName==>{string.Join(",", userLists)}");
                }

                return(result);
            }
        }
        void ImportProductComment()
        {
            int minPkid = int.MaxValue;
            int maxPkid = int.MaxValue;

            using (var client = new ConfigClient())
            {
                var response = client.GetOrSetRuntimeSwitch("ProductCommentToTopicJob");
                if (response.Success && (response.Result?.Value ?? false))
                {
                    var pkidArr = response.Result.Description.Split(',');
                    if (pkidArr.Length == 2)
                    {
                        int.TryParse(pkidArr[0], out minPkid);
                        int.TryParse(pkidArr[1], out maxPkid);
                    }
                }
            }
            int current    = 0;
            int pageSize   = 500;
            int pageIndex  = 1;
            int totalCount = GetCommentsCount(minPkid, maxPkid);
            int pageTotal  = (totalCount - 1) / pageSize + 1;

            while (pageIndex <= pageTotal && totalCount > 0)
            {
                pageIndex++;

                var comments = GetComments(minPkid, maxPkid, pageSize);
                Logger.Info(
                    $"ImportProductComment {current}/{totalCount} minPkid={minPkid} 总共获取到 {comments.Rows.Count}条数据");
                if (comments.Rows.Count == 0)
                {
                    break;
                }
                int tempMinPkid = minPkid;
                minPkid = comments.Rows[comments.Rows.Count - 1].GetValue <int>("CommentId");
                Logger.Info(
                    $"ImportProductComment {current}/{totalCount} minPkid={tempMinPkid} maxPkid={minPkid} 开始导入");
                Stopwatch watcher = new Stopwatch();
                watcher.Start();
                var userIds = new List <Guid>(comments.Rows.Count);
                var pids    = new List <string>(comments.Rows.Count);
                foreach (DataRow row in comments.Rows)
                {
                    userIds.Add(row.GetValue <Guid>("CommentUserId"));
                    pids.Add(row.GetValue <string>("CommentProductId"));
                }
                var mobilesDic =
                    new Dictionary <Guid, string>(comments.Rows.Count);
                //批量获取用户手机号
                using (var client = new UserAccountClient())
                {
                    var response = client.GetUsersByIds(userIds);
                    if (response.Success)
                    {
                        foreach (var item in response.Result)
                        {
                            mobilesDic[item.UserId] = item.MobileNumber;
                        }
                    }
                }

                //批量获取产品数据
                var productDic =
                    new Dictionary <string, Service.Product.Models.New.SkuProductDetailModel>(comments.Rows.Count);
                using (var client = new ProductClient())
                {
                    var response = client.SelectSkuProductListByPids(pids);
                    if (response.Success && response.Result.Any())
                    {
                        foreach (var item in response.Result)
                        {
                            productDic[item.Pid] = item;
                        }
                    }
                }
                //批量获取默认车型数据
                var vehicleDt  = GetDefaultVehicleByUserIds(userIds);
                var vehicleDic = new Dictionary <Guid, string>(comments.Rows.Count);
                foreach (DataRow row in vehicleDt.Rows)
                {
                    vehicleDic[row.GetValue <Guid>("UserId")] = row.GetValue <string>("VehicleId");
                }

                Parallel.ForEach(comments.Rows.OfType <DataRow>(),
                                 new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 10
                },
                                 item =>
                {
                    AddTopic(item, mobilesDic, productDic, vehicleDic);
                });
                watcher.Stop();
                current += pageSize;
                Logger.Info(
                    $"ImportProductComment {current}/{totalCount} minPkid={tempMinPkid} maxPkid={minPkid} 导入完毕 用时{watcher.ElapsedMilliseconds}");
            }
        }
        void ImportAdditionComment()
        {
            int minPkid = int.MaxValue;
            int maxPkid = int.MaxValue;

            using (var client = new ConfigClient())
            {
                var response = client.GetOrSetRuntimeSwitch("ProductCommentToTopicJob");
                if (response.Success && (response.Result?.Value ?? false))
                {
                    var pkidArr = response.Result.Description.Split(',');
                    if (pkidArr.Length == 2)
                    {
                        int.TryParse(pkidArr[0], out minPkid);
                        int.TryParse(pkidArr[1], out maxPkid);
                    }
                }
            }
            int current    = 0;
            int pageSize   = 500;
            int pageIndex  = 1;
            int totalCount = GetAdditionCommentsCount(minPkid, maxPkid);
            int pageTotal  = (totalCount - 1) / pageSize + 1;

            while (pageIndex <= pageTotal)
            {
                pageIndex++;

                var comments = GetAdditionComments(minPkid, maxPkid, pageSize);
                Logger.Info(
                    $"ImportAdditionComment {current}/{totalCount} minPkid={minPkid} 总共获取到 {comments.Rows.Count}条数据");
                if (comments.Rows.Count == 0)
                {
                    break;
                }
                int tempMinPkid = minPkid;
                minPkid = comments.Rows[comments.Rows.Count - 1].GetValue <int>("CommentId");
                Logger.Info(
                    $"ImportAdditionComment {current}/{totalCount} minPkid={tempMinPkid} maxPkid={minPkid} 开始导入");
                Stopwatch watcher = new Stopwatch();
                watcher.Start();
                var userIds = new List <Guid>(comments.Rows.Count);
                foreach (DataRow row in comments.Rows)
                {
                    userIds.Add(row.GetValue <Guid>("CommentUserId"));
                }
                var mobilesDic =
                    new Dictionary <Guid, string>(comments.Rows.Count);
                //批量获取用户手机号
                using (var client = new UserAccountClient())
                {
                    var response = client.GetUsersByIds(userIds);
                    if (response.Success)
                    {
                        foreach (var item in response.Result)
                        {
                            mobilesDic[item.UserId] = item.MobileNumber;
                        }
                    }
                }

                Parallel.ForEach(comments.Rows.OfType <DataRow>(),
                                 new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 10
                },
                                 item =>
                {
                    AddReply(item.GetValue <Guid>("CommentUserId"), item.GetValue <string>("CommentUserName"),
                             item.GetValue <int>("CommentId"), item.GetValue <string>("AdditionCommentContent"),
                             item.GetValue <string>("AdditionCommentImages"), item.GetValue <int>("AdditionCommentStatus"),
                             item.GetValue <string>("CreateTime"), item.GetValue <string>("UpdateTime"), item.GetValue <int>("AdditionCommentId"), mobilesDic, false);
                });
                watcher.Stop();
                current += pageSize;
                Logger.Info(
                    $"ImportAdditionComment {current}/{totalCount} minPkid={tempMinPkid} maxPkid={minPkid} 导入完毕 用时{watcher.ElapsedMilliseconds}");
            }
        }