分页查询附件
(pageIndex, pageSize int)
| 81 | |
| 82 | //分页查询附件 |
| 83 | func (m *Attachment) FindToPager(pageIndex, pageSize int) (attachList []*AttachmentResult, totalCount int64, err error) { |
| 84 | o := orm.NewOrm() |
| 85 | |
| 86 | totalCount, err = o.QueryTable(m.TableNameWithPrefix()).Count() |
| 87 | if err != nil { |
| 88 | return |
| 89 | } |
| 90 | |
| 91 | offset := (pageIndex - 1) * pageSize |
| 92 | |
| 93 | var list []*Attachment |
| 94 | _, err = o.QueryTable(m.TableNameWithPrefix()).OrderBy("-attachment_id").Offset(offset).Limit(pageSize).All(&list) |
| 95 | |
| 96 | if err != nil { |
| 97 | return |
| 98 | } |
| 99 | |
| 100 | for _, item := range list { |
| 101 | attach := &AttachmentResult{} |
| 102 | attach.Attachment = *item |
| 103 | attach.FileShortSize = utils.FormatBytes(int64(attach.FileSize)) |
| 104 | |
| 105 | book := NewBook() |
| 106 | if e := o.QueryTable(book.TableNameWithPrefix()).Filter("book_id", item.BookId).One(book, "book_name", "identify"); e == nil { |
| 107 | attach.BookName = book.BookName |
| 108 | attach.BookIdentify = book.Identify |
| 109 | } else { |
| 110 | attach.BookName = "[不存在]" |
| 111 | } |
| 112 | |
| 113 | doc := NewDocument() |
| 114 | if e := o.QueryTable(doc.TableNameWithPrefix()).Filter("document_id", item.DocumentId).One(doc, "document_name", "identify"); e == nil { |
| 115 | attach.DocumentName = doc.DocumentName |
| 116 | attach.DocIdentify = doc.Identify |
| 117 | } else { |
| 118 | attach.DocumentName = "[不存在]" |
| 119 | } |
| 120 | attach.LocalHttpPath = strings.Replace(item.FilePath, "\\", "/", -1) |
| 121 | attachList = append(attachList, attach) |
| 122 | } |
| 123 | |
| 124 | return |
| 125 | } |
nothing calls this directly
no test coverage detected