From db5414769724de63e5be1cffd81ba6d6f9244e14 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 3 Jan 2022 12:26:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=E7=9A=84=E6=8C=82=E8=B5=B7?= =?UTF-8?q?=E4=B8=8E=E6=BF=80=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/model/BpmModelController.java | 7 +++++ .../model/vo/BpmModelUpdateStateReqVO.java | 21 +++++++++++++++ .../bpm/enums/BpmErrorCodeConstants.java | 9 +++---- .../definition/BpmDefinitionService.java | 16 ++++++++++++ .../service/definition/ProcessService.java | 10 ------- .../definition/ProcessServiceImpl.java | 25 ------------------ .../impl/BpmDefinitionServiceImpl.java | 22 +++++++++++++++- .../bpm/service/model/BpmModelService.java | 8 ++++++ .../model/impl/BpmModelServiceImpl.java | 26 +++++++++++++++++++ yudao-admin-ui/src/api/bpm/model.js | 12 +++++++++ yudao-admin-ui/src/api/infra/job.js | 1 - .../src/views/bpm/definition/index.vue | 4 +-- yudao-admin-ui/src/views/bpm/model/index.vue | 22 +++++++++++++--- 13 files changed, 135 insertions(+), 48 deletions(-) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateStateReqVO.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java index 3b4f177e9..79b29cd0d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java @@ -69,4 +69,11 @@ public class BpmModelController { return success(true); } + @PutMapping("/update-state") + @ApiOperation(value = "修改模型的状态", notes = "实际更新的部署的流程定义的状态") + public CommonResult updateModelState(@RequestBody BpmModelUpdateStateReqVO reqVO) { + bpmModelService.updateModelState(reqVO.getId(), reqVO.getState()); + return success(true); + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateStateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateStateReqVO.java new file mode 100644 index 000000000..4351af0b1 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateStateReqVO.java @@ -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; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java index 2c64cc1b9..74c492b68 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java @@ -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, "动态表单不存在"); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java index 4804d28a7..b188317a5 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmDefinitionService.java @@ -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); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java index 7e8cb6831..432fb9f86 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessService.java @@ -17,14 +17,4 @@ public interface ProcessService { */ void deployProcess(MultipartFile multipartFile); - - /** - * 激活或者挂起流程模型实体 - * @param processDefinitionId 流程模型实体id - * @param type 类型 - * @return 状态 - */ - String setActivOrHang(String processDefinitionId,String type); - - } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java index bfa53c06d..17dea8154 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/ProcessServiceImpl.java @@ -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 文件输入流 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmDefinitionServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmDefinitionServiceImpl.java index baf8146f2..ce91fa245 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmDefinitionServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmDefinitionServiceImpl.java @@ -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 getDefinitionListByDeploymentIds(Set 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); + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java index 83d68e5a8..1d1d2fd1d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java @@ -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); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java index 385517f29..1bc7d6418 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java @@ -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(); } diff --git a/yudao-admin-ui/src/api/bpm/model.js b/yudao-admin-ui/src/api/bpm/model.js index 8cb7e314b..83dca3000 100644 --- a/yudao-admin-ui/src/api/bpm/model.js +++ b/yudao-admin-ui/src/api/bpm/model.js @@ -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', diff --git a/yudao-admin-ui/src/api/infra/job.js b/yudao-admin-ui/src/api/infra/job.js index 7801f0399..c2237c519 100644 --- a/yudao-admin-ui/src/api/infra/job.js +++ b/yudao-admin-ui/src/api/infra/job.js @@ -65,7 +65,6 @@ export function updateJobStatus(jobId, status) { }) } - // 定时任务立即执行一次 export function runJob(jobId) { return request({ diff --git a/yudao-admin-ui/src/views/bpm/definition/index.vue b/yudao-admin-ui/src/views/bpm/definition/index.vue index 4666a7f48..19f943c14 100644 --- a/yudao-admin-ui/src/views/bpm/definition/index.vue +++ b/yudao-admin-ui/src/views/bpm/definition/index.vue @@ -2,8 +2,8 @@
- - + +