diff --git a/wfc-api/wfc-api-system/src/main/java/org/wfc/system/api/RemoteFileService.java b/wfc-api/wfc-api-system/src/main/java/org/wfc/system/api/RemoteFileService.java index b01f516..2b953f7 100644 --- a/wfc-api/wfc-api-system/src/main/java/org/wfc/system/api/RemoteFileService.java +++ b/wfc-api/wfc-api-system/src/main/java/org/wfc/system/api/RemoteFileService.java @@ -2,7 +2,9 @@ package org.wfc.system.api; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; import org.wfc.common.core.constant.ServiceNameConstants; @@ -26,4 +28,8 @@ public interface RemoteFileService */ @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public R upload(@RequestPart(value = "file") MultipartFile file); + + + @GetMapping("/download") + public R download(@RequestParam("filePath") String filePath); } diff --git a/wfc-modules/wfc-file/src/main/java/org/wfc/file/controller/SysFileController.java b/wfc-modules/wfc-file/src/main/java/org/wfc/file/controller/SysFileController.java index c6f35cd..4ce5cc4 100644 --- a/wfc-modules/wfc-file/src/main/java/org/wfc/file/controller/SysFileController.java +++ b/wfc-modules/wfc-file/src/main/java/org/wfc/file/controller/SysFileController.java @@ -1,12 +1,17 @@ package org.wfc.file.controller; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import org.wfc.common.core.domain.R; +import org.wfc.common.core.exception.ServiceException; import org.wfc.common.core.utils.file.FileUtils; import org.wfc.file.service.ISysFileService; import org.wfc.file.service.LocalSysFileServiceImpl.FileUploadResult; @@ -14,7 +19,7 @@ import org.wfc.system.api.domain.SysFile; /** * 文件请求处理 - * + * * @author wfc */ @RestController @@ -46,4 +51,16 @@ public class SysFileController { return R.fail(e.getMessage()); } } + + @GetMapping("/download") + public R download(@RequestParam("filePath") String filePath) { + byte[] content = null; + if (StrUtil.isNotBlank(filePath)) { + content = FileUtil.readBytes(filePath); + if (content == null) { + throw new ServiceException("file does not exist"); + } + } + return R.ok(content); + } } \ No newline at end of file diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UBillServiceImpl.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UBillServiceImpl.java index f43cc50..802b8c8 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UBillServiceImpl.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UBillServiceImpl.java @@ -105,7 +105,8 @@ public class UBillServiceImpl extends ServiceImpl implements UBill bill = this.getById(id); String invoiceFilePath = bill.getInvoiceFilePath(); if (StrUtil.isNotBlank(invoiceFilePath)) { - byte[] content = FileUtil.readBytes(invoiceFilePath); + R result = remoteFileService.download(invoiceFilePath); + byte[] content = result.getData(); if (content == null) { throw new ServiceException("file does not exist"); }