From c3f2e428aca9450637c5390261381dc432600cea Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Mon, 26 Jan 2026 16:09:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=96=B0=E5=A2=9E=E9=87=8D?= =?UTF-8?q?=E7=BD=AE=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/api/AppUserAccountClientApi.java | 7 +++ .../cmd/user/account/ResetPasswordCmd.java | 20 +++++++ .../app/user/UserAuthTypeRestController.java | 18 +++++++ .../account/AppUserAccountClientEndpoint.java | 13 +++-- .../user/user/UserAccountClientService.java | 6 +++ .../impl/UserAccountClientServiceImpl.java | 52 +++++++++++++++++++ 6 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/user/account/ResetPasswordCmd.java diff --git a/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/AppUserAccountClientApi.java b/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/AppUserAccountClientApi.java index 4078eee9..3c063b2d 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/AppUserAccountClientApi.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-api/src/main/java/com/red/circle/other/inner/endpoint/user/user/api/AppUserAccountClientApi.java @@ -10,6 +10,7 @@ import com.red.circle.other.inner.model.cmd.user.account.AccountLoginCmd; import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd; import com.red.circle.other.inner.model.cmd.user.account.MobileCredentialCmd; import com.red.circle.other.inner.model.cmd.user.account.PunishmentAccountCmd; +import com.red.circle.other.inner.model.cmd.user.account.ResetPasswordCmd; import com.red.circle.other.inner.model.cmd.user.account.UnblockAccountCmd; import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO; import com.red.circle.other.inner.model.dto.user.account.MobileAuthDTO; @@ -124,4 +125,10 @@ public interface AppUserAccountClientApi { @GetMapping(value = "/lastApprovalUserAccountStatusLog") ResultResponse> lastApprovalUserAccountStatusLog( @RequestParam("beApprovalUser") Long beApprovalUser, @RequestParam("size") Integer size); + + /** + * 重置密码. + */ + @PostMapping(value = "/resetPassword") + ResultResponse resetPassword(@RequestBody @Validated ResetPasswordCmd cmd); } diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/user/account/ResetPasswordCmd.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/user/account/ResetPasswordCmd.java new file mode 100644 index 00000000..629c53cd --- /dev/null +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/cmd/user/account/ResetPasswordCmd.java @@ -0,0 +1,20 @@ +package com.red.circle.other.inner.model.cmd.user.account; + +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 重置密码命令 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class ResetPasswordCmd extends AppExtCommand { + + /** + * 用户ID + */ + @NotNull(message = "用户ID不能为空") + private Long userId; +} diff --git a/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/UserAuthTypeRestController.java b/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/UserAuthTypeRestController.java index e928e5d8..337bd596 100644 --- a/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/UserAuthTypeRestController.java +++ b/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/UserAuthTypeRestController.java @@ -7,6 +7,8 @@ import com.red.circle.console.app.service.app.user.UserAuthTypeService; import com.red.circle.console.infra.annotations.OpsOperationReqLog; import com.red.circle.framework.core.security.UserCredential; import com.red.circle.framework.web.controller.BaseController; +import com.red.circle.other.inner.endpoint.user.user.AppUserAccountClient; +import com.red.circle.other.inner.model.cmd.user.account.ResetPasswordCmd; import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO; import com.red.circle.other.inner.model.dto.user.account.UserMobileUpdateCmd; import lombok.RequiredArgsConstructor; @@ -34,6 +36,7 @@ import org.springframework.web.bind.annotation.RestController; public class UserAuthTypeRestController extends BaseController { private final UserAuthTypeService userAuthTypeService; + private final AppUserAccountClient appUserAccountClient; /** * 获取注册信息. @@ -97,6 +100,21 @@ public class UserAuthTypeRestController extends BaseController { userAuthTypeService.initUserAccountLogin(userId); } + + /** + * 重置用户密码为默认密码 + * + * @eo.name 重置用户密码 + * @eo.url /account/resetPassword + * @eo.method post + * @eo.request-type json + */ + @OpsOperationReqLog("重置用户密码") + @PostMapping("/account/resetPassword") + public void resetPassword(@RequestBody @Validated ResetPasswordCmd cmd) { + appUserAccountClient.resetPassword(cmd); + } + /** * 删除用户账号密码登录信息. */ diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/account/AppUserAccountClientEndpoint.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/account/AppUserAccountClientEndpoint.java index bd4523e6..64c51586 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/account/AppUserAccountClientEndpoint.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/endpoint/user/account/AppUserAccountClientEndpoint.java @@ -8,11 +8,7 @@ import com.red.circle.other.infra.annotation.CreateAccount; import com.red.circle.other.inner.endpoint.user.user.api.AppUserAccountClientApi; import com.red.circle.other.inner.model.cmd.user.ApprovalUserAccountStatusLogCmd; import com.red.circle.other.inner.model.cmd.user.UserChannelCredentialCmd; -import com.red.circle.other.inner.model.cmd.user.account.AccountLoginCmd; -import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd; -import com.red.circle.other.inner.model.cmd.user.account.MobileCredentialCmd; -import com.red.circle.other.inner.model.cmd.user.account.PunishmentAccountCmd; -import com.red.circle.other.inner.model.cmd.user.account.UnblockAccountCmd; +import com.red.circle.other.inner.model.cmd.user.account.*; import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO; import com.red.circle.other.inner.model.dto.user.account.MobileAuthDTO; import com.red.circle.other.inner.model.dto.user.account.UserAccountDTO; @@ -174,4 +170,11 @@ public class AppUserAccountClientEndpoint implements AppUserAccountClientApi { return ResultResponse.success( userAccountClientService.lastApprovalUserAccountStatusLog(beApprovalUser, size)); } + + @Override + public ResultResponse resetPassword(ResetPasswordCmd cmd) { + userAccountClientService.resetPassword(cmd); + return ResultResponse.success(); + } + } diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserAccountClientService.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserAccountClientService.java index 32b63a06..2f909d6c 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserAccountClientService.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/UserAccountClientService.java @@ -7,6 +7,7 @@ import com.red.circle.other.inner.model.cmd.user.account.AccountLoginCmd; import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd; import com.red.circle.other.inner.model.cmd.user.account.MobileCredentialCmd; import com.red.circle.other.inner.model.cmd.user.account.PunishmentAccountCmd; +import com.red.circle.other.inner.model.cmd.user.account.ResetPasswordCmd; import com.red.circle.other.inner.model.cmd.user.account.UnblockAccountCmd; import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO; import com.red.circle.other.inner.model.dto.user.account.MobileAuthDTO; @@ -96,4 +97,9 @@ public interface UserAccountClientService { PageResult pgeApprovalUserAccountStatusLog(UserAccountStatusLogQryCmd cmd); List lastApprovalUserAccountStatusLog(Long beApprovalUser, Integer size); + + /** + * 重置密码 + */ + void resetPassword(ResetPasswordCmd cmd); } diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserAccountClientServiceImpl.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserAccountClientServiceImpl.java index 47a6a492..23e00148 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserAccountClientServiceImpl.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserAccountClientServiceImpl.java @@ -31,6 +31,7 @@ import com.red.circle.other.infra.database.rds.entity.user.user.ApprovalUserAcco import com.red.circle.other.infra.database.rds.entity.user.user.AuthType; import com.red.circle.other.infra.database.rds.entity.user.user.BaseInfo; import com.red.circle.other.infra.database.rds.entity.user.user.LogoutRecord; +import com.red.circle.other.infra.database.rds.entity.user.user.PasswordLog; import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService; import com.red.circle.other.infra.database.rds.service.user.device.ArchiveDeviceService; import com.red.circle.other.infra.database.rds.service.user.device.LatestMobileDeviceService; @@ -40,6 +41,7 @@ import com.red.circle.other.infra.database.rds.service.user.user.AuthTypeService import com.red.circle.other.infra.database.rds.service.user.user.BaseInfoService; import com.red.circle.other.infra.database.rds.service.user.user.LogoutRecordService; import com.red.circle.other.infra.database.rds.service.user.user.MobileAuthService; +import com.red.circle.other.infra.database.rds.service.user.user.PasswordLogService; import com.red.circle.other.inner.asserts.user.UserErrorCode; import com.red.circle.other.inner.enums.user.AuthTypeEnum; import com.red.circle.other.inner.model.cmd.user.UserChannelCredentialCmd; @@ -47,6 +49,7 @@ import com.red.circle.other.inner.model.cmd.user.account.AccountLoginCmd; import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd; import com.red.circle.other.inner.model.cmd.user.account.MobileCredentialCmd; import com.red.circle.other.inner.model.cmd.user.account.PunishmentAccountCmd; +import com.red.circle.other.inner.model.cmd.user.account.ResetPasswordCmd; import com.red.circle.other.inner.model.cmd.user.account.UnblockAccountCmd; import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO; import com.red.circle.other.inner.model.dto.user.account.MobileAuthDTO; @@ -98,6 +101,7 @@ public class UserAccountClientServiceImpl implements UserAccountClientService { private final UserAccountAuthCacheService accountAuthCacheService; private final UserAccountAuthCacheService userAccountAuthCacheService; private final ApprovalUserAccountStatusLogService approvalUserAccountStatusLogService; + private final PasswordLogService passwordLogService; @Override public UserAccountDTO create(CreateAccountCmd cmd) { @@ -431,4 +435,52 @@ public class UserAccountClientServiceImpl implements UserAccountClientService { private String requestUserSign(Long userId) { return ResponseAssert.requiredSuccess(imAccountClient.createUserSig(userId)); } + + @Override + public void resetPassword(ResetPasswordCmd cmd) { + Long userId = cmd.getUserId(); + String newPassword = "123456"; + + // 验证用户是否存在 + UserProfile userProfile = userProfileGateway.getByUserId(userId); + ResponseAssert.notNull(UserErrorCode.USER_INFO_NOT_FOUND, userProfile); + + // 获取旧的账号认证信息 + AccountAuth oldAccountAuth = accountAuthService.getByUserId(userId); + + // 如果存在旧密码,删除旧的认证信息 + if (Objects.nonNull(oldAccountAuth)) { + accountAuthService.deleteById(oldAccountAuth.getId()); + authTypeService.deleteAuthType(userId, AuthTypeEnum.ACCOUNT.name()); + } + + // 保存新密码 + accountAuthService.saveAccountAuth(new AccountAuth() + .setUserId(userId) + .setPwd(newPassword) + .setDel(Boolean.FALSE)); + + // 保存认证类型 + AuthType authType = new AuthType(); + authType.setUserId(userId); + authType.setType(AuthTypeEnum.ACCOUNT.name()); + authType.setOpenId(String.valueOf(userId)); + authType.setDel(Boolean.FALSE); + authTypeService.save(authType); + + // 记录密码修改日志 + passwordLogService.save(PasswordLog.builder() + .businessType("ACCOUNT_PASSWORD") + .operateType("RESET_PASSWORD") + .userId(userId) + .sysOrigin(userProfile.getOriginSys()) + .pwd(newPassword) + .imei(cmd.getReqImei()) + .build()); + + // 清除密码登录缓存 + accountAuthCacheService.deleteByUserId(userId); + + log.info("重置用户密码成功, userId: {}, newPassword: {}", userId, newPassword); + } }