product_plan.go
3.1 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package domain
import (
"errors"
"time"
)
const (
PlanOnline = 1 // 计划上线
PlanOffline = 2 // 计划下线
)
// 生产计划
type ProductPlan struct {
// 生产计划ID
ProductPlanId int `json:"productPlanId,omitempty"`
// 企业id
CompanyId int `json:"companyId,omitempty"`
// 组织ID
OrgId int `json:"orgId,omitempty"`
// 批号
BatchNumber string `json:"batchNumber,omitempty"`
// 生产日期
ProductDate time.Time `json:"productDate,omitempty"`
// 车间
Workshop *Workshop `json:"workshop,omitempty"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn,omitempty"`
// 机台 (A、B、C、D 区分机器大小)
Machine string `json:"machine,omitempty"`
// 计划的产品名称
PlanProductName string `json:"planProductName,omitempty"`
// 计划投入
PlanDevoted *UnitQuantity `json:"planDevoted,omitempty"`
// 计划状态 (1:上线 2:下线 默认下线)
PlanStatus int `json:"planStatus,omitempty"`
// 工作位置
WorkStation *WorkStation `json:"workStation,omitempty"`
// 备注
Remark string `json:"remark,omitempty"`
// 创建时间
CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt,omitempty"`
// 删除时间
DeletedAt time.Time `json:"deletedAt,omitempty"`
// 扩展数据
Ext *Ext `json:"ext,omitempty"`
}
type ProductPlanRepository interface {
Save(productPlan *ProductPlan) (*ProductPlan, error)
Remove(productPlan *ProductPlan) (*ProductPlan, error)
FindOne(queryOptions map[string]interface{}) (*ProductPlan, error)
Find(queryOptions map[string]interface{}) (int64, []*ProductPlan, error)
}
func (productPlan *ProductPlan) Identify() interface{} {
if productPlan.ProductPlanId == 0 {
return nil
}
return productPlan.ProductPlanId
}
func (productPlan *ProductPlan) Update(data map[string]interface{}) error {
//if batchNumber, ok := data["batchNumber"]; ok {
// productPlan.BatchNumber = batchNumber.(string)
//}
if productDate, ok := data["productDateTime"]; ok {
productPlan.ProductDate = productDate.(time.Time)
}
if workOn, ok := data["workOn"]; ok {
productPlan.WorkOn = workOn.(int)
}
if machine, ok := data["machine"]; ok {
productPlan.Machine = machine.(string)
}
if planProductName, ok := data["planProductName"]; ok {
productPlan.PlanProductName = planProductName.(string)
}
if quantity, ok := data["quantity"]; ok {
productPlan.PlanDevoted.Quantity = quantity.(float64)
}
if unit, ok := data["unit"]; ok {
productPlan.PlanDevoted.Unit = unit.(string)
}
if weight, ok := data["weight"]; ok {
productPlan.PlanDevoted.Weight = weight.(float64)
}
if remark, ok := data["remark"]; ok {
productPlan.Remark = remark.(string)
}
productPlan.UpdatedAt = time.Now()
return nil
}
func (productPlan *ProductPlan) ChangeStatus(status int) error {
if productPlan.PlanStatus == status && status == PlanOnline {
return errors.New("计划已经上线")
}
if productPlan.PlanStatus == status && status == PlanOffline {
return errors.New("计划已经下线")
}
if !(status == PlanOnline || status == PlanOffline) {
return errors.New("计划状态有误")
}
productPlan.PlanStatus = status
return nil
}