refactor(backend): optimize service layer and add transaction support
- Add TransactionManagerConfig for reactive transaction management - Add OperationLogWebFilter for operation logging - Remove deprecated AuditLogAspect in favor of WebFilter approach - Optimize service implementations (SysUserService, SysRoleService, etc.) - Enhance audit log functionality with better error handling - Update security configuration and tests - Add operation_log table migration script - Improve IP utility with better validation
This commit is contained in:
@@ -42,6 +42,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
|
||||
+35
-4
@@ -1,16 +1,24 @@
|
||||
package cn.novalon.gym.manage.app;
|
||||
|
||||
import cn.novalon.gym.manage.sys.core.service.IOperationLogService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = "cn.novalon.gym.manage", exclude = {ReactiveUserDetailsServiceAutoConfiguration.class})
|
||||
@EnableR2dbcRepositories(basePackages = {"cn.novalon.gym.manage.db.dao", "cn.novalon.gym.manage.sys.audit.repository"})
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = "cn.novalon.gym.manage", exclude = {
|
||||
ReactiveUserDetailsServiceAutoConfiguration.class })
|
||||
@EnableR2dbcRepositories(basePackages = { "cn.novalon.gym.manage.db.dao",
|
||||
"cn.novalon.gym.manage.sys.audit.repository" })
|
||||
public class ManageApplication {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ManageApplication.class);
|
||||
@@ -18,9 +26,32 @@ public class ManageApplication {
|
||||
public static void main(String[] args) {
|
||||
logger.info("应用程序启动中...");
|
||||
logger.info("包扫描路径: cn.novalon.gym.manage");
|
||||
|
||||
// 使用简单的启动方式,避免自动配置问题
|
||||
|
||||
SpringApplication.run(ManageApplication.class, args);
|
||||
logger.info("应用程序启动完成");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner checkWebFilters(List<WebFilter> webFilters) {
|
||||
return args -> {
|
||||
logger.info("=== 检查已注册的 WebFilter ===");
|
||||
logger.info("WebFilter 总数: {}", webFilters.size());
|
||||
for (WebFilter filter : webFilters) {
|
||||
logger.info(" - {} (Order: {})",
|
||||
filter.getClass().getName(),
|
||||
filter.getClass().getAnnotation(org.springframework.core.annotation.Order.class) != null
|
||||
? filter.getClass().getAnnotation(org.springframework.core.annotation.Order.class)
|
||||
.value()
|
||||
: "无");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner checkOperationLogService(IOperationLogService service) {
|
||||
return args -> {
|
||||
logger.info("=== 检查 IOperationLogService ===");
|
||||
logger.info("IOperationLogService 实现: {}", service.getClass().getName());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package cn.novalon.gym.manage.app.config;
|
||||
|
||||
import io.r2dbc.spi.ConnectionFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.transaction.ReactiveTransactionManager;
|
||||
import org.springframework.transaction.reactive.TransactionalOperator;
|
||||
import org.springframework.r2dbc.connection.R2dbcTransactionManager;
|
||||
|
||||
@Configuration
|
||||
public class TransactionManagerConfig {
|
||||
|
||||
@Bean(name = "connectionFactoryTransactionManager")
|
||||
@Primary
|
||||
public ReactiveTransactionManager reactiveTransactionManager(ConnectionFactory connectionFactory) {
|
||||
return new R2dbcTransactionManager(connectionFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public TransactionalOperator transactionalOperator(ReactiveTransactionManager reactiveTransactionManager) {
|
||||
return TransactionalOperator.create(reactiveTransactionManager);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,10 @@ spring:
|
||||
logging:
|
||||
level:
|
||||
cn.novalon.manage: DEBUG
|
||||
cn.novalon.gym.manage: DEBUG
|
||||
cn.novalon.gym.manage.sys.audit: DEBUG
|
||||
org.springframework.r2dbc: DEBUG
|
||||
cn.novalon.manage.db: DEBUG
|
||||
org.flywaydb: DEBUG
|
||||
org.flywaydb: DEBUG
|
||||
|
||||
debug: true
|
||||
Reference in New Issue
Block a user