Browse Source

feat:启用流程,修复导出流程图bug

xuezizhuo 1 year ago
parent
commit
5a4f677309

+ 10 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/BpmProcessController.java

@@ -97,6 +97,7 @@ public class BpmProcessController extends BaseController {
     @PutMapping
     @ApiOperation(value = "修改流程定义")
     public AjaxResult edit(BpmProcess bpmProcess, @RequestParam("fileXML") MultipartFile fileXML) {
+        System.err.println(bpmProcess.toString());
         return toAjax(bpmProcessService.updateBpmProcess(bpmProcess, fileXML));
     }
 
@@ -133,5 +134,14 @@ public class BpmProcessController extends BaseController {
         bpmProcessService.exportProcessFile(processIds, request, response);
     }
 
+    /**
+     * 启用流程
+     */
+    @PostMapping("/enableProcess")
+    public AjaxResult enableProcess(@RequestBody BpmProcess bpmProcess){
+        return toAjax(bpmProcessService.enableProcess(bpmProcess));
+    }
+
+
 
 }

+ 18 - 0
ruoyi-common/src/main/java/com/ruoyi/common/config/datasource/config/RedisDataClear.java

@@ -0,0 +1,18 @@
+package com.ruoyi.common.config.datasource.config;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+
+@Component
+
+public class RedisDataClear implements CommandLineRunner {
+    @Autowired
+    private RedisTemplate redisTemplate;
+
+    @Override
+    public void run(String... args) throws Exception {
+        redisTemplate.getConnectionFactory().getConnection().flushDb();
+    }
+}

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/BpmProcessMapper.java

@@ -65,4 +65,10 @@ public interface BpmProcessMapper
      */
     List<BpmProcess> selectBpmProcessByProcessIds(List<Long> processIds);
 
+    /**
+     * 查询当前新版本流程定义
+     * @param processKey 流程别名
+     * @return
+     */
+    BpmProcess selectBpmProcessByProcessKey(String processKey);
 }

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IBpmProcessService.java

@@ -75,6 +75,11 @@ public interface IBpmProcessService {
      */
     void exportProcessFile(List<Long> processIds, HttpServletRequest request, HttpServletResponse response) throws Exception;
 
+    /**
+     * 启用流程
+     */
+    int enableProcess(BpmProcess bpmProcess);
+
 
 
 }

+ 26 - 8
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BpmProcessServiceImpl.java

@@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.system.mapper.BpmProcessMapper;
 import com.ruoyi.system.service.IBpmProcessService;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.multipart.MultipartFile;
 import org.w3c.dom.Document;
@@ -178,10 +179,12 @@ public class BpmProcessServiceImpl implements IBpmProcessService {
      */
     @Override
     public int bpmBackups(BpmProcess bpmProcess) {
+        String remark = bpmProcess.getRemark(); // 存储备份操作信息
         bpmProcess = bpmProcessMapper.selectBpmProcessByProcessId(bpmProcess.getProcessId());
         bpmProcess.setCreateTime(DateUtils.getNowDate());
         bpmProcess.setCreateBy(SecurityUtils.getUsername());
         bpmProcess.setProcessVersion(1L);  // 设置为历史版本,备份状态
+        bpmProcess.setRemark(remark);
         String filePath = RuoYiConfig.getProfile() + StringUtils.substringAfter(bpmProcess.getProcessXmlPath(), Constants.RESOURCE_PREFIX);
         // 复制流程文件
         Path fileInfo = Paths.get(filePath);
@@ -203,7 +206,7 @@ public class BpmProcessServiceImpl implements IBpmProcessService {
 //        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));
+            list.add(localPath + StringUtils.substringAfter(item.getProcessXmlPath(), Constants.RESOURCE_PREFIX));
         });
         if (CollectionUtils.isEmpty(list)) {
             throw new Exception("请选择要下载文件/图片");
@@ -215,7 +218,7 @@ public class BpmProcessServiceImpl implements IBpmProcessService {
         response.setHeader("Access-Control-Allow-Origin", "*");
         //设置压缩包的名字,date为时间戳
         String date = String.valueOf(System.currentTimeMillis());
-        String downloadName = "压缩包" + date + ".zip";
+        String downloadName = date + ".zip";
         //返回客户端浏览器的版本号、类型
         String agent = request.getHeader("USER-AGENT");
         try {
@@ -231,15 +234,30 @@ public class BpmProcessServiceImpl implements IBpmProcessService {
             log.error("系统异常", e);
         }
 
-//        if (list.size()>1){
+        if (list.size()>1){
         //多文件/图压缩下载
         batchFileDownLoad(list, downloadName, response);
-//        }else {
-//            //单文件/图直接下载
-//            singleFileDownLoad(list,bpmProcessList.get(0).getProcessName(),response);
-//
-//        }
+        }else {
+            //单文件/图直接下载
+            singleFileDownLoad(list,bpmProcessList.get(0).getProcessName(),response);
 
+        }
+
+    }
+
+    @Override
+    @Transactional
+    public int enableProcess(BpmProcess bpmProcess) {
+        //查询最新版本流程
+        BpmProcess process = bpmProcessMapper.selectBpmProcessByProcessKey(bpmProcess.getProcessKey());
+        //当前最新版本流程改为流程备份
+        BpmProcess process1 = new BpmProcess();
+        process1.setProcessId(process.getProcessId());
+        process1.setProcessVersion(1L);
+        bpmProcessMapper.updateBpmProcess(process1);
+        //历史版本改为最新版本流程
+        bpmProcess.setProcessVersion(0L);
+        return bpmProcessMapper.updateBpmProcess(bpmProcess);
     }
 
     private void batchFileDownLoad(List<String> list, String downloadName, HttpServletResponse response) {

+ 7 - 1
ruoyi-system/src/main/resources/mapper/BpmProcessMapper.xml

@@ -48,7 +48,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 #{processXmlContent}
             </if>
             <if test="processXmlPath != null  and processXmlPath != ''">and process_xml_path = #{processXmlPath}</if>
-            and process_version = 0 and del_flag = '0'
+            <if test="processVersion != null">and process_version = #{processVersion}</if>
+            and del_flag = '0'
         </where>
         order by create_time desc
     </select>
@@ -149,4 +150,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{processId}
         </foreach>
     </select>
+
+    <select id="selectBpmProcessByProcessKey" resultMap="BpmProcessResult">
+        <include refid="selectBpmProcessVo"/>
+        where process_key = #{processKey} and process_version = 0 and del_flag = '0'
+    </select>
 </mapper>