Пример #1
0
        public virtual List <ContentPost> GetRelatedPosts(ContentPost post)
        {
            List <Tag> tags = post.Tag.List;

            List <int> ids = new List <int>();

            foreach (Tag t in tags)
            {
                List <DataTagShip> list = DataTagShip.find("TagId=" + t.Id + " and TypeFullName=:tname")
                                          .set("tname", typeof(ContentPost).FullName)
                                          .list();

                getPostIds(ids, list, post);
            }

            if (ids.Count == 0)
            {
                return(new List <ContentPost>());
            }

            String strIds = "";

            for (int i = 0; i < ids.Count; i++)
            {
                strIds += ids[i];
                if (i < ids.Count - 1)
                {
                    strIds += ",";
                }
            }

            List <ContentPost> posts = ContentPost.find("Id in (" + strIds + ") and SaveStatus=" + SaveStatus.Normal).list();

            return(posts);
        }
Пример #2
0
        public virtual List <ContentPost> GetTopBySectionAndCategory(int sectionId, int categoryId, int appId, int count)
        {
            List <ContentPost> list;

            // 兼容旧版
            ContentSection s = ContentSection.findById(sectionId);

            if (strUtil.IsNullOrEmpty(s.CachePostIds))
            {
                list = ContentPost.find("AppId=" + appId + " and PageSection.Id=" + sectionId + " and CategoryId=" + categoryId + " and SaveStatus=" + SaveStatus.Normal + " order by Id desc").list(count);
            }
            else
            {
                //list = ContentPost.findBySql( "select top " + count + " from ContentPost a, ContentSection b where a.AppId=" + appId + " and a.SectionId=" + sectionId + " and a.CategoryId=" + categoryId + " and a.SaveStatus=" + SaveStatus.Normal + " and b.SectionId=" + sectionId );

                list = new List <ContentPost>();
                List <ContentPost> posts = ContentPost.find("Id in (" + s.CachePostIds + ") and SaveStatus=" + SaveStatus.Normal).list();
                foreach (ContentPost p in posts)
                {
                    if (p.CategoryId == categoryId)
                    {
                        list.Add(p);
                    }
                }
            }

            list.Sort();

            return(list);
        }
Пример #3
0
        public List <ContentPost> GetPicked(String ids, int count)
        {
            String sids = checkIds(ids);

            if (strUtil.IsNullOrEmpty(sids))
            {
                return(new List <ContentPost>());
            }

            if (count <= 0)
            {
                count = 10;
            }

            List <ContentPost> list = ContentPost.find("AppId in (" + sids + ")  and PickStatus<" + PickStatus.Focus + " order by PickStatus desc, Id desc").list(count);

            list.Sort();

            ContentPost post = ContentPost.find("AppId in (" + sids + ")  and PickStatus=" + PickStatus.Focus).first();

            List <ContentPost> results = new List <ContentPost>();

            addFocusFirst(list, post, results);

            foreach (ContentPost a in list)
            {
                results.Add(a);
            }

            return(results);
        }
Пример #4
0
        public virtual List <ContentPost> GetByCategory(long sectionId, long categoryId, long appId, int count)
        {
            List <ContentPost> list = ContentPost.find("AppId=" + appId + " and PageSection.Id=" + sectionId + " and CategoryId=" + categoryId + " and SaveStatus=" + SaveStatus.Normal + " order by Id desc").list(count);

            list.Sort();
            return(list);
        }
Пример #5
0
        public virtual List <ContentPost> GetByIds(string ids)
        {
            if (strUtil.IsNullOrEmpty(ids))
            {
                return(new List <ContentPost>());
            }
            List <ContentPost> posts = ContentPost.find("Id in (" + ids + ") and SaveStatus=" + SaveStatus.Normal).list();

            return(posts);
        }
Пример #6
0
        //----------------------------------------------------------------------------------------------------------

        public virtual void Trans(String postIds, String targetSectionIds)
        {
            List <ContentPost> posts = ContentPost.find("Id in (" + postIds + ") ").list();

            List <ContentSection> sections = ContentSection.find("Id in (" + targetSectionIds + ") ").list();

            foreach (ContentPost x in posts)
            {
                transOne(x, sections);
            }
        }
Пример #7
0
        private static bool articleExist(SpiderArticle spiderArticle)
        {
            logger.Info("articleExist=" + spiderArticle.Url);
            ContentPost post = ContentPost.find("OutUrl=:url").set("url", spiderArticle.Url).first();

            if (post != null)
            {
                return(true);
            }
            return(ContentTempPost.find("SourceLink=:url").set("url", spiderArticle.Url).first() != null);
        }
Пример #8
0
        public ContentPoll GetRecentPoll(int appId, int sectionId)
        {
            List <ContentPost> list = ContentPost.find("AppId=" + appId + " and PageSection.Id=" + sectionId + " and SaveStatus=" + SaveStatus.Normal + " order by Id desc").list();

            if (list.Count == 0)
            {
                return(null);
            }

            return(db.find <ContentPoll>("TopicId=" + list[0].Id).first());
        }
Пример #9
0
        public void TransSection()
        {
            // 获取所有Post
            List <ContentPost> list = ContentPost.find("AppId=" + ctx.app.Id).list();

            foreach (ContentPost x in list)
            {
                transSectionOne(x);
            }

            echoRedirect(lang("opok"));
        }
Пример #10
0
        public virtual List <ContentPost> GetBySection(int sectionId, int count)
        {
            List <ContentPostSection> psList = ContentPostSection
                                               .find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal + " order by PostId desc")
                                               .list(count);

            if (psList.Count == 0)
            {
                // 兼容旧版
                return(ContentPost.find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal).list(count));
            }

            return(populatePost(psList));
        }
Пример #11
0
        public virtual List <ContentPost> GetAllBySection(int sectionId)
        {
            List <ContentPost> xResult = ContentPostSection
                                         .find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal + " order by PostId desc")
                                         .listChildren <ContentPost>("Post");

            if (xResult.Count == 0)
            {
                // 兼容旧版
                return(ContentPost.find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal).list());
            }
            else
            {
                return(xResult);
            }
        }
Пример #12
0
        private void updateCachePostIds(int sectionId)
        {
            ContentSection section = ContentSection.findById(sectionId);

            if (section == null)
            {
                throw new NullReferenceException();
            }

            // 为了兼容旧版,section和post一对多关系下的数据也要抓取
            List <ContentPostSection> list  = ContentPostSection.find("SectionId=" + sectionId).list(section.ListCount);
            List <ContentPost>        posts = ContentPost.find("SectionId=" + sectionId).list(section.ListCount);
            List <int> idList = getRecentIds(list, posts);

            section.CachePostIds = getCacheIds(idList, section.ListCount);
            section.update();
        }
Пример #13
0
        public virtual ContentPost GetFirstPost(int appId, int sectionId)
        {
            ContentPostSection xResult = ContentPostSection
                                         .find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal + " order by PostId desc")
                                         .first();

            if (xResult == null)
            {
                // 兼容旧版
                return(ContentPost.find("SectionId=" + sectionId + " and SaveStatus=" + SaveStatus.Normal).first());
            }
            if (xResult.Post.AppId != appId)
            {
                return(null);
            }
            return(xResult.Post);
        }
Пример #14
0
        //--------------------- service ------------------------------------------------------------------------

        public virtual List <IBinderValue> GetByAppIds(String ids, int count)
        {
            String sids = checkIds(ids);

            if (strUtil.IsNullOrEmpty(sids))
            {
                return(new List <IBinderValue>());
            }

            if (count <= 0)
            {
                count = 10;
            }

            List <ContentPost> list = ContentPost.find("AppId in (" + sids + ") and SaveStatus=" + SaveStatus.Normal).list(count);

            return(populateBinder(list));
        }
Пример #15
0
        public void TransSection()
        {
            runsql("update ContentPostSection set SaveStatus=0");
            runsql("update microblog set SaveStatus=0");

            List <ContentApp> apps = ContentApp.find("").list();

            foreach (ContentApp app in apps)
            {
                // 获取所有Post
                List <ContentPost> list = ContentPost.find("AppId=" + app.Id).list();
                foreach (ContentPost x in list)
                {
                    transSectionOne(x);
                }
            }

            echoRedirect(lang("opok"));
        }
Пример #16
0
        public virtual List <IBinderValue> GetRepliesRankByAppIds(String ids, int count)
        {
            String sids = checkIds(ids);

            if (strUtil.IsNullOrEmpty(sids))
            {
                return(new List <IBinderValue>());
            }

            if (count <= 0)
            {
                count = 10;
            }

            String             strSort = " order by Replies desc, Id desc";
            List <ContentPost> list    = ContentPost.find("AppId in (" + sids + ")  and SaveStatus=" + SaveStatus.Normal + strSort).list(count);

            return(populatePosts(list));
        }
Пример #17
0
        public virtual List <ContentPost> GetBySection(int appId, int sectionId, int count)
        {
            List <ContentPost> list;

            // 兼容旧版
            ContentSection s = ContentSection.findById(sectionId);

            if (strUtil.IsNullOrEmpty(s.CachePostIds))
            {
                list = ContentPost.find("AppId=" + appId + " and PageSection.Id=" + sectionId + " and SaveStatus=" + SaveStatus.Normal + " order by Id desc").list(count);
            }
            else
            {
                list = ContentPost.find("Id in (" + s.CachePostIds + ") and SaveStatus=" + SaveStatus.Normal).list();
            }

            list.Sort();
            return(list);
        }
Пример #18
0
        public void MovePostList(String ids, int targeSectionId)
        {
            // 首页缓存移除
            removeCacheSingle(controller.to(new ContentController().Index));

            List <ContentPost> posts = ContentPost.find("Id in (" + ids + ")").list();

            foreach (ContentPost post in posts)
            {
                // 列表页标记过期
                String listKey = "content_list_" + post.PageSection.Id;
                cacheHelper.SetTimestamp(listKey, DateTime.Now);

                // 详细页标记过期(包括分页)
                String detailKey = "content_post_" + post.Id;
                cacheHelper.SetTimestamp(detailKey, DateTime.Now);
            }

            // 目标列表页标记过期
            String tagetListKey = "content_list_" + targeSectionId;

            cacheHelper.SetTimestamp(tagetListKey, DateTime.Now);
        }
Пример #19
0
 public virtual List <ContentPost> GetByApp(int appId)
 {
     return(ContentPost.find("AppId=" + appId + " and SaveStatus=" + SaveStatus.Normal + " order by Id desc").list());
 }
Пример #20
0
 public virtual List <ContentPost> GetRankPost(int appId, int count, int typeId)
 {
     return(ContentPost.find("AppId=" + appId + " and CategoryId=" + typeId + " and SaveStatus=" + SaveStatus.Normal + " order by Hits desc, Replies desc, Id desc").list(count));
 }
Пример #21
0
 public virtual List <ContentPost> GetRecentPost(int appId, int count, int typeId)
 {
     return(ContentPost.find("AppId=" + appId + " and CategoryId=" + typeId + " and SaveStatus=" + SaveStatus.Normal).list(count));
 }
Пример #22
0
 public virtual ContentPost GetTopImg(long sectionId, long categoryId, long appId)
 {
     return(ContentPost.find("AppId=" + appId + " and PageSection.Id=" + sectionId + " and CategoryId=" + categoryId + " and SaveStatus=" + SaveStatus.Normal + " order by Id desc").first());
 }
Пример #23
0
 public virtual ContentPost GetNextPost(ContentPost post)
 {
     return(ContentPost.find("Id>" + post.Id + " and AppId=" + post.AppId + " and SaveStatus=" + SaveStatus.Normal + " order by Id asc").first());
 }