diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/LarkFileHelper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/LarkFileHelper.java index 7953777..d9857c6 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/LarkFileHelper.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/LarkFileHelper.java @@ -87,4 +87,30 @@ public class LarkFileHelper extends LarkHelper { throw new RuntimeException(new LarkException("LarkFileHelper.uploadFile",uploadAllFileResp.getMsg(),request).getErrorMessageBody()); } } + + /** + * 获取临时链接 + * @param request + * @return + */ + public BatchGetTmpDownloadUrlMediaRespBody getTemporaryMediaFileLink(LarkFileRequest request) { + BatchGetTmpDownloadUrlMediaResp linkResult = null; + try { + linkResult = buildClient(request) + .drive() + .media() + .batchGetTmpDownloadUrl( + BatchGetTmpDownloadUrlMediaReq.newBuilder() + .fileTokens(request.getFileToken()) + .build() + ); + } catch (Exception e) { + throw new RuntimeException(new LarkException("LarkFileHelper.getTemporaryMediaFileLink",e.getMessage(),request).getErrorMessageBody()); + } + if (linkResult!= null && linkResult.getCode() == 0){ + return linkResult.getData(); + }else { + throw new RuntimeException(new LarkException("LarkFileHelper.getTemporaryMediaFileLink",linkResult.getMsg(),request).getErrorMessageBody()); + } + } } diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/LarkTaskHelper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/LarkTaskHelper.java index 0ffae97..5e30da8 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/LarkTaskHelper.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/LarkHelper/LarkTaskHelper.java @@ -75,12 +75,12 @@ public class LarkTaskHelper extends LarkHelper { .build() ); } catch (Exception e) { - throw new RuntimeException(new LarkException("LarkTaskHelper.createTask",e.getMessage(),request).getErrorMessageBody()); + throw new RuntimeException(new LarkException("LarkTaskHelper.getTaskInfo",e.getMessage(),request).getErrorMessageBody()); } if (getTaskResp != null && getTaskResp.getCode() == 0){ return getTaskResp.getData(); }else { - throw new RuntimeException(new LarkException("LarkTaskHelper.createTask", getTaskResp.getMsg(),request).getErrorMessageBody()); + throw new RuntimeException(new LarkException("LarkTaskHelper.getTaskInfo", getTaskResp.getMsg(),request).getErrorMessageBody()); } } } 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 baf0982..b08e700 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 @@ -3,20 +3,25 @@ package com.ruoyi.flyingbook.LarkHelper.script; import com.google.gson.internal.LinkedTreeMap; import com.lark.oapi.service.bitable.v1.model.AppTableRecord; import com.lark.oapi.service.bitable.v1.model.GetAppTableRecordResp; +import com.lark.oapi.service.drive.v1.model.BatchGetTmpDownloadUrlMediaRespBody; +import com.lark.oapi.service.drive.v1.model.TmpDownloadUrl; import com.lark.oapi.service.drive.v1.model.UploadAllMediaRespBody; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.PdfEntity; import com.ruoyi.common.enums.ConfigurationSubTypeEnum; import com.ruoyi.common.enums.ConfigurationTypeEnum; import com.ruoyi.common.enums.FlagStatus; +import com.ruoyi.common.enums.TemplateSubTypeEnum; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.PdfUtils; import com.ruoyi.flyingbook.LarkHelper.LarkFileHelper; +import com.ruoyi.flyingbook.LarkHelper.LarkRobotHelper; import com.ruoyi.flyingbook.LarkHelper.LarkTableHelper; import com.ruoyi.flyingbook.domain.LarkTableConfiguration; import com.ruoyi.flyingbook.domain.LarkTableRelation; import com.ruoyi.flyingbook.domain.RequestVo; import com.ruoyi.flyingbook.domain.lark.LarkFileRequest; +import com.ruoyi.flyingbook.domain.lark.LarkRobotRequest; import com.ruoyi.flyingbook.domain.lark.LarkTableRequest; import com.ruoyi.flyingbook.domain.template.CourseFeedbackTemplateDto; import com.ruoyi.flyingbook.mapper.LarkTableConfigurationMapper; @@ -51,6 +56,8 @@ public class LarkCreatePdfHelper { @Autowired private LarkTableHelper larkTableHelper; + @Autowired + private LarkRobotHelper larkRobotHelper; private static final String FOLDER_SPLIT = Constants.FOLDER_SPLIT; @@ -112,12 +119,23 @@ public class LarkCreatePdfHelper { String fileToken = uploadAllMediaRespBody.getFileToken(); Map fileMap = new HashMap<>(); fileMap.put("file_token", fileToken); + String user = getUser(fields.get("人员"), "id"); 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); + + LarkFileRequest getTokenUrl = new LarkFileRequest(request.getAppId(), request.getAppSecret(), fileToken); + BatchGetTmpDownloadUrlMediaRespBody temporaryMediaFileLink = larkFileHelper.getTemporaryMediaFileLink(getTokenUrl); + TmpDownloadUrl[] tmpDownloadUrls = temporaryMediaFileLink.getTmpDownloadUrls(); + if (tmpDownloadUrls != null && tmpDownloadUrls.length > 0){ + TmpDownloadUrl tmpDownloadUrl = tmpDownloadUrls[0]; + String content = String.format("{\"text\":\"课程反馈表已生成完毕,%s\"}", tmpDownloadUrl.getTmpDownloadUrl()); + LarkRobotRequest larkRobotRequest = new LarkRobotRequest(request.getAppId(), request.getAppSecret(), user, TemplateSubTypeEnum.TEXT.getCode(),content); + larkRobotHelper.sendUserMessage(larkRobotRequest); + } } } diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/lark/LarkFileRequest.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/lark/LarkFileRequest.java index fd5115b..aafe737 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/lark/LarkFileRequest.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/lark/LarkFileRequest.java @@ -20,6 +20,7 @@ public class LarkFileRequest extends LarkRequest{ private String fileName; private Integer fileSize; private String parentNode; + private String[] fileToken; public LarkFileRequest(String appId, String appSecret, File file, String fileName, Integer fileSize, String parentNode) { super(appId, appSecret); @@ -28,4 +29,15 @@ public class LarkFileRequest extends LarkRequest{ this.fileSize = fileSize; this.parentNode = parentNode; } + + public LarkFileRequest(String appId, String appSecret, String fileToken) { + super(appId, appSecret); + String[] strings = {fileToken}; + this.fileToken = strings; + } + + public LarkFileRequest(String appId, String appSecret, String[] fileToken) { + super(appId, appSecret); + this.fileToken = fileToken; + } }