product.go
2.3 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
79
80
81
package domain
import "time"
// 产品信息
type Product struct {
// 企业id
CompanyId int `json:"companyId,omitempty"`
// 组织ID
OrgId int `json:"orgId,omitempty"`
// 产品ID
ProductId int `json:"productId,omitempty"`
// 产品编号 编码规则为“CP”+2 位年+2 位月+2 位日+3 位流水码,如 CP211229001
ProductCode string `json:"productCode,omitempty"`
// 产品名称
ProductName string `json:"productName,omitempty"`
// 产品类别
ProductCategory string `json:"productCategory,omitempty"`
// 产品规格
ProductSpec *UnitQuantity `json:"productSpec,omitempty"`
// 创建时间
CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt,omitempty"`
// 删除时间
DeletedAt time.Time `json:"deletedAt,omitempty"`
}
type ProductRepository interface {
Save(product *Product) (*Product, error)
Remove(product *Product) (*Product, error)
FindOne(queryOptions map[string]interface{}) (*Product, error)
Find(queryOptions map[string]interface{}) (int64, []*Product, error)
}
func (product *Product) Identify() interface{} {
if product.ProductId == 0 {
return nil
}
return product.ProductId
}
func (product *Product) Update(data map[string]interface{}) error {
if companyId, ok := data["companyId"]; ok {
product.CompanyId = companyId.(int)
}
if orgId, ok := data["orgId"]; ok {
product.OrgId = orgId.(int)
}
if productCode, ok := data["productCode"]; ok {
product.ProductCode = productCode.(string)
}
if productName, ok := data["productName"]; ok {
product.ProductName = productName.(string)
}
if productCategory, ok := data["productCategory"]; ok {
product.ProductCategory = productCategory.(string)
}
if quantity, ok := data["quantity"]; ok {
product.ProductSpec.Quantity = quantity.(float64)
}
if unit, ok := data["unit"]; ok {
product.ProductSpec.Unit = unit.(string)
}
if unitWeight, ok := data["unitWeight"]; ok {
product.ProductSpec.UnitWeight = unitWeight.(float64)
}
if weight, ok := data["weight"]; ok {
product.ProductSpec.Weight = weight.(float64)
}
if createdAt, ok := data["createdAt"]; ok {
product.CreatedAt = createdAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
product.UpdatedAt = updatedAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
product.DeletedAt = deletedAt.(time.Time)
}
return nil
}