| | |
| | | import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; |
| | | import com.baomidou.mybatisplus.core.MybatisConfiguration; |
| | | import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory; |
| | | import com.baomidou.mybatisplus.extension.parser.JsqlParserGlobal; |
| | | import com.baomidou.mybatisplus.extension.parser.cache.JdkSerialCaffeineJsqlParseCache; |
| | | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
| | | import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; |
| | | import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; |
| | |
| | | import com.vincent.rsf.server.system.entity.User; |
| | | import net.sf.jsqlparser.expression.Expression; |
| | | import net.sf.jsqlparser.expression.LongValue; |
| | | import net.sf.jsqlparser.expression.NullValue; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.security.core.Authentication; |
| | |
| | | import org.springframework.transaction.annotation.EnableTransactionManagement; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * MybatisPlus配置 |
| | |
| | | @EnableTransactionManagement |
| | | public class MybatisPlusConfig { |
| | | |
| | | private static volatile boolean jsqlParserConfigured = false; |
| | | |
| | | @Bean |
| | | public MybatisPlusInterceptor mybatisPlusInterceptor() { |
| | | configureJsqlParser(); |
| | | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
| | | |
| | | // 添加乐观锁插件 |
| | |
| | | "sys_menu", |
| | | "sys_pda_role_menu", |
| | | "sys_menu_pda", |
| | | "sys_matnr_role_menu", |
| | | "sys_warehouse_role_menu", |
| | | "man_loc_type_rela", |
| | | "man_qly_inspect_result", |
| | | "view_stock_manage", |
| | |
| | | interceptor.addInnerInterceptor(paginationInnerInterceptor); |
| | | |
| | | return interceptor; |
| | | } |
| | | |
| | | private void configureJsqlParser() { |
| | | if (jsqlParserConfigured) { |
| | | return; |
| | | } |
| | | synchronized (MybatisPlusConfig.class) { |
| | | if (jsqlParserConfigured) { |
| | | return; |
| | | } |
| | | AtomicInteger threadIndex = new AtomicInteger(1); |
| | | int parserThreads = Math.max(4, Runtime.getRuntime().availableProcessors()); |
| | | ThreadPoolExecutor parserExecutor = new ThreadPoolExecutor( |
| | | parserThreads, |
| | | parserThreads, |
| | | 0L, |
| | | TimeUnit.MILLISECONDS, |
| | | new LinkedBlockingQueue<>(2048), |
| | | runnable -> { |
| | | Thread thread = new Thread(runnable); |
| | | thread.setName("jsql-parser-" + threadIndex.getAndIncrement()); |
| | | thread.setDaemon(true); |
| | | return thread; |
| | | }, |
| | | new ThreadPoolExecutor.CallerRunsPolicy() |
| | | ); |
| | | JsqlParserGlobal.setExecutorService(parserExecutor, new Thread(() -> { |
| | | if (!parserExecutor.isShutdown()) { |
| | | parserExecutor.shutdown(); |
| | | } |
| | | }, "jsql-parser-shutdown")); |
| | | JsqlParserGlobal.setJsqlParseCache(new JdkSerialCaffeineJsqlParseCache(builder -> |
| | | builder.maximumSize(1024).expireAfterAccess(30, TimeUnit.MINUTES))); |
| | | jsqlParserConfigured = true; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | }; |
| | | } |
| | | } |
| | | |