From c859fa4c38cc027cb7005dcb5c504ffc89430e33 Mon Sep 17 00:00:00 2001 From: songgaoshuai <1742057357@qq.com> Date: 星期五, 29 三月 2024 15:59:48 +0800 Subject: [PATCH] update 调整自定义任务 --- ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActModelServiceImpl.java | 72 +++++++++++++++++++++++------------- 1 files changed, 46 insertions(+), 26 deletions(-) diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActModelServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActModelServiceImpl.java index 718086b..e070dfd 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActModelServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActModelServiceImpl.java @@ -15,12 +15,16 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.dromara.common.core.exception.ServiceException; +import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; 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; @@ -51,6 +55,7 @@ public class ActModelServiceImpl implements IActModelService { private final RepositoryService repositoryService; + private final IWfFormDefinitionService iWfFormDefinitionService; /** * 鍒嗛〉鏌ヨ妯″瀷 @@ -59,7 +64,7 @@ * @return 杩斿洖鍒嗛〉鍒楄〃 */ @Override - public TableDataInfo<Model> page(ModelBo modelBo) { + public TableDataInfo<Model> page(ModelBo modelBo, PageQuery pageQuery) { ModelQuery query = QueryUtils.modelQuery(); if (StringUtils.isNotEmpty(modelBo.getName())) { query.modelNameLike("%" + modelBo.getName() + "%"); @@ -74,10 +79,13 @@ // 鍒涘缓鏃堕棿闄嶅簭鎺掑垪 query.orderByCreateTime().desc(); // 鍒嗛〉鏌ヨ - List<Model> modelList = query.listPage(modelBo.getPageNum(), modelBo.getPageSize()); + 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; } /** @@ -107,9 +115,7 @@ model.setVersion(version); model.setCategory(categoryCode); model.setMetaInfo(description); - if (TenantHelper.isEnable()) { - model.setTenantId(TenantHelper.getTenantId()); - } + model.setTenantId(TenantHelper.getTenantId()); //淇濆瓨鍒濆鍖栫殑妯″瀷鍩烘湰淇℃伅鏁版嵁 repositoryService.saveModel(model); repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(xml)); @@ -250,6 +256,7 @@ } // 鏌ヨ妯″瀷鐨勫熀鏈俊鎭� Model model = repositoryService.getModel(id); + ProcessDefinition processDefinition = QueryUtils.definitionQuery().processDefinitionKey(model.getKey()).latestVersion().singleResult(); // xml璧勬簮鐨勫悕绉� 锛屽搴攁ct_ge_bytearray琛ㄤ腑鐨刵ame_瀛楁 String processName = model.getName() + ".bpmn20.xml"; // 璋冪敤閮ㄧ讲鐩稿叧鐨刟pi鏂规硶杩涜閮ㄧ讲娴佺▼瀹氫箟 @@ -272,6 +279,17 @@ // 鏇存柊鍒嗙被 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(); @@ -282,35 +300,37 @@ /** * 瀵煎嚭妯″瀷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"; - // 灏唜ml娣诲姞鍒板帇缂╁寘涓�(鎸囧畾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"; + // 灏唜ml娣诲姞鍒板帇缂╁寘涓�(鎸囧畾xml鏂囦欢鍚嶏細璇峰亣娴佺▼.bpmn20.xml + zos.putNextEntry(new ZipEntry(fileName + ".bpmn20.xml")); + zos.write(xmlBytes); + } } } response.setHeader("Content-Disposition", -- Gitblit v1.9.3