From 57da2e33a6d03cbf188b915144d1be553e622f1b Mon Sep 17 00:00:00 2001 From: zlyx <1242874891@qq.com> Date: Thu, 19 Jan 2023 20:03:26 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E7=AE=80=E5=8C=96=20stream=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=86=99=E6=B3=95=20(java=2016)=20xx.collect?= =?UTF-8?q?(Collectors.toList())=20=3D>=20xx.toList()=20;=20update=20?= =?UTF-8?q?=E7=AE=80=E5=8C=96=20instanceof=20=E4=BB=A3=E7=A0=81=E5=86=99?= =?UTF-8?q?=E6=B3=95=20(java=2012)=20=E7=9B=B4=E6=8E=A5=E5=9C=A8=E5=90=8E?= =?UTF-8?q?=E9=9D=A2=E5=AE=9A=E4=B9=89=E5=8F=98=E9=87=8F=20;=20update=20?= =?UTF-8?q?=E7=AE=80=E5=8C=96=20switch=20=E4=BB=A3=E7=A0=81=E5=86=99?= =?UTF-8?q?=E6=B3=95=20(java=2012)=20;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/common/core/utils/StreamUtils.java | 6 +++--- .../ruoyi/common/excel/core/DefaultExcelListener.java | 6 ++---- .../common/idempotent/aspectj/RepeatSubmitAspect.java | 3 +-- .../handler/CreateAndUpdateMetaObjectHandler.java | 6 ++---- .../mybatis/handler/PlusDataPermissionHandler.java | 2 +- .../common/mybatis/helper/DataPermissionHelper.java | 4 ++-- .../interceptor/PlusDataPermissionInterceptor.java | 3 +-- .../main/java/com/ruoyi/common/oss/core/OssClient.java | 9 +++------ .../java/com/ruoyi/common/redis/utils/RedisUtils.java | 2 +- .../ruoyi/system/controller/monitor/CacheController.java | 2 +- .../com/ruoyi/system/service/impl/SysOssServiceImpl.java | 2 +- 11 files changed, 18 insertions(+), 27 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StreamUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StreamUtils.java index b11fa519..b851d5cc 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StreamUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StreamUtils.java @@ -30,7 +30,7 @@ public class StreamUtils { if (CollUtil.isEmpty(collection)) { return CollUtil.newArrayList(); } - return collection.stream().filter(function).collect(Collectors.toList()); + return collection.stream().filter(function).toList(); } /** @@ -70,7 +70,7 @@ public class StreamUtils { if (CollUtil.isEmpty(collection)) { return CollUtil.newArrayList(); } - return collection.stream().sorted(comparing).collect(Collectors.toList()); + return collection.stream().sorted(comparing).toList(); } /** @@ -188,7 +188,7 @@ public class StreamUtils { .stream() .map(function) .filter(Objects::nonNull) - .collect(Collectors.toList()); + .toList(); } /** diff --git a/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/core/DefaultExcelListener.java b/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/core/DefaultExcelListener.java index a94f2d09..759b1ac5 100644 --- a/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/core/DefaultExcelListener.java +++ b/ruoyi-common/ruoyi-common-excel/src/main/java/com/ruoyi/common/excel/core/DefaultExcelListener.java @@ -55,9 +55,8 @@ public class DefaultExcelListener extends AnalysisEventListener implements @Override public void onException(Exception exception, AnalysisContext context) throws Exception { String errMsg = null; - if (exception instanceof ExcelDataConvertException) { + if (exception instanceof ExcelDataConvertException excelDataConvertException) { // 如果是某一个单元格的转换异常 能获取到具体行号 - ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception; Integer rowIndex = excelDataConvertException.getRowIndex(); Integer columnIndex = excelDataConvertException.getColumnIndex(); errMsg = StrUtil.format("第{}行-第{}列-表头{}: 解析异常
", @@ -66,8 +65,7 @@ public class DefaultExcelListener extends AnalysisEventListener implements log.error(errMsg); } } - if (exception instanceof ConstraintViolationException) { - ConstraintViolationException constraintViolationException = (ConstraintViolationException) exception; + if (exception instanceof ConstraintViolationException constraintViolationException) { Set> constraintViolations = constraintViolationException.getConstraintViolations(); String constraintViolationsMsg = StreamUtils.join(constraintViolations, ConstraintViolation::getMessage, ", "); errMsg = StrUtil.format("第{}行数据校验异常: {}", context.readRowHolder().getRowIndex() + 1, constraintViolationsMsg); diff --git a/ruoyi-common/ruoyi-common-idempotent/src/main/java/com/ruoyi/common/idempotent/aspectj/RepeatSubmitAspect.java b/ruoyi-common/ruoyi-common-idempotent/src/main/java/com/ruoyi/common/idempotent/aspectj/RepeatSubmitAspect.java index b5d3564f..f7cbf31f 100644 --- a/ruoyi-common/ruoyi-common-idempotent/src/main/java/com/ruoyi/common/idempotent/aspectj/RepeatSubmitAspect.java +++ b/ruoyi-common/ruoyi-common-idempotent/src/main/java/com/ruoyi/common/idempotent/aspectj/RepeatSubmitAspect.java @@ -78,9 +78,8 @@ public class RepeatSubmitAspect { */ @AfterReturning(pointcut = "@annotation(repeatSubmit)", returning = "jsonResult") public void doAfterReturning(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Object jsonResult) { - if (jsonResult instanceof R) { + if (jsonResult instanceof R r) { try { - R r = (R) jsonResult; // 成功则不删除redis数据 保证在有效时间内无法重复提交 if (r.getCode() == R.SUCCESS) { return; diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java index 4ab329de..5388ae58 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/CreateAndUpdateMetaObjectHandler.java @@ -25,8 +25,7 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { @Override public void insertFill(MetaObject metaObject) { try { - if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) { - BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject(); + if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity baseEntity) { Date current = ObjectUtil.isNotNull(baseEntity.getCreateTime()) ? baseEntity.getCreateTime() : new Date(); baseEntity.setCreateTime(current); @@ -46,8 +45,7 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { @Override public void updateFill(MetaObject metaObject) { try { - if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity) { - BaseEntity baseEntity = (BaseEntity) metaObject.getOriginalObject(); + if (ObjectUtil.isNotNull(metaObject) && metaObject.getOriginalObject() instanceof BaseEntity baseEntity) { Date current = new Date(); // 更新时间填充(不管为不为空) baseEntity.setUpdateTime(current); diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/PlusDataPermissionHandler.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/PlusDataPermissionHandler.java index 95535252..42e238a1 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/PlusDataPermissionHandler.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/handler/PlusDataPermissionHandler.java @@ -163,7 +163,7 @@ public class PlusDataPermissionHandler { String methodName = sb.substring(index + 1, sb.length()); Class clazz = ClassUtil.loadClass(clazzName); List methods = Arrays.stream(ClassUtil.getDeclaredMethods(clazz)) - .filter(method -> method.getName().equals(methodName)).collect(Collectors.toList()); + .filter(method -> method.getName().equals(methodName)).toList(); DataPermission dataPermission; // 获取方法注解 for (Method method : methods) { diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/helper/DataPermissionHelper.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/helper/DataPermissionHelper.java index 9555b014..20941662 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/helper/DataPermissionHelper.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/helper/DataPermissionHelper.java @@ -39,8 +39,8 @@ public class DataPermissionHelper { saStorage.set(DATA_PERMISSION_KEY, new HashMap<>()); attribute = saStorage.get(DATA_PERMISSION_KEY); } - if (attribute instanceof Map) { - return (Map) attribute; + if (attribute instanceof Map map) { + return map; } throw new NullPointerException("data permission context type exception"); } diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/interceptor/PlusDataPermissionInterceptor.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/interceptor/PlusDataPermissionInterceptor.java index 9b6a0b07..fd4ffcd0 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/interceptor/PlusDataPermissionInterceptor.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/com/ruoyi/common/mybatis/interceptor/PlusDataPermissionInterceptor.java @@ -68,8 +68,7 @@ public class PlusDataPermissionInterceptor extends JsqlParserSupport implements SelectBody selectBody = select.getSelectBody(); if (selectBody instanceof PlainSelect) { this.setWhere((PlainSelect) selectBody, (String) obj); - } else if (selectBody instanceof SetOperationList) { - SetOperationList setOperationList = (SetOperationList) selectBody; + } else if (selectBody instanceof SetOperationList setOperationList) { List selectBodyList = setOperationList.getSelects(); selectBodyList.forEach(s -> this.setWhere((PlainSelect) s, (String) obj)); } diff --git a/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java b/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java index 0e5e881b..302b229f 100644 --- a/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java +++ b/ruoyi-common/ruoyi-common-oss/src/main/java/com/ruoyi/common/oss/core/OssClient.java @@ -221,15 +221,12 @@ public class OssClient { } builder.append("{\n\"Action\": "); switch (policyType) { - case WRITE: + case WRITE -> builder.append("[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n"); - break; - case READ_WRITE: + case READ_WRITE -> builder.append("[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:GetObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n"); - break; - default: + default -> builder.append("\"s3:GetObject\",\n"); - break; } builder.append("\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::"); builder.append(bucketName); diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/utils/RedisUtils.java b/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/utils/RedisUtils.java index b665160d..79ea3b8e 100644 --- a/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/utils/RedisUtils.java +++ b/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/utils/RedisUtils.java @@ -438,7 +438,7 @@ public class RedisUtils { */ public static Collection keys(final String pattern) { Stream stream = CLIENT.getKeys().getKeysStreamByPattern(pattern); - return stream.collect(Collectors.toList()); + return stream.toList(); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/monitor/CacheController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/monitor/CacheController.java index 84f17bc9..ab86b9b3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/monitor/CacheController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/monitor/CacheController.java @@ -94,7 +94,7 @@ public class CacheController { if (isCacheNames(cacheName)) { Set keys = CacheUtils.keys(cacheName); if (CollUtil.isNotEmpty(keys)) { - cacheKeys = keys.stream().map(Object::toString).collect(Collectors.toList()); + cacheKeys = keys.stream().map(Object::toString).toList(); } } else { cacheKeys = RedisUtils.keys(cacheName + "*"); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java index 0caf8408..cc303221 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOssServiceImpl.java @@ -52,7 +52,7 @@ public class SysOssServiceImpl implements ISysOssService { public TableDataInfo queryPageList(SysOssBo bo, PageQuery pageQuery) { LambdaQueryWrapper lqw = buildQueryWrapper(bo); Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); - List filterResult = result.getRecords().stream().map(this::matchingUrl).collect(Collectors.toList()); + List filterResult = result.getRecords().stream().map(this::matchingUrl).toList(); result.setRecords(filterResult); return TableDataInfo.build(result); }