From 69e3afc7707d467b758858b52d3784947f7a502b Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期一, 20 五月 2024 10:25:23 +0800
Subject: [PATCH] !538 ♥️发布 5.2.0-BETA 公测版本 Merge pull request !538 from 疯狂的狮子Li/dev

---
 ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/flowable/cmd/AttachmentCmd.java |   64 ++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/flowable/cmd/AttachmentCmd.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/flowable/cmd/AttachmentCmd.java
new file mode 100644
index 0000000..dd9849a
--- /dev/null
+++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/flowable/cmd/AttachmentCmd.java
@@ -0,0 +1,64 @@
+package org.dromara.workflow.flowable.cmd;
+
+import cn.hutool.core.collection.CollUtil;
+import org.dromara.common.core.domain.dto.OssDTO;
+import org.dromara.common.core.service.OssService;
+import org.dromara.common.core.utils.SpringUtils;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.satoken.utils.LoginHelper;
+import org.flowable.common.engine.impl.interceptor.Command;
+import org.flowable.common.engine.impl.interceptor.CommandContext;
+import org.flowable.engine.impl.persistence.entity.AttachmentEntity;
+import org.flowable.engine.impl.persistence.entity.AttachmentEntityManager;
+import org.flowable.engine.impl.util.CommandContextUtil;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 闄勪欢涓婁紶
+ *
+ * @author may
+ */
+public class AttachmentCmd implements Command<Boolean> {
+
+    private final String fileId;
+
+    private final String taskId;
+
+    private final String processInstanceId;
+
+    public AttachmentCmd(String fileId, String taskId, String processInstanceId) {
+        this.fileId = fileId;
+        this.taskId = taskId;
+        this.processInstanceId = processInstanceId;
+    }
+
+    @Override
+    public Boolean execute(CommandContext commandContext) {
+        try {
+            if (StringUtils.isNotBlank(fileId)) {
+                List<OssDTO> ossList = SpringUtils.getBean(OssService.class).selectByIds(fileId);
+                if (CollUtil.isNotEmpty(ossList)) {
+                    for (OssDTO oss : ossList) {
+                        AttachmentEntityManager attachmentEntityManager = CommandContextUtil.getAttachmentEntityManager();
+                        AttachmentEntity attachmentEntity = attachmentEntityManager.create();
+                        attachmentEntity.setRevision(1);
+                        attachmentEntity.setUserId(LoginHelper.getUserId().toString());
+                        attachmentEntity.setName(oss.getOriginalName());
+                        attachmentEntity.setDescription(oss.getOriginalName());
+                        attachmentEntity.setType(oss.getFileSuffix());
+                        attachmentEntity.setTaskId(taskId);
+                        attachmentEntity.setProcessInstanceId(processInstanceId);
+                        attachmentEntity.setContentId(oss.getOssId().toString());
+                        attachmentEntity.setTime(new Date());
+                        attachmentEntityManager.insert(attachmentEntity);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return true;
+    }
+}

--
Gitblit v1.9.3