diff --git a/continew-common/src/main/java/top/continew/admin/common/constant/ContainerConstants.java b/continew-common/src/main/java/top/continew/admin/common/constant/ContainerConstants.java index beb0ba5d..19fce960 100644 --- a/continew-common/src/main/java/top/continew/admin/common/constant/ContainerConstants.java +++ b/continew-common/src/main/java/top/continew/admin/common/constant/ContainerConstants.java @@ -29,6 +29,11 @@ public class ContainerConstants { */ public static final String USER_NICKNAME = "UserNickname"; + /** + * 文件信息 + */ + public static final String FILE_INFO = "FileInfo"; + /** * 用户角色 ID 列表 */ diff --git a/continew-common/src/main/java/top/continew/admin/common/constant/SysFileConstants.java b/continew-common/src/main/java/top/continew/admin/common/constant/SysFileConstants.java new file mode 100644 index 00000000..50973481 --- /dev/null +++ b/continew-common/src/main/java/top/continew/admin/common/constant/SysFileConstants.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.common.constant; + +import top.continew.starter.core.constant.StringConstants; + +import java.time.LocalDate; + +/** + * 系统文件相关常量 + * + * @author luoqiz + * @since 2025/3/12 18:11 + */ +public class SysFileConstants { + + /** + * 用户头像路径前缀 + */ + public static final String USER_AVATAR_PATH = "user/avatar/"; + + /** + * 默认文件路径 + */ + public static String getDefaultFilePath() { + LocalDate today = LocalDate.now(); + String path = today.getYear() + StringConstants.SLASH + today.getMonthValue() + StringConstants.SLASH + today + .getDayOfMonth() + StringConstants.SLASH; + return path; + } + + private SysFileConstants() { + } +} diff --git a/continew-module-system/src/main/java/top/continew/admin/system/config/container/FileInfoContainer.java b/continew-module-system/src/main/java/top/continew/admin/system/config/container/FileInfoContainer.java new file mode 100644 index 00000000..e74322c3 --- /dev/null +++ b/continew-module-system/src/main/java/top/continew/admin/system/config/container/FileInfoContainer.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.system.config.container; + +import cn.crane4j.core.container.Container; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import top.continew.admin.common.constant.ContainerConstants; +import top.continew.admin.system.model.entity.FileDO; +import top.continew.admin.system.service.FileService; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Component +@RequiredArgsConstructor +public class FileInfoContainer implements Container { + + private final FileService fileService; + + public String getNamespace() { + return ContainerConstants.FILE_INFO; + } + + public Map get(Collection ids) { + List list = fileService.listByIds(ids); + return list.stream().collect(Collectors.toMap(FileDO::getId, Function.identity())); + } + +} \ No newline at end of file diff --git a/continew-module-system/src/main/java/top/continew/admin/system/service/FileService.java b/continew-module-system/src/main/java/top/continew/admin/system/service/FileService.java index c7634d00..fcc22619 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/service/FileService.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/service/FileService.java @@ -18,6 +18,7 @@ package top.continew.admin.system.service; import org.dromara.x.file.storage.core.FileInfo; import org.springframework.web.multipart.MultipartFile; +import top.continew.admin.common.constant.SysFileConstants; import top.continew.admin.system.model.entity.FileDO; import top.continew.admin.system.model.query.FileQuery; import top.continew.admin.system.model.req.FileReq; @@ -43,17 +44,28 @@ public interface FileService extends BaseService