正在显示
2 个修改的文件
包含
271 行增加
和
0 行删除
@@ -52,6 +52,8 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s | @@ -52,6 +52,8 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s | ||
52 | var isPrincipal bool | 52 | var isPrincipal bool |
53 | var status int | 53 | var status int |
54 | var uids []int64 | 54 | var uids []int64 |
55 | + var addEmployees []map[string]interface{} | ||
56 | + var editEmployees []map[string]interface{} | ||
55 | var data map[string]interface{} | 57 | var data map[string]interface{} |
56 | if err := json.Unmarshal([]byte(syncEmployeeCallbackCommand.Data), &data); err != nil { | 58 | if err := json.Unmarshal([]byte(syncEmployeeCallbackCommand.Data), &data); err != nil { |
57 | return false, err | 59 | return false, err |
@@ -86,8 +88,111 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s | @@ -86,8 +88,111 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s | ||
86 | uids = append(uids, int64(uid.(float64))) | 88 | uids = append(uids, int64(uid.(float64))) |
87 | } | 89 | } |
88 | } | 90 | } |
91 | + if value, ok := data["add"]; ok { | ||
92 | + for _, addEmployee := range value.([]interface{}) { | ||
93 | + addEmployees = append(addEmployees, addEmployee.(map[string]interface{})) | ||
94 | + } | ||
95 | + } | ||
96 | + if value, ok := data["edit"]; ok { | ||
97 | + for _, editEmployee := range value.([]interface{}) { | ||
98 | + editEmployees = append(editEmployees, editEmployee.(map[string]interface{})) | ||
99 | + } | ||
100 | + } | ||
89 | if syncEmployeeCallbackCommand.Module == "employee" { | 101 | if syncEmployeeCallbackCommand.Module == "employee" { |
90 | switch syncEmployeeCallbackCommand.Action { | 102 | switch syncEmployeeCallbackCommand.Action { |
103 | + case "import": | ||
104 | + var companyId int64 | ||
105 | + var uid int64 | ||
106 | + var employeeName string | ||
107 | + var employeeAccount string | ||
108 | + var employeeAvatarUrl string | ||
109 | + var isPrincipal bool | ||
110 | + var status int | ||
111 | + for _, addEmployee := range addEmployees { | ||
112 | + if value, ok := addEmployee["company_id"]; ok { | ||
113 | + companyId = int64(value.(float64)) | ||
114 | + } | ||
115 | + if value, ok := addEmployee["id"]; ok { | ||
116 | + uid = int64(value.(float64)) | ||
117 | + } | ||
118 | + if value, ok := addEmployee["name"]; ok { | ||
119 | + employeeName = value.(string) | ||
120 | + } | ||
121 | + if value, ok := addEmployee["phone"]; ok { | ||
122 | + employeeAccount = value.(string) | ||
123 | + } | ||
124 | + if value, ok := addEmployee["avatar"]; ok { | ||
125 | + employeeAvatarUrl = value.(string) | ||
126 | + } | ||
127 | + if value, ok := addEmployee["admin_type"]; ok { | ||
128 | + if int(value.(float64)) == 2 { | ||
129 | + isPrincipal = true | ||
130 | + } else { | ||
131 | + isPrincipal = false | ||
132 | + } | ||
133 | + } | ||
134 | + if value, ok := addEmployee["status"]; ok { | ||
135 | + status = int(value.(float64)) | ||
136 | + } | ||
137 | + employee := &domain.Employee{ | ||
138 | + CompanyId: companyId, | ||
139 | + EmployeeInfo: &domain.EmployeeInfo{ | ||
140 | + Uid: uid, | ||
141 | + EmployeeName: employeeName, | ||
142 | + EmployeeAccount: employeeAccount, | ||
143 | + EmployeeAvatarUrl: employeeAvatarUrl, | ||
144 | + IsPrincipal: isPrincipal, | ||
145 | + }, | ||
146 | + Status: status, | ||
147 | + SuMoney: 0, | ||
148 | + } | ||
149 | + if _, err := employeeRepository.Save(employee); err != nil { | ||
150 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
151 | + } | ||
152 | + } | ||
153 | + for _, editEmployee := range editEmployees { | ||
154 | + if value, ok := editEmployee["company_id"]; ok { | ||
155 | + companyId = int64(value.(float64)) | ||
156 | + } | ||
157 | + if value, ok := editEmployee["id"]; ok { | ||
158 | + uid = int64(value.(float64)) | ||
159 | + } | ||
160 | + if value, ok := editEmployee["name"]; ok { | ||
161 | + employeeName = value.(string) | ||
162 | + } | ||
163 | + if value, ok := editEmployee["phone"]; ok { | ||
164 | + employeeAccount = value.(string) | ||
165 | + } | ||
166 | + if value, ok := editEmployee["avatar"]; ok { | ||
167 | + employeeAvatarUrl = value.(string) | ||
168 | + } | ||
169 | + if value, ok := editEmployee["admin_type"]; ok { | ||
170 | + if int(value.(float64)) == 2 { | ||
171 | + isPrincipal = true | ||
172 | + } else { | ||
173 | + isPrincipal = false | ||
174 | + } | ||
175 | + } | ||
176 | + if value, ok := editEmployee["status"]; ok { | ||
177 | + status = int(value.(float64)) | ||
178 | + } | ||
179 | + employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": uid}) | ||
180 | + if err == nil && employee != nil { | ||
181 | + updateData := make(map[string]interface{}) | ||
182 | + updateData["employeeName"] = employeeName | ||
183 | + updateData["employeeAccount"] = employeeAccount | ||
184 | + updateData["employeeAvatarUrl"] = employeeAvatarUrl | ||
185 | + updateData["isPrincipal"] = isPrincipal | ||
186 | + updateData["status"] = status | ||
187 | + if err := employee.Update(updateData); err != nil { | ||
188 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
189 | + } | ||
190 | + if _, err := employeeRepository.Save(employee); err != nil { | ||
191 | + return false, nil | ||
192 | + } | ||
193 | + } | ||
194 | + } | ||
195 | + break | ||
91 | case "add": | 196 | case "add": |
92 | employee := &domain.Employee{ | 197 | employee := &domain.Employee{ |
93 | CompanyId: companyId, | 198 | CompanyId: companyId, |
@@ -339,6 +339,172 @@ var _ = Describe("同步企业员工回调", func() { | @@ -339,6 +339,172 @@ var _ = Describe("同步企业员工回调", func() { | ||
339 | ContainsKey("data").ValueEqual("data", true) | 339 | ContainsKey("data").ValueEqual("data", true) |
340 | }) | 340 | }) |
341 | }) | 341 | }) |
342 | + Context("同步批量导入或更新员工", func() { | ||
343 | + It("批量导入或更新成功", func() { | ||
344 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
345 | + body := map[string]interface{}{ | ||
346 | + "module": "employee", | ||
347 | + "action": "import", | ||
348 | + "data": `{ | ||
349 | + "add": [ | ||
350 | + { | ||
351 | + "id": 3240049086271232, | ||
352 | + "company_id": 1, | ||
353 | + "open_id": 0, | ||
354 | + "name": "张三(示例)", | ||
355 | + "sex": 1, | ||
356 | + "job_num": "", | ||
357 | + "phone": "14500000001", | ||
358 | + "private_phone": "14500000000", | ||
359 | + "email": "zhangsan@dingtalkcs.com", | ||
360 | + "extension_num": "0571-12345678", | ||
361 | + "entry_time": null, | ||
362 | + "workspace": "", | ||
363 | + "is_business": 1, | ||
364 | + "status": 2, | ||
365 | + "avatar": "", | ||
366 | + "extra_text": "[]", | ||
367 | + "remarks": "", | ||
368 | + "admin_type": 1, | ||
369 | + "charge_status": 2, | ||
370 | + "created_at": "2020-02-19 03:46:57", | ||
371 | + "updated_at": "2020-02-19 03:46:57", | ||
372 | + "deleted_at": null, | ||
373 | + "user_departments": [ | ||
374 | + { | ||
375 | + "id": 214, | ||
376 | + "company_id": 1, | ||
377 | + "department_id": 69, | ||
378 | + "user_id": 3240049086271232, | ||
379 | + "created_at": "2020-02-19 03:46:57", | ||
380 | + "updated_at": "2020-02-19 03:46:57", | ||
381 | + "deleted_at": null | ||
382 | + }, | ||
383 | + { | ||
384 | + "id": 215, | ||
385 | + "company_id": 1, | ||
386 | + "department_id": 74, | ||
387 | + "user_id": 3240049086271232, | ||
388 | + "created_at": "2020-02-19 03:46:57", | ||
389 | + "updated_at": "2020-02-19 03:46:57", | ||
390 | + "deleted_at": null | ||
391 | + } | ||
392 | + ], | ||
393 | + "user_positions": [ | ||
394 | + { | ||
395 | + "id": 68, | ||
396 | + "company_id": 1, | ||
397 | + "position_id": 23, | ||
398 | + "user_id": 3240049086271232, | ||
399 | + "created_at": "2020-02-19 03:46:57", | ||
400 | + "updated_at": "2020-02-19 03:46:57", | ||
401 | + "deleted_at": null | ||
402 | + } | ||
403 | + ], | ||
404 | + "user_roles": [ | ||
405 | + { | ||
406 | + "id": 90, | ||
407 | + "role_id": 7, | ||
408 | + "enable_status": 1, | ||
409 | + "company_id": 1, | ||
410 | + "user_id": 3240049086271232 | ||
411 | + }, | ||
412 | + { | ||
413 | + "id": 91, | ||
414 | + "role_id": 8, | ||
415 | + "enable_status": 1, | ||
416 | + "company_id": 1, | ||
417 | + "user_id": 3240049086271232 | ||
418 | + } | ||
419 | + ] | ||
420 | + } | ||
421 | + ], | ||
422 | + "edit": [ | ||
423 | + { | ||
424 | + "id": 3240033896900352, | ||
425 | + "company_id": 1, | ||
426 | + "open_id": 0, | ||
427 | + "name": "张三(示例)", | ||
428 | + "sex": 1, | ||
429 | + "job_num": "110", | ||
430 | + "phone": "14500000000", | ||
431 | + "private_phone": "14500000000", | ||
432 | + "email": "zhangsan@dingtalkcs.com", | ||
433 | + "extension_num": "0571-12345678", | ||
434 | + "entry_time": "2015-03-03", | ||
435 | + "workspace": "杭州市阿里巴巴西溪园区1号楼502", | ||
436 | + "is_business": 1, | ||
437 | + "status": 2, | ||
438 | + "avatar": "", | ||
439 | + "extra_text": "[]", | ||
440 | + "remarks": "创始团队成员", | ||
441 | + "admin_type": 1, | ||
442 | + "charge_status": 2, | ||
443 | + "created_at": null, | ||
444 | + "updated_at": "2020-02-19 03:46:57", | ||
445 | + "deleted_at": null, | ||
446 | + "user_departments": [ | ||
447 | + { | ||
448 | + "id": 216, | ||
449 | + "company_id": 1, | ||
450 | + "department_id": 69, | ||
451 | + "user_id": 3240033896900352, | ||
452 | + "created_at": "2020-02-19 03:46:57", | ||
453 | + "updated_at": "2020-02-19 03:46:57", | ||
454 | + "deleted_at": null | ||
455 | + }, | ||
456 | + { | ||
457 | + "id": 217, | ||
458 | + "company_id": 1, | ||
459 | + "department_id": 74, | ||
460 | + "user_id": 3240033896900352, | ||
461 | + "created_at": "2020-02-19 03:46:57", | ||
462 | + "updated_at": "2020-02-19 03:46:57", | ||
463 | + "deleted_at": null | ||
464 | + } | ||
465 | + ], | ||
466 | + "user_positions": [ | ||
467 | + { | ||
468 | + "id": 69, | ||
469 | + "company_id": 1, | ||
470 | + "position_id": 23, | ||
471 | + "user_id": 3240033896900352, | ||
472 | + "created_at": "2020-02-19 03:46:57", | ||
473 | + "updated_at": "2020-02-19 03:46:57", | ||
474 | + "deleted_at": null | ||
475 | + } | ||
476 | + ], | ||
477 | + "user_roles": [ | ||
478 | + { | ||
479 | + "id": 92, | ||
480 | + "role_id": 7, | ||
481 | + "enable_status": 1, | ||
482 | + "company_id": 1, | ||
483 | + "user_id": 3240033896900352 | ||
484 | + }, | ||
485 | + { | ||
486 | + "id": 93, | ||
487 | + "role_id": 8, | ||
488 | + "enable_status": 1, | ||
489 | + "company_id": 1, | ||
490 | + "user_id": 3240033896900352 | ||
491 | + } | ||
492 | + ] | ||
493 | + } | ||
494 | + ] | ||
495 | + }`, | ||
496 | + } | ||
497 | + httpExpect.POST("/api/business/index"). | ||
498 | + WithJSON(body). | ||
499 | + Expect(). | ||
500 | + Status(http.StatusOK). | ||
501 | + JSON(). | ||
502 | + Object(). | ||
503 | + ContainsKey("code").ValueEqual("code", 0). | ||
504 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
505 | + ContainsKey("data").ValueEqual("data", true) | ||
506 | + }) | ||
507 | + }) | ||
342 | }) | 508 | }) |
343 | AfterEach(func() { | 509 | AfterEach(func() { |
344 | _, err := pG.DB.Exec("DELETE FROM employees WHERE true") | 510 | _, err := pG.DB.Exec("DELETE FROM employees WHERE true") |
-
请 注册 或 登录 后发表评论