From 18622c5d064a30a1c8eb3db5ceb68df615c8c5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=92=B1=E5=93=A5=E4=B8=B6?= <385454831@qq.com> Date: Wed, 4 Jan 2023 12:02:46 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20yudao-mo?= =?UTF-8?q?dule-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yuda?= =?UTF-8?q?o/module/infra/service/file/FileServiceImpl.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/service/file/FileServiceImpl.java | 96 ------------------- 1 file changed, 96 deletions(-) delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java deleted file mode 100644 index dd0e339e0..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java +++ /dev/null @@ -1,96 +0,0 @@ -package cn.iocoder.yudao.module.infra.service.file; - -import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.io.FileUtils; -import cn.iocoder.yudao.framework.file.core.client.FileClient; -import cn.iocoder.yudao.framework.file.core.utils.FileTypeUtils; -import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO; -import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; -import cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper; -import lombok.SneakyThrows; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS; - -/** - * 文件 Service 实现类 - * - * @author 芋道源码 - */ -@Service -public class FileServiceImpl implements FileService { - - @Resource - private FileConfigService fileConfigService; - - @Resource - private FileMapper fileMapper; - - @Override - public PageResult getFilePage(FilePageReqVO pageReqVO) { - return fileMapper.selectPage(pageReqVO); - } - - @Override - @SneakyThrows - public String createFile(String name, String path, byte[] content) { - // 计算默认的 path 名,path可增加自定义路径如 aaa/,aaa/bbb/ - String type = FileTypeUtils.getMineType(content, name); - path = StrUtil.isEmpty(path) ? FileUtils.generatePath(content, name) : path + FileUtils.generatePath(content, name); - // 如果 name 为空,则使用 path 填充 - if (StrUtil.isEmpty(name)) { - name = path; - } - - // 上传到文件存储器 - FileClient client = fileConfigService.getMasterFileClient(); - Assert.notNull(client, "客户端(master) 不能为空"); - String url = client.upload(content, path, type); - - // 保存到数据库 - FileDO file = new FileDO(); - file.setConfigId(client.getId()); - file.setName(name); - file.setPath(path); - file.setUrl(url); - file.setType(type); - file.setSize(content.length); - fileMapper.insert(file); - return url; - } - - @Override - public void deleteFile(Long id) throws Exception { - // 校验存在 - FileDO file = this.validateFileExists(id); - - // 从文件存储器中删除 - FileClient client = fileConfigService.getFileClient(file.getConfigId()); - Assert.notNull(client, "客户端({}) 不能为空", file.getConfigId()); - client.delete(file.getPath()); - - // 删除记录 - fileMapper.deleteById(id); - } - - private FileDO validateFileExists(Long id) { - FileDO fileDO = fileMapper.selectById(id); - if (fileDO == null) { - throw exception(FILE_NOT_EXISTS); - } - return fileDO; - } - - @Override - public byte[] getFileContent(Long configId, String path) throws Exception { - FileClient client = fileConfigService.getFileClient(configId); - Assert.notNull(client, "客户端({}) 不能为空", configId); - return client.getContent(path); - } - -}