From 1a40caaa6c9e486575f05284065f5738a7388d8b Mon Sep 17 00:00:00 2001 From: lifei6671 Date: Tue, 15 Jan 2019 19:36:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:1=E3=80=81=E5=A2=9E=E5=8A=A0=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=90=9C=E7=B4=A2=202=E3=80=81=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=AF=B9=E9=A1=B9=E7=9B=AE=E6=A0=87=E7=AD=BE=E5=92=8C=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E4=BB=A4=E7=89=8C=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/BookController.go | 98 ++++++++++++++---------------- controllers/SearchController.go | 1 + models/DocumentSearchResult.go | 104 +++++++++++++++++++++++++++----- routers/router.go | 1 - static/css/main.css | 13 ++++ views/book/setting.tpl | 17 ------ views/search/index.tpl | 11 +++- 7 files changed, 159 insertions(+), 86 deletions(-) diff --git a/controllers/BookController.go b/controllers/BookController.go index 131a8fb5..d86f05d5 100644 --- a/controllers/BookController.go +++ b/controllers/BookController.go @@ -139,7 +139,7 @@ func (c *BookController) SaveBook() { bookName := strings.TrimSpace(c.GetString("book_name")) description := strings.TrimSpace(c.GetString("description", "")) commentStatus := c.GetString("comment_status") - tag := strings.TrimSpace(c.GetString("label")) + //tag := strings.TrimSpace(c.GetString("label")) editor := strings.TrimSpace(c.GetString("editor")) autoRelease := strings.TrimSpace(c.GetString("auto_release")) == "on" publisher := strings.TrimSpace(c.GetString("publisher")) @@ -156,12 +156,7 @@ func (c *BookController) SaveBook() { if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" { commentStatus = "closed" } - if tag != "" { - tags := strings.Split(tag, ",") - if len(tags) > 10 { - c.JsonResult(6005, "最多允许添加10个标签") - } - } + if !models.NewItemsets().Exist(itemId) { c.JsonResult(6006, "项目空间不存在") } @@ -173,7 +168,7 @@ func (c *BookController) SaveBook() { book.Description = description book.CommentStatus = commentStatus book.Publisher = publisher - book.Label = tag + //book.Label = tag book.Editor = editor book.HistoryCount = historyCount book.IsDownload = 0 @@ -211,7 +206,6 @@ func (c *BookController) SaveBook() { bookResult.BookName = bookName bookResult.Description = description bookResult.CommentStatus = commentStatus - bookResult.Label = tag beego.Info("用户 [", c.Member.Account, "] 修改了项目 ->", book) @@ -646,49 +640,49 @@ func (c *BookController) Import() { } // CreateToken 创建访问来令牌. -func (c *BookController) CreateToken() { - - action := c.GetString("action") - - bookResult, err := c.IsPermission() - - if err != nil { - if err == models.ErrPermissionDenied { - c.JsonResult(403, "权限不足") - } - if err == orm.ErrNoRows { - c.JsonResult(404, "项目不存在") - } - logs.Error("生成阅读令牌失败 =>", err) - c.JsonResult(6002, err.Error()) - } - book := models.NewBook() - - if _, err := book.Find(bookResult.BookId); err != nil { - c.JsonResult(6001, "项目不存在") - } - if action == "create" { - if bookResult.PrivatelyOwned == 0 { - c.JsonResult(6001, "公开项目不能创建阅读令牌") - } - - book.PrivateToken = string(utils.Krand(conf.GetTokenSize(), utils.KC_RAND_KIND_ALL)) - if err := book.Update(); err != nil { - logs.Error("生成阅读令牌失败 => ", err) - c.JsonResult(6003, "生成阅读令牌失败") - } - beego.Info("用户[", c.Member.Account, "]创建项目令牌 ->", book.PrivateToken) - c.JsonResult(0, "ok", conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)) - } else { - book.PrivateToken = "" - if err := book.Update(); err != nil { - logs.Error("CreateToken => ", err) - c.JsonResult(6004, "删除令牌失败") - } - beego.Info("用户[", c.Member.Account, "]创建项目令牌 ->", book.PrivateToken) - c.JsonResult(0, "ok", "") - } -} +//func (c *BookController) CreateToken() { +// +// action := c.GetString("action") +// +// bookResult, err := c.IsPermission() +// +// if err != nil { +// if err == models.ErrPermissionDenied { +// c.JsonResult(403, "权限不足") +// } +// if err == orm.ErrNoRows { +// c.JsonResult(404, "项目不存在") +// } +// logs.Error("生成阅读令牌失败 =>", err) +// c.JsonResult(6002, err.Error()) +// } +// book := models.NewBook() +// +// if _, err := book.Find(bookResult.BookId); err != nil { +// c.JsonResult(6001, "项目不存在") +// } +// if action == "create" { +// if bookResult.PrivatelyOwned == 0 { +// c.JsonResult(6001, "公开项目不能创建阅读令牌") +// } +// +// book.PrivateToken = string(utils.Krand(conf.GetTokenSize(), utils.KC_RAND_KIND_ALL)) +// if err := book.Update(); err != nil { +// logs.Error("生成阅读令牌失败 => ", err) +// c.JsonResult(6003, "生成阅读令牌失败") +// } +// beego.Info("用户[", c.Member.Account, "]创建项目令牌 ->", book.PrivateToken) +// c.JsonResult(0, "ok", conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)) +// } else { +// book.PrivateToken = "" +// if err := book.Update(); err != nil { +// logs.Error("CreateToken => ", err) +// c.JsonResult(6004, "删除令牌失败") +// } +// beego.Info("用户[", c.Member.Account, "]创建项目令牌 ->", book.PrivateToken) +// c.JsonResult(0, "ok", "") +// } +//} // Delete 删除项目. func (c *BookController) Delete() { diff --git a/controllers/SearchController.go b/controllers/SearchController.go index dbe88015..12fe0819 100644 --- a/controllers/SearchController.go +++ b/controllers/SearchController.go @@ -40,6 +40,7 @@ func (c *SearchController) Index() { searchResult, totalCount, err := models.NewDocumentSearchResult().FindToPager(sqltil.EscapeLike(keyword), pageIndex, conf.PageSize, memberId) if err != nil { + beego.Error("搜索失败 ->",err) return } if totalCount > 0 { diff --git a/models/DocumentSearchResult.go b/models/DocumentSearchResult.go index 4d6ecb65..44dcfd2d 100644 --- a/models/DocumentSearchResult.go +++ b/models/DocumentSearchResult.go @@ -59,16 +59,34 @@ FROM ( LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0 LEFT JOIN md_members AS member ON rel.member_id = member.member_id WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE ?) + UNION ALL +SELECT + book.book_id AS document_id, + book.modify_time, + book.create_time, + book.book_name AS document_name, + book.identify, + book.description, + book.identify AS book_identify, + book.book_name, + rel.member_id, + member.account AS author, + 'book' AS search_type +FROM md_books AS book + LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0 + LEFT JOIN md_members AS member ON rel.member_id = member.member_id +WHERE book.privately_owned = 0 AND (book.book_name LIKE ? OR book.description LIKE ?) + UNION ALL SELECT - blog.blog_id, + blog.blog_id AS document_id, blog.modify_time, blog.create_time, - blog.blog_title, + blog.blog_title as document_name, blog.blog_identify, blog.blog_release, blog.blog_identify, - blog.blog_title, + blog.blog_title as book_name, blog.member_id, member.account, 'blog' AS search_type @@ -97,8 +115,19 @@ LIMIT ?, ?;` } totalCount += c + //查询项目的数量 + sql4 := `SELECT count(*) as total_count FROM md_books as book +WHERE book.privately_owned = 0 AND (book.book_name LIKE ? OR book.description LIKE ?);` - _, err = o.Raw(sql2, keyword, keyword,keyword,keyword, offset, pageSize).QueryRows(&searchResult) + err = o.Raw(sql4, keyword, keyword).QueryRow(&c) + if err != nil { + beego.Error("查询搜索结果失败 -> ",err) + return + } + + totalCount += c + + _, err = o.Raw(sql2, keyword, keyword,keyword,keyword,keyword,keyword, offset, pageSize).QueryRows(&searchResult) if err != nil { beego.Error("查询搜索结果失败 -> ",err) return @@ -112,7 +141,7 @@ LIMIT ?, ?;` from md_team_relationship as mtr left join md_team_member as mtm on mtm.team_id=mtr.team_id and mtm.member_id=? order by role_id desc )as t group by t.role_id,t.team_member_id,t.book_id) as team on team.book_id = book.book_id -WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 or team.team_member_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?) ` +WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 or team.team_member_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?);` sql2 := `SELECT * FROM ( @@ -148,14 +177,43 @@ FROM ( UNION ALL SELECT - blog.blog_id, + book.book_id AS document_id, + book.modify_time, + book.create_time, + book.book_name AS document_name, + book.identify, + book.description AS description, + book.identify AS book_identify, + book.book_name, + rel.member_id, + member.account AS author, + 'book' AS search_type + FROM md_books AS book + LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0 + LEFT JOIN md_members AS member ON rel.member_id = member.member_id + LEFT JOIN md_relationship AS rel1 ON book.book_id = rel1.book_id AND rel1.member_id = ? + LEFT JOIN (SELECT * + FROM (SELECT + book_id, + team_member_id, + role_id + FROM md_team_relationship AS mtr + LEFT JOIN md_team_member AS mtm ON mtm.team_id = mtr.team_id AND mtm.member_id = ? + ORDER BY role_id DESC) AS t + GROUP BY t.role_id, t.team_member_id, t.book_id) AS team + ON team.book_id = book.book_id + WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 OR team.team_member_id > 0) AND + (book.book_name LIKE ? OR book.description LIKE ?) + UNION ALL + SELECT + blog.blog_id AS document_id, blog.modify_time, blog.create_time, - blog.blog_title, - blog.blog_identify, - blog.blog_release, - blog.blog_identify, - blog.blog_title, + blog.blog_title as document_name, + blog.blog_identify as identify, + blog.blog_release as description, + blog.blog_identify AS book_identify, + blog.blog_title as book_name, blog.member_id, member.account, 'blog' AS search_type @@ -185,7 +243,25 @@ LIMIT ?, ?;` } totalCount += c - _, err = o.Raw(sql2, memberId, memberId, keyword, keyword,memberId,keyword, keyword, offset, pageSize).QueryRows(&searchResult) + + sql4 := `SELECT count(*) as total_count FROM md_books as book + LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0 + LEFT JOIN md_relationship AS rel1 ON book.book_id = rel1.book_id AND rel1.member_id = ? + left join (select * from (select book_id,team_member_id,role_id + from md_team_relationship as mtr + left join md_team_member as mtm on mtm.team_id=mtr.team_id and mtm.member_id=? order by role_id desc )as t group by t.role_id,t.team_member_id,t.book_id) as team + on team.book_id = book.book_id +WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 or team.team_member_id > 0) AND (book.book_name LIKE ? OR book.description LIKE ?);` + + err = o.Raw(sql4,memberId, memberId,keyword, keyword).QueryRow(&c) + if err != nil { + beego.Error("查询搜索结果失败 -> ",err) + return + } + + totalCount += c + + _, err = o.Raw(sql2, memberId, memberId, keyword, keyword,memberId,memberId,keyword, keyword,memberId,keyword, keyword,offset, pageSize).QueryRows(&searchResult) if err != nil { return } @@ -194,13 +270,13 @@ LIMIT ?, ?;` } //项目内搜索. -func (m *DocumentSearchResult) SearchDocument(keyword string, book_id int) (docs []*DocumentSearchResult, err error) { +func (m *DocumentSearchResult) SearchDocument(keyword string, bookId int) (docs []*DocumentSearchResult, err error) { o := orm.NewOrm() sql := "SELECT * FROM md_documents WHERE book_id = ? AND (document_name LIKE ? OR `release` LIKE ?) " keyword = "%" + keyword + "%" - _, err = o.Raw(sql, book_id, keyword, keyword).QueryRows(&docs) + _, err = o.Raw(sql, bookId, keyword, keyword).QueryRows(&docs) return } diff --git a/routers/router.go b/routers/router.go index 8af91bbc..95a83836 100644 --- a/routers/router.go +++ b/routers/router.go @@ -88,7 +88,6 @@ func init() { beego.Router("/book/setting/open", &controllers.BookController{}, "post:PrivatelyOwned") beego.Router("/book/setting/transfer", &controllers.BookController{}, "post:Transfer") beego.Router("/book/setting/upload", &controllers.BookController{}, "post:UploadCover") - beego.Router("/book/setting/token", &controllers.BookController{}, "post:CreateToken") beego.Router("/book/setting/delete", &controllers.BookController{}, "post:Delete") beego.Router("/book/team/add", &controllers.BookController{}, "POST:TeamAdd") diff --git a/static/css/main.css b/static/css/main.css index d67b6729..8e8d9913 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -441,6 +441,19 @@ textarea{ font-size: 16px; font-weight: 400; } +.manual-search-reader .search-item .title .label{ + color: #fff; + padding-top: .3em; +} +.manual-search-reader .search-item .title .mark-book{ + background-color: #009a61; +} +.manual-search-reader .search-item .title .mark-blog{ + background-color: #0084FF; +} +.manual-search-reader .search-item .title .mark-doc{ + background-color: #337ab7; +} .manual-search-reader .search-item .description{ color: #666; line-height: 25px; diff --git a/views/book/setting.tpl b/views/book/setting.tpl index be9a28e4..154c819c 100644 --- a/views/book/setting.tpl +++ b/views/book/setting.tpl @@ -82,11 +82,6 @@

描述信息不超过500个字符,支持Markdown语法

-
- - -

最多允许添加10个标签,多个标签请用“,”分割

-
@@ -99,18 +94,6 @@
{{if eq .Model.PrivatelyOwned 1}} -
- -
-
- -
-
- - -
-
-
diff --git a/views/search/index.tpl b/views/search/index.tpl index ef269a5c..1cf8d408 100644 --- a/views/search/index.tpl +++ b/views/search/index.tpl @@ -27,9 +27,14 @@
{{if eq $item.SearchType "document"}} + 文档 {{str2html $item.DocumentName}} - {{else}} - {{str2html $item.DocumentName}} + {{else if eq $item.SearchType "book"}} + 项目 + {{str2html $item.DocumentName}} + {{else}} + 文章 + {{str2html $item.DocumentName}} {{end}}
@@ -38,6 +43,8 @@
{{if eq $item.SearchType "document"}} 来自项目:{{$item.BookName}} + {{else if eq $item.SearchType "book"}} + 项目:{{$item.BookName}} {{else}} 来自文章:{{$item.BookName}} {{end}}