Forráskód Böngészése

feat:修复导出流程文件接口,解决后台反前端跨域问题

韩帛霖 1 éve
szülő
commit
f87106fb20

+ 3 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/BpmProcessController.java

@@ -35,6 +35,7 @@ import org.springframework.web.multipart.MultipartFile;
  * @author hzh
  * @date 2023-10-10
  */
+@CrossOrigin
 @RestController
 @RequestMapping("/system/process")
 @Api(value = "/system/process", description = "流程定义接口")
@@ -127,8 +128,8 @@ public class BpmProcessController extends BaseController {
     @ApiImplicitParams({
             @ApiImplicitParam(name = "processId", value = "编号", dataType = "Long"),
     })
-    @GetMapping("/exportProcessFile")
-    public void exportProcessFile(@RequestParam("processIds") List<Long> processIds, HttpServletRequest request, HttpServletResponse response) throws Exception {
+    @GetMapping("/exportProcessFile/{processIds}")
+    public void exportProcessFile(@PathVariable List<Long> processIds, HttpServletRequest request, HttpServletResponse response) throws Exception {
         bpmProcessService.exportProcessFile(processIds, request, response);
     }
 

+ 3 - 0
ruoyi-admin/src/main/resources/application.yml

@@ -14,6 +14,9 @@ ruoyi:
   addressEnabled: false
   # 验证码类型 math 数组计算 char 字符验证
   captchaType: math
+  # 流程文件存储地址
+  bpmnPath: /Users/zrwj/Desktop/ZKQY_LJJ/log/file/bpmnXML/
+
 
 # 开发环境配置
 server:

+ 8 - 0
ruoyi-admin/src/main/resources/mybatis/mybatis-config.xml

@@ -19,10 +19,18 @@
         <setting name="callSettersOnNulls" value="true"/>
 
         <setting name="mapUnderscoreToCamelCase" value="true"/>
+
     </settings>
+    <typeHandlers>
+        <typeHandler handler="com.ruoyi.system.entity.BlobTypeHandler"/>
+    </typeHandlers>
     <!--  重写驼峰转换工具类  -->
     <objectWrapperFactory type="com.ruoyi.common.utils.MapWrapperFactory"/>
     <plugins>
         <plugin interceptor="com.ruoyi.framework.aspectj.SqlInterceptor"/>
     </plugins>
+
+
+
+
 </configuration>

+ 29 - 22
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BpmProcessServiceImpl.java

@@ -11,6 +11,7 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
 import java.util.Base64;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -110,6 +111,8 @@ public class BpmProcessServiceImpl implements IBpmProcessService {
         bpmProcess.setCreateTime(DateUtils.getNowDate());
         bpmProcess.setCreateBy(SecurityUtils.getUsername());
         bpmProcess.setProcessVersion(0L);
+        bpmProcess.setProcessType(0L);
+        bpmProcess.setStartEventType(0L);
         return bpmProcessMapper.insertBpmProcess(bpmProcess);
     }
 
@@ -197,16 +200,19 @@ public class BpmProcessServiceImpl implements IBpmProcessService {
 
         List<BpmProcess> bpmProcessList = bpmProcessMapper.selectBpmProcessByProcessIds(processIds);
         String localPath = RuoYiConfig.getProfile();
-        List<String> list = bpmProcessList.stream().map(m ->localPath + StringUtils.substringAfter(m.getProcessXmlPath(), Constants.RESOURCE_PREFIX)).collect(Collectors.toList());
-
-        if (CollectionUtils.isEmpty(list)){
+//        List<String> list = bpmProcessList.stream().map(m ->localPath + StringUtils.substringAfter(m.getProcessXmlPath(), Constants.RESOURCE_PREFIX)).collect(Collectors.toList());
+        List<String> list = new ArrayList<>();
+        bpmProcessList.forEach(item -> {
+            list.add(localPath.substring(0, localPath.length() - 1) + StringUtils.substringAfter(item.getProcessXmlPath(), Constants.RESOURCE_PREFIX));
+        });
+        if (CollectionUtils.isEmpty(list)) {
             throw new Exception("请选择要下载文件/图片");
         }
-
         //设置响应头信息
         response.reset();
         response.setCharacterEncoding("utf-8");
         response.setContentType("multipart/form-data");
+        response.setHeader("Access-Control-Allow-Origin", "*");
         //设置压缩包的名字,date为时间戳
         String date = String.valueOf(System.currentTimeMillis());
         String downloadName = "压缩包" + date + ".zip";
@@ -221,18 +227,18 @@ public class BpmProcessServiceImpl implements IBpmProcessService {
                 downloadName = new String(downloadName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
             }
         } catch (Exception e) {
+            System.err.println(e);
             log.error("系统异常", e);
         }
 
-        if (list.size()>1){
-            //多文件/图压缩下载
-            batchFileDownLoad(list,downloadName,response);
-
-        }else {
-            //单文件/图直接下载
-            singleFileDownLoad(list,bpmProcessList.get(0).getProcessName(),response);
-
-        }
+//        if (list.size()>1){
+        //多文件/图压缩下载
+        batchFileDownLoad(list, downloadName, response);
+//        }else {
+//            //单文件/图直接下载
+//            singleFileDownLoad(list,bpmProcessList.get(0).getProcessName(),response);
+//
+//        }
 
     }
 
@@ -254,7 +260,7 @@ public class BpmProcessServiceImpl implements IBpmProcessService {
                     //文件存储路径
                     String path = t;
                     //压缩文件中每个文件的文件名称
-                    String name = t.substring(t.lastIndexOf("\\")+1);
+                    String name = t.substring(t.lastIndexOf("\\") + 1);
                     log.info("batchDownloadFile:[filePath:{}]", path);
                     File file = new File(path);
                     if (!file.exists()) {
@@ -263,7 +269,7 @@ public class BpmProcessServiceImpl implements IBpmProcessService {
                     FileInputStream fs = null;
                     try {
                         //添加ZipEntry,并将ZipEntry中写入文件流
-                        zipOs.putNextEntry(new ZipEntry(name));
+                        zipOs.putNextEntry(new ZipEntry(URLEncoder.encode(name, StandardCharsets.UTF_8.toString()) + ".bpmn"));
                         os = new DataOutputStream(zipOs);
                         fs = new FileInputStream(file);
                         byte[] b = new byte[100];
@@ -305,27 +311,28 @@ public class BpmProcessServiceImpl implements IBpmProcessService {
 
     /**
      * 单文件直接下载
-     * @param list 文件/图片路径
+     *
+     * @param list     文件/图片路径
      * @param response
      */
-    private void singleFileDownLoad(List<String> list,String processName, HttpServletResponse response) throws UnsupportedEncodingException {
+    private void singleFileDownLoad(List<String> list, String processName, HttpServletResponse response) throws UnsupportedEncodingException {
 
         FileInputStream fis = null;
         OutputStream out = null;
         String path = list.get(0);
-        String name = path.substring(path.lastIndexOf("\\")+1);
-        response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(processName, StandardCharsets.UTF_8.toString())+".bpmn");
+        String name = path.substring(path.lastIndexOf("\\") + 1);
+        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(processName, StandardCharsets.UTF_8.toString()) + ".bpmn");
         try {
             fis = new FileInputStream(path);
             out = response.getOutputStream();
             byte[] b = new byte[1024];
             int len = 0;
-            while((len = fis.read(b))!=-1){
+            while ((len = fis.read(b)) != -1) {
                 out.write(b, 0, len);
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
-        }finally {
+        } finally {
             try {
                 if (out != null) {
                     out.flush();