up_chain.go
1.9 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package domain
import "time"
// 上链数据
type UpChain struct {
// 上链数据唯一标识
UpChainId int64 `json:"upChainId,string"`
// 数据来源 例如:app.model
Source string `json:"source"`
// 来源数据唯一ID
PrimaryId string `json:"primaryId"`
// 溯源ID 标记同一个系列的数据;例如订单相关事件
IssueId string `json:"issueId"`
// 数据体
Data string `json:"data"`
// 数据块hash
Hash string `json:"hash"`
// 上链状态 1:成功 2:失败
UpChainStatus int `json:"upChainStatus"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
}
type UpChainRepository interface {
Save(upChain *UpChain) (*UpChain, error)
Remove(upChain *UpChain) (*UpChain, error)
FindOne(queryOptions map[string]interface{}) (*UpChain, error)
Find(queryOptions map[string]interface{}) (int64, []*UpChain, error)
}
func (upChain *UpChain) Identify() interface{} {
if upChain.UpChainId == 0 {
return nil
}
return upChain.UpChainId
}
func (upChain *UpChain) Update(data map[string]interface{}) error {
//if source, ok := data["source"]; ok {
// upChain.Source = source.(string)
//}
//if primaryId, ok := data["primaryId"]; ok {
// upChain.PrimaryId = primaryId.(string)
//}
//if issueId, ok := data["issueId"]; ok {
// upChain.IssueId = issueId.(string)
//}
//if data, ok := data["data"]; ok {
// upChain.Data = data.(string)
//}
if hash, ok := data["hash"]; ok {
upChain.Hash = hash.(string)
}
if upChainStatus, ok := data["upChainStatus"]; ok {
upChain.UpChainStatus = upChainStatus.(int)
}
if createdAt, ok := data["createdAt"]; ok {
upChain.CreatedAt = createdAt.(time.Time)
}
return nil
}
func (upChain *UpChain) UpSuccess(hashData string) {
if len(upChain.Hash) > 0 {
return
}
upChain.Hash = hashData
upChain.UpChainStatus = 1
}
func (upChain *UpChain) UpFail() {
if len(upChain.Hash) > 0 {
return
}
upChain.Hash = ""
upChain.UpChainStatus = 2
}