update 优化修改用户信息
This commit is contained in:
parent
a3f43f8ea3
commit
dd6d4c67ed
@ -3,10 +3,12 @@ package org.dromara.system.controller.system;
|
|||||||
import cn.dev33.satoken.secure.BCrypt;
|
import cn.dev33.satoken.secure.BCrypt;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.dromara.common.core.domain.R;
|
import org.dromara.common.core.domain.R;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.core.utils.file.MimeTypeUtils;
|
import org.dromara.common.core.utils.file.MimeTypeUtils;
|
||||||
import org.dromara.common.encrypt.annotation.ApiEncrypt;
|
import org.dromara.common.encrypt.annotation.ApiEncrypt;
|
||||||
|
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
||||||
import org.dromara.common.log.annotation.Log;
|
import org.dromara.common.log.annotation.Log;
|
||||||
import org.dromara.common.log.enums.BusinessType;
|
import org.dromara.common.log.enums.BusinessType;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
@ -19,9 +21,7 @@ import org.dromara.system.domain.vo.ProfileVo;
|
|||||||
import org.dromara.system.domain.vo.SysOssVo;
|
import org.dromara.system.domain.vo.SysOssVo;
|
||||||
import org.dromara.system.domain.vo.SysUserVo;
|
import org.dromara.system.domain.vo.SysUserVo;
|
||||||
import org.dromara.system.service.ISysOssService;
|
import org.dromara.system.service.ISysOssService;
|
||||||
import org.dromara.system.service.ISysRoleService;
|
|
||||||
import org.dromara.system.service.ISysUserService;
|
import org.dromara.system.service.ISysUserService;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -57,12 +57,14 @@ public class SysProfileController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用户
|
* 修改用户信息
|
||||||
*/
|
*/
|
||||||
|
@RepeatSubmit
|
||||||
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public R<Void> updateProfile(@RequestBody SysUserProfileBo profile) {
|
public R<Void> updateProfile(@RequestBody SysUserProfileBo profile) {
|
||||||
SysUserBo user = BeanUtil.toBean(profile, SysUserBo.class);
|
SysUserBo user = BeanUtil.toBean(profile, SysUserBo.class);
|
||||||
|
user.setUserId(LoginHelper.getUserId());
|
||||||
String username = LoginHelper.getUsername();
|
String username = LoginHelper.getUsername();
|
||||||
if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
|
||||||
return R.fail("修改用户'" + username + "'失败,手机号码已存在");
|
return R.fail("修改用户'" + username + "'失败,手机号码已存在");
|
||||||
@ -70,7 +72,6 @@ public class SysProfileController extends BaseController {
|
|||||||
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
||||||
return R.fail("修改用户'" + username + "'失败,邮箱账号已存在");
|
return R.fail("修改用户'" + username + "'失败,邮箱账号已存在");
|
||||||
}
|
}
|
||||||
user.setUserId(LoginHelper.getUserId());
|
|
||||||
if (userService.updateUserProfile(user) > 0) {
|
if (userService.updateUserProfile(user) > 0) {
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
@ -82,6 +83,7 @@ public class SysProfileController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param bo 新旧密码
|
* @param bo 新旧密码
|
||||||
*/
|
*/
|
||||||
|
@RepeatSubmit
|
||||||
@ApiEncrypt
|
@ApiEncrypt
|
||||||
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping("/updatePwd")
|
@PutMapping("/updatePwd")
|
||||||
@ -106,6 +108,7 @@ public class SysProfileController extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param avatarfile 用户头像
|
* @param avatarfile 用户头像
|
||||||
*/
|
*/
|
||||||
|
@RepeatSubmit
|
||||||
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
||||||
@PostMapping(value = "/avatar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping(value = "/avatar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
public R<AvatarVo> avatar(@RequestPart("avatarfile") MultipartFile avatarfile) {
|
public R<AvatarVo> avatar(@RequestPart("avatarfile") MultipartFile avatarfile) {
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package org.dromara.system.domain.bo;
|
package org.dromara.system.domain.bo;
|
||||||
|
|
||||||
import org.dromara.common.core.xss.Xss;
|
|
||||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
|
||||||
import org.dromara.common.sensitive.annotation.Sensitive;
|
|
||||||
import org.dromara.common.sensitive.core.SensitiveStrategy;
|
|
||||||
import jakarta.validation.constraints.Email;
|
import jakarta.validation.constraints.Email;
|
||||||
|
import jakarta.validation.constraints.Pattern;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.dromara.common.core.constant.RegexConstants;
|
||||||
|
import org.dromara.common.core.xss.Xss;
|
||||||
|
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||||
|
import org.dromara.common.sensitive.annotation.Sensitive;
|
||||||
|
import org.dromara.common.sensitive.core.SensitiveStrategy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 个人信息业务处理
|
* 个人信息业务处理
|
||||||
@ -21,11 +23,6 @@ import lombok.NoArgsConstructor;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class SysUserProfileBo extends BaseEntity {
|
public class SysUserProfileBo extends BaseEntity {
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户ID
|
|
||||||
*/
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户昵称
|
* 用户昵称
|
||||||
*/
|
*/
|
||||||
@ -44,6 +41,7 @@ public class SysUserProfileBo extends BaseEntity {
|
|||||||
/**
|
/**
|
||||||
* 手机号码
|
* 手机号码
|
||||||
*/
|
*/
|
||||||
|
@Pattern(regexp = RegexConstants.MOBILE, message = "手机号格式不正确")
|
||||||
@Sensitive(strategy = SensitiveStrategy.PHONE)
|
@Sensitive(strategy = SensitiveStrategy.PHONE)
|
||||||
private String phonenumber;
|
private String phonenumber;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user