|
@@ -4,6 +4,9 @@ import ( |
|
@@ -4,6 +4,9 @@ import ( |
4
|
"github.com/linmadan/egglib-go/core/application"
|
4
|
"github.com/linmadan/egglib-go/core/application"
|
5
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
5
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
7
|
+ service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
|
|
|
8
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/adapter"
|
|
|
9
|
+ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/command"
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
11
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
9
|
)
|
12
|
)
|
|
@@ -46,6 +49,8 @@ func (us *UserService) ListByDepartment(in *query.ListByDepartmentQuery) (interf |
|
@@ -46,6 +49,8 @@ func (us *UserService) ListByDepartment(in *query.ListByDepartmentQuery) (interf |
46
|
}()
|
49
|
}()
|
47
|
|
50
|
|
48
|
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
51
|
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
52
|
+ positionRepo := factory.CreatePositionRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
53
|
+
|
49
|
inMap := tool_funs.SimpleStructToMap(in)
|
54
|
inMap := tool_funs.SimpleStructToMap(in)
|
50
|
if in.DepartmentId == 0 {
|
55
|
if in.DepartmentId == 0 {
|
51
|
delete(inMap, "departmentId") // 删除部门ID字段
|
56
|
delete(inMap, "departmentId") // 删除部门ID字段
|
|
@@ -54,8 +59,108 @@ func (us *UserService) ListByDepartment(in *query.ListByDepartmentQuery) (interf |
|
@@ -54,8 +59,108 @@ func (us *UserService) ListByDepartment(in *query.ListByDepartmentQuery) (interf |
54
|
if err != nil {
|
59
|
if err != nil {
|
55
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
60
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
56
|
}
|
61
|
}
|
|
|
62
|
+
|
|
|
63
|
+ parentIds := make([]int64, 0) // 上级ID
|
|
|
64
|
+ positionIds := make([]int, 0) // 职位ID
|
|
|
65
|
+ for i := range list {
|
|
|
66
|
+ if list[i].ParentId > 0 {
|
|
|
67
|
+ parentIds = append(parentIds, list[i].ParentId)
|
|
|
68
|
+ }
|
|
|
69
|
+
|
|
|
70
|
+ pList := list[i].PositionId
|
|
|
71
|
+ for i2 := range pList {
|
|
|
72
|
+ if pList[i2] > 0 {
|
|
|
73
|
+ positionIds = append(positionIds, pList[i2])
|
|
|
74
|
+ }
|
|
|
75
|
+ }
|
|
|
76
|
+ }
|
|
|
77
|
+
|
|
|
78
|
+ // 获取上级
|
|
|
79
|
+ parentMap := map[int64]*domain.User{}
|
|
|
80
|
+ if len(parentIds) > 0 {
|
|
|
81
|
+ _, parentList, err := userRepo.Find(map[string]interface{}{"ids": parentIds})
|
|
|
82
|
+ if err != nil {
|
|
|
83
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
84
|
+ }
|
|
|
85
|
+ for i := range parentList {
|
|
|
86
|
+ parentMap[parentList[i].Id] = parentList[i]
|
|
|
87
|
+ }
|
|
|
88
|
+ }
|
|
|
89
|
+
|
|
|
90
|
+ // 获取职位
|
|
|
91
|
+ positionMap := map[int64]*domain.Position{}
|
|
|
92
|
+ if len(positionIds) > 0 {
|
|
|
93
|
+ _, positionList, err := positionRepo.Find(map[string]interface{}{"ids": positionIds})
|
|
|
94
|
+ if err != nil {
|
|
|
95
|
+ return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
96
|
+ }
|
|
|
97
|
+ for i := range positionList {
|
|
|
98
|
+ positionMap[positionList[i].Id] = positionList[i]
|
|
|
99
|
+ }
|
|
|
100
|
+ }
|
|
|
101
|
+
|
|
|
102
|
+ adapters := make([]*adapter.UserResp, 0)
|
|
|
103
|
+ for i := range list {
|
|
|
104
|
+ adp := &adapter.UserResp{
|
|
|
105
|
+ User: list[i],
|
|
|
106
|
+ }
|
|
|
107
|
+ // 上级名称
|
|
|
108
|
+ if v, ok := parentMap[list[i].ParentId]; ok {
|
|
|
109
|
+ adp.ParentName = v.Name
|
|
|
110
|
+ }
|
|
|
111
|
+ // 职位名称数组
|
|
|
112
|
+ adp.PositionNames = make([]string, 0)
|
|
|
113
|
+ pList := list[i].PositionId
|
|
|
114
|
+ for i2 := range pList {
|
|
|
115
|
+ if v2, ok := positionMap[int64(pList[i2])]; ok {
|
|
|
116
|
+ adp.PositionNames = append(adp.PositionNames, v2.Name)
|
|
|
117
|
+ }
|
|
|
118
|
+ }
|
|
|
119
|
+ adapters = append(adapters, adp)
|
|
|
120
|
+ }
|
|
|
121
|
+
|
57
|
if err := transactionContext.CommitTransaction(); err != nil {
|
122
|
if err := transactionContext.CommitTransaction(); err != nil {
|
58
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
123
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
59
|
}
|
124
|
}
|
60
|
- return tool_funs.SimpleWrapGridMap(int64(count), list), nil
|
125
|
+ return tool_funs.SimpleWrapGridMap(int64(count), adapters), nil
|
|
|
126
|
+}
|
|
|
127
|
+
|
|
|
128
|
+// EditParentUser 保存上级
|
|
|
129
|
+func (us *UserService) EditParentUser(in *command.EditParentCommand) error {
|
|
|
130
|
+ transactionContext, err := factory.ValidateStartTransaction(in)
|
|
|
131
|
+ if err != nil {
|
|
|
132
|
+ return err
|
|
|
133
|
+ }
|
|
|
134
|
+ defer func() {
|
|
|
135
|
+ transactionContext.RollbackTransaction()
|
|
|
136
|
+ }()
|
|
|
137
|
+
|
|
|
138
|
+ hrbp, err := service.GetHRBP(transactionContext, in.CompanyId, in.OperatorId)
|
|
|
139
|
+ if err != nil {
|
|
|
140
|
+ return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
141
|
+ }
|
|
|
142
|
+ if hrbp != 1 {
|
|
|
143
|
+ return application.ThrowError(application.BUSINESS_ERROR, "拥有HRBP权限才能编辑")
|
|
|
144
|
+ }
|
|
|
145
|
+
|
|
|
146
|
+ userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
147
|
+ user, err := userRepo.FindOne(map[string]interface{}{"id": in.Id})
|
|
|
148
|
+ if err != nil {
|
|
|
149
|
+ return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
150
|
+ }
|
|
|
151
|
+ // 上级ID是否存在
|
|
|
152
|
+ _, err = userRepo.FindOne(map[string]interface{}{"id": in.ParentId})
|
|
|
153
|
+ if err != nil {
|
|
|
154
|
+ return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
155
|
+ }
|
|
|
156
|
+ user.ParentId = in.ParentId
|
|
|
157
|
+
|
|
|
158
|
+ if _, err = userRepo.Update(user); err != nil {
|
|
|
159
|
+ return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
160
|
+ }
|
|
|
161
|
+
|
|
|
162
|
+ if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
163
|
+ return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
164
|
+ }
|
|
|
165
|
+ return nil
|
61
|
} |
166
|
} |