|
@@ -2,13 +2,18 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelCreateReqVO;
|
|
|
+import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.BpmModelRespVO;
|
|
|
import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.ModelPageReqVO;
|
|
|
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
|
|
|
+import cn.iocoder.yudao.adminserver.modules.bpm.convert.model.ModelConvert;
|
|
|
+import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO;
|
|
|
import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants;
|
|
|
-import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService;
|
|
|
-import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
|
|
+import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService;
|
|
|
+import cn.iocoder.yudao.adminserver.modules.bpm.service.model.BpmModelService;
|
|
|
+import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -20,6 +25,7 @@ import org.activiti.engine.repository.Model;
|
|
|
import org.activiti.engine.repository.ModelQuery;
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
@@ -30,7 +36,12 @@ import java.io.ByteArrayInputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Optional;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.BPM_MODEL_KEY_EXISTS;
|
|
|
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
|
/**
|
|
|
* 流程定义实现
|
|
@@ -44,9 +55,11 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|
|
|
|
|
@Resource
|
|
|
private RepositoryService repositoryService;
|
|
|
+ @Resource
|
|
|
+ private BpmFormService bpmFormService;
|
|
|
|
|
|
@Override
|
|
|
- public PageResult<Model> getModelPage(ModelPageReqVO pageVO) {
|
|
|
+ public PageResult<BpmModelRespVO> getModelPage(ModelPageReqVO pageVO) {
|
|
|
ModelQuery modelQuery = repositoryService.createModelQuery();
|
|
|
if (StrUtil.isNotBlank(pageVO.getName())) {
|
|
|
modelQuery.modelNameLike("%" + pageVO.getName() + "%"); // 模糊匹配
|
|
@@ -55,18 +68,29 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|
|
List<Model> models = modelQuery.orderByCreateTime().desc()
|
|
|
.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
|
|
|
long modelCount = modelQuery.count();
|
|
|
- return new PageResult<>(models, modelCount);
|
|
|
+
|
|
|
+ // 获得 Form Map
|
|
|
+ Set<Long> formIds = CollectionUtils.convertSet(models, model -> {
|
|
|
+ BpmModelMetaInfoRespDTO metaInfo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class);
|
|
|
+ return metaInfo != null ? metaInfo.getFormId() : null;
|
|
|
+ });
|
|
|
+ Map<Long, BpmFormDO> formMap = bpmFormService.getFormMap(formIds);
|
|
|
+ // 拼接结果
|
|
|
+ return new PageResult<>(ModelConvert.INSTANCE.convertList(models, formMap), modelCount);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务
|
|
|
public String createModel(BpmModelCreateReqVO createReqVO) {
|
|
|
- // TODO 芋艿:校验 key 是否重复
|
|
|
+ // 校验流程标识已经存在
|
|
|
+ Model keyModel = this.getModelByKey(createReqVO.getKey());
|
|
|
+ if (keyModel != null) {
|
|
|
+ throw exception(BPM_MODEL_KEY_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
// 创建流程定义
|
|
|
Model model = repositoryService.newModel();
|
|
|
- model.setName(createReqVO.getName());
|
|
|
- model.setKey(createReqVO.getKey());
|
|
|
- // TODO 芋艿:metaInfo,description、category、formId
|
|
|
- model.setMetaInfo(JsonUtils.toJsonString(createReqVO));
|
|
|
+ ModelConvert.INSTANCE.copy(model, createReqVO);
|
|
|
// 保存流程定义
|
|
|
repositoryService.saveModel(model);
|
|
|
// 添加 BPMN XML
|
|
@@ -109,11 +133,11 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|
|
try {
|
|
|
Model modelData = repositoryService.getModel(modelId);
|
|
|
if (ObjectUtils.isEmpty(modelData)) {
|
|
|
- throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
|
|
+ throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
|
|
}
|
|
|
byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
|
|
|
if (bytes == null) {
|
|
|
- throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
|
|
+ throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
|
|
}
|
|
|
// 将xml转换为流
|
|
|
// TODO @Li:这里是标准逻辑,看看 hutool 有没工具类提供。如果没有,咱自己封装一个
|
|
@@ -124,7 +148,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|
|
// 流数据转化为 model
|
|
|
BpmnModel model = new BpmnXMLConverter().convertToBpmnModel(xtr);
|
|
|
if(ObjectUtils.isEmpty(model.getProcesses())){
|
|
|
- throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_PROCESS_NOT_EXISTS);
|
|
|
+ throw exception(BpmErrorCodeConstants.BPMN_MODEL_PROCESS_NOT_EXISTS);
|
|
|
}
|
|
|
byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
|
|
|
// 部署发布模型流程
|
|
@@ -137,7 +161,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|
|
return CommonResult.success(deployment.getId());
|
|
|
} catch (Exception e) {
|
|
|
log.info("模型部署失败!modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e));
|
|
|
- throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
|
|
+ throw exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -146,7 +170,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|
|
try {
|
|
|
Model modelData = repositoryService.getModel(modelId);
|
|
|
if (ObjectUtils.isEmpty(modelData)) {
|
|
|
- throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
|
|
+ throw exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
|
|
}
|
|
|
byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
|
|
|
FileResp fileResp = new FileResp();
|
|
@@ -155,7 +179,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|
|
return fileResp;
|
|
|
} catch (Exception e) {
|
|
|
log.info("模型部署失败!modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e));
|
|
|
- throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
|
|
+ throw exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -166,4 +190,8 @@ public class BpmModelServiceImpl implements BpmModelService {
|
|
|
return CommonResult.success("删除成功");
|
|
|
}
|
|
|
|
|
|
+ private Model getModelByKey(String key) {
|
|
|
+ return repositoryService.createModelQuery().modelKey(key).singleResult();
|
|
|
+ }
|
|
|
+
|
|
|
}
|