|
|
@@ -2,28 +2,37 @@ package cn.iocoder.yudao.module.iscs.service.workflow;
|
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
|
|
|
+import cn.iocoder.yudao.framework.common.util.io.FileDriveLetterUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
-import cn.iocoder.yudao.module.iscs.controller.admin.workflow.vo.WorkflowModePageReqVO;
|
|
|
-import cn.iocoder.yudao.module.iscs.controller.admin.workflow.vo.WorkflowModeRespVO;
|
|
|
-import cn.iocoder.yudao.module.iscs.controller.admin.workflow.vo.WorkflowModeSaveReqVO;
|
|
|
-import cn.iocoder.yudao.module.iscs.controller.admin.workflow.vo.WorkflowStepRespVO;
|
|
|
+import cn.iocoder.yudao.module.iscs.controller.admin.workflow.vo.*;
|
|
|
import cn.iocoder.yudao.module.iscs.dal.dataobject.workflow.WorkflowModeDO;
|
|
|
import cn.iocoder.yudao.module.iscs.dal.dataobject.workflow.WorkflowStepDO;
|
|
|
import cn.iocoder.yudao.module.iscs.dal.mysql.workflow.WorkflowModeMapper;
|
|
|
+import cn.iocoder.yudao.module.iscs.utils.AES256Utils;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
+import javax.crypto.BadPaddingException;
|
|
|
+import javax.crypto.IllegalBlockSizeException;
|
|
|
+import javax.crypto.NoSuchPaddingException;
|
|
|
+import java.io.*;
|
|
|
+import java.security.InvalidAlgorithmParameterException;
|
|
|
+import java.security.InvalidKeyException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
-
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipOutputStream;
|
|
|
/**
|
|
|
* 工作流模式 Service 实现类
|
|
|
*
|
|
|
@@ -135,4 +144,113 @@ public class WorkflowModeServiceImpl extends ServiceImpl<WorkflowModeMapper, Wor
|
|
|
return bean;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void exportWorkflowMode(HttpServletResponse response, List<Long> ids) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
|
|
|
+ Assert.isFalse(ids.isEmpty(), "导出的数据不可为空!");
|
|
|
+ // 开始查询数据
|
|
|
+ List<WorkflowModeDO> workflowModeDOS = listByIds(ids);
|
|
|
+ List<WorkflowStepDO> stepDOList = workflowStepService.list(Wrappers.<WorkflowStepDO>lambdaQuery()
|
|
|
+ .in(WorkflowStepDO::getModeId, ids));
|
|
|
+ // 开始构建数据
|
|
|
+ List<WorkflowModeExportVO> modeExportVOS = BeanUtils.toBean(workflowModeDOS, WorkflowModeExportVO.class);
|
|
|
+ for (WorkflowModeExportVO modeExportVO : modeExportVOS) {
|
|
|
+ List<WorkflowStepDO> list = stepDOList.stream().filter(o -> o.getModeId().equals(modeExportVO.getId())).toList();
|
|
|
+ List<WorkflowStepExportVO> stepExportVOS = BeanUtils.toBean(list, WorkflowStepExportVO.class);
|
|
|
+ modeExportVO.setStepList(stepExportVOS);
|
|
|
+ }
|
|
|
+ // 开始加密
|
|
|
+ String s = AES256Utils.AES256DECRYPT(modeExportVOS.toString());
|
|
|
+ // 时间戳
|
|
|
+ long currentTimestamp = System.currentTimeMillis();
|
|
|
+ // 开始写入dat文件
|
|
|
+ String url = getPath() + currentTimestamp + ".dat";
|
|
|
+ try (FileOutputStream fos = new FileOutputStream(url)) {
|
|
|
+ fos.write(s.getBytes()); // 写入字节数组
|
|
|
+ System.out.println("数据已成功写入" + currentTimestamp + ".dat");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开始写入.sha文件
|
|
|
+ String url1 = getPath() + currentTimestamp + ".sha";
|
|
|
+ try (FileOutputStream fos = new FileOutputStream(url1)) {
|
|
|
+ fos.write(s.getBytes()); // 写入字节数组
|
|
|
+ System.out.println("数据已成功写入" + currentTimestamp + ".sha");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开始压缩
|
|
|
+ List<String> filesToZip = List.of(url, url1);
|
|
|
+ String outputZip = getPath() + currentTimestamp + ".zip";
|
|
|
+
|
|
|
+ try {
|
|
|
+ zipFiles(filesToZip, outputZip);
|
|
|
+ System.out.println("成功创建ZIP文件:" + outputZip);
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.err.println("创建ZIP文件失败!");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 设置 HTTP 响应头
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + HttpUtils.encodeUtf8(currentTimestamp + ".zip"));
|
|
|
+ response.setContentType("application/zip");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String getPath() {
|
|
|
+ // D:
|
|
|
+ String driveLetter = FileDriveLetterUtils.getDriveLetter();
|
|
|
+ // 获取临时文件地址
|
|
|
+ String path = driveLetter + "/home/flow/temp/";
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将多个文件压缩到指定的ZIP文件中
|
|
|
+ *
|
|
|
+ * @param filePaths 待压缩的文件路径列表
|
|
|
+ * @param zipFilePath 目标ZIP文件路径
|
|
|
+ * @throws IOException 如果发生I/O错误
|
|
|
+ */
|
|
|
+ public static void zipFiles(List<String> filePaths, String zipFilePath) throws IOException {
|
|
|
+ // 创建ZIP输出流
|
|
|
+ try (FileOutputStream fos = new FileOutputStream(zipFilePath);
|
|
|
+ ZipOutputStream zos = new ZipOutputStream(fos)) {
|
|
|
+
|
|
|
+ for (String filePath : filePaths) {
|
|
|
+ File file = new File(filePath);
|
|
|
+ if (!file.exists() || !file.isFile()) {
|
|
|
+ System.out.println("警告:文件 " + filePath + " 不存在或不是文件,已跳过");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加文件到ZIP
|
|
|
+ try (FileInputStream fis = new FileInputStream(file);
|
|
|
+ BufferedInputStream bis = new BufferedInputStream(fis)) {
|
|
|
+
|
|
|
+ // 创建ZIP条目(保留文件名)
|
|
|
+ ZipEntry zipEntry = new ZipEntry(file.getName());
|
|
|
+ zos.putNextEntry(zipEntry);
|
|
|
+
|
|
|
+ // 设置压缩级别(可选)
|
|
|
+ zipEntry.setMethod(ZipEntry.DEFLATED); // 默认压缩方式
|
|
|
+
|
|
|
+ // 写入文件数据
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int bytesRead;
|
|
|
+ while ((bytesRead = bis.read(buffer)) != -1) {
|
|
|
+ zos.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭当前ZIP条目
|
|
|
+ zos.closeEntry();
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.err.println("错误:无法压缩文件 " + filePath);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|