refactor: 获取不到用户信息时抛出异常,不使用默认用户
This commit is contained in:
parent
7a53dfce58
commit
33fa764e40
|
|
@ -440,8 +440,8 @@ public class EbomApi extends BaseApi {
|
||||||
dto.setRealName("郑军榕");
|
dto.setRealName("郑军榕");
|
||||||
dto.setDepartName("信息流程中心/IT支持");
|
dto.setDepartName("信息流程中心/IT支持");
|
||||||
dto.setFullDeptName("信息流程中心/IT支持");
|
dto.setFullDeptName("信息流程中心/IT支持");
|
||||||
dto.setRowId(1585164668335439881l);
|
dto.setRowId(1585164668335439881L);
|
||||||
SessionUtil.loginUser.set(dto);
|
BaseApi.loginUser.set(dto);
|
||||||
|
|
||||||
return ResultVO.success();
|
return ResultVO.success();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
package com.nflg.product.base.core.conmon.util;
|
package com.nflg.product.base.core.conmon.util;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.nflg.product.base.core.api.BaseApi;
|
import com.nflg.product.base.core.api.BaseApi;
|
||||||
|
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||||
|
import nflg.product.common.constant.STATE;
|
||||||
import nflg.product.common.dto.LoginUserInfoDTO;
|
import nflg.product.common.dto.LoginUserInfoDTO;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @decription
|
* @decription
|
||||||
|
|
@ -12,7 +14,7 @@ import java.util.*;
|
||||||
* @Date 2022/7/15 9:04
|
* @Date 2022/7/15 9:04
|
||||||
**/
|
**/
|
||||||
public class SessionUtil {
|
public class SessionUtil {
|
||||||
public static ThreadLocal<LoginUserInfoDTO> loginUser= BaseApi.loginUser;
|
//public static ThreadLocal<LoginUserInfoDTO> loginUser= BaseApi.loginUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取登入用户编号
|
* 获取登入用户编号
|
||||||
|
|
@ -20,7 +22,8 @@ public class SessionUtil {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Long getRowId() {
|
public static Long getRowId() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getRowId).orElse(1585164668335439881L);
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getRowId).orElse(1585164668335439881L);
|
||||||
|
return getUser().getRowId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -29,7 +32,9 @@ public class SessionUtil {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getUserCode() {
|
public static String getUserCode() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getUserCode).orElse("QHI17062100");
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getUserCode).orElse("QHI17062100");
|
||||||
|
return getUser().getUserCode();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,7 +43,8 @@ public class SessionUtil {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getUserName() {
|
public static String getUserName() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getUserName).orElse("郑军榕");
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getUserName).orElse("郑军榕");
|
||||||
|
return getUser().getUserName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,48 +53,61 @@ public class SessionUtil {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Long getPartRowId() {
|
public static Long getPartRowId() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getDepartRowId).orElse(null);
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getDepartRowId).orElse(null);
|
||||||
|
return getUser().getDepartRowId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRealName() {
|
public static String getRealName() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getRealName).orElse("郑军榕");
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getRealName).orElse("郑军榕");
|
||||||
|
return getUser().getRealName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDepartName() {
|
public static String getDepartName() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getDepartName).orElse(null);
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getDepartName).orElse(null);
|
||||||
|
return getUser().getDepartName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Long> getAruList() {
|
public static List<Long> getAruList() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getAruList).orElse(null);
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getAruList).orElse(null);
|
||||||
|
return getUser().getAruList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取岗位代码
|
// 获取岗位代码
|
||||||
public static Integer getQueryData() {
|
public static Integer getQueryData() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getQueryData).orElse(null);
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getQueryData).orElse(null);
|
||||||
|
return getUser().getQueryData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFullDeptName() {
|
public static String getFullDeptName() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getFullDeptName).orElse(null);
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getFullDeptName).orElse(null);
|
||||||
|
return getUser().getFullDeptName();
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取2级部门以下
|
// //获取2级部门以下
|
||||||
public static String getSecondFullDeptName() {
|
// public static String getSecondFullDeptName() {
|
||||||
String depName = Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getFullDeptName).orElse("");
|
// String depName = Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getFullDeptName).orElse("");
|
||||||
|
//
|
||||||
depName= StrUtil.replace(depName,"OU=","").replace("福建南方路面机械有限公司,DC=nflg","");
|
// depName= StrUtil.replace(depName,"OU=","").replace("福建南方路面机械有限公司,DC=nflg","");
|
||||||
List<String> depts = new ArrayList<>(Arrays.asList(StrUtil.split(depName, ",")));
|
// List<String> depts = new ArrayList<>(Arrays.asList(StrUtil.split(depName, ",")));
|
||||||
depts.remove("");
|
// depts.remove("");
|
||||||
Collections.reverse(depts );
|
// Collections.reverse(depts );
|
||||||
return StrUtil.join("/",depts);
|
// return StrUtil.join("/",depts);
|
||||||
|
//
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static String getLanguage() {
|
public static String getLanguage() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getLanguage).orElse("");
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getLanguage).orElse("");
|
||||||
|
return getUser().getLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSessionKey() {
|
public static String getSessionKey() {
|
||||||
return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getSessionKey).orElse(null);
|
//return Optional.ofNullable(loginUser.get()).map(LoginUserInfoDTO::getSessionKey).orElse(null);
|
||||||
|
return getUser().getSessionKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LoginUserInfoDTO getUser() {
|
||||||
|
return Optional.ofNullable(BaseApi.loginUser.get())
|
||||||
|
.orElseThrow(() -> new NflgBusinessException(STATE.LoginError, "请登录"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue