From 4290886554fc1ddd1116ec67ea601fb5cecf4592 Mon Sep 17 00:00:00 2001 From: weihaonan Date: Mon, 19 Dec 2022 09:48:41 +0800 Subject: [PATCH] fix update password error --- .../com/whn/hellospring/controller/RoleController.java | 4 ++-- .../com/whn/hellospring/controller/UserController.java | 17 ++++++++++++----- .../com/whn/hellospring/log/OperationLogAspect.java | 6 ++++-- .../java/com/whn/hellospring/service/UserService.java | 2 +- src/main/resources/application.yml | 12 ++++++------ 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/whn/hellospring/controller/RoleController.java b/src/main/java/com/whn/hellospring/controller/RoleController.java index ebcc5e2..6b32b94 100644 --- a/src/main/java/com/whn/hellospring/controller/RoleController.java +++ b/src/main/java/com/whn/hellospring/controller/RoleController.java @@ -48,10 +48,10 @@ public class RoleController { return new Status(StateMessage.TOKEN_ERROR); } - if(request.getId()!=null){ + if(request.getP_id()!=null){ // 获取角色详情 - RoleDO roleDetail = roleService.getRoleWithId(request.getId()); + RoleDO roleDetail = roleService.getRoleWithId(Long.parseLong(request.getP_id())); if(roleDetail==null){ return new Status(StateMessage.SUCCESS, "此id角色不存在"); diff --git a/src/main/java/com/whn/hellospring/controller/UserController.java b/src/main/java/com/whn/hellospring/controller/UserController.java index 2bb1d45..68fc2c1 100644 --- a/src/main/java/com/whn/hellospring/controller/UserController.java +++ b/src/main/java/com/whn/hellospring/controller/UserController.java @@ -52,11 +52,18 @@ public class UserController { return new Status(StateMessage.SUCCESS, "此id用户不存在"); } - //编辑 信息 - UserDO userDO = MergeObjectsUtil.mergeObjects(request, userDetail); - userService.updateUser(userDO); - - return new Status(StateMessage.SUCCESS, userDO); + //有密码,覆盖密码,加密 + if(request.getUserPassword()!=null && !"".equals(request.getUserPassword())){ + userDetail.setUserPassword(request.getUserPassword()); + UserDO userDO = MergeObjectsUtil.mergeObjects(request, userDetail); + userService.updateUser(userDO); + return new Status(StateMessage.SUCCESS, userDO); + }else{ + //没有密码,不重新加密 + UserDO userDO = MergeObjectsUtil.mergeObjects(request, userDetail); + userService.updateUserNoPassword(userDO); + return new Status(StateMessage.SUCCESS, userDO); + } }else{ //新增 diff --git a/src/main/java/com/whn/hellospring/log/OperationLogAspect.java b/src/main/java/com/whn/hellospring/log/OperationLogAspect.java index 7d8726e..9523083 100644 --- a/src/main/java/com/whn/hellospring/log/OperationLogAspect.java +++ b/src/main/java/com/whn/hellospring/log/OperationLogAspect.java @@ -78,8 +78,10 @@ public class OperationLogAspect { try { if(request.getHeader("token")!=null){ UserDO user = userService.getUserWithToken(request.getHeader("token")); - operationLog.setUser_id(user.getId().toString()); - operationLog.setUser_name(user.getUserName()); + if(user!=null){ + operationLog.setUser_id(user.getId().toString()); + operationLog.setUser_name(user.getUserName()); + } } }catch (Exception e){ System.out.println("e:"+e.toString()); diff --git a/src/main/java/com/whn/hellospring/service/UserService.java b/src/main/java/com/whn/hellospring/service/UserService.java index 86d3b50..22137cd 100644 --- a/src/main/java/com/whn/hellospring/service/UserService.java +++ b/src/main/java/com/whn/hellospring/service/UserService.java @@ -132,7 +132,7 @@ public class UserService { } /** - * 编辑客户 + * 编辑客户,加密密码 */ public UserDO updateUser(UserDO userDo) { userDo.setUserPassword(SHAUtils.getSHA256StrJava(userDo.getUserPassword())); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e2ccbcc..42c9d45 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -22,13 +22,13 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://101.37.147.15:3306/AgileTools?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL username: root - password: root + password: Digiproto@123 #数据源2 -# zentao: -# driver-class-name: com.mysql.cj.jdbc.Driver -# url: jdbc:mysql://101.37.147.15:23306/zentao?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL -# username: root -# password: 123456 + zentao: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://101.37.147.15:23306/zentao?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL + username: root + password: Digiproto@123 # url: jdbc:mysql://101.37.147.15:3306/AgileTools?useUnicode=true&characterEncoding=UTF-8?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&failOverReadOnly=false&serverTimezone=UTC # username: root