Exemplo n.º 1
0
        private void SyncOne(PRO_PICTURE product)
        {
            if (!EnsureProductContext(product))
                return ;
            var log = LogManager.GetLogger(this.GetType());
            //download remote picture
            string exPicDomain = ConfigurationManager.AppSettings["EXPIC_DOMAIN"];
            var filePath = FetchRemotePic(string.Format("{0}/{1}",exPicDomain.TrimEnd('/'),Path.Combine(product.PRO_PICT_DIR,product.PRO_PICT_NAME)));
            //resize pics
            var file = new FileInfo(filePath);
            FileInfor uploadFile;
            var uploadResult = FileUploadServiceManager.UploadFile(file, "product", out uploadFile, string.Empty);
            if (uploadResult != FileMessage.Success)
            {
                log.Error(string.Format("upload file error:{0}", filePath));
                 File.Delete(filePath);
                return;
            }
            
            using (var db = new YintaiHangzhouContext("YintaiHangzhouContext"))
            {
                var existPic = db.Set<ResourceEntity>().Where(r => r.ChannelPicId == product.SID).FirstOrDefault();
                if (existPic == null)
                {
                    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 existProduct = db.Set<ProductEntity>().Join(db.Set<ProductMapEntity>().Where(ep => ep.ChannelPId == product.PRODUCT_SID), o => o.Id, i => i.ProductId, (o, i) => o).FirstOrDefault();
                    db.Resources.Add(new ResourceEntity()
                    {
                        ColorId = colorEntity == null ? 0 : colorEntity.Id,
                        SourceId = existProduct.Id,
                        SourceType = (int)SourceType.Product,
                        ContentSize = uploadFile.FileSize,
                        CreatedDate = DateTime.Now,
                        CreatedUser = 0,
                        Domain = string.Empty,
                        ExtName = uploadFile.FileExtName,
                        Height = uploadFile.Height,
                        IsDefault = product.PICTURE_MAST_BIT == 1 ? true : false,
                        UpdatedDate = product.OPT_UPDATE_TIME ?? DateTime.Now,
                        Name = uploadFile.FileName,
                        Status = 1,
                        SortOrder = (int)product.PRO_PICT_ORDER,
                        Size = string.Format("{0}x{1}", uploadFile.Width, uploadFile.Height),
                        Type = (int)uploadFile.ResourceType,
                        Width = uploadFile.Width,
                        ChannelPicId = (int)product.SID
                    });
                    existProduct.IsHasImage = true;
                    existProduct.UpdatedDate = product.OPT_UPDATE_TIME ?? DateTime.Now;
                    existProduct.Status = (int)DataStatus.Normal;
                    db.SaveChanges();
                }
            }

            File.Delete(filePath);
        }
Exemplo n.º 2
0
 private bool EnsureProductContext(PRO_PICTURE product)
 {
     using(var erpDb= new ErpContext())
     {
         
         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();
             if (colorEntity == null)
             {
                 var exProduct = erpDb.Set<SUPPLY_MIN_PRICE_MX>().Where(ep => ep.PRODUCT_SID == product.PRODUCT_SID && ep.PRO_COLOR_SID == product.PRO_COLOR_SID).FirstOrDefault();
                 if (exProduct == null)
                 {
                     Log.Error(string.Format("product sid:{0} has no inventory record for color_sid:{1}",product.PRODUCT_SID,product.PRO_COLOR_SID));
                     return false;
                 }
                 return ProductPropertySyncJob.SyncOne(exProduct.PRODUCT_SID, exProduct.PRO_STAN_SID ?? 0, exProduct.PRO_STAN_NAME, exProduct.PRO_COLOR_SID ?? 0, exProduct.PRO_COLOR);
             }
  
         }
      
     }
     return true;
 }