|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private UserSv sv; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${user.defaultTrueRandomFalsePassword:true}") | 
|---|
|  |  |  | private Boolean defaultTrueRandomFalsePassword; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${user.defaultPassword:ABC123}") | 
|---|
|  |  |  | private String defaultPassword; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private void setSv(UserSv sv) { | 
|---|
|  |  |  | this.sv = sv; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 客户端请求得到默认密码 | 
|---|
|  |  |  | * @return 默认密码 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得默认密码", description = "获得默认密码") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回默认密码(BaseResponse.content:password)", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = String.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "defaultPassword") | 
|---|
|  |  |  | public BaseResponse<String> defaultPassword(){ | 
|---|
|  |  |  | if(defaultTrueRandomFalsePassword){ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(defaultPassword) ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | String password = this.sv.getStringRandom(6) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(password) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 重置密码 | 
|---|
|  |  |  | * @param vo form表单对象 | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "重置密码", description = "提交数据(form表单json数据),进行密码重置") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "操作结果:true:成功,false:失败(BaseResponse.content)", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = Boolean.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "resetPassword", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop("-1")//@SsoAop(power = "-1") | 
|---|
|  |  |  | public BaseResponse<Boolean> resetPassword(@RequestBody @Parameter(description = "form表单json数据", required = true) ResetPasswordVo vo) throws Exception { | 
|---|
|  |  |  | if (vo.id == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("id不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String password = MD5.encrypt(vo.password);//进行加密码 | 
|---|
|  |  |  | Long idLg = Long.parseLong(vo.id); | 
|---|
|  |  |  | int count; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | BaUser po = this.sv.selectById(idLg); | 
|---|
|  |  |  | if (Objects.isNull(po)) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("未得到用户,请求失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | count = this.sv.changePassword(idLg, password); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("保存用户异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (count <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail("数据库存储失败"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | * 重置密码为默认值 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 用户ID | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Operation(summary = "重置密码为默认密码", description = "提交用户ID") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | * 重置密码为随机数字加字母 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id 用户ID | 
|---|
|  |  |  | * @return 是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Operation(summary = "重置密码为随机数字加字母", description = "提交用户ID") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(randomPassword); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | * 2023-12-05 在 save和update方法中进行了角色设置关联,本方法废弃 | 
|---|