Bläddra i källkod

用户首次登录修改密码

caozixuan 1 år sedan
förälder
incheckning
4736933de6

+ 10 - 11
src/main/java/cn/com/qmth/print/manage/controller/UserController.java

@@ -6,6 +6,7 @@ import cn.com.qmth.print.manage.enums.RoleMeta;
 import cn.com.qmth.print.manage.service.PmSession;
 import cn.com.qmth.print.manage.service.UserService;
 import cn.com.qmth.print.manage.service.query.UserQuery;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
@@ -93,15 +94,13 @@ public class UserController extends BaseController {
         if (!RoleMeta.ADMIN.equals(requestUser.getRole())) {
             throw new StatusException("只有管理员能重置密码");
         }
-
-        UserEntity db = userService.getById(userId);
-        if (Objects.isNull(db)) {
-            throw new StatusException("用户不存在");
-        }
-        db.setPassword(PmConstants.DEFAULT_PASSWORD);
-        db.setPasswordCount(db.getPasswordCount() + 1);
-        db.setUpdaterId(userId);
-        db.setUpdateTime(new Date());
-        userService.updateById(db);
+        UpdateWrapper<UserEntity> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.lambda()
+                .eq(UserEntity::getId, userId)
+                .set(UserEntity::getPassword, PmConstants.DEFAULT_PASSWORD)
+                .set(UserEntity::getPasswordCount, 0)
+                .set(UserEntity::getUpdaterId, userId)
+                .set(UserEntity::getUpdateTime, new Date());
+        userService.update(updateWrapper);
     }
-}
+}

+ 3 - 3
src/main/java/cn/com/qmth/print/manage/entity/UserEntity.java

@@ -16,7 +16,7 @@ public class UserEntity extends AuditingEntity {
 
     private String password;
 
-    private Integer passwordCount;
+    private int passwordCount;
 
     private boolean enable;
 
@@ -46,11 +46,11 @@ public class UserEntity extends AuditingEntity {
         this.password = password;
     }
 
-    public Integer getPasswordCount() {
+    public int getPasswordCount() {
         return passwordCount;
     }
 
-    public void setPasswordCount(Integer passwordCount) {
+    public void setPasswordCount(int passwordCount) {
         this.passwordCount = passwordCount;
     }
 

+ 11 - 0
src/main/java/cn/com/qmth/print/manage/vo/UserVo.java

@@ -5,6 +5,7 @@ import java.io.Serializable;
 import cn.com.qmth.print.manage.config.PmConstants;
 import cn.com.qmth.print.manage.entity.UserEntity;
 import cn.com.qmth.print.manage.enums.RoleMeta;
+import io.swagger.annotations.ApiModelProperty;
 
 /**
  * 用户
@@ -41,6 +42,9 @@ public class UserVo implements Serializable {
 
     private boolean enable;
 
+    @ApiModelProperty("密码重置次数")
+    private int passwordCount;
+
     public UserVo(UserEntity entity) {
         this.loginName = entity.getLoginName();
         this.id = entity.getId();
@@ -106,4 +110,11 @@ public class UserVo implements Serializable {
         this.role = role;
     }
 
+    public int getPasswordCount() {
+        return passwordCount;
+    }
+
+    public void setPasswordCount(int passwordCount) {
+        this.passwordCount = passwordCount;
+    }
 }