workshops.go
3.0 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package domain
import "strings"
/*车间列表*/
type Workshops []*Workshop
func (m Workshops) FindWorkStation(workshopId, lineId, sectionId int) *WorkStation {
for i := range m {
item := m[i]
workstation, err := item.FindWorkStation(workshopId, lineId, sectionId)
if err == nil && workstation != nil {
return workstation
}
}
return &WorkStation{} //返回空的对象
}
func (m Workshops) FindWorkStationOrNil(workshopId, lineId, sectionId int) *WorkStation {
for i := range m {
item := m[i]
workstation, err := item.FindWorkStationOrNil(workshopId, lineId, sectionId)
if err == nil && workstation != nil {
return workstation
}
}
return &WorkStation{} //返回空的对象
}
func (m Workshops) FindWorkshopsByName(workshopName string) []int {
result := make([]int, 0)
if len(workshopName) == 0 {
return result
}
for i := range m {
item := m[i]
if strings.Contains(item.WorkshopName, workshopName) {
result = append(result, item.WorkshopId)
}
}
return result
}
func (m Workshops) FindProductLinesByName(lineName string) []int {
result := make([]int, 0)
if len(lineName) == 0 {
return result
}
for i := range m {
item := m[i]
for j := range item.ProductLines {
line := item.ProductLines[j]
if line.Removed == Deleted {
continue
}
if strings.Contains(line.LineName, lineName) {
result = append(result, line.LineId)
}
}
}
return result
}
func (m Workshops) FindProductSectionsByName(sectionName string) []int {
result := make([]int, 0)
if len(sectionName) == 0 {
return result
}
for i := range m {
item := m[i]
for j := range item.ProductLines {
line := item.ProductLines[j]
if line.Removed == Deleted {
continue
}
for z := range line.ProductSections {
section := line.ProductSections[z]
if section.Removed == Deleted {
continue
}
if strings.Contains(section.SectionName, sectionName) {
result = append(result, section.SectionId)
}
}
}
}
return result
}
func (m Workshops) FindByName(workshopName, lineName, sectionName string) (workshops []int, lines []int, sections []int) {
workshops = m.FindWorkshopsByName(workshopName)
lines = m.FindProductLinesByName(lineName)
sections = m.FindProductSectionsByName(sectionName)
return
}
func (m Workshops) FindByNameWithQuery(query map[string]interface{}, workshopName, lineName, sectionName string) map[string]interface{} {
var workshops, lines, sections []int
workshops = m.FindWorkshopsByName(workshopName)
lines = m.FindProductLinesByName(lineName)
sections = m.FindProductSectionsByName(sectionName)
defaultValue := []int{0}
if len(workshops) > 0 {
query["inWorkshopIds"] = workshops
} else {
if len(workshopName) > 0 {
query["inWorkshopIds"] = defaultValue
}
}
if len(lines) > 0 {
query["inLineIds"] = lines
} else {
if len(lineName) > 0 {
query["inLineIds"] = defaultValue
}
}
if len(sections) > 0 {
query["inSectionIds"] = sections
} else {
if len(sectionName) > 0 {
query["inSectionIds"] = defaultValue
}
}
return query
}