1、实现通过SSL、TSL发送邮件

2、增加用户真实姓名字段
3、优化项目列表显示
4、实现限定文档历史记录数量
5、优化部分页面的用户体验
This commit is contained in:
Minho
2018-02-02 23:12:29 +08:00
parent 257a758b21
commit c7d83576bd
22 changed files with 176 additions and 71 deletions

View File

@@ -47,6 +47,8 @@ type Book struct {
Theme string `orm:"column(theme);size(255);default(default)" json:"theme"`
// CreateTime 创建时间 .
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"`
//每个文档保存的历史记录数量0 为不限制
HistoryCount int `orm:"column(history_count);type(int);default(0)" json:"history_count"`
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"`
@@ -281,7 +283,7 @@ func (m *Book) FindForHomeToPager(pageIndex, pageSize, member_id int) (books []*
if err != nil {
return
}
sql2 := `SELECT book.*,rel1.*,member.account AS create_name FROM md_books AS book
sql2 := `SELECT book.*,rel1.*,member.account AS create_name,member.real_name FROM md_books AS book
LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.member_id = ?
LEFT JOIN md_relationship AS rel1 ON rel1.book_id = book.book_id AND rel1.role_id = 0
LEFT JOIN md_members AS member ON rel1.member_id = member.member_id
@@ -289,8 +291,6 @@ func (m *Book) FindForHomeToPager(pageIndex, pageSize, member_id int) (books []*
_, err = o.Raw(sql2, member_id, offset, pageSize).QueryRows(&books)
return
} else {
count, err1 := o.QueryTable(m.TableNameWithPrefix()).Filter("privately_owned", 0).Count()
@@ -300,17 +300,17 @@ func (m *Book) FindForHomeToPager(pageIndex, pageSize, member_id int) (books []*
}
totalCount = int(count)
sql := `SELECT book.*,rel.*,member.account AS create_name FROM md_books AS book
sql := `SELECT book.*,rel.*,member.account AS create_name,member.real_name FROM md_books AS book
LEFT JOIN md_relationship AS rel ON rel.book_id = book.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 ORDER BY order_index DESC ,book.book_id DESC LIMIT ?,?`
_, err = o.Raw(sql, offset, pageSize).QueryRows(&books)
return
}
return
}
//分页全局搜索.

View File

@@ -34,6 +34,7 @@ type BookResult struct {
CommentCount int `json:"comment_count"`
CreateTime time.Time `json:"create_time"`
CreateName string `json:"create_name"`
RealName string `json:"real_name"`
ModifyTime time.Time `json:"modify_time"`
Cover string `json:"cover"`
Theme string `json:"theme"`
@@ -41,6 +42,7 @@ type BookResult struct {
MemberId int `json:"member_id"`
Editor string `json:"editor"`
AutoRelease bool `json:"auto_release"`
HistoryCount int `json:"history_count"`
RelationshipId int `json:"relationship_id"`
RoleId int `json:"role_id"`
@@ -94,6 +96,9 @@ func (m *BookResult) FindByIdentify(identify string, member_id int) (*BookResult
m = NewBookResult().ToBookResult(*book)
m.CreateName = member.Account
if member.RealName != "" {
m.RealName = member.RealName
}
m.MemberId = relationship.MemberId
m.RoleId = relationship.RoleId
m.RelationshipId = relationship.RelationshipId
@@ -133,7 +138,7 @@ func (m *BookResult) FindToPager(pageIndex, pageSize int) (books []*BookResult,
totalCount = int(count)
sql := `SELECT
book.*,rel.relationship_id,rel.role_id,m.account AS create_name
book.*,rel.relationship_id,rel.role_id,m.account AS create_name,m.real_name
FROM md_books AS book
LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.role_id = 0
LEFT JOIN md_members AS m ON rel.member_id = m.member_id
@@ -168,6 +173,7 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
m.Theme = book.Theme
m.AutoRelease = book.AutoRelease == 1
m.Publisher = book.Publisher
m.HistoryCount = book.HistoryCount
if book.Theme == "" {
m.Theme = "default"
@@ -266,6 +272,9 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
if m.Publisher != "" {
ebookConfig.Footer = "<p style='color:#8E8E8E;font-size:12px;'>本文档由 <span style='text-decoration:none;color:#1abc9c;font-weight:bold;'>"+ m.Publisher +"</span> 生成<span style='float:right'>- _PAGENUM_ -</span></p>"
}
if m.RealName != "" {
ebookConfig.Creator = m.RealName
}
if tempOutputPath, err = filepath.Abs(tempOutputPath); err != nil {
beego.Error("导出目录配置错误:" + err.Error())

View File

@@ -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

View File

@@ -21,6 +21,7 @@ import (
type Member struct {
MemberId int `orm:"pk;auto;unique;column(member_id)" json:"member_id"`
Account string `orm:"size(100);unique;column(account)" json:"account"`
RealName string `orm:"size(255);column(real_name)" json:"real_name"`
Password string `orm:"size(1000);column(password)" json:"-"`
//认证方式: local 本地数据库 /ldap LDAP
AuthMethod string `orm:"column(auth_method);default(local);size(50);" json:"auth_method"`