From b8fa5ad88c472ff8a7bf2ddccc37f0c28e604f37 Mon Sep 17 00:00:00 2001 From: lzttt <1803073139@qq.com> Date: Sat, 12 Oct 2024 12:41:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=E5=AF=BC=E5=87=BA=E5=B7=A5?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/knowledge/constants/Result.java | 3 + dl-module-repair/pom.xml | 29 +++++- .../admin/DlRepairTicketsController.java | 47 +++++++++ .../tickets/tools/TOperaDocRequestUtil.java | 96 ++++++++++++++++++ .../src/main/resources/templates/gdmb.docx | Bin 0 -> 14825 bytes .../yudao-module-infra-biz/pom.xml | 6 ++ .../infra/service/file/FileService.java | 16 +++ .../infra/service/file/FileServiceImpl.java | 47 +++++++++ 8 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/tools/TOperaDocRequestUtil.java create mode 100644 dl-module-repair/src/main/resources/templates/gdmb.docx diff --git a/dl-module-knowledge/src/main/java/cn/iocoder/yudao/module/knowledge/constants/Result.java b/dl-module-knowledge/src/main/java/cn/iocoder/yudao/module/knowledge/constants/Result.java index c14bc477..89636c7b 100644 --- a/dl-module-knowledge/src/main/java/cn/iocoder/yudao/module/knowledge/constants/Result.java +++ b/dl-module-knowledge/src/main/java/cn/iocoder/yudao/module/knowledge/constants/Result.java @@ -15,6 +15,9 @@ public class Result implements Serializable { public Result() { } + public Result(Object o, String 文件不能为空) { + } + public Integer getCode() { return this.code; } diff --git a/dl-module-repair/pom.xml b/dl-module-repair/pom.xml index d474358e..a6ee9701 100644 --- a/dl-module-repair/pom.xml +++ b/dl-module-repair/pom.xml @@ -26,10 +26,37 @@ yudao-module-system-biz ${revision} + + com.deepoove + poi-tl + 1.12.2 + + + io.minio + minio + 8.4.0 + + + cn.iocoder.boot + dl-module-knowledge + 2.1.0-jdk8-snapshot + compile + + + cn.iocoder.boot + yudao-module-infra-biz + 2.1.0-jdk8-snapshot + compile + + + org.springframework + spring-test + + 8 8 - \ No newline at end of file + diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTicketsController.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTicketsController.java index cf88bd70..c3fae8bf 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTicketsController.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTicketsController.java @@ -1,18 +1,34 @@ package cn.iocoder.yudao.module.tickets.controller.admin; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; +import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient; +import cn.iocoder.yudao.module.infra.service.file.FileConfigService; +import cn.iocoder.yudao.module.infra.service.file.FileService; +import cn.iocoder.yudao.module.knowledge.constants.Result; +import cn.iocoder.yudao.module.knowledge.controller.requestdto.TOperationDocRequest; import cn.iocoder.yudao.module.tickets.entity.DlRepairTickets; import cn.iocoder.yudao.module.tickets.service.DlRepairTicketsService; +import cn.iocoder.yudao.module.tickets.tools.TOperaDocRequestUtil; import cn.iocoder.yudao.module.tickets.vo.CustomerAndCarVO; import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsReqVO; import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsRespVO; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.tencentcloudapi.ess.v20201111.models.FileInfo; import io.swagger.v3.oas.annotations.Operation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.io.IOException; + import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; /** @@ -28,6 +44,15 @@ public class DlRepairTicketsController { */ @Resource private DlRepairTicketsService dlRepairTicketsService; + @Autowired + private TOperaDocRequestUtil tOperaDocRequestUtil; + @Autowired + private FileService fileService; + @Resource + private FileConfigService fileConfigService; + + + /** * 维修工单表 新增 @@ -102,6 +127,28 @@ public class DlRepairTicketsController { return CommonResult.ok(); } + /** + * 维修工单表 导出 + * + * @author lzt + * @date 2024年10月11日 + * @param file 导出文件 + */ + @PostMapping("/print") + @Operation(summary = "维修工单表 导出") + public ResponseEntity> printDocument(@RequestParam("file") MultipartFile file) { + if (file.isEmpty()) { + return ResponseEntity.badRequest().body(new Result<>(null, "文件不能为空")); + } + + try { + FileDO fileInfo = fileService.createFileDetail(file.getOriginalFilename(), "/ticket", IoUtil.readBytes(file.getInputStream())); + return ResponseEntity.ok(new Result<>(fileInfo, "文件上传成功")); + } catch (Exception e) { + return ResponseEntity.status(500).body(new Result<>(null, "文件上传失败: " + e.getMessage())); + } + } + /** * 客户信息和车辆信息 新增、修改 * diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/tools/TOperaDocRequestUtil.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/tools/TOperaDocRequestUtil.java new file mode 100644 index 00000000..cd7581c6 --- /dev/null +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/tools/TOperaDocRequestUtil.java @@ -0,0 +1,96 @@ +package cn.iocoder.yudao.module.tickets.tools; + +import cn.iocoder.yudao.module.infra.service.file.FileService; +import cn.iocoder.yudao.module.knowledge.constants.Result; +import cn.iocoder.yudao.module.tickets.controller.admin.DlRepairTicketsController; +import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsReqVO; +import com.deepoove.poi.XWPFTemplate; +import com.deepoove.poi.config.Configure; +import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy; +import com.tencentcloudapi.ess.v20201111.models.FileInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.HashMap; + +import static com.fhs.core.trans.util.ConvertUtil.convert; + + +/** + * 工单导出工具类 + * @author lzt + * @date 9:27 2024年10月11日 + */ +@Component(value = "TOperaDocRequestUtil" ) +public class TOperaDocRequestUtil { + + @Resource + private FileService fileService; + @Value("${minio.bucketName:dev}") + private String bucketName; + + public TOperaDocRequestUtil() throws FileNotFoundException { + } + + + private static String TEMPLATE_PATH = "/templates/gdmb.docx"; + + @Autowired + private DlRepairTicketsController dlRepairTicketsController; + + public FileInfo export(DlRepairTicketsReqVO request) throws IOException { + String fileStr = TEMPLATE_PATH; + + if (fileStr != null) { + byte[] inputStream = fileService.downloadFile(bucketName, fileStr); + + // 数据循环填充 + LoopRowTableRenderPolicy loopRowTableRenderPolicy = new LoopRowTableRenderPolicy(); + Configure configure = Configure.builder().bind("czTable", loopRowTableRenderPolicy).build(); + + // word导出到本地 + MultipartFile convert = null; + if (fileStr.contains("gdmb.docx")) { + // 操作模板文件-数据填充 + XWPFTemplate template = XWPFTemplate.compile(String.valueOf(inputStream), configure).render( + new HashMap() {{ + // 填充数据 TODO + //put("requestData", request); + + }} + ); + ByteArrayOutputStream outputStreamWord = new ByteArrayOutputStream();; + template.writeAndClose(outputStreamWord); + //IConverter converter = LocalConverter.builder().build(); + byte[] bytes = outputStreamWord.toByteArray(); + ByteArrayInputStream inputStreamWord = new ByteArrayInputStream(bytes); + + ByteArrayOutputStream outputStreamPdf = new ByteArrayOutputStream(); + + //converter.convert(inputStreamWord).as(DocumentType.DOCX).to(outputStreamPdf).as(DocumentType.PDF).execute(); + byte[] bytesPdf = outputStreamPdf.toByteArray(); + ByteArrayInputStream inputStreamPdf = new ByteArrayInputStream(bytesPdf); + + // convert = new MultipartFile(fileStr.replace(".docx", ".pdf"), "application/pdf", inputStreamPdf.readAllBytes()); + convert = new MockMultipartFile("gdmb.pdf", bytes); + } + ResponseEntity> responseEntity = dlRepairTicketsController.printDocument(convert); + +// 获取 Result 对象 + Result fileupload = responseEntity.getBody(); + if (fileupload != null) { + return fileupload.getData(); + } + } + return null; + } +} diff --git a/dl-module-repair/src/main/resources/templates/gdmb.docx b/dl-module-repair/src/main/resources/templates/gdmb.docx new file mode 100644 index 0000000000000000000000000000000000000000..6d061efae58adb65ca9daace959f7ea8bddae9e9 GIT binary patch literal 14825 zcma)j19W9e*KORfZ9D1Mww;dCv2C+s+h)hMZQHidap$G){qBG7?f3m}yxQYn>{GKa z*RDEMwbqoA1O|Zw_?3cWcKCjM{*@p;z8F~R%h_4m*ngJ$$cFrJ1N@I{Fgc6aMt}eS z?mz$l@c+!FYhy#}Vrh|~Fe=ka2j50?4JUsQf+Kh&sF8=b^(|XL(XEWycvY3S!4OO6 z9XBW!v0}~1Xm9!~a{EW^Wh|V7Hb%QxSb8CZnJH!gT$qC*uhA^iHUE)_gUBu+cdo4U z(>`cfdi9Z?K$Z~HIhrY!Uk1{SVOaZ>YrLbTt_LxiV6F&3;RuEp` z6R@9p2TN51K5sv*E`+5qe@Rm>IF z>Eon)GDJ${HUfbz6xw}jd?FxR6gXLm_(cRO?6x*N4V!!5{FZ)4X7l$e7pXxgm5rv|pe+>iJ)aP_LMY&OUa4ik{4O~G&=EB$QDkp( zoaB+8YEy<4@ygpWE0c4p?M9NeGO#CkG+?^3OnF8#%U3@sywtcYTjYBM>a9rt3`3B$ zI7y*xJ~3PYI9WLlTadv;Js}$EGeinVcJieJRpj!l+p%JTRb@I9O?l0 z_h_(EGfkoVU>@Ovd8B_a?`ZE}ZTXA)f*5{Te>&vBOH!{-Gw!Cx#a%$u;R1SGCOd2M z(F!bxCgK`}Vb`szhBCX|VYpv^e(rp5zbq(Sw7r5ANYfs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MDFDM?m_NqJ|EscJlC?k6ugZRk1poiAAO11${;2z}(58Psr@sd` g{atJQzkz>;I>||b{xRy{KeU-sAI}po%P-LX0p=J07ytkO literal 0 HcmV?d00001 diff --git a/yudao-module-infra/yudao-module-infra-biz/pom.xml b/yudao-module-infra/yudao-module-infra-biz/pom.xml index a12f078a..ada189a0 100644 --- a/yudao-module-infra/yudao-module-infra-biz/pom.xml +++ b/yudao-module-infra/yudao-module-infra-biz/pom.xml @@ -124,6 +124,12 @@ org.apache.tika tika-core + + com.aliyun.oss + aliyun-sdk-oss + 3.11.2 + compile + diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileService.java index cf40e74e..98bcaaa0 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileService.java @@ -5,6 +5,10 @@ import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileCreateReq import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO; import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePresignedUrlRespVO; import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; +import org.apache.tomcat.jni.FileInfo; +import org.springframework.web.multipart.MultipartFile; + +import javax.xml.ws.Response; /** * 文件 Service 接口 @@ -63,4 +67,16 @@ public interface FileService { */ FilePresignedUrlRespVO getFilePresignedUrl(String path) throws Exception; + /** + * 下载文件 + * + * @author lzt + * @date 2024年10月11日 + * @param bucketName 存储桶名称 + * @param fileName 文件名称 + * @return 文件下载响应 + */ + byte[] downloadFile(String bucketName, String fileName); + +// FileInfo uploadFile(MultipartFile file); } 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 index 85aa8121..f23a7063 100644 --- 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 @@ -13,10 +13,18 @@ import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePresignedUrlRespVO; import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; import cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper; +import com.aliyun.oss.OSS; +import com.aliyun.oss.model.PutObjectRequest; import lombok.SneakyThrows; +import org.apache.tomcat.jni.FileInfo; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.xml.ws.Response; + +import java.io.IOException; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS; @@ -145,4 +153,43 @@ public class FileServiceImpl implements FileService { object -> object.setConfigId(fileClient.getId())); } + @Override + @SneakyThrows + public byte[] downloadFile(String bucketName, String fileStr) { + // 获取文件存储客户端 + FileClient client = fileConfigService.getFileClient(Long.valueOf(bucketName)); + Assert.notNull(client, "客户端({}) 不能为空", bucketName); + + // 获取文件内容 + return client.getContent(fileStr); + } + +// @Override +// public FileInfo uploadFile(MultipartFile file) { +// String bucketName = "xxxxx"; // 存储桶名称 +// String fileName = file.getOriginalFilename(); +// +// try { +// // 上传文件到 OSS +// PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, file.getInputStream()); +// ossClient.putObject(putObjectRequest); +// +// // 创建并返回 FileInfo 对象 +// FileInfo fileInfo = new FileInfo(); +// fileInfo.setFileName(fileName); +// fileInfo.setBucketName(bucketName); +// return fileInfo; +// +// } catch (IOException e) { +// e.printStackTrace(); +// throw new RuntimeException("文件上传到 OSS 失败: " + e.getMessage()); +// } finally { +// // 关闭 OSS 客户端 +// ossClient.shutdown(); +// } +// } + + + + }