product_line.go
1.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
package domain
import "fmt"
// 生产线
type ProductLine struct {
// 生产线ID
LineId int `json:"lineId,omitempty"`
// 生产线名称
LineName string `json:"lineName,omitempty"`
// 工段列表
ProductSections []*ProductSection `json:"productSections,omitempty"`
// 已删除标识 1:正常 2:已删除
Removed int `json:"removed,omitempty"`
}
//输出简化的模型
type SimpleProductLine struct {
LineId int `json:"lineId"` // 生产线ID
LineName string `json:"lineName"` // 生产线名称
}
// 查询生产线
func (productLine *ProductLine) FindSection(sectionId int) (*ProductSection, error) {
for i := range productLine.ProductSections {
item := productLine.ProductSections[i]
if item.SectionId == sectionId {
return item, nil
}
}
return nil, fmt.Errorf("工段不存在")
}
func (productLine *ProductLine) GetProductSections(removed int) []*ProductSection {
var result = make([]*ProductSection, 0)
for i := range productLine.ProductSections {
if removed > 0 && productLine.ProductSections[i].Removed != removed {
continue
}
item := productLine.ProductSections[i]
item.Removed = 0
result = append(result, item)
}
return result
}
//SimpleProductLine 输出简化的模型
func (productLine *ProductLine) SimpleProductLine() SimpleProductLine {
return SimpleProductLine{
LineId: productLine.LineId,
LineName: productLine.LineName,
}
}