实现设置第一篇文章为项目默认打开的页面

This commit is contained in:
Minho
2018-03-23 10:00:36 +08:00
parent 789a9155d1
commit e56210165f
20 changed files with 151 additions and 106 deletions

View File

@@ -56,6 +56,8 @@ type Book struct {
MemberId int `orm:"column(member_id);size(100)" json:"member_id"`
ModifyTime time.Time `orm:"type(datetime);column(modify_time);null;auto_now" json:"modify_time"`
Version int64 `orm:"type(bigint);column(version)" json:"version"`
//是否使用第一篇文章项目为默认首页,0 否/1 是
IsUseFirstDocument int `orm:"column(is_use_first_document);type(int);default(0)" json:"is_use_first_document"`
}
// TableName 获取对应数据库表名.

View File

@@ -51,6 +51,7 @@ type BookResult struct {
RoleName string `json:"role_name"`
Status int `json:"status"`
IsEnableShare bool `json:"is_enable_share"`
IsUseFirstDocument bool `json:"is_use_first_document"`
LastModifyText string `json:"last_modify_text"`
IsDisplayComment bool `json:"is_display_comment"`
@@ -168,8 +169,8 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
m.DocCount = book.DocCount
m.CommentStatus = book.CommentStatus
m.CommentCount = book.CommentCount
m.CreateTime = book.CreateTime.Local()
m.ModifyTime = book.ModifyTime.Local()
m.CreateTime = book.CreateTime
m.ModifyTime = book.ModifyTime
m.Cover = book.Cover
m.Label = book.Label
m.Status = book.Status
@@ -177,6 +178,7 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
m.Theme = book.Theme
m.AutoRelease = book.AutoRelease == 1
m.IsEnableShare = book.IsEnableShare == 0
m.IsUseFirstDocument = book.IsUseFirstDocument == 1
m.Publisher = book.Publisher
m.HistoryCount = book.HistoryCount
m.IsDownload = book.IsDownload == 0
@@ -465,8 +467,17 @@ func exportMarkdown(p string,parentId int,bookId int) (error){
return nil
}
//查询项目的第一篇文档
func (m *BookResult) FindFirstDocumentByBookId(bookId int) (*Document,error) {
o := orm.NewOrm()
doc := NewDocument()
err := o.QueryTable(doc.TableNameWithPrefix()).Filter("book_id", bookId).Filter("parent_id",0).OrderBy("order_sort").One(doc)
return doc,err
}

View File

@@ -33,7 +33,7 @@ type Document struct {
Content string `orm:"column(content);type(text);null" json:"content"`
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
MemberId int `orm:"column(member_id);type(int)" json:"member_id"`
ModifyTime time.Time `orm:"column(modify_time);type(datetime)" json:"modify_time"`
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"`
ModifyAt int `orm:"column(modify_at);type(int)" json:"-"`
Version int64 `orm:"type(bigint);column(version)" json:"version"`
AttachList []*Attachment `orm:"-" json:"attach"`
@@ -81,11 +81,8 @@ func (m *Document) InsertOrUpdate(cols ...string) error {
o := orm.NewOrm()
var err error
if m.DocumentId > 0 {
m.ModifyTime = time.Now().Local()
_, err = o.Update(m)
} else {
m.ModifyTime = time.Now().Local()
m.CreateTime = time.Now().Local()
_, err = o.Insert(m)
NewBook().ResetDocumentNumber(m.BookId)
}