mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
update 调整流程定义配置逻辑
This commit is contained in:
@ -53,7 +53,7 @@ public class ActTaskController extends BaseController {
|
||||
@Log(title = "任务管理", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/startWorkFlow")
|
||||
public R<Map<String, Object>> startWorkFlow(@RequestBody StartProcessBo startProcessBo) {
|
||||
public R<Map<String, Object>> startWorkFlow(@Validated(AddGroup.class) @RequestBody StartProcessBo startProcessBo) {
|
||||
Map<String, Object> map = actTaskService.startWorkFlow(startProcessBo);
|
||||
return R.ok("提交成功", map);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class WfDefinitionConfigController extends BaseController {
|
||||
*/
|
||||
@GetMapping("/getByDefId/{definitionId}")
|
||||
public R<WfDefinitionConfigVo> getByDefId(@NotBlank(message = "流程定义ID不能为空")
|
||||
@PathVariable String definitionId) {
|
||||
@PathVariable String definitionId) {
|
||||
return R.ok(wfDefinitionConfigService.getByDefId(definitionId));
|
||||
}
|
||||
|
||||
@ -63,4 +63,17 @@ public class WfDefinitionConfigController extends BaseController {
|
||||
@PathVariable Long[] ids) {
|
||||
return toAjax(wfDefinitionConfigService.deleteByIds(List.of(ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流程定义配置排除当前查询的流程定义
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param definitionId 流程定义id
|
||||
*/
|
||||
@GetMapping("/getByTableNameNotDefId/{tableName}/{definitionId}")
|
||||
public R<List<WfDefinitionConfigVo>> getByTableNameNotDefId(@NotBlank(message = "表名不能为空") @PathVariable String tableName,
|
||||
@NotBlank(message = "流程定义ID不能为空") @PathVariable String definitionId) {
|
||||
return R.ok(wfDefinitionConfigService.getByTableNameNotDefId(tableName, definitionId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ public class WfDefinitionConfig extends BaseEntity {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 表单ID
|
||||
* 表名
|
||||
*/
|
||||
private Long formId;
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 流程定义ID
|
||||
@ -42,6 +42,11 @@ public class WfDefinitionConfig extends BaseEntity {
|
||||
*/
|
||||
private String processKey;
|
||||
|
||||
/**
|
||||
* 流程版本
|
||||
*/
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
@ -1,7 +1,9 @@
|
||||
package org.dromara.workflow.domain.bo;
|
||||
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import org.dromara.common.core.validate.AddGroup;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@ -23,12 +25,14 @@ public class StartProcessBo implements Serializable {
|
||||
/**
|
||||
* 业务唯一值id
|
||||
*/
|
||||
@NotBlank(message = "业务ID不能为空", groups = {AddGroup.class})
|
||||
private String businessKey;
|
||||
|
||||
/**
|
||||
* 流程执行key
|
||||
* 表名
|
||||
*/
|
||||
private String processKey;
|
||||
@NotBlank(message = "表名不能为空", groups = {AddGroup.class})
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 流程变量,前端会提交一个元素{'entity': {业务详情数据对象}}
|
||||
|
@ -27,10 +27,10 @@ public class WfDefinitionConfigBo extends BaseEntity {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 表单ID
|
||||
* 表名
|
||||
*/
|
||||
@NotNull(message = "表单ID不能为空", groups = {AddGroup.class})
|
||||
private Long formId;
|
||||
@NotBlank(message = "表名不能为空", groups = {AddGroup.class})
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 流程定义ID
|
||||
@ -44,6 +44,12 @@ public class WfDefinitionConfigBo extends BaseEntity {
|
||||
@NotBlank(message = "流程KEY不能为空", groups = {AddGroup.class})
|
||||
private String processKey;
|
||||
|
||||
/**
|
||||
* 流程版本
|
||||
*/
|
||||
@NotNull(message = "流程版本不能为空", groups = {AddGroup.class})
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
@ -31,10 +31,10 @@ public class WfDefinitionConfigVo implements Serializable {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 表单ID
|
||||
* 表名
|
||||
*/
|
||||
@ExcelProperty(value = "表单ID")
|
||||
private Long formId;
|
||||
@ExcelProperty(value = "表名")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 流程定义ID
|
||||
@ -48,6 +48,13 @@ public class WfDefinitionConfigVo implements Serializable {
|
||||
@ExcelProperty(value = "流程KEY")
|
||||
private String processKey;
|
||||
|
||||
|
||||
/**
|
||||
* 流程版本
|
||||
*/
|
||||
@ExcelProperty(value = "流程版本")
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
@ -22,6 +22,32 @@ public interface IWfDefinitionConfigService {
|
||||
*/
|
||||
WfDefinitionConfigVo getByDefId(String definitionId);
|
||||
|
||||
/**
|
||||
* 查询流程定义配置
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @return 结果
|
||||
*/
|
||||
WfDefinitionConfigVo getByTableNameLastVersion(String tableName);
|
||||
|
||||
/**
|
||||
* 查询流程定义配置
|
||||
*
|
||||
* @param definitionId 流程定义id
|
||||
* @param tableName 表名
|
||||
* @return 结果
|
||||
*/
|
||||
WfDefinitionConfigVo getByDefIdAndTableName(String definitionId, String tableName);
|
||||
|
||||
/**
|
||||
* 查询流程定义配置排除当前查询的流程定义
|
||||
*
|
||||
* @param definitionId 流程定义id
|
||||
* @param tableName 表名
|
||||
* @return 结果
|
||||
*/
|
||||
List<WfDefinitionConfigVo> getByTableNameNotDefId(String tableName, String definitionId);
|
||||
|
||||
/**
|
||||
* 查询流程定义配置列表
|
||||
*
|
||||
|
@ -30,6 +30,7 @@ import org.dromara.workflow.flowable.strategy.FlowTaskEventHandler;
|
||||
import org.dromara.workflow.mapper.ActHiTaskinstMapper;
|
||||
import org.dromara.workflow.mapper.ActTaskMapper;
|
||||
import org.dromara.workflow.service.IActTaskService;
|
||||
import org.dromara.workflow.service.IWfDefinitionConfigService;
|
||||
import org.dromara.workflow.service.IWfNodeConfigService;
|
||||
import org.dromara.workflow.service.IWfTaskBackNodeService;
|
||||
import org.dromara.workflow.utils.ModelUtils;
|
||||
@ -78,6 +79,7 @@ public class ActTaskServiceImpl implements IActTaskService {
|
||||
private final IWfTaskBackNodeService iWfTaskBackNodeService;
|
||||
private final ActHiTaskinstMapper actHiTaskinstMapper;
|
||||
private final IWfNodeConfigService iWfNodeConfigService;
|
||||
private final IWfDefinitionConfigService iWfDefinitionConfigService;
|
||||
|
||||
/**
|
||||
* 启动任务
|
||||
@ -106,6 +108,10 @@ public class ActTaskServiceImpl implements IActTaskService {
|
||||
map.put("taskId", taskResult.get(0).getId());
|
||||
return map;
|
||||
}
|
||||
WfDefinitionConfigVo wfDefinitionConfigVo = iWfDefinitionConfigService.getByTableNameLastVersion(startProcessBo.getTableName());
|
||||
if (wfDefinitionConfigVo == null) {
|
||||
throw new ServiceException("请到流程定义绑定业务表名与流程KEY!");
|
||||
}
|
||||
// 设置启动人
|
||||
identityService.setAuthenticatedUserId(String.valueOf(LoginHelper.getUserId()));
|
||||
Authentication.setAuthenticatedUserId(String.valueOf(LoginHelper.getUserId()));
|
||||
@ -118,12 +124,12 @@ public class ActTaskServiceImpl implements IActTaskService {
|
||||
ProcessInstance pi;
|
||||
try {
|
||||
if (TenantHelper.isEnable()) {
|
||||
pi = runtimeService.startProcessInstanceByKeyAndTenantId(startProcessBo.getProcessKey(), startProcessBo.getBusinessKey(), variables, TenantHelper.getTenantId());
|
||||
pi = runtimeService.startProcessInstanceByKeyAndTenantId(wfDefinitionConfigVo.getProcessKey(), startProcessBo.getBusinessKey(), variables, TenantHelper.getTenantId());
|
||||
} else {
|
||||
pi = runtimeService.startProcessInstanceByKey(startProcessBo.getProcessKey(), startProcessBo.getBusinessKey(), variables);
|
||||
pi = runtimeService.startProcessInstanceByKey(wfDefinitionConfigVo.getProcessKey(), startProcessBo.getBusinessKey(), variables);
|
||||
}
|
||||
} catch (FlowableObjectNotFoundException e) {
|
||||
throw new ServiceException("找不到当前【" + startProcessBo.getProcessKey() + "】流程定义!");
|
||||
throw new ServiceException("找不到当前【" + wfDefinitionConfigVo.getProcessKey() + "】流程定义!");
|
||||
}
|
||||
// 将流程定义名称 作为 流程实例名称
|
||||
runtimeService.setProcessInstanceName(pi.getProcessInstanceId(), pi.getProcessDefinitionName());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.dromara.workflow.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -34,6 +35,49 @@ public class WfDefinitionConfigServiceImpl implements IWfDefinitionConfigService
|
||||
return baseMapper.selectVoOne(new LambdaQueryWrapper<WfDefinitionConfig>().eq(WfDefinitionConfig::getDefinitionId, definitionId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流程定义配置
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public WfDefinitionConfigVo getByTableNameLastVersion(String tableName) {
|
||||
List<WfDefinitionConfigVo> wfDefinitionConfigVos = baseMapper.selectVoList(
|
||||
new LambdaQueryWrapper<WfDefinitionConfig>().eq(WfDefinitionConfig::getTableName, tableName).orderByDesc(WfDefinitionConfig::getVersion));
|
||||
if (CollUtil.isNotEmpty(wfDefinitionConfigVos)) {
|
||||
return wfDefinitionConfigVos.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流程定义配置
|
||||
*
|
||||
* @param definitionId 流程定义id
|
||||
* @param tableName 表名
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public WfDefinitionConfigVo getByDefIdAndTableName(String definitionId, String tableName) {
|
||||
return baseMapper.selectVoOne(new LambdaQueryWrapper<WfDefinitionConfig>()
|
||||
.eq(WfDefinitionConfig::getDefinitionId, definitionId)
|
||||
.eq(WfDefinitionConfig::getTableName, tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流程定义配置排除当前查询的流程定义
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param definitionId 流程定义id
|
||||
*/
|
||||
@Override
|
||||
public List<WfDefinitionConfigVo> getByTableNameNotDefId(String tableName, String definitionId) {
|
||||
return baseMapper.selectVoList(new LambdaQueryWrapper<WfDefinitionConfig>()
|
||||
.eq(WfDefinitionConfig::getTableName, tableName)
|
||||
.ne(WfDefinitionConfig::getDefinitionId, definitionId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流程定义配置列表
|
||||
*/
|
||||
@ -49,6 +93,8 @@ public class WfDefinitionConfigServiceImpl implements IWfDefinitionConfigService
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean saveOrUpdate(WfDefinitionConfigBo bo) {
|
||||
WfDefinitionConfig add = MapstructUtils.convert(bo, WfDefinitionConfig.class);
|
||||
baseMapper.delete(new LambdaQueryWrapper<WfDefinitionConfig>().eq(WfDefinitionConfig::getTableName, bo.getTableName()));
|
||||
add.setTableName(add.getTableName().toLowerCase());
|
||||
boolean flag = baseMapper.insertOrUpdate(add);
|
||||
if (baseMapper.insertOrUpdate(add)) {
|
||||
bo.setId(add.getId());
|
||||
|
Reference in New Issue
Block a user