Commit 451672c6969cd10c2a871c4e1e2e95f0b2831651
1 parent
b51d8686
feat: ERP升级
1、文件上传
Showing
2 changed files
with
32 additions
and
2 deletions
src/main/java/com/order/erp/domain/vo/FileRespVO.java
0 → 100644
1 | +package com.order.erp.domain.vo; | ||
2 | + | ||
3 | +import lombok.*; | ||
4 | +import lombok.experimental.SuperBuilder; | ||
5 | + | ||
6 | +import java.io.Serializable; | ||
7 | + | ||
8 | +/** | ||
9 | + * 文件上传实体类 | ||
10 | + * | ||
11 | + * @author xms | ||
12 | + * @since 2023-10-08 14:52:27 | ||
13 | + */ | ||
14 | +@Data | ||
15 | +@AllArgsConstructor | ||
16 | +@ToString | ||
17 | +@NoArgsConstructor | ||
18 | +@EqualsAndHashCode(callSuper = false) | ||
19 | +@SuperBuilder | ||
20 | +public class FileRespVO implements Serializable { | ||
21 | + | ||
22 | + /** | ||
23 | + * file地址 | ||
24 | + */ | ||
25 | + private String fileUrl; | ||
26 | + | ||
27 | +} |
src/main/java/com/order/erp/service/impl/LocalStorageServiceImpl.java
@@ -14,6 +14,7 @@ import com.order.erp.common.utils.FileUtil; | @@ -14,6 +14,7 @@ import com.order.erp.common.utils.FileUtil; | ||
14 | import com.order.erp.common.utils.StringUtils; | 14 | import com.order.erp.common.utils.StringUtils; |
15 | import com.order.erp.config.AliOssConfig; | 15 | import com.order.erp.config.AliOssConfig; |
16 | import com.order.erp.domain.dto.LocalStorageDO; | 16 | import com.order.erp.domain.dto.LocalStorageDO; |
17 | +import com.order.erp.domain.vo.FileRespVO; | ||
17 | import com.order.erp.domain.vo.ImageRespVO; | 18 | import com.order.erp.domain.vo.ImageRespVO; |
18 | import com.order.erp.domain.vo.LocalStorageQueryVO; | 19 | import com.order.erp.domain.vo.LocalStorageQueryVO; |
19 | import com.order.erp.domain.vo.LocalStorageVO; | 20 | import com.order.erp.domain.vo.LocalStorageVO; |
@@ -55,13 +56,15 @@ public class LocalStorageServiceImpl extends ServiceImpl<LocalStorageMapper, Loc | @@ -55,13 +56,15 @@ public class LocalStorageServiceImpl extends ServiceImpl<LocalStorageMapper, Loc | ||
55 | FileUtil.checkSize(maxSize, file.getSize()); | 56 | FileUtil.checkSize(maxSize, file.getSize()); |
56 | String fileName = AliOssUtil.getUniqueFileName(name); | 57 | String fileName = AliOssUtil.getUniqueFileName(name); |
57 | String tempFileName = "Thumbnails" + Constant.CROSS_BAR_CHARACTER + fileName; | 58 | String tempFileName = "Thumbnails" + Constant.CROSS_BAR_CHARACTER + fileName; |
58 | - ImageRespVO imageRespVO = new ImageRespVO(); | 59 | + FileRespVO fileRespVO = new FileRespVO(); |
59 | try { | 60 | try { |
60 | File tempFile = new File(path + "files" + File.separator + tempFileName); | 61 | File tempFile = new File(path + "files" + File.separator + tempFileName); |
61 | if (AliOssUtil.upload(AliOssConfig.ALIYUN_BUCKET, fileName, file.getBytes())) { | 62 | if (AliOssUtil.upload(AliOssConfig.ALIYUN_BUCKET, fileName, file.getBytes())) { |
63 | + String fileUrl = AliOssUtil.createUrl(AliOssConfig.ALIYUN_BUCKET, fileName, new DateTime().plusYears(Constant.ENABLE_TEN).toDate()); | ||
64 | + fileRespVO.setFileUrl(fileUrl); | ||
62 | FileUtil.del(tempFile); | 65 | FileUtil.del(tempFile); |
63 | } | 66 | } |
64 | - return ServerResult.success(imageRespVO); | 67 | + return ServerResult.success(fileRespVO); |
65 | } catch (Exception e) { | 68 | } catch (Exception e) { |
66 | log.error("上传文件异常:{}", e.getMessage()); | 69 | log.error("上传文件异常:{}", e.getMessage()); |
67 | throw new BusinessException(ServerResultCode.UPLOAD_IMAGES_ERROR); | 70 | throw new BusinessException(ServerResultCode.UPLOAD_IMAGES_ERROR); |