mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 09:11:52 +08:00
流程的挂起与激活
This commit is contained in:
parent
f8b34d5b6d
commit
db54147697
@ -69,4 +69,11 @@ public class BpmModelController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-state")
|
||||
@ApiOperation(value = "修改模型的状态", notes = "实际更新的部署的流程定义的状态")
|
||||
public CommonResult<Boolean> updateModelState(@RequestBody BpmModelUpdateStateReqVO reqVO) {
|
||||
bpmModelService.updateModelState(reqVO.getId(), reqVO.getState());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@ApiModel("流程模型更新状态 Request VO")
|
||||
@Data
|
||||
public class BpmModelUpdateStateReqVO {
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1024")
|
||||
@NotNull(message = "编号不能为空")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 SuspensionState 枚举")
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer state;
|
||||
|
||||
}
|
@ -28,13 +28,10 @@ public interface BpmErrorCodeConstants {
|
||||
ErrorCode MODEL_NOT_EXISTS = new ErrorCode(1009002001, "流程模型不存在");
|
||||
ErrorCode MODEL_KEY_VALID = new ErrorCode(1009002002, "流程标识格式不正确,需要以字母或下划线开头,后接任意字母、数字、中划线、下划线、句点!");
|
||||
|
||||
// ========== 流程模型 1-009-003-000 ==========
|
||||
// ========== 流程定义 1-009-003-000 ==========
|
||||
ErrorCode DEFINITION_KEY_NOT_MATCH = new ErrorCode(1009003000, "流程定义的标识期望是({}),当前是({}),请修改 BPMN 流程图");
|
||||
ErrorCode DEFINITION_NAME_NOT_MATCH = new ErrorCode(1009003000, "流程定义的名字期望是({}),当前是({}),请修改 BPMN 流程图");
|
||||
|
||||
ErrorCode BPMN = new ErrorCode(1004001002, "工作流模型异常");
|
||||
ErrorCode BPMN_MODEL_PROCESS_NOT_EXISTS = new ErrorCode(1004001009, "流程数据为空");
|
||||
ErrorCode BPMN_PROCESS_DEFINITION_NOT_EXISTS = new ErrorCode(1004001004, "流程定义不存在");
|
||||
ErrorCode DEFINITION_NAME_NOT_MATCH = new ErrorCode(1009003001, "流程定义的名字期望是({}),当前是({}),请修改 BPMN 流程图");
|
||||
ErrorCode DEFINITION_NOT_EXISTS = new ErrorCode(1009003002, "流程定义不存在");
|
||||
|
||||
// ========== 动态表单模块 1-009-004-000 ==========
|
||||
ErrorCode FORM_NOT_EXISTS = new ErrorCode(1009004000, "动态表单不存在");
|
||||
|
@ -80,6 +80,14 @@ public interface BpmDefinitionService {
|
||||
return CollectionUtils.convertMap(getDeployments(ids), Deployment::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 deploymentId 对应的 ProcessDefinition
|
||||
*
|
||||
* @param deploymentId 部署编号
|
||||
* @return 流程定义
|
||||
*/
|
||||
ProcessDefinition getDefinitionByDeploymentId(String deploymentId);
|
||||
|
||||
/**
|
||||
* 获得 deploymentIds 对应的 ProcessDefinition 数组
|
||||
*
|
||||
@ -96,4 +104,12 @@ public interface BpmDefinitionService {
|
||||
*/
|
||||
String createDefinition(@Valid BpmDefinitionCreateReqDTO createReqDTO);
|
||||
|
||||
/**
|
||||
* 更新流程定义的挂起状态
|
||||
*
|
||||
* @param id 流程定义的编号
|
||||
* @param state 挂起状态 {@link org.activiti.engine.impl.persistence.entity.SuspensionState}
|
||||
*/
|
||||
void updateDefinitionSuspensionState(String id, Integer state);
|
||||
|
||||
}
|
||||
|
@ -17,14 +17,4 @@ public interface ProcessService {
|
||||
*/
|
||||
void deployProcess(MultipartFile multipartFile);
|
||||
|
||||
|
||||
/**
|
||||
* 激活或者挂起流程模型实体
|
||||
* @param processDefinitionId 流程模型实体id
|
||||
* @param type 类型
|
||||
* @return 状态
|
||||
*/
|
||||
String setActivOrHang(String processDefinitionId,String type);
|
||||
|
||||
|
||||
}
|
||||
|
@ -55,31 +55,6 @@ public class ProcessServiceImpl implements ProcessService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活或者挂起流程模型实体
|
||||
* @param processDefinitionId 流程模型实体id
|
||||
* @param type 类型
|
||||
* @return 提示
|
||||
*/
|
||||
@Override
|
||||
public String setActivOrHang(String processDefinitionId, String type) {
|
||||
String result = "无操作";
|
||||
switch (type){
|
||||
case "active":
|
||||
repositoryService.activateProcessDefinitionById(processDefinitionId,true,null);
|
||||
result = "已激活ID为【"+processDefinitionId+"】的流程模型实例";
|
||||
break;
|
||||
case "suspend":
|
||||
repositoryService.suspendProcessDefinitionById(processDefinitionId,true,null);
|
||||
result = "已挂起ID为【"+processDefinitionId+"】的流程模型实例";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据上传文件类型对应实现不同方式的流程部署
|
||||
* @param inputStream 文件输入流
|
||||
|
@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.BpmProcessDefinitionPageItemRespVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.BpmProcessDefinitionPageReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmDefinitionConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
|
||||
@ -19,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.activiti.bpmn.converter.BpmnXMLConverter;
|
||||
import org.activiti.bpmn.model.BpmnModel;
|
||||
import org.activiti.engine.RepositoryService;
|
||||
import org.activiti.engine.impl.persistence.entity.SuspensionState;
|
||||
import org.activiti.engine.repository.Deployment;
|
||||
import org.activiti.engine.repository.ProcessDefinition;
|
||||
import org.activiti.engine.repository.ProcessDefinitionQuery;
|
||||
@ -133,6 +133,11 @@ public class BpmDefinitionServiceImpl implements BpmDefinitionService {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessDefinition getDefinitionByDeploymentId(String deploymentId) {
|
||||
return repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProcessDefinition> getDefinitionListByDeploymentIds(Set<String> deploymentIds) {
|
||||
if (CollUtil.isEmpty(deploymentIds)) {
|
||||
@ -170,4 +175,19 @@ public class BpmDefinitionServiceImpl implements BpmDefinitionService {
|
||||
return definition.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDefinitionSuspensionState(String id, Integer state) {
|
||||
// 激活
|
||||
if (Objects.equals(SuspensionState.ACTIVE.getStateCode(), state)) {
|
||||
repositoryService.activateProcessDefinitionById(id, true, null);
|
||||
return;
|
||||
}
|
||||
// 挂起
|
||||
if (Objects.equals(SuspensionState.SUSPENDED.getStateCode(), state)) {
|
||||
repositoryService.suspendProcessDefinitionById(id, true, null);
|
||||
return;
|
||||
}
|
||||
log.error("[updateDefinitionSuspensionState][流程定义({}) 修改未知状态({})]", id, state);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,4 +57,12 @@ public interface BpmModelService {
|
||||
*/
|
||||
void deleteModel(String id);
|
||||
|
||||
/**
|
||||
* 修改模型的状态,实际更新的部署的流程定义的状态
|
||||
*
|
||||
* @param id 编号
|
||||
* @param state 状态 {@link org.activiti.engine.impl.persistence.entity.SuspensionState}
|
||||
*/
|
||||
void updateModelState(String id, Integer state);
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.activiti.engine.RepositoryService;
|
||||
import org.activiti.engine.impl.persistence.entity.SuspensionState;
|
||||
import org.activiti.engine.repository.Deployment;
|
||||
import org.activiti.engine.repository.Model;
|
||||
import org.activiti.engine.repository.ModelQuery;
|
||||
@ -158,6 +159,14 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
.setBpmnXml(StrUtil.utf8Str(bpmnBytes));
|
||||
String definitionId = bpmDefinitionService.createDefinition(definitionCreateReqDTO);
|
||||
|
||||
// 将老的流程定义进行挂起。也就是说,只有最新部署的流程定义,才可以发起任务。
|
||||
if (StrUtil.isNotEmpty(model.getDeploymentId())) {
|
||||
ProcessDefinition oldDefinition = bpmDefinitionService.getDefinitionByDeploymentId(model.getDeploymentId());
|
||||
if (oldDefinition != null) {
|
||||
bpmDefinitionService.updateDefinitionSuspensionState(oldDefinition.getId(), SuspensionState.SUSPENDED.getStateCode());
|
||||
}
|
||||
}
|
||||
|
||||
// 更新 model 的 deploymentId,进行关联
|
||||
ProcessDefinition definition = bpmDefinitionService.getDefinition(definitionId);
|
||||
model.setDeploymentId(definition.getDeploymentId());
|
||||
@ -175,6 +184,23 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
repositoryService.deleteModel(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateModelState(String id, Integer state) {
|
||||
// 校验流程模型存在
|
||||
Model model = repositoryService.getModel(id);
|
||||
if (model == null) {
|
||||
throw exception(MODEL_NOT_EXISTS);
|
||||
}
|
||||
// 校验流程定义存在
|
||||
ProcessDefinition definition = bpmDefinitionService.getDefinitionByDeploymentId(model.getDeploymentId());
|
||||
if (definition == null) {
|
||||
throw exception(DEFINITION_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 更新状态
|
||||
bpmDefinitionService.updateDefinitionSuspensionState(definition.getId(), state);
|
||||
}
|
||||
|
||||
private Model getModelByKey(String key) {
|
||||
return repositoryService.createModelQuery().modelKey(key).singleResult();
|
||||
}
|
||||
|
@ -23,6 +23,18 @@ export function updateModel(data) {
|
||||
})
|
||||
}
|
||||
|
||||
// 任务状态修改
|
||||
export function updateModelState(id, state) {
|
||||
return request({
|
||||
url: '/bpm/model/update-state',
|
||||
method: 'put',
|
||||
data: {
|
||||
id,
|
||||
state
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function createModel(data) {
|
||||
return request({
|
||||
url: '/bpm/model/create',
|
||||
|
@ -65,7 +65,6 @@ export function updateJobStatus(jobId, status) {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 定时任务立即执行一次
|
||||
export function runJob(jobId) {
|
||||
return request({
|
||||
|
@ -2,8 +2,8 @@
|
||||
<div class="app-container">
|
||||
<!-- 列表 -->
|
||||
<el-table v-loading="loading" :data="list">
|
||||
<el-table-column label="定义编号" align="center" prop="id" />
|
||||
<el-table-column label="定义名称" align="center" prop="name" width="200">
|
||||
<el-table-column label="定义编号" align="center" prop="id" width="400" />
|
||||
<el-table-column label="定义名称" align="center" prop="name" width="100">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" @click="handleBpmnDetail(scope.row)">
|
||||
<span>{{ scope.row.name }}</span>
|
||||
|
@ -69,7 +69,7 @@
|
||||
<el-table-column label="激活状态" align="center" prop="processDefinition.version" width="80">
|
||||
<template slot-scope="scope">
|
||||
<el-switch v-if="scope.row.processDefinition" v-model="scope.row.processDefinition.suspensionState"
|
||||
:active-value="1" :inactive-value="2" @change="handleStatusChange(scope.row)" />
|
||||
:active-value="1" :inactive-value="2" @change="handleChangeState(scope.row)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="部署时间" align="center" prop="deploymentTime" width="180">
|
||||
@ -104,7 +104,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {deleteModel, deployModel, getModelPage, getModel} from "@/api/bpm/model";
|
||||
import {deleteModel, deployModel, getModelPage, getModel, updateModelState} from "@/api/bpm/model";
|
||||
import {DICT_TYPE, getDictDatas} from "@/utils/dict";
|
||||
import {getForm} from "@/api/bpm/form";
|
||||
import {decodeFields} from "@/utils/formGenerator";
|
||||
@ -250,7 +250,23 @@ export default {
|
||||
key: row.key
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
/** 更新状态操作 */
|
||||
handleChangeState(row) {
|
||||
const id = row.id;
|
||||
let state = row.processDefinition.suspensionState;
|
||||
let statusState = state === 1 ? '激活' : '挂起';
|
||||
this.$confirm('是否确认' + statusState + '流程名字为"' + row.name + '"的数据项?', "警告", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(function() {
|
||||
return updateModelState(id, state);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.msgSuccess(statusState + "成功");
|
||||
})
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user