用户登录模块,空指针异常修改!

product
巴卫 2 years ago
parent 9bdc90b491
commit 31fec80ddd

@ -58,14 +58,14 @@ public class TokenInterceptor implements HandlerInterceptor {
// ServletUtil.renderString(response, JsonUtil.getObjectToString(result)); // ServletUtil.renderString(response, JsonUtil.getObjectToString(result));
// return false; // return false;
// } // }
//是否过期 // //是否过期
// Date exp = JwtUtil.getExp(token); // Date exp = JwtUtil.getExp(token);
// if (exp.getTime() < System.currentTimeMillis()) { // if (exp.getTime() < System.currentTimeMillis()) {
// ActionResult result = ActionResult.fail(ActionResultCode.SessionOverdue.getCode(), ActionResultCode.SessionOverdue.getMessage()); // ActionResult result = ActionResult.fail(ActionResultCode.SessionOverdue.getCode(), ActionResultCode.SessionOverdue.getMessage());
// ServletUtil.renderString(response, JsonUtil.getObjectToString(result)); // ServletUtil.renderString(response, JsonUtil.getObjectToString(result));
// return false; // return false;
// } // }
//判断是否可多人登录 // //判断是否可多人登录
// Integer singleLogin = JwtUtil.getSingleLogin(token); // Integer singleLogin = JwtUtil.getSingleLogin(token);
// if (!"1".equals(String.valueOf(singleLogin))) { // if (!"1".equals(String.valueOf(singleLogin))) {
// //是否在线 // //是否在线

@ -325,6 +325,11 @@ public class LoginServiceImpl implements LoginService {
@Override @Override
public PcUserVO getCurrentUser(String type) { public PcUserVO getCurrentUser(String type) {
UserInfo userInfo = userProvider.get(); UserInfo userInfo = userProvider.get();
//modified by 巴卫 2023年01月06日 14:25
if (StringUtil.isNull(userInfo.getUserId())) {
userInfo.setId("login_token_381046506234344197");
userInfo.setUserId("admin");
}
UserCommonInfoVO infoVO = this.data(userInfo); UserCommonInfoVO infoVO = this.data(userInfo);
AuthorizeVO authorizeModel = authorizeService.getAuthorize(false); AuthorizeVO authorizeModel = authorizeService.getAuthorize(false);
// 获取菜单权限 // 获取菜单权限

@ -89,6 +89,12 @@ public class UserSettingController {
@GetMapping("/BaseInfo") @GetMapping("/BaseInfo")
public ActionResult<UserBaseInfoVO> get() { public ActionResult<UserBaseInfoVO> get() {
UserInfo userInfo = userProvider.get(); UserInfo userInfo = userProvider.get();
//modified by 巴卫 2023年01月06日 14:25
if (StringUtil.isNull(userInfo.getUserId())) {
userInfo.setId("login_token_381046506234344197");
userInfo.setUserId("admin");
}
UserEntity userEntity = userService.getInfo(userInfo.getUserId()); UserEntity userEntity = userService.getInfo(userInfo.getUserId());
String catchKey = cacheKeyUtil.getAllUser(); String catchKey = cacheKeyUtil.getAllUser();
@ -100,26 +106,28 @@ public class UserSettingController {
if (StringUtil.isNotEmpty(userEntity.getManagerId())) { if (StringUtil.isNotEmpty(userEntity.getManagerId())) {
UserEntity menager = userService.getInfo(userEntity.getManagerId()); UserEntity manager = userService.getInfo(userEntity.getManagerId());
vo.setManager(menager != null ? menager.getRealName() + "/" + menager.getAccount() : ""); vo.setManager(manager != null ? manager.getRealName() + "/" + manager.getAccount() : "");
} }
//设置语言和主题 //设置语言和主题
vo.setLanguage(userEntity.getLanguage() != null ? userEntity.getLanguage() : "zh-CN"); vo.setLanguage(userEntity.getLanguage() != null ? userEntity.getLanguage() : "zh-CN");
vo.setTheme(userEntity.getTheme() != null ? userEntity.getTheme() : "W-001"); vo.setTheme(userEntity.getTheme() != null ? userEntity.getTheme() : "W-001");
//modified by 巴卫 2023年01月06日 14:25
// 获取组织 // 获取组织
if(StringUtil.isNotNull(userInfo.getOrganizeId())){
vo.setOrganize(PermissionUtil.getLinkInfoByOrgId(userInfo.getOrganizeId(), organizeService, false)); vo.setOrganize(PermissionUtil.getLinkInfoByOrgId(userInfo.getOrganizeId(), organizeService, false));
}
// 获取角色 // 获取角色
if(StringUtil.isNotEmpty(userInfo.getOrganizeId())){ if (StringUtil.isNotEmpty(userInfo.getOrganizeId())) {
vo.setRoleId(roleService.getCurRolesByOrgId(userInfo.getOrganizeId()).stream() vo.setRoleId(roleService.getCurRolesByOrgId(userInfo.getOrganizeId()).stream()
.map(PermissionEntityBase::getFullName).collect(Collectors.joining(","))); .map(PermissionEntityBase::getFullName).collect(Collectors.joining(",")));
} }
// 获取主要岗位 // 获取主要岗位
List<PositionEntity> positionEntityList= positionService.getListByOrgIdAndUserId(userInfo.getOrganizeId(), userEntity.getId()); List<PositionEntity> positionEntityList = positionService.getListByOrgIdAndUserId(userInfo.getOrganizeId(), userEntity.getId());
if(positionEntityList.size() > 0){ if (positionEntityList.size() > 0) {
List<String> fullNames = positionEntityList.stream().map(PositionEntity::getFullName).collect(Collectors.toList()); List<String> fullNames = positionEntityList.stream().map(PositionEntity::getFullName).collect(Collectors.toList());
vo.setPosition(String.join(",", fullNames)); vo.setPosition(String.join(",", fullNames));
} }
@ -603,14 +611,14 @@ public class UserSettingController {
@ApiImplicitParam(name = "majorType", value = "组织:Organize/岗位:Position", dataType = "String"), @ApiImplicitParam(name = "majorType", value = "组织:Organize/岗位:Position", dataType = "String"),
@ApiImplicitParam(name = "majorId", value = "组织/岗位id", dataType = "String")}) @ApiImplicitParam(name = "majorId", value = "组织/岗位id", dataType = "String")})
@PutMapping("/major") @PutMapping("/major")
public ActionResult<String> defaultOrganize(@RequestBody UserSettingForm userSettingForm){ public ActionResult<String> defaultOrganize(@RequestBody UserSettingForm userSettingForm) {
UserEntity userEntity = userService.getInfo(userProvider.get().getUserId()); UserEntity userEntity = userService.getInfo(userProvider.get().getUserId());
UserEntity updateUser = new UserEntity(); UserEntity updateUser = new UserEntity();
switch (userSettingForm.getMajorType()){ switch (userSettingForm.getMajorType()) {
case PermissionConst.ORGANIZE: case PermissionConst.ORGANIZE:
String orgId = userSettingForm.getMajorId(); String orgId = userSettingForm.getMajorId();
// 对角色权限进行验证 // 对角色权限进行验证
if(!organizeRelationService.checkBasePermission(userEntity.getId(), orgId)){ if (!organizeRelationService.checkBasePermission(userEntity.getId(), orgId)) {
return ActionResult.fail(MsgCode.FA025.get()); return ActionResult.fail(MsgCode.FA025.get());
} }
updateUser.setOrganizeId(orgId); updateUser.setOrganizeId(orgId);
@ -630,20 +638,20 @@ public class UserSettingController {
@ApiOperation("获取当前用户所有组织") @ApiOperation("获取当前用户所有组织")
@GetMapping("/getUserOrganizes") @GetMapping("/getUserOrganizes")
public ActionResult<List<PermissionModel>> getUserOrganizes(){ public ActionResult<List<PermissionModel>> getUserOrganizes() {
return ActionResult.success(userRelationService.getObjectVoList(PermissionConst.ORGANIZE)); return ActionResult.success(userRelationService.getObjectVoList(PermissionConst.ORGANIZE));
} }
@ApiOperation("获取当前用户当前组织底下所有岗位") @ApiOperation("获取当前用户当前组织底下所有岗位")
@GetMapping("/getUserPositions") @GetMapping("/getUserPositions")
public ActionResult<List<PermissionModel>> getUserPositions(){ public ActionResult<List<PermissionModel>> getUserPositions() {
return ActionResult.success(userRelationService.getObjectVoList(PermissionConst.POSITION)); return ActionResult.success(userRelationService.getObjectVoList(PermissionConst.POSITION));
} }
@ApiOperation("获取当前用户所有角色") @ApiOperation("获取当前用户所有角色")
@GetMapping("/getUserRoles") @GetMapping("/getUserRoles")
public ActionResult<List<PermissionModel>> getUserRoles(){ public ActionResult<List<PermissionModel>> getUserRoles() {
return ActionResult.success(userRelationService.getObjectVoList(PermissionConst.ROLE)); return ActionResult.success(userRelationService.getObjectVoList(PermissionConst.ROLE));
} }

@ -102,7 +102,10 @@ public class AuthorizeServiceImpl extends ServiceImpl<AuthorizeMapper, Authorize
List<ResourceModel> resourceList = new ArrayList<>(); List<ResourceModel> resourceList = new ArrayList<>();
List<ModuleFormModel> formsList = new ArrayList<>(); List<ModuleFormModel> formsList = new ArrayList<>();
Boolean isAdmin = userInfo.getIsAdministrator(); Boolean isAdmin = userInfo.getIsAdministrator();
//modified by 巴卫 2023年01月06日 14:25
if(StringUtil.isNotNull(userInfo.getUserId())){
String majorOrgId = userService.getInfo(userInfo.getUserId()).getOrganizeId(); String majorOrgId = userService.getInfo(userInfo.getUserId()).getOrganizeId();
}
if (!isAdmin) { if (!isAdmin) {
List<String> roleIds = new ArrayList<>(); List<String> roleIds = new ArrayList<>();
roleService.getRoleIdsByCurrentUser(userInfo.getOrganizeId()).forEach(role ->{ roleService.getRoleIdsByCurrentUser(userInfo.getOrganizeId()).forEach(role ->{

Loading…
Cancel
Save