mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-03-12 01:30:08 +08:00
update 优化 代码增加空判断与其他性能优化
This commit is contained in:
@@ -48,7 +48,8 @@ public class StartProcessDTO implements Serializable {
|
||||
|
||||
public Map<String, Object> getVariables() {
|
||||
if (variables == null) {
|
||||
return new HashMap<>(16);
|
||||
variables = new HashMap<>(16);
|
||||
return variables;
|
||||
}
|
||||
variables.entrySet().removeIf(entry -> Objects.isNull(entry.getValue()));
|
||||
return variables;
|
||||
|
||||
@@ -6,10 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.executor.parameter.ParameterHandler;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.plugin.Intercepts;
|
||||
import org.apache.ibatis.plugin.Invocation;
|
||||
import org.apache.ibatis.plugin.Signature;
|
||||
import org.apache.ibatis.plugin.*;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.encrypt.annotation.EncryptField;
|
||||
import org.dromara.common.encrypt.core.EncryptContext;
|
||||
@@ -42,19 +39,19 @@ public class MybatisEncryptInterceptor implements Interceptor {
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
return invocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
Object target = invocation.getTarget();
|
||||
if (target instanceof ParameterHandler parameterHandler) {
|
||||
// 进行加密操作
|
||||
Object parameterObject = parameterHandler.getParameterObject();
|
||||
if (ObjectUtil.isNotNull(parameterObject) && !(parameterObject instanceof String)) {
|
||||
this.encryptHandler(parameterObject);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
return Plugin.wrap(target, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -523,6 +523,9 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
* @param table 业务表信息
|
||||
*/
|
||||
public void setPkColumn(GenTable table) {
|
||||
if (CollUtil.isEmpty(table.getColumns())) {
|
||||
throw new ServiceException("表【" + table.getTableName() + "】字段为空,请检查表结构");
|
||||
}
|
||||
for (GenTableColumn column : table.getColumns()) {
|
||||
if (column.isPk()) {
|
||||
table.setPkColumn(column);
|
||||
|
||||
@@ -229,6 +229,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
@Override
|
||||
public String getDictLabel(String dictType, String dictValue, String separator) {
|
||||
List<SysDictDataVo> datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
|
||||
if (CollUtil.isEmpty(datas)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel);
|
||||
if (StringUtils.containsAny(dictValue, separator)) {
|
||||
return Arrays.stream(dictValue.split(separator))
|
||||
@@ -250,6 +253,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
@Override
|
||||
public String getDictValue(String dictType, String dictLabel, String separator) {
|
||||
List<SysDictDataVo> datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
|
||||
if (CollUtil.isEmpty(datas)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictLabel, SysDictDataVo::getDictValue);
|
||||
if (StringUtils.containsAny(dictLabel, separator)) {
|
||||
return Arrays.stream(dictLabel.split(separator))
|
||||
@@ -269,6 +275,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
@Override
|
||||
public Map<String, String> getAllDictByDictType(String dictType) {
|
||||
List<SysDictDataVo> list = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
// 保证顺序
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
for (SysDictDataVo vo : list) {
|
||||
@@ -286,6 +295,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
@Override
|
||||
public DictTypeDTO getDictType(String dictType) {
|
||||
SysDictTypeVo vo = SpringUtils.getAopProxy(this).selectDictTypeByType(dictType);
|
||||
if (ObjectUtil.isNull(vo)) {
|
||||
return null;
|
||||
}
|
||||
return BeanUtil.toBean(vo, DictTypeDTO.class);
|
||||
}
|
||||
|
||||
@@ -298,6 +310,9 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
|
||||
@Override
|
||||
public List<DictDataDTO> getDictData(String dictType) {
|
||||
List<SysDictDataVo> list = SpringUtils.getAopProxy(this).selectDictDataByType(dictType);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return BeanUtil.copyToList(list, DictDataDTO.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,8 @@ public class BackProcessBo implements Serializable {
|
||||
|
||||
public Map<String, Object> getVariables() {
|
||||
if (variables == null) {
|
||||
return new HashMap<>(16);
|
||||
variables = new HashMap<>(16);
|
||||
return variables;
|
||||
}
|
||||
variables.entrySet().removeIf(entry -> Objects.isNull(entry.getValue()));
|
||||
return variables;
|
||||
|
||||
@@ -30,7 +30,8 @@ public class FlowNextNodeBo implements Serializable {
|
||||
|
||||
public Map<String, Object> getVariables() {
|
||||
if (variables == null) {
|
||||
return new HashMap<>(16);
|
||||
variables = new HashMap<>(16);
|
||||
return variables;
|
||||
}
|
||||
variables.entrySet().removeIf(entry -> Objects.isNull(entry.getValue()));
|
||||
return variables;
|
||||
|
||||
@@ -53,7 +53,8 @@ public class StartProcessBo implements Serializable {
|
||||
|
||||
public Map<String, Object> getVariables() {
|
||||
if (variables == null) {
|
||||
return new HashMap<>(16);
|
||||
variables = new HashMap<>(16);
|
||||
return variables;
|
||||
}
|
||||
variables.entrySet().removeIf(entry -> Objects.isNull(entry.getValue()));
|
||||
return variables;
|
||||
|
||||
@@ -80,11 +80,13 @@ public class WorkflowGlobalListener implements GlobalListener {
|
||||
NodeExtVo nodeExt = nodeExtService.parseNodeExt(ext, variable);
|
||||
Set<String> copyList = nodeExt.getCopySettings();
|
||||
if (CollUtil.isNotEmpty(copyList)) {
|
||||
List<Long> userIds = StreamUtils.toList(copyList, Convert::toLong);
|
||||
Map<Long, String> nickNameMap = userService.selectUserNicksByIds(userIds);
|
||||
List<FlowCopyBo> list = StreamUtils.toList(copyList, x -> {
|
||||
FlowCopyBo bo = new FlowCopyBo();
|
||||
Long id = Convert.toLong(x);
|
||||
bo.setUserId(id);
|
||||
bo.setNickName(userService.selectNicknameById(id));
|
||||
bo.setNickName(nickNameMap.getOrDefault(id, StringUtils.EMPTY));
|
||||
return bo;
|
||||
});
|
||||
variable.put(FlowConstant.FLOW_COPY_LIST, list);
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.dto.UserDTO;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.SpringUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
@@ -126,6 +127,9 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
|
||||
@Override
|
||||
public String applyNodeCode(Long definitionId) {
|
||||
List<Node> firstBetweenNode = FlowEngine.nodeService().getFirstBetweenNode(definitionId, new HashMap<>());
|
||||
if (CollUtil.isEmpty(firstBetweenNode)) {
|
||||
throw new ServiceException("流程定义缺少申请人节点,请检查流程定义配置");
|
||||
}
|
||||
return firstBetweenNode.get(0).getNodeCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,8 +111,14 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
||||
@Override
|
||||
public FlowInstanceVo queryByBusinessId(Long businessId) {
|
||||
FlowInstance instance = this.selectInstByBusinessId(Convert.toStr(businessId));
|
||||
if (ObjectUtil.isNull(instance)) {
|
||||
throw new ServiceException(ExceptionCons.NOT_FOUNT_INSTANCE);
|
||||
}
|
||||
FlowInstanceVo instanceVo = BeanUtil.toBean(instance, FlowInstanceVo.class);
|
||||
Definition definition = defService.getById(instanceVo.getDefinitionId());
|
||||
if (ObjectUtil.isNull(definition)) {
|
||||
throw new ServiceException(ExceptionCons.NOT_FOUNT_DEF);
|
||||
}
|
||||
instanceVo.setFlowName(definition.getFlowName());
|
||||
instanceVo.setFlowCode(definition.getFlowCode());
|
||||
instanceVo.setVersion(definition.getVersion());
|
||||
@@ -383,6 +389,9 @@ public class FlwInstanceServiceImpl implements IFlwInstanceService {
|
||||
@Override
|
||||
public Map<String, Object> instanceVariable(Long instanceId) {
|
||||
FlowInstance flowInstance = flowInstanceMapper.selectById(instanceId);
|
||||
if (ObjectUtil.isNull(flowInstance)) {
|
||||
throw new ServiceException(ExceptionCons.NOT_FOUNT_INSTANCE);
|
||||
}
|
||||
Map<String, Object> variableMap = Optional.ofNullable(flowInstance.getVariableMap()).orElse(Collections.emptyMap());
|
||||
List<Map<String, Object>> variableList = variableMap.entrySet().stream()
|
||||
.map(entry -> Map.of("key", entry.getKey(), "value", entry.getValue()))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.dromara.workflow.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -9,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.domain.dto.TaskAssigneeDTO;
|
||||
import org.dromara.common.core.domain.model.TaskAssigneeBody;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
@@ -125,7 +127,14 @@ public class FlwSpelServiceImpl implements IFlwSpelService {
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(FlowSpel entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
if (StringUtils.isNotBlank(entity.getViewSpel())) {
|
||||
boolean exists = baseMapper.exists(new LambdaQueryWrapper<FlowSpel>()
|
||||
.eq(FlowSpel::getViewSpel, entity.getViewSpel())
|
||||
.ne(ObjectUtil.isNotNull(entity.getId()), FlowSpel::getId, entity.getId()));
|
||||
if (exists) {
|
||||
throw new ServiceException("SpEL表达式已存在,请勿重复添加");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +146,7 @@ public class FlwSpelServiceImpl implements IFlwSpelService {
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if(isValid){
|
||||
if (isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
|
||||
@@ -44,7 +44,6 @@ import org.dromara.warm.flow.orm.mapper.FlowInstanceMapper;
|
||||
import org.dromara.warm.flow.orm.mapper.FlowNodeMapper;
|
||||
import org.dromara.warm.flow.orm.mapper.FlowTaskMapper;
|
||||
import org.dromara.workflow.common.ConditionalOnEnable;
|
||||
import org.dromara.workflow.common.constant.FlowConstant;
|
||||
import org.dromara.workflow.common.enums.TaskAssigneeType;
|
||||
import org.dromara.workflow.common.enums.TaskOperationEnum;
|
||||
import org.dromara.workflow.common.enums.TaskStatusEnum;
|
||||
@@ -128,6 +127,9 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
// 已存在流程
|
||||
BusinessStatusEnum.checkStartStatus(flowInstance.getFlowStatus());
|
||||
List<Task> taskList = taskService.list(new FlowTask().setInstanceId(flowInstance.getId()));
|
||||
if (CollUtil.isEmpty(taskList)) {
|
||||
throw new ServiceException("流程实例缺少任务,请检查流程定义配置");
|
||||
}
|
||||
taskService.mergeVariable(flowInstance, variables);
|
||||
insService.updateById(flowInstance);
|
||||
StartProcessReturnDTO dto = new StartProcessReturnDTO();
|
||||
@@ -157,6 +159,9 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
this.buildFlowInstanceBizExt(instance, bizExt);
|
||||
// 申请人执行流程
|
||||
List<Task> taskList = taskService.list(new FlowTask().setInstanceId(instance.getId()));
|
||||
if (CollUtil.isEmpty(taskList)) {
|
||||
throw new ServiceException("流程启动失败,未生成任务");
|
||||
}
|
||||
if (taskList.size() > 1) {
|
||||
throw new ServiceException("请检查流程第一个环节是否为申请人!");
|
||||
}
|
||||
@@ -220,6 +225,9 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
throw new ServiceException("流程任务不存在或任务已审批!");
|
||||
}
|
||||
Instance ins = insService.getById(flowTask.getInstanceId());
|
||||
if (ObjectUtil.isNull(ins)) {
|
||||
throw new ServiceException("流程实例不存在");
|
||||
}
|
||||
// 检查流程状态是否为草稿、已撤销或已退回状态,若是则执行流程提交监听
|
||||
if (BusinessStatusEnum.isDraftOrCancelOrBack(ins.getFlowStatus())) {
|
||||
variables.put(SUBMIT, true);
|
||||
@@ -483,6 +491,9 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
throw new ServiceException("任务不存在!");
|
||||
}
|
||||
Instance inst = insService.getById(task.getInstanceId());
|
||||
if (ObjectUtil.isNull(inst)) {
|
||||
throw new ServiceException("流程实例不存在");
|
||||
}
|
||||
BusinessStatusEnum.checkBackStatus(inst.getFlowStatus());
|
||||
Long definitionId = task.getDefinitionId();
|
||||
String applyNodeCode = flwCommonService.applyNodeCode(definitionId);
|
||||
@@ -514,6 +525,9 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
@Override
|
||||
public List<Node> getBackTaskNode(Long taskId, String nowNodeCode) {
|
||||
FlowTask task = flowTaskMapper.selectById(taskId);
|
||||
if (ObjectUtil.isNull(task)) {
|
||||
throw new ServiceException("任务不存在!");
|
||||
}
|
||||
List<Node> nodeCodes = nodeService.getByNodeCodes(Collections.singletonList(nowNodeCode), task.getDefinitionId());
|
||||
if (!CollUtil.isNotEmpty(nodeCodes)) {
|
||||
return nodeCodes;
|
||||
@@ -598,7 +612,13 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
}
|
||||
FlowTaskVo flowTaskVo = BeanUtil.toBean(task, FlowTaskVo.class);
|
||||
Instance instance = insService.getById(task.getInstanceId());
|
||||
if (ObjectUtil.isNull(instance)) {
|
||||
throw new ServiceException("流程实例不存在");
|
||||
}
|
||||
Definition definition = defService.getById(task.getDefinitionId());
|
||||
if (ObjectUtil.isNull(definition)) {
|
||||
throw new ServiceException("流程定义不存在");
|
||||
}
|
||||
flowTaskVo.setFlowStatus(instance.getFlowStatus());
|
||||
flowTaskVo.setVersion(definition.getVersion());
|
||||
flowTaskVo.setFlowCode(definition.getFlowCode());
|
||||
@@ -641,11 +661,23 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
Long taskId = bo.getTaskId();
|
||||
Map<String, Object> variables = bo.getVariables();
|
||||
Task task = taskService.getById(taskId);
|
||||
if (ObjectUtil.isNull(task)) {
|
||||
throw new ServiceException("任务不存在!");
|
||||
}
|
||||
Instance instance = insService.getById(task.getInstanceId());
|
||||
if (ObjectUtil.isNull(instance)) {
|
||||
throw new ServiceException("流程实例不存在");
|
||||
}
|
||||
Definition definition = defService.getById(task.getDefinitionId());
|
||||
if (ObjectUtil.isNull(definition)) {
|
||||
throw new ServiceException("流程定义不存在");
|
||||
}
|
||||
Map<String, Object> mergeVariable = MapUtil.mergeAll(instance.getVariableMap(), variables);
|
||||
// 获取下一节点列表
|
||||
List<Node> nextNodeList = nodeService.getNextNodeList(task.getDefinitionId(), task.getNodeCode(), null, SkipType.PASS.getKey(), mergeVariable);
|
||||
if (CollUtil.isEmpty(nextNodeList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<FlowNode> nextFlowNodes = BeanUtil.copyToList(nextNodeList, FlowNode.class);
|
||||
// 只获取中间节点
|
||||
nextFlowNodes = StreamUtils.filter(nextFlowNodes, node -> NodeType.BETWEEN.getKey().equals(node.getNodeType()));
|
||||
@@ -749,7 +781,13 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
||||
|
||||
Long taskId = bo.getTaskId();
|
||||
Task task = taskService.getById(taskId);
|
||||
if (ObjectUtil.isNull(task)) {
|
||||
throw new ServiceException("任务不存在!");
|
||||
}
|
||||
FlowNode flowNode = getByNodeCode(task.getNodeCode(), task.getDefinitionId());
|
||||
if (ObjectUtil.isNull(flowNode)) {
|
||||
throw new ServiceException("流程节点不存在");
|
||||
}
|
||||
if (op == TaskOperationEnum.ADD_SIGNATURE || op == TaskOperationEnum.REDUCTION_SIGNATURE) {
|
||||
if (CooperateType.isOrSign(flowNode.getNodeRatio())) {
|
||||
throw new ServiceException(task.getNodeName() + "不是会签或票签节点!");
|
||||
|
||||
Reference in New Issue
Block a user