product_group_employees_dto.go
3.9 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
127
128
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils/converter"
"strings"
)
// 生产班组员工
type ProductGroupEmployeesDto struct {
// 用户Id 用户唯一标识
UserId int `json:"userId,omitempty"`
// 用户姓名
UserName string `json:"userName,omitempty"`
// 生产小组ID
ProductGroupId int `json:"productGroupId,omitempty"`
// 班组名称
GroupName string `json:"groupName,omitempty"`
// 上班班次 1:全天 2:白班 4:中班 8:夜班
WorkOnDescription string `json:"workOn,omitempty"`
// 工作位置键值 (车间ID+'.'+生产线ID+'.'+工段ID)
//WorkStationId string `json:"workStationId,omitempty"`
UserNamePinyin string `json:"pinyin"`
// 在线的
Online bool `json:"online"`
}
func NewProductGroupEmployeesDto(group *domain.ProductGroup) []*ProductGroupEmployeesDto {
employees := make([]*ProductGroupEmployeesDto, 0)
if group.GroupLeader != nil {
employees = append(employees, NewGroupEmployee(group, group.GroupLeader))
}
for i := range group.GroupMembers {
employees = append(employees, NewGroupEmployee(group, group.GroupMembers[i]))
}
return employees
}
func NewGroupEmployee(group *domain.ProductGroup, u *domain.User) *ProductGroupEmployeesDto {
item := &ProductGroupEmployeesDto{}
item.UserId = u.UserId
item.UserName = u.UserName
item.ProductGroupId = group.ProductGroupId
item.GroupName = group.GroupName
workOns := domain.WorkOnDescription(group.WorkOn)
item.WorkOnDescription = strings.Join(workOns, ",")
//item.WorkStationId = group.WorkStation.WorkStationId
if len(item.UserName) > 0 {
item.UserNamePinyin = converter.ToPinYin(item.UserName, "")
}
return item
}
type ProductGroupEmployeesDtos struct {
Result []*ProductGroupEmployeesDto
MapResult map[int]*ProductGroupEmployeesDto
}
func (d *ProductGroupEmployeesDtos) Append(items ...*ProductGroupEmployeesDto) {
for i := range items {
if _, ok := d.MapResult[items[i].UserId]; ok {
continue
}
d.MapResult[items[i].UserId] = items[i]
d.Result = append(d.Result, items[i])
}
}
func (d *ProductGroupEmployeesDtos) LoadDto(groups ...*domain.ProductGroup) {
for i := range groups {
items := NewProductGroupEmployeesDto(groups[i])
d.Append(items...)
}
}
func (d *ProductGroupEmployeesDtos) LoadDtoV2(list []*domain.ProductAttendanceRecord, mapGroupUser map[string]*domain.User, keyFunc func(int) string) {
var mapUser = make(map[int]int)
// 打卡的用户
for _, v := range list {
item := &ProductGroupEmployeesDto{}
item.UserId = v.ProductWorker.UserId
item.UserName = v.ProductWorker.UserName
item.ProductGroupId = 0
item.GroupName = ""
item.Online = true
if v, ok := mapGroupUser[keyFunc(item.UserId)]; ok {
item.GroupName = v.GroupName
item.ProductGroupId = v.GroupId
item.WorkOnDescription = domain.WorkOnDescriptions(v.WorkOn)
}
if len(item.UserName) > 0 {
item.UserNamePinyin = converter.ToPinYin(item.UserName, "")
}
if _, ok := mapUser[item.UserId]; ok {
continue
}
mapUser[item.UserId] = item.UserId
d.Append(item)
}
// 未打卡的用户
for _, v := range mapGroupUser {
if _, ok := mapUser[v.UserId]; ok {
continue
}
item := &ProductGroupEmployeesDto{}
item.UserId = v.UserId
item.UserName = v.UserName
item.ProductGroupId = v.GroupId
item.GroupName = v.GroupName
mapUser[item.UserId] = item.UserId
d.Append(item)
}
}
func NewProductGroupEmployeesDtos() *ProductGroupEmployeesDtos {
return &ProductGroupEmployeesDtos{
Result: make([]*ProductGroupEmployeesDto, 0),
MapResult: make(map[int]*ProductGroupEmployeesDto),
}
}
func (ms *ProductGroupEmployeesDtos) Len() int { return len(ms.Result) }
func (ms *ProductGroupEmployeesDtos) Less(i, j int) bool {
return ms.Result[i].UserNamePinyin < ms.Result[j].UserNamePinyin
}
func (ms *ProductGroupEmployeesDtos) Swap(i, j int) {
ms.Result[i], ms.Result[j] = ms.Result[j], ms.Result[i]
}