feat(): 增加mybatis-plus元数据填充
parent
3009c07ed6
commit
0b02eeac8a
|
@ -141,10 +141,17 @@
|
|||
<artifactId>apm-toolkit-logback-1.x</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- HuTool 工具类 -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot 单元测试框架 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.common.core.basic;
|
||||
|
||||
/**
|
||||
* @author dongzeliang
|
||||
* @version 1.0
|
||||
* @description: 权限获取标准接口
|
||||
* @date 2025/3/1 11:57
|
||||
*/
|
||||
public interface SecurityBasic {
|
||||
|
||||
/**
|
||||
* 获取当前登录用户的用户名称
|
||||
* @return 当前登录用户名称
|
||||
*/
|
||||
public String getUsername();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.core.config;
|
||||
package com.muyu.common.core.mybatisplus;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.common.core.mybatisplus;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.muyu.common.core.basic.SecurityBasic;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 框架字段自动填充器
|
||||
* @author dongzeliang
|
||||
* @version 1.0
|
||||
* @description: 框架字段自动填充器
|
||||
* @date 2025/3/1 11:51
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@ConditionalOnProperty(value = "basic.mybatis-plus.meta.enabled", havingValue = "true")
|
||||
public class SystemMetaObjectHandler implements MetaObjectHandler {
|
||||
|
||||
private final SecurityBasic securityBasic;
|
||||
|
||||
/**
|
||||
* 插入元对象字段填充(用于插入时对公共字段的填充)
|
||||
*
|
||||
* @param metaObject 元对象
|
||||
*/
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
this.strictInsertFill(metaObject, "createBy", String.class, securityBasic.getUsername());
|
||||
this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新元对象字段填充(用于更新时对公共字段的填充)
|
||||
*
|
||||
* @param metaObject 元对象
|
||||
*/
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
|
||||
this.strictInsertFill(metaObject, "updateBy", String.class, securityBasic.getUsername());
|
||||
this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
com.muyu.common.core.utils.SpringUtils
|
||||
com.muyu.common.core.feign.FeginConfig
|
||||
com.muyu.common.core.config.MybatisPlusConfig
|
||||
com.muyu.common.core.mybatisplus.MybatisPlusConfig
|
||||
com.muyu.common.core.mybatisplus.SystemMetaObjectHandler
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.common.security.service;
|
||||
|
||||
import com.muyu.common.core.basic.SecurityBasic;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
|
||||
/**
|
||||
* 登陆信息标准实现
|
||||
* @author dongzeliang
|
||||
* @version 1.0
|
||||
* @description: 登陆信息标准实现
|
||||
* @date 2025/3/1 11:59
|
||||
*/
|
||||
public class SecurityBasicImpl implements SecurityBasic {
|
||||
|
||||
/**
|
||||
* 获取当前登录用户的用户名称
|
||||
*
|
||||
* @return 当前登录用户名称
|
||||
*/
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return SecurityUtils.getUsername();
|
||||
}
|
||||
}
|
|
@ -3,3 +3,4 @@ com.muyu.common.security.service.TokenService
|
|||
com.muyu.common.security.aspect.PreAuthorizeAspect
|
||||
com.muyu.common.security.aspect.InnerAuthAspect
|
||||
com.muyu.common.security.handler.GlobalExceptionHandler
|
||||
com.muyu.common.security.service.SecurityBasicImpl
|
|
@ -9,10 +9,14 @@ import com.muyu.gateway.service.ValidateCodeService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* 验证码过滤器
|
||||
|
@ -64,13 +68,13 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object> {
|
|||
|
||||
private String resolveBodyFromRequest (ServerHttpRequest serverHttpRequest) {
|
||||
// 获取请求体
|
||||
return DataBufferUtils.join(serverHttpRequest.getBody())
|
||||
.map(dataBuffer -> {
|
||||
byte[] bytes = new byte[dataBuffer.readableByteCount()];
|
||||
dataBuffer.read(bytes);
|
||||
DataBufferUtils.release(dataBuffer);
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
})
|
||||
.block();
|
||||
Flux<DataBuffer> dataBufferFlux = serverHttpRequest.getBody();
|
||||
AtomicReference<String> bodyStr = new AtomicReference<>();
|
||||
dataBufferFlux.cache().subscribe(dataBuffer -> {
|
||||
byte[] bytes = new byte[dataBuffer.readableByteCount()];
|
||||
dataBuffer.read(bytes);
|
||||
bodyStr.set(new String(bytes, StandardCharsets.UTF_8));
|
||||
});
|
||||
return bodyStr.get();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue