代码优化

This commit is contained in:
smallchill 2018-12-24 13:22:49 +08:00
parent 474db1b5ec
commit 8058ca9e06
5 changed files with 39 additions and 4 deletions

View File

@ -67,7 +67,7 @@ public class BladeController {
* @return * @return
*/ */
public BladeUser getUser() { public BladeUser getUser() {
return SecureUtil.getUser(request); return SecureUtil.getUser();
} }
/** ============================ API_RESULT ================================================= */ /** ============================ API_RESULT ================================================= */

View File

@ -65,7 +65,7 @@ public class ApiLogListener {
logApi.setRequestUri(URLUtil.getPath(request.getRequestURI())); logApi.setRequestUri(URLUtil.getPath(request.getRequestURI()));
logApi.setMethod(request.getMethod()); logApi.setMethod(request.getMethod());
logApi.setParams(WebUtil.getRequestParamString(request)); logApi.setParams(WebUtil.getRequestParamString(request));
logApi.setCreateBy(SecureUtil.getUser(request).getAccount()); logApi.setCreateBy(SecureUtil.getUserAccount(request).getAccount());
logApi.setCreateTime(LocalDateTime.now()); logApi.setCreateTime(LocalDateTime.now());
logService.saveApiLog(logApi); logService.saveApiLog(logApi);
} }

View File

@ -62,7 +62,7 @@ public class BladeLogListener {
logBlade.setServerHost(serverInfo.getHostName()); logBlade.setServerHost(serverInfo.getHostName());
logBlade.setServerIp(serverInfo.getIPWithPort()); logBlade.setServerIp(serverInfo.getIPWithPort());
logBlade.setEnv(bladeProperties.getEnv()); logBlade.setEnv(bladeProperties.getEnv());
logBlade.setCreateBy(SecureUtil.getUser(request).getAccount()); logBlade.setCreateBy(SecureUtil.getUserAccount(request));
logBlade.setCreateTime(LocalDateTime.now()); logBlade.setCreateTime(LocalDateTime.now());
logService.saveBladeLog(logBlade); logService.saveBladeLog(logBlade);
} }

View File

@ -60,7 +60,7 @@ public class ErrorLogListener {
logError.setServerHost(serverInfo.getHostName()); logError.setServerHost(serverInfo.getHostName());
logError.setServerIp(serverInfo.getIPWithPort()); logError.setServerIp(serverInfo.getIPWithPort());
logError.setEnv(bladeProperties.getEnv()); logError.setEnv(bladeProperties.getEnv());
logError.setCreateBy(SecureUtil.getUser(request).getAccount()); logError.setCreateBy(SecureUtil.getUserAccount(request).getAccount());
logError.setCreateTime(LocalDateTime.now()); logError.setCreateTime(LocalDateTime.now());
logService.saveErrorLog(logError); logService.saveErrorLog(logError);
} }

View File

@ -24,6 +24,7 @@ import org.springblade.core.tool.date.DateField;
import org.springblade.core.tool.date.DateTime; import org.springblade.core.tool.date.DateTime;
import org.springblade.core.tool.date.DateUtil; import org.springblade.core.tool.date.DateUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.WebUtil; import org.springblade.core.tool.utils.WebUtil;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
@ -89,6 +90,40 @@ public class SecureUtil {
return bladeUser; return bladeUser;
} }
/**
* 获取用户id
* @return
*/
public static Integer getUserId() {
return (null == getUser()) ? -1 : getUser().getUserId();
}
/**
* 获取用户id
* @return
*/
public static Integer getUserId(HttpServletRequest request) {
return (null == getUser(request)) ? -1 : getUser().getUserId();
}
/**
* 获取用户账号
* @return
*/
public static String getUserAccount() {
return (null == getUser()) ? StringPool.EMPTY : getUser().getAccount();
}
/**
* 获取用户账号
* @return
*/
public static String getUserAccount(HttpServletRequest request) {
return (null == getUser(request)) ? StringPool.EMPTY : getUser().getAccount();
}
/** /**
* 获取Claims * 获取Claims
* *