This repository has been archived by the owner on Feb 19, 2023. It is now read-only.
/
document.go
64 lines (53 loc) · 1.45 KB
/
document.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package accountancy
import (
"time"
"github.com/google/uuid"
"xorm.io/xorm"
)
// Document -
type Document struct {
ID int64
Dt time.Time `xorm:"notnull index"`
UUID string `xorm:"varchar(36) notnull unique"`
DocTypeID int64 `xorm:"notnull index"`
DebID int64 `xorm:"notnull index"`
CredID int64 `xorm:"notnull index"`
Props map[string]interface{} `xorm:"jsonb"`
Status int `xorm:"notnull index"`
Created time.Time `xorm:"created"`
Updated time.Time `xorm:"updated"`
}
// NewDocument -
func NewDocument(docTypeID int64, props map[string]interface{}) (doc *Document, err error) {
doc = &Document{
UUID: uuid.New().String(),
DocTypeID: docTypeID,
Props: props,
}
return
}
// FillDocument -
func (doc *Document) FillDocument(eng *xorm.Engine) (err error) {
typedoc := &TypeDocument{ID: doc.DocTypeID}
_, err = typedoc.Get(eng)
if err != nil {
return
}
err = fillDocument(doc, *typedoc)
return
}
// Insert -
func (doc *Document) Insert(eng *xorm.Engine) (affected int64, err error) {
affected, err = eng.Insert(doc)
return
}
// Get -
func (doc *Document) Get(eng *xorm.Engine) (has bool, err error) {
has, err = eng.Get(doc)
return
}
// Update -
func (doc *Document) Update(eng *xorm.Engine) (affected int64, err error) {
affected, err = eng.ID(doc.ID).Update(doc)
return
}