正在显示
1 个修改的文件
包含
35 行增加
和
17 行删除
@@ -43,7 +43,7 @@ type ModuleEmployee struct { | @@ -43,7 +43,7 @@ type ModuleEmployee struct { | ||
43 | Email string `json:"email"` | 43 | Email string `json:"email"` |
44 | ExtensionNum string `json:"extension_num"` //分机号 | 44 | ExtensionNum string `json:"extension_num"` //分机号 |
45 | EntryTime string `json:"entry_time"` //入职时间 | 45 | EntryTime string `json:"entry_time"` //入职时间 |
46 | - WorkSpace string `json:"work_space"` | 46 | + WorkSpace string `json:"workspace"` |
47 | IsBusiness int8 `json:"is_business"` | 47 | IsBusiness int8 `json:"is_business"` |
48 | Status int8 `json:"status"` | 48 | Status int8 `json:"status"` |
49 | Avatar string `json:"avatar"` | 49 | Avatar string `json:"avatar"` |
@@ -72,6 +72,11 @@ type RemoveUserDepartmentData struct { | @@ -72,6 +72,11 @@ type RemoveUserDepartmentData struct { | ||
72 | DepartmentIds []int64 `json:"department_ids"` | 72 | DepartmentIds []int64 `json:"department_ids"` |
73 | } | 73 | } |
74 | 74 | ||
75 | +type ImportEmployeeData struct { | ||
76 | + Add []ModuleEmployee `json:"add"` | ||
77 | + Edit []ModuleEmployee `json:"edit"` | ||
78 | +} | ||
79 | + | ||
75 | var _ PlatformAction = ModuleEmployee{} | 80 | var _ PlatformAction = ModuleEmployee{} |
76 | 81 | ||
77 | //DoAction PlatformAction 的接口实现 | 82 | //DoAction PlatformAction 的接口实现 |
@@ -133,14 +138,18 @@ func (m ModuleEmployee) DoAction(code string, jsondata []byte) error { | @@ -133,14 +138,18 @@ func (m ModuleEmployee) DoAction(code string, jsondata []byte) error { | ||
133 | case "import": | 138 | case "import": |
134 | //导入用户 | 139 | //导入用户 |
135 | var ( | 140 | var ( |
136 | - data []ModuleEmployee | 141 | + data ImportEmployeeData |
137 | err error | 142 | err error |
138 | ) | 143 | ) |
139 | err = json.Unmarshal(jsondata, &data) | 144 | err = json.Unmarshal(jsondata, &data) |
140 | if err != nil { | 145 | if err != nil { |
141 | return fmt.Errorf("数据解析失败:%s", err) | 146 | return fmt.Errorf("数据解析失败:%s", err) |
142 | } | 147 | } |
143 | - return AddEmployeeData(data) | 148 | + AddEmployeeData(data.Add) |
149 | + for i := range data.Edit { | ||
150 | + UpdateEmployeeData(data.Edit[i]) | ||
151 | + } | ||
152 | + return nil | ||
144 | default: | 153 | default: |
145 | return errors.New("action not found") | 154 | return errors.New("action not found") |
146 | } | 155 | } |
@@ -148,7 +157,7 @@ func (m ModuleEmployee) DoAction(code string, jsondata []byte) error { | @@ -148,7 +157,7 @@ func (m ModuleEmployee) DoAction(code string, jsondata []byte) error { | ||
148 | } | 157 | } |
149 | 158 | ||
150 | // AddEmployeeData ... | 159 | // AddEmployeeData ... |
151 | -func AddEmployeeData(data []ModuleEmployee) error { | 160 | +func AddEmployeeData(data []ModuleEmployee, om ...orm.Ormer) error { |
152 | if len(data) == 0 { | 161 | if len(data) == 0 { |
153 | return nil | 162 | return nil |
154 | } | 163 | } |
@@ -263,7 +272,12 @@ func AddEmployeeData(data []ModuleEmployee) error { | @@ -263,7 +272,12 @@ func AddEmployeeData(data []ModuleEmployee) error { | ||
263 | userpositionData = append(userpositionData, p) | 272 | userpositionData = append(userpositionData, p) |
264 | } | 273 | } |
265 | } | 274 | } |
266 | - o := orm.NewOrm() | 275 | + var o orm.Ormer |
276 | + if len(om) > 0 { | ||
277 | + o = om[0] | ||
278 | + } else { | ||
279 | + o = orm.NewOrm() | ||
280 | + } | ||
267 | o.Begin() | 281 | o.Begin() |
268 | _, err = o.InsertMulti(20, &usercompanydata) | 282 | _, err = o.InsertMulti(20, &usercompanydata) |
269 | if err != nil { | 283 | if err != nil { |
@@ -295,23 +309,37 @@ func AddEmployeeData(data []ModuleEmployee) error { | @@ -295,23 +309,37 @@ func AddEmployeeData(data []ModuleEmployee) error { | ||
295 | } | 309 | } |
296 | 310 | ||
297 | // UpdateEmployeeData ... | 311 | // UpdateEmployeeData ... |
298 | -func UpdateEmployeeData(data ModuleEmployee) error { | 312 | +func UpdateEmployeeData(data ModuleEmployee, om ...orm.Ormer) error { |
299 | var ( | 313 | var ( |
300 | err error | 314 | err error |
301 | ucompany *models.UserCompany | 315 | ucompany *models.UserCompany |
302 | companyInfo *models.Company | 316 | companyInfo *models.Company |
303 | userdata *models.User | 317 | userdata *models.User |
304 | ) | 318 | ) |
319 | + companyInfo, err = models.GetCompanyByUCenter(data.CompanyId) | ||
320 | + if err != nil { | ||
321 | + e := fmt.Errorf("获取公司数据失败:%s", err) | ||
322 | + log.Error(e.Error()) | ||
323 | + return e | ||
324 | + } | ||
325 | + var o orm.Ormer | ||
326 | + if len(om) > 0 { | ||
327 | + o = om[0] | ||
328 | + } else { | ||
329 | + o = orm.NewOrm() | ||
330 | + } | ||
331 | + o.Begin() | ||
305 | ucompany, err = models.GetUserCompanyById(data.Id) | 332 | ucompany, err = models.GetUserCompanyById(data.Id) |
306 | if err == orm.ErrNoRows { | 333 | if err == orm.ErrNoRows { |
307 | log.Error("编辑操作,未找到数据,执行添加操作") | 334 | log.Error("编辑操作,未找到数据,执行添加操作") |
308 | - return AddEmployeeData([]ModuleEmployee{data}) | 335 | + return AddEmployeeData([]ModuleEmployee{data}, om...) |
309 | } | 336 | } |
310 | if err != nil { | 337 | if err != nil { |
311 | e := fmt.Errorf("获取用户和公司的关联数据失败:%s", err) | 338 | e := fmt.Errorf("获取用户和公司的关联数据失败:%s", err) |
312 | log.Error(e.Error()) | 339 | log.Error(e.Error()) |
313 | return e | 340 | return e |
314 | } | 341 | } |
342 | + //更新用户数据 | ||
315 | ucenterReturn, err := ucenter.RequestUCenterAddUser(data.Phone, data.Name, "") | 343 | ucenterReturn, err := ucenter.RequestUCenterAddUser(data.Phone, data.Name, "") |
316 | if err != nil { | 344 | if err != nil { |
317 | log.Error("请求统一用户中心数据失败:%s", err) | 345 | log.Error("请求统一用户中心数据失败:%s", err) |
@@ -324,16 +352,6 @@ func UpdateEmployeeData(data ModuleEmployee) error { | @@ -324,16 +352,6 @@ func UpdateEmployeeData(data ModuleEmployee) error { | ||
324 | log.Error(e.Error()) | 352 | log.Error(e.Error()) |
325 | return e | 353 | return e |
326 | } | 354 | } |
327 | - companyInfo, err = models.GetCompanyByUCenter(data.CompanyId) | ||
328 | - if err != nil { | ||
329 | - e := fmt.Errorf("获取公司数据失败:%s", err) | ||
330 | - log.Error(e.Error()) | ||
331 | - return e | ||
332 | - } | ||
333 | - | ||
334 | - o := orm.NewOrm() | ||
335 | - o.Begin() | ||
336 | - //更新用户数据 | ||
337 | userdata.NickName = data.Name | 355 | userdata.NickName = data.Name |
338 | userdata.Phone = data.Phone | 356 | userdata.Phone = data.Phone |
339 | userdata.UserCenterId = data.OpenId | 357 | userdata.UserCenterId = data.OpenId |
-
请 注册 或 登录 后发表评论