private void IncreaseKeywordTagStat <TModel>(TModel info, object tagId)
            where TModel : InfoBase <TModel>, new()
        {
            var parentCode = info.Category.Parent.Code;
            var code       = info.Category.Code;

            if (tagId != null)
            {
                var tagCollection = info.GetValue("TagCollection") as IEnumerable <InfoTag>;
                if (tagCollection != null)
                {
                    var tag = tagCollection.FirstOrDefault(item => item.Id == Convert.ToByte(tagId));
                    if (tag != null)
                    {
                        var keyword = keywordList.FirstOrDefault(item => item.ParentCode == parentCode && item.Code == code && item.ObjType == tag.ObjectTypeId && item.Tag == (byte?)tagId);
                        if (keyword == null)
                        {
                            keyword = Keyword.Insert(new Keyword()
                            {
                                ParentCode = parentCode, Code = code, ObjType = tag.ObjectTypeId, Tag = (byte?)tagId
                            });
                        }
                        IncreaseKeywordStat(info, keyword);
                    }
                }
            }
        }
Esempio n. 2
0
        public void Update()
        {
            Keyword.DeleteAll();

            var categories = InfoCategory.Categories;

            foreach (var parent in categories)
            {
                if (!(parent is JobCategory))
                {
                    //if (Keyword.SelectAll(new { ParentCode = parent.Code }).Count == 0)
                    if (Keyword.Select(item => item.ParentCode == parent.Code) == null)
                    {
                        var keyword = new Keyword()
                        {
                            Key        = parent.Name,
                            ParentCode = parent.Code
                        };
                        keyword.Insert();
                    }
                }

                if (parent.Children != null)
                {
                    foreach (var item in parent.Children)
                    {
                        if (string.IsNullOrWhiteSpace(item.Code))
                        {
                            continue;
                        }
                        //if (Keyword.SelectAll(new { ParentCode = parent.Code, Code = item.Code }).Count == 0)
                        if (Keyword.Select(key => key.ParentCode == parent.Code && key.Code == item.Code) == null)
                        {
                            var keyword = new Keyword()
                            {
                                ParentCode = parent.Code,
                                Code       = item.Code,
                                Key        = item.Name
                            };
                            keyword.Insert();
                        }
                        if (item.ObjectTypeCollection != null)
                        {
                            foreach (var objType in item.ObjectTypeCollection)
                            {
                                //if (Keyword.SelectAll(new { ParentCode = parent.Code, Code = item.Code, ObjType = objType.Id }).Count == 0)
                                if (Keyword.Select(key => key.ParentCode == parent.Code && key.Code == item.Code && key.ObjType == objType.Id) == null)
                                {
                                    var keyword = new Keyword()
                                    {
                                        ParentCode = parent.Code,
                                        Code       = item.Code,
                                        ObjType    = objType.Id,
                                        Key        = objType.Name
                                    };
                                    keyword.Insert();
                                }
                            }
                        }
                        if (item.TagCollection != null)
                        {
                            foreach (var tag in item.TagCollection)
                            {
                                //if (Keyword.SelectAll(new { ParentCode = parent.Code, Code = item.Code, ObjType = tag.ObjectTypeId,Tag=tag.Id }).Count == 0)
                                if (tag.ObjectTypeId == null)
                                {
                                    //continue;
                                }
                                if (Keyword.Select(key => key.ParentCode == parent.Code && key.Code == item.Code && key.ObjType == tag.ObjectTypeId && key.Tag == tag.Id) == null)
                                {
                                    var keyword = new Keyword()
                                    {
                                        ParentCode = parent.Code,
                                        Code       = item.Code,
                                        ObjType    = tag.ObjectTypeId,
                                        Tag        = tag.Id,
                                        Key        = tag.Name
                                    };
                                    keyword.Insert();
                                }
                            }
                        }
                    }
                }
            }

            //if (Keyword.SelectAll(new { ParentCode = "ZhaoPin" }).Count == 0)
            if (Keyword.Select(item => item.ParentCode == "ZhaoPin") == null)
            {
                var keyword = new Keyword()
                {
                    Key        = "招聘",
                    ParentCode = "ZhaoPin"
                };
                keyword.Insert();
            }
            //if (Keyword.SelectAll(new { ParentCode = "QiuZhi" }).Count == 0)
            if (Keyword.Select(item => item.ParentCode == "QiuZhi") == null)
            {
                var keyword = new Keyword()
                {
                    Key        = "求职",
                    ParentCode = "QiuZhi"
                };
                keyword.Insert();
            }

            KeywordStat.DeleteAll();
            //KeywordStatUpdate update = new KeywordStatUpdate();
            //update.Update();//待改进,目前速度特慢,不可行
        }
        private void Update <TModel>()
            where TModel : InfoBase <TModel>, new()
        {
            var _info      = new TModel();
            var maxId      = 0;
            var totalCount = _info.DataRecordCount();
            var pageSize   = 100;
            var pageTotal  = totalCount / pageSize + 1;


            for (var i = 0; i < pageTotal; i++)
            {
                var list = _info.DataSelectTop(item => item.Id > maxId, pageSize);
                if (list.Count == 0)
                {
                    break;
                }
                foreach (var info in list)
                {
                    var parentCode = info.Category.Parent.Code;
                    var keyword    = keywordList.FirstOrDefault(item => item.ParentCode == parentCode);
                    if (keyword == null)
                    {
                        keyword = Keyword.Insert(new Keyword()
                        {
                            ParentCode = parentCode
                        });
                    }
                    IncreaseKeywordStat(info, keyword);

                    //////////////
                    var code = info.Category.Code;
                    keyword = keywordList.FirstOrDefault(item => item.ParentCode == parentCode && item.Code == code);
                    if (keyword == null)
                    {
                        keyword = Keyword.Insert(new Keyword()
                        {
                            ParentCode = parentCode, Code = code
                        });
                    }
                    IncreaseKeywordStat(info, keyword);

                    /////////////
                    var objType = info.GetValue("ObjectType");
                    if (objType != null)
                    {
                        byte typeId = Convert.ToByte(objType);
                        if (typeId > 0)
                        {
                            keyword = keywordList.FirstOrDefault(item => item.ParentCode == parentCode && item.Code == code && item.ObjType == typeId);
                            if (keyword == null)
                            {
                                keyword = Keyword.Insert(new Keyword()
                                {
                                    ParentCode = parentCode, Code = code, ObjType = typeId
                                });
                            }
                            IncreaseKeywordStat(info, keyword);
                        }
                    }

                    /////////////
                    IncreaseKeywordTagStat(info, info.GetValue("Tag"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag1"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag2"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag3"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag4"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag5"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag6"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag7"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag8"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag9"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag10"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag11"));
                    IncreaseKeywordTagStat(info, info.GetValue("Tag12"));
                }
                maxId = list.Select(item => item.Id).Max();
            }
        }