作者 linmadan

添加同步企业平台批量导入于编辑接口

... ... @@ -52,6 +52,8 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
var isPrincipal bool
var status int
var uids []int64
var addEmployees []map[string]interface{}
var editEmployees []map[string]interface{}
var data map[string]interface{}
if err := json.Unmarshal([]byte(syncEmployeeCallbackCommand.Data), &data); err != nil {
return false, err
... ... @@ -86,8 +88,111 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
uids = append(uids, int64(uid.(float64)))
}
}
if value, ok := data["add"]; ok {
for _, addEmployee := range value.([]interface{}) {
addEmployees = append(addEmployees, addEmployee.(map[string]interface{}))
}
}
if value, ok := data["edit"]; ok {
for _, editEmployee := range value.([]interface{}) {
editEmployees = append(editEmployees, editEmployee.(map[string]interface{}))
}
}
if syncEmployeeCallbackCommand.Module == "employee" {
switch syncEmployeeCallbackCommand.Action {
case "import":
var companyId int64
var uid int64
var employeeName string
var employeeAccount string
var employeeAvatarUrl string
var isPrincipal bool
var status int
for _, addEmployee := range addEmployees {
if value, ok := addEmployee["company_id"]; ok {
companyId = int64(value.(float64))
}
if value, ok := addEmployee["id"]; ok {
uid = int64(value.(float64))
}
if value, ok := addEmployee["name"]; ok {
employeeName = value.(string)
}
if value, ok := addEmployee["phone"]; ok {
employeeAccount = value.(string)
}
if value, ok := addEmployee["avatar"]; ok {
employeeAvatarUrl = value.(string)
}
if value, ok := addEmployee["admin_type"]; ok {
if int(value.(float64)) == 2 {
isPrincipal = true
} else {
isPrincipal = false
}
}
if value, ok := addEmployee["status"]; ok {
status = int(value.(float64))
}
employee := &domain.Employee{
CompanyId: companyId,
EmployeeInfo: &domain.EmployeeInfo{
Uid: uid,
EmployeeName: employeeName,
EmployeeAccount: employeeAccount,
EmployeeAvatarUrl: employeeAvatarUrl,
IsPrincipal: isPrincipal,
},
Status: status,
SuMoney: 0,
}
if _, err := employeeRepository.Save(employee); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
for _, editEmployee := range editEmployees {
if value, ok := editEmployee["company_id"]; ok {
companyId = int64(value.(float64))
}
if value, ok := editEmployee["id"]; ok {
uid = int64(value.(float64))
}
if value, ok := editEmployee["name"]; ok {
employeeName = value.(string)
}
if value, ok := editEmployee["phone"]; ok {
employeeAccount = value.(string)
}
if value, ok := editEmployee["avatar"]; ok {
employeeAvatarUrl = value.(string)
}
if value, ok := editEmployee["admin_type"]; ok {
if int(value.(float64)) == 2 {
isPrincipal = true
} else {
isPrincipal = false
}
}
if value, ok := editEmployee["status"]; ok {
status = int(value.(float64))
}
employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": uid})
if err == nil && employee != nil {
updateData := make(map[string]interface{})
updateData["employeeName"] = employeeName
updateData["employeeAccount"] = employeeAccount
updateData["employeeAvatarUrl"] = employeeAvatarUrl
updateData["isPrincipal"] = isPrincipal
updateData["status"] = status
if err := employee.Update(updateData); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if _, err := employeeRepository.Save(employee); err != nil {
return false, nil
}
}
}
break
case "add":
employee := &domain.Employee{
CompanyId: companyId,
... ...
... ... @@ -339,6 +339,172 @@ var _ = Describe("同步企业员工回调", func() {
ContainsKey("data").ValueEqual("data", true)
})
})
Context("同步批量导入或更新员工", func() {
It("批量导入或更新成功", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"module": "employee",
"action": "import",
"data": `{
"add": [
{
"id": 3240049086271232,
"company_id": 1,
"open_id": 0,
"name": "张三(示例)",
"sex": 1,
"job_num": "",
"phone": "14500000001",
"private_phone": "14500000000",
"email": "zhangsan@dingtalkcs.com",
"extension_num": "0571-12345678",
"entry_time": null,
"workspace": "",
"is_business": 1,
"status": 2,
"avatar": "",
"extra_text": "[]",
"remarks": "",
"admin_type": 1,
"charge_status": 2,
"created_at": "2020-02-19 03:46:57",
"updated_at": "2020-02-19 03:46:57",
"deleted_at": null,
"user_departments": [
{
"id": 214,
"company_id": 1,
"department_id": 69,
"user_id": 3240049086271232,
"created_at": "2020-02-19 03:46:57",
"updated_at": "2020-02-19 03:46:57",
"deleted_at": null
},
{
"id": 215,
"company_id": 1,
"department_id": 74,
"user_id": 3240049086271232,
"created_at": "2020-02-19 03:46:57",
"updated_at": "2020-02-19 03:46:57",
"deleted_at": null
}
],
"user_positions": [
{
"id": 68,
"company_id": 1,
"position_id": 23,
"user_id": 3240049086271232,
"created_at": "2020-02-19 03:46:57",
"updated_at": "2020-02-19 03:46:57",
"deleted_at": null
}
],
"user_roles": [
{
"id": 90,
"role_id": 7,
"enable_status": 1,
"company_id": 1,
"user_id": 3240049086271232
},
{
"id": 91,
"role_id": 8,
"enable_status": 1,
"company_id": 1,
"user_id": 3240049086271232
}
]
}
],
"edit": [
{
"id": 3240033896900352,
"company_id": 1,
"open_id": 0,
"name": "张三(示例)",
"sex": 1,
"job_num": "110",
"phone": "14500000000",
"private_phone": "14500000000",
"email": "zhangsan@dingtalkcs.com",
"extension_num": "0571-12345678",
"entry_time": "2015-03-03",
"workspace": "杭州市阿里巴巴西溪园区1号楼502",
"is_business": 1,
"status": 2,
"avatar": "",
"extra_text": "[]",
"remarks": "创始团队成员",
"admin_type": 1,
"charge_status": 2,
"created_at": null,
"updated_at": "2020-02-19 03:46:57",
"deleted_at": null,
"user_departments": [
{
"id": 216,
"company_id": 1,
"department_id": 69,
"user_id": 3240033896900352,
"created_at": "2020-02-19 03:46:57",
"updated_at": "2020-02-19 03:46:57",
"deleted_at": null
},
{
"id": 217,
"company_id": 1,
"department_id": 74,
"user_id": 3240033896900352,
"created_at": "2020-02-19 03:46:57",
"updated_at": "2020-02-19 03:46:57",
"deleted_at": null
}
],
"user_positions": [
{
"id": 69,
"company_id": 1,
"position_id": 23,
"user_id": 3240033896900352,
"created_at": "2020-02-19 03:46:57",
"updated_at": "2020-02-19 03:46:57",
"deleted_at": null
}
],
"user_roles": [
{
"id": 92,
"role_id": 7,
"enable_status": 1,
"company_id": 1,
"user_id": 3240033896900352
},
{
"id": 93,
"role_id": 8,
"enable_status": 1,
"company_id": 1,
"user_id": 3240033896900352
}
]
}
]
}`,
}
httpExpect.POST("/api/business/index").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").ValueEqual("data", true)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM employees WHERE true")
... ...