From 06df89cb220d670695fa39df20b3e41519eb9632 Mon Sep 17 00:00:00 2001 From: "liang.chao" <1360241448@qq.com> Date: Mon, 16 Dec 2024 17:34:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=9F=E8=B5=81=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bonus-modules/bonus-material-mall/pom.xml | 4 +++ .../order/controller/OrderController.java | 25 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/bonus-modules/bonus-material-mall/pom.xml b/bonus-modules/bonus-material-mall/pom.xml index 72546d3..49ad73d 100644 --- a/bonus-modules/bonus-material-mall/pom.xml +++ b/bonus-modules/bonus-material-mall/pom.xml @@ -23,6 +23,10 @@ jasypt-spring-boot-starter ${jasypt-spring-boot-starter.version} + + org.springframework + spring-test + com.alibaba.cloud diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/order/controller/OrderController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/order/controller/OrderController.java index 5f62157..4a29850 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/order/controller/OrderController.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/order/controller/OrderController.java @@ -15,6 +15,8 @@ import com.bonus.material.order.domain.OrderDetailDto; import com.bonus.material.order.domain.OrderInfoDto; import com.bonus.material.order.mapper.OrderMapper; import com.bonus.material.order.service.OrderService; +import com.bonus.system.api.RemoteFileService; +import com.bonus.system.api.domain.SysFile; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -23,6 +25,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; @@ -58,6 +61,9 @@ public class OrderController extends BaseController { @Resource private BmContractService bmContractService; + @Resource + private RemoteFileService sysFileService; + /** * 提交预约车到订单 */ @@ -165,7 +171,7 @@ public class OrderController extends BaseController { @ApiOperation(value = "租赁协议(查看)") @GetMapping("/leaseAgreement") - public ResponseEntity getleaseAgreement(String orderId, Map replacements) throws IOException { + public AjaxResult getleaseAgreement(String orderId, Map replacements) throws IOException { OrderInfoDto orderInfoDto = orderService.getAgreementByOrderId(orderId); BmContract bmContract = new BmContract(); bmContract.setStatus(1); @@ -202,6 +208,7 @@ public class OrderController extends BaseController { document.write(outputStream); byte[] wordBytes = outputStream.toByteArray(); + // Convert Word to Image (simple example using BufferedImage) /* BufferedImage image = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = image.createGraphics(); @@ -210,12 +217,14 @@ public class OrderController extends BaseController { graphics.setPaint(Color.black); graphics.drawString(new String(wordBytes), 10, 20); graphics.dispose();*/ - - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); - headers.setContentDispositionFormData("attachment", "contract.docx"); - return ResponseEntity.ok() - .headers(headers) - .body(wordBytes); + MultipartFile file = new MockMultipartFile("contract", "contract.docx", MediaType.APPLICATION_OCTET_STREAM_VALUE, wordBytes); + AjaxResult upload = sysFileService.upload(file); + return upload; +// HttpHeaders headers = new HttpHeaders(); +// headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); +// headers.setContentDispositionFormData("attachment", "contract.docx"); +// return ResponseEntity.ok() +// .headers(headers) +// .body(wordBytes); } }