diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/PdfUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/PdfUtils.java index 80043bc..8485acd 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/PdfUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/PdfUtils.java @@ -101,7 +101,7 @@ public class PdfUtils { } } - public boolean waterMark(PdfEntity pdf) throws IOException, DocumentException { + public boolean waterMark(PdfEntity pdf) throws IOException, DocumentException { PdfReader reader = null; PdfStamper stamper = null; FileOutputStream fileOutputStream = null; @@ -146,6 +146,7 @@ public class PdfUtils { watermark.setLineWidth(1f); watermark.stroke(); } + stamper.close(); reader.close(); return true; @@ -161,8 +162,17 @@ public class PdfUtils { if (fileOutputStream != null){ fileOutputStream.close(); } + removeFile(new File(pdf.getPdfAllPath())); return false; } } + private void removeFile(File file){ + try { + file.delete(); + }catch (Exception e){ + log.error("PdfUtils removeFile failed",e); + } + } + } diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/script/LarkCreatePdfHelper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/script/LarkCreatePdfHelper.java index 16fc880..baf0982 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/script/LarkCreatePdfHelper.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/script/LarkCreatePdfHelper.java @@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.io.File; +import java.time.LocalDateTime; import java.util.*; /** @@ -103,18 +104,29 @@ public class LarkCreatePdfHelper { entity.setTemplateName("JTDX_PDF_TEMPLATE.ftl"); pdfUtils.createFile(entity); File file = new File(pdfWatermarkingAllPath); - Long length = file.length(); - LarkFileRequest fileRequest = new LarkFileRequest(request.getAppId(),request.getAppSecret(), - file,file.getName(),length.intValue(),tableRelation.getFromAppToken()); - UploadAllMediaRespBody uploadAllMediaRespBody = larkFileHelper.uploadMediaFile(fileRequest); - String fileToken = uploadAllMediaRespBody.getFileToken(); - Map fileMap = new HashMap<>(); - fileMap.put("file_token",fileToken); - fields.clear(); - fields.put(attachment, Arrays.asList(fileMap)); - LarkTableRequest updateRequest = new LarkTableRequest(request.getAppId(),request.getAppSecret(), - tableRelation.getFromAppToken(),tableRelation.getFromTableId(),record.getRecordId(),fields); - larkTableHelper.updateTableRecord(updateRequest); + if (file.exists()) { + Long length = file.length(); + LarkFileRequest fileRequest = new LarkFileRequest(request.getAppId(), request.getAppSecret(), + file, file.getName(), length.intValue(), tableRelation.getFromAppToken()); + UploadAllMediaRespBody uploadAllMediaRespBody = larkFileHelper.uploadMediaFile(fileRequest); + String fileToken = uploadAllMediaRespBody.getFileToken(); + Map fileMap = new HashMap<>(); + fileMap.put("file_token", fileToken); + fields.clear(); + fields.put(attachment, Arrays.asList(fileMap)); + LarkTableRequest updateRequest = new LarkTableRequest(request.getAppId(), request.getAppSecret(), + tableRelation.getFromAppToken(), tableRelation.getFromTableId(), record.getRecordId(), fields); + larkTableHelper.updateTableRecord(updateRequest); + removeLocalFile(file); + } + } + + private void removeLocalFile(File file){ + try { + file.delete(); + }catch (Exception e){ + log.error("LarkCreatePdfHelper removeLocalFile fail",e); + } } private LarkTableConfiguration check(RequestVo request) { @@ -141,10 +153,12 @@ public class LarkCreatePdfHelper { resultDTO.setProgram(program); resultDTO.setStudentName(getUser(fields.get("人员"),"name")); resultDTO.setTutor(getUser(fields.get("人员"),"name")); - String startTimeStr = getTimeByDate(fields.get("日期")); - String endTimeStr = getTimeByDate(fields.get("日期")); - resultDTO.setStartClassTime(startTimeStr); - resultDTO.setEndClassTime(endTimeStr); + LocalDateTime startTime = getTimeByDate(fields.get("日期")); + LocalDateTime endTime = getTimeByDate(fields.get("日期")); + resultDTO.setMonth(String.valueOf(startTime.getMonthValue())); + resultDTO.setDay(String.valueOf(startTime.getDayOfMonth())); + resultDTO.setStartClassTime(DateUtils.ldt2str(startTime,DateUtils.YYYY_MM_DD_HH_MM_SS)); + resultDTO.setEndClassTime(DateUtils.ldt2str(endTime,DateUtils.YYYY_MM_DD_HH_MM_SS)); resultDTO.setFeedback("作业完成情况"); Integer feedbackScore = getNumber(fields.get("数字")); resultDTO.setFeedbackScore(String.format("%s /10",feedbackScore)); @@ -170,9 +184,9 @@ public class LarkCreatePdfHelper { /** * 获取日期信息 */ - private String getTimeByDate(Object data){ + private LocalDateTime getTimeByDate(Object data){ try { - return DateUtils.e2Str(data,DateUtils.YYYY_MM_DD_HH_MM_SS); + return DateUtils.e2ldt(data); }catch (Exception e){ log.info("LarkCreatePdfHelper getTimeByDate data",data,e); } diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EdiController.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EdiController.java index d5b1a08..b03204b 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EdiController.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/EdiController.java @@ -67,7 +67,7 @@ public class EdiController extends BaseController { String pdfWatermarkingAllPath = new StringBuilder(pdfGeneratePath).append("temporary").append(FOLDER_SPLIT).append(fileName).append("watermark").append(".pdf").toString(); entity.setPdfAllPath(pdfAllPath); entity.setPdfWatermarkingAllPath(pdfWatermarkingAllPath); - entity.setTitlePicAllPath(new StringBuilder(pdfGeneratePath).append("photo").append(FOLDER_SPLIT).append("pdf").append(FOLDER_SPLIT).append("jtdx_pdf_title.png").toString()); + entity.setTitlePicAllPath(new StringBuilder(pdfGeneratePath).append("photo").append(FOLDER_SPLIT).append("pdf").append(FOLDER_SPLIT).toString()); entity.setTemplatePath(new StringBuilder(pdfGeneratePath).append("template").toString()); entity.setFontAllPath(new StringBuilder(pdfGeneratePath).append("font").append(FOLDER_SPLIT).append("simsun.ttc").toString()); entity.setWatermarkingPickAllPath(new StringBuilder(pdfGeneratePath).append("photo").append(FOLDER_SPLIT).append("pdf").append(FOLDER_SPLIT).append("jtdx_pdf_watermark.jpg").toString()); @@ -97,6 +97,8 @@ public class EdiController extends BaseController { resultDTO.setProgram("program"); resultDTO.setStudentName("student"); resultDTO.setTutor("tutor"); + resultDTO.setMonth("10"); + resultDTO.setDay("12"); resultDTO.setStartClassTime("2023-05-21 15:51:45"); resultDTO.setEndClassTime("2023-05-22 15:51:45"); resultDTO.setFeedback("作业完成情况"); diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/template/CourseFeedbackTemplateDto.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/template/CourseFeedbackTemplateDto.java index 6653fe6..1fa9577 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/template/CourseFeedbackTemplateDto.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/template/CourseFeedbackTemplateDto.java @@ -13,6 +13,9 @@ public class CourseFeedbackTemplateDto { private String watermark; + private String month; + private String day; + private String program; private String studentName; private String startClassTime;