Bläddra i källkod

补充修改重置员工密码功能

Huanyi 7 timmar sedan
förälder
incheckning
be0f64690e

+ 2 - 3
.idea/runConfigurations/8080 - 主服务.xml

@@ -1,12 +1,11 @@
-<?xml version="1.0" encoding="UTF-8"?>
 <component name="ProjectRunConfigurationManager">
   <configuration default="false" name="8080 - 主服务" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
     <module name="ruoyi-admin" />
+    <option name="SHORTEN_COMMAND_LINE" value="ARGS_FILE" />
     <option name="SPRING_BOOT_MAIN_CLASS" value="org.dromara.DromaraApplication" />
     <option name="VM_PARAMETERS" value="-Dspring.profiles.active=dev -Dserver.port=8080" />
-    <option name="PROGRAM_PARAMETERS" value="" />
     <method v="2">
       <option name="Make" enabled="true" />
     </method>
   </configuration>
-</component>
+</component>

+ 1 - 0
ruoyi-admin/src/main/resources/i18n/messages.properties

@@ -4,6 +4,7 @@ user.jcaptcha.error=验证码错误
 user.jcaptcha.expire=验证码已失效
 user.not.exists=对不起, 您的账号:{0} 不存在.
 user.password.not.match=用户不存在/密码错误
+user.password.error=密码错误
 user.password.retry.limit.count=密码输入错误{0}次
 user.password.retry.limit.exceed=密码输入错误{0}次,账户锁定{1}分钟
 user.password.delete=对不起,您的账号:{0} 已被删除

+ 1 - 0
ruoyi-admin/src/main/resources/i18n/messages_en_US.properties

@@ -4,6 +4,7 @@ user.jcaptcha.error=Captcha error
 user.jcaptcha.expire=Captcha invalid
 user.not.exists=Sorry, your account: {0} does not exist
 user.password.not.match=User does not exist/Password error
+user.password.error=Incorrect password
 user.password.retry.limit.count=Password input error {0} times
 user.password.retry.limit.exceed=Password input error {0} times, account locked for {1} minutes
 user.password.delete=Sorry, your account:{0} has been deleted

+ 1 - 0
ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties

@@ -4,6 +4,7 @@ user.jcaptcha.error=验证码错误
 user.jcaptcha.expire=验证码已失效
 user.not.exists=对不起, 您的账号:{0} 不存在.
 user.password.not.match=用户不存在/密码错误
+user.password.error=密码错误
 user.password.retry.limit.count=密码输入错误{0}次
 user.password.retry.limit.exceed=密码输入错误{0}次,账户锁定{1}分钟
 user.password.delete=对不起,您的账号:{0} 已被删除

+ 27 - 12
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysEmployeeController.java

@@ -1,7 +1,6 @@
 package org.dromara.system.controller.system;
 
 import cn.hutool.crypto.digest.BCrypt;
-import jakarta.validation.constraints.NotEmpty;
 import jakarta.validation.constraints.NotNull;
 import lombok.RequiredArgsConstructor;
 import org.dromara.common.core.domain.R;
@@ -14,6 +13,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.satoken.utils.LoginHelper;
 import org.dromara.common.web.core.BaseController;
 import org.dromara.system.domain.bo.SysEmployeeBo;
+import org.dromara.system.domain.bo.SysEmployeePasswordBo;
 import org.dromara.system.domain.vo.SysEmployeeVo;
 import org.dromara.system.service.ISysEmployeeService;
 import org.springframework.validation.annotation.Validated;
@@ -119,18 +119,13 @@ public class SysEmployeeController extends BaseController {
     /**
      * 授权客户(支持多个,逗号分隔)
      *
-     * @param id                 员工ID
-     * @param authClientFRowIDs  授权客户 RowID 列表
+     * @param bo 包含员工ID和授权客户RowID列表
      */
     @Log(title = "员工管理", businessType = BusinessType.UPDATE)
     @RepeatSubmit()
     @PutMapping("/auth")
-    public R<Void> auth(@NotNull(message = "员工ID不能为空") Long id,
-                        @NotEmpty(message = "授权客户 RowID 不能为空") String authClientFRowIDs) {
-        sysEmployeeService.checkAuthClientConflict(id, authClientFRowIDs);
-        SysEmployeeBo bo = new SysEmployeeBo();
-        bo.setId(id);
-        bo.setAuthClientFRowIDs(authClientFRowIDs);
+    public R<Void> auth(@RequestBody SysEmployeeBo bo) {
+        sysEmployeeService.checkAuthClientConflict(bo.getId(), bo.getAuthClientFRowIDs());
         return toAjax(sysEmployeeService.updateByBo(bo));
     }
 
@@ -140,8 +135,28 @@ public class SysEmployeeController extends BaseController {
     @Log(title = "员工管理", businessType = BusinessType.UPDATE)
     @RepeatSubmit()
     @PutMapping("/changeStatus")
-    public R<Void> changeStatus(@NotNull(message = "员工ID不能为空") Long id,
-                                @NotNull(message = "状态不能为空") String status) {
-        return toAjax(sysEmployeeService.changeStatus(id, status));
+    public R<Void> changeStatus(@RequestBody SysEmployeeBo bo) {
+        return toAjax(sysEmployeeService.changeStatus(bo.getId(), bo.getStatus()));
+    }
+
+    /**
+     * 当前员工修改密码
+     */
+    @Log(title = "员工管理", businessType = BusinessType.UPDATE)
+    @RepeatSubmit()
+    @PutMapping("/resetPassword")
+    public R<Void> resetPassword(@Validated @RequestBody SysEmployeePasswordBo bo) {
+        Long employeeId = LoginHelper.getUserId();
+        return toAjax(sysEmployeeService.resetPassword(employeeId, bo.getOldPassword(), bo.getNewPassword()));
+    }
+
+    /**
+     * 管理员重置员工密码
+     */
+    @Log(title = "员工管理", businessType = BusinessType.UPDATE)
+    @RepeatSubmit()
+    @PutMapping("/adminResetPassword")
+    public R<Void> adminResetPassword(@RequestBody SysEmployeeBo bo) {
+        return toAjax(sysEmployeeService.adminResetPassword(bo.getId()));
     }
 }

+ 27 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysEmployeePasswordBo.java

@@ -0,0 +1,27 @@
+package org.dromara.system.domain.bo;
+
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.Size;
+import lombok.Data;
+
+/**
+ * 员工修改密码业务对象
+ *
+ * @author Trae
+ */
+@Data
+public class SysEmployeePasswordBo {
+
+    /**
+     * 旧密码
+     */
+    @NotBlank(message = "旧密码不能为空")
+    private String oldPassword;
+
+    /**
+     * 新密码
+     */
+    @NotBlank(message = "新密码不能为空")
+    @Size(min = 6, max = 100, message = "新密码长度必须在6-100之间")
+    private String newPassword;
+}

+ 10 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysEmployeeService.java

@@ -73,4 +73,14 @@ public interface ISysEmployeeService {
      * 修改员工状态(启用/禁用)
      */
     Boolean changeStatus(Long id, String status);
+
+    /**
+     * 当前员工修改密码
+     */
+    Boolean resetPassword(Long employeeId, String oldPassword, String newPassword);
+
+    /**
+     * 管理员重置员工密码
+     */
+    Boolean adminResetPassword(Long employeeId);
 }

+ 30 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysEmployeeServiceImpl.java

@@ -1,6 +1,7 @@
 package org.dromara.system.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.crypto.digest.BCrypt;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -359,4 +360,33 @@ public class SysEmployeeServiceImpl implements ISysEmployeeService, EmployeeServ
         employee.setStatus(status);
         return baseMapper.updateById(employee) > 0;
     }
+
+    /**
+     * 当前员工修改密码
+     */
+    @Override
+    public Boolean resetPassword(Long employeeId, String oldPassword, String newPassword) {
+        SysEmployee employee = baseMapper.selectById(employeeId);
+        if (employee == null) {
+            throw new ServiceException("员工不存在");
+        }
+        if (!BCrypt.checkpw(oldPassword, employee.getPassword())) {
+            throw new ServiceException("旧密码不正确");
+        }
+        employee.setPassword(BCrypt.hashpw(newPassword));
+        return baseMapper.updateById(employee) > 0;
+    }
+
+    /**
+     * 管理员重置员工密码为 123456
+     */
+    @Override
+    public Boolean adminResetPassword(Long employeeId) {
+        SysEmployee employee = baseMapper.selectById(employeeId);
+        if (employee == null) {
+            throw new ServiceException("员工不存在");
+        }
+        employee.setPassword(BCrypt.hashpw("123456"));
+        return baseMapper.updateById(employee) > 0;
+    }
 }