mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-10-21 11:27:26 +08:00
1、实现通过SSL、TSL发送邮件
2、增加用户真实姓名字段 3、优化项目列表显示 4、实现限定文档历史记录数量 5、优化部分页面的用户体验
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/lifei6671/mindoc/conf"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type DocumentHistory struct {
|
||||
@@ -58,28 +59,28 @@ func (m *DocumentHistory) Find(id int) (*DocumentHistory, error) {
|
||||
}
|
||||
|
||||
//清空指定文档的历史.
|
||||
func (m *DocumentHistory) Clear(doc_id int) error {
|
||||
func (m *DocumentHistory) Clear(docId int) error {
|
||||
o := orm.NewOrm()
|
||||
|
||||
_, err := o.Raw("DELETE md_document_history WHERE document_id = ?", doc_id).Exec()
|
||||
_, err := o.Raw("DELETE md_document_history WHERE document_id = ?", docId).Exec()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
//删除历史.
|
||||
func (m *DocumentHistory) Delete(history_id, doc_id int) error {
|
||||
func (m *DocumentHistory) Delete(historyId, docId int) error {
|
||||
o := orm.NewOrm()
|
||||
|
||||
_, err := o.QueryTable(m.TableNameWithPrefix()).Filter("history_id", history_id).Filter("document_id", doc_id).Delete()
|
||||
_, err := o.QueryTable(m.TableNameWithPrefix()).Filter("history_id", historyId).Filter("document_id", docId).Delete()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
//恢复指定历史的文档.
|
||||
func (m *DocumentHistory) Restore(history_id, doc_id, uid int) error {
|
||||
func (m *DocumentHistory) Restore(historyId, docId, uid int) error {
|
||||
o := orm.NewOrm()
|
||||
|
||||
err := o.QueryTable(m.TableNameWithPrefix()).Filter("history_id", history_id).Filter("document_id", doc_id).One(m)
|
||||
err := o.QueryTable(m.TableNameWithPrefix()).Filter("history_id", historyId).Filter("document_id", docId).One(m)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -90,7 +91,7 @@ func (m *DocumentHistory) Restore(history_id, doc_id, uid int) error {
|
||||
return err
|
||||
}
|
||||
history := NewDocumentHistory()
|
||||
history.DocumentId = doc_id
|
||||
history.DocumentId = docId
|
||||
history.Content = doc.Content
|
||||
history.Markdown = doc.Markdown
|
||||
history.DocumentName = doc.DocumentName
|
||||
@@ -122,16 +123,38 @@ func (m *DocumentHistory) InsertOrUpdate() (history *DocumentHistory, err error)
|
||||
_, err = o.Update(m)
|
||||
} else {
|
||||
_, err = o.Insert(m)
|
||||
if err == nil {
|
||||
if doc,e := NewDocument().Find(m.DocumentId);e == nil {
|
||||
if book,e := NewBook().Find(doc.BookId);e == nil && book.HistoryCount > 0 {
|
||||
//如果已存在的历史记录大于指定的记录,则清除旧记录
|
||||
if c,e := o.QueryTable(m.TableNameWithPrefix()).Filter("document_id",doc.DocumentId).Count(); e == nil && c > int64(book.HistoryCount) {
|
||||
|
||||
count := c - int64(book.HistoryCount)
|
||||
beego.Info("需要删除的历史文档数量:" ,count)
|
||||
var lists []DocumentHistory
|
||||
|
||||
if _,e := o.QueryTable(m.TableNameWithPrefix()).Filter("document_id",doc.DocumentId).OrderBy("history_id").Limit(count).All(&lists,"history_id"); e == nil {
|
||||
for _,d := range lists {
|
||||
o.Delete(&d)
|
||||
}
|
||||
}
|
||||
}else{
|
||||
beego.Info(book.HistoryCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//分页查询指定文档的历史.
|
||||
func (m *DocumentHistory) FindToPager(doc_id, page_index, page_size int) (docs []*DocumentHistorySimpleResult, totalCount int, err error) {
|
||||
func (m *DocumentHistory) FindToPager(docId, pageIndex, pageSize int) (docs []*DocumentHistorySimpleResult, totalCount int, err error) {
|
||||
|
||||
o := orm.NewOrm()
|
||||
|
||||
offset := (page_index - 1) * page_size
|
||||
offset := (pageIndex - 1) * pageSize
|
||||
|
||||
totalCount = 0
|
||||
|
||||
@@ -141,13 +164,13 @@ LEFT JOIN md_members AS m1 ON history.member_id = m1.member_id
|
||||
LEFT JOIN md_members AS m2 ON history.modify_at = m2.member_id
|
||||
WHERE history.document_id = ? ORDER BY history.history_id DESC LIMIT ?,?;`
|
||||
|
||||
_, err = o.Raw(sql, doc_id, offset, page_size).QueryRows(&docs)
|
||||
_, err = o.Raw(sql, docId, offset, pageSize).QueryRows(&docs)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var count int64
|
||||
count, err = o.QueryTable(m.TableNameWithPrefix()).Filter("document_id", doc_id).Count()
|
||||
count, err = o.QueryTable(m.TableNameWithPrefix()).Filter("document_id", docId).Count()
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
Reference in New Issue
Block a user