diff --git a/admin-convert-pdf/pom.xml b/admin-framework/admin-convert-pdf/pom.xml similarity index 81% rename from admin-convert-pdf/pom.xml rename to admin-framework/admin-convert-pdf/pom.xml index 10cff4f4..8701ab87 100644 --- a/admin-convert-pdf/pom.xml +++ b/admin-framework/admin-convert-pdf/pom.xml @@ -3,8 +3,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - admin com.ibeetl + admin-framwork 1.3.1 4.0.0 @@ -30,12 +30,13 @@ itextpdf 5.5.13.3 + com.aspose aspose-words 18.10 - jdk16 - + system + ${project.basedir}/src/main/resources/lib/aspose-words-18.10-jdk16.jar com.aspose @@ -45,7 +46,9 @@ com.aspose aspose-cells - 18.2 + 20.7 + system + ${project.basedir}/src/main/resources/lib/aspose-cells-20.7.jar diff --git a/admin-convert-pdf/src/main/java/util/convertPDF/PDFConverUtil.java b/admin-framework/admin-convert-pdf/src/main/java/util/convertPDF/PDFConverUtil.java similarity index 80% rename from admin-convert-pdf/src/main/java/util/convertPDF/PDFConverUtil.java rename to admin-framework/admin-convert-pdf/src/main/java/util/convertPDF/PDFConverUtil.java index 6462496f..9efb9690 100644 --- a/admin-convert-pdf/src/main/java/util/convertPDF/PDFConverUtil.java +++ b/admin-framework/admin-convert-pdf/src/main/java/util/convertPDF/PDFConverUtil.java @@ -33,14 +33,16 @@ public final class PDFConverUtil { final private static Map> types = new HashMap<>(); public static enum TypeEnum { - WORD, EXCEL, PPT, PPTX + WORD, EXCEL, PPT, PPTX, OTHER } static { - types.put(WORD, Arrays.asList("DOC", "DOCX", "OOXML", "RTF HTML", "OpenDocument", "PDF","EPUB", "XPS", "SWF")); + types.put(WORD, Arrays.asList("DOC", "DOCX")); types.put(EXCEL, Arrays.asList("XLS", "XLSX")); types.put(PPT, Arrays.asList("PPT")); types.put(PPTX, Arrays.asList("PPTX")); + types.put(OTHER, Arrays.asList("OOXML", "RTF HTML", "OpenDocument", "PDF","EPUB", "XPS", "SWF")); + } /** @@ -95,13 +97,8 @@ public final class PDFConverUtil { e.printStackTrace(); return false; } finally { - try { - if (document != null) { - document.close(); - } - } catch (Exception e) { - e.printStackTrace(); - } + closeOutput(outputStream); + closeInput(inputStream); } return true; @@ -129,18 +126,50 @@ public final class PDFConverUtil { e.printStackTrace(); return false; }finally { - if (outputStream != null) { - try { - outputStream.flush(); - outputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } + closeOutput(outputStream); + closeInput(inputStream); } return true; } + /** + * 关闭输出流 + * @param outputStream + */ + private static void closeOutput(OutputStream outputStream) { + if (outputStream != null) { + try { + outputStream.flush(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * 关闭输出流 + * @param inputStream + */ + private static void closeInput(InputStream inputStream) { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private static void close(Document document, PdfWriter pdfWriter) { + if (document != null) { + document.close(); + } + if (pdfWriter != null) { + pdfWriter.close(); + } + } + // 官方文档的要求 无需理会 public static boolean getLicense() { boolean result = false; @@ -173,7 +202,7 @@ public final class PDFConverUtil { **/ public static boolean excelToPdf(InputStream inputStream, OutputStream outputStream) { // 验证License 若不验证则转化出的pdf文档会有水印产生 - if (!getExeclLicense()) { + if (!getExcelLicense()) { return false; } try { @@ -183,7 +212,6 @@ public final class PDFConverUtil { com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions(); pdfSaveOptions.setOnePagePerSheet(false); - int[] autoDrawSheets={3}; //当excel中对应的sheet页宽度太大时,在PDF中会拆断并分页。此处等比缩放。 autoDraw(wb,autoDrawSheets); @@ -192,13 +220,14 @@ public final class PDFConverUtil { //隐藏workbook中不需要的sheet页。 printSheetPage(wb,showSheets); wb.save(outputStream, pdfSaveOptions); - outputStream.flush(); - outputStream.close(); System.out.println("excel转换完毕"); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); + }finally { + closeOutput(outputStream); + closeInput(inputStream); } return true; } @@ -237,10 +266,21 @@ public final class PDFConverUtil { } } - public static boolean getExeclLicense() { + public static boolean getExcelLicense() { boolean result = false; try { - String s = "Aspose.Total for JavaAspose.Words for JavaEnterprise20991231209912318bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU="; + String s = "\n" + + " \n" + + " \n" + + " Aspose.Cells for Java\n" + + " \n" + + " Enterprise\n" + + " 29991231\n" + + " 29991231\n" + + " evilrule\n" + + " \n" + + " evilrule\n" + + ""; ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes()); com.aspose.cells.License aposeLic = new com.aspose.cells.License(); aposeLic.setLicense(is); @@ -284,11 +324,13 @@ public final class PDFConverUtil { HSLFSlide hslfSlide = hslfSlideList.get(i); // 设置字体, 解决中文乱码 for (HSLFShape shape : hslfSlide.getShapes()) { - HSLFTextShape textShape = (HSLFTextShape) shape; + if (shape instanceof HSLFTextShape) { + HSLFTextShape textShape = (HSLFTextShape) shape; - for (HSLFTextParagraph textParagraph : textShape.getTextParagraphs()) { - for (HSLFTextRun textRun : textParagraph.getTextRuns()) { - textRun.setFontFamily("宋体"); + for (HSLFTextParagraph textParagraph : textShape.getTextParagraphs()) { + for (HSLFTextRun textRun : textParagraph.getTextRuns()) { + textRun.setFontFamily("宋体"); + } } } } @@ -315,12 +357,9 @@ public final class PDFConverUtil { e.printStackTrace(); return false; } finally { - if (document != null) { - document.close(); - } - if (pdfWriter != null) { - pdfWriter.close(); - } + close(document, pdfWriter); + closeOutput(outputStream); + closeInput(inputStream); } System.out.println("ppt转换完毕"); return true; @@ -362,11 +401,13 @@ public final class PDFConverUtil { // 设置字体, 解决中文乱码 for (XSLFShape shape : slide.getShapes()) { - XSLFTextShape textShape = (XSLFTextShape) shape; + if (shape instanceof XSLFTextShape) { + XSLFTextShape textShape = (XSLFTextShape) shape; - for (XSLFTextParagraph textParagraph : textShape.getTextParagraphs()) { - for (XSLFTextRun textRun : textParagraph.getTextRuns()) { - textRun.setFontFamily("宋体"); + for (XSLFTextParagraph textParagraph : textShape.getTextParagraphs()) { + for (XSLFTextRun textRun : textParagraph.getTextRuns()) { + textRun.setFontFamily("宋体"); + } } } } @@ -393,12 +434,9 @@ public final class PDFConverUtil { e.printStackTrace(); return false; } finally { - if (document != null) { - document.close(); - } - if (pdfWriter != null) { - pdfWriter.close(); - } + close(document, pdfWriter); + closeOutput(outputStream); + closeInput(inputStream); } System.out.println("pptx转换完毕"); return true; @@ -419,14 +457,17 @@ public final class PDFConverUtil { if (types.get(WORD).contains(fileSuffix)) { return wordToPdfByAspose(inputStream, outputStream); } + if (types.get(EXCEL).contains(fileSuffix)) { + return excelToPdf(inputStream, outputStream); + } if (types.get(PPT).contains(fileSuffix)) { return pptToPdf(inputStream, outputStream); } if (types.get(PPTX).contains(fileSuffix)) { return pptxToPdf(inputStream, outputStream); } - if (types.get(EXCEL).contains(fileSuffix)) { - return excelToPdf(inputStream, outputStream); + if (types.get(OTHER).contains(fileSuffix)) { + return wordToPdfByAspose(inputStream, outputStream); } return false; } diff --git a/admin-framework/admin-convert-pdf/src/main/resources/lib/aspose-cells-20.7.jar b/admin-framework/admin-convert-pdf/src/main/resources/lib/aspose-cells-20.7.jar new file mode 100644 index 00000000..9676f04c Binary files /dev/null and b/admin-framework/admin-convert-pdf/src/main/resources/lib/aspose-cells-20.7.jar differ diff --git a/admin-framework/admin-convert-pdf/src/main/resources/lib/aspose-words-18.10-jdk16.jar b/admin-framework/admin-convert-pdf/src/main/resources/lib/aspose-words-18.10-jdk16.jar new file mode 100644 index 00000000..33057f90 Binary files /dev/null and b/admin-framework/admin-convert-pdf/src/main/resources/lib/aspose-words-18.10-jdk16.jar differ diff --git a/admin-framework/pom.xml b/admin-framework/pom.xml new file mode 100644 index 00000000..36e001f1 --- /dev/null +++ b/admin-framework/pom.xml @@ -0,0 +1,23 @@ + + + + admin + com.ibeetl + 1.3.1 + + 4.0.0 + com.ibeetl + admin-framwork + pom + + + 8 + 8 + + + + admin-convert-pdf + + \ No newline at end of file diff --git a/httpTest/SchoolClass.http b/httpTest/SchoolClass.http deleted file mode 100644 index e69de29b..00000000 diff --git a/httpTest/Student.http b/httpTest/Student.http deleted file mode 100644 index edc2a604..00000000 --- a/httpTest/Student.http +++ /dev/null @@ -1,10 +0,0 @@ -### 学生列表 -POST {{baseURL}}/jlw/student/list.json -Content-Type: application/x-www-form-urlencoded -Cookie: JSESSIONID={{session}} - - -### -GET {{baseURL}}/jlw/student/getValues.json?universitySystemId=1569331621092564992 -Cookie: JSESSIONID={{session}} - diff --git a/httpTest/TeacherMergeSchoolClass.http b/httpTest/TeacherMergeSchoolClass.http deleted file mode 100644 index 6b2ae1b9..00000000 --- a/httpTest/TeacherMergeSchoolClass.http +++ /dev/null @@ -1,6 +0,0 @@ -### 教师关联班级 -POST {{baseURL}}/jlw/teacherOpenCourseMergeSchoolClass/add.json -Content-Type: application/x-www-form-urlencoded -Cookie: JSESSIONID={{session}} - -schoolClassId=1&teacherOpenCourseId=1569699665614643200 \ No newline at end of file diff --git a/httpTest/TeacherOpenCourse.http b/httpTest/TeacherOpenCourse.http deleted file mode 100644 index 9b75db62..00000000 --- a/httpTest/TeacherOpenCourse.http +++ /dev/null @@ -1,21 +0,0 @@ -### 课程开课 -POST {{baseURL}}/jlw/teacherOpenCourse/add.json -Content-Type: application/x-www-form-urlencoded -Cookie: JSESSIONID={{session}} - -teacherId=2&teacherOpenCourseTitle={{$randomInt}}&teacherOpenCourseCode={{$randomInt}}&teacherOpenCourseCover=http://baidu.com&startTime=2022-09-12&endTime=2022-10-12 - - -### 禁用开课的课程 -POST {{baseURL}}/jlw/teacherOpenCourse/edit.json -Content-Type: application/x-www-form-urlencoded -Cookie: JSESSIONID={{session}} -# 打开开课的课程 teacherOpenCourseStatus=1 -teacherOpenCourseId=1569699665614643200&teacherOpenCourseStatus=2 - -### 排课列表 -POST {{baseURL}}/jlw/teacherOpenCourse/edit.json -Content-Type: application/x-www-form-urlencoded -Cookie: JSESSIONID={{session}} -# 打开开课的课程 teacherOpenCourseStatus=1 -teacherOpenCourseId=1569699665614643200&teacherOpenCourseStatus=2 \ No newline at end of file diff --git a/httpTest/TeacherOpenCourseChatLog.http b/httpTest/TeacherOpenCourseChatLog.http deleted file mode 100644 index 7969c093..00000000 --- a/httpTest/TeacherOpenCourseChatLog.http +++ /dev/null @@ -1,19 +0,0 @@ -### 教师发表评论 -POST {{baseURL}}/jlw/teacherOpenCourseChatLog/add.json -Content-Type: application/json -Cookie: JSESSIONID={{session}} - -{ - "chatContent": "我是讨论的内容_{{$timestamp}}", - "keywords": "讨论,内容", - "schoolClassIds": "1,2", - "teacherId": "2", - "teacherOpenCourseId": "1569699665614643200" -} - -### 教师开课互动 -POST {{baseURL}}/jlw/teacherOpenCourseChatLog/details.json -Content-Type: application/x-www-form-urlencoded -Cookie: JSESSIONID={{session}} - -teacherOpenCourseChatLogParentId=1571525020268797952 diff --git a/httpTest/TeacherOpenCourseQuestion.http b/httpTest/TeacherOpenCourseQuestion.http deleted file mode 100644 index 76669482..00000000 --- a/httpTest/TeacherOpenCourseQuestion.http +++ /dev/null @@ -1,25 +0,0 @@ -### 新增作业 -POST {{baseURL}}/jlw/teacherOpenCourseQuestion/addByType.json -Content-Type: application/json -Cookie: JSESSIONID={{session}} - -{ - "teacherOpenCourseId": 59, - "teacherOpenCourseQuestionName": "fake_data", - "teacherOpenCourseQuestionClasses": "2", - "teacherOpenCourseQuestionStartTime": "2018-12-08 12:40:39", - "teacherOpenCourseQuestionEndTime": "2031-08-02 15:28:09", - "teacherOpenCourseQuestionType": "QUESTION", - "teacherOpenCourseQuestionUploadFile": "fake_data", - "teacherOpenCourseQuestionPushStatus": 1, - "teacherOpenCourseQuestionStatus": 1, - "teacherOpenCourseQuestionAddTime": "2023-12-06 19:10:09", - "teacherOpenCourseQuestionSettingQuery": { - "teacherOpenCourseQuestionSettingDoCount": 10, - "teacherOpenCourseQuestionSettingQuestionNoOrder": 1, - "teacherOpenCourseQuestionSettingOptionNoOrder": 1, - "teacherOpenCourseQuestionSettingEndShowQa": 1, - "teacherOpenCourseQuestionSettingEndShowTrueFalse": 1, - "teacherOpenCourseQuestionSettingAddTime": "2022-05-25 03:23:43" - } -} \ No newline at end of file diff --git a/httpTest/TeacherOpenCourseScheduleSession.http b/httpTest/TeacherOpenCourseScheduleSession.http deleted file mode 100644 index 84ab1ab1..00000000 --- a/httpTest/TeacherOpenCourseScheduleSession.http +++ /dev/null @@ -1,63 +0,0 @@ -### 学校管理员--新增排课 -POST {{baseURL}}/jlw/teacherOpenCourseScheduleSession/addSession.json -Content-Type: application/json -Cookie: JSESSIONID={{session}} - -//{ -// "startTime": "2022-10-25", -// "weekNum": "3", -// "openOnHolidays": false, -// "weekDetail": [ -// "T1", -// "T2", -// "T3", -// "T4", -// "T5" -// ], -// "schoolClassIdPlural": "5,11,8", -// "teacherId": "1", -// "teacherOpenCourseId": "1569", -// "sessionClassList": { -// "1568607566282530816": [ -// 1568633666106728448, -// 1568634328282472448, -// 1568634328282472448 -// ], -// "1568621132431663104": [ -// 1586024846784110592, -// 1586025166549458944 -// ] -// } -//} - -{ - "startTime": "2022-10-25", - "weekNum": "4", - "openOnHolidays": false, - "weekDetail": [ - "T1", - "T2", - "T3", - "T4" - ], - "schoolClassIdPlural": "12,13,14,7,9", - "teacherId": "102", - "teacherOpenCourseId": "10086", - "sessionClassList": { - "1568607566282530816": [ - 1586025337723199488 - ], - "1568621132431663104": [ - 1586025244957777920 - ] - } -} - -### 排课列表 -POST {{baseURL}}/jlw/teacherOpenCourseScheduleSession/groupList.json -Content-Type: application/x-www-form-urlencoded -Cookie: JSESSIONID={{session}} -# 可以带TeacherOpenCourseScheduleSessionQuery 里的查询参数 - - - diff --git a/httpTest/http-client.private.env.json b/httpTest/http-client.private.env.json deleted file mode 100644 index 5617ee70..00000000 --- a/httpTest/http-client.private.env.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "dev": { - "baseURL": "http://localhost:9090/server/", - "session": "4DF96B3C791C90F8696C81F5EED4F81C" - } -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index bf352ad4..0a20caaa 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ admin-console web admin-test - admin-convert-pdf + admin-framework diff --git a/web/pom.xml b/web/pom.xml index f2935869..b70f5188 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -21,10 +21,10 @@ com.ibeetl admin-core - - - - + + com.ibeetl + admin-convert-pdf + com.ibeetl diff --git a/web/src/main/java/com/ibeetl/jlw/web/TempFileController.java b/web/src/main/java/com/ibeetl/jlw/web/TempFileController.java index 05c6fca9..40339c4f 100644 --- a/web/src/main/java/com/ibeetl/jlw/web/TempFileController.java +++ b/web/src/main/java/com/ibeetl/jlw/web/TempFileController.java @@ -1,13 +1,17 @@ package com.ibeetl.jlw.web; +import cn.hutool.core.io.FileUtil; import cn.jlw.Interceptor.RFile; import com.ibeetl.admin.core.web.JsonResult; import com.ibeetl.jlw.entity.FileEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseBody; +import util.convertPDF.PDFConverUtil; +import java.io.BufferedInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -76,12 +80,16 @@ public class TempFileController { //fileEntity.moveTo("D://"); //相对路径 //fileEntity.moveTo("/image"); -// if (null != fileEntity) { -// String absoluteUrl = fileEntity.getAbsoluteUrl(); -// BufferedInputStream inputStream = FileUtil.getInputStream(absoluteUrl); -// FileOutputStream outputStream = new FileOutputStream(absoluteUrl.replaceAll("\\.[^\\.]+", ".pdf")); -// PDFConverUtil.convertToPDFByFileNameSuffix(absoluteUrl, inputStream, outputStream); -// } + if (null != fileEntity) { + String absoluteUrl = fileEntity.getAbsoluteUrl(); + BufferedInputStream inputStream = FileUtil.getInputStream(absoluteUrl); + String pdfName = absoluteUrl.replaceAll("\\.[^\\.]+", ".pdf"); + FileOutputStream outputStream = new FileOutputStream(pdfName); + boolean convertedSuccess = PDFConverUtil.convertToPDFByFileNameSuffix(absoluteUrl, inputStream, outputStream); + if(convertedSuccess) { + fileEntity.set("cvPDFAbsoluteUrl", pdfName); + } + } return JsonResult.success(fileEntity); //return JsonResult.success();