feat: 模型的流程数据清理功能
This commit is contained in:
parent
1784aab186
commit
62b271fbf8
|
@ -161,6 +161,15 @@ public class BpmModelController {
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/clean")
|
||||||
|
@Operation(summary = "清理模型")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('bpm:model:delete')")
|
||||||
|
public CommonResult<Boolean> cleanModel(@RequestParam("id") String id) {
|
||||||
|
modelService.cleanModel(getLoginUserId(), id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
// ========== 仿钉钉/飞书的精简模型 =========
|
// ========== 仿钉钉/飞书的精简模型 =========
|
||||||
|
|
||||||
@GetMapping("/simple/get")
|
@GetMapping("/simple/get")
|
||||||
|
|
|
@ -88,6 +88,14 @@ public interface BpmModelService {
|
||||||
*/
|
*/
|
||||||
void deleteModel(Long userId, String id);
|
void deleteModel(Long userId, String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理模型
|
||||||
|
*
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void cleanModel(Long userId, String id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改模型的状态,实际更新的部署的流程定义的状态
|
* 修改模型的状态,实际更新的部署的流程定义的状态
|
||||||
*
|
*
|
||||||
|
|
|
@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert;
|
||||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
|
||||||
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
|
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
|
||||||
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum;
|
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum;
|
||||||
|
import cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
|
||||||
|
@ -25,10 +26,14 @@ import org.flowable.bpmn.model.BpmnModel;
|
||||||
import org.flowable.bpmn.model.StartEvent;
|
import org.flowable.bpmn.model.StartEvent;
|
||||||
import org.flowable.bpmn.model.UserTask;
|
import org.flowable.bpmn.model.UserTask;
|
||||||
import org.flowable.common.engine.impl.db.SuspensionState;
|
import org.flowable.common.engine.impl.db.SuspensionState;
|
||||||
|
import org.flowable.engine.HistoryService;
|
||||||
import org.flowable.engine.RepositoryService;
|
import org.flowable.engine.RepositoryService;
|
||||||
|
import org.flowable.engine.RuntimeService;
|
||||||
|
import org.flowable.engine.history.HistoricProcessInstance;
|
||||||
import org.flowable.engine.repository.Model;
|
import org.flowable.engine.repository.Model;
|
||||||
import org.flowable.engine.repository.ModelQuery;
|
import org.flowable.engine.repository.ModelQuery;
|
||||||
import org.flowable.engine.repository.ProcessDefinition;
|
import org.flowable.engine.repository.ProcessDefinition;
|
||||||
|
import org.flowable.engine.runtime.ProcessInstance;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -63,6 +68,11 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||||
@Resource
|
@Resource
|
||||||
private BpmTaskCandidateInvoker taskCandidateInvoker;
|
private BpmTaskCandidateInvoker taskCandidateInvoker;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private HistoryService historyService;
|
||||||
|
@Resource
|
||||||
|
private RuntimeService runtimeService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Model> getModelList(String name) {
|
public List<Model> getModelList(String name) {
|
||||||
ModelQuery modelQuery = repositoryService.createModelQuery();
|
ModelQuery modelQuery = repositoryService.createModelQuery();
|
||||||
|
@ -246,6 +256,28 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||||
updateProcessDefinitionSuspended(model.getDeploymentId());
|
updateProcessDefinitionSuspended(model.getDeploymentId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanModel(Long userId, String id) {
|
||||||
|
// 1. 校验流程模型存在
|
||||||
|
Model model = validateModelManager(id, userId);
|
||||||
|
|
||||||
|
// 2. 清理所有流程数据
|
||||||
|
// TODO @芋艿:这里没有找到批量操作的方法,会不会有性能问题~
|
||||||
|
// 2.1 先取消所有正在运行的流程
|
||||||
|
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery()
|
||||||
|
.processDefinitionKey(model.getKey()).list();
|
||||||
|
processInstances.forEach(processInstance -> {
|
||||||
|
runtimeService.deleteProcessInstance(processInstance.getId(),
|
||||||
|
BpmReasonEnum.CANCEL_BY_SYSTEM.getReason());
|
||||||
|
});
|
||||||
|
// 2.2 再从历史中删除所有相关的流程数据
|
||||||
|
List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery()
|
||||||
|
.processDefinitionKey(model.getKey()).list();
|
||||||
|
historicProcessInstances.forEach(historicProcessInstance -> {
|
||||||
|
historyService.deleteHistoricProcessInstance(historicProcessInstance.getId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateModelState(Long userId, String id, Integer state) {
|
public void updateModelState(Long userId, String id, Integer state) {
|
||||||
// 1.1 校验流程模型存在
|
// 1.1 校验流程模型存在
|
||||||
|
|
Loading…
Reference in New Issue