From 36947acbd9306131973a40efb5c338968008f136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=96=E5=85=94=E5=AD=90=E7=9A=84=E5=B0=8F=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Wed, 19 Jul 2023 05:47:01 +0000 Subject: [PATCH 1/2] =?UTF-8?q?add=20JavaThreadLocal.=20=E5=8F=B2=E5=AE=98?= =?UTF-8?q?=E5=8F=B2=E5=AE=98=E5=9C=A8=E5=93=AA=E9=87=8C=EF=BC=8C=E4=B8=80?= =?UTF-8?q?=E5=AE=9A=E8=A6=81=E6=8A=8A=E8=BF=99=E4=B8=AA=E9=80=BC=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E7=9A=84=E4=BB=A3=E7=A0=81=E5=86=99=E8=BF=9B=E5=8F=B2?= =?UTF-8?q?=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 卖兔子的小萝卜 --- JavaThreadLocal | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 JavaThreadLocal diff --git a/JavaThreadLocal b/JavaThreadLocal new file mode 100644 index 0000000..9916c0d --- /dev/null +++ b/JavaThreadLocal @@ -0,0 +1,37 @@ +public class ThreadLocalUtil { + private static final ThreadLocal> threadLocal = new ThreadLocal() { + protected Map initialValue() { + return new HashMap(0); + } + }; + + public static Map getThreadLocal() { + return threadLocal.get(); + } + + public static Object get(String key) { + Map map = (Map) threadLocal.get(); + return map.get(key); + } + + public static Object get(String key, Object defaultValue) { + Map map = (Map) threadLocal.get(); + return map.get(key) == null ? defaultValue : map.get(key); + } + + public static void set(String key, Object value) { + Map map = (Map) threadLocal.get(); + map.put(key, value); + } + + public static void set(Map keyValueMap) { + Map map = (Map) threadLocal.get(); + map.putAll(keyValueMap); + } + + public static Object remove(String key) { + Map map = (Map) threadLocal.get(); + return map.remove(key); + } + +} \ No newline at end of file -- Gitee From 2e0f21e4495c8e1b76e54af037ad2e5e60aa7694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=96=E5=85=94=E5=AD=90=E7=9A=84=E5=B0=8F=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Fri, 28 Jul 2023 01:51:57 +0000 Subject: [PATCH 2/2] =?UTF-8?q?add=20java/XtFileInfoServiceImpl.java.=20?= =?UTF-8?q?=E7=A5=9E=E4=BB=99=E4=BB=A3=E7=A0=81=E7=AC=AC=E4=BA=8C=E5=BC=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 卖兔子的小萝卜 --- java/XtFileInfoServiceImpl.java | 157 ++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 java/XtFileInfoServiceImpl.java diff --git a/java/XtFileInfoServiceImpl.java b/java/XtFileInfoServiceImpl.java new file mode 100644 index 0000000..19014f3 --- /dev/null +++ b/java/XtFileInfoServiceImpl.java @@ -0,0 +1,157 @@ + /** + * 根据模板生成word excel 并且上传到minio 中 + * + * @param bussType 业务类型:中文简称 tzgg、回执单hzd + * @param bussTypeName 业务类型名称 通知公告、通知公告 + * @param fileType 文件类型:docx和xlsx + * @param map 模板参照 + * @param url 模板路径 + * @param isPdf 0:word 1:pdf 2:word和pdf --例如需要界面编辑的就是0 不需要编辑就是1 例如回执单就是1 审计公告就是0 + * @param billId 业务id 以后做版本查询 + */ + public Map uploadCreateFile(String bussType, String bussTypeName, String fileType, Map map, String url,String isPdf,String billId){ + Map rtnMap = new HashMap(); + String rtnFileId = ""; + String filePdfId = ""; // pdf文件id + isPdf = CommonUtil.isNull(isPdf); // 0:word 1:pdf 2:word和pdf + try { + String uuid = CommonUtil.getUUID(); + String urls = sjxmProperties.getProfile() + "/" + uuid; // 文件上传路径 + //创建文件夹 + String fileName = "/" + bussTypeName; + File file = new File(urls); + if (!file.exists()) { + file.mkdirs(); + } + String fileUploadPath = ""; // word文档地址 + if(CommonUtil.isNull(fileType).equals("docx")){ + // -------------word + fileUploadPath = urls + fileName + ".docx"; // word文档地址 + XWPFDocument doc = WordExportUtil.exportWord07(url, map); + //输出文件 + FileOutputStream outs = new FileOutputStream(new File(fileUploadPath)); + doc.write(outs); + outs.flush(); + outs.close(); + + }else if(CommonUtil.isNull(fileType).equals("xlsx")){ + //---------------excel + fileUploadPath = urls + fileName + ".xlsx"; // word文档地址 + TemplateExportParams params = new TemplateExportParams(url); + Workbook workbook = ExcelExportUtil.exportExcel(params, map); + //输出文件 + FileOutputStream outs = new FileOutputStream(new File(fileUploadPath)); + workbook.write(outs); + outs.flush(); + outs.close(); + } + + if (!fileUploadPath.equals("")){ + String filePdfPath = urls + fileName + ".pdf"; // pdf生成地址 + + //File转MultipartFile + File tempFile = new File(fileUploadPath); + FileInputStream fileInputStream = new FileInputStream(tempFile); + MultipartFile multipartFile = new MockMultipartFile(tempFile.getName(), tempFile.getName(), + ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream); + + // 附件上传 + MultipartFile[] files = null; + FileInputStream fileInputStreamPdf = null; + + if(isPdf.equals("0")){ + files = new MultipartFile[1]; + files[0] = multipartFile; + } else if(isPdf.equals("1")) { + files = new MultipartFile[1]; + + if(CommonUtil.isNull(fileType).equals("docx")){ + //word 转pdf + WordToPdf wordToPdf = new WordToPdf(); + wordToPdf.change(fileUploadPath, filePdfPath); + }else{ + // excel 转pdf + ExeclToPDF excelToPdf = new ExeclToPDF(); + excelToPdf.change(fileUploadPath, filePdfPath); + } + //File转MultipartFile --pdf + File pdfFile = new File(filePdfPath); + fileInputStreamPdf = new FileInputStream(pdfFile); + MultipartFile multipartFilePdf = new MockMultipartFile(pdfFile.getName(), pdfFile.getName(), + ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStreamPdf); + + files[0] = multipartFilePdf; + + }else if(isPdf.equals("2")) { + files = new MultipartFile[2]; + files[0] = multipartFile; + + if(CommonUtil.isNull(fileType).equals("docx")){ + //word 转pdf + WordToPdf wordToPdf = new WordToPdf(); + wordToPdf.change(fileUploadPath, filePdfPath); + }else{ + // excel 转pdf + ExeclToPDF excelToPdf = new ExeclToPDF(); + excelToPdf.change(fileUploadPath, filePdfPath); + } + //File转MultipartFile --pdf + File pdfFile = new File(filePdfPath); + fileInputStreamPdf = new FileInputStream(pdfFile); + MultipartFile multipartFilePdf = new MockMultipartFile(pdfFile.getName(), pdfFile.getName(), + ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStreamPdf); + + files[1] = multipartFilePdf; + } + + + RetData r = uploadFiles(files); + List> resultMaps = (List>) r.getData(); + for (int z = 0; z < resultMaps.size(); z++) { + Map tempMaps = resultMaps.get(z); + String tempRtnFild = tempMaps.get("id"); + if (tempRtnFild.equals("-1")){ + tempRtnFild = ""; + } + if(isPdf.equals("0")){ + rtnFileId = tempRtnFild; //word + }else if(isPdf.equals("1")){ + filePdfId = tempRtnFild; //pdf + }else if(isPdf.equals("2")){ + if (z == 0) { + rtnFileId = tempRtnFild; + } else if (z == 1) { + filePdfId = tempRtnFild; + } + } + } + + fileInputStream.close(); + if(!isPdf.equals("0")){ + fileInputStreamPdf.close(); + File linshiFile2 = new File(filePdfPath); + if (linshiFile2.exists()) { + linshiFile2.delete(); + } + } + + //上传成功后删除临时文件 + File linshiFile = new File(fileUploadPath); + if (linshiFile.exists()) { + linshiFile.delete(); + } + + if (file.exists()) { + file.delete(); + } + + } + }catch (Exception e) { + e.printStackTrace(); + } + + rtnMap.put("rtnFileId",rtnFileId); + rtnMap.put("filePdfId",filePdfId); + return rtnMap; + + } \ No newline at end of file -- Gitee