update 优化修改用户信息

2.X
AprilWind 8 months ago
parent cc6871288a
commit c12c201912

@ -10,6 +10,7 @@ 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;
@ -61,12 +62,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(@Validated @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 + "'失败,手机号码已存在");
@ -74,7 +77,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();
} }
@ -86,6 +88,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")
@ -110,6 +113,7 @@ public class SysProfileController extends BaseController {
* *
* @param avatarfile * @param avatarfile
*/ */
@RepeatSubmit
@GlobalTransactional(rollbackFor = Exception.class) @GlobalTransactional(rollbackFor = Exception.class)
@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)

@ -1,16 +1,17 @@
package org.dromara.system.domain.bo; package org.dromara.system.domain.bo;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Pattern;
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.mybatis.core.domain.BaseEntity; import org.dromara.common.core.constant.RegexConstants;
import org.dromara.common.core.xss.Xss; 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.annotation.Sensitive;
import org.dromara.common.sensitive.core.SensitiveStrategy; import org.dromara.common.sensitive.core.SensitiveStrategy;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Size;
/** /**
* *
* *
@ -22,11 +23,6 @@ import jakarta.validation.constraints.Size;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class SysUserProfileBo extends BaseEntity { public class SysUserProfileBo extends BaseEntity {
/**
* ID
*/
private Long userId;
/** /**
* *
*/ */
@ -46,6 +42,7 @@ public class SysUserProfileBo extends BaseEntity {
* *
*/ */
@Sensitive(strategy = SensitiveStrategy.PHONE) @Sensitive(strategy = SensitiveStrategy.PHONE)
@Pattern(regexp = RegexConstants.MOBILE, message = "手机号格式不正确")
private String phonenumber; private String phonenumber;
/** /**

Loading…
Cancel
Save