product_record_employee.go
3.6 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
package domain
import "time"
const (
ParticipateNormal = 1 // 正常
ParticipateSupport = 2 // 支援
)
const (
ProductSection1 = "打料"
ProductSection2 = "成型"
ProductSection3 = "穿串"
ProductSection4 = "包装"
)
// 员工生产记录
type EmployeeProductRecord struct {
// 企业id
CompanyId int `json:"companyId,omitempty"`
// 组织ID
OrgId int `json:"orgId,omitempty"`
// 员工产能记录ID
EmployeeProductRecordId int `json:"employeeProductRecordId"`
// 工作位置
WorkStation *WorkStation `json:"workStation"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOn int `json:"workOn"`
// 参与类型 1:正常 2:支援
ParticipateType int `json:"participateType"`
// 初始产能
ProductWeigh float64 `json:"productWeigh"`
// 二级品产能
SecondLevelWeigh float64 `json:"secondLevelWeigh"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 扩展
Ext *Ext `json:"ext"`
// 版本号
Version int `json:"version"`
// 生产记录统计信息
ProductRecordInfo *ProductRecordStaticInfo `json:"productRecordInfo"`
// 生产工人
ProductWorker *User `comment:"生产工人"`
}
type EmployeeProductRecordRepository interface {
Save(employeeProductRecord *EmployeeProductRecord) (*EmployeeProductRecord, error)
Remove(employeeProductRecord *EmployeeProductRecord) (*EmployeeProductRecord, error)
FindOne(queryOptions map[string]interface{}) (*EmployeeProductRecord, error)
Find(queryOptions map[string]interface{}) (int64, []*EmployeeProductRecord, error)
}
func (employeeProductRecord *EmployeeProductRecord) Identify() interface{} {
if employeeProductRecord.EmployeeProductRecordId == 0 {
return nil
}
return employeeProductRecord.EmployeeProductRecordId
}
func (employeeProductRecord *EmployeeProductRecord) Update(data map[string]interface{}) error {
return nil
}
// 更新生产量
func (employeeProductRecord *EmployeeProductRecord) UpdateProductWeigh(weigh float64, productRecordType int, sectionName string, yesterdayWeight float64, bestWeight float64) {
if employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh == nil {
employeeProductRecord.ProductRecordInfo.OtherSectionSecondLevelWeigh = make(map[string]float64)
}
if productRecordType == RecordTypeSecondLevelWeigh {
// 当前工段
if employeeProductRecord.WorkStation.SectionName == sectionName {
employeeProductRecord.SecondLevelWeigh += weigh
} else {
// 其他工段的二级品
employeeProductRecord.ProductRecordInfo.AddSectionWeight(sectionName, weigh)
}
}
if productRecordType == RecordTypeReceiveMaterial {
employeeProductRecord.ProductWeigh += weigh
}
if productRecordType == RecordTypeReturnMaterial {
employeeProductRecord.ProductWeigh -= weigh
}
employeeProductRecord.ProductRecordInfo.PreStatistics(employeeProductRecord.ProductWeigh, employeeProductRecord.SecondLevelWeigh, 0, 0)
employeeProductRecord.UpdatedAt = time.Now()
employeeProductRecord.Version += 1
}
// 产能
func (employeeProductRecord *EmployeeProductRecord) RealProductWeigh() float64 {
// 产能 = 总投入量 - 本阶段二级品重量 - 其他上级二级品重量
return employeeProductRecord.ProductWeigh - employeeProductRecord.SecondLevelWeigh - employeeProductRecord.ProductRecordInfo.OtherSecondLevelWeigh()
}
// 合格率
func (employeeProductRecord *EmployeeProductRecord) QualificationRate() int {
realProductWeigh := employeeProductRecord.RealProductWeigh()
if realProductWeigh == 0 {
return 0
}
result := int(realProductWeigh * 100 / employeeProductRecord.ProductWeigh)
return result
}