Beispiel #1
0
 public void AccountSyncing(int userId)
 {
     using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
     {
         var account   = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.FavorCount && ua.User_Id == userId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault();
         var favorites = db.Favorites.Where(p => p.User_Id == userId && p.Status != (int)DataStatus.Deleted).Count();
         if (account != null)
         {
             account.Amount          = favorites;
             account.UpdatedDate     = DateTime.Now;
             db.Entry(account).State = System.Data.EntityState.Modified;
             db.SaveChanges();
         }
         else
         {
             db.UserAccounts.Add(new UserAccountEntity()
             {
                 AccountType = (int)AccountType.FavorCount,
                 Amount      = favorites,
                 User_Id     = userId,
                 Status      = (int)DataStatus.Normal,
                 CreatedDate = DateTime.Now,
                 CreatedUser = userId,
                 UpdatedDate = DateTime.Now,
                 UpdatedUser = userId
             });
         }
     }
 }
Beispiel #2
0
        private void updateILike(YintaiHangzhouContext db, int accountId)
        {
            var account = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.IlikeCount && ua.User_Id == accountId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault();
            var likes   = db.Likes.Where(p => p.LikeUserId == accountId && p.Status != (int)DataStatus.Deleted).Count();

            if (account != null)
            {
                account.Amount          = likes;
                account.UpdatedDate     = DateTime.Now;
                db.Entry(account).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                db.UserAccounts.Add(new UserAccountEntity()
                {
                    AccountType = (int)AccountType.IlikeCount,
                    Amount      = likes,
                    User_Id     = accountId,
                    Status      = (int)DataStatus.Normal,
                    CreatedDate = DateTime.Now,
                    CreatedUser = accountId,
                    UpdatedDate = DateTime.Now,
                    UpdatedUser = accountId
                });
            }
        }
Beispiel #3
0
        private void updateILike(YintaiHangzhouContext db, int accountId)
        {
            var account = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.IlikeCount && ua.User_Id == accountId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault();
            var likes = db.Likes.Where(p => p.LikeUserId == accountId && p.Status != (int)DataStatus.Deleted).Count();
            if (account != null)
            {
                account.Amount = likes;
                account.UpdatedDate = DateTime.Now;
                db.Entry(account).State = System.Data.EntityState.Modified;
                db.SaveChanges();

            }
            else
            {
                db.UserAccounts.Add(new UserAccountEntity()
                {
                    AccountType = (int)AccountType.IlikeCount,
                    Amount = likes,
                    User_Id = accountId,
                    Status = (int)DataStatus.Normal,
                    CreatedDate = DateTime.Now,
                    CreatedUser = accountId,
                    UpdatedDate = DateTime.Now,
                    UpdatedUser = accountId
                });
            } 
        }
        public void AccountSyncing(int userId)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var account = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.FavorCount && ua.User_Id == userId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault();
                var favorites = db.Favorites.Where(p => p.User_Id == userId && p.Status != (int)DataStatus.Deleted ).Count();            
                if (account != null)
                {
                    account.Amount = favorites;
                    account.UpdatedDate = DateTime.Now;
                    db.Entry(account).State = System.Data.EntityState.Modified;
                    

                }
                else
                {
                    db.UserAccounts.Add(new UserAccountEntity()
                    {
                        AccountType = (int)AccountType.FavorCount,
                        Amount = favorites,
                        User_Id = userId,
                        Status = (int)DataStatus.Normal,
                        CreatedDate = DateTime.Now,
                        CreatedUser = userId,
                        UpdatedDate = DateTime.Now,
                        UpdatedUser = userId
                    });
                }
                db.SaveChanges();
            }
        }
        public static void SyncOne(PRO_CLASS_DICT cat)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var existCat = db.Set<CategoryEntity>().Where(b => b.ExCatId == cat.SID).FirstOrDefault();
                if (existCat == null)
                {
                    db.Categories.Add(new CategoryEntity()
                    {
                        ExCatCode = cat.PRO_CLASS_NUM,
                        ExCatId = (int)cat.SID,
                        Name = cat.PRO_CLASS_DESC,
                        Status = 1,
                        UpdateDate = cat.OPT_UPDATE_TIME ?? DateTime.Now

                    });
                }
                else
                {
                    existCat.ExCatCode = cat.PRO_CLASS_NUM;
                    existCat.Name = cat.PRO_CLASS_DESC;
                    existCat.UpdateDate = cat.OPT_UPDATE_TIME ?? DateTime.Now;
                }
                db.SaveChanges();

            }
        }
Beispiel #6
0
 public void AccountSyncing(int userId)
 {
     using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
     {
         updateILike(db, LikeUserId);
         updateLikeMe(db, LikedUserId);
     }
 }
Beispiel #7
0
 public void AccountSyncing(int userId)
 {
     using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
     {
         updateILike(db, LikeUserId);
         updateLikeMe(db, LikedUserId);
     }
 }
Beispiel #8
0
        private void Query(DateTime benchTime, Action<IQueryable<OrderTransactionEntity>> callback)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var accounts = db.Set<OrderTransactionEntity>().Where(ot => ot.IsSynced == false);

                if (callback != null)
                    callback(accounts);
            }
        }
        private void DoSyncWXReply(string host, string public_key, string private_key, DateTime benchDate)
        {
            ILog log = LogManager.GetLogger(this.GetType());
            int cursor = 0;
           int size = JobConfig.DEFAULT_PAGE_SIZE;
            int successCount = 0;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var prods = from r in db.WXReplies
                            where (r.UpdateDate >= benchDate)
                            select r;

                int totalCount = prods.Count();
                while (cursor < totalCount)
                {
                    var linq = prods.OrderByDescending(p => p.Id).Skip(cursor).Take(size).ToList();
                    foreach (var l in linq)
                    {
                        try
                        {
                           dynamic jsonResponse = null;
                           if (AwsHelper.SendHttpMessage(host, new
                            {
                                id = l.Id,
                                rkey = l.MatchKey,
                                rmsg = l.ReplyMsg,
                                status = l.Status
                            }, public_key, private_key, r => jsonResponse = r, null))
                           {
                               successCount++;
                           }
                           else
                           {
                               log.Info("request error!");
                               continue;
                           }

                            
                        }
                        catch (Exception ex)
                        {
                            log.Info(ex);
                        }
                    }

                    cursor += size;
                }

            }
            sw.Stop();
            log.Info(string.Format("{0} wx rely message in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));
            
        }
        private void Query(DateTime benchTime, Action<IQueryable<OrderEntity>> callback)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var orders = db.Set<OrderEntity>().Where(ot => ot.Status == (int)OrderStatus.Create 
                            && ot.CreateDate < benchTime);

                if (callback != null)
                    callback(orders);
            }
        }
Beispiel #11
0
        private static void EnsureSectionContext(SALE_CODE section)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var entity = db.Set<StoreEntity>().Where(b => b.ExStoreId == section.SHOP_SID).FirstOrDefault();
                if (null == entity)
                {
                    StoreSyncJob.SyncOne(section.SHOP_INFO);
                }

            }
        }
        private void internalVoidOrderWhenRMAComplete()
        {
            ILog log = LogManager.GetLogger(this.GetType());
            int cursor = 0;
            int size = JobConfig.DEFAULT_PAGE_SIZE;
            int successCount = 0;
            var benchDate = DateTime.Today;
            var toBenchDate = benchDate.AddDays(1);
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {

                var rmas = db.RMAs.Where(r => r.Status == (int)RMAStatus.Complete && r.UpdateDate >= benchDate && r.UpdateDate < toBenchDate);
                int totalCount = rmas.Count();
                while (cursor < totalCount)
                {
                    var result = rmas.OrderByDescending(r => r.Id).Skip(cursor).Take(size);
                    foreach (var rma in result)
                    {
                        var rmaQuantity = db.RMAs.Where(r => r.OrderNo == rma.OrderNo && r.Status == (int)RMAStatus.Complete)
                                         .Join(db.RMAItems, o => o.RMANo, i => i.RMANo, (o, i) => i).Sum(i => i.Quantity);
                        var totalQuantity = db.OrderItems.Where(o => o.OrderNo == rma.OrderNo).Sum(i => i.Quantity);
                        if (rmaQuantity != totalQuantity)
                            continue;
                        var orderEntity = db.Orders.Where(o => o.OrderNo == rma.OrderNo).First();
                        if (orderEntity.Status != (int)OrderStatus.RMAd)
                        {
                            orderEntity.Status = (int)OrderStatus.RMAd;
                            orderEntity.UpdateDate = DateTime.Now;

                            db.OrderLogs.Add(new OrderLogEntity()
                            {
                                CreateDate = DateTime.Now,
                                CreateUser = 0,
                                CustomerId = orderEntity.CustomerId,
                                Operation = "订单全部退货",
                                OrderNo = orderEntity.OrderNo,
                                Type = (int)OrderOpera.FromSystem
                            });

                            db.SaveChanges();
                            successCount++;
                        }
                    }
                    cursor += size;
                }

            }
            sw.Stop();
            log.Info(string.Format("{0} order convert to rmad in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));

        }
        public void AccountSyncing(int userId)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var offlineAccount = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.OfflineCoupon && ua.User_Id == userId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault();
                var account = db.UserAccounts.Where(ua => ua.AccountType == (int)AccountType.Coupon && ua.User_Id == userId && ua.Status != (int)DataStatus.Deleted).FirstOrDefault();
                var sumCoupons = db.CouponHistories.Where(p => p.User_Id == userId && p.Status != (int)DataStatus.Deleted && p.ValidEndDate >= DateTime.Now && p.Status != (int)CouponStatus.Used).Count();
                var sumStoreCoupons = db.StoreCoupons.Where(p => p.UserId == userId && p.Status != (int)DataStatus.Deleted && p.ValidEndDate >= DateTime.Now && p.Status != (int)CouponStatus.Used).Count();
                if (offlineAccount != null)
                {
                    offlineAccount.Amount = sumStoreCoupons;
                    offlineAccount.UpdatedDate = DateTime.Now;
                    db.Entry(offlineAccount).State = System.Data.EntityState.Modified;
                }
                else
                {
                    db.UserAccounts.Add(new UserAccountEntity()
                    {
                        AccountType = (int)AccountType.OfflineCoupon,
                        Amount = sumStoreCoupons,
                        User_Id = userId,
                        Status = (int)DataStatus.Normal,
                        CreatedDate = DateTime.Now,
                        CreatedUser = userId,
                        UpdatedDate = DateTime.Now,
                        UpdatedUser = userId
                    });
                }
                if (account != null)
                {
                    account.Amount = sumCoupons + sumStoreCoupons;
                    account.UpdatedDate = DateTime.Now;
                    db.Entry(account).State = System.Data.EntityState.Modified;


                }
                else
                {
                    db.UserAccounts.Add(new UserAccountEntity()
                    {
                        AccountType = (int)AccountType.Coupon,
                        Amount = sumCoupons + sumStoreCoupons,
                        User_Id = userId,
                        Status = (int)DataStatus.Normal,
                        CreatedDate = DateTime.Now,
                        CreatedUser = userId,
                        UpdatedDate = DateTime.Now,
                        UpdatedUser = userId
                    });
                }
                db.SaveChanges();
            }
        }
        private void Query(Action<IQueryable<ProductMapEntity>> callback)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var pms = db.Set<ProductMapEntity>()
                          .Join(db.Set<ProductEntity>().Where(p=>p.Status==1),o=>o.ProductId,i=>i.Id,(o,i)=>o)
                          .Where(pm => !db.Set<ResourceEntity>().Where(r => r.SourceType == (int)SourceType.Product).Any(r => r.SourceId == pm.ProductId));

                if (callback != null)
                    callback(pms);
            }
        }
        private void Query(Action<IQueryable<ExOrderEntity>> callback)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {

                var prods = db.Set<ExOrderEntity>().Where(o =>o.IsShipped.HasValue && o.IsShipped.Value== true
                            && !db.Set<JobSuccessHistoryEntity>().Any(j => j.JobType == (int)JobType.Wx_ShippingEx && j.JobId == o.Id));


                if (callback != null)
                    callback(prods);
            }
        }
         private void Query(Action<IQueryable<OrderEntity>> callback)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {

                var prods = db.Set<OrderEntity>().Where(o => o.Status >= (int)OrderStatus.Shipped
                            && o.OrderSource == WxPayConfig.ORDER_SOURCE
                            && !db.Set<JobSuccessHistoryEntity>().Any(j => j.JobType == (int)JobType.Wx_Shipping && j.JobId == o.Id));


                if (callback != null)
                    callback(prods);
            }
        }
        private void Query(DateTime benchTime, Action<IQueryable<Map4Order>> callback)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var orders =
                    db.Set<Map4Order>()
                        .Where(
                            m =>
                                m.CreateDate >= benchTime && m.Channel == ConstValue.WGW_CHANNEL_NAME &&
                                !db.Set<Order2ExEntity>().Any(o => o.OrderNo == m.OrderNo));

                if (callback != null)
                    callback(orders);
            }
        }
Beispiel #18
0
        private void IndexStorePromotion(ElasticClient client, DateTime benchDate)
        {
            ILog log = LogManager.GetLogger(this.GetType());
            int cursor = 0;
           int size = JobConfig.DEFAULT_PAGE_SIZE;
            int successCount = 0;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var prods = db.StorePromotions.Where(r=> r.CreateDate >= benchDate || r.UpdateDate >= benchDate)
                            .GroupJoin(db.PointOrderRules.Where(r=>r.Status!=(int)DataStatus.Deleted),o=>o.Id,i=>i.StorePromotionId,
                                    (o,i)=>new {S=o,R = i});

                int totalCount = prods.Count();
                client.MapFromAttributes<ESStorePromotion>();
                while (cursor < totalCount)
                {
                    var linq = from l in prods.OrderByDescending(p => p.S.Id).Skip(cursor).Take(size).ToList()
                               select new ESStorePromotion().FromEntity<ESStorePromotion>(l.S, s => { 
                                    s.ExchangeRule = JsonConvert.SerializeObject(l.R.Select(r=>new {
                                        rangefrom=r.RangeFrom,
                                        rangeto = r.RangeTo,
                                        ratio = r.Ratio
                                    }));
                               });
                    var result = client.IndexMany(linq);
                    if (!result.IsValid)
                    {
                        foreach (var item in result.Items)
                        {
                            if (item.OK)
                                successCount++;
                            else
                                log.Info(string.Format("id index failed:{0}", item.Id));
                        }
                    }
                    else
                        successCount += result.Items.Count();

                    cursor += size;
                }

            }
            sw.Stop();
            log.Info(string.Format("{0} store promotions in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));
            
        }
Beispiel #19
0
        public void Notify(int id)
        {
            int notifiedId = NotifyId;

            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                db.NotificationLogs.Add(new NotificationLogEntity()
                {
                    CreateDate = DateTime.Now,
                    SourceId   = notifiedId,
                    SourceType = (int)Yintai.Hangzhou.Model.Enums.SourceType.Comment,
                    Status     = (int)NotificationStatus.Default
                });
                db.SaveChanges();
            }
        }
        protected virtual void QueueNotification(PushBroker push,IJobExecutionContext context)
        {
            ILog log = LogManager.GetLogger(typeof(ApnsNotificationJob));
            int cursor = 0;
           int size = JobConfig.DEFAULT_PAGE_SIZE;
            int successCount = 0;
            DateTime startDate = DateTime.Today;
            DateTime endDate = startDate.AddDays(1);
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var prods = (from p in db.Promotions
                            where (p.StartDate >= startDate && p.StartDate < endDate)
                            && p.Status == 1
                             select p).OrderByDescending(p=>p.IsTop).ThenByDescending(p=>p.CreatedDate).FirstOrDefault();
                if (prods != null)
                {
                    var devices = (from d in db.DeviceLogs
                                   where d.Status == 1

                                   select new {DeviceToken = d.DeviceToken }).Distinct();

                    int totalCount = devices.Count();
                    while (cursor < totalCount)
                    {
                        var pageDevices = devices.OrderBy(o=>o.DeviceToken).Skip(cursor).Take(size);
                        foreach (var device in pageDevices)
                        {
                            push.QueueNotification(new AppleNotification()
                                               .ForDeviceToken(device.DeviceToken)
                                               .WithAlert(prods.Name)
                                               .WithBadge(1)
                                               .WithCustomItem("from",JsonConvert.SerializeObject(new {targettype=(int)PushSourceType.Promotion,targetvalue=prods.Id.ToString()}))
                                               .WithSound("sound.caf"));
                            successCount++;
                        }

                        cursor += size;
                    }
                }

            }
            sw.Stop();
            log.Info(string.Format("{0} notifications in {1} => {2} notis/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));

        }
        public void Execute(IJobExecutionContext context)
        {
            ILog log = LogManager.GetLogger(this.GetType());

            JobDataMap data = context.JobDetail.JobDataMap;
            var benchDate = data.ContainsKey("benchdate") ? data.GetDateTime("benchdate") : DateTime.Today.AddDays(-1);
            if (!data.ContainsKey("intervalofsec"))
            {
                log.Info("intervalofsec not set");
                return;
            }
            var secondsInterval = data.ContainsKey("intervalofsec");
            int successCount = 0;
            int cursor = 0;
           int size = JobConfig.DEFAULT_PAGE_SIZE;

            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                
                /*
                int totalCount = 0;
                while (cursor < totalCount)
                {
                    var linq = prods.OrderByDescending(p => p.Id).Skip(cursor).Take(size).ToList();
                    foreach (var l in linq)
                    {
                        var sumPoints = db.PointHistories.Where(p => p.User_Id == l.User_Id && p.Status != (int)DataStatus.Deleted).Sum(p => p.Amount);
                        if (sumPoints == l.Amount)
                            continue;
                        l.Amount = sumPoints > 0 ? sumPoints : 0;
                        l.UpdatedDate = DateTime.Now;
                        db.Entry(l).State = System.Data.EntityState.Modified;
                        db.SaveChanges();
                        successCount++;
                    }

                    cursor += size;
                }
                 * */

            }
            sw.Stop();
            log.Info(string.Format("{0} external products in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));

        }
 private void Query(YintaiHangzhouContext db, int minPoints, Action<IQueryable<LinqInner>> callback)
 {
     var accounts = from p in db.UserAccounts
                    join c in db.Cards on p.User_Id equals c.User_Id
                    where p.AccountType == (int)AccountType.Point
                      && p.Status == (int)DataStatus.Normal
                      && p.Amount >= minPoints
                      && c.CardNo.Length > 0
                      && (!c.IsLocked.HasValue || c.IsLocked.Value==false)
                    select new LinqInner()
                    {
                        U = p,
                        C = c
                    };
     if (callback != null)
         callback(accounts);
 }
        public void Notify(int id)
        {
            int notifiedId = NotifyId;
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                db.NotificationLogs.Add(new NotificationLogEntity()
                {
                    CreateDate = DateTime.Now,
                    SourceId = notifiedId,
                    SourceType = (int)Yintai.Hangzhou.Model.Enums.SourceType.PMessage,
                    Status = (int)NotificationStatus.Default

                });
                db.SaveChanges();

            }
        }
Beispiel #24
0
        public static void SyncOne(SHOP_INFO store)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var existStore = db.Set<StoreEntity>().Where(b => b.ExStoreId == store.SID).FirstOrDefault();
                if (existStore == null)
                {
                    db.Stores.Add(new StoreEntity()
                    {

                        CreatedDate = DateTime.Now,
                        CreatedUser = 0,
                        ExStoreId = (int)store.SID,
                        Description = string.Empty,
                        Location = store.SHOP_ADDR??string.Empty,
                        Name = store.SHOP_NAME,
                        RMAAddress = store.SHOP_ADDR,
                        RMAPerson = store.REFUND_LINKER,
                        RMAPhone = store.REFUND_TEL,
                        RMAZipCode = store.POSTCODE.HasValue?store.POSTCODE.ToString():string.Empty,
                        UpdatedDate = store.OPT_UPDATE_TIME ?? DateTime.Now,
                        UpdatedUser = 0,
                        Status = 1,
                        Tel = store.LINKER_PHONE??string.Empty

                    });
                }
                else
                {
                    existStore.RMAZipCode = store.POSTCODE.HasValue ? store.POSTCODE.ToString() : string.Empty;
                    existStore.RMAPhone = store.REFUND_TEL;
                    existStore.RMAAddress = store.SHOP_ADDR;
                    existStore.RMAPerson = store.REFUND_LINKER;
                    existStore.UpdatedDate = store.OPT_UPDATE_TIME ?? DateTime.Now;
                    existStore.Location = store.SHOP_ADDR??string.Empty;
                    existStore.Tel = store.LINKER_PHONE ?? string.Empty;
                    existStore.Name = store.SHOP_NAME;
                    db.Entry(existStore).State = System.Data.EntityState.Modified;
                }
                db.SaveChanges();

            }
        }
Beispiel #25
0
        public static void SyncOne(BRAND brand)
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var existBrand = db.Set<BrandEntity>().Where(b => b.ChannelBrandId == brand.SID).FirstOrDefault();
                if (existBrand == null)
                {
                    db.Brands.Add(new BrandEntity()
                    {
                        ChannelBrandId = (int)brand.SID,
                        CreatedDate = DateTime.Now,
                        CreatedUser = 0,
                        Name = brand.BRAND_NAME,
                        EnglishName = brand.BRAND_NAME_SECOND,
                        Logo = brand.PICTURE_URL??string.Empty,
                        Status = brand.BRAND_ACTIVE_BIT,
                        UpdatedDate = brand.OPT_UPDATE_TIME ?? DateTime.Now,
                        UpdatedUser = 0,
                        Description = brand.BRAND_STORY??string.Empty,
                        Group = (brand.BRAND_GROUP_NUM??0).ToString(),
                         WebSite = string.Empty

                    });
                }
                else
                {
                    existBrand.Name = brand.BRAND_NAME;
                    existBrand.EnglishName = brand.BRAND_NAME_SECOND;
                    existBrand.Logo = brand.PICTURE_URL??string.Empty;;
                    existBrand.Status = brand.BRAND_ACTIVE_BIT;
                    existBrand.UpdatedUser = 0;
                    existBrand.UpdatedDate = brand.OPT_UPDATE_TIME ?? DateTime.Now;
                    existBrand.Description = brand.BRAND_STORY??string.Empty;
                    existBrand.Group = (brand.BRAND_GROUP_NUM ?? 0).ToString();

                    db.Entry(existBrand).State = System.Data.EntityState.Modified;
                  
                }
                db.SaveChanges();

            }
        }
        public object Composing()
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var linq = db.StoreCoupons.Find(this.SyncId);
                if (linq == null)
                    return null;
                return new
                {
                    id = linq.Id,
                    status = linq.Status,
                    code = linq.Code,
                    amount = linq.Amount,
                    userid = linq.UserId,
                    validstartdate = linq.ValidStartDate.GetValueOrDefault().ToUniversalTime(),
                    validenddate = linq.ValidEndDate.GetValueOrDefault().ToUniversalTime(),
                    vipcard = linq.VipCard,
                    lastupdate = linq.UpdateDate.GetValueOrDefault().ToUniversalTime()

                };
            }
        }
        public object Composing()
        {
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var linq = db.CouponHistories.Find(this.SyncId);
                if (linq == null)
                    return null;
                return new
                {
                    id = linq.Id,
                    status = linq.Status,
                    code = linq.CouponId,
                    amount = 0m,
                    userid = linq.User_Id,
                    validstartdate = linq.ValidStartDate.ToUniversalTime(),
                    validenddate = linq.ValidEndDate.ToUniversalTime(),
                    vipcard = 0,
                    islimitonce = linq.IsLimitOnce??false

                };
            }
        }
Beispiel #28
0
 public object Composing()
 {
     using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
     {
         var linq = db.CouponHistories.Find(this.SyncId);
         if (linq == null)
         {
             return(null);
         }
         return(new
         {
             id = linq.Id,
             status = linq.Status,
             code = linq.CouponId,
             amount = 0m,
             userid = linq.User_Id,
             validstartdate = linq.ValidStartDate.ToUniversalTime(),
             validenddate = linq.ValidEndDate.ToUniversalTime(),
             vipcard = 0
         });
     }
 }
        private static bool EnsureProductContext(SUPPLY_MIN_PRICE_MX product)
        {
            bool shouldSyncProduct = false;
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {

                var colorEntity = db.Set<ProductPropertyValueEntity>().Where(ppv => ppv.ChannelValueId == product.PRO_COLOR_SID)
                                    .Join(db.Set<ProductPropertyEntity>()
                                            .Join(db.Set<ProductMapEntity>().Where(pm => pm.ChannelPId == product.PRODUCT_SID), o => o.ProductId, i => i.ProductId, (o, i) => o)
                                     ,o => o.PropertyId, i => i.Id, (o, i) => o).FirstOrDefault();
                var sizeEntity = db.Set<ProductPropertyValueEntity>().Where(ppv => ppv.ChannelValueId == product.PRO_STAN_SID)
                                    .Join(db.Set<ProductPropertyEntity>()
                                            .Join(db.Set<ProductMapEntity>().Where(pm => pm.ChannelPId == product.PRODUCT_SID)
                                                   , o => o.ProductId, i => i.ProductId, (o, i) => o),
                                            o => o.PropertyId, i => i.Id, (o, i) => o).FirstOrDefault();
                if (colorEntity == null || sizeEntity == null)
                    shouldSyncProduct = true;
                
                if (shouldSyncProduct)
                   return ProductPropertySyncJob.SyncOne(product.PRODUCT_SID, product.PRO_STAN_SID ?? 0, product.PRO_STAN_NAME, product.PRO_COLOR_SID ?? 0, product.PRO_COLOR);
            }
            return true;
        }
Beispiel #30
0
 public object Composing()
 {
     using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
     {
         var linq = db.StoreCoupons.Find(this.SyncId);
         if (linq == null)
         {
             return(null);
         }
         return(new
         {
             id = linq.Id,
             status = linq.Status,
             code = linq.Code,
             amount = linq.Amount,
             userid = linq.UserId,
             validstartdate = linq.ValidStartDate.GetValueOrDefault().ToUniversalTime(),
             validenddate = linq.ValidEndDate.GetValueOrDefault().ToUniversalTime(),
             vipcard = linq.VipCard,
             lastupdate = linq.UpdateDate.GetValueOrDefault().ToUniversalTime()
         });
     }
 }
Beispiel #31
0
        private void IndexProds(ElasticClient client,DateTime? benchDate,Func<IQueryable<ProductEntity>,YintaiHangzhouContext,IQueryable<ProductEntity>> whereCondition)
        {
            ILog log = LogManager.GetLogger(this.GetType());
            int cursor = 0;
            int successCount = 0;
           int size = JobConfig.DEFAULT_PAGE_SIZE;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var linq = db.Products.AsQueryable();
                if (benchDate.HasValue)
                    linq = linq.Where(p => p.CreatedDate >= benchDate.Value || p.UpdatedDate >= benchDate.Value);
                else if (whereCondition!=null)
                {
                    linq = whereCondition(linq, db);
                   
                }

                var prods = from p in linq
                            join s in db.Stores on p.Store_Id equals s.Id
                            join b in db.Brands on p.Brand_Id equals b.Id
                            join t in db.Tags on p.Tag_Id equals t.Id
                            let resource = (from r in db.Resources
                                            where r.SourceId == p.Id
                                            && r.SourceType == 1
                                            select new ESResource()
                                            {
                                                Domain = r.Domain,
                                                Name = r.Name,
                                                SortOrder = r.SortOrder,
                                                IsDefault = r.IsDefault,
                                                Type = r.Type,
                                                Width = r.Width,
                                                Height = r.Height
                                            })
                            let specials = from psp in db.SpecialTopicProductRelations
                                            where psp.Product_Id == p.Id 
                                            join sp in db.SpecialTopics on psp.SpecialTopic_Id equals sp.Id
                                            select new ESSpecialTopic
                                            {
                                                Id = sp.Id,
                                                Name = sp.Name,
                                                Description = sp.Description
                                            }
                            let promotions = from ppr in db.Promotion2Product
                                             where ppr.ProdId == p.Id
                                             join pro in db.Promotions on ppr.ProId equals pro.Id
                                             select new ESPromotion { 
                                                Id = pro.Id,
                                                Name = pro.Name,
                                                Description = pro.Description,
                                                CreatedDate = p.CreatedDate,
                                                StartDate = pro.StartDate,
                                                EndDate = pro.EndDate,
                                                Status = pro.Status
                                             }
                            let section = (from section in db.Sections
                                           where section.BrandId == p.Brand_Id && section.StoreId == p.Store_Id
                                          select new ESSection(){
                                              ContactPerson = section.ContactPerson,
                                               ContactPhone = section.ContactPhone,
                                                Id = section.Id,
                                                 Location = section.Location,
                                                  Name = section.Name,
                                                   Status = section.Status
                                          })

                            select new ESProduct()
                            {
                                Id = p.Id,
                                Name = p.Name,
                                Description = p.Description,
                                CreatedDate = p.CreatedDate,
                                Price = p.Price,
                                RecommendedReason = p.RecommendedReason,
                                Status = p.Status,
                                CreateUserId = p.CreatedUser,
                                SortOrder = p.SortOrder,
                                Tag = new ESTag()
                                {
                                    Id = t.Id,
                                    Name = t.Name,
                                    Description = t.Description
                                },
                                Store = new ESStore()
                                {
                                    Id = s.Id,
                                    Name = s.Name,
                                    Description = s.Description,
                                    Address = s.Location,
                                    Location = new Location
                                    {
                                        Lon = s.Longitude,
                                        Lat = s.Latitude
                                    },
                                    GpsAlt = s.GpsAlt,
                                    GpsLat = s.GpsLat,
                                    GpsLng = s.GpsLng,
                                    Tel = s.Tel
                                },
                                Brand = new ESBrand()
                                {
                                    Id = b.Id,
                                    Name = b.Name,
                                    Description = b.Description,
                                    EngName = b.EnglishName
                                },
                                Resource = resource,
                                SpecialTopic = specials,
                                Promotion = promotions,
                                Is4Sale = p.Is4Sale ?? false,
                                UnitPrice = p.UnitPrice,
                                FavoriteCount = p.FavoriteCount,
                                InvolvedCount = p.InvolvedCount,
                                ShareCount = p.ShareCount,
                                RecommendUserId = p.RecommendUser,
                                Section=section.FirstOrDefault(),
                                UpcCode = p.SkuCode
                            };
                int totalCount = prods.Count();
                client.MapFromAttributes<ESProduct>();
                while (cursor < totalCount)
                {
                    var result = client.IndexMany(prods.OrderByDescending(p => p.Id).Skip(cursor).Take(size));
                    if (!result.IsValid)
                    {
                        foreach (var item in result.Items)
                        {
                            if (item.OK)
                                successCount++;
                            else
                                log.Info(string.Format("id index failed:{0}", item.Id));
                        }
                    }
                    else
                        successCount += result.Items.Count();

                    cursor += size;
                }
            }
            sw.Stop();
            log.Info(string.Format("{0} products in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));

        }
Beispiel #32
0
        private void IndexPros(ElasticClient client, DateTime? benchDate, Func<IQueryable<PromotionEntity>, YintaiHangzhouContext, IQueryable<PromotionEntity>> whereCondition)
        {
            ILog log = LogManager.GetLogger(this.GetType());
            int cursor = 0;
           int size = JobConfig.DEFAULT_PAGE_SIZE;
            int successCount = 0;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var linq = db.Promotions.AsQueryable();
                if (benchDate.HasValue)
                    linq = linq.Where(p => p.CreatedDate >= benchDate.Value || p.UpdatedDate >= benchDate.Value);
                else if (whereCondition != null)
                {
                    linq = whereCondition(linq, db);

                }
                var prods = from p in linq
                            join s in db.Stores on p.Store_Id equals s.Id
                            let resource = (from r in db.Resources
                                           where r.SourceId == p.Id
                                           && r.SourceType == 2
                                           select new ESResource() { 
                                             Domain = r.Domain,
                                             Name = r.Name,
                                             SortOrder = r.SortOrder,
                                             IsDefault = r.IsDefault,
                                             Type = r.Type,
                                             Width = r.Width,
                                             Height = r.Height
                                           })
                            select new ESPromotion()
                            {
                                Id = p.Id,
                                Name = p.Name,
                                Description = p.Description,
                                CreatedDate = p.CreatedDate,
                                StartDate = p.StartDate,
                                EndDate = p.EndDate,
                                FavoriteCount = p.FavoriteCount,
                                IsTop = p.IsTop,
                                Status = p.Status,
                                CreateUserId = p.CreatedUser,
                                Store = new ESStore()
                                {
                                    Id = s.Id,
                                    Name = s.Name,
                                    Description = s.Description,
                                    Address = s.Location,
                                    Location = new Location
                                    {
                                        Lon = s.Longitude,
                                        Lat = s.Latitude
                                    },
                                    GpsAlt = s.GpsAlt,
                                    GpsLat = s.GpsLat,
                                    GpsLng = s.GpsLng,
                                    Tel = s.Tel
                                },
                                Resource = resource,
                                ShowInList = p.IsMain.HasValue ? p.IsMain.Value : true,
                                PublicCode = p.PublicProCode,
                                InvolvedCount = p.InvolvedCount,
                                IsProdBindable = p.IsProdBindable ?? false,
                                LikeCount = p.LikeCount,
                                PublicationLimit = p.PublicationLimit ?? -1,
                                ShareCount = p.ShareCount
                            };

                int totalCount = prods.Count();
                client.MapFromAttributes<ESPromotion>();
            
                while (cursor < totalCount)
                {
                    var result = client.IndexMany(prods.OrderByDescending(p => p.Id).Skip(cursor).Take(size));
                    if (!result.IsValid)
                    {
                        foreach(var item in result.Items)
                        {
                            if (item.OK)
                                successCount++;
                            else
                                log.Info(string.Format("id index failed:{0}",item.Id));
                        }
                    } else
                        successCount+=result.Items.Count();

                    cursor += size;
                }

            }
            sw.Stop();
            log.Info(string.Format("{0} promotions in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));
            if (successCount > 0 && CascadPush)
            { 
                //index related products
                log.Info("index products affected by related promotions ");
                IndexProds(client, null,
                    (p,db) => {
                        return p.Where(prod => (from pro in db.Promotions
                                             from ppr in db.Promotion2Product
                                             where ppr.ProId == pro.Id
                                             && (pro.CreatedDate >= benchDate || pro.UpdatedDate >= benchDate)
                                             && ppr.ProdId == prod.Id
                                             select ppr.ProdId).Any());
                    });
            }
        }
Beispiel #33
0
        private void IndexTag(ElasticClient client, DateTime benchDate)
        {
            ILog log = LogManager.GetLogger(this.GetType());
            int cursor = 0;
           int size = JobConfig.DEFAULT_PAGE_SIZE;
            int successCount = 0;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var prods = from p in db.Tags
                            where (p.CreatedDate >= benchDate || p.UpdatedDate >= benchDate)
                            select new ESTag()
                            {
                                Id = p.Id,
                                Name = p.Name,
                                Description = p.Description,
                                Status = p.Status,
                                SortOrder = p.SortOrder

                            };

                int totalCount = prods.Count();
                client.MapFromAttributes<ESTag>();
                while (cursor < totalCount)
                {
                    var result = client.IndexMany(prods.OrderByDescending(p => p.Id).Skip(cursor).Take(size));
                    if (!result.IsValid)
                    {
                        foreach (var item in result.Items)
                        {
                            if (item.OK)
                                successCount++;
                            else
                                log.Info(string.Format("id index failed:{0}", item.Id));
                        }
                    }
                    else
                        successCount += result.Items.Count();

                    cursor += size;
                }

            }
            sw.Stop();
            log.Info(string.Format("{0} tags in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));

        }
Beispiel #34
0
        private void IndexSpecialTopic(ElasticClient client, DateTime? benchDate, Func<IQueryable<SpecialTopicEntity>, YintaiHangzhouContext, IQueryable<SpecialTopicEntity>> whereCondition)
        {
            ILog log = LogManager.GetLogger(this.GetType());
            int cursor = 0;
           int size = JobConfig.DEFAULT_PAGE_SIZE;
            int successCount = 0;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var linq = db.SpecialTopics.AsQueryable();
                if (benchDate.HasValue)
                    linq = linq.Where(p => p.CreatedDate >= benchDate.Value || p.UpdatedDate >= benchDate.Value);
                else if (whereCondition != null)
                {
                    linq = whereCondition(linq, db);

                }
                var prods = from p in linq
                            let resource = (from r in db.Resources
                                            where r.SourceId == p.Id
                                            && r.SourceType == 9
                                            select new ESResource()
                                            {
                                                Domain = r.Domain,
                                                Name = r.Name,
                                                SortOrder = r.SortOrder,
                                                IsDefault = r.IsDefault,
                                                Type = r.Type,
                                                Width = r.Width,
                                                Height = r.Height
                                            })
                            select new ESSpecialTopic()
                            {
                                Id = p.Id,
                                Name = p.Name,
                                Description = p.Description,
                                Status = p.Status,
                                CreatedDate = p.CreatedDate,
                                CreateUser = p.CreatedUser,
                                Resource = resource,
                                Type = p.Type,
                                TargetValue =  p.TargetValue
                            };

                int totalCount = prods.Count();
                client.MapFromAttributes<ESSpecialTopic>();
                while (cursor < totalCount)
                {
                    var result = client.IndexMany(prods.OrderByDescending(p => p.Id).Skip(cursor).Take(size));
                    if (!result.IsValid)
                    {
                        foreach (var item in result.Items)
                        {
                            if (item.OK)
                                successCount++;
                            else
                                log.Info(string.Format("id index failed:{0}", item.Id));
                        }
                    }
                    else
                        successCount += result.Items.Count();

                    cursor += size;
                }

            }
            sw.Stop();
            log.Info(string.Format("{0} special topics in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));
            if (successCount > 0 && CascadPush)
            {
                //index related products
                log.Info("index products affected by related specialtopic ");
                IndexProds(client, null,
                    (p, db) =>
                    {
                        return p.Where(prod => (from pro in db.SpecialTopics
                                                from ppr in db.SpecialTopicProductRelations
                                                where ppr.SpecialTopic_Id == pro.Id
                                                && (pro.CreatedDate >= benchDate || pro.UpdatedDate >= benchDate)
                                                && ppr.Product_Id == prod.Id
                                                select ppr.Product_Id).Any());
                    });
            }
        }
Beispiel #35
0
        private void IndexBrand(ElasticClient client, DateTime benchDate)
        {
            ILog log = LogManager.GetLogger(this.GetType());
            int cursor = 0;
           int size = JobConfig.DEFAULT_PAGE_SIZE;
            int successCount = 0;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var prods = from p in db.Brands
                            where (p.CreatedDate >= benchDate || p.UpdatedDate >= benchDate)
                            select new ESBrand()
                            {
                                Id = p.Id,
                                Name = p.Name,
                                Description = p.Description,
                                Status = p.Status,
                                Group = p.Group
                            };

                int totalCount = prods.Count();
                client.MapFromAttributes<ESBrand>();
                while (cursor < totalCount)
                {
                    var result = client.IndexMany(prods.OrderByDescending(p => p.Id).Skip(cursor).Take(size));
                    if (!result.IsValid)
                    {
                        foreach (var item in result.Items)
                        {
                            if (item.OK)
                                successCount++;
                            else
                                log.Info(string.Format("id index failed:{0}", item.Id));
                        }
                    }
                    else
                        successCount += result.Items.Count();

                    cursor += size;
                }

            }
            sw.Stop();
            log.Info(string.Format("{0} brands in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));
             //update related source if any affected
            if (successCount > 0 && CascadPush)
            {
                //index related products
                log.Info("index products affected by related brands ");
                IndexProds(client, null,
                    (p, db) =>
                    {
                        return p.Where(prod => (from r in db.Brands
                                                where (r.CreatedDate >= benchDate || r.UpdatedDate >= benchDate)
                                                && r.Id == prod.Brand_Id
                                                select r.Id).Any());
                    });
            }
        }
Beispiel #36
0
        private void IndexStore(ElasticClient client, DateTime benchDate)
        {
            ILog log = LogManager.GetLogger(this.GetType());
            int cursor = 0;
           int size = JobConfig.DEFAULT_PAGE_SIZE;
            int successCount = 0;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var prods = from s in db.Stores
                            let resource = (from r in db.Resources
                                            where r.SourceId == s.Id
                                            && r.SourceType == (int)SourceType.StoreLogo
                                            select new ESResource()
                                            {
                                                Domain = r.Domain,
                                                Name = r.Name,
                                                SortOrder = r.SortOrder,
                                                IsDefault = r.IsDefault,
                                                Type = r.Type,
                                                Width = r.Width,
                                                Height = r.Height
                                            })
                            where (s.CreatedDate >= benchDate || s.UpdatedDate >= benchDate)
                            select new ESStore()
                            {
                                Id = s.Id,
                                Name = s.Name,
                                Description = s.Description,
                                Address = s.Location,
                                Location = new Location
                                {
                                    Lon = s.Longitude,
                                    Lat = s.Latitude
                                },
                                GpsAlt = s.GpsAlt,
                                GpsLat = s.GpsLat,
                                GpsLng = s.GpsLng,
                                Tel = s.Tel,
                                Status = s.Status,
                                Resource = resource

                            };

                int totalCount = prods.Count();
                client.MapFromAttributes<ESStore>();
                while (cursor < totalCount)
                {
                    var result = client.IndexMany(prods.OrderByDescending(p => p.Id).Skip(cursor).Take(size));
                    if (!result.IsValid)
                    {
                        foreach (var item in result.Items)
                        {
                            if (item.OK)
                                successCount++;
                            else
                                log.Info(string.Format("id index failed:{0}", item.Id));
                        }
                    }
                    else
                        successCount += result.Items.Count();

                    cursor += size;
                }

            }
            sw.Stop();
            log.Info(string.Format("{0} stores in {1} => {2} docs/s", successCount, sw.Elapsed, successCount / sw.Elapsed.TotalSeconds));

        }