diff --git a/src/main/java/com/lz/modules/sys/controller/SysUserController.java b/src/main/java/com/lz/modules/sys/controller/SysUserController.java index 5c682880..75337332 100644 --- a/src/main/java/com/lz/modules/sys/controller/SysUserController.java +++ b/src/main/java/com/lz/modules/sys/controller/SysUserController.java @@ -84,11 +84,10 @@ public class SysUserController extends AbstractController { String newPassword = new Sha256Hash(form.getNewPassword(), getUser().getSalt()).toHex(); //更新密码 - boolean flag = sysUserService.updatePassword(getUserId(), password, newPassword); + boolean flag = sysUserService.updatePassword(getUser(), password, newPassword); if (!flag) { return R.error("原密码不正确"); } - return R.ok(); } diff --git a/src/main/java/com/lz/modules/sys/service/SysUserService.java b/src/main/java/com/lz/modules/sys/service/SysUserService.java index 1b6bcdf9..da83c320 100644 --- a/src/main/java/com/lz/modules/sys/service/SysUserService.java +++ b/src/main/java/com/lz/modules/sys/service/SysUserService.java @@ -11,6 +11,7 @@ package com.lz.modules.sys.service; import com.baomidou.mybatisplus.extension.service.IService; import com.lz.common.utils.PageUtils; import com.lz.modules.sys.entity.SysUserEntity; +import org.apache.catalina.User; import java.util.List; import java.util.Map; @@ -62,7 +63,7 @@ public interface SysUserService extends IService { * @param password 原密码 * @param newPassword 新密码 */ - boolean updatePassword(Long userId, String password, String newPassword); + boolean updatePassword(SysUserEntity user, String password, String newPassword); List queryMenuIdListByRoleId(Long roleId); } diff --git a/src/main/java/com/lz/modules/sys/service/impl/SysUserServiceImpl.java b/src/main/java/com/lz/modules/sys/service/impl/SysUserServiceImpl.java index ecc3cc32..0e500244 100644 --- a/src/main/java/com/lz/modules/sys/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/lz/modules/sys/service/impl/SysUserServiceImpl.java @@ -13,7 +13,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.lz.common.exception.RRException; import com.lz.common.utils.Constant; import com.lz.common.utils.PageUtils; +import com.lz.modules.app.dao.StaffDao; import com.lz.modules.app.dto.UserDto; +import com.lz.modules.app.entity.StaffEntity; import com.lz.modules.sys.dao.SysUserDao; import com.lz.modules.sys.entity.SysUserEntity; import com.lz.modules.sys.service.SysRoleService; @@ -46,6 +48,9 @@ public class SysUserServiceImpl extends ServiceImpl i @Autowired private SysUserDao sysUserDao; + @Autowired + private StaffDao staffDao; + @Override public PageUtils queryPage(Map params) { @@ -126,11 +131,21 @@ public class SysUserServiceImpl extends ServiceImpl i } @Override - public boolean updatePassword(Long userId, String password, String newPassword) { - SysUserEntity userEntity = new SysUserEntity(); - userEntity.setPassword(newPassword); - return this.update(userEntity, - new QueryWrapper().eq("user_id", userId).eq("password", password)); + public boolean updatePassword(SysUserEntity user, String password, String newPassword) { + if (user.getType() == 1) { + StaffEntity staffEntity = staffDao.selectStaffById(user.getUserId()); + if (!staffEntity.getPassword().equals(password)) { + return false; + } + staffEntity.setPassword(newPassword); + staffDao.updateStaffById(staffEntity); + } else { + SysUserEntity userEntity = new SysUserEntity(); + userEntity.setPassword(newPassword); + return this.update(userEntity, + new QueryWrapper().eq("user_id", user.getUserId()).eq("password", password)); + } + return true ; } @Override