Merge branch 'master' into unit_system_dept

# Conflicts:
#	src/main/java/cn/iocoder/dashboard/framework/mybatis/core/dataobject/BaseDO.java
This commit is contained in:
niudehua 2021-03-09 19:07:43 +08:00
commit e06256da1e
4 changed files with 36 additions and 10 deletions

View File

@ -1,5 +1,7 @@
package cn.iocoder.dashboard.framework.mybatis.config; package cn.iocoder.dashboard.framework.mybatis.config;
import cn.iocoder.dashboard.framework.mybatis.core.handle.DefaultDBFieldHandler;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -24,4 +26,9 @@ public class MybatisConfiguration {
return mybatisPlusInterceptor; return mybatisPlusInterceptor;
} }
@Bean
public MetaObjectHandler defaultMetaObjectHandler(){
return new DefaultDBFieldHandler(); // 自动填充参数类
}
} }

View File

@ -22,7 +22,7 @@ public class BaseDO implements Serializable {
/** /**
* 最后更新时间 * 最后更新时间
*/ */
@TableField(fill = FieldFill.UPDATE) @TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime; private Date updateTime;
/** /**
* 创建者 * 创建者
@ -32,7 +32,7 @@ public class BaseDO implements Serializable {
/** /**
* 更新者 * 更新者
*/ */
@TableField(fill = FieldFill.UPDATE) @TableField(fill = FieldFill.INSERT_UPDATE)
private String updater; private String updater;
/** /**
* 是否删除 * 是否删除

View File

@ -2,7 +2,10 @@ package cn.iocoder.dashboard.framework.security.core.util;
import cn.iocoder.dashboard.framework.security.core.LoginUser; import cn.iocoder.dashboard.framework.security.core.LoginUser;
import cn.iocoder.dashboard.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.dashboard.framework.web.core.util.WebFrameworkUtils;
import org.springframework.lang.Nullable;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -40,9 +43,20 @@ public class SecurityFrameworkUtils {
/** /**
* 获取当前用户 * 获取当前用户
*
* @return 当前用户
*/ */
@Nullable
public static LoginUser getLoginUser() { public static LoginUser getLoginUser() {
return (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); SecurityContext context = SecurityContextHolder.getContext();
if (context == null) {
return null;
}
Authentication authentication = context.getAuthentication();
if (authentication == null) {
return null;
}
return (LoginUser) authentication.getPrincipal();
} }
/** /**
@ -50,8 +64,10 @@ public class SecurityFrameworkUtils {
* *
* @return 用户编号 * @return 用户编号
*/ */
@Nullable
public static Long getLoginUserId() { public static Long getLoginUserId() {
return getLoginUser().getId(); LoginUser loginUser = getLoginUser();
return loginUser != null ? loginUser.getId() : null;
} }
/** /**
@ -59,8 +75,10 @@ public class SecurityFrameworkUtils {
* *
* @return 角色编号数组 * @return 角色编号数组
*/ */
@Nullable
public static Set<Long> getLoginUserRoleIds() { public static Set<Long> getLoginUserRoleIds() {
return getLoginUser().getRoleIds(); LoginUser loginUser = getLoginUser();
return loginUser != null ? loginUser.getRoleIds() : null;
} }
/** /**

View File

@ -162,22 +162,23 @@ public class SysAuthServiceImpl implements SysAuthService {
public void logout(String token) { public void logout(String token) {
// 查询用户信息 // 查询用户信息
LoginUser loginUser = userSessionService.getLoginUser(token); LoginUser loginUser = userSessionService.getLoginUser(token);
if(loginUser == null) { if (loginUser == null) {
return; return;
} }
// 删除session // 删除 session
userSessionService.deleteUserSession(token); userSessionService.deleteUserSession(token);
this.createLogoutLog(loginUser.getUsername(), SysLoginResultEnum.SUCCESS); // 记录登出日子和
this.createLogoutLog(loginUser.getUsername());
} }
private void createLogoutLog(String username, SysLoginResultEnum loginResult) { private void createLogoutLog(String username) {
SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO(); SysLoginLogCreateReqVO reqVO = new SysLoginLogCreateReqVO();
reqVO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); reqVO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType());
reqVO.setTraceId(TracerUtils.getTraceId()); reqVO.setTraceId(TracerUtils.getTraceId());
reqVO.setUsername(username); reqVO.setUsername(username);
reqVO.setUserAgent(ServletUtils.getUserAgent()); reqVO.setUserAgent(ServletUtils.getUserAgent());
reqVO.setUserIp(ServletUtils.getClientIP()); reqVO.setUserIp(ServletUtils.getClientIP());
reqVO.setResult(loginResult.getResult()); reqVO.setResult(SysLoginResultEnum.SUCCESS.getResult());
loginLogService.createLoginLog(reqVO); loginLogService.createLoginLog(reqVO);
} }