refactor: 代码优化
This commit is contained in:
@@ -46,7 +46,7 @@ public class DictController {
|
||||
return PageResult.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "字典列表")
|
||||
@Operation(summary = "所有字典列表")
|
||||
@GetMapping("/list")
|
||||
public Result<List<DictVO>> getAllDictWithData() {
|
||||
List<DictVO> list = dictService.getAllDictWithData();
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.List;
|
||||
* @author Ray
|
||||
* @since 2.10.0
|
||||
*/
|
||||
@Tag(name = "09.日志接口")
|
||||
@Tag(name = "13.日志接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/logs")
|
||||
@RequiredArgsConstructor
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 10:31
|
||||
*/
|
||||
@Tag(name = "通知公告接口")
|
||||
@Tag(name = "12.通知公告接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/notices")
|
||||
@RequiredArgsConstructor
|
||||
|
||||
@@ -91,7 +91,8 @@ public class UserController {
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:edit')")
|
||||
public Result<Void> updateUser(
|
||||
@Parameter(description = "用户ID") @PathVariable Long userId,
|
||||
@RequestBody @Valid UserForm userForm) {
|
||||
@RequestBody @Valid UserForm userForm
|
||||
) {
|
||||
boolean result = userService.updateUser(userId, userForm);
|
||||
return Result.judge(result);
|
||||
}
|
||||
@@ -170,7 +171,7 @@ public class UserController {
|
||||
return Result.success(userProfile);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改个人中心用户信息")
|
||||
@Operation(summary = "个人中心修改用户信息")
|
||||
@PutMapping("/profile")
|
||||
public Result<?> updateUserProfile(@RequestBody UserProfileForm formData) {
|
||||
boolean result = userService.updateUserProfile(formData);
|
||||
@@ -208,7 +209,7 @@ public class UserController {
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "绑定个人中心用户手机号")
|
||||
@Operation(summary = "个人中心绑定用户手机号")
|
||||
@PutMapping(value = "/mobile")
|
||||
public Result<?> bindMobile(
|
||||
@RequestBody @Validated MobileBindingForm data
|
||||
@@ -218,16 +219,15 @@ public class UserController {
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "绑定个人中心用户邮箱")
|
||||
@Operation(summary = "个人中心绑定用户邮箱")
|
||||
@PutMapping(value = "/email")
|
||||
public Result<?> bindEmail(
|
||||
@RequestBody @Validated EmailChangeForm data
|
||||
@RequestBody @Validated EmailBindingForm data
|
||||
) {
|
||||
boolean result = userService.bindEmail(data);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "用户下拉选项")
|
||||
@GetMapping("/options")
|
||||
public Result<List<Option<String>>> listUserOptions() {
|
||||
|
||||
@@ -4,16 +4,16 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 修改邮箱表单
|
||||
* 绑定邮箱表单
|
||||
*
|
||||
* @author Ray
|
||||
* @author Ray.Hao
|
||||
* @since 2024/8/19
|
||||
*/
|
||||
@Schema(description = "修改邮箱表单")
|
||||
@Schema(description = "绑定邮箱表单")
|
||||
@Data
|
||||
public class EmailChangeForm {
|
||||
public class EmailBindingForm {
|
||||
|
||||
@Schema(description = "原密码")
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "验证码")
|
||||
@@ -4,16 +4,16 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 修改手机表单
|
||||
* 绑定手机表单
|
||||
*
|
||||
* @author Ray
|
||||
* @since 2024/8/19
|
||||
*/
|
||||
@Schema(description = "修改手机表单")
|
||||
@Schema(description = "绑定手机表单")
|
||||
@Data
|
||||
public class MobileBindingForm {
|
||||
|
||||
@Schema(description = "原密码")
|
||||
@Schema(description = "手机号码")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "验证码")
|
||||
|
||||
@@ -150,7 +150,7 @@ public interface UserService extends IService<User> {
|
||||
* @param data 表单数据
|
||||
* @return {@link Boolean} 是否绑定成功
|
||||
*/
|
||||
boolean bindEmail(EmailChangeForm data);
|
||||
boolean bindEmail(EmailBindingForm data);
|
||||
|
||||
/**
|
||||
* 获取用户选项列表
|
||||
|
||||
@@ -379,56 +379,68 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
/**
|
||||
* 修改当前用户手机号码
|
||||
*
|
||||
* @param data 表单数据
|
||||
* @param form 表单数据
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean bindMobile(MobileBindingForm data) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
User user = this.getById(userId);
|
||||
if (user == null) {
|
||||
public boolean bindMobile(MobileBindingForm form) {
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
User currentUser = this.getById(currentUserId);
|
||||
|
||||
if (currentUser == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
String verificationCode = data.getCode();
|
||||
String contact = data.getMobile();
|
||||
String verificationCodeKey = RedisConstants.MOBILE_VERIFICATION_CODE_PREFIX + contact;
|
||||
String code = redisTemplate.opsForValue().get(verificationCodeKey);
|
||||
if (!verificationCode.equals(code)) {
|
||||
String inputVerificationCode = form.getCode();
|
||||
String mobile = form.getMobile();
|
||||
|
||||
String redisCacheKey = RedisConstants.MOBILE_VERIFICATION_CODE_PREFIX + mobile;
|
||||
String cachedVerificationCode = redisTemplate.opsForValue().get(redisCacheKey);
|
||||
|
||||
if (!inputVerificationCode.equals(cachedVerificationCode)) {
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
|
||||
// 更新手机号码
|
||||
return this.update(new LambdaUpdateWrapper<User>()
|
||||
.eq(User::getId, userId)
|
||||
.set(User::getMobile, contact)
|
||||
return this.update(
|
||||
new LambdaUpdateWrapper<User>()
|
||||
.eq(User::getId, currentUserId)
|
||||
.set(User::getMobile, mobile)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改当前用户邮箱
|
||||
*
|
||||
* @param data 表单数据
|
||||
* @param form 表单数据
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean bindEmail(EmailChangeForm data) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
User user = this.getById(userId);
|
||||
if (user == null) {
|
||||
public boolean bindEmail(EmailBindingForm form) {
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
|
||||
User currentUser = this.getById(currentUserId);
|
||||
if (currentUser == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
String verificationCode = data.getCode();
|
||||
String email = data.getEmail();
|
||||
String verificationCodeKey = RedisConstants.EMAIL_VERIFICATION_CODE_PREFIX + email;
|
||||
String code = redisTemplate.opsForValue().get(verificationCodeKey);
|
||||
if (!verificationCode.equals(code)) {
|
||||
String inputVerificationCode = form.getCode();
|
||||
String email = form.getEmail();
|
||||
|
||||
String redisCacheKey = RedisConstants.EMAIL_VERIFICATION_CODE_PREFIX + email;
|
||||
String cachedVerificationCode = redisTemplate.opsForValue().get(redisCacheKey);
|
||||
|
||||
if (cachedVerificationCode == null || !inputVerificationCode.equals(cachedVerificationCode)) {
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
// 更新邮箱
|
||||
return this.update(new LambdaUpdateWrapper<User>()
|
||||
.eq(User::getId, userId)
|
||||
.set(User::getEmail, email)
|
||||
|
||||
// 更新邮箱地址
|
||||
return this.update(
|
||||
new LambdaUpdateWrapper<User>()
|
||||
.eq(User::getId, currentUserId)
|
||||
.set(User::getEmail, email)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user