feat: 修复修改个人信息时会清空手机邮箱问题 & 优化用户提醒

development
Parker 3 months ago
parent 7eef6ae9c6
commit 79a1fe2964

@ -15,21 +15,18 @@
*/ */
package org.opsli.api.wrapper.system.user; package org.opsli.api.wrapper.system.user;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.opsli.api.base.warpper.ApiWrapper; import org.opsli.api.base.warpper.ApiWrapper;
import org.opsli.common.annotation.validator.Validator; import org.opsli.common.annotation.validator.Validator;
import org.opsli.common.annotation.validator.ValidatorLenMax; import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.annotation.validator.ValidatorLenMin;
import org.opsli.common.enums.ValidatorType; import org.opsli.common.enums.ValidatorType;
import org.opsli.plugins.excel.annotation.ExcelInfo; import org.opsli.plugins.excel.annotation.ExcelInfo;
/** /**
* * -
* *
* @author Pace * @author Pace
* @date 2020-09-16 17:33 * @date 2020-09-16 17:33
@ -38,33 +35,6 @@ import org.opsli.plugins.excel.annotation.ExcelInfo;
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class UserSelfSaveModel extends ApiWrapper { public class UserSelfSaveModel extends ApiWrapper {
/** 登录账户 */
@Schema(description = "登录账户")
@ExcelIgnore
@Validator({ValidatorType.IS_NOT_NULL, ValidatorType.IS_GENERAL})
@ValidatorLenMax(32)
@ValidatorLenMin(4)
private String username;
/** 登录密码 */
@Schema(description = "登录密码")
@ExcelIgnore
@ValidatorLenMin(6)
@ValidatorLenMax(50)
private String password;
/** 登录密码强度 */
@Schema(description = "登录密码强度")
@ExcelIgnore
@ValidatorLenMin(1)
@ValidatorLenMax(1)
private String passwordLevel;
/** 是否启用 */
@Schema(description = "是否启用")
@ExcelIgnore
@ValidatorLenMax(1)
private String enable;
/** 真实姓名 */ /** 真实姓名 */
@Schema(description = "真实姓名") @Schema(description = "真实姓名")
@ -74,45 +44,6 @@ public class UserSelfSaveModel extends ApiWrapper {
@ValidatorLenMax(50) @ValidatorLenMax(50)
private String realName; private String realName;
/** 手机 */
@Schema(description = "手机")
@ExcelProperty(value = "手机", order = 2)
@ExcelInfo
private String mobile;
/** 邮箱 */
@Schema(description = "邮箱")
@ExcelProperty(value = "邮箱", order = 3)
@ExcelInfo
private String email;
/** 工号 */
@Schema(description = "工号")
@ExcelProperty(value = "工号", order = 4)
@ExcelInfo
@Validator({ValidatorType.IS_GENERAL})
@ValidatorLenMax(32)
private String no;
/** 头像 */
@Schema(description = "头像")
@ExcelIgnore
@ValidatorLenMax(255)
private String avatar;
/** 最后登陆IP */
@Schema(description = "最后登陆IP")
@ExcelIgnore
@Validator(ValidatorType.IS_IPV4)
private String loginIp;
/** 备注 */
@Schema(description = "备注")
@ExcelProperty(value = "备注", order = 5)
@ExcelInfo
@ValidatorLenMax(255)
private String remark;
/** 签名 */ /** 签名 */
@Schema(description = "签名") @Schema(description = "签名")
@ExcelProperty(value = "签名", order = 5) @ExcelProperty(value = "签名", order = 5)
@ -120,38 +51,4 @@ public class UserSelfSaveModel extends ApiWrapper {
@ValidatorLenMax(255) @ValidatorLenMax(255)
private String sign; private String sign;
/** 多租户字段 */
@Schema(description = "多租户ID")
@ExcelIgnore
@ValidatorLenMax(20)
private String tenantId;
/** 是否租户管理员 */
@Schema(description = "是否租户管理员")
@ExcelIgnore
@ValidatorLenMax(1)
private String izTenantAdmin;
/** 是否存在组织 */
@JsonIgnore
@ExcelIgnore
@ValidatorLenMax(1)
private String izExistOrg;
/** 允许切换租户0 不允许 1 允许) */
@Schema(description = "是否允许切换运营商")
@ExcelIgnore
private String enableSwitchTenant;
/** 切换后的租户id*/
@JsonIgnore
@ExcelIgnore
private String switchTenantId;
/** 切换后的租户管理员*/
@JsonIgnore
@ExcelIgnore
private String switchTenantUserId;
} }

@ -49,11 +49,11 @@ public class SysUser extends BaseEntity {
private String realName; private String realName;
/** 手机 */ /** 手机 */
@TableField(updateStrategy = FieldStrategy.ALWAYS) @TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
private String mobile; private String mobile;
/** 邮箱 */ /** 邮箱 */
@TableField(updateStrategy = FieldStrategy.ALWAYS) @TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
private String email; private String email;
/** 工号 */ /** 工号 */

@ -51,6 +51,12 @@ public interface IUserService extends CrudServiceInterface<SysUser, UserModel> {
*/ */
UserModel queryByEmail(String email); UserModel queryByEmail(String email);
/**
*
* @param userSelfSaveModel model
* @return boolean
*/
boolean updateUserInfo(UserSelfSaveModel userSelfSaveModel);
/** /**
* *

@ -610,8 +610,7 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
// 刷新用户缓存 // 刷新用户缓存
this.clearCache(Collections.singletonList(userModel)); this.clearCache(Collections.singletonList(userModel));
} }
return ret;
return false;
} }
@ -654,8 +653,7 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
// 刷新用户缓存 // 刷新用户缓存
this.clearCache(Collections.singletonList(userModel)); this.clearCache(Collections.singletonList(userModel));
} }
return ret;
return false;
} }
@Override @Override
@ -678,12 +676,10 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
// 修改密码 // 修改密码
boolean ret = mapper.updatePassword(userPassword); boolean ret = mapper.updatePassword(userPassword);
if(ret){ if(ret){
// 刷新用户缓存 // 刷新用户缓存
this.clearCache(Collections.singletonList(userModel)); this.clearCache(Collections.singletonList(userModel));
} }
return ret; return ret;
} }
@ -722,7 +718,33 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
SysUser sysUser = new SysUser(); SysUser sysUser = new SysUser();
sysUser.setId(model.getId()); sysUser.setId(model.getId());
sysUser.setAvatar(model.getAvatar()); sysUser.setAvatar(model.getAvatar());
return mapper.updateAvatar(sysUser); boolean ret = mapper.updateAvatar(sysUser);
if(ret){
// 刷新用户缓存
this.clearCache(Collections.singletonList(model));
}
return ret;
}
/**
*
* @param userSelfSaveModel model
* @return boolean
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateUserInfo(UserSelfSaveModel userSelfSaveModel){
UserModel currUser = UserUtil.getUserBySource();
LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.set(SysUser::getRealName, userSelfSaveModel.getRealName())
.set(SysUser::getSign, userSelfSaveModel.getSign())
.eq(SysUser::getId, currUser.getId());
boolean ret = this.update(updateWrapper);
if(ret){
// 刷新用户缓存
this.clearCache(Collections.singletonList(currUser));
}
return ret;
} }

@ -199,8 +199,10 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
UserModel user = UserUtil.getUserBySource(); UserModel user = UserUtil.getUserBySource();
userPassword.setUserId(user.getId()); userPassword.setUserId(user.getId());
IService.updatePasswordByCheckOld(userPassword);
return ResultWrapper.getSuccessResultWrapper(); boolean flag = IService.updatePasswordByCheckOld(userPassword);
return flag ? ResultWrapper.getSuccessResultWrapper()
: ResultWrapper.getErrorResultWrapper();
} }
/** /**
@ -229,8 +231,9 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
userPassword.setUserId(userBySource.getId()); userPassword.setUserId(userBySource.getId());
userPassword.setNewPassword(updateUserPasswordByForgetModel.getNewPassword()); userPassword.setNewPassword(updateUserPasswordByForgetModel.getNewPassword());
IService.updatePasswordByNotCheckOld(userPassword); boolean flag = IService.updatePasswordByNotCheckOld(userPassword);
return ResultWrapper.getSuccessResultWrapper(); return flag ? ResultWrapper.getSuccessResultWrapper()
: ResultWrapper.getErrorResultWrapper();
} }
/** /**
@ -251,9 +254,10 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
// 验证对象 // 验证对象
ValidatorUtil.verify(updateUserEmailModel); ValidatorUtil.verify(updateUserEmailModel);
// 修改用户邮箱 // 修改邮箱
IService.updateUserEmail(updateUserEmailModel); boolean flag = IService.updateUserEmail(updateUserEmailModel);
return ResultWrapper.getSuccessResultWrapper(); return flag ? ResultWrapper.getSuccessResultWrapper()
: ResultWrapper.getErrorResultWrapper();
} }
/** /**
@ -274,9 +278,10 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
// 验证对象 // 验证对象
ValidatorUtil.verify(updateUserMobileModel); ValidatorUtil.verify(updateUserMobileModel);
// 修改用户邮箱 // 修改手机
IService.updateUserMobile(updateUserMobileModel); boolean flag = IService.updateUserMobile(updateUserMobileModel);
return ResultWrapper.getSuccessResultWrapper(); return flag ? ResultWrapper.getSuccessResultWrapper()
: ResultWrapper.getErrorResultWrapper();
} }
/** /**
@ -292,10 +297,9 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
UserModel userModel = new UserModel(); UserModel userModel = new UserModel();
userModel.setId(user.getId()); userModel.setId(user.getId());
userModel.setAvatar(userAvatarModel.getImgUrl()); userModel.setAvatar(userAvatarModel.getImgUrl());
IService.updateAvatar(userModel); boolean flag = IService.updateAvatar(userModel);
// 刷新用户信息 return flag ? ResultWrapper.getSuccessResultWrapper()
UserUtil.refreshUser(user); : ResultWrapper.getErrorResultWrapper();
return ResultWrapper.getSuccessResultWrapper();
} }
// ================================================== // ==================================================
@ -535,13 +539,9 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
throw new ServiceException(SystemMsg.EXCEPTION_USER_ILLEGAL_PARAMETER); throw new ServiceException(SystemMsg.EXCEPTION_USER_ILLEGAL_PARAMETER);
} }
// 防止篡改手机号、邮箱号 boolean flag = IService.updateUserInfo(model);
model.setMobile(null); return flag ? ResultWrapper.getSuccessResultWrapperByMsg("修改用户信息成功")
model.setEmail(null); : ResultWrapper.getErrorResultWrapper();
// 调用修改方法
IService.update(Convert.convert(UserModel.class, model));
return ResultWrapper.getSuccessResultWrapperByMsg("修改用户信息成功");
} }
/** /**

Loading…
Cancel
Save