更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -11,10 +11,8 @@ import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
)
|
||||
|
||||
// OnEmployeeCreatedHook 员工创建后的外部回调(由 controllers 包在初始化时注册,如同步通讯录)
|
||||
var OnEmployeeCreatedHook func(tid uint64, employeeID uint64, emp *models.BackendEmployee)
|
||||
|
||||
// parseDate 解析日期字符串为 *time.Time
|
||||
func parseDate(v string) *time.Time {
|
||||
v = strings.TrimSpace(v)
|
||||
if v == "" {
|
||||
@@ -29,8 +27,6 @@ func parseDate(v string) *time.Time {
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnsureEmployeeForTenantUser 确保租户用户在 yz_backend_employee 中有对应的人员记录。
|
||||
// 规则:先有用户,后自动生成员工,以 (tid, account) 严格匹配。
|
||||
func EnsureEmployeeForTenantUser(tu *models.SystemTenantUser) (*models.BackendEmployee, bool, error) {
|
||||
if tu == nil || tu.Account == nil {
|
||||
return nil, false, nil
|
||||
@@ -74,7 +70,6 @@ func EnsureEmployeeForTenantUser(tu *models.SystemTenantUser) (*models.BackendEm
|
||||
}
|
||||
|
||||
if err == orm.ErrNoRows {
|
||||
// 不存在 -> 自动创建新员工
|
||||
newEmp := models.BackendEmployee{
|
||||
Tid: &tid,
|
||||
Account: account,
|
||||
@@ -101,10 +96,8 @@ func EnsureEmployeeForTenantUser(tu *models.SystemTenantUser) (*models.BackendEm
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
// 已存在 -> 只同步用户侧明确提供的基础资料;不覆盖部门、职位及其他员工专属字段。
|
||||
update := orm.Params{}
|
||||
if emp.Tid == nil || *emp.Tid <= 0 {
|
||||
// 历史无租户归属的员工记录:被当前租户用户明确匹配后,补上租户归属。
|
||||
update["tid"] = tid
|
||||
}
|
||||
if emp.DeleteTime != nil {
|
||||
@@ -145,7 +138,6 @@ func EnsureEmployeeForTenantUser(tu *models.SystemTenantUser) (*models.BackendEm
|
||||
return &emp, false, nil
|
||||
}
|
||||
|
||||
// SyncSelectedTenantUsersToEmployees 对指定租户用户进行比对;仅对缺失或基础资料有差异的员工执行写入。
|
||||
func SyncSelectedTenantUsersToEmployees(tid uint64, userIDs []uint64) (map[string]interface{}, error) {
|
||||
counts := map[string]interface{}{"created": 0, "updated": 0, "unchanged": 0, "failed": 0, "errors": []string{}}
|
||||
if tid == 0 || len(userIDs) == 0 {
|
||||
@@ -237,12 +229,11 @@ func tenantUserEmployeeDiffers(user *models.SystemTenantUser) bool {
|
||||
|
||||
func employeeStatusDiffers(employeeStatus, userStatus int8) bool {
|
||||
if employeeStatus == 2 {
|
||||
return false // 离职员工由人事管理维护,不通过用户同步自动复职
|
||||
return false
|
||||
}
|
||||
return employeeStatus != userStatus
|
||||
}
|
||||
|
||||
// SyncEmployeeOnUserUpdate 当用户在用户管理中被编辑时,同步修改对应员工
|
||||
func SyncEmployeeOnUserUpdate(tid uint64, oldAccount string, tu *models.SystemTenantUser) error {
|
||||
if tu == nil || tid == 0 {
|
||||
return nil
|
||||
@@ -262,7 +253,6 @@ func SyncEmployeeOnUserUpdate(tid uint64, oldAccount string, tu *models.SystemTe
|
||||
Filter("account", acc).
|
||||
One(&emp)
|
||||
if err != nil {
|
||||
// 员工不存在则自动创建
|
||||
_, _, err = EnsureEmployeeForTenantUser(tu)
|
||||
return err
|
||||
}
|
||||
@@ -311,7 +301,6 @@ func SyncEmployeeOnUserUpdate(tid uint64, oldAccount string, tu *models.SystemTe
|
||||
return nil
|
||||
}
|
||||
|
||||
// SyncEmployeeOnUserDelete 当租户用户被删除时,将员工置为离职状态(2)
|
||||
func SyncEmployeeOnUserDelete(tid uint64, account string) error {
|
||||
account = strings.TrimSpace(account)
|
||||
if tid == 0 || account == "" {
|
||||
@@ -322,13 +311,12 @@ func SyncEmployeeOnUserDelete(tid uint64, account string) error {
|
||||
Filter("account", account).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(orm.Params{
|
||||
"account_status": int8(2), // 2 = 离职
|
||||
"account_status": int8(2),
|
||||
"update_time": time.Now(),
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// SyncUserFromEmployee 当在人员管理中编辑了员工的基本信息时,同步回用户表
|
||||
func SyncUserFromEmployee(tid uint64, emp *models.BackendEmployee) error {
|
||||
if emp == nil || tid == 0 {
|
||||
return nil
|
||||
@@ -361,7 +349,6 @@ func SyncUserFromEmployee(tid uint64, emp *models.BackendEmployee) error {
|
||||
update["org_id"] = orgId
|
||||
}
|
||||
}
|
||||
// 员工状态 1: 启用 -> 用户 1; 员工状态 0: 禁用 / 2: 离职 -> 用户 0 (禁用登录)
|
||||
if emp.AccountStatus == 1 {
|
||||
update["status"] = int8(1)
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user