product_record.go
2.5 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
package domain
import (
"errors"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"time"
)
const (
RecordTypeReceiveMaterial = 1 // 领料
RecordTypeReturnMaterial = 2 // 退料
RecordTypeWeigh = 4 // 称重
RecordTypeSecondLevelWeigh = 8 // 二级品称重
)
const (
ProductRecordNotApprove = 1 // 未审核
ProductRecordApproved = 2 // 已审核
)
// 生产记录
type ProductRecord struct {
// 生产记录ID
ProductRecordId int `json:"productRecordId,omitempty"`
// 企业id
CompanyId int `json:"companyId,omitempty"`
// 组织ID
OrgId int `json:"orgId,omitempty"`
// 生产记录类型:1:领料 2:退料 4:称重 8:二级品称重
ProductRecordType int `json:"productRecordType,omitempty"`
// 生产工人
ProductWorker *User `json:"productWorker,omitempty"`
// 工作位置
WorkStation *WorkStation `json:"workStation,omitempty"`
// 创建时间
CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt,omitempty"`
// 删除时间
DeletedAt time.Time `json:"deletedAt,omitempty"`
// 生产记录信息
ProductRecordInfo *ProductRecordInfo `json:"productRecordInfo,omitempty"`
// 扩展数据
Ext *Ext `json:"ext,omitempty"`
}
type ProductRecordRepository interface {
Save(productRecord *ProductRecord) (*ProductRecord, error)
Remove(productRecord *ProductRecord) (*ProductRecord, error)
FindOne(queryOptions map[string]interface{}) (*ProductRecord, error)
Find(queryOptions map[string]interface{}) (int64, []*ProductRecord, error)
}
func (productRecord *ProductRecord) Identify() interface{} {
if productRecord.ProductRecordId == 0 {
return nil
}
return productRecord.ProductRecordId
}
func (productRecord *ProductRecord) Update(data map[string]interface{}) error {
return nil
}
func (productRecord *ProductRecord) Approve(approveUser *User, weighAfter float64, approveAt time.Time, status int) error {
if productRecord.ProductRecordInfo.ApproveAt > 0 {
return errors.New("已审核")
}
if weighAfter <= 0 {
return errors.New("审核后重量必须大于0")
}
productRecord.ProductRecordInfo.ApproveAt = approveAt.Unix()
productRecord.ProductRecordInfo.ApproveStatus = status
productRecord.ProductRecordInfo.ApproveUser = approveUser
productRecord.ProductRecordInfo.WeighAfter = weighAfter
productRecord.ProductRecordInfo.Weigh = weighAfter
productRecord.UpdatedAt = time.Now()
return nil
}
func TaskKeyPatternProductRecordStatics() string {
return fmt.Sprintf("%v:task:product-record:statics", constant.CACHE_PREFIX)
}