Commit 224980aa1a13e562cbf477c10666940e448f1717
1 parent
495ef72a
feat: 使用 jdk instanceof 新特性
Showing
7 changed files
with
12 additions
and
20 deletions
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/mq/rabbitmq/TenantRabbitMQInitializer.java
| @@ -13,11 +13,10 @@ public class TenantRabbitMQInitializer implements BeanPostProcessor { | @@ -13,11 +13,10 @@ public class TenantRabbitMQInitializer implements BeanPostProcessor { | ||
| 13 | 13 | ||
| 14 | @Override | 14 | @Override |
| 15 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | 15 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { |
| 16 | - if (bean instanceof RabbitTemplate) { | ||
| 17 | - RabbitTemplate rabbitTemplate = (RabbitTemplate) bean; | 16 | + if (bean instanceof RabbitTemplate rabbitTemplate) { |
| 18 | rabbitTemplate.addBeforePublishPostProcessors(new TenantRabbitMQMessagePostProcessor()); | 17 | rabbitTemplate.addBeforePublishPostProcessors(new TenantRabbitMQMessagePostProcessor()); |
| 19 | } | 18 | } |
| 20 | return bean; | 19 | return bean; |
| 21 | } | 20 | } |
| 22 | 21 | ||
| 23 | -} | ||
| 24 | \ No newline at end of file | 22 | \ No newline at end of file |
| 23 | +} |
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/mq/rocketmq/TenantRocketMQInitializer.java
| @@ -18,11 +18,9 @@ public class TenantRocketMQInitializer implements BeanPostProcessor { | @@ -18,11 +18,9 @@ public class TenantRocketMQInitializer implements BeanPostProcessor { | ||
| 18 | 18 | ||
| 19 | @Override | 19 | @Override |
| 20 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | 20 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { |
| 21 | - if (bean instanceof DefaultRocketMQListenerContainer) { | ||
| 22 | - DefaultRocketMQListenerContainer container = (DefaultRocketMQListenerContainer) bean; | 21 | + if (bean instanceof DefaultRocketMQListenerContainer container) { |
| 23 | initTenantConsumer(container.getConsumer()); | 22 | initTenantConsumer(container.getConsumer()); |
| 24 | - } else if (bean instanceof RocketMQTemplate) { | ||
| 25 | - RocketMQTemplate template = (RocketMQTemplate) bean; | 23 | + } else if (bean instanceof RocketMQTemplate template) { |
| 26 | initTenantProducer(template.getProducer()); | 24 | initTenantProducer(template.getProducer()); |
| 27 | } | 25 | } |
| 28 | return bean; | 26 | return bean; |
| @@ -50,4 +48,4 @@ public class TenantRocketMQInitializer implements BeanPostProcessor { | @@ -50,4 +48,4 @@ public class TenantRocketMQInitializer implements BeanPostProcessor { | ||
| 50 | consumerImpl.registerConsumeMessageHook(new TenantRocketMQConsumeMessageHook()); | 48 | consumerImpl.registerConsumeMessageHook(new TenantRocketMQConsumeMessageHook()); |
| 51 | } | 49 | } |
| 52 | 50 | ||
| 53 | -} | ||
| 54 | \ No newline at end of file | 51 | \ No newline at end of file |
| 52 | +} |
yudao-framework/yudao-spring-boot-starter-job/src/main/java/cn/iocoder/yudao/framework/quartz/config/YudaoAsyncAutoConfiguration.java
| @@ -23,15 +23,13 @@ public class YudaoAsyncAutoConfiguration { | @@ -23,15 +23,13 @@ public class YudaoAsyncAutoConfiguration { | ||
| 23 | @Override | 23 | @Override |
| 24 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { | 24 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { |
| 25 | // 处理 ThreadPoolTaskExecutor | 25 | // 处理 ThreadPoolTaskExecutor |
| 26 | - if (bean instanceof ThreadPoolTaskExecutor) { | ||
| 27 | - ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean; | 26 | + if (bean instanceof ThreadPoolTaskExecutor executor) { |
| 28 | executor.setTaskDecorator(TtlRunnable::get); | 27 | executor.setTaskDecorator(TtlRunnable::get); |
| 29 | return executor; | 28 | return executor; |
| 30 | } | 29 | } |
| 31 | // 处理 SimpleAsyncTaskExecutor | 30 | // 处理 SimpleAsyncTaskExecutor |
| 32 | // 参考 https://t.zsxq.com/CBoks 增加 | 31 | // 参考 https://t.zsxq.com/CBoks 增加 |
| 33 | - if (bean instanceof SimpleAsyncTaskExecutor) { | ||
| 34 | - SimpleAsyncTaskExecutor executor = (SimpleAsyncTaskExecutor) bean; | 32 | + if (bean instanceof SimpleAsyncTaskExecutor executor) { |
| 35 | executor.setTaskDecorator(TtlRunnable::get); | 33 | executor.setTaskDecorator(TtlRunnable::get); |
| 36 | return executor; | 34 | return executor; |
| 37 | } | 35 | } |
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/handler/DefaultDBFieldHandler.java
| @@ -19,8 +19,7 @@ public class DefaultDBFieldHandler implements MetaObjectHandler { | @@ -19,8 +19,7 @@ public class DefaultDBFieldHandler implements MetaObjectHandler { | ||
| 19 | 19 | ||
| 20 | @Override | 20 | @Override |
| 21 | public void insertFill(MetaObject metaObject) { | 21 | public void insertFill(MetaObject metaObject) { |
| 22 | - if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BaseDO) { | ||
| 23 | - BaseDO baseDO = (BaseDO) metaObject.getOriginalObject(); | 22 | + if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BaseDO baseDO) { |
| 24 | 23 | ||
| 25 | LocalDateTime current = LocalDateTime.now(); | 24 | LocalDateTime current = LocalDateTime.now(); |
| 26 | // 创建时间为空,则以当前时间为插入时间 | 25 | // 创建时间为空,则以当前时间为插入时间 |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
| @@ -184,8 +184,7 @@ public class GlobalExceptionHandler { | @@ -184,8 +184,7 @@ public class GlobalExceptionHandler { | ||
| 184 | @ExceptionHandler(HttpMessageNotReadableException.class) | 184 | @ExceptionHandler(HttpMessageNotReadableException.class) |
| 185 | public CommonResult<?> methodArgumentTypeInvalidFormatExceptionHandler(HttpMessageNotReadableException ex) { | 185 | public CommonResult<?> methodArgumentTypeInvalidFormatExceptionHandler(HttpMessageNotReadableException ex) { |
| 186 | log.warn("[methodArgumentTypeInvalidFormatExceptionHandler]", ex); | 186 | log.warn("[methodArgumentTypeInvalidFormatExceptionHandler]", ex); |
| 187 | - if (ex.getCause() instanceof InvalidFormatException) { | ||
| 188 | - InvalidFormatException invalidFormatException = (InvalidFormatException) ex.getCause(); | 187 | + if (ex.getCause() instanceof InvalidFormatException invalidFormatException) { |
| 189 | return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数类型错误:%s", invalidFormatException.getValue())); | 188 | return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数类型错误:%s", invalidFormatException.getValue())); |
| 190 | } | 189 | } |
| 191 | if (StrUtil.startWith(ex.getMessage(), "Required request body is missing")) { | 190 | if (StrUtil.startWith(ex.getMessage(), "Required request body is missing")) { |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java
| @@ -146,10 +146,9 @@ public class WebFrameworkUtils { | @@ -146,10 +146,9 @@ public class WebFrameworkUtils { | ||
| 146 | 146 | ||
| 147 | public static HttpServletRequest getRequest() { | 147 | public static HttpServletRequest getRequest() { |
| 148 | RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); | 148 | RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); |
| 149 | - if (!(requestAttributes instanceof ServletRequestAttributes)) { | 149 | + if (!(requestAttributes instanceof ServletRequestAttributes servletRequestAttributes)) { |
| 150 | return null; | 150 | return null; |
| 151 | } | 151 | } |
| 152 | - ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes; | ||
| 153 | return servletRequestAttributes.getRequest(); | 152 | return servletRequestAttributes.getRequest(); |
| 154 | } | 153 | } |
| 155 | 154 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/framework/justauth/core/AuthRequestFactory.java
| @@ -77,8 +77,8 @@ public class AuthRequestFactory { | @@ -77,8 +77,8 @@ public class AuthRequestFactory { | ||
| 77 | extendList = extend.getConfig() | 77 | extendList = extend.getConfig() |
| 78 | .keySet() | 78 | .keySet() |
| 79 | .stream() | 79 | .stream() |
| 80 | - .filter(x -> names.contains(x.toUpperCase())) | ||
| 81 | .map(String::toUpperCase) | 80 | .map(String::toUpperCase) |
| 81 | + .filter(names::contains) | ||
| 82 | .collect(Collectors.toList()); | 82 | .collect(Collectors.toList()); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| @@ -318,4 +318,4 @@ public class AuthRequestFactory { | @@ -318,4 +318,4 @@ public class AuthRequestFactory { | ||
| 318 | .proxy(new Proxy(Proxy.Type.valueOf(proxyConfig.getType()), new InetSocketAddress(proxyConfig.getHostname(), proxyConfig.getPort()))) | 318 | .proxy(new Proxy(Proxy.Type.valueOf(proxyConfig.getType()), new InetSocketAddress(proxyConfig.getHostname(), proxyConfig.getPort()))) |
| 319 | .build()); | 319 | .build()); |
| 320 | } | 320 | } |
| 321 | -} | ||
| 322 | \ No newline at end of file | 321 | \ No newline at end of file |
| 322 | +} |