|
|
@@ -86,6 +86,9 @@ type (
|
|
|
// - 调用方负责对 ids 去重并控制长度,空切片直接返回 nil;
|
|
|
// - session==nil 返回错误。
|
|
|
BatchIncrementTokenVersionWithTx(ctx context.Context, session sqlx.Session, ids []int64) error
|
|
|
+ // UpdateSelfInfo 更新用户自身安全字段(昵称/头像/邮箱/手机),不涉及 deptId/status/tokenVersion。
|
|
|
+ // username 仅用于构造缓存键失效。avatar 使用 sql.NullString 语义写入(空串置 NULL)。
|
|
|
+ UpdateSelfInfo(ctx context.Context, id int64, username string, nickname, avatar, email, phone string, expectedUpdateTime int64) error
|
|
|
}
|
|
|
|
|
|
customSysUserModel struct {
|
|
|
@@ -193,6 +196,30 @@ func (m *customSysUserModel) UpdateProfile(ctx context.Context, id int64, userna
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func (m *customSysUserModel) UpdateSelfInfo(ctx context.Context, id int64, username string, nickname, avatar, email, phone string, expectedUpdateTime int64) error {
|
|
|
+ sysUserIdKey := fmt.Sprintf("%s%v", cacheSysUserIdPrefix, id)
|
|
|
+ sysUserUsernameKey := fmt.Sprintf("%s%v", cacheSysUserUsernamePrefix, username)
|
|
|
+ now := time.Now().Unix()
|
|
|
+
|
|
|
+ var avatarVal sql.NullString
|
|
|
+ if avatar != "" {
|
|
|
+ avatarVal = sql.NullString{String: avatar, Valid: true}
|
|
|
+ }
|
|
|
+
|
|
|
+ res, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (sql.Result, error) {
|
|
|
+ query := fmt.Sprintf("UPDATE %s SET `nickname`=?, `avatar`=?, `email`=?, `phone`=?, `updateTime`=? WHERE `id`=? AND `updateTime`=?", m.table)
|
|
|
+ return conn.ExecCtx(ctx, query, nickname, avatarVal, email, phone, now, id, expectedUpdateTime)
|
|
|
+ }, sysUserIdKey, sysUserUsernameKey)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ affected, _ := res.RowsAffected()
|
|
|
+ if affected == 0 {
|
|
|
+ return ErrUpdateConflict
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
// UpdateProfileWithTx 见接口注释(审计 M-R11-3 + L-R12-1)。
|
|
|
// 实现上**绕过** m.ExecCtx 的 pre-commit DelCache 语义——仅调用 session.ExecCtx,缓存失效由
|
|
|
// 调用方在事务 commit 成功后显式走 InvalidateProfileCache。
|