add 新增 warmflow 源码级定制化开发

This commit is contained in:
疯狂的狮子Li 2026-09-11 17:06:33 +08:00
parent bd82af3727
commit 472d2d1a3a
20 changed files with 98 additions and 222 deletions

View File

@ -15,20 +15,18 @@
*/ */
package org.dromara.warm.flow; package org.dromara.warm.flow;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.warm.flow.config.WarmFlowProperties; import org.dromara.warm.flow.config.WarmFlowProperties;
import org.dromara.warm.flow.handler.DataFillHandler; import org.dromara.warm.flow.handler.DataFillHandler;
import org.dromara.warm.flow.handler.PermissionHandler; import org.dromara.warm.flow.handler.PermissionHandler;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.warm.flow.listener.GlobalListener; import org.dromara.warm.flow.listener.GlobalListener;
import org.dromara.warm.flow.service.*; import org.dromara.warm.flow.service.*;
import cn.hutool.core.util.ClassUtil;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.function.Supplier; import java.util.function.Supplier;
/** /**
* 流程引擎通过静态方法驱动流程流转 * 流程引擎通过静态方法驱动流程流转
*/ */
@ -129,24 +127,24 @@ public class FlowEngine {
* @return bean * @return bean
*/ */
private static <T> T initBean(Class<T> tClazz, String beanPath, Supplier<T> supplier) { private static <T> T initBean(Class<T> tClazz, String beanPath, Supplier<T> supplier) {
T hander = null; T handler = null;
try { try {
if (!StrUtil.isEmpty(beanPath)) { if (StrUtil.isNotBlank(beanPath)) {
Class<?> clazz = ClassUtil.loadClass(beanPath); Class<?> clazz = ClassUtil.loadClass(beanPath);
if (clazz != null && tClazz.isAssignableFrom(clazz)) { if (clazz != null && tClazz.isAssignableFrom(clazz)) {
Constructor<?> constructor = clazz.getConstructor(); Constructor<?> constructor = clazz.getConstructor();
hander = tClazz.cast(constructor.newInstance()); handler = tClazz.cast(constructor.newInstance());
} }
} }
} catch (Exception ignored) { } catch (Exception ignored) {
} }
if (hander == null) { if (handler == null) {
hander = SpringUtils.getBeanOrNull(tClazz); handler = SpringUtils.getBeanOrNull(tClazz);
} }
if (hander == null && supplier != null) { if (handler == null && supplier != null) {
hander = supplier.get(); handler = supplier.get();
} }
return hander; return handler;
} }
} }

View File

@ -18,9 +18,9 @@ package org.dromara.warm.flow.config;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import org.dromara.warm.flow.FlowEngine; import org.dromara.warm.flow.FlowEngine;
import org.dromara.warm.flow.enums.FrameworkType; import org.dromara.warm.flow.enums.FrameworkType;
import org.dromara.workflow.common.ConditionalOnEnable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -32,7 +32,7 @@ import org.springframework.stereotype.Component;
*/ */
@Component @Component
@EnableConfigurationProperties(WarmFlowProperties.class) @EnableConfigurationProperties(WarmFlowProperties.class)
@ConditionalOnProperty(value = "warm-flow.enabled", havingValue = "true", matchIfMissing = true) @ConditionalOnEnable
public class WarmFlowInitializer { public class WarmFlowInitializer {
private static final Logger log = LoggerFactory.getLogger(WarmFlowInitializer.class); private static final Logger log = LoggerFactory.getLogger(WarmFlowInitializer.class);

View File

@ -16,7 +16,7 @@
package org.dromara.warm.flow.dto; package org.dromara.warm.flow.dto;
import java.io.Serial; import java.io.Serial;
import org.dromara.warm.flow.json.JsonUtil; import org.dromara.common.json.utils.JsonUtils;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -250,7 +250,7 @@ public class FlowParams implements Serializable {
} }
public String getVariableStr() { public String getVariableStr() {
return JsonUtil.objToStr(variable); return JsonUtils.toJsonString(variable);
} }
public String getHandler() { public String getHandler() {

View File

@ -14,7 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package org.dromara.warm.flow.entity; package org.dromara.warm.flow.entity;
import org.dromara.warm.flow.json.JsonUtil; import org.dromara.common.json.utils.JsonUtils;
import tools.jackson.core.type.TypeReference;
import org.dromara.warm.flow.entity.RootEntity; import org.dromara.warm.flow.entity.RootEntity;
@ -24,7 +25,10 @@ import lombok.experimental.Accessors;
import org.dromara.warm.flow.entity.FlowHisTask; import org.dromara.warm.flow.entity.FlowHisTask;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
/** /**
* 历史任务记录 * 历史任务记录
*/ */
@ -165,7 +169,8 @@ public class FlowHisTask implements RootEntity {
/** /**
* 流程变量转 map * 流程变量转 map
*/ */
public java.util.Map<String, Object> getVariableMap() { public Map<String, Object> getVariableMap() {
return JsonUtil.strToMap(getVariable()); return Optional.ofNullable(JsonUtils.parseObject(getVariable(), new TypeReference<Map<String, Object>>() {
})).orElseGet(HashMap::new);
} }
} }

View File

@ -14,7 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package org.dromara.warm.flow.entity; package org.dromara.warm.flow.entity;
import org.dromara.warm.flow.json.JsonUtil; import org.dromara.common.json.utils.JsonUtils;
import tools.jackson.core.type.TypeReference;
import org.dromara.warm.flow.entity.RootEntity; import org.dromara.warm.flow.entity.RootEntity;
@ -24,6 +25,9 @@ import lombok.experimental.Accessors;
import org.dromara.warm.flow.entity.FlowInstance; import org.dromara.warm.flow.entity.FlowInstance;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/** /**
* 流程实例 * 流程实例
*/ */
@ -134,7 +138,8 @@ public class FlowInstance implements RootEntity {
/** /**
* 流程变量转 map * 流程变量转 map
*/ */
public java.util.Map<String, Object> getVariableMap() { public Map<String, Object> getVariableMap() {
return JsonUtil.strToMap(getVariable()); return Optional.ofNullable(JsonUtils.parseObject(getVariable(), new TypeReference<Map<String, Object>>() {
})).orElseGet(HashMap::new);
} }
} }

View File

@ -9,8 +9,6 @@ import org.springframework.expression.spel.support.DataBindingMethodResolver;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -22,21 +20,20 @@ import java.util.Set;
*/ */
public class SafeMethodResolver implements MethodResolver { public class SafeMethodResolver implements MethodResolver {
private static final Set<String> DANGEROUS_METHODS = new HashSet<>(Arrays.asList( private static final Set<String> DANGEROUS_METHODS = Set.of(
"getRuntime", "getRuntime",
"exec", "exec",
"forName", "forName",
"loadClass", "loadClass",
"getClassLoader", "getClassLoader",
"setAccessible", "setAccessible",
"newInstance", "newInstance",
"invoke", "invoke",
"getField", "getField",
"getDeclaredField", "getDeclaredField",
"getMethod", "getMethod",
"getDeclaredMethod" "getDeclaredMethod"
)); );
@Nullable @Nullable
@Override @Override

View File

@ -1,121 +0,0 @@
/*
* Copyright 2024-2025, Warm-Flow (290631660@qq.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.warm.flow.json;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import org.dromara.warm.flow.exception.FlowException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.DeserializationFeature;
import tools.jackson.databind.json.JsonMapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Jackson 3map和json字符串转换工具类
*
* @author warm
*/
public final class JsonUtil {
private static final Logger log = LoggerFactory.getLogger(JsonUtil.class);
private static final JsonMapper JSON_MAPPER = JsonMapper.builder()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.build();
private JsonUtil() {
}
/**
* 将字符串转为map
*
* @param jsonStr json字符串
* @return map
*/
public static Map<String, Object> strToMap(String jsonStr) {
if (StrUtil.isNotEmpty(jsonStr)) {
try {
return JSON_MAPPER.readValue(jsonStr,
JSON_MAPPER.getTypeFactory().constructMapType(Map.class, String.class, Object.class));
} catch (Exception e) {
log.error("json转换异常", e);
throw new FlowException("json转换异常");
}
}
return new HashMap<>();
}
/**
* 将字符串转为bean
*
* @param jsonStr json字符串
* @param clazz Class<T>
* @return T
*/
public static <T> T strToBean(String jsonStr, Class<T> clazz) {
if (StrUtil.isNotEmpty(jsonStr)) {
try {
return JSON_MAPPER.readValue(jsonStr, clazz);
} catch (Exception e) {
log.error("json转换异常", e);
throw new FlowException("json转换异常");
}
}
return null;
}
/**
* 将字符串转为集合
*
* @param jsonStr json字符串
* @return List<T>
*/
public static <T> List<T> strToList(String jsonStr) {
if (StrUtil.isNotEmpty(jsonStr)) {
try {
return JSON_MAPPER.readValue(jsonStr, new TypeReference<List<T>>() {
});
} catch (Exception e) {
log.error("json转换异常", e);
throw new FlowException("json转换异常");
}
}
return null;
}
/**
* 将对象转为字符串
*
* @param variable object
* @return json字符串
*/
public static String objToStr(Object variable) {
if (ObjectUtil.isNotNull(variable)) {
try {
return JSON_MAPPER.writeValueAsString(variable);
} catch (Exception e) {
log.error("Map转换异常", e);
throw new FlowException("Map转换异常");
}
}
return null;
}
}

View File

@ -80,7 +80,7 @@ public interface FlowUserMapper extends WarmMapper<FlowUser> {
queryWrapper.in(FlowUser::getProcessedBy, processedBys); queryWrapper.in(FlowUser::getProcessedBy, processedBys);
} }
} }
queryWrapper.in(ArrayUtil.isNotEmpty(types), FlowUser::getType, types); queryWrapper.in(ArrayUtil.isNotEmpty(types), FlowUser::getType, Arrays.asList(types));
return selectList(queryWrapper); return selectList(queryWrapper);
} }
} }

View File

@ -15,7 +15,7 @@
*/ */
package org.dromara.warm.flow.service; package org.dromara.warm.flow.service;
import org.dromara.warm.flow.json.JsonUtil; import org.dromara.common.json.utils.JsonUtils;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
@ -70,12 +70,12 @@ public class ChartService {
NodeType.isEnd(node.getNodeType()) ? ChartStatus.DONE.getKey() : ChartStatus.TO_DO.getKey() NodeType.isEnd(node.getNodeType()) ? ChartStatus.DONE.getKey() : ChartStatus.TO_DO.getKey()
)); ));
return JsonUtil.objToStr(defJson); return JsonUtils.toJsonString(defJson);
} }
public String skipMetadata(PathWayData pathWayData) { public String skipMetadata(PathWayData pathWayData) {
FlowInstance instance = FlowEngine.insService().getById(pathWayData.getInsId()); FlowInstance instance = FlowEngine.insService().getById(pathWayData.getInsId());
DefJson defJson = JsonUtil.strToBean(instance.getDefJson(), DefJson.class); DefJson defJson = JsonUtils.parseObject(instance.getDefJson(), DefJson.class);
List<NodeJson> nodeList = defJson.getNodeList(); List<NodeJson> nodeList = defJson.getNodeList();
List<SkipJson> skipList = defJson.getNodeList().stream().map(NodeJson::getSkipList) List<SkipJson> skipList = defJson.getNodeList().stream().map(NodeJson::getSkipList)
@ -125,7 +125,7 @@ public class ChartService {
}); });
return JsonUtil.objToStr(defJson); return JsonUtils.toJsonString(defJson);
} }
public List<String> getChartRgb(String modelValue) { public List<String> getChartRgb(String modelValue) {

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.dromara.warm.flow.service; package org.dromara.warm.flow.service;
import org.dromara.warm.flow.json.JsonUtil; import org.dromara.common.json.utils.JsonUtils;
import org.dromara.warm.flow.entity.*; import org.dromara.warm.flow.entity.*;
@ -79,7 +79,7 @@ public class DefService extends WarmServiceImpl<FlowDefinition> {
} }
public FlowDefinition importJson(String defJson) { public FlowDefinition importJson(String defJson) {
return importDef(JsonUtil.strToBean(defJson, DefJson.class)); return importDef(JsonUtils.parseObject(defJson, DefJson.class));
} }
public FlowDefinition importDef(DefJson defJson) { public FlowDefinition importDef(DefJson defJson) {
@ -147,7 +147,7 @@ public class DefService extends WarmServiceImpl<FlowDefinition> {
} }
public String exportJson(Long id) { public String exportJson(Long id) {
return JsonUtil.objToStr(queryDesign(id).setIsPublish(null)); return JsonUtils.toJsonString(queryDesign(id).setIsPublish(null));
} }
public FlowDefinition getAllDataDefinition(Long id) { public FlowDefinition getAllDataDefinition(Long id) {
@ -357,4 +357,4 @@ public class DefService extends WarmServiceImpl<FlowDefinition> {
public FlowDefinitionMapper getMapper() { public FlowDefinitionMapper getMapper() {
return SpringUtils.getBean(FlowDefinitionMapper.class); return SpringUtils.getBean(FlowDefinitionMapper.class);
} }
} }

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.dromara.warm.flow.service; package org.dromara.warm.flow.service;
import org.dromara.warm.flow.json.JsonUtil; import org.dromara.common.json.utils.JsonUtils;
import org.dromara.warm.flow.entity.*; import org.dromara.warm.flow.entity.*;
@ -187,7 +187,7 @@ public class InsService extends WarmServiceImpl<FlowInstance> {
.setNodeName(firstBetweenNode.getNodeName()) .setNodeName(firstBetweenNode.getNodeName())
.setFlowStatus(StrUtil.emptyToDefault(flowParams.getFlowStatus(), FlowStatus.TOBESUBMIT.getKey())) .setFlowStatus(StrUtil.emptyToDefault(flowParams.getFlowStatus(), FlowStatus.TOBESUBMIT.getKey()))
.setActivityStatus(ActivityStatus.ACTIVITY.getKey()) .setActivityStatus(ActivityStatus.ACTIVITY.getKey())
.setVariable(JsonUtil.objToStr(flowParams.getVariable())) .setVariable(JsonUtils.toJsonString(flowParams.getVariable()))
.setCreateTime(now) .setCreateTime(now)
.setUpdateTime(now) .setUpdateTime(now)
.setCreateBy(flowParams.getHandler()) .setCreateBy(flowParams.getHandler())
@ -236,7 +236,7 @@ public class InsService extends WarmServiceImpl<FlowInstance> {
for (String key : keys) { for (String key : keys) {
variableMap.remove(key); variableMap.remove(key);
} }
instance.setVariable(JsonUtil.objToStr(variableMap)); instance.setVariable(JsonUtils.toJsonString(variableMap));
FlowEngine.insService().updateById(instance); FlowEngine.insService().updateById(instance);
} }
} }
@ -245,4 +245,4 @@ public class InsService extends WarmServiceImpl<FlowInstance> {
public FlowInstanceMapper getMapper() { public FlowInstanceMapper getMapper() {
return SpringUtils.getBean(FlowInstanceMapper.class); return SpringUtils.getBean(FlowInstanceMapper.class);
} }
} }

View File

@ -14,7 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package org.dromara.warm.flow.service; package org.dromara.warm.flow.service;
import org.dromara.warm.flow.json.JsonUtil; import org.dromara.common.json.utils.JsonUtils;
import tools.jackson.core.type.TypeReference;
import org.dromara.warm.flow.entity.*; import org.dromara.warm.flow.entity.*;
@ -292,7 +293,8 @@ public class NodeService extends WarmServiceImpl<FlowNode> {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
String ext = node.getExt(); String ext = node.getExt();
if (StrUtil.isNotEmpty(ext)) { if (StrUtil.isNotEmpty(ext)) {
List<Map<String, Object>> extList = JsonUtil.strToList(ext); List<Map<String, Object>> extList = JsonUtils.parseObject(ext, new TypeReference<List<Map<String, Object>>>() {
});
if (CollUtil.isNotEmpty(extList)) { if (CollUtil.isNotEmpty(extList)) {
for (Map<String, Object> extMap : extList) { for (Map<String, Object> extMap : extList) {
String code = ObjectUtil.defaultIfNull(extMap.get("code"), "").toString(); String code = ObjectUtil.defaultIfNull(extMap.get("code"), "").toString();
@ -359,4 +361,4 @@ public class NodeService extends WarmServiceImpl<FlowNode> {
public FlowNodeMapper getMapper() { public FlowNodeMapper getMapper() {
return SpringUtils.getBean(FlowNodeMapper.class); return SpringUtils.getBean(FlowNodeMapper.class);
} }
} }

View File

@ -14,7 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package org.dromara.warm.flow.service; package org.dromara.warm.flow.service;
import org.dromara.warm.flow.json.JsonUtil; import org.dromara.common.json.utils.JsonUtils;
import tools.jackson.core.type.TypeReference;
import org.dromara.warm.flow.entity.*; import org.dromara.warm.flow.entity.*;
@ -559,9 +560,10 @@ public class TaskService extends WarmServiceImpl<FlowTask> {
public void mergeVariable(FlowInstance instance, Map<String, Object> variable) { public void mergeVariable(FlowInstance instance, Map<String, Object> variable) {
if (MapUtil.isNotEmpty(variable)) { if (MapUtil.isNotEmpty(variable)) {
String variableStr = instance.getVariable(); String variableStr = instance.getVariable();
Map<String, Object> deserialize = JsonUtil.strToMap(variableStr); Map<String, Object> deserialize = Optional.ofNullable(JsonUtils.parseObject(variableStr, new TypeReference<Map<String, Object>>() {
})).orElseGet(HashMap::new);
deserialize.putAll(variable); deserialize.putAll(variable);
instance.setVariable(JsonUtil.objToStr(deserialize)); instance.setVariable(JsonUtils.toJsonString(deserialize));
} }
} }
@ -814,7 +816,7 @@ public class TaskService extends WarmServiceImpl<FlowTask> {
return; return;
} }
DefJson defJson = JsonUtil.strToBean(instance.getDefJson(), DefJson.class); DefJson defJson = JsonUtils.parseObject(instance.getDefJson(), DefJson.class);
Map<String, NodeJson> nodeJsonMap = StreamUtils.toMap(defJson.getNodeList(), NodeJson::getNodeCode, node -> node); Map<String, NodeJson> nodeJsonMap = StreamUtils.toMap(defJson.getNodeList(), NodeJson::getNodeCode, node -> node);
// 途径节点中的并行/包容网关只剩一个前置待办任务时才能生成新的代办任务 // 途径节点中的并行/包容网关只剩一个前置待办任务时才能生成新的代办任务
List<FlowNode> parallelOrInclusiveList = StreamUtils.filter(pathWayData.getPathWayNodes(), List<FlowNode> parallelOrInclusiveList = StreamUtils.filter(pathWayData.getPathWayNodes(),

View File

@ -15,13 +15,9 @@
*/ */
package org.dromara.warm.flow.strategy; package org.dromara.warm.flow.strategy;
import cn.hutool.core.util.ObjectUtil;
import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StreamUtils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* 办理人表达式策略接口 * 办理人表达式策略接口
@ -48,15 +44,15 @@ public interface HandlerStrategy extends ExpressionStrategy<List<String>> {
} }
default List<String> afterEval(Object o) { default List<String> afterEval(Object o) {
if (ObjectUtil.isNull(o)) { if (o == null) {
return null; return null;
} }
if (o instanceof List) { if (o instanceof List<?> list) {
return StreamUtils.toList((List<?>) o, Object::toString); return StreamUtils.toList(list, Object::toString);
} }
if (o instanceof Object[]) { if (o instanceof Object[] array) {
return Arrays.stream((Object[]) o).map(Object::toString).toList(); return Arrays.stream(array).map(Object::toString).toList();
} }
return Collections.singletonList(o.toString()); return List.of(o.toString());
} }
} }

View File

@ -17,6 +17,7 @@ package org.dromara.warm.flow.ui.config;
import org.dromara.warm.flow.ui.controller.WarmFlowController; import org.dromara.warm.flow.ui.controller.WarmFlowController;
import org.dromara.warm.flow.ui.controller.WarmFlowUiController; import org.dromara.warm.flow.ui.controller.WarmFlowUiController;
import org.dromara.workflow.common.ConditionalOnEnable;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
@ -29,9 +30,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* @author ruoyi * @author ruoyi
*/ */
@Configuration @Configuration
@ConditionalOnEnable
@ConditionalOnProperty(value = "warm-flow.ui", havingValue = "true", matchIfMissing = true) @ConditionalOnProperty(value = "warm-flow.ui", havingValue = "true", matchIfMissing = true)
@Import({WarmFlowUiController.class @Import({WarmFlowUiController.class, WarmFlowController.class})
, WarmFlowController.class})
public class WarmFlowUiConfig implements WebMvcConfigurer { public class WarmFlowUiConfig implements WebMvcConfigurer {
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {

View File

@ -15,11 +15,10 @@
*/ */
package org.dromara.warm.flow.ui.service; package org.dromara.warm.flow.ui.service;
import org.dromara.warm.flow.json.JsonUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.dromara.common.json.utils.JsonUtils;
import org.dromara.warm.flow.FlowEngine; import org.dromara.warm.flow.FlowEngine;
import org.dromara.warm.flow.config.WarmFlowProperties; import org.dromara.warm.flow.config.WarmFlowProperties;
import org.dromara.warm.flow.dto.*; import org.dromara.warm.flow.dto.*;
@ -124,7 +123,7 @@ public class WarmFlowService {
try { try {
FlowInstance instance = FlowEngine.insService().getById(id); FlowInstance instance = FlowEngine.insService().getById(id);
String defJsonStr = instance.getDefJson(); String defJsonStr = instance.getDefJson();
DefJson defJson = JsonUtil.strToBean(defJsonStr, DefJson.class); DefJson defJson = JsonUtils.parseObject(defJsonStr, DefJson.class);
defJson.setInstance(instance); defJson.setInstance(instance);
// 获取流程图三原色 // 获取流程图三原色

View File

@ -72,30 +72,23 @@ public class AssertUtil {
public static void isNotEmpty(Object obj, String errorMsg) { public static void isNotEmpty(Object obj, String errorMsg) {
if (obj != null) { if (obj != null) {
if (obj instanceof String) { switch (obj) {
AssertUtil.isTrue(StrUtil.isNotEmpty((String) obj), errorMsg); case String str -> AssertUtil.isTrue(StrUtil.isNotEmpty(str), errorMsg);
} else if (obj instanceof Collection) { case Collection<?> collection -> AssertUtil.isTrue(CollUtil.isNotEmpty(collection), errorMsg);
AssertUtil.isTrue(CollUtil.isNotEmpty((Collection<?>) obj), errorMsg); case Map<?, ?> map -> AssertUtil.isTrue(MapUtil.isNotEmpty(map), errorMsg);
} else if (obj instanceof Map) { default -> throw new FlowException("Unsupported type: " + obj.getClass().getName());
AssertUtil.isTrue(MapUtil.isNotEmpty((Map<?, ?>) obj), errorMsg);
} else {
throw new FlowException("Unsupported type: " + obj.getClass().getName());
} }
} }
} }
public static void isEmpty(Object obj, String errorMsg) { public static void isEmpty(Object obj, String errorMsg) {
if (obj == null) { switch (obj) {
throw new FlowException(errorMsg); case null -> throw new FlowException(errorMsg);
} else if (obj instanceof String) { case String str -> AssertUtil.isTrue(StrUtil.isEmpty(str), errorMsg);
AssertUtil.isTrue(StrUtil.isEmpty((String) obj), errorMsg); case Collection<?> collection -> AssertUtil.isTrue(CollUtil.isEmpty(collection), errorMsg);
} else if (obj instanceof Collection) { case Map<?, ?> map -> AssertUtil.isTrue(MapUtil.isEmpty(map), errorMsg);
AssertUtil.isTrue(CollUtil.isEmpty((Collection<?>) obj), errorMsg); default -> throw new FlowException("Unsupported type: " + obj.getClass().getName());
} else if (obj instanceof Map) {
AssertUtil.isTrue(MapUtil.isEmpty((Map<?, ?>) obj), errorMsg);
} else {
throw new FlowException("Unsupported type: " + obj.getClass().getName());
} }
} }

View File

@ -96,7 +96,7 @@ public class ExpressionUtil {
.map(s -> evalVariable(s, variable)).filter(Objects::nonNull) .map(s -> evalVariable(s, variable)).filter(Objects::nonNull)
.flatMap(List::stream) .flatMap(List::stream)
.distinct() .distinct()
.toList(); .collect(Collectors.toCollection(ArrayList::new));
// 转换办理人比如设计器中预设了能办理的人如果其中包含角色或者部门id等可以通过此接口进行转换成用户id // 转换办理人比如设计器中预设了能办理的人如果其中包含角色或者部门id等可以通过此接口进行转换成用户id
PermissionHandler permissionHandler = FlowEngine.permissionHandler(); PermissionHandler permissionHandler = FlowEngine.permissionHandler();
@ -125,7 +125,7 @@ public class ExpressionUtil {
if (CollUtil.isNotEmpty(value)) { if (CollUtil.isNotEmpty(value)) {
return value; return value;
} }
return Collections.singletonList(expression); return List.of(expression);
} }
/** /**
@ -188,7 +188,7 @@ public class ExpressionUtil {
return permissions; return permissions;
} }
if (nextHandlerAppend) { if (nextHandlerAppend) {
permissions.addAll(new ArrayList<>(Arrays.asList(nextHandler))); permissions.addAll(Arrays.asList(nextHandler));
} else { } else {
permissions = new ArrayList<>(Arrays.asList(nextHandler)); permissions = new ArrayList<>(Arrays.asList(nextHandler));
} }

View File

@ -16,7 +16,6 @@
package org.dromara.warm.flow.utils; package org.dromara.warm.flow.utils;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -36,7 +35,7 @@ public class MapUtil {
* @return true为空 false非空 * @return true为空 false非空
*/ */
public static boolean isEmpty(Map<?, ?> map) { public static boolean isEmpty(Map<?, ?> map) {
return ObjectUtil.isNull(map) || map.isEmpty(); return cn.hutool.core.map.MapUtil.isEmpty(map);
} }
/** /**
@ -46,7 +45,7 @@ public class MapUtil {
* @return true非空 false * @return true非空 false
*/ */
public static boolean isNotEmpty(Map<?, ?> map) { public static boolean isNotEmpty(Map<?, ?> map) {
return !isEmpty(map); return cn.hutool.core.map.MapUtil.isNotEmpty(map);
} }
/** /**

View File

@ -1,6 +1,6 @@
package org.dromara.workflow.service.impl; package org.dromara.workflow.service.impl;
import org.dromara.warm.flow.json.JsonUtil; import org.dromara.common.json.utils.JsonUtils;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
@ -400,7 +400,7 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
return false; return false;
} }
variableMap.put(bo.key(), bo.value()); variableMap.put(bo.key(), bo.value());
flowInstance.setVariable(JsonUtil.objToStr(variableMap)); flowInstance.setVariable(JsonUtils.toJsonString(variableMap));
return flowInstanceMapper.updateById(flowInstance) > 0; return flowInstanceMapper.updateById(flowInstance) > 0;
} }