增加文本比较功能

This commit is contained in:
Minho
2017-06-09 18:14:55 +08:00
parent 33ad75a088
commit fc9a237259
63 changed files with 14512 additions and 23 deletions

View File

@@ -9,6 +9,8 @@ import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"github.com/lifei6671/godoc/conf"
"github.com/lifei6671/godoc/utils"
"strings"
)
// Attachment struct .
@@ -86,3 +88,49 @@ func (m *Attachment) FindListByDocumentId(doc_id int) (attaches []*Attachment, e
_, err = o.QueryTable(m.TableNameWithPrefix()).Filter("document_id", doc_id).OrderBy("-attachment_id").All(&attaches)
return
}
//分页查询附件
func (m *Attachment) FindToPager(pageIndex, pageSize int) (attachList []*AttachmentResult, totalCount int64, err error) {
o := orm.NewOrm()
totalCount, err = o.QueryTable(m.TableNameWithPrefix()).Count()
if err != nil {
return
}
offset := (pageIndex - 1) * pageSize
var list []*Attachment
_, err = o.QueryTable(m.TableNameWithPrefix()).OrderBy("-attachment_id").Offset(offset).Limit(pageSize).All(&list)
if err != nil {
return
}
for _, item := range list {
attach := &AttachmentResult{}
attach.Attachment = *item
attach.FileShortSize = utils.FormatBytes(int64(attach.FileSize))
book := NewBook()
if e := o.QueryTable(book.TableNameWithPrefix()).Filter("book_id", item.BookId).One(book, "book_name"); e == nil {
attach.BookName = book.BookName
} else {
attach.BookName = "[不存在]"
}
doc := NewDocument()
if e := o.QueryTable(doc.TableNameWithPrefix()).Filter("document_id", item.DocumentId).One(doc, "document_name"); e == nil {
attach.DocumentName = doc.DocumentName
} else {
attach.DocumentName = "[不存在]"
}
attach.LocalHttpPath = strings.Replace(item.FilePath,"\\","/",-1)
attachList = append(attachList, attach)
}
return
}

View File

@@ -0,0 +1,61 @@
package models
import (
"github.com/astaxie/beego/orm"
"github.com/lifei6671/godoc/utils"
"strings"
)
type AttachmentResult struct {
Attachment
IsExist bool
BookName string
DocumentName string
FileShortSize string
Account string
LocalHttpPath string
}
func NewAttachmentResult() *AttachmentResult {
return &AttachmentResult{ IsExist : false }
}
func (m *AttachmentResult) Find(id int) (*AttachmentResult,error) {
o := orm.NewOrm()
attach := NewAttachment()
err := o.QueryTable(m.TableNameWithPrefix()).Filter("attachment_id",id).One(attach)
if err != nil {
return m,err
}
m.Attachment = *attach
book := NewBook()
if e := o.QueryTable(book.TableNameWithPrefix()).Filter("book_id", attach.BookId).One(book, "book_name"); e == nil {
m.BookName = book.BookName
} else {
m.BookName = "[不存在]"
}
doc := NewDocument()
if e := o.QueryTable(doc.TableNameWithPrefix()).Filter("document_id", attach.DocumentId).One(doc, "document_name"); e == nil {
m.DocumentName = doc.DocumentName
} else {
m.DocumentName = "[不存在]"
}
if attach.CreateAt > 0 {
member := NewMember()
if e := o.QueryTable(member.TableNameWithPrefix()).Filter("member_id",attach.CreateAt).One(member,"account");e == nil {
m.Account = member.Account
}
}
m.FileShortSize = utils.FormatBytes(int64(attach.FileSize))
m.LocalHttpPath = strings.Replace(m.FilePath,"\\","/",-1)
return m,nil
}

View File

@@ -3,19 +3,23 @@ package models
import (
"time"
"github.com/lifei6671/godoc/conf"
"sync/atomic"
"github.com/astaxie/beego/orm"
"errors"
)
const (
Logger_Operate = "operate"
Logger_System = "system"
Logger_Exception = "exception"
)
var loggerQueue = &logQueue{ channel : make(chan *Logger,100),isRuning : 0 }
type logQueue struct {
channel chan *Logger
isRuning int32
}
// Logger struct .
type Logger struct {
LoggerId int64 `orm:"pk;auto;unique;column(log_id)" json:"log_id"`
MemberId int `orm:"column(member_id);type(int)" json:"member_id"`
// 日志类别operate 操作日志/ system 系统日志/ exception 异常日志
// 日志类别operate 操作日志/ system 系统日志/ exception 异常日志 / document 文档操作日志
Category string `orm:"column(category);size(255);default(operate)" json:"category"`
Content string `orm:"column(content);type(text)" json:"content"`
OriginalData string `orm:"column(original_data);type(text)" json:"original_data"`
@@ -41,7 +45,34 @@ func NewLogger() *Logger {
return &Logger{}
}
func (m *Logger) Add() error {
if m.MemberId <= 0 {
return errors.New("用户ID不能为空")
}
if m.Category == "" {
m.Category = "system"
}
if m.Content == "" {
return errors.New("日志内容不能为空")
}
loggerQueue.channel <- m
if atomic.LoadInt32(&(loggerQueue.isRuning)) <= 0 {
atomic.AddInt32(&(loggerQueue.isRuning),1)
go addLoggerAsync()
}
return nil
}
func addLoggerAsync() {
defer atomic.AddInt32(&(loggerQueue.isRuning),-1)
o := orm.NewOrm()
for{
logger := <- loggerQueue.channel
o.Insert(logger)
}
}