打印导出工单
This commit is contained in:
parent
eebe5ef676
commit
b8fa5ad88c
@ -15,6 +15,9 @@ public class Result<T> implements Serializable {
|
|||||||
public Result() {
|
public Result() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result(Object o, String 文件不能为空) {
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getCode() {
|
public Integer getCode() {
|
||||||
return this.code;
|
return this.code;
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,37 @@
|
|||||||
<artifactId>yudao-module-system-biz</artifactId>
|
<artifactId>yudao-module-system-biz</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.deepoove</groupId>
|
||||||
|
<artifactId>poi-tl</artifactId>
|
||||||
|
<version>1.12.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.minio</groupId>
|
||||||
|
<artifactId>minio</artifactId>
|
||||||
|
<version>8.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.iocoder.boot</groupId>
|
||||||
|
<artifactId>dl-module-knowledge</artifactId>
|
||||||
|
<version>2.1.0-jdk8-snapshot</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.iocoder.boot</groupId>
|
||||||
|
<artifactId>yudao-module-infra-biz</artifactId>
|
||||||
|
<version>2.1.0-jdk8-snapshot</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,18 +1,34 @@
|
|||||||
package cn.iocoder.yudao.module.tickets.controller.admin;
|
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.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.entity.DlRepairTickets;
|
||||||
import cn.iocoder.yudao.module.tickets.service.DlRepairTicketsService;
|
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.CustomerAndCarVO;
|
||||||
import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsReqVO;
|
import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsReqVO;
|
||||||
import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsRespVO;
|
import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsRespVO;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.tencentcloudapi.ess.v20201111.models.FileInfo;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
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.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,6 +44,15 @@ public class DlRepairTicketsController {
|
|||||||
*/
|
*/
|
||||||
@Resource
|
@Resource
|
||||||
private DlRepairTicketsService dlRepairTicketsService;
|
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();
|
return CommonResult.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 维修工单表 导出
|
||||||
|
*
|
||||||
|
* @author lzt
|
||||||
|
* @date 2024年10月11日
|
||||||
|
* @param file 导出文件
|
||||||
|
*/
|
||||||
|
@PostMapping("/print")
|
||||||
|
@Operation(summary = "维修工单表 导出")
|
||||||
|
public ResponseEntity<Result<FileInfo>> 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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户信息和车辆信息 新增、修改
|
* 客户信息和车辆信息 新增、修改
|
||||||
*
|
*
|
||||||
|
@ -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<String, Object>() {{
|
||||||
|
// 填充数据 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<Result<FileInfo>> responseEntity = dlRepairTicketsController.printDocument(convert);
|
||||||
|
|
||||||
|
// 获取 Result<FileInfo> 对象
|
||||||
|
Result<FileInfo> fileupload = responseEntity.getBody();
|
||||||
|
if (fileupload != null) {
|
||||||
|
return fileupload.getData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
BIN
dl-module-repair/src/main/resources/templates/gdmb.docx
Normal file
BIN
dl-module-repair/src/main/resources/templates/gdmb.docx
Normal file
Binary file not shown.
@ -124,6 +124,12 @@
|
|||||||
<groupId>org.apache.tika</groupId>
|
<groupId>org.apache.tika</groupId>
|
||||||
<artifactId>tika-core</artifactId> <!-- 文件客户端:文件类型的识别 -->
|
<artifactId>tika-core</artifactId> <!-- 文件客户端:文件类型的识别 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
<version>3.11.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -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.FilePageReqVO;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePresignedUrlRespVO;
|
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.dataobject.file.FileDO;
|
||||||
|
import org.apache.tomcat.jni.FileInfo;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.xml.ws.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件 Service 接口
|
* 文件 Service 接口
|
||||||
@ -63,4 +67,16 @@ public interface FileService {
|
|||||||
*/
|
*/
|
||||||
FilePresignedUrlRespVO getFilePresignedUrl(String path) throws Exception;
|
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);
|
||||||
}
|
}
|
||||||
|
@ -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.controller.admin.file.vo.file.FilePresignedUrlRespVO;
|
||||||
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
||||||
import cn.iocoder.yudao.module.infra.dal.mysql.file.FileMapper;
|
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 lombok.SneakyThrows;
|
||||||
|
import org.apache.tomcat.jni.FileInfo;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
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.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS;
|
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()));
|
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();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user