workshop.go
2.4 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
82
83
84
85
package domain
import "time"
// 车间
type Workshop struct {
// 企业id
CompanyId int `json:"companyId,omitempty"`
// 组织ID
OrgId int `json:"orgId,omitempty"`
// 车间ID
WorkshopId int `json:"workshopId,omitempty"`
// 车间名称
WorkshopName string `json:"workshopName,omitempty"`
// 负责人 (用户对象)
Principal *User `json:"principal,omitempty"`
// 生产线
ProductLines []*ProductLine `json:"productLines,omitempty"`
// 创建时间
CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt,omitempty"`
// 删除时间
DeletedAt time.Time `json:"deletedAt,omitempty"`
}
type WorkshopRepository interface {
Save(workshop *Workshop) (*Workshop, error)
Remove(workshop *Workshop) (*Workshop, error)
FindOne(queryOptions map[string]interface{}) (*Workshop, error)
Find(queryOptions map[string]interface{}) (int64, []*Workshop, error)
}
func (workshop *Workshop) Identify() interface{} {
if workshop.WorkshopId == 0 {
return nil
}
return workshop.WorkshopId
}
func (workshop *Workshop) Update(data map[string]interface{}) error {
//if companyId, ok := data["companyId"]; ok {
// workshop.CompanyId = companyId.(int)
//}
//if orgId, ok := data["orgId"]; ok {
// workshop.OrgId = orgId.(int)
//}
//if workshopId, ok := data["workshopId"]; ok {
// workshop.WorkshopId = workshopId.(int)
//}
if workshopName, ok := data["workshopName"]; ok {
workshop.WorkshopName = workshopName.(string)
}
if userId, ok := data["userId"]; ok {
workshop.Principal.UserId = userId.(int)
}
if userName, ok := data["userName"]; ok {
workshop.Principal.UserName = userName.(string)
}
if employeeType, ok := data["employeeType"]; ok {
workshop.Principal.EmployeeType = employeeType.(int)
}
if icCardNumber, ok := data["icCardNumber"]; ok {
workshop.Principal.IcCardNumber = icCardNumber.(string)
}
if avatar, ok := data["avatar"]; ok {
workshop.Principal.Avatar = avatar.(string)
}
if phone, ok := data["phone"]; ok {
workshop.Principal.Phone = phone.(string)
}
//if productLines, ok := data["productLines"]; ok {
// workshop.ProductLines = productLines.(array)
//}
if createdAt, ok := data["createdAt"]; ok {
workshop.CreatedAt = createdAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
workshop.UpdatedAt = updatedAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
workshop.DeletedAt = deletedAt.(time.Time)
}
return nil
}