更新
This commit is contained in:
1 parent
b6b528490c
commit
4ab63e77ed
28 files changed
+1858
-695
No files matched your search
@@ -224,6 +224,51 @@ func findBackendTenantUser(idOrUid uint64, jwtTid uint64, byID bool) (*models.Sy
|
||||
|
||||
// GetAllUsers 获取当前租户后台用户列表
|
||||
// GET /backend/getAllUsers
|
||||
// SyncTenantUsersToEmployees 手动同步当前租户选中的用户到人员档案。
|
||||
// POST /backend/syncTenantUsersToEmployees {"user_ids":[...]};服务层再次按 JWT tid 校验每个 ID。
|
||||
func (c *BackendAdminUserController) SyncTenantUsersToEmployees() {
|
||||
_, tid, ok := c.requireBackendIdentity()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if tid == 0 {
|
||||
c.Data["json"] = map[string]interface{}{"code": 403, "msg": "登录态未绑定企业"}
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
var request struct {
|
||||
UserIDs []uint64 `json:"user_ids"`
|
||||
}
|
||||
body := c.Ctx.Input.RequestBody
|
||||
if len(body) == 0 {
|
||||
var readErr error
|
||||
body, readErr = io.ReadAll(c.Ctx.Request.Body)
|
||||
if readErr != nil {
|
||||
c.Data["json"] = map[string]interface{}{"code": 400, "msg": "读取同步请求失败"}
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := json.Unmarshal(body, &request); err != nil || len(request.UserIDs) == 0 {
|
||||
c.Data["json"] = map[string]interface{}{"code": 400, "msg": "请先选择要同步的用户"}
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
if len(request.UserIDs) > 500 {
|
||||
c.Data["json"] = map[string]interface{}{"code": 400, "msg": "单次最多同步500个用户"}
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
result, err := services.SyncSelectedTenantUsersToEmployees(tid, request.UserIDs)
|
||||
if err != nil {
|
||||
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "同步失败: " + err.Error()}
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": result}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *BackendAdminUserController) GetAllUsers() {
|
||||
_, jwtTid, ok := c.requireBackendIdentity()
|
||||
if !ok {
|
||||
@@ -557,6 +602,8 @@ func (c *BackendAdminUserController) AddUser() {
|
||||
if e := models.Orm.QueryTable(new(models.SystemTenantUser)).Filter("id", id).One(&created); e == nil {
|
||||
syncTenantUserToAuth(&created, false)
|
||||
}
|
||||
// 自动生成员工并同步通讯录(先有用户,后自动生成员工)
|
||||
_, _, _ = services.EnsureEmployeeForTenantUser(&created)
|
||||
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
"code": 200,
|
||||
@@ -687,6 +734,12 @@ func (c *BackendAdminUserController) EditUser() {
|
||||
var edited models.SystemTenantUser
|
||||
if e := models.Orm.QueryTable(new(models.SystemTenantUser)).Filter("id", row.ID).One(&edited); e == nil {
|
||||
syncTenantUserToAuth(&edited, false)
|
||||
oldAccount := ""
|
||||
if row.Account != nil {
|
||||
oldAccount = *row.Account
|
||||
}
|
||||
_ = services.SyncEmployeeOnUserUpdate(row.Tid, oldAccount, &edited)
|
||||
|
||||
}
|
||||
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success"}
|
||||
@@ -729,6 +782,11 @@ func (c *BackendAdminUserController) DeleteUser() {
|
||||
return
|
||||
}
|
||||
|
||||
// 同步将员工状态置为离职(2)
|
||||
if row.Account != nil {
|
||||
_ = services.SyncEmployeeOnUserDelete(row.Tid, *row.Account)
|
||||
}
|
||||
|
||||
// 双写:删除认证中心中的企业绑定
|
||||
removeTenantUserFromAuth(row)
|
||||
|
||||
@@ -790,7 +848,6 @@ func (c *BackendAdminUserController) ChangePassword() {
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
// 双写:同步新密码到统一认证中心(改密场景,显式允许更新身份层密码)
|
||||
var updated models.SystemTenantUser
|
||||
if e := models.Orm.QueryTable(new(models.SystemTenantUser)).Filter("id", row.ID).One(&updated); e == nil {
|
||||
|
||||
Reference in new issue
Block a user