| | |
| | | import org.dromara.common.tenant.helper.TenantHelper; |
| | | import org.dromara.workflow.common.constant.FlowConstant; |
| | | import org.dromara.workflow.domain.bo.ModelBo; |
| | | import org.dromara.workflow.domain.bo.WfFormDefinitionBo; |
| | | import org.dromara.workflow.domain.vo.ModelVo; |
| | | import org.dromara.workflow.domain.vo.WfFormDefinitionVo; |
| | | import org.dromara.workflow.service.IActModelService; |
| | | import org.dromara.workflow.service.IWfFormDefinitionService; |
| | | import org.dromara.workflow.utils.ModelUtils; |
| | | import org.dromara.workflow.utils.QueryUtils; |
| | | import org.flowable.bpmn.model.BpmnModel; |
| | |
| | | public class ActModelServiceImpl implements IActModelService { |
| | | |
| | | private final RepositoryService repositoryService; |
| | | private final IWfFormDefinitionService iWfFormDefinitionService; |
| | | |
| | | /** |
| | | * 分页查询模型 |
| | |
| | | List<Model> modelList = query.listPage(pageQuery.getFirstNum(), pageQuery.getPageSize()); |
| | | // 总记录数 |
| | | long total = query.count(); |
| | | return new TableDataInfo<>(modelList, total); |
| | | TableDataInfo<Model> build = TableDataInfo.build(); |
| | | build.setRows(modelList); |
| | | build.setTotal(total); |
| | | return build; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | // 查询模型的基本信息 |
| | | Model model = repositoryService.getModel(id); |
| | | ProcessDefinition processDefinition = QueryUtils.definitionQuery().processDefinitionKey(model.getKey()).latestVersion().singleResult(); |
| | | // xml资源的名称 ,对应act_ge_bytearray表中的name_字段 |
| | | String processName = model.getName() + ".bpmn20.xml"; |
| | | // 调用部署相关的api方法进行部署流程定义 |
| | |
| | | // 更新分类 |
| | | ProcessDefinition definition = QueryUtils.definitionQuery().deploymentId(deployment.getId()).singleResult(); |
| | | repositoryService.setProcessDefinitionCategory(definition.getId(), model.getCategory()); |
| | | if (processDefinition != null) { |
| | | WfFormDefinitionVo definitionVo = iWfFormDefinitionService.getByDefId(processDefinition.getId()); |
| | | if (definitionVo != null) { |
| | | WfFormDefinitionBo wfFormDefinition = new WfFormDefinitionBo(); |
| | | wfFormDefinition.setDefinitionId(definition.getId()); |
| | | wfFormDefinition.setProcessKey(definition.getKey()); |
| | | wfFormDefinition.setPath(definitionVo.getPath()); |
| | | wfFormDefinition.setRemark(definitionVo.getRemark()); |
| | | iWfFormDefinitionService.saveOrUpdate(wfFormDefinition); |
| | | } |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | /** |
| | | * 导出模型zip压缩包 |
| | | * |
| | | * @param modelId 模型id |
| | | * @param modelIds 模型id |
| | | * @param response 相应 |
| | | */ |
| | | @Override |
| | | public void exportZip(String modelId, HttpServletResponse response) { |
| | | public void exportZip(List<String> modelIds, HttpServletResponse response) { |
| | | ZipOutputStream zos = null; |
| | | try { |
| | | zos = ZipUtil.getZipOutputStream(response.getOutputStream(), StandardCharsets.UTF_8); |
| | | // 压缩包文件名 |
| | | String zipName = "模型不存在"; |
| | | // 查询模型基本信息 |
| | | Model model = repositoryService.getModel(modelId); |
| | | byte[] xmlBytes = repositoryService.getModelEditorSource(modelId); |
| | | if (ObjectUtil.isNotNull(model)) { |
| | | if (JSONUtil.isTypeJSON(IOUtils.toString(xmlBytes, StandardCharsets.UTF_8.toString())) && ArrayUtil.isEmpty(ModelUtils.bpmnJsonToXmlBytes(xmlBytes))) { |
| | | zipName = "模型不能为空,请至少设计一条主线流程!"; |
| | | zos.putNextEntry(new ZipEntry(zipName + ".txt")); |
| | | zos.write(zipName.getBytes(StandardCharsets.UTF_8)); |
| | | } else if (ArrayUtil.isEmpty(xmlBytes)) { |
| | | zipName = "模型数据为空,请先设计流程定义模型,再进行部署!"; |
| | | zos.putNextEntry(new ZipEntry(zipName + ".txt")); |
| | | zos.write(zipName.getBytes(StandardCharsets.UTF_8)); |
| | | } else { |
| | | String fileName = model.getName() + "-" + model.getKey(); |
| | | // 压缩包文件名 |
| | | zipName = fileName + ".zip"; |
| | | // 将xml添加到压缩包中(指定xml文件名:请假流程.bpmn20.xml |
| | | zos.putNextEntry(new ZipEntry(fileName + ".bpmn20.xml")); |
| | | zos.write(xmlBytes); |
| | | for (String modelId : modelIds) { |
| | | Model model = repositoryService.getModel(modelId); |
| | | byte[] xmlBytes = repositoryService.getModelEditorSource(modelId); |
| | | if (ObjectUtil.isNotNull(model)) { |
| | | if (JSONUtil.isTypeJSON(IOUtils.toString(xmlBytes, StandardCharsets.UTF_8.toString())) && ArrayUtil.isEmpty(ModelUtils.bpmnJsonToXmlBytes(xmlBytes))) { |
| | | zipName = "模型不能为空,请至少设计一条主线流程!"; |
| | | zos.putNextEntry(new ZipEntry(zipName + ".txt")); |
| | | zos.write(zipName.getBytes(StandardCharsets.UTF_8)); |
| | | } else if (ArrayUtil.isEmpty(xmlBytes)) { |
| | | zipName = "模型数据为空,请先设计流程定义模型,再进行部署!"; |
| | | zos.putNextEntry(new ZipEntry(zipName + ".txt")); |
| | | zos.write(zipName.getBytes(StandardCharsets.UTF_8)); |
| | | } else { |
| | | String fileName = model.getName() + "-" + model.getKey(); |
| | | // 压缩包文件名 |
| | | zipName = fileName + ".zip"; |
| | | // 将xml添加到压缩包中(指定xml文件名:请假流程.bpmn20.xml |
| | | zos.putNextEntry(new ZipEntry(fileName + ".bpmn20.xml")); |
| | | zos.write(xmlBytes); |
| | | } |
| | | } |
| | | } |
| | | response.setHeader("Content-Disposition", |