Пример #1
0
        public void GetDTO_ObjectProp_Test()
        {
            var dataType = new DataType()
            {
                ID       = new Guid("3FD6B018-C30A-470A-A4B5-0470366ACAB6"),
                TypeName = "INTEGER"
            };

            var attr = new ERModel.Attribute()
            {
                ID            = new Guid("1814BE78-4065-4F64-BD32-1A3FE588D3EA"),
                AttributeName = "FirstName",
                IsRequired    = true,

                DataType = dataType                 // !Important
            };

            var          asm = new Assembler();
            AttributeDTO dto = asm.GetDTO(attr) as AttributeDTO;

            Assert.AreEqual(attr.ID, dto.ID);
            Assert.AreEqual(attr.AttributeName, dto.AttributeName);
            Assert.AreEqual(attr.IsRequired, dto.IsRequired);

            Assert.AreEqual(attr.DataType.ID, dto.DataTypeID);
        }
Пример #2
0
        public void ProcessCreateNewAttribute()
        {
            var entityID = new ProjectTreeHelper().GetFirstAncestorID <EntityDTO>();

            if (entityID == Guid.Empty)
            {
                throw new InvalidOperationException("No entity selected.");
            }
            var newAttribute = new AttributeDTO()
            {
                AttributeName = "<Enter name>", EntityID = entityID
            };

            var view = new AttributeDetailsView();

            view.Object = newAttribute;

            var popup = new PopupWindow();

            popup.Title    = "New Attribute";
            popup.Validate = () => { return(new Validator().Validate(newAttribute)); };
            popup.ViewPanel.Children.Add(view);

            if (popup.ShowDialog() == true)
            {
                new ObjectDataSource().SaveObject(newAttribute);
                ServiceLocator serviceLocator = ServiceLocator.GetActive();
                serviceLocator.BasicController.ProcessProjectTreeRefresh();
            }
        }
Пример #3
0
        public void GetDTO_ParentProp_Test()
        {
            var entity = new Entity()
            {
                ID         = new Guid("A81DD7C9-3B6B-41D7-95E9-72ECEE645F05"),
                SchemaName = "dbo",
                EntityName = "Author"
            };

            var dataType = new DataType()
            {
                ID       = new Guid("3FD6B018-C30A-470A-A4B5-0470366ACAB6"),
                TypeName = "INTEGER"
            };

            var attr = new ERModel.Attribute()
            {
                ID            = new Guid("1814BE78-4065-4F64-BD32-1A3FE588D3EA"),
                AttributeName = "FirstName",
                IsRequired    = true,
                DataType      = dataType,

                Entity = entity                 // !important
            };

            var          asm = new Assembler();
            AttributeDTO dto = asm.GetDTO(attr) as AttributeDTO;

            Assert.AreEqual(attr.ID, dto.ID);
            Assert.AreEqual(attr.AttributeName, dto.AttributeName);
            Assert.AreEqual(attr.IsRequired, dto.IsRequired);

            Assert.AreEqual(attr.Entity.ID, dto.EntityID);
        }
Пример #4
0
        public static List <AttributeDTO> getTaskAttributes(string task_id)
        {
            List <AttributeDTO> attributes = new List <AttributeDTO>();

            using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionRRHHDatabase"].ConnectionString))
            {
                SqlCommand command = new SqlCommand("usp_get_availableAttributesbyTask", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("@task_id", SqlDbType.Int);
                command.Parameters["@task_id"].Value = task_id;
                command.Connection.Open();
                SqlDataReader rdr = command.ExecuteReader();
                while (rdr.Read())
                {
                    AttributeDTO attribute = new AttributeDTO();
                    attribute.categorie_id = rdr["categorie_id"].ToString();
                    attribute.type_id      = rdr["type"].ToString();
                    attribute.isGeneral    = rdr["isGeneral"].ToString();
                    attribute.id_attribute = rdr["id_attribute"].ToString();
                    attribute.name         = rdr["name"].ToString();
                    attributes.Add(attribute);
                }
            };
            return(attributes);
        }
Пример #5
0
        public OperationDetails EditAttribute(AttributeDTO dto)
        {
            Attrib attribute = _unitOfWork.AttribRepository.Get(c => c.Id == dto.Id).FirstOrDefault();

            attribute.SortOrder    = dto.SortOrder;
            attribute.DateAdded    = DateTime.Now;
            attribute.DateModefied = DateTime.Now;
            attribute.GroupId      = dto.GroupId;
            _unitOfWork.AttribRepository.Update(attribute);

            long arabicLang  = (long)Langs.Arabic;
            long englishLang = (long)Langs.English;

            AttributeDescription arabicDescription = _unitOfWork.AttributeDescriptionRepository.Get(c => c.AttributeId == dto.Id && c.LanguageId == arabicLang).FirstOrDefault();

            AttributeDescription englishDescription = _unitOfWork.AttributeDescriptionRepository.Get(c => c.AttributeId == dto.Id && c.LanguageId == englishLang).FirstOrDefault();


            arabicDescription.Text = dto.ArabicName;
            //arabicDescription.LanguageId = (long)Langs.Arabic;
            arabicDescription.DateModefied = DateTime.Now;


            englishDescription.Text         = dto.EnglishName;
            englishDescription.DateModefied = DateTime.Now;

            _unitOfWork.AttributeDescriptionRepository.Update(arabicDescription);
            _unitOfWork.AttributeDescriptionRepository.Update(englishDescription);

            _unitOfWork.Save();
            return(new OperationDetails(true, "تمت تعديل الواصفة بنجاح", ""));
        }
Пример #6
0
        public OperationDetails AddAttribute(AttributeDTO dto)
        {
            Attrib attribute = new Attrib();

            attribute.SortOrder    = dto.SortOrder;
            attribute.DateAdded    = DateTime.Now;
            attribute.DateModefied = DateTime.Now;
            attribute.GroupId      = dto.GroupId;
            attribute = _unitOfWork.AttribRepository.Insert(attribute);
            _unitOfWork.Save();
            AttributeDescription arabicDescription  = new AttributeDescription();
            AttributeDescription englishDescription = new AttributeDescription();

            arabicDescription.AttributeId  = attribute.Id;
            arabicDescription.Text         = dto.ArabicName;
            arabicDescription.LanguageId   = (long)Langs.Arabic;
            arabicDescription.DateAdded    = DateTime.Now;
            arabicDescription.DateModefied = DateTime.Now;

            englishDescription.AttributeId  = attribute.Id;
            englishDescription.Text         = dto.EnglishName;
            englishDescription.LanguageId   = (long)Langs.English;
            englishDescription.DateAdded    = DateTime.Now;
            englishDescription.DateModefied = DateTime.Now;
            _unitOfWork.AttributeDescriptionRepository.Insert(arabicDescription);
            _unitOfWork.AttributeDescriptionRepository.Insert(englishDescription);

            _unitOfWork.Save();
            return(new OperationDetails(true, "تمت إضافة الواصفة بنجاح", ""));
        }
Пример #7
0
        public ActionResult Edit(long Id)
        {
            AttributeDTO attributeDTO = _ManageAttributeGroup.GetAttributeById(Id);

            Mapper.Initialize(c => c.CreateMap <AttributeDTO, AttributeVM>());
            AttributeVM attribute = Mapper.Map <AttributeDTO, AttributeVM>(attributeDTO);

            return(View(attribute));
        }
Пример #8
0
        partial void Merge(CombatAttribute entity, AttributeDTO dto, object state)
        {
            int modifier;

            if (int.TryParse(dto.Modifier, out modifier))
            {
                entity.Modifier = modifier;
            }
        }
        public AttributeDTO AttributeToAttributeDto(MyPhotosServiceReference.Attribute item)
        {
            AttributeDTO attributeDto = new AttributeDTO();

            attributeDto.Id    = item.Id;
            attributeDto.Name  = item.Name;
            attributeDto.Value = item.Value;

            return(attributeDto);
        }
Пример #10
0
        public async Task <ResponseDTO> GetListAttributesWithParentCode(string parentCode, string orgCode)
        {
            try
            {
                var moduleName = GetListModule(EncryptionConstant.MASTER).Response;
                List <TblMasterMenu> lstMenu = new List <TblMasterMenu>();
                foreach (var item in moduleName)
                {
                    TblMasterMenu tblMasterMenu = new TblMasterMenu();
                    tblMasterMenu = item as TblMasterMenu;
                    lstMenu.Add(tblMasterMenu);
                }
                if (parentCode == EncryptionConstant.ADMIN_USER)
                {
                    List <AttributeDTO> lstTblMasterMenus = new List <AttributeDTO>();
                    for (int i = 0; i < lst.Count; i++)
                    {
                        AttributeDTO tblMasterMenu = new AttributeDTO();
                        tblMasterMenu.AttributeCode  = (i + 1).ToString();
                        tblMasterMenu.AttributeLabel = lst[i];
                        tblMasterMenu.ModuleName     = lstMenu.Where(x => x.MenuCode == EncryptionConstant.ADMIN_USER).FirstOrDefault().MenuName;
                        lstTblMasterMenus.Add(tblMasterMenu);
                    }
                    var lstMenuAdminUser = lstTblMasterMenus.Where(x => !db.TblEncryption.Where(c => c.AttributeCode == x.AttributeCode && c.OrgCode == orgCode).Select(c => c.AttributeCode).Contains(x.AttributeCode)).ToList();
                    return(new ResponseDTO()
                    {
                        StatusCode = 200, Response = lstMenuAdminUser
                    });
                }
                else
                {
                    var lstAttribute = await db.TblVocattributes.Where(x => x.ModuleParent == parentCode && x.IsReuse != true).AsNoTracking().ToListAsync();

                    var data = lstAttribute.Where(x => !db.TblEncryption.Where(c => c.AttributeCode == x.AttributeCode && c.ParentCode == x.ModuleParent).Select(c => c.AttributeCode).Contains(x.AttributeCode)).Select(x => new AttributeDTO()
                    {
                        AttributeCode  = x.AttributeCode,
                        AttributeLabel = x.AttributeLabel,
                        ModuleName     = lstMenu.Where(c => c.MenuCode == parentCode).FirstOrDefault().MenuName
                    }).ToList();
                    return(new ResponseDTO()
                    {
                        StatusCode = 200, Response = data
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ResponseDTO()
                {
                    StatusCode = 500, Response = ex.Message
                });
            }
        }
Пример #11
0
        public ActionResult Add(AttributeVM attribute)
        {
            if (ModelState.IsValid)
            {
                Mapper.Initialize(c => c.CreateMap <AttributeVM, AttributeDTO>());
                AttributeDTO     dto = Mapper.Map <AttributeVM, AttributeDTO>(attribute);
                OperationDetails op  = _ManageAttributeGroup.AddAttribute(dto);

                return(Json(new { Succedeed = op.Succedeed, message = op.Message }));
            }
            else
            {
                return(View(attribute));
            }
        }
Пример #12
0
        public AttributeDTO ConvertAttributeToAttributeDto(MpAttribute attribute)
        {
            var attributeDto = new AttributeDTO
            {
                AttributeId         = attribute.AttributeId,
                Name                = attribute.Name,
                Description         = attribute.Description,
                SortOrder           = attribute.SortOrder,
                CategoryId          = attribute.CategoryId,
                Category            = attribute.Category,
                CategoryDescription = attribute.CategoryDescription,
                EndDate             = attribute.EndDate
            };

            return(attributeDto);
        }
Пример #13
0
        public AttributeDTO GetAttributeById(long Id)
        {
            Attrib attribute = _unitOfWork.AttribRepository.Get(c => c.Id == Id).FirstOrDefault();

            long arabicLang  = (long)Langs.Arabic;
            long englishLang = (long)Langs.English;

            AttributeDTO attributeDto = new AttributeDTO();

            attributeDto.Id          = attribute.Id;
            attributeDto.GroupId     = attribute.GroupId;
            attributeDto.GroupName   = attribute.Group.AttributeGroupDescriptions.Where(c => c.LanguageId == arabicLang).FirstOrDefault().Text;
            attributeDto.ArabicName  = _unitOfWork.AttributeDescriptionRepository.Get(c => c.LanguageId == arabicLang && c.AttributeId == Id).Select(n => n.Text).FirstOrDefault();
            attributeDto.EnglishName = _unitOfWork.AttributeDescriptionRepository.Get(c => c.LanguageId == englishLang && c.AttributeId == Id).Select(n => n.Text).FirstOrDefault();
            attributeDto.SortOrder   = attribute.SortOrder;
            attributeDto.Groups      = GetAllAttributeGroups();
            return(attributeDto);
        }
Пример #14
0
        /// <summary>
        /// 商品属性添加
        /// </summary>
        /// <param name="attributeId"></param>
        /// <param name="name"></param>
        /// <param name="appid"></param>
        /// <returns></returns>
        public ResultDTO AddAttributeExt(System.Guid attributeId, string name, Guid appid)
        {
            try
            {
                if (name == "颜色" || name == "尺寸")
                {
                    return(new ResultDTO {
                        ResultCode = 1, Message = "属性名称已存在!"
                    });
                }

                var haveAttr = Jinher.AMP.BTP.BE.Attribute.ObjectSet().Where(r => r.Name == name && r.AppId == appid && r.IsDel == false).FirstOrDefault();
                if (haveAttr == null)
                {
                    ContextSession contextSession = ContextFactory.CurrentThreadContext;
                    AttributeDTO   attrDTO        = new AttributeDTO();
                    attrDTO.Id          = attributeId;
                    attrDTO.Name        = name;
                    attrDTO.AppId       = appid;
                    attrDTO.EntityState = System.Data.EntityState.Added;
                    Jinher.AMP.BTP.BE.Attribute attribute = new Jinher.AMP.BTP.BE.Attribute().FromEntityData(attrDTO);
                    attribute.SubTime = DateTime.Now;
                    contextSession.SaveObject(attribute);
                    contextSession.SaveChanges();
                }
                else
                {
                    return(new ResultDTO {
                        ResultCode = 1, Message = "属性名称已存在!"
                    });
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("添加属性服务异常。attributeId:{0},name:{1},appid:{2}", attributeId, name, appid), ex);
                return(new ResultDTO {
                    ResultCode = 1, Message = "Error"
                });
            }
            return(new ResultDTO {
                ResultCode = 0, Message = "Success"
            });
        }
            public void Prefetch()
            {
                attributes.Clear();

                foreach (PXDataRecord rec in PXDatabase.SelectMulti <CSAttributeGroup>(
                             new PXDataField <CSAttributeGroup.attributeID>(),
                             new PXDataField <CSAttributeGroup.entityType>(),
                             new PXDataField <CSAttributeGroup.entityClassID>()))
                {
                    if (rec.GetString(1) == KCConstants.InventoryItemEntityType)
                    {
                        AttributeDTO attribute = new AttributeDTO
                        {
                            AttributeId = rec.GetString(0),
                            ItemClassId = int.Parse(rec.GetString(2))
                        };
                        attributes.Add(attribute);
                    }
                }
            }
Пример #16
0
        public List <AttributeDTO> GetAttributeGroupAttributes(long groupId, Langs l)
        {
            AttributeGroup      attributeGroup = _unitOfWork.AttributeGroupRepsitory.Get(c => c.Id == groupId).FirstOrDefault();
            List <AttributeDTO> attributesDtos = new List <AttributeDTO>();

            //long arabicLang = (long)Langs.Arabic;
            //long englishLang = (long)Langs.English;
            long Lang = Utils.getLanguage(l);


            if (attributeGroup != null)
            {
                List <Attrib> attributes = attributeGroup.Attributes.ToList();
                foreach (var attribute in attributes)
                {
                    AttributeDTO dto = new AttributeDTO();
                    dto.Id   = attribute.Id;
                    dto.Name = _unitOfWork.AttributeDescriptionRepository.Get(c => c.LanguageId == Lang && c.AttributeId == attribute.Id).Select(g => g.Text).FirstOrDefault();
                    attributesDtos.Add(dto);
                }
            }
            return(attributesDtos);
        }
        private void CreateAndPostOrder(IVoucherService voucherService)
        {
            var createVoucher = new CreateVoucherDTO
            {
                vouchertypeId  = Properties.Settings.Default.VoucherTypeId,
                maxRedemptions = 0,
                firstName      = _customerDetailViewModel.FirstName,
                lastName       = _customerDetailViewModel.SecondName,
                email          = _customerDetailViewModel.Email
            };

            foreach (var itemLine in _cart.Lines)
            {
                var attribute = new AttributeDTO
                {
                    attributeId = itemLine.Experience.Code,
                    value       = itemLine.Quantity.ToString(),
                };
                createVoucher.attributes.Add(attribute);
            }

            var voucherDetail = voucherService.CreateVoucher(createVoucher).Result;

            _cart.Clear();

            var model = new VoucherDetailViewModel
            {
                VoucherToken       = voucherDetail.voucherToken,
                VoucherDescription = voucherDetail.voucherDescription,
                Name = voucherDetail.name,
                VoucherPurchasedOn = voucherDetail.voucherPurchasedOn,
                UsedOn             = voucherDetail.usedOn
            };

            _voucherDetailViewModel = null;
            _voucherDetailViewModel = model;
        }
Пример #18
0
        public void Run()
        {
            // Get the location of the file we are going to import from the configuration settings
            string fileLocation = _setup.GetSetting("InvolvementFileLocation");

            // Initialize the FileHelper engine
            FileHelperEngine <FileFormat> engine = new FileHelperEngine <FileFormat>();

            FileFormat[] result = engine.ReadFile(fileLocation);

            _logger.Log.Info($"{fileLocation} has been loaded.");

            List <AttributeDTO> attributeList = new List <AttributeDTO>();

            foreach (FileFormat row in result)
            {
                AttributeDTO attributeDto = new AttributeDTO(
                    row.ConstituentId,
                    _translator.Translate("AttributeType", row.InvolvementCode))    // Using the ITranslator to convert CX involvement code to attribute code
                {
                    AttributeDoc = row.Comment,
                    BeginsOn     = row.BeginsOn,
                    EndsOn       = row.EndsOn
                };

                attributeList.Add(attributeDto);
            }

            if (_translator.Warnings.Any())
            {
                string msg =
                    "Translation errors occured in the lookup file.  Please review the log file and correct before posting data.";

                _logger.Log.Error(msg);

                // Send the error message to an email address.  Useful for when this is an automated process.
                //_email.Send(
                //    _setup.GetSetting("SmtpTo"),
                //    _setup.GetSetting("SmtpFrom"),
                //    "JX.Net Example Attribute Loader Error",
                //    msg
                //    );
            }
            else
            {
                // Translation is valid, so lets attempt to create the attributes by interating through the list
                foreach (AttributeDTO attribute in attributeList)
                {
                    IList <AttributeDTO> userAttributes = _attributeService.GetAllByConstituent(attribute.ConstituentId);
                    if (!userAttributes.ToList().Exists(x => x.AttributeType == attribute.AttributeType && x.BeginsOn == attribute.BeginsOn && x.EndsOn == attribute.EndsOn))
                    {
                        try
                        {
                            // Use the Create method of the AttributeService to post the data to JX.
                            AttributeDTO ret = _attributeService.Create(attribute);

                            // The created object is returned from the Create method.  here we can check if its null or not.
                            // If it is null then there was a problem creating the Attribute.
                            if (ret != null)
                            {
                                _logger.Log.Info($"Successfully Created {ret.AttributeType} Attribute for {ret.ConstituentId} ");
                            }
                            else
                            {
                                _logger.Log.Error("Failed to create attribute.  Please review logs.");
                            }
                        }
                        catch (MissingDataException ex)
                        {
                            // The MissingDataException is thrown if there are any failed validations that generated an error message and we can assume
                            // that there was insufficient data provided to result in a valid posting of data to JX.
                            _logger.Log.Error(ex);
                        }
                    }
                    else
                    {
                        _logger.Log.Info("Caleb error");
                    }
                }
            }
        }
Пример #19
0
 partial void Merge(CombatAttribute entity, AttributeDTO dto, object state)
 {
     entity.Modifier = dto.Modifier;
 }
Пример #20
0
        /// <summary>
        /// 自动同步严选商品信息
        /// </summary>
        /// <param name="AppId"></param>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> AutoSyncYXCommodityInfoExt(System.Guid AppId, System.Collections.Generic.List <System.Guid> Ids)
        {
            try
            {
                Jinher.AMP.App.Deploy.CustomDTO.AppIdOwnerIdTypeDTO appModel = APPSV.Instance.GetAppOwnerInfo(AppId);
                bool isFnull = true;
                if (appModel.OwnerType == 0)
                {
                    CBC.Deploy.CustomDTO.OrgInfoNewDTO orgInfoDTO = CBCSV.Instance.GetOrgInfoNewBySubId(appModel.OwnerId);
                    if (orgInfoDTO == null || string.IsNullOrEmpty(orgInfoDTO.CompanyPhone))
                    {
                        isFnull = false;
                    }
                }
                JdCommoditySearchDTO JdComDTO = new JdCommoditySearchDTO();
                Guid           userId         = this.ContextDTO.LoginUserID;
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                if (isFnull)
                {
                    //取出补全的商品信息
                    var                   YXComList       = JdCommodity.ObjectSet().Where(p => p.AppId == AppId && Ids.Contains(p.Id)).ToList();
                    List <string>         skuIds          = YXComList.Select(s => s.JDCode).ToList();
                    List <YXComDetailDTO> YXComDetailList = new List <YXComDetailDTO>();

                    for (int i = 0; i < skuIds.Count; i += 30)
                    {
                        YXComDetailList.AddRange(YXSV.GetComDetailList(skuIds.Skip(i).Take(30).ToList()));
                    }
                    if (!YXComDetailList.Any())
                    {
                        return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> {
                            Data = JdComDTO, ResultCode = 1, isSuccess = false, Message = "未获取到严选商品信息"
                        });
                    }
                    #region 获取所有skuid库存 处理严选商品属性

                    List <StockDTO>             YXstockNumList = new List <StockDTO>();             //库存信息
                    List <itemSkuSpecValueList> skuAttr        = new List <itemSkuSpecValueList>(); //商品属性

                    if (YXComDetailList.Any())
                    {
                        List <string> Sku = new List <string>();
                        foreach (var item in YXComDetailList)
                        {
                            Sku.AddRange(item.skuList.Select(s => s.id).ToList());
                            foreach (var it in item.skuList)
                            {
                                skuAttr.AddRange(it.itemSkuSpecValueList);
                            }
                        }
                        //批量获取严选库存信息
                        for (int i = 0; i < Sku.Count; i += 90)
                        {
                            YXstockNumList.AddRange(YXSV.GetStockNum(Sku.Skip(i).Take(90).ToList()));
                            //Thread.Sleep(1000);
                        }
                        //写入严选商品属性
                        List <ComAttribute> ComAttr = new List <ComAttribute>();
                        foreach (var item in skuAttr)
                        {
                            ComAttribute Com = new ComAttribute();
                            Com.AttrName  = item.skuSpec.name;
                            Com.Attrvalue = item.skuSpecValue.value;
                            ComAttr.Add(Com);
                        }
                        var firstAttributeName = ComAttr.Select(s => s.AttrName).ToList();
                        //写入不存在的商品属性
                        List <string> colorAndSize = new List <string>()
                        {
                            "颜色", "尺寸"
                        };
                        var NoExistAttr = firstAttributeName.Except(Jinher.AMP.BTP.BE.Attribute.ObjectSet().Where(p => p.AppId == AppId && p.IsDel == false).Select(s => s.Name).ToList().Union(colorAndSize)).ToList();
                        if (NoExistAttr.Any())
                        {
                            foreach (var item in NoExistAttr)
                            {
                                AttributeDTO attrDTO = new AttributeDTO();
                                attrDTO.Id          = Guid.NewGuid();
                                attrDTO.Name        = item;
                                attrDTO.AppId       = AppId;
                                attrDTO.EntityState = System.Data.EntityState.Added;
                                Jinher.AMP.BTP.BE.Attribute attribute = new Jinher.AMP.BTP.BE.Attribute().FromEntityData(attrDTO);
                                attribute.SubId   = userId;
                                attribute.SubTime = DateTime.Now;
                                contextSession.SaveObject(attribute);
                            }
                        }
                    }
                    #endregion
                    #region 获取所有的商城分类  商品类目
                    //获取商城品类
                    var InnerCategoryNameList = YXComList.Select(s => s.VideoName.Trim()).ToList();

                    //获取商品分类
                    var           CategoryNameList = YXComList.Select(s => s.CategoryName).ToList();//获取所有的商品分类
                    string        ggg  = string.Join(",", CategoryNameList.ToArray());
                    List <string> list = new List <string>(ggg.Split(','));
                    //易捷北京
                    var CategoryList = Category.ObjectSet().Where(p => p.AppId == new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6") && !p.IsDel && CategoryNameList.Contains(p.Name)).ToList();
                    var categoryList = InnerCategory.ObjectSet().Where(p => InnerCategoryNameList.Contains(p.Name) && p.AppId == new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6") && !p.IsDel).ToList();
                    //本地调试
                    //var categoryList = InnerCategory.ObjectSet().Where(p => InnerCategoryNameList.Contains(p.Name) && p.AppId == AppId && !p.IsDel).ToList();
                    //var CategoryList = Category.ObjectSet().Where(p => p.AppId == AppId && !p.IsDel && list.Distinct().Contains(p.Name)).ToList();
                    #endregion

                    //获取不到商品类目的
                    List <string> NoCategoryData = new List <string>();
                    //店铺中存在的备注编码进行更新  不存在则插入
                    var ExistCommodity = Commodity.ObjectSet().Where(p => skuIds.Contains(p.Barcode) && !p.IsDel && p.AppId == AppId).ToList();
                    JdComDTO.RepeatData = ExistCommodity.Select(s => s.Barcode).ToList();

                    foreach (var item in ExistCommodity)
                    {
                        var YXCom           = YXComList.FirstOrDefault(p => p.JDCode == item.Barcode);
                        var YXComDetailInfo = YXComDetailList.Where(p => p.id == item.Barcode).FirstOrDefault();

                        var minSortValueQuery = (from m in Commodity.ObjectSet()
                                                 where m.AppId == AppId && m.CommodityType == 0
                                                 select m);
                        int?minSort      = minSortValueQuery.Min(m => (int?)m.SortValue);
                        int minSortValue = 2;
                        if (minSort.HasValue)
                        {
                            minSortValue = minSort.Value;
                        }
                        item.Name         = "网易严选 " + YXComDetailInfo.name;
                        item.SubId        = userId;
                        item.No_Number    = YXCom.No_Number ?? 0;
                        item.Price        = YXComDetailInfo.skuList.Min(p => p.channelPrice);
                        item.Stock        = YXCom.Stock;
                        item.PicturesPath = YXComDetailInfo.listPicUrl;
                        item.Description  = "<div class=\"JD-goods\">" + YXComDetailInfo.itemDetail.detailHtml + "</div>";

                        //Com.State = 1; 只更新商品信息,不更新商品上下架状态
                        item.IsDel             = false;
                        item.AppId             = YXCom.AppId;
                        item.TotalCollection   = 0;
                        item.TotalReview       = 0;
                        item.Salesvolume       = 0;
                        item.ModifiedOn        = DateTime.Now;
                        item.ComAttribute      = YXCom.ComAttribute;
                        item.CategoryName      = YXCom.CategoryName;
                        item.SortValue         = minSortValue - 1;
                        item.FreightTemplateId = YXCom.FreightTemplateId;  //99元以下商品8元运费
                        item.MarketPrice       = YXCom.MarketPrice;
                        //Com.Weight = YXComDetailInfo.;
                        //Com.SaleService = JdComDetailInfo.wareQD + "<br>" + JdComDetailInfo.shouhou;
                        item.SaleAreas     = YXCom.SaleAreas;
                        item.SharePercent  = YXCom.SharePercent;
                        item.CommodityType = 0;
                        item.Duty          = YXCom.Duty;
                        item.TaxRate       = YXCom.TaxRate;
                        item.TaxClassCode  = YXCom.TaxClassCode;
                        item.Unit          = "件";
                        item.InputRax      = YXCom.InputRax;

                        if (YXComDetailInfo.skuList.Count() == 1)
                        {
                            //单条属性与库存表保持一致
                            item.JDCode  = YXComDetailInfo.skuList.FirstOrDefault().id;
                            item.Code    = item.JDCode;
                            item.Barcode = YXComDetailInfo.id;
                            item.No_Code = item.JDCode;
                        }
                        else
                        {
                            //多条属性存储SPU
                            item.JDCode  = YXComDetailInfo.skuList.OrderBy(p => p.channelPrice).FirstOrDefault().id;
                            item.Code    = item.JDCode;
                            item.Barcode = YXComDetailInfo.id; //存严选商品的SPU
                            item.No_Code = item.JDCode;
                        }

                        item.CostPrice        = item.Price * Convert.ToDecimal(0.8);
                        item.ServiceSettingId = YXCom.ServiceSettingId;
                        //Com.TechSpecs = JdComDetailInfo.param;
                        item.SaleService        = YXCom.SaleService;
                        item.Type               = 0;
                        item.YJCouponActivityId = "";
                        item.YJCouponType       = "";
                        item.ModifieId          = userId;
                        List <ComAttributeDTO> ComAttr = new List <ComAttributeDTO>();
                        foreach (var skuitem in YXComDetailInfo.skuList)
                        {
                            foreach (var it in skuitem.itemSkuSpecValueList)
                            {
                                ComAttributeDTO ComAtt = new ComAttributeDTO();
                                ComAtt.Attribute       = it.skuSpec.name;
                                ComAtt.SecondAttribute = it.skuSpecValue.value;
                                ComAttr.Add(ComAtt);
                            }
                        }
                        item.ComAttribute = JsonHelper.JsonSerializer <List <ComAttributeDTO> >(ComAttr);
                        item.RefreshCache(EntityState.Modified);
                        //更新库存表
                        UpdateCommodityStock(item, YXComDetailInfo, YXstockNumList, contextSession);
                        int count1 = contextSession.SaveChanges();
                        //更新JdCommodity表中状态
                        YXCom.State = 1;
                        #region 商品图片
                        //删除图片
                        ProductDetailsPictureBP pdpbp = new ProductDetailsPictureBP();
                        pdpbp.DeletePictures(item.Id);

                        List <string> PicList = new List <string>();
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl1);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl2);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl3);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl4);
                        //添加图片
                        int sort = 1;
                        foreach (var itempic in PicList)
                        {
                            if (!string.IsNullOrWhiteSpace(itempic) && itempic.Length >= 50)
                            {
                                ProductDetailsPicture pic = ProductDetailsPicture.CreateProductDetailsPicture();
                                pic.Name         = "商品图片";
                                pic.SubId        = userId;
                                pic.SubTime      = DateTime.Now;
                                pic.PicturesPath = itempic;
                                pic.CommodityId  = item.Id;
                                pic.Sort         = sort;
                                contextSession.SaveObject(pic);
                                sort++;
                            }
                        }
                        #endregion
                        #region 商品分类
                        //删除商品分类
                        var catList = CommodityCategory.ObjectSet().Where(c => c.CommodityId == item.Id).ToList();
                        foreach (var commodityCategory in catList)
                        {
                            contextSession.Delete(commodityCategory);
                        }
                        //添加商品分类
                        var ComCategory = CategoryList.Where(p => YXCom.CategoryName.Contains(p.Name)).ToList();
                        if (ComCategory.Any())
                        {
                            foreach (var itemcate in ComCategory)
                            {
                                CommodityCategory comcate = CommodityCategory.CreateCommodityCategory();
                                comcate.CategoryId  = itemcate.Id;
                                comcate.CommodityId = item.Id;
                                comcate.SubId       = userId;
                                comcate.SubTime     = DateTime.Now;
                                comcate.Name        = "商品分类";
                                comcate.IsDel       = false;
                                #region 本地测试
                                //comcate.SubId = AppId;
                                //comcate.AppId = AppId;
                                //comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                                #endregion
                                //正式环境
                                comcate.SubId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.AppId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"));
                                contextSession.SaveObject(comcate);
                            }
                        }
                        else
                        {
                            NoCategoryData.Add(YXCom.JDCode);
                        }
                        #endregion
                        #region 商城分类
                        //删除商城分类
                        var oldCCs = CommodityInnerCategory.ObjectSet().Where(c => c.CommodityId == item.Id).ToList();
                        foreach (var commodityCategory in oldCCs)
                        {
                            contextSession.Delete(commodityCategory);
                        }
                        //添加商城分类
                        var innerCateid = categoryList.Where(p => p.Name == YXCom.VideoName.Trim()).FirstOrDefault();
                        if (innerCateid != null)
                        {
                            CommodityInnerCategory comInnerCate = CommodityInnerCategory.CreateCommodityInnerCategory();
                            comInnerCate.CategoryId  = innerCateid.Id;
                            comInnerCate.CommodityId = item.Id;
                            comInnerCate.SubId       = userId;
                            comInnerCate.SubTime     = DateTime.Now;
                            comInnerCate.Name        = "商品分类";
                            comInnerCate.IsDel       = false;
                            comInnerCate.SubId       = AppId;
                            comInnerCate.AppId       = AppId;
                            comInnerCate.CrcAppId    = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                            contextSession.SaveObject(comInnerCate);
                        }
                        #endregion
                    }
                    #region 商品中不存在的插入
                    var NoExist = YXComList.Where(p => !JdComDTO.RepeatData.Contains(p.Barcode)).ToList();
                    foreach (var item in NoExist)
                    {
                        var YXComDetailInfo = YXComDetailList.Where(p => p.id == item.JDCode).FirstOrDefault();

                        var minSortValueQuery = (from m in Commodity.ObjectSet()
                                                 where m.AppId == AppId && m.CommodityType == 0
                                                 select m);
                        int?minSort      = minSortValueQuery.Min(m => (int?)m.SortValue);
                        int minSortValue = 2;
                        if (minSort.HasValue)
                        {
                            minSortValue = minSort.Value;
                        }
                        Commodity Com = Commodity.CreateCommodity();
                        Com.Id                = Guid.NewGuid();
                        Com.Name              = "网易严选 " + YXComDetailInfo.name;
                        Com.SubTime           = DateTime.Now;
                        Com.SubId             = userId;
                        Com.No_Number         = item.No_Number ?? 0;
                        Com.Price             = YXComDetailInfo.skuList.Min(p => p.channelPrice);
                        Com.Stock             = item.Stock;
                        Com.PicturesPath      = YXComDetailInfo.listPicUrl;
                        Com.Description       = "<div class=\"JD-goods\">" + YXComDetailInfo.itemDetail.detailHtml + "</div>";
                        Com.State             = 1; //只更新商品信息,不更新商品上下架状态
                        Com.IsDel             = false;
                        Com.AppId             = item.AppId;
                        Com.TotalCollection   = 0;
                        Com.TotalReview       = 0;
                        Com.Salesvolume       = 0;
                        Com.ModifiedOn        = DateTime.Now;
                        Com.ComAttribute      = item.ComAttribute;
                        Com.CategoryName      = item.CategoryName;
                        Com.SortValue         = minSortValue - 1;
                        Com.FreightTemplateId = item.FreightTemplateId;  //99元以下商品8元运费
                        Com.MarketPrice       = item.MarketPrice;
                        //Com.Weight = YXComDetailInfo.;
                        //Com.SaleService = JdComDetailInfo.wareQD + "<br>" + JdComDetailInfo.shouhou;
                        Com.SaleAreas     = item.SaleAreas;
                        Com.SharePercent  = item.SharePercent;
                        Com.CommodityType = 0;
                        Com.Duty          = item.Duty;
                        Com.TaxRate       = item.TaxRate;
                        Com.TaxClassCode  = item.TaxClassCode;
                        Com.Unit          = "件";
                        Com.InputRax      = item.InputRax;

                        if (YXComDetailInfo.skuList.Count() == 1)
                        {
                            //单条属性与库存表保持一致
                            Com.JDCode  = YXComDetailInfo.skuList.FirstOrDefault().id;
                            Com.Code    = Com.JDCode;
                            Com.Barcode = YXComDetailInfo.id;
                            Com.No_Code = Com.JDCode;
                        }
                        else
                        {
                            //多条属性存储SPU
                            Com.JDCode  = YXComDetailInfo.skuList.OrderBy(p => p.channelPrice).FirstOrDefault().id;
                            Com.Code    = Com.JDCode;
                            Com.Barcode = YXComDetailInfo.id; //存严选商品的SPU
                            Com.No_Code = Com.JDCode;
                        }

                        Com.CostPrice        = Com.Price * Convert.ToDecimal(0.8);
                        Com.ServiceSettingId = item.ServiceSettingId;
                        //Com.TechSpecs = JdComDetailInfo.param;
                        Com.SaleService        = item.SaleService;
                        Com.Type               = 0;
                        Com.YJCouponActivityId = "";
                        Com.YJCouponType       = "";
                        Com.ModifieId          = userId;
                        List <ComAttributeDTO> ComAttr = new List <ComAttributeDTO>();
                        foreach (var skuitem in YXComDetailInfo.skuList)
                        {
                            foreach (var it in skuitem.itemSkuSpecValueList)
                            {
                                ComAttributeDTO ComAtt = new ComAttributeDTO();
                                ComAtt.Attribute       = it.skuSpec.name;
                                ComAtt.SecondAttribute = it.skuSpecValue.value;
                                ComAttr.Add(ComAtt);
                            }
                        }
                        Com.ComAttribute = JsonHelper.JsonSerializer <List <ComAttributeDTO> >(ComAttr);
                        contextSession.SaveObject(Com);
                        SaveCommodityStock(Com, YXComDetailInfo, YXstockNumList, contextSession);

                        //更新JdCommodity表中状态
                        item.State = 1;
                        #region 商品图片
                        List <string> PicList = new List <string>();
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl1);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl2);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl3);
                        PicList.Add(YXComDetailInfo.itemDetail.picUrl4);
                        //添加图片
                        int sort = 1;
                        foreach (var itempic in PicList)
                        {
                            if (!string.IsNullOrEmpty(itempic))
                            {
                                ProductDetailsPicture pic = ProductDetailsPicture.CreateProductDetailsPicture();
                                pic.Name         = "商品图片";
                                pic.SubId        = userId;
                                pic.SubTime      = DateTime.Now;
                                pic.PicturesPath = itempic;
                                pic.CommodityId  = Com.Id;
                                pic.Sort         = sort;
                                contextSession.SaveObject(pic);
                                sort++;
                            }
                        }
                        #endregion
                        #region 商品分类
                        var ComCategory = CategoryList.Where(p => item.CategoryName.Contains(p.Name)).ToList();
                        if (ComCategory.Any())
                        {
                            foreach (var itemcate in ComCategory)
                            {
                                CommodityCategory comcate = CommodityCategory.CreateCommodityCategory();
                                comcate.CategoryId  = itemcate.Id;
                                comcate.CommodityId = Com.Id;
                                comcate.SubId       = userId;
                                comcate.SubTime     = DateTime.Now;
                                comcate.Name        = "商品分类";
                                comcate.IsDel       = false;
                                #region 本地测试
                                //comcate.SubId = AppId;
                                //comcate.AppId = AppId;
                                //comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                                #endregion
                                comcate.SubId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.AppId    = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                                comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"));
                                contextSession.SaveObject(comcate);
                            }
                        }
                        else
                        {
                            NoCategoryData.Add(item.JDCode);
                        }
                        #endregion
                        #region 商城分类
                        var innerCateid = categoryList.Where(p => p.Name == item.VideoName.Trim()).FirstOrDefault();
                        if (innerCateid != null)
                        {
                            CommodityInnerCategory comInnerCate = CommodityInnerCategory.CreateCommodityInnerCategory();
                            comInnerCate.CategoryId  = innerCateid.Id;
                            comInnerCate.CommodityId = Com.Id;
                            comInnerCate.SubId       = userId;
                            comInnerCate.SubTime     = DateTime.Now;
                            comInnerCate.Name        = "商品分类";
                            comInnerCate.IsDel       = false;
                            comInnerCate.SubId       = AppId;
                            comInnerCate.AppId       = AppId;
                            comInnerCate.CrcAppId    = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId);
                            contextSession.SaveObject(comInnerCate);
                        }
                        #endregion
                    }
                    #endregion

                    int count = contextSession.SaveChanges();
                    JdComDTO.NoCategoryData = NoCategoryData;
                }
                return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> {
                    Data = JdComDTO, ResultCode = 0, isSuccess = true, Message = "自动同步成功"
                });
            }
            catch (Exception ex)
            {
                LogHelper.Error("YJEmployeeBP.AutoSyncCommodityInfoExt 异常", ex);
                return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> {
                    ResultCode = 1, isSuccess = false, Message = ex.Message
                });
            }
        }
Пример #21
0
        internal List <EntityDTO> LoadEntities(DatabaseDTO database, ref int lastTable)
        {
            const int ExpectedColumnsTotal = 9;
            const int TablesPerCall        = 4;

            // TODO: merge entities, attributes, not only data types

            var dataTypes = new Dictionary <string, DataTypeDTO>();
            var entities  = new List <EntityDTO>();

            foreach (var dataType in database.DataTypes)
            {
                dataTypes.Add(dataType.TypeName, dataType);
            }

            var commandText = SqlQueries.GetColumnsQuery;

            using (var connection = new SqlConnection(database.ConnectionString))
            {
                var command = connection.CreateCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = commandText;

                var param1 = new SqlParameter();
                param1.ParameterName = "@TABLE_NUMBER";
                param1.SqlDbType     = SqlDbType.Int;
                param1.Direction     = ParameterDirection.Input;
                param1.Value         = lastTable;
                command.Parameters.Add(param1);

                var param2 = new SqlParameter();
                param2.ParameterName = "@TABLES_IN_ONE_CALL";
                param2.SqlDbType     = SqlDbType.Int;
                param2.Direction     = ParameterDirection.Input;
                param2.Value         = TablesPerCall;
                command.Parameters.Add(param2);

                connection.Open();
                var reader = command.ExecuteReader();
                {
                    if (reader.HasRows)
                    {
                        if (reader.FieldCount != ExpectedColumnsTotal)
                        {
                            throw new InvalidOperationException(String.Format("Query returned less or more than {0} columns ({1})", ExpectedColumnsTotal, commandText));
                        }

                        string    lastTableSchema = string.Empty;
                        string    lastTableName   = string.Empty;
                        EntityDTO entity          = null;

                        int tablesProcessed = 0;
                        while (reader.Read())
                        {
                            lastTable = Convert.ToInt32(reader["TABLE_NUMBER"]);

                            string tableSchema = reader["SchemaName"].ToString();
                            string tableName   = reader["TableName"].ToString();

                            // New table
                            if (!tableSchema.Equals(lastTableSchema, StringComparison.InvariantCultureIgnoreCase) ||
                                !tableName.Equals(lastTableName, StringComparison.InvariantCultureIgnoreCase))
                            {
                                entity = new EntityDTO()
                                {
                                    DatabaseID = database.ID,
                                    SchemaName = tableSchema,
                                    EntityName = tableName
                                };
                                entities.Add(entity);
                                tablesProcessed++;
                            }

                            var attribute = new AttributeDTO()
                            {
                                EntityID      = entity.ID,
                                AttributeName = reader["ColumnName"].ToString(),
                                IsRequired    = Convert.ToInt32(reader["IsNullable"]) == 0 ? true : false,
                                IsPrimaryKey  = Convert.ToInt32(reader["IsPrimaryKey"]) == 0 ? false : true,
                            };

                            var attributeTypeName = reader["DataType"].ToString();
                            if (!dataTypes.ContainsKey(attributeTypeName))
                            {
                                var dataType = new DataTypeDTO()
                                {
                                    DatabaseID = database.ID,
                                    TypeName   = attributeTypeName
                                };
                                dataTypes.Add(attributeTypeName, dataType);
                                database.DataTypes.Add(dataType);
                            }
                            var attributeType = dataTypes[attributeTypeName];
                            attribute.DataTypeID = attributeType.ID;

                            entity.Attributes.Add(attribute);

                            lastTableSchema = tableSchema;
                            lastTableName   = tableName;
                        }
                    }
                }
                reader.Close();
            }

            return(entities);
        }