deason před 8 měsíci
rodič
revize
623ed16370

+ 5 - 2
src/main/java/com/qmth/exam/reserve/bean/Constants.java

@@ -39,11 +39,14 @@ public interface Constants {
      */
     String XLSX_PREFIX = ".xlsx";
 
-     /**
+    /**
      * 异步下载提示
      */
     String ASYNC_TIPS = "正在执行,请在我的任务中查看执行结果";
 
-
+    /**
+     * 用户初始密码
+     */
+    String DEFAULT_PASSWORD = "123456";
 
 }

+ 3 - 3
src/main/java/com/qmth/exam/reserve/controller/admin/UserController.java

@@ -34,7 +34,7 @@ public class UserController extends BaseController {
         return userService.pageUser(req);
     }
 
-    @ApiOperation(value = "用户新增/编辑")
+    @ApiOperation(value = "用户新增编辑")
     @PostMapping(value = "/save")
     public void save(@RequestBody UserSaveReq req) {
         LoginUser user = curLoginUser();
@@ -48,9 +48,9 @@ public class UserController extends BaseController {
         userService.resetPassword(id);
     }
 
-    @ApiOperation(value = "用户启用/禁用")
+    @ApiOperation(value = "用户启用禁用")
     @PostMapping(value = "/enable")
-    public void enable(@ApiParam("用户ID") @RequestParam Long id, @ApiParam("启用/禁用") @RequestParam Boolean enable) {
+    public void enable(@ApiParam("用户ID") @RequestParam Long id, @ApiParam("启用禁用") @RequestParam Boolean enable) {
         userService.enable(id, enable);
     }
 

+ 10 - 5
src/main/java/com/qmth/exam/reserve/service/impl/AuthServiceImpl.java

@@ -1,6 +1,6 @@
 package com.qmth.exam.reserve.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.core.security.annotation.AuthorizationComponent;
 import com.qmth.boot.core.security.service.AuthorizationService;
@@ -201,24 +201,29 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
         if (StringUtils.isBlank(password)) {
             throw new StatusException("密码不能为空");
         }
+
         String regex = "^[a-zA-Z0-9]{6,12}$";
         if (!password.matches(regex)) {
             throw new StatusException("密码必须为:6-12位的大小写字母或者数字");
         }
+
         String encodePassword = DigestUtils.sha256Hex(password).toUpperCase();
         UserEntity user = userService.getById(id);
         if (user.getPassword().equals(encodePassword)) {
             throw new StatusException("修改的密码不能和原密码相同");
         }
-        userService.update(new UpdateWrapper<UserEntity>().lambda().set(UserEntity::getPassword, encodePassword).eq(UserEntity::getId, id));
+
+        LambdaUpdateWrapper<UserEntity> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.set(UserEntity::getPassword, encodePassword);
         //更新修改密码标志
         if (user.getFirstLogin() == null || user.getFirstLogin()) {
-            userService.update(
-                    new UpdateWrapper<UserEntity>().lambda().set(UserEntity::getFirstLogin, Boolean.FALSE).eq(UserEntity::getId, id));
+            updateWrapper.set(UserEntity::getFirstLogin, Boolean.FALSE);
         }
+        updateWrapper.set(UserEntity::getUpdateTime, System.currentTimeMillis());
+        updateWrapper.eq(UserEntity::getId, id);
+        userService.update(updateWrapper);
     }
 
-
     @Override
     public LoginUser findByIdentity(String identity, SignatureType type, String path) {
         return loginSessionManager.getLoginSession(identity);

+ 13 - 15
src/main/java/com/qmth/exam/reserve/service/impl/UserServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.core.collection.PageResult;
 import com.qmth.boot.core.exception.StatusException;
+import com.qmth.exam.reserve.bean.Constants;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.user.UserReq;
 import com.qmth.exam.reserve.bean.user.UserSaveReq;
@@ -55,7 +56,7 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
 
         if (req.getId() == null) {
             userEntity.setEnable(Boolean.TRUE);
-            userEntity.setPassword(DigestUtils.sha256Hex("123456").toUpperCase());
+            userEntity.setPassword(DigestUtils.sha256Hex(Constants.DEFAULT_PASSWORD).toUpperCase());
             this.save(userEntity);
         } else {
             this.updateById(userEntity);
@@ -64,28 +65,25 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
 
     @Override
     public void resetPassword(Long id) {
-        UserEntity userEntity = getById(id);
-        if (userEntity == null) {
-            log.error("[重置密码] 找不到用户记录:id:{}", id);
-            throw new StatusException("重置失败");
-        }
-
         LambdaUpdateWrapper<UserEntity> updateWrapper = new LambdaUpdateWrapper<>();
-        updateWrapper.set(UserEntity::getPassword, DigestUtils.sha256Hex("123456").toUpperCase()).eq(UserEntity::getId, id);
+        updateWrapper.set(UserEntity::getPassword, DigestUtils.sha256Hex(Constants.DEFAULT_PASSWORD).toUpperCase());
+        updateWrapper.set(UserEntity::getFirstLogin, true);
+        updateWrapper.set(UserEntity::getUpdateTime, System.currentTimeMillis());
+        updateWrapper.eq(UserEntity::getId, id);
+
         this.update(updateWrapper);
+        log.warn("重置用户密码!userId:{}", id);
     }
 
     @Override
     public void enable(Long id, Boolean enable) {
-        UserEntity userEntity = getById(id);
-        if (userEntity == null) {
-            log.error("[启用/禁用] 找不到用户记录:id:{}", id);
-            throw new StatusException("启用/禁用失败");
-        }
-
         LambdaUpdateWrapper<UserEntity> updateWrapper = new LambdaUpdateWrapper<>();
-        updateWrapper.set(UserEntity::getEnable, enable).eq(UserEntity::getId, id);
+        updateWrapper.set(UserEntity::getEnable, enable);
+        updateWrapper.set(UserEntity::getUpdateTime, System.currentTimeMillis());
+        updateWrapper.eq(UserEntity::getId, id);
+
         this.update(updateWrapper);
+        log.warn("更新用户状态!userId:{} enable:{}", id, enable);
     }
 
     private void checkUser(UserSaveReq req) {