mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
修改mybatis自动插入的creator updater 字段为用户昵称
This commit is contained in:
+5
-4
@@ -33,13 +33,14 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
|
||||
}
|
||||
|
||||
Long userId = WebFrameworkUtils.getLoginUserId();
|
||||
String loginUserName = WebFrameworkUtils.getLoginUserName();
|
||||
// 当前登录用户不为空,创建人为空,则当前登录用户为创建人
|
||||
if (Objects.nonNull(userId) && Objects.isNull(baseDO.getCreator())) {
|
||||
baseDO.setCreator(userId.toString());
|
||||
if (Objects.nonNull(loginUserName) && Objects.isNull(baseDO.getCreator())) {
|
||||
baseDO.setCreator(loginUserName);
|
||||
}
|
||||
// 当前登录用户不为空,更新人为空,则当前登录用户为更新人
|
||||
if (Objects.nonNull(userId) && Objects.isNull(baseDO.getUpdater())) {
|
||||
baseDO.setUpdater(userId.toString());
|
||||
if (Objects.nonNull(loginUserName) && Objects.isNull(baseDO.getUpdater())) {
|
||||
baseDO.setUpdater(loginUserName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -75,4 +75,8 @@ public class LoginUser {
|
||||
* 数据源编码
|
||||
*/
|
||||
private String dataCode;
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickname;
|
||||
}
|
||||
|
||||
+1
@@ -106,6 +106,7 @@ public class SecurityFrameworkUtils {
|
||||
// 原因是,Spring Security 的 Filter 在 ApiAccessLogFilter 后面,在它记录访问日志时,线上上下文已经没有用户编号等信息
|
||||
WebFrameworkUtils.setLoginUserId(request, loginUser.getId());
|
||||
WebFrameworkUtils.setLoginUserType(request, loginUser.getUserType());
|
||||
WebFrameworkUtils.setLoginUserName(request, loginUser.getNickname());
|
||||
}
|
||||
|
||||
private static Authentication buildAuthentication(LoginUser loginUser, HttpServletRequest request) {
|
||||
|
||||
+26
@@ -25,6 +25,8 @@ public class WebFrameworkUtils {
|
||||
|
||||
private static final String REQUEST_ATTRIBUTE_COMMON_RESULT = "common_result";
|
||||
|
||||
private static final String REQUEST_ATTRIBUTE_LOGIN_USER_NAME = "login-user-name";
|
||||
|
||||
public static final String HEADER_ORGAN_ID = "organ-id";
|
||||
|
||||
/**
|
||||
@@ -56,6 +58,10 @@ public class WebFrameworkUtils {
|
||||
request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID, userId);
|
||||
}
|
||||
|
||||
public static void setLoginUserName(ServletRequest request, String nickname) {
|
||||
request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_NAME, nickname);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户类型
|
||||
*
|
||||
@@ -80,6 +86,20 @@ public class WebFrameworkUtils {
|
||||
return (Long) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前用户的昵称,从请求中
|
||||
* 注意:该方法仅限于 framework 框架使用!!!
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 用户编号
|
||||
*/
|
||||
private static String getLoginUserName(HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
return null;
|
||||
}
|
||||
return (String) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前用户的类型
|
||||
* 注意:该方法仅限于 web 相关的 framework 组件使用!!!
|
||||
@@ -116,6 +136,12 @@ public class WebFrameworkUtils {
|
||||
return getLoginUserId(request);
|
||||
}
|
||||
|
||||
public static String getLoginUserName() {
|
||||
HttpServletRequest request = getRequest();
|
||||
return getLoginUserName(request);
|
||||
}
|
||||
|
||||
|
||||
public static Integer getTerminal() {
|
||||
HttpServletRequest request = getRequest();
|
||||
if (request == null) {
|
||||
|
||||
Reference in New Issue
Block a user