update - 调整流程定义相关错误码
This commit is contained in:
parent
dd3b32c0af
commit
ccc673250a
@ -19,7 +19,17 @@ import lombok.Getter;
|
||||
CONVERTOR_UNKNOW_NODE_TYPE("02001", "节点类型【{}】暂不支持"),
|
||||
CONVERTOR_META_DATA_FORMAT_ERROR("02002", "JSON 数据格式有误"),
|
||||
// ========== model 03-001 ==========
|
||||
MODEL_KEY_EXISTS("03001", "已经存在流程标识为【{}】的流程"),
|
||||
MODEL_ID_NOT_EXISTS("03002", "流程模型ID【{}】不存在"),
|
||||
MODEL_KEY_NOT_EXISTS("03003", "流程模型KEY【{}】不存在"),
|
||||
|
||||
// ========== processDefinition 04-001 ==========
|
||||
PROCESS_DEFINITION_BPMN_NOT_EXISTS("04001", "模型ID【{}】的定义内容不存在"),
|
||||
PROCESS_DEFINITION_ID_NOT_EXISTS("04002", "模型定义ID【{}】不存在"),
|
||||
PROCESS_DEFINITION_DEPLOY_ID_NOT_EXISTS("04003", "模型定义部署ID【{}】不存在"),
|
||||
PROCESS_DEFINITION_KEY_NOT_EXISTS("04004", "模型定义KEY【{}】不存在"),
|
||||
PROCESS_DEFINITION_RESULT_TOO_MANY("04005", "租户[]中存在多条分类为[]的流程定义,不允许直接变更状态"),
|
||||
// "数据出现异常,同一个工作台下,同一个所属分类,只能有一个流程定义"),
|
||||
// ========== processInstance 05-001 ==========
|
||||
// ========== task 06-001 ==========
|
||||
// ========== formDefinition 07-001 ==========
|
||||
@ -28,12 +38,9 @@ import lombok.Getter;
|
||||
|
||||
|
||||
// ========== 流程模型 01-001 ==========
|
||||
MODEL_KEY_EXISTS("01001", "已经存在流程标识为【{}】的流程"),
|
||||
|
||||
|
||||
MODEL_KEY_EXISTS2("9002000", "已经存在流程标识为【{}】的流程"),
|
||||
MODEL_NOT_EXISTS("9002001", "流程模型不存在"),
|
||||
MODEL_KEY_VALID("9002002",
|
||||
MODEL_KEY_VALID("9002002",
|
||||
"流程标识格式不正确,需要以字母或下划线开头,后接任意字母、数字、中划线、下划线、句点!"),
|
||||
MODEL_DEPLOY_FAIL_FORM_NOT_CONFIG("9002003",
|
||||
"部署流程失败,原因:流程表单未配置,请点击【修改流程】按钮进行配置"),
|
||||
@ -111,10 +118,9 @@ import lombok.Getter;
|
||||
"流程模型模板不存在,或者模型未配置 BPMN 流程"),
|
||||
BPM_PROCESS_DEFINITION_NOT_EXISTS("9012014",
|
||||
"未查询到可以用于发起工作流的流程定义ID, 请确认工作台与所属分类是否匹配"),
|
||||
BPM_PROCESS_DEFINITION_RESULT_TOO_MANY("9012015",
|
||||
"数据出现异常,同一个工作台下,同一个所属分类,只能有一个流程定义"),
|
||||
|
||||
FORM_NOT_ENABLE("9012016", "表单已经不可用"),
|
||||
|
||||
FORM_NOT_ENABLE("9012016", "表单已经不可用"),
|
||||
ILLEGAL_FORM_DATA("9012017", "表单类型数据异常, 非法数据"),
|
||||
BPMN_XML_NOT_EXISTS("9012018", "BPMN 文件内容不存在,将终止发布"),
|
||||
BPMN_XML_NOT_VALID("9012019", "BPMN 文件内容不合法,将终止发布"),
|
||||
|
||||
@ -24,8 +24,9 @@ import org.springframework.util.ObjectUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.MODEL_NOT_EXISTS;
|
||||
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.*;
|
||||
|
||||
@Service
|
||||
public class BpmModelServiceImpl implements BpmModelService {
|
||||
@ -38,29 +39,30 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
|
||||
@Override
|
||||
public BpmPageResult<BpmModelPageItemVO> getModelPage(BpmModelBpmPageDTO modelPageDTO) {
|
||||
//TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createBpmModel(@Valid BpmModelCreateDTO createDTO) {
|
||||
public String createBpmModel(@Valid BpmModelCreateDTO dto) {
|
||||
|
||||
Model existModel = repositoryService.createModelQuery().modelKey(createDTO.getKey()).singleResult();
|
||||
Model existModel = repositoryService.createModelQuery().modelKey(dto.getKey()).singleResult();
|
||||
if (!ObjectUtils.isEmpty(existModel)) {
|
||||
throw new WorkflowEngineException("模型已存在");
|
||||
throw new WorkflowEngineException(MODEL_KEY_EXISTS, dto.getKey());
|
||||
}
|
||||
|
||||
Model model = repositoryService.newModel();
|
||||
model.setName(createDTO.getName());
|
||||
model.setMetaInfo(JSON.toJSONString(createDTO.getMetaInfo()));
|
||||
model.setCategory(createDTO.getCategory());
|
||||
model.setKey(createDTO.getKey());
|
||||
model.setTenantId(createDTO.getTenantId());
|
||||
model.setName(dto.getName());
|
||||
model.setMetaInfo(JSON.toJSONString(dto.getMetaInfo()));
|
||||
model.setCategory(dto.getCategory());
|
||||
model.setKey(dto.getKey());
|
||||
model.setTenantId(dto.getTenantId());
|
||||
repositoryService.saveModel(model);
|
||||
//存储Bpmn协议
|
||||
if (createDTO.getNode() != null) {
|
||||
if (dto.getNode() != null) {
|
||||
//FIXME 在底层 Service 中直接将 jsonToXml 有风险,应先判断数据格式是否是 JSON
|
||||
byte[] bpmn = BpmTransformUtil.transformBpmnJsonToXml(createDTO.getNode(), model);
|
||||
saveModelBpmnXml(model, bpmn);
|
||||
byte[] bpmn = BpmTransformUtil.transformBpmnJsonToXml(dto.getNode(), model);
|
||||
saveModelBpmnXml(model, bpmn);
|
||||
}
|
||||
return model.getId();
|
||||
}
|
||||
@ -71,6 +73,9 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
@Override
|
||||
public BpmModelDetailVO getModelDetailById(String modelId) {
|
||||
Model model = repositoryService.getModel(modelId);
|
||||
if (Objects.isNull(model)) {
|
||||
throw new WorkflowEngineException(MODEL_ID_NOT_EXISTS, modelId);
|
||||
}
|
||||
return BpmModelConverter.convert(model);
|
||||
}
|
||||
|
||||
@ -80,24 +85,27 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
@Override
|
||||
public BpmModelDetailVO getModelDetailByKey(String modelKey) {
|
||||
Model model = repositoryService.createModelQuery().modelKey(modelKey).singleResult();
|
||||
if (Objects.isNull(model)) {
|
||||
throw new WorkflowEngineException(MODEL_KEY_NOT_EXISTS, modelKey);
|
||||
}
|
||||
return BpmModelConverter.convert(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBpmModel(BpmModelUpdateDTO updateDTO) {
|
||||
Model originModel = repositoryService.createModelQuery().modelId(updateDTO.getId()).singleResult();
|
||||
public void updateBpmModel(BpmModelUpdateDTO dto) {
|
||||
Model originModel = repositoryService.createModelQuery().modelId(dto.getId()).singleResult();
|
||||
if (ObjectUtils.isEmpty(originModel)) {
|
||||
throw new RuntimeException("模型不存在");
|
||||
throw new WorkflowEngineException(MODEL_ID_NOT_EXISTS, dto.getId());
|
||||
}
|
||||
originModel.setName(updateDTO.getName());
|
||||
originModel.setMetaInfo(JSON.toJSONString(updateDTO.getMetaInfo()));
|
||||
originModel.setCategory(updateDTO.getCategory());
|
||||
originModel.setKey(updateDTO.getKey());
|
||||
originModel.setTenantId(updateDTO.getTenantId());
|
||||
originModel.setName(dto.getName());
|
||||
originModel.setMetaInfo(JSON.toJSONString(dto.getMetaInfo()));
|
||||
originModel.setCategory(dto.getCategory());
|
||||
originModel.setKey(dto.getKey());
|
||||
originModel.setTenantId(dto.getTenantId());
|
||||
//存储Bpmn协议
|
||||
if (updateDTO.getNode() != null) {
|
||||
if (dto.getNode() != null) {
|
||||
//FIXME 入参是否强制为 JSON 格式?
|
||||
byte[] bpmn = BpmTransformUtil.transformBpmnJsonToXml(updateDTO.getNode(), originModel);
|
||||
byte[] bpmn = BpmTransformUtil.transformBpmnJsonToXml(dto.getNode(), originModel);
|
||||
saveModelBpmnXml(originModel, bpmn);
|
||||
}
|
||||
repositoryService.saveModel(originModel);
|
||||
@ -108,12 +116,12 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
public String deployBpmModelById(String modelId) {
|
||||
Model model = this.repositoryService.getModel(modelId);
|
||||
if (ObjectUtils.isEmpty(model)) {
|
||||
throw new WorkflowEngineException(MODEL_NOT_EXISTS);
|
||||
throw new WorkflowEngineException(MODEL_ID_NOT_EXISTS);
|
||||
}
|
||||
|
||||
byte[] bpmnBytes = this.repositoryService.getModelEditorSource(model.getId());
|
||||
if (bpmnBytes == null) {
|
||||
throw new WorkflowEngineException(MODEL_NOT_EXISTS);
|
||||
throw new WorkflowEngineException(PROCESS_DEFINITION_BPMN_NOT_EXISTS, model.getId());
|
||||
}
|
||||
|
||||
String definitionId = this.processDefinitionService.createProcessDefinition(model, bpmnBytes);
|
||||
@ -128,6 +136,9 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
@Override
|
||||
public String deployBpmModelByKey(String modelKey) {
|
||||
Model model = repositoryService.createModelQuery().modelKey(modelKey).singleResult();
|
||||
if (Objects.isNull(model)) {
|
||||
throw new WorkflowEngineException(MODEL_KEY_NOT_EXISTS, modelKey);
|
||||
}
|
||||
return deployBpmModelById(model.getId());
|
||||
}
|
||||
|
||||
@ -136,7 +147,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
// 校验流程模型存在
|
||||
Model model = repositoryService.getModel(id);
|
||||
if (model == null) {
|
||||
throw new WorkflowEngineException(MODEL_NOT_EXISTS);
|
||||
throw new WorkflowEngineException(MODEL_ID_NOT_EXISTS);
|
||||
}
|
||||
// 执行删除
|
||||
repositoryService.deleteModel(id);
|
||||
@ -149,16 +160,18 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
}
|
||||
|
||||
private void saveModelBpmnXml(Model model, byte[] bpmnXml) {
|
||||
if(bpmnXml != null && bpmnXml.length != 0){
|
||||
if (bpmnXml != null && bpmnXml.length != 0) {
|
||||
this.repositoryService.addModelEditorSource(model.getId(), bpmnXml);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProcessDefinitionSuspended(String deploymentId) {
|
||||
if (!StringUtils.isBlank(deploymentId)) {
|
||||
ProcessDefinition oldDefinition = this.processDefinitionService.getProcessDefinitionByDeploymentId(deploymentId);
|
||||
ProcessDefinition oldDefinition =
|
||||
this.processDefinitionService.getProcessDefinitionByDeploymentId(deploymentId);
|
||||
if (oldDefinition != null) {
|
||||
this.processDefinitionService.updateProcessDefinitionSuspendedState(oldDefinition.getId(), SuspensionState.SUSPENDED.getStateCode());
|
||||
this.processDefinitionService.updateProcessDefinitionSuspendedState(oldDefinition.getId(),
|
||||
SuspensionState.SUSPENDED.getStateCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ import cn.axzo.workflow.core.service.dto.response.process.BpmProcessDefinitionPa
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.flowable.common.engine.impl.db.SuspensionState;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.repository.Deployment;
|
||||
@ -105,7 +104,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
|
||||
if (StrUtil.isNotBlank(request.getKey())) {
|
||||
definitionQuery.processDefinitionKey(request.getKey());
|
||||
}
|
||||
if (StrUtil.isNotBlank(request.getTenantId())){
|
||||
if (StrUtil.isNotBlank(request.getTenantId())) {
|
||||
definitionQuery.processDefinitionTenantId(request.getTenantId());
|
||||
}
|
||||
// 执行查询
|
||||
@ -143,37 +142,45 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
|
||||
|
||||
@Override
|
||||
public ProcessDefinition getProcessDefinition(String id) {
|
||||
if (StringUtils.isBlank(id)) {
|
||||
return null;
|
||||
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(id);
|
||||
if (Objects.isNull(processDefinition)) {
|
||||
throw new WorkflowEngineException(PROCESS_DEFINITION_ID_NOT_EXISTS, id);
|
||||
}
|
||||
return repositoryService.getProcessDefinition(id);
|
||||
return processDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessDefinition getProcessDefinitionByDeploymentId(String deploymentId) {
|
||||
if (StringUtils.isBlank(deploymentId)) {
|
||||
return null;
|
||||
ProcessDefinition processDefinition =
|
||||
repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId)
|
||||
.singleResult();
|
||||
if (Objects.isNull(processDefinition)) {
|
||||
throw new WorkflowEngineException(PROCESS_DEFINITION_DEPLOY_ID_NOT_EXISTS, deploymentId);
|
||||
}
|
||||
return repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId)
|
||||
.singleResult();
|
||||
return processDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessDefinition getActiveProcessDefinitionByKey(String key) {
|
||||
return repositoryService.createProcessDefinitionQuery().processDefinitionKey(key).latestVersion()
|
||||
.singleResult();
|
||||
ProcessDefinition processDefinition =
|
||||
repositoryService.createProcessDefinitionQuery().processDefinitionKey(key).latestVersion()
|
||||
.singleResult();
|
||||
if (Objects.isNull(processDefinition)) {
|
||||
throw new WorkflowEngineException(PROCESS_DEFINITION_KEY_NOT_EXISTS, key);
|
||||
}
|
||||
return processDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActiveProcessDefinitionId(String tenantId, String category) {
|
||||
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery()
|
||||
.processDefinitionTenantId(String.valueOf(tenantId))
|
||||
.processDefinitionTenantId(tenantId)
|
||||
.processDefinitionCategory(category)
|
||||
.active()
|
||||
.latestVersion()
|
||||
.list();
|
||||
if (!CollectionUtils.isEmpty(list) && list.size() != 1) {
|
||||
throw new WorkflowEngineException(BPM_PROCESS_DEFINITION_RESULT_TOO_MANY);
|
||||
throw new WorkflowEngineException(PROCESS_DEFINITION_RESULT_TOO_MANY, tenantId, category);
|
||||
} else {
|
||||
return list.get(0).getId();
|
||||
}
|
||||
|
||||
@ -13,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Slf4j
|
||||
@RequestMapping("/web/v1/api/process/definition")
|
||||
@ -40,7 +42,7 @@ public class BpmProcessDefinitionController {
|
||||
* @return 流程定义
|
||||
*/
|
||||
@GetMapping("/get")
|
||||
public CommonResponse<ProcessDefinition> getProcessDefinition(@RequestParam String id) {
|
||||
public CommonResponse<ProcessDefinition> getProcessDefinition(@Valid @NotBlank(message = "流程定义ID不能为空") @RequestParam String id) {
|
||||
log.info("获取活跃的流程定义分页getProcessDefinition===>>>参数:{}", JSON.toJSONString(id));
|
||||
ProcessDefinition result = bpmProcessDefinitionService.getProcessDefinition(id);
|
||||
return CommonResponse.success(result);
|
||||
@ -54,7 +56,8 @@ public class BpmProcessDefinitionController {
|
||||
* @return 流程定义
|
||||
*/
|
||||
@GetMapping("/getByDeploymentId")
|
||||
public CommonResponse<ProcessDefinition> getProcessDefinitionByDeploymentId(@RequestParam String deploymentId) {
|
||||
public CommonResponse<ProcessDefinition> getProcessDefinitionByDeploymentId(@Valid @NotBlank(message = "流程部署ID" +
|
||||
"不能为空") @RequestParam String deploymentId) {
|
||||
log.info(" 获得 deploymentId 对应的 getProcessDefinitionByDeploymentId===>>>参数:{}", JSON.toJSONString(deploymentId));
|
||||
ProcessDefinition result = bpmProcessDefinitionService.getProcessDefinitionByDeploymentId(deploymentId);
|
||||
return CommonResponse.success(result);
|
||||
@ -68,7 +71,7 @@ public class BpmProcessDefinitionController {
|
||||
* @return 流程定义
|
||||
*/
|
||||
@GetMapping("/active/getByKey")
|
||||
public CommonResponse<ProcessDefinition> getActiveProcessDefinitionByKey(@RequestParam String key) {
|
||||
public CommonResponse<ProcessDefinition> getActiveProcessDefinitionByKey(@Valid @NotBlank(message = "模型定义KEY不能为空") @RequestParam String key) {
|
||||
log.info("获得流程定义标识对应的激活的流程定义 getActiveProcessDefinitionByKey===>>>参数:{}", JSON.toJSONString(key));
|
||||
ProcessDefinition result = bpmProcessDefinitionService.getActiveProcessDefinitionByKey(key);
|
||||
return CommonResponse.success(result);
|
||||
@ -82,22 +85,22 @@ public class BpmProcessDefinitionController {
|
||||
* {@link SuspensionState}
|
||||
*/
|
||||
@PutMapping("/state/update")
|
||||
public CommonResponse getActiveProcessDefinitionByKey(@RequestParam String processDefinitionId,
|
||||
@RequestParam Integer state) {
|
||||
public CommonResponse<Boolean> getActiveProcessDefinitionByKey(@Valid @NotBlank(message = "流程定义ID不能为空") @RequestParam String processDefinitionId,
|
||||
@Valid @NotNull(message = "状态不能为空") @RequestParam Integer state) {
|
||||
log.info("挂起/激活流程 updateProcessDefinitionSuspendedState===>>>参数:{},{}", processDefinitionId, state);
|
||||
bpmProcessDefinitionService.updateProcessDefinitionSuspendedState(processDefinitionId, state);
|
||||
return CommonResponse.success();
|
||||
return CommonResponse.success(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取指定模型激活的定义 ID
|
||||
* 获取指定模型的 Category 激活
|
||||
*
|
||||
* @return 流程定义ID
|
||||
*/
|
||||
@GetMapping("/active/getById")
|
||||
public CommonResponse<String> getActiveProcessDefinitionId(@RequestParam String tenantId,
|
||||
@RequestParam String category) {
|
||||
@GetMapping("/active/getByCategory")
|
||||
public CommonResponse<String> getActiveProcessDefinitionId(@Valid @NotBlank(message = "租户不能为空") @RequestParam String tenantId,
|
||||
@Valid @NotBlank(message = "分类不能为空") @RequestParam String category) {
|
||||
log.info("挂起/激活流程 getActiveProcessDefinitionId===>>>参数:{},{}", tenantId, category);
|
||||
String result = bpmProcessDefinitionService.getActiveProcessDefinitionId(tenantId, category);
|
||||
return CommonResponse.success(result);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user