//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;
//
//
///**
// * 工单导出工具类
// * @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;
//    }
//}
