mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-20 02:37:59 +08:00
修复生成树状文档结构时子节点重复的问题
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/lifei6671/godoc/conf"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"strings"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// Book struct .
|
||||
@@ -325,7 +326,17 @@ func (book *Book) ToBookResult() *BookResult {
|
||||
return m
|
||||
}
|
||||
|
||||
|
||||
//重置文档数量
|
||||
func (m *Book) ResetDocumentNumber(book_id int) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
totalCount,err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id",book_id).Count()
|
||||
if err == nil {
|
||||
o.Raw("UPDATE md_books SET doc_count = ? WHERE book_id = ?",int(totalCount),book_id).Exec()
|
||||
}else{
|
||||
beego.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -65,6 +65,7 @@ func (m *Document) Find(id int) (*Document,error) {
|
||||
return m,nil
|
||||
}
|
||||
|
||||
//插入和更新文档.
|
||||
func (m *Document) InsertOrUpdate(cols... string) error {
|
||||
o := orm.NewOrm()
|
||||
|
||||
@@ -73,10 +74,12 @@ func (m *Document) InsertOrUpdate(cols... string) error {
|
||||
return err
|
||||
}else{
|
||||
_,err := o.Insert(m)
|
||||
NewBook().ResetDocumentNumber(m.BookId)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
//根据指定字段查询一条文档.
|
||||
func (m *Document) FindByFieldFirst(field string,v interface{}) (*Document,error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
@@ -112,6 +115,7 @@ func (m *Document) RecursiveDocument(doc_id int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//发布文档
|
||||
func (m *Document) ReleaseContent(book_id int) {
|
||||
|
||||
o := orm.NewOrm()
|
||||
|
@@ -96,7 +96,7 @@ func getDocumentTree(array []*DocumentTree,parent_id int,selected_id int,selecte
|
||||
for _,item := range array {
|
||||
pid := 0
|
||||
|
||||
if p,ok := item.ParentId.(int);ok {
|
||||
if p, ok := item.ParentId.(int); ok {
|
||||
pid = p
|
||||
}
|
||||
if pid == parent_id {
|
||||
@@ -126,11 +126,11 @@ func getDocumentTree(array []*DocumentTree,parent_id int,selected_id int,selecte
|
||||
buf.WriteString("\"")
|
||||
buf.WriteString(selected_li)
|
||||
buf.WriteString("><a href=\"")
|
||||
if item.Identify != ""{
|
||||
uri := beego.URLFor("DocumentController.Read",":key",item.BookIdentify,":id" ,item.Identify)
|
||||
if item.Identify != "" {
|
||||
uri := beego.URLFor("DocumentController.Read", ":key", item.BookIdentify, ":id", item.Identify)
|
||||
buf.WriteString(uri)
|
||||
}else{
|
||||
uri := beego.URLFor("DocumentController.Read",":key",item.BookIdentify,":id" ,item.DocumentId)
|
||||
} else {
|
||||
uri := beego.URLFor("DocumentController.Read", ":key", item.BookIdentify, ":id", item.DocumentId)
|
||||
buf.WriteString(uri)
|
||||
}
|
||||
buf.WriteString("\" title=\"")
|
||||
@@ -138,9 +138,10 @@ func getDocumentTree(array []*DocumentTree,parent_id int,selected_id int,selecte
|
||||
buf.WriteString(selected + ">")
|
||||
buf.WriteString(template.HTMLEscapeString(item.DocumentName) + "</a>")
|
||||
|
||||
for _,sub := range array {
|
||||
if p,ok := sub.ParentId.(int);ok && p == item.DocumentId{
|
||||
getDocumentTree(array,p,selected_id,selected_parent_id,buf)
|
||||
for _, sub := range array {
|
||||
if p, ok := sub.ParentId.(int); ok && p == item.DocumentId {
|
||||
getDocumentTree(array, p, selected_id, selected_parent_id, buf)
|
||||
break
|
||||
}
|
||||
}
|
||||
buf.WriteString("</li>")
|
||||
|
Reference in New Issue
Block a user