update 升级warm-flow到1.6.0-m4

This commit is contained in:
AprilWind 2025-01-15 16:56:09 +08:00
parent 3444b50da6
commit 4ba4ea4fcc
6 changed files with 44 additions and 70 deletions

View File

@ -50,7 +50,7 @@
<!-- 面向运行时的D-ORM依赖 --> <!-- 面向运行时的D-ORM依赖 -->
<anyline.version>8.7.2-20241022</anyline.version> <anyline.version>8.7.2-20241022</anyline.version>
<!--工作流配置--> <!--工作流配置-->
<warm-flow.version>1.3.7</warm-flow.version> <warm-flow.version>1.6.0-m4</warm-flow.version>
<!-- 插件版本 --> <!-- 插件版本 -->
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version> <maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>

View File

@ -1,12 +1,6 @@
package org.dromara.workflow.config; package org.dromara.workflow.config;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import org.dromara.warm.flow.core.config.WarmFlow;
import org.dromara.warm.flow.core.utils.IdUtils;
import org.dromara.warm.plugin.modes.sb.config.BeanConfig;
import org.dromara.workflow.common.ConditionalOnEnable; import org.dromara.workflow.common.ConditionalOnEnable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
@ -16,16 +10,7 @@ import org.springframework.context.annotation.Configuration;
*/ */
@ConditionalOnEnable @ConditionalOnEnable
@Configuration @Configuration
public class WarmFlowConfig extends BeanConfig { public class WarmFlowConfig {
@Autowired
private IdentifierGenerator identifierGenerator;
@Override
public void after(WarmFlow flowConfig) {
// 设置Mybatis-Plus默认主键生成器
IdUtils.setInstanceNative(() -> identifierGenerator.nextId(null).longValue());
}
} }

View File

@ -104,7 +104,6 @@ public class FlwDefinitionController extends BaseController {
@Log(title = "流程定义", businessType = BusinessType.INSERT) @Log(title = "流程定义", businessType = BusinessType.INSERT)
@PutMapping("/publish/{id}") @PutMapping("/publish/{id}")
@RepeatSubmit() @RepeatSubmit()
@Transactional(rollbackFor = Exception.class)
public R<Boolean> publish(@PathVariable Long id) { public R<Boolean> publish(@PathVariable Long id) {
return R.ok(flwDefinitionService.publish(id)); return R.ok(flwDefinitionService.publish(id));
} }
@ -127,7 +126,6 @@ public class FlwDefinitionController extends BaseController {
*/ */
@Log(title = "流程定义", businessType = BusinessType.DELETE) @Log(title = "流程定义", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
@Transactional(rollbackFor = Exception.class)
public R<Void> remove(@PathVariable List<Long> ids) { public R<Void> remove(@PathVariable List<Long> ids) {
return toAjax(flwDefinitionService.removeDef(ids)); return toAjax(flwDefinitionService.removeDef(ids));
} }
@ -153,9 +151,8 @@ public class FlwDefinitionController extends BaseController {
*/ */
@Log(title = "流程定义", businessType = BusinessType.IMPORT) @Log(title = "流程定义", businessType = BusinessType.IMPORT)
@PostMapping("/importDef") @PostMapping("/importDef")
@Transactional(rollbackFor = Exception.class)
public R<Boolean> importDef(MultipartFile file, String category) { public R<Boolean> importDef(MultipartFile file, String category) {
return R.ok(flwDefinitionService.importXml(file, category)); return R.ok(flwDefinitionService.importJson(file, category));
} }
/** /**
@ -172,13 +169,13 @@ public class FlwDefinitionController extends BaseController {
} }
/** /**
* 获取流程定义xml字符串 * 获取流程定义JSON字符串
* *
* @param id 流程定义id * @param id 流程定义id
*/ */
@GetMapping("/xmlString/{id}") @GetMapping("/xmlString/{id}")
public R<String> xmlString(@PathVariable Long id) { public R<String> xmlString(@PathVariable Long id) {
return R.ok("操作成功", defService.xmlString(id)); return R.ok("操作成功", defService.exportJson(id));
} }
/** /**
@ -189,6 +186,7 @@ public class FlwDefinitionController extends BaseController {
*/ */
@RepeatSubmit() @RepeatSubmit()
@PutMapping("/active/{id}") @PutMapping("/active/{id}")
@Transactional(rollbackFor = Exception.class)
public R<Boolean> active(@PathVariable Long id, @RequestParam boolean active) { public R<Boolean> active(@PathVariable Long id, @RequestParam boolean active) {
return R.ok(active ? defService.active(id) : defService.unActive(id)); return R.ok(active ? defService.active(id) : defService.unActive(id));
} }

View File

@ -60,7 +60,7 @@ public interface IFlwDefinitionService {
* @param category 分类 * @param category 分类
* @return 结果 * @return 结果
*/ */
boolean importXml(MultipartFile file, String category); boolean importJson(MultipartFile file, String category);
/** /**
* 删除流程定义 * 删除流程定义

View File

@ -3,22 +3,21 @@ package org.dromara.workflow.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IoUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StreamUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.json.utils.JsonUtils;
import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.warm.flow.core.dto.FlowCombine; import org.dromara.warm.flow.core.dto.DefJson;
import org.dromara.warm.flow.core.entity.Definition;
import org.dromara.warm.flow.core.enums.NodeType; import org.dromara.warm.flow.core.enums.NodeType;
import org.dromara.warm.flow.core.enums.PublishStatus; import org.dromara.warm.flow.core.enums.PublishStatus;
import org.dromara.warm.flow.core.service.DefService; import org.dromara.warm.flow.core.service.DefService;
@ -42,6 +41,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -120,6 +121,7 @@ public class FlwDefinitionServiceImpl implements IFlwDefinitionService {
* @param id 流程定义id * @param id 流程定义id
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class)
public boolean publish(Long id) { public boolean publish(Long id) {
List<FlowNode> flowNodes = flowNodeMapper.selectList(new LambdaQueryWrapper<FlowNode>().eq(FlowNode::getDefinitionId, id)); List<FlowNode> flowNodes = flowNodeMapper.selectList(new LambdaQueryWrapper<FlowNode>().eq(FlowNode::getDefinitionId, id));
List<String> errorMsg = new ArrayList<>(); List<String> errorMsg = new ArrayList<>();
@ -143,16 +145,20 @@ public class FlwDefinitionServiceImpl implements IFlwDefinitionService {
* @param file 文件 * @param file 文件
*/ */
@Override @Override
public boolean importXml(MultipartFile file, String category) { @Transactional(rollbackFor = Exception.class)
try { public boolean importJson(MultipartFile file, String category) {
FlowCombine combine = defService.readXml(file.getInputStream()); try (InputStream inputStream = file.getInputStream()) {
// 流程定义 byte[] fileBytes = inputStream.readAllBytes();
Definition definition = combine.getDefinition(); String fileContent = new String(fileBytes, StandardCharsets.UTF_8);
definition.setCategory(category); DefJson defJson = JsonUtils.parseObject(fileContent, DefJson.class);
defService.importFlow(combine); defJson.setCategory(category);
defService.importDef(defJson);
} catch (IOException e) {
log.error("读取文件流错误: {}", e.getMessage(), e);
throw new IllegalStateException("文件读取失败,请检查文件内容", e);
} catch (Exception e) { } catch (Exception e) {
log.error("导入流程定义错误: {}", e.getMessage(), e); log.error("导入流程定义错误: {}", e.getMessage(), e);
throw new RuntimeException(e); throw new IllegalStateException("导入流程定义失败", e);
} }
return true; return true;
} }
@ -166,24 +172,15 @@ public class FlwDefinitionServiceImpl implements IFlwDefinitionService {
*/ */
@Override @Override
public void exportDef(Long id, HttpServletResponse response) throws IOException { public void exportDef(Long id, HttpServletResponse response) throws IOException {
Document document = defService.exportXml(id); byte[] data = defService.exportJson(id).getBytes(StandardCharsets.UTF_8);
// 设置生成xml的格式 String filename = "workflow_export_" + DateUtils.dateTimeNow() + ".json";
OutputFormat of = OutputFormat.createPrettyPrint(); // 设置响应头和内容类型
// 设置编码格式
of.setEncoding("UTF-8");
of.setIndent(true);
of.setIndent(" ");
of.setNewlines(true);
// 创建一个xml文档编辑器
XMLWriter writer = new XMLWriter(response.getOutputStream(), of);
writer.setEscapeText(false);
response.reset(); response.reset();
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setContentType("application/x-msdownload"); response.setContentType("application/json");
response.setHeader("Content-Disposition", "attachment;"); response.setHeader("Content-Disposition", "attachment; filename=" + filename);
writer.write(document); response.addHeader("Content-Length", "" + data.length);
writer.close(); IoUtil.write(response.getOutputStream(), false, data);
} }
/** /**

View File

@ -19,13 +19,14 @@ import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.warm.flow.core.FlowFactory; import org.dromara.warm.flow.core.FlowEngine;
import org.dromara.warm.flow.core.constant.ExceptionCons; import org.dromara.warm.flow.core.constant.ExceptionCons;
import org.dromara.warm.flow.core.dto.FlowParams; import org.dromara.warm.flow.core.dto.FlowParams;
import org.dromara.warm.flow.core.entity.Definition; import org.dromara.warm.flow.core.entity.Definition;
import org.dromara.warm.flow.core.entity.Instance; import org.dromara.warm.flow.core.entity.Instance;
import org.dromara.warm.flow.core.entity.Task; import org.dromara.warm.flow.core.entity.Task;
import org.dromara.warm.flow.core.enums.NodeType; import org.dromara.warm.flow.core.enums.NodeType;
import org.dromara.warm.flow.core.service.ChartService;
import org.dromara.warm.flow.core.service.DefService; import org.dromara.warm.flow.core.service.DefService;
import org.dromara.warm.flow.core.service.InsService; import org.dromara.warm.flow.core.service.InsService;
import org.dromara.warm.flow.core.service.TaskService; import org.dromara.warm.flow.core.service.TaskService;
@ -51,7 +52,6 @@ import org.dromara.workflow.utils.WorkflowUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -68,6 +68,7 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
private final InsService insService; private final InsService insService;
private final DefService defService; private final DefService defService;
private final ChartService chartService;
private final TaskService taskService; private final TaskService taskService;
private final FlowHisTaskMapper flowHisTaskMapper; private final FlowHisTaskMapper flowHisTaskMapper;
private final FlowInstanceMapper flowInstanceMapper; private final FlowInstanceMapper flowInstanceMapper;
@ -248,7 +249,7 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
//撤销 //撤销
WorkflowUtils.backTask(message, instance.getId(), applyNodeCode, BusinessStatusEnum.CANCEL.getStatus(), BusinessStatusEnum.CANCEL.getStatus()); WorkflowUtils.backTask(message, instance.getId(), applyNodeCode, BusinessStatusEnum.CANCEL.getStatus(), BusinessStatusEnum.CANCEL.getStatus());
//判断或签节点是否有多个只保留一个 //判断或签节点是否有多个只保留一个
List<Task> currentTaskList = taskService.list(FlowFactory.newTask().setInstanceId(instance.getId())); List<Task> currentTaskList = taskService.list(FlowEngine.newTask().setInstanceId(instance.getId()));
if (CollUtil.isNotEmpty(currentTaskList)) { if (CollUtil.isNotEmpty(currentTaskList)) {
if (currentTaskList.size() > 1) { if (currentTaskList.size() > 1) {
currentTaskList.remove(0); currentTaskList.remove(0);
@ -284,14 +285,14 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
*/ */
@Override @Override
public Map<String, Object> flowImage(String businessId) { public Map<String, Object> flowImage(String businessId) {
Map<String, Object> map = new HashMap<>(16);
FlowInstance flowInstance = this.selectInstByBusinessId(businessId); FlowInstance flowInstance = this.selectInstByBusinessId(businessId);
if (flowInstance == null) { if (ObjectUtil.isNull(flowInstance)) {
throw new ServiceException(ExceptionCons.NOT_FOUNT_INSTANCE); throw new ServiceException(ExceptionCons.NOT_FOUNT_INSTANCE);
} }
Long instanceId = flowInstance.getId();
//运行中的任务 //运行中的任务
List<FlowHisTaskVo> list = new ArrayList<>(); List<FlowHisTaskVo> list = new ArrayList<>();
List<FlowTask> flowTaskList = flwTaskService.selectByInstId(flowInstance.getId()); List<FlowTask> flowTaskList = flwTaskService.selectByInstId(instanceId);
if (CollUtil.isNotEmpty(flowTaskList)) { if (CollUtil.isNotEmpty(flowTaskList)) {
List<FlowHisTaskVo> flowHisTaskVos = BeanUtil.copyToList(flowTaskList, FlowHisTaskVo.class); List<FlowHisTaskVo> flowHisTaskVos = BeanUtil.copyToList(flowTaskList, FlowHisTaskVo.class);
for (FlowHisTaskVo flowHisTaskVo : flowHisTaskVos) { for (FlowHisTaskVo flowHisTaskVo : flowHisTaskVos) {
@ -312,22 +313,15 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
} }
//历史任务 //历史任务
LambdaQueryWrapper<FlowHisTask> wrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<FlowHisTask> wrapper = Wrappers.lambdaQuery();
wrapper.eq(FlowHisTask::getInstanceId, flowInstance.getId()); wrapper.eq(FlowHisTask::getInstanceId, instanceId);
wrapper.eq(FlowHisTask::getNodeType, NodeType.BETWEEN.getKey()); wrapper.eq(FlowHisTask::getNodeType, NodeType.BETWEEN.getKey());
wrapper.orderByDesc(FlowHisTask::getCreateTime).orderByDesc(FlowHisTask::getUpdateTime); wrapper.orderByDesc(FlowHisTask::getCreateTime).orderByDesc(FlowHisTask::getUpdateTime);
List<FlowHisTask> flowHisTasks = flowHisTaskMapper.selectList(wrapper); List<FlowHisTask> flowHisTasks = flowHisTaskMapper.selectList(wrapper);
if (CollUtil.isNotEmpty(flowHisTasks)) { if (CollUtil.isNotEmpty(flowHisTasks)) {
list.addAll(BeanUtil.copyToList(flowHisTasks, FlowHisTaskVo.class)); list.addAll(BeanUtil.copyToList(flowHisTasks, FlowHisTaskVo.class));
} }
String flowChart = chartService.chartIns(instanceId);
map.put("list", list); return Map.of("list", list, "image", flowChart);
try {
String flowChart = defService.flowChart(flowInstance.getId());
map.put("image", flowChart);
} catch (IOException e) {
throw new RuntimeException(e);
}
return map;
} }
/** /**