Skip to content

Commit 80becfa

Browse files
authored
Merge pull request #43 from hiparker/development
Merge: 修复修改个人信息时会清空手机邮箱问题 & 优化用户提醒
2 parents ff53026 + d0df970 commit 80becfa

File tree

5 files changed

+59
-134
lines changed

5 files changed

+59
-134
lines changed

opsli-api/src/main/java/org/opsli/api/wrapper/system/user/UserSelfSaveModel.java

Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@
1515
*/
1616
package org.opsli.api.wrapper.system.user;
1717

18-
import com.alibaba.excel.annotation.ExcelIgnore;
1918
import com.alibaba.excel.annotation.ExcelProperty;
20-
import com.fasterxml.jackson.annotation.JsonIgnore;
2119
import io.swagger.v3.oas.annotations.media.Schema;
2220
import lombok.Data;
2321
import lombok.EqualsAndHashCode;
2422
import org.opsli.api.base.warpper.ApiWrapper;
2523
import org.opsli.common.annotation.validator.Validator;
2624
import org.opsli.common.annotation.validator.ValidatorLenMax;
27-
import org.opsli.common.annotation.validator.ValidatorLenMin;
2825
import org.opsli.common.enums.ValidatorType;
2926
import org.opsli.plugins.excel.annotation.ExcelInfo;
3027

3128
/**
32-
* 用户信息表
29+
* 用户信息表 - 用于修改自身信息
3330
*
3431
* @author Pace
3532
* @date 2020-09-16 17:33
@@ -38,33 +35,6 @@
3835
@EqualsAndHashCode(callSuper = false)
3936
public class UserSelfSaveModel extends ApiWrapper {
4037

41-
/** 登录账户 */
42-
@Schema(description = "登录账户")
43-
@ExcelIgnore
44-
@Validator({ValidatorType.IS_NOT_NULL, ValidatorType.IS_GENERAL})
45-
@ValidatorLenMax(32)
46-
@ValidatorLenMin(4)
47-
private String username;
48-
49-
/** 登录密码 */
50-
@Schema(description = "登录密码")
51-
@ExcelIgnore
52-
@ValidatorLenMin(6)
53-
@ValidatorLenMax(50)
54-
private String password;
55-
56-
/** 登录密码强度 */
57-
@Schema(description = "登录密码强度")
58-
@ExcelIgnore
59-
@ValidatorLenMin(1)
60-
@ValidatorLenMax(1)
61-
private String passwordLevel;
62-
63-
/** 是否启用 */
64-
@Schema(description = "是否启用")
65-
@ExcelIgnore
66-
@ValidatorLenMax(1)
67-
private String enable;
6838

6939
/** 真实姓名 */
7040
@Schema(description = "真实姓名")
@@ -74,84 +44,11 @@ public class UserSelfSaveModel extends ApiWrapper {
7444
@ValidatorLenMax(50)
7545
private String realName;
7646

77-
/** 手机 */
78-
@Schema(description = "手机")
79-
@ExcelProperty(value = "手机", order = 2)
80-
@ExcelInfo
81-
private String mobile;
82-
83-
/** 邮箱 */
84-
@Schema(description = "邮箱")
85-
@ExcelProperty(value = "邮箱", order = 3)
86-
@ExcelInfo
87-
private String email;
88-
89-
/** 工号 */
90-
@Schema(description = "工号")
91-
@ExcelProperty(value = "工号", order = 4)
92-
@ExcelInfo
93-
@Validator({ValidatorType.IS_GENERAL})
94-
@ValidatorLenMax(32)
95-
private String no;
96-
97-
/** 头像 */
98-
@Schema(description = "头像")
99-
@ExcelIgnore
100-
@ValidatorLenMax(255)
101-
private String avatar;
102-
103-
/** 最后登陆IP */
104-
@Schema(description = "最后登陆IP")
105-
@ExcelIgnore
106-
@Validator(ValidatorType.IS_IPV4)
107-
private String loginIp;
108-
109-
/** 备注 */
110-
@Schema(description = "备注")
111-
@ExcelProperty(value = "备注", order = 5)
112-
@ExcelInfo
113-
@ValidatorLenMax(255)
114-
private String remark;
115-
11647
/** 签名 */
11748
@Schema(description = "签名")
11849
@ExcelProperty(value = "签名", order = 5)
11950
@ExcelInfo
12051
@ValidatorLenMax(255)
12152
private String sign;
12253

123-
124-
/** 多租户字段 */
125-
@Schema(description = "多租户ID")
126-
@ExcelIgnore
127-
@ValidatorLenMax(20)
128-
private String tenantId;
129-
130-
/** 是否租户管理员 */
131-
@Schema(description = "是否租户管理员")
132-
@ExcelIgnore
133-
@ValidatorLenMax(1)
134-
private String izTenantAdmin;
135-
136-
/** 是否存在组织 */
137-
@JsonIgnore
138-
@ExcelIgnore
139-
@ValidatorLenMax(1)
140-
private String izExistOrg;
141-
142-
/** 允许切换租户(0 不允许 1 允许) */
143-
@Schema(description = "是否允许切换运营商")
144-
@ExcelIgnore
145-
private String enableSwitchTenant;
146-
147-
/** 切换后的租户id*/
148-
@JsonIgnore
149-
@ExcelIgnore
150-
private String switchTenantId;
151-
152-
/** 切换后的租户管理员*/
153-
@JsonIgnore
154-
@ExcelIgnore
155-
private String switchTenantUserId;
156-
15754
}

opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/entity/SysUser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public class SysUser extends BaseEntity {
4949
private String realName;
5050

5151
/** 手机 */
52-
@TableField(updateStrategy = FieldStrategy.ALWAYS)
52+
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
5353
private String mobile;
5454

5555
/** 邮箱 */
56-
@TableField(updateStrategy = FieldStrategy.ALWAYS)
56+
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
5757
private String email;
5858

5959
/** 工号 */

opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/IUserService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public interface IUserService extends CrudServiceInterface<SysUser, UserModel> {
5151
*/
5252
UserModel queryByEmail(String email);
5353

54+
/**
55+
* 修改个人信息
56+
* @param userSelfSaveModel model
57+
* @return boolean
58+
*/
59+
boolean updateUserInfo(UserSelfSaveModel userSelfSaveModel);
5460

5561
/**
5662
* 修改密码 验证旧密码

opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserServiceImpl.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,7 @@ public boolean updateUserEmail(UpdateUserEmailModel updateUserEmailModel) {
610610
// 刷新用户缓存
611611
this.clearCache(Collections.singletonList(userModel));
612612
}
613-
614-
return false;
613+
return ret;
615614
}
616615

617616

@@ -654,8 +653,7 @@ public boolean updateUserMobile(UpdateUserMobileModel updateUserMobileModel) {
654653
// 刷新用户缓存
655654
this.clearCache(Collections.singletonList(userModel));
656655
}
657-
658-
return false;
656+
return ret;
659657
}
660658

661659
@Override
@@ -678,12 +676,10 @@ public boolean resetPassword(UserPassword userPassword) {
678676

679677
// 修改密码
680678
boolean ret = mapper.updatePassword(userPassword);
681-
682679
if(ret){
683680
// 刷新用户缓存
684681
this.clearCache(Collections.singletonList(userModel));
685682
}
686-
687683
return ret;
688684
}
689685

@@ -722,7 +718,33 @@ public boolean updateAvatar(UserModel model) {
722718
SysUser sysUser = new SysUser();
723719
sysUser.setId(model.getId());
724720
sysUser.setAvatar(model.getAvatar());
725-
return mapper.updateAvatar(sysUser);
721+
boolean ret = mapper.updateAvatar(sysUser);
722+
if(ret){
723+
// 刷新用户缓存
724+
this.clearCache(Collections.singletonList(model));
725+
}
726+
return ret;
727+
}
728+
729+
/**
730+
* 修改个人信息
731+
* @param userSelfSaveModel model
732+
* @return boolean
733+
*/
734+
@Override
735+
@Transactional(rollbackFor = Exception.class)
736+
public boolean updateUserInfo(UserSelfSaveModel userSelfSaveModel){
737+
UserModel currUser = UserUtil.getUserBySource();
738+
LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<>();
739+
updateWrapper.set(SysUser::getRealName, userSelfSaveModel.getRealName())
740+
.set(SysUser::getSign, userSelfSaveModel.getSign())
741+
.eq(SysUser::getId, currUser.getId());
742+
boolean ret = this.update(updateWrapper);
743+
if(ret){
744+
// 刷新用户缓存
745+
this.clearCache(Collections.singletonList(currUser));
746+
}
747+
return ret;
726748
}
727749

728750

opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/web/UserRestController.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@ public ResultWrapper<?> updatePassword(EncryptModel encryptModel) {
199199

200200
UserModel user = UserUtil.getUserBySource();
201201
userPassword.setUserId(user.getId());
202-
IService.updatePasswordByCheckOld(userPassword);
203-
return ResultWrapper.getSuccessResultWrapper();
202+
203+
boolean flag = IService.updatePasswordByCheckOld(userPassword);
204+
return flag ? ResultWrapper.getSuccessResultWrapper()
205+
: ResultWrapper.getErrorResultWrapper();
204206
}
205207

206208
/**
@@ -229,8 +231,9 @@ public ResultWrapper<?> updatePasswordByForget(EncryptModel encryptModel) {
229231
userPassword.setUserId(userBySource.getId());
230232
userPassword.setNewPassword(updateUserPasswordByForgetModel.getNewPassword());
231233

232-
IService.updatePasswordByNotCheckOld(userPassword);
233-
return ResultWrapper.getSuccessResultWrapper();
234+
boolean flag = IService.updatePasswordByNotCheckOld(userPassword);
235+
return flag ? ResultWrapper.getSuccessResultWrapper()
236+
: ResultWrapper.getErrorResultWrapper();
234237
}
235238

236239
/**
@@ -251,9 +254,10 @@ public ResultWrapper<?> updateEmail(EncryptModel encryptModel) {
251254
// 验证对象
252255
ValidatorUtil.verify(updateUserEmailModel);
253256

254-
// 修改用户邮箱
255-
IService.updateUserEmail(updateUserEmailModel);
256-
return ResultWrapper.getSuccessResultWrapper();
257+
// 修改邮箱
258+
boolean flag = IService.updateUserEmail(updateUserEmailModel);
259+
return flag ? ResultWrapper.getSuccessResultWrapper()
260+
: ResultWrapper.getErrorResultWrapper();
257261
}
258262

259263
/**
@@ -274,9 +278,10 @@ public ResultWrapper<?> updateMobile(EncryptModel encryptModel) {
274278
// 验证对象
275279
ValidatorUtil.verify(updateUserMobileModel);
276280

277-
// 修改用户邮箱
278-
IService.updateUserMobile(updateUserMobileModel);
279-
return ResultWrapper.getSuccessResultWrapper();
281+
// 修改手机
282+
boolean flag = IService.updateUserMobile(updateUserMobileModel);
283+
return flag ? ResultWrapper.getSuccessResultWrapper()
284+
: ResultWrapper.getErrorResultWrapper();
280285
}
281286

282287
/**
@@ -292,10 +297,9 @@ public ResultWrapper<?> updateAvatar(UserAvatarModel userAvatarModel) {
292297
UserModel userModel = new UserModel();
293298
userModel.setId(user.getId());
294299
userModel.setAvatar(userAvatarModel.getImgUrl());
295-
IService.updateAvatar(userModel);
296-
// 刷新用户信息
297-
UserUtil.refreshUser(user);
298-
return ResultWrapper.getSuccessResultWrapper();
300+
boolean flag = IService.updateAvatar(userModel);
301+
return flag ? ResultWrapper.getSuccessResultWrapper()
302+
: ResultWrapper.getErrorResultWrapper();
299303
}
300304

301305
// ==================================================
@@ -535,13 +539,9 @@ public ResultWrapper<?> updateSelf(UserSelfSaveModel model) {
535539
throw new ServiceException(SystemMsg.EXCEPTION_USER_ILLEGAL_PARAMETER);
536540
}
537541

538-
// 防止篡改手机号、邮箱号
539-
model.setMobile(null);
540-
model.setEmail(null);
541-
542-
// 调用修改方法
543-
IService.update(Convert.convert(UserModel.class, model));
544-
return ResultWrapper.getSuccessResultWrapperByMsg("修改用户信息成功");
542+
boolean flag = IService.updateUserInfo(model);
543+
return flag ? ResultWrapper.getSuccessResultWrapperByMsg("修改用户信息成功")
544+
: ResultWrapper.getErrorResultWrapper();
545545
}
546546

547547
/**

0 commit comments

Comments
 (0)