| | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import org.apache.commons.io.IOUtils; |
| | |
| | | import org.dromara.common.tenant.helper.TenantHelper; |
| | | import org.dromara.workflow.common.constant.FlowConstant; |
| | | import org.dromara.workflow.domain.WfCategory; |
| | | import org.dromara.workflow.domain.WfNodeConfig; |
| | | import org.dromara.workflow.domain.bo.ProcessDefinitionBo; |
| | | import org.dromara.workflow.domain.bo.WfDefinitionConfigBo; |
| | | import org.dromara.workflow.domain.vo.ProcessDefinitionVo; |
| | | import org.dromara.workflow.domain.vo.WfFormDefinitionVo; |
| | | import org.dromara.workflow.domain.vo.WfDefinitionConfigVo; |
| | | import org.dromara.workflow.service.IActProcessDefinitionService; |
| | | import org.dromara.workflow.service.IWfCategoryService; |
| | | import org.dromara.workflow.service.IWfFormDefinitionService; |
| | | import org.dromara.workflow.service.IWfDefinitionConfigService; |
| | | import org.dromara.workflow.service.IWfNodeConfigService; |
| | | import org.dromara.workflow.utils.ModelUtils; |
| | | import org.dromara.workflow.utils.QueryUtils; |
| | | import org.flowable.bpmn.model.UserTask; |
| | | import org.flowable.engine.ProcessMigrationService; |
| | | import org.flowable.engine.RepositoryService; |
| | | import org.flowable.engine.impl.bpmn.deployer.ResourceNameUtil; |
| | |
| | | import java.io.InputStream; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipInputStream; |
| | |
| | | private final RepositoryService repositoryService; |
| | | private final ProcessMigrationService processMigrationService; |
| | | private final IWfCategoryService wfCategoryService; |
| | | private final IWfFormDefinitionService iWfFormDefinitionService; |
| | | private final IWfDefinitionConfigService iWfDefinitionConfigService; |
| | | private final IWfNodeConfigService iWfNodeConfigService; |
| | | |
| | | /** |
| | | * 分页查询 |
| | |
| | | } |
| | | if (CollUtil.isNotEmpty(definitionList)) { |
| | | List<String> ids = StreamUtils.toList(definitionList, ProcessDefinition::getId); |
| | | List<WfFormDefinitionVo> wfFormDefinitionVos = iWfFormDefinitionService.queryList(ids); |
| | | List<WfDefinitionConfigVo> wfDefinitionConfigVos = iWfDefinitionConfigService.queryList(ids); |
| | | for (ProcessDefinition processDefinition : definitionList) { |
| | | ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); |
| | | if (CollUtil.isNotEmpty(deploymentList)) { |
| | |
| | | processDefinitionVo.setDeploymentTime(e.getDeploymentTime()); |
| | | }); |
| | | } |
| | | if (CollUtil.isNotEmpty(wfFormDefinitionVos)) { |
| | | wfFormDefinitionVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfFormDefinitionVo); |
| | | if (CollUtil.isNotEmpty(wfDefinitionConfigVos)) { |
| | | wfDefinitionConfigVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfDefinitionConfigVo); |
| | | } |
| | | processDefinitionVoList.add(processDefinitionVo); |
| | | } |
| | | } |
| | | // 总记录数 |
| | | long total = query.count(); |
| | | |
| | | return new TableDataInfo<>(processDefinitionVoList, total); |
| | | TableDataInfo<ProcessDefinitionVo> build = TableDataInfo.build(); |
| | | build.setRows(processDefinitionVoList); |
| | | build.setTotal(total); |
| | | return build; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | if (CollUtil.isNotEmpty(definitionList)) { |
| | | List<String> ids = StreamUtils.toList(definitionList, ProcessDefinition::getId); |
| | | List<WfFormDefinitionVo> wfFormDefinitionVos = iWfFormDefinitionService.queryList(ids); |
| | | List<WfDefinitionConfigVo> wfDefinitionConfigVos = iWfDefinitionConfigService.queryList(ids); |
| | | for (ProcessDefinition processDefinition : definitionList) { |
| | | ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class); |
| | | if (CollUtil.isNotEmpty(deploymentList)) { |
| | |
| | | deploymentList.stream().filter(e -> e.getId().equals(processDefinition.getDeploymentId())).findFirst().ifPresent(e -> { |
| | | processDefinitionVo.setDeploymentTime(e.getDeploymentTime()); |
| | | }); |
| | | if (CollUtil.isNotEmpty(wfFormDefinitionVos)) { |
| | | wfFormDefinitionVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfFormDefinitionVo); |
| | | if (CollUtil.isNotEmpty(wfDefinitionConfigVos)) { |
| | | wfDefinitionConfigVos.stream().filter(e -> e.getDefinitionId().equals(processDefinition.getId())).findFirst().ifPresent(processDefinitionVo::setWfDefinitionConfigVo); |
| | | } |
| | | } |
| | | processDefinitionVoList.add(processDefinitionVo); |
| | |
| | | * @param processDefinitionId 流程定义id |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteDeployment(String deploymentId, String processDefinitionId) { |
| | | try { |
| | | List<HistoricTaskInstance> taskInstanceList = QueryUtils.hisTaskInstanceQuery() |
| | |
| | | } |
| | | //删除流程定义 |
| | | repositoryService.deleteDeployment(deploymentId); |
| | | //删除流程定义配置 |
| | | iWfDefinitionConfigService.deleteByDefIds(Collections.singletonList(processDefinitionId)); |
| | | //删除节点配置 |
| | | iWfNodeConfigService.deleteByDefIds(Collections.singletonList(processDefinitionId)); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | String processName = splitFilename[0]; |
| | | //流程key |
| | | String processKey = splitFilename[1]; |
| | | ProcessDefinition oldProcessDefinition = QueryUtils.definitionQuery().processDefinitionKey(processKey).latestVersion().singleResult(); |
| | | DeploymentBuilder builder = repositoryService.createDeployment(); |
| | | Deployment deployment = builder.addInputStream(filename, zipInputStream) |
| | | .tenantId(TenantHelper.getTenantId()) |
| | | .name(processName).key(processKey).category(categoryCode).deploy(); |
| | | ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); |
| | | repositoryService.setProcessDefinitionCategory(definition.getId(), categoryCode); |
| | | setWfConfig(oldProcessDefinition, definition); |
| | | zipInputStream.closeEntry(); |
| | | } |
| | | } catch (IOException e) { |
| | |
| | | String processName = splitFilename[0]; |
| | | //流程key |
| | | String processKey = splitFilename[1]; |
| | | ProcessDefinition oldProcessDefinition = QueryUtils.definitionQuery().processDefinitionKey(processKey).latestVersion().singleResult(); |
| | | DeploymentBuilder builder = repositoryService.createDeployment(); |
| | | Deployment deployment = builder.addInputStream(originalFilename, inputStream) |
| | | .tenantId(TenantHelper.getTenantId()) |
| | |
| | | // 更新分类 |
| | | ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); |
| | | repositoryService.setProcessDefinitionCategory(definition.getId(), categoryCode); |
| | | setWfConfig(oldProcessDefinition, definition); |
| | | } else { |
| | | throw new ServiceException("文件类型上传错误!"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 设置表单内容 |
| | | * |
| | | * @param oldProcessDefinition 部署前最新流程定义 |
| | | * @param definition 部署后最新流程定义 |
| | | */ |
| | | private void setWfConfig(ProcessDefinition oldProcessDefinition, ProcessDefinition definition) { |
| | | //更新流程定义表单 |
| | | if (oldProcessDefinition != null) { |
| | | WfDefinitionConfigVo definitionVo = iWfDefinitionConfigService.getByDefId(oldProcessDefinition.getId()); |
| | | if (definitionVo != null) { |
| | | iWfDefinitionConfigService.deleteByDefIds(Collections.singletonList(oldProcessDefinition.getId())); |
| | | WfDefinitionConfigBo wfFormDefinition = new WfDefinitionConfigBo(); |
| | | wfFormDefinition.setDefinitionId(definition.getId()); |
| | | wfFormDefinition.setProcessKey(definition.getKey()); |
| | | wfFormDefinition.setTableName(definitionVo.getTableName()); |
| | | wfFormDefinition.setVersion(definition.getVersion()); |
| | | wfFormDefinition.setRemark(definitionVo.getRemark()); |
| | | iWfDefinitionConfigService.saveOrUpdate(wfFormDefinition); |
| | | } |
| | | } |
| | | //更新流程节点配置表单 |
| | | List<UserTask> userTasks = ModelUtils.getUserTaskFlowElements(definition.getId()); |
| | | UserTask applyUserTask = ModelUtils.getApplyUserTask(definition.getId()); |
| | | List<WfNodeConfig> wfNodeConfigList = new ArrayList<>(); |
| | | for (UserTask userTask : userTasks) { |
| | | if (StringUtils.isNotBlank(userTask.getFormKey()) && userTask.getFormKey().contains(StrUtil.COLON)) { |
| | | WfNodeConfig wfNodeConfig = new WfNodeConfig(); |
| | | wfNodeConfig.setNodeId(userTask.getId()); |
| | | wfNodeConfig.setNodeName(userTask.getName()); |
| | | wfNodeConfig.setDefinitionId(definition.getId()); |
| | | String[] split = userTask.getFormKey().split(StrUtil.COLON); |
| | | wfNodeConfig.setFormType(split[0]); |
| | | wfNodeConfig.setFormId(Long.valueOf(split[1])); |
| | | wfNodeConfig.setApplyUserTask(applyUserTask.getId().equals(userTask.getId()) ? FlowConstant.TRUE : FlowConstant.FALSE); |
| | | wfNodeConfigList.add(wfNodeConfig); |
| | | } |
| | | } |
| | | if (CollUtil.isNotEmpty(wfNodeConfigList)) { |
| | | iWfNodeConfigService.saveOrUpdate(wfNodeConfigList); |
| | | } |
| | | } |
| | | } |