From ef26bf4fde77ba361bcd083a769c3a1b8a229738 Mon Sep 17 00:00:00 2001 From: 许鹏程 <1821349743@qq.com> Date: 星期一, 10 二月 2025 14:39:24 +0800 Subject: [PATCH] excel文件预览使用pdf --- src/main/java/com/product/file/service/OnlineDocumentEditService.java | 71 ++++++++++++++++++++--------------- 1 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/product/file/service/OnlineDocumentEditService.java b/src/main/java/com/product/file/service/OnlineDocumentEditService.java index 819baea..b95e5f7 100644 --- a/src/main/java/com/product/file/service/OnlineDocumentEditService.java +++ b/src/main/java/com/product/file/service/OnlineDocumentEditService.java @@ -75,7 +75,15 @@ } List<File> fileList = new ArrayList<>(3); if (!StringUtils.isEmpty(document_template)) { - fileList.add(fileManagerService.getFile(document_template)); + File file1 = fileManagerService.getFile(document_template); + //鍒ゆ柇file1鐨勬枃浠剁被鍨� + if (file1.getName().substring(file1.getName().lastIndexOf(".") + 1).equals("doc")) { + //杞崲涓篸ocx + File docx = com.product.file.util.FileUtil.toDocx(file1); + FileUtil.del(file1); + file1 = docx; + } + fileList.add(file1); fileList.add(file); } else { fileList.add(file); @@ -83,10 +91,9 @@ if (!StringUtils.isEmpty(document_template_tail)) { fileList.add(fileManagerService.getFile(document_template_tail)); } - File mergeFile = MergeDoc.mergeDoc(fileList, Global.getSystemConfig("upload.file.temp.path", "./attachment/temp") + - File.separator + "nest_red_document_" + IdUtil.randomUUID() + "_" + ff.getString("file_uuid")); + File mergeFile = MergeDoc.mergeDoc(fileList, Global.getSystemConfig("upload.file.temp.path", "./attachment/temp") + File.separator + "nest_red_document_" + IdUtil.randomUUID() + "_" + ff.getString("file_uuid")); if (mergeFile != null && mergeFile.isFile()) { - if("doc".equals(fileType)){ + if ("doc".equals(fileType)) { //灏哾ocx鏂囦欢杞崲涓篸oc鏂囦欢 File f = mergeFile; mergeFile = com.product.file.util.FileUtil.toDoc(f); @@ -104,6 +111,7 @@ } catch (BaseException e) { throw e; } catch (Exception e) { + e.printStackTrace(); throw new BaseException(FileCode.NEST_RED_DOCUMENT_FAIL); } } @@ -158,12 +166,15 @@ return; } //姝e垯鍖归厤redis涓殑key - try (Jedis jedis = RedisUtil.getJedis()) { - Set<String> keys = jedis.keys(this.DOCUMENT_EDIT_KEY + "*-" + userId); - if (keys != null && keys.size() > 0) { - //娓呯┖redis - RedisUtil.del(keys.toArray(new String[keys.size()])); + Set<byte[]> keys = RedisUtil.keys(this.DOCUMENT_EDIT_KEY + "*-" + userId); + if (keys != null && keys.size() > 0) { + String[] strKeys = new String[keys.size()]; + int i = 0; + for (byte[] key : keys) { + strKeys[i++] = new String(key); } + //娓呯┖redis + RedisUtil.del(strKeys); } } @@ -301,30 +312,28 @@ throw new BaseException(FileCode.GET_FILE_RECORD_FAIL); } String key = this.DOCUMENT_EDIT_KEY + fileUuid + "-" + userId; - try (Jedis jedis = RedisUtil.getJedis()) { - //妯$硦鍖归厤key - Set<byte[]> keyBytes = jedis.keys((this.DOCUMENT_EDIT_KEY + fileUuid + "-*").getBytes(StandardCharsets.UTF_8)); - if (!CollectionUtil.isEmpty(keyBytes)) { - Set<String> keys = keyBytes.stream().map(item -> new String(item, StandardCharsets.UTF_8)).collect(Collectors.toSet()); - boolean remove = keys.remove(this.DOCUMENT_EDIT_KEY + fileUuid + "-" + userId); - if (keys != null && keys.size() > 0) { - //姝e湪琚紪杈� - String existsKey = keys.toArray(new String[]{})[0]; - //杩欓噷浼氭姏鍑烘鍦ㄧ紪杈戠殑寮傚父 - throwBeingEditDocument(existsKey.substring(existsKey.lastIndexOf("-") + 1)); - } else if (remove) { - RedisUtil.setOutTime(key, getExpirationTime()); - return; - } + //妯$硦鍖归厤key + Set<byte[]> keyBytes = RedisUtil.keys((this.DOCUMENT_EDIT_KEY + fileUuid + "-*").getBytes(StandardCharsets.UTF_8)); + if (!CollectionUtil.isEmpty(keyBytes)) { + Set<String> keys = keyBytes.stream().map(item -> new String(item, StandardCharsets.UTF_8)).collect(Collectors.toSet()); + boolean remove = keys.remove(this.DOCUMENT_EDIT_KEY + fileUuid + "-" + userId); + if (keys != null && keys.size() > 0) { + //姝e湪琚紪杈� + String existsKey = keys.toArray(new String[]{})[0]; + //杩欓噷浼氭姏鍑烘鍦ㄧ紪杈戠殑寮傚父 + throwBeingEditDocument(existsKey.substring(existsKey.lastIndexOf("-") + 1)); + } else if (remove) { + RedisUtil.setOutTime(key, getExpirationTime()); + return; } - - Map<String, Object> params = new HashMap<>(); - params.put("userId", userId); - params.put("fileUuid", fileUuid); - params.put("uniqueKey", IdUtil.randomUUID()); - RedisUtil.set(key, params); - RedisUtil.setOutTime(key, getExpirationTime()); } + + Map<String, Object> params = new HashMap<>(); + params.put("userId", userId); + params.put("fileUuid", fileUuid); + params.put("uniqueKey", IdUtil.randomUUID()); + RedisUtil.set(key, params); + RedisUtil.setOutTime(key, getExpirationTime()); } /** -- Gitblit v1.9.2