refactor: 代码生成支持js,已知问题修复
This commit is contained in:
@@ -28,7 +28,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "08.系统配置")
|
||||
@Tag(name = "07.系统配置")
|
||||
@RequestMapping("/api/v1/configs")
|
||||
public class ConfigController {
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
* @author Ray.Hao
|
||||
* @since 2.10.0
|
||||
*/
|
||||
@Tag(name = "10.日志接口")
|
||||
@Tag(name = "09.日志接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/logs")
|
||||
@RequiredArgsConstructor
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
* @author youlaitech
|
||||
* @since 2024-08-27 10:31
|
||||
*/
|
||||
@Tag(name = "09.通知公告")
|
||||
@Tag(name = "08.通知公告")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/notices")
|
||||
@RequiredArgsConstructor
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.time.LocalDate;
|
||||
* @author Ray.Hao
|
||||
* @since 2025-12-15
|
||||
*/
|
||||
@Tag(name = "11.统计分析")
|
||||
@Tag(name = "12.统计分析")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/statistics")
|
||||
@RequiredArgsConstructor
|
||||
|
||||
@@ -125,6 +125,17 @@ public class UserController {
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "重置指定用户密码")
|
||||
@PutMapping(value = "/{userId}/password/reset")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:reset-password')")
|
||||
public Result<?> resetUserPassword(
|
||||
@Parameter(description = "用户ID") @PathVariable Long userId,
|
||||
@RequestParam String password
|
||||
) {
|
||||
boolean result = userService.resetUserPassword(userId, password);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取当前登录用户信息")
|
||||
@GetMapping("/me")
|
||||
@Log(value = "获取当前登录用户信息", module = LogModuleEnum.USER)
|
||||
@@ -176,6 +187,13 @@ public class UserController {
|
||||
.doWrite(exportUserList);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户下拉选项")
|
||||
@GetMapping("/options")
|
||||
public Result<List<Option<String>>> listUserOptions() {
|
||||
List<Option<String>> list = userService.listUserOptions();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取个人中心用户信息")
|
||||
@GetMapping("/profile")
|
||||
@Log(value = "获取个人中心用户信息", module = LogModuleEnum.USER)
|
||||
@@ -193,16 +211,6 @@ public class UserController {
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "重置指定用户密码")
|
||||
@PutMapping(value = "/{userId}/password/reset")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:reset-password')")
|
||||
public Result<?> resetUserPassword(
|
||||
@Parameter(description = "用户ID") @PathVariable Long userId,
|
||||
@RequestParam String password
|
||||
) {
|
||||
boolean result = userService.resetUserPassword(userId, password);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "当前用户修改密码")
|
||||
@PutMapping(value = "/password")
|
||||
@@ -232,6 +240,15 @@ public class UserController {
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "解绑手机号")
|
||||
@DeleteMapping(value = "/mobile")
|
||||
public Result<?> unbindMobile(
|
||||
@RequestBody @Validated PasswordVerifyForm data
|
||||
) {
|
||||
boolean result = userService.unbindMobile(data);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "发送邮箱验证码(绑定或更换邮箱)")
|
||||
@PostMapping(value = "/email/code")
|
||||
public Result<Void> sendEmailCode(
|
||||
@@ -250,10 +267,14 @@ public class UserController {
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户下拉选项")
|
||||
@GetMapping("/options")
|
||||
public Result<List<Option<String>>> listUserOptions() {
|
||||
List<Option<String>> list = userService.listUserOptions();
|
||||
return Result.success(list);
|
||||
@Operation(summary = "解绑邮箱")
|
||||
@DeleteMapping(value = "/email")
|
||||
public Result<?> unbindEmail(
|
||||
@RequestBody @Validated PasswordVerifyForm data
|
||||
) {
|
||||
boolean result = userService.unbindEmail(data);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.youlai.boot.system.model.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -16,10 +17,15 @@ public class EmailUpdateForm {
|
||||
|
||||
@Schema(description = "邮箱")
|
||||
@NotBlank(message = "邮箱不能为空")
|
||||
@Email(message = "邮箱格式不正确")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "验证码")
|
||||
@NotBlank(message = "验证码不能为空")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "当前密码")
|
||||
@NotBlank(message = "当前密码不能为空")
|
||||
private String password;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.youlai.boot.system.model.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -16,10 +17,15 @@ public class MobileUpdateForm {
|
||||
|
||||
@Schema(description = "手机号码")
|
||||
@NotBlank(message = "手机号码不能为空")
|
||||
@Pattern(regexp = "^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$", message = "手机号码格式不正确")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "验证码")
|
||||
@NotBlank(message = "验证码不能为空")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "当前密码")
|
||||
@NotBlank(message = "当前密码不能为空")
|
||||
private String password;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.youlai.boot.system.model.form;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "密码校验表单")
|
||||
@Data
|
||||
public class PasswordVerifyForm {
|
||||
|
||||
@Schema(description = "当前密码")
|
||||
@NotBlank(message = "当前密码不能为空")
|
||||
private String password;
|
||||
}
|
||||
@@ -12,13 +12,6 @@ import lombok.Data;
|
||||
@Schema(description = "个人中心用户信息")
|
||||
@Data
|
||||
public class UserProfileForm {
|
||||
|
||||
@Schema(description = "用户ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "用户昵称")
|
||||
private String nickname;
|
||||
|
||||
@@ -28,11 +21,4 @@ public class UserProfileForm {
|
||||
@Schema(description = "性别")
|
||||
private Integer gender;
|
||||
|
||||
@Schema(description = "手机号")
|
||||
private String mobile;
|
||||
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -158,6 +158,22 @@ public interface UserService extends IService<User> {
|
||||
*/
|
||||
boolean bindOrChangeEmail(EmailUpdateForm data);
|
||||
|
||||
/**
|
||||
* 解绑手机号
|
||||
*
|
||||
* @param data 表单数据
|
||||
* @return {@link Boolean} 是否解绑成功
|
||||
*/
|
||||
boolean unbindMobile(PasswordVerifyForm data);
|
||||
|
||||
/**
|
||||
* 解绑邮箱
|
||||
*
|
||||
* @param data 表单数据
|
||||
* @return {@link Boolean} 是否解绑成功
|
||||
*/
|
||||
boolean unbindEmail(PasswordVerifyForm data);
|
||||
|
||||
/**
|
||||
* 获取用户选项列表
|
||||
*
|
||||
|
||||
@@ -491,9 +491,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
@Override
|
||||
public boolean updateUserProfile(UserProfileForm formData) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
User entity = userConverter.toEntity(formData);
|
||||
entity.setId(userId);
|
||||
return this.updateById(entity);
|
||||
|
||||
if (formData.getNickname() == null && formData.getAvatar() == null && formData.getGender() == null) {
|
||||
throw new BusinessException("请修改至少一个字段");
|
||||
}
|
||||
|
||||
return this.update(new LambdaUpdateWrapper<User>()
|
||||
.eq(User::getId, userId)
|
||||
.set(formData.getNickname() != null, User::getNickname, formData.getNickname())
|
||||
.set(formData.getAvatar() != null, User::getAvatar, formData.getAvatar())
|
||||
.set(formData.getGender() != null, User::getGender, formData.getGender())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -523,7 +531,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
}
|
||||
|
||||
// 判断新密码和确认密码是否一致
|
||||
if (passwordEncoder.matches(data.getNewPassword(), data.getConfirmPassword())) {
|
||||
if (!Objects.equals(data.getNewPassword(), data.getConfirmPassword())) {
|
||||
throw new BusinessException("新密码和确认密码不一致");
|
||||
}
|
||||
|
||||
@@ -569,6 +577,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
@Override
|
||||
public boolean sendMobileCode(String mobile) {
|
||||
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
long mobileCount = this.count(new LambdaQueryWrapper<User>()
|
||||
.eq(User::getMobile, mobile)
|
||||
.ne(User::getId, currentUserId)
|
||||
);
|
||||
if (mobileCount > 0) {
|
||||
throw new BusinessException("手机号已被其他账号绑定");
|
||||
}
|
||||
|
||||
// String code = String.valueOf((int) ((Math.random() * 9 + 1) * 1000));
|
||||
// TODO 为了方便测试,验证码固定为 1234,实际开发中在配置了厂商短信服务后,可以使用上面的随机验证码
|
||||
String code = "1234";
|
||||
@@ -600,6 +617,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
if (!passwordEncoder.matches(form.getPassword(), currentUser.getPassword())) {
|
||||
throw new BusinessException("当前密码错误");
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
String inputVerifyCode = form.getCode();
|
||||
String mobile = form.getMobile();
|
||||
@@ -614,7 +635,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
if (!inputVerifyCode.equals(cachedVerifyCode)) {
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
// 验证完成删除验证码
|
||||
|
||||
long mobileCount = this.count(new LambdaQueryWrapper<User>()
|
||||
.eq(User::getMobile, mobile)
|
||||
.ne(User::getId, currentUserId)
|
||||
);
|
||||
if (mobileCount > 0) {
|
||||
throw new BusinessException("手机号已被其他账号绑定");
|
||||
}
|
||||
|
||||
redisTemplate.delete(cacheKey);
|
||||
|
||||
// 更新手机号码
|
||||
@@ -633,6 +662,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
@Override
|
||||
public void sendEmailCode(String email) {
|
||||
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
long emailCount = this.count(new LambdaQueryWrapper<User>()
|
||||
.eq(User::getEmail, email)
|
||||
.ne(User::getId, currentUserId)
|
||||
);
|
||||
if (emailCount > 0) {
|
||||
throw new BusinessException("邮箱已被其他账号绑定");
|
||||
}
|
||||
|
||||
// String code = String.valueOf((int) ((Math.random() * 9 + 1) * 1000));
|
||||
// TODO 为了方便测试,验证码固定为 1234,实际开发中在配置了邮箱服务后,可以使用上面的随机验证码
|
||||
String code = "1234";
|
||||
@@ -659,6 +697,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
if (!passwordEncoder.matches(form.getPassword(), currentUser.getPassword())) {
|
||||
throw new BusinessException("当前密码错误");
|
||||
}
|
||||
|
||||
// 获取前端输入的验证码
|
||||
String inputVerifyCode = form.getCode();
|
||||
|
||||
@@ -674,7 +716,15 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
if (!inputVerifyCode.equals(cachedVerifyCode)) {
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
// 验证完成删除验证码
|
||||
|
||||
long emailCount = this.count(new LambdaQueryWrapper<User>()
|
||||
.eq(User::getEmail, email)
|
||||
.ne(User::getId, currentUserId)
|
||||
);
|
||||
if (emailCount > 0) {
|
||||
throw new BusinessException("邮箱已被其他账号绑定");
|
||||
}
|
||||
|
||||
redisTemplate.delete(redisCacheKey);
|
||||
|
||||
// 更新邮箱地址
|
||||
@@ -685,6 +735,66 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑手机号
|
||||
*
|
||||
* @param form 表单数据
|
||||
* @return true|false
|
||||
*/
|
||||
@Override
|
||||
public boolean unbindMobile(PasswordVerifyForm form) {
|
||||
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
User currentUser = this.getById(currentUserId);
|
||||
|
||||
if (currentUser == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(currentUser.getMobile())) {
|
||||
throw new BusinessException("当前账号未绑定手机号");
|
||||
}
|
||||
|
||||
if (!passwordEncoder.matches(form.getPassword(), currentUser.getPassword())) {
|
||||
throw new BusinessException("当前密码错误");
|
||||
}
|
||||
|
||||
return this.update(new LambdaUpdateWrapper<User>()
|
||||
.eq(User::getId, currentUserId)
|
||||
.set(User::getMobile, null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑邮箱
|
||||
*
|
||||
* @param form 表单数据
|
||||
* @return true|false
|
||||
*/
|
||||
@Override
|
||||
public boolean unbindEmail(PasswordVerifyForm form) {
|
||||
|
||||
Long currentUserId = SecurityUtils.getUserId();
|
||||
User currentUser = this.getById(currentUserId);
|
||||
|
||||
if (currentUser == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(currentUser.getEmail())) {
|
||||
throw new BusinessException("当前账号未绑定邮箱");
|
||||
}
|
||||
|
||||
if (!passwordEncoder.matches(form.getPassword(), currentUser.getPassword())) {
|
||||
throw new BusinessException("当前密码错误");
|
||||
}
|
||||
|
||||
return this.update(new LambdaUpdateWrapper<User>()
|
||||
.eq(User::getId, currentUserId)
|
||||
.set(User::getEmail, null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户选项列表
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user