FYJ.Blogs开发系列(四)-后台文章Controller
FYJ.Blogs开发系列(五)-前台基页Controller
FYJ.Blogs开发系列(六)-前台主页Controller
FYJ.Blogs开发系列(七)-前台文章Controller
USE [db_blogs] GO /****** Object: StoredProcedure [dbo].[blog_proc_main] Script Date: 2014/5/29 23:52:35 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <fangyj> -- Create date: <2012-12-30> -- Description: <个人博客首页> -- 分类和标签下的文章数必须大于0 才会显示分类和标签 -- ============================================= ALTER PROCEDURE [dbo].[blog_proc_main] -- Add the parameters for the stored procedure here @blogID nvarchar(50), @categoryID nvarchar(50)='' AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; --博客信息 select *,themeName from blog_tb_blog left join blog_tb_theme on blog_tb_theme.themeID=blog_tb_blog.themeID where blogID=@blogID --最新文章 前10条 select top 10 row_number() over(order by articleDatetime desc) as rownum,articleID,articleTitle,articleTitle2, articleUrl as url from blog_view_article where blogID=@blogID and isDisabled=0 --阅读排行榜 select top 10 row_number() over(order by articleClickTimes desc) as rownum,articleID,articleTitle,articleTitle2,articleClickTimes,articleUrl as url from blog_view_article where blogID=@blogID and isDisabled=0 --评论排行榜 select top 10 row_number() over(order by articleCommentTimes desc) as rownum,articleID,articleTitle,articleTitle2,articleCommentTimes,articleUrl as url from blog_view_article where blogID=@blogID and isDisabled=0 --按月份的文章档案 SELECT yyyy,RIGHT('0'+cast(mm as nvarchar(2)),2) as mm,url,(select COUNT(0) from blog_view_article where MONTH(articleDatetime)=mm and YEAR(articleDatetime)=yyyy and blogID=@blogID) as ArticleCount FROM ( SELECT DISTINCT YEAR(articleDatetime) yyyy, MONTH(articleDatetime) AS mm,dbo.blog_func_articleMonthUrl(blogName,blogDomain,YEAR(articleDatetime),MONTH(articleDatetime),(CASE @categoryID when null then null when '' then '' else( select top 1 categoryDomain from blog_tb_category where categoryID=@categoryID) end)) as url FROM blog_view_article WHERE blogID=@blogID --Null判断有点问题 and categoryID=(case @categoryID when null then categoryID when '' then categoryID else @categoryID end) Group by articleDatetime,blogName,blogDomain ) as tt ORDER BY mm DESC --获取博客分类 --select top 10 (select COUNT(1) from blog_view_article where blog_view_article.categoryID=blog_tb_category.categoryID) cc,categoryID,categoryDisplay ,dbo.blog_func_categoryUrl(blogName, blogDomain,blog_tb_category.categoryID,blog_tb_category.categoryDomain) as url from blog_tb_category inner join blog_tb_blog on blog_tb_category.blogID=blog_tb_blog.blogID where blog_tb_category.blogID=@blogID order by categoryOrder asc select ArticleCount,blog_tb_category.categoryID,categoryDisplay ,dbo.blog_func_categoryUrl(blogName, blogDomain,blog_tb_category.categoryID,blog_tb_category.categoryDomain) as url from blog_tb_category inner join blog_tb_blog on blog_tb_category.blogID=blog_tb_blog.blogID left join (select COUNT(*) as ArticleCount,categoryID from blog_view_article where blog_view_article.blogID=@blogID group by categoryID) as table1 on blog_tb_category.categoryID=table1.categoryID where blog_tb_category.blogID=@blogID and ArticleCount>0 order by categoryOrderWeight asc --获取博客标签 -- select row_number() over(order by tagOrder asc) as rownum, (select COUNT(1) from blog_tb_tagArticle where tagID=blog_tb_tag.tagID) as cc,tagID,tagDisplay ,dbo.blog_func_tagUrl(blogName,blogDomain,blog_tb_tag.tagID,categoryDomain) as url --from blog_tb_tag --inner join blog_tb_blog on blog_tb_tag.blogID=blog_tb_blog.blogID --left join blog_tb_category on blog_tb_tag.categoryID=blog_tb_category.categoryID --where blog_tb_tag.blogID=@blogID select row_number() over(order by tagOrder asc) as rownum, (select COUNT(1) from blog_tb_tagArticle where tagID=blog_tb_tag.tagID) as ArticleCount,blog_tb_tag.tagID,tagDisplay ,dbo.blog_func_tagUrl(blogName,blogDomain,blog_tb_tag.tagID,categoryDomain) as url from blog_tb_tag inner join blog_tb_blog on blog_tb_tag.blogID=blog_tb_blog.blogID left join blog_tb_category on blog_tb_tag.categoryID=blog_tb_category.categoryID left join (select COUNT(1) as ArticleCount,tagID from blog_tb_tagArticle group by tagID) table1 on table1.tagID=blog_tb_tag.tagID where blog_tb_tag.blogID=@blogID and ArticleCount>0 --and (blog_tb_tag.categoryID=(CASE @categoryID when null then blog_tb_tag.categoryID when '' then blog_tb_tag.categoryID else @categoryID end)) --获取浏览次数和回复次数 --select count(1) as cc1,ISNULL(sum(articleClickTimes),0) as cc2,ISNULL(sum(articleCommentTimes),0) cc3 from blog_view_article where blogID=@blogID --select count(1) as cc1,(select COUNT(*) from blog_tb_visit where blogID=@blogID) as cc2,ISNULL(sum(articleCommentTimes),0) cc3 from blog_view_article where blogID=@blogID select COUNT(blog_tb_article.articleID) as cc1, ISNULL( sum(articleClickTimes),0) as cc2,ISNULL(sum(articleCommentTimes),0) as cc3 from blog_tb_article left join blog_tb_article_extend on blog_tb_article_extend.articleID=blog_tb_article.articleID where blogID=@blogID --置顶 前5条 select top 5 row_number() over(order by articleDatetime desc) as rownum,articleID,articleTitle,articleTitle articleTitle2, articleUrl as url from blog_view_article where blogID=@blogID and isDisabled=0 and articleIsTop=1 --获取导航 declare @baseUrl nvarchar(50) select @baseUrl=(case when (blogDomain is not null and blogDomain<>'') then 'http://'+blogDomain+'/' else 'http://www.ztku.com/'+blogName+'/' end) from blog_tb_blog where blogID=@blogID select @baseUrl+'' as menuUrl,'首页' as menuDisplay,'' as menuTarget,999998 as menuOrder union select menuUrl ,menuDisplay,'' as menuTarget,menuOrder from blog_tb_menu where blogID=@blogID and menuIsHidden=0 union select @baseUrl+'list.html' as menuUrl,'文章列表' as menuDisplay,'' as menuTarget,-2 as menuOrder union select @baseUrl+'mobile.html' as menuUrl,'手机版' as menuDisplay,'_blank' as menuTarget,-3 as menuOrder union select 'http://service.ztku.com/so' as menuUrl,'搜索' as menuDisplay,'_blank' as menuTarget,-4 as menuOrder union select @baseUrl+'rss' as menuUrl,'Rss' as menuDisplay,'_blank' as menuTarget,-5 as menuOrder union select 'javascript:;' as menuUrl,'管理' as menuDisplay,'_blank' as menuTarget,-7 as menuOrder order by menuOrder DESC --获取前10条友情链接列表 select * from dbo.blog_func_fixedLinkTable(@blogID) union select top 10 * from blog_tb_link where blogID=@blogID and linkIsHidden=0 order by linkOrder,ADD_DATE desc --获取随机10条 select top 10 articleUrl,articleTitle,articleTitle2 from blog_view_article where blogID=@blogID order by newid() --获取社区信息 select blog_tb_blog.blogID,blog_tb_blog_social.* from blog_tb_blog inner join blog_tb_blog_social on blog_tb_blog.userID=blog_tb_blog_social.userID where blogID=@blogID END