| | |
| | | // "undefined";该值绝不能覆盖 sys_user.roleid。 |
| | | if (isValidRoleId(user.getRoleid())) { |
| | | oldUser.setRoleid(user.getRoleid()); |
| | | // 角色归属类型决定账号的数据范围。切换角色时同步 objectType, |
| | | // 但保留原 objectId,避免修改角色意外解除门店/运营商归属。 |
| | | syncObjectTypeWithRole(oldUser, user.getRoleid()); |
| | | // 仅内置平台管理员(1)和门店管理员(3)切换数据归属类型; |
| | | // 其他自定义角色只控制菜单权限,不改变账号归属。objectId 始终保留。 |
| | | syncObjectTypeWithBuiltInRole(oldUser, user.getRoleid()); |
| | | } |
| | | this.userService.updateById(oldUser); |
| | | return SUCCESS_TIP; |
| | |
| | | && !"null".equalsIgnoreCase(roleId); |
| | | } |
| | | |
| | | private void syncObjectTypeWithRole(User user, String roleId) { |
| | | try { |
| | | Role role = roleService.getById(Integer.valueOf(roleId)); |
| | | if (role != null && role.getObjType() != null) { |
| | | user.setObjectType(role.getObjType()); |
| | | } |
| | | } catch (NumberFormatException ignored) { |
| | | // 历史账号可能保存多角色或脏数据;无法解析为单个角色时保留原归属类型。 |
| | | private void syncObjectTypeWithBuiltInRole(User user, String roleId) { |
| | | if ("1".equals(roleId)) { |
| | | user.setObjectType(1); |
| | | } else if ("3".equals(roleId)) { |
| | | user.setObjectType(3); |
| | | } |
| | | } |
| | | |