优化代码结构

This commit is contained in:
ajaxfan
2021-04-09 17:53:43 +08:00
parent 36855664a2
commit 88fa5eb9d5
2 changed files with 4 additions and 5 deletions

View File

@ -128,7 +128,7 @@ public class DefaultAttachmentClient implements AttachmentClient {
// 创建压缩文件流 // 创建压缩文件流
createCompressionStream(list, out); createCompressionStream(list, out);
return Optional.ofNullable(out.toByteArray()); return Optional.of(out.toByteArray());
} catch (IOException e) { } catch (IOException e) {
log.error(e.getMessage()); log.error(e.getMessage());
} }
@ -177,8 +177,8 @@ public class DefaultAttachmentClient implements AttachmentClient {
// 创建压缩文件流 // 创建压缩文件流
createCompressionStream(list, out); createCompressionStream(list, out);
return Optional.ofNullable(new DownloadEntity() return Optional.of(new DownloadEntity().setFilename(String.format("%s.zip", UUID.randomUUID()))
.setFilename(String.format("%s.zip", UUID.randomUUID())).setStream(out.toByteArray())); .setStream(out.toByteArray()));
} catch (IOException e) { } catch (IOException e) {
log.error(e.getMessage()); log.error(e.getMessage());
} }

View File

@ -3,7 +3,6 @@ package com.chinaunicom.mall.ebtp.cloud.security.starter.filter;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -79,7 +78,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
// 根据当前角色设定权限列表 // 根据当前角色设定权限列表
List<RoleCodeAuthority> authorities = Optional.ofNullable(securityUser.getAuthorityList()).map(list -> { List<RoleCodeAuthority> authorities = Optional.ofNullable(securityUser.getAuthorityList()).map(list -> {
return list.stream().filter(auth -> Objects.equals(auth.getRoleCode(), currentRoleCode)) return list.stream().filter(auth -> StringUtils.equals(auth.getRoleCode(), currentRoleCode))
.map(auth -> new RoleCodeAuthority(auth.getRoleCode())).collect(Collectors.toList()); .map(auth -> new RoleCodeAuthority(auth.getRoleCode())).collect(Collectors.toList());
}).orElseGet(() -> Collections.emptyList()); }).orElseGet(() -> Collections.emptyList());