diff --git a/models/book_result.go b/models/BookResult.go similarity index 100% rename from models/book_result.go rename to models/BookResult.go diff --git a/models/convert_book_result.go b/models/ConvertBookResult.go similarity index 100% rename from models/convert_book_result.go rename to models/ConvertBookResult.go diff --git a/models/document_history.go b/models/DocumentHistory.go similarity index 100% rename from models/document_history.go rename to models/DocumentHistory.go diff --git a/models/document.go b/models/DocumentModel.go similarity index 93% rename from models/document.go rename to models/DocumentModel.go index d5131382..b1214acd 100644 --- a/models/document.go +++ b/models/DocumentModel.go @@ -90,10 +90,15 @@ func (m *Document) InsertOrUpdate(cols ...string) error { if m.Identify == "" { book := NewBook() identify := "docs" - if err := o.QueryTable(book.TableNameWithPrefix()).One(book,"identify");err == nil { + if err := o.QueryTable(book.TableNameWithPrefix()).Filter("book_id",m.BookId).One(book,"identify");err == nil { identify = book.Identify } - m.Identify = fmt.Sprintf("%s-%d%d",identify,m.BookId,time.Now().Unix()) + + m.Identify = fmt.Sprintf("%s-%s",identify,strconv.FormatInt(time.Now().UnixNano(), 32)) + } + if m.OrderSort == 0{ + sort,_ := o.QueryTable(m.TableNameWithPrefix()).Filter("book_id",m.BookId).Filter("parent_id",m.ParentId).Count() + m.OrderSort = int(sort) + 1 } _, err = o.Insert(m) NewBook().ResetDocumentNumber(m.BookId) diff --git a/models/document_search_result.go b/models/DocumentSearchResult.go similarity index 100% rename from models/document_search_result.go rename to models/DocumentSearchResult.go diff --git a/models/document_tree.go b/models/DocumentTree.go similarity index 77% rename from models/document_tree.go rename to models/DocumentTree.go index 39e8d7cd..30d126c2 100644 --- a/models/document_tree.go +++ b/models/DocumentTree.go @@ -25,19 +25,19 @@ type DocumentSelected struct { } //获取项目的文档树状结构 -func (m *Document) FindDocumentTree(book_id int) ([]*DocumentTree, error) { +func (m *Document) FindDocumentTree(bookId int) ([]*DocumentTree, error) { o := orm.NewOrm() trees := make([]*DocumentTree, 0) var docs []*Document - count, err := o.QueryTable(m).Filter("book_id", book_id).OrderBy("order_sort", "document_id").Limit(math.MaxInt32).All(&docs, "document_id", "version", "document_name", "parent_id", "identify") + count, err := o.QueryTable(m).Filter("book_id", bookId).OrderBy("order_sort", "document_id").Limit(math.MaxInt32).All(&docs, "document_id", "version", "document_name", "parent_id", "identify") if err != nil { return trees, err } - book, _ := NewBook().Find(book_id) + book, _ := NewBook().Find(bookId) trees = make([]*DocumentTree, count) @@ -64,16 +64,16 @@ func (m *Document) FindDocumentTree(book_id int) ([]*DocumentTree, error) { return trees, nil } -func (m *Document) CreateDocumentTreeForHtml(book_id, selected_id int) (string, error) { - trees, err := m.FindDocumentTree(book_id) +func (m *Document) CreateDocumentTreeForHtml(bookId, selectedId int) (string, error) { + trees, err := m.FindDocumentTree(bookId) if err != nil { return "", err } - parentId := getSelectedNode(trees, selected_id) + parentId := getSelectedNode(trees, selectedId) buf := bytes.NewBufferString("") - getDocumentTree(trees, 0, selected_id, parentId, buf) + getDocumentTree(trees, 0, selectedId, parentId, buf) return buf.String(), nil @@ -92,7 +92,7 @@ func getSelectedNode(array []*DocumentTree, parent_id int) int { return 0 } -func getDocumentTree(array []*DocumentTree, parent_id int, selected_id int, selected_parent_id int, buf *bytes.Buffer) { +func getDocumentTree(array []*DocumentTree, parentId int, selectedId int, selectedParentId int, buf *bytes.Buffer) { buf.WriteString("