|
|
|
|
@ -1,16 +1,16 @@
|
|
|
|
|
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.ModelPageReqVO;
|
|
|
|
|
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
|
|
|
|
|
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo;
|
|
|
|
|
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO;
|
|
|
|
|
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.framework.common.pojo.CommonResult;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.activiti.bpmn.converter.BpmnXMLConverter;
|
|
|
|
|
import org.activiti.bpmn.model.BpmnModel;
|
|
|
|
|
@ -21,7 +21,9 @@ import org.activiti.engine.repository.ModelQuery;
|
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.xml.stream.XMLInputFactory;
|
|
|
|
|
import javax.xml.stream.XMLStreamReader;
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
|
@ -31,80 +33,75 @@ import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 工作流模型实现
|
|
|
|
|
* 流程定义实现
|
|
|
|
|
*
|
|
|
|
|
* @author yunlongn
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Validated
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class BpmModelServiceImpl implements BpmModelService {
|
|
|
|
|
|
|
|
|
|
private final RepositoryService repositoryService;
|
|
|
|
|
@Resource
|
|
|
|
|
private RepositoryService repositoryService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageResult<Model> pageList(ModelPageReqVo modelPageReqVo) {
|
|
|
|
|
public PageResult<Model> getModelPage(ModelPageReqVO pageVO) {
|
|
|
|
|
ModelQuery modelQuery = repositoryService.createModelQuery();
|
|
|
|
|
String likeName = modelPageReqVo.getName();
|
|
|
|
|
if (StrUtil.isNotBlank(likeName)){
|
|
|
|
|
modelQuery.modelNameLike("%"+likeName+"%");
|
|
|
|
|
if (StrUtil.isNotBlank(pageVO.getName())) {
|
|
|
|
|
modelQuery.modelNameLike("%" + pageVO.getName() + "%"); // 模糊匹配
|
|
|
|
|
}
|
|
|
|
|
// 执行查询
|
|
|
|
|
List<Model> models = modelQuery.orderByCreateTime().desc()
|
|
|
|
|
.listPage((modelPageReqVo.getPageNo() - 1) * modelPageReqVo.getPageSize(), modelPageReqVo.getPageSize());
|
|
|
|
|
return new PageResult<>(models, modelQuery.count());
|
|
|
|
|
.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
|
|
|
|
|
long modelCount = modelQuery.count();
|
|
|
|
|
return new PageResult<>(models, modelCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CommonResult<String> newModel(ModelVO modelVO) {
|
|
|
|
|
try {
|
|
|
|
|
//初始化一个空模型
|
|
|
|
|
Model model = repositoryService.newModel();
|
|
|
|
|
// TODO @Li:name 可以直接赋值过去哈,不用声明一个变量
|
|
|
|
|
String name = Optional.ofNullable(modelVO.getName()).orElse("new-process");
|
|
|
|
|
//设置一些默认信息
|
|
|
|
|
model.setName(name);
|
|
|
|
|
model.setKey(Optional.ofNullable(modelVO.getKey()).orElse("processKey"));
|
|
|
|
|
model.setMetaInfo(JsonUtils.toJsonString(modelVO));
|
|
|
|
|
repositoryService.saveModel(model);
|
|
|
|
|
if (!ObjectUtils.isEmpty(modelVO.getBpmnXml())) {
|
|
|
|
|
repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
}
|
|
|
|
|
return CommonResult.success(model.getId());
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
// TODO @Li:这里可以捕获,交给全局么?
|
|
|
|
|
// TODO @Li:异常,是不是 error 比较合适,然后堆栈使用 e 直接打印即可
|
|
|
|
|
log.info("模型创建失败!modelVO = {} e = {} ", modelVO, ExceptionUtils.getStackTrace(e));
|
|
|
|
|
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
|
|
|
|
}
|
|
|
|
|
public String createModel(BpmModelCreateReqVO createReqVO) {
|
|
|
|
|
// TODO 芋艿:校验 key 是否重复
|
|
|
|
|
// 创建流程定义
|
|
|
|
|
Model model = repositoryService.newModel();
|
|
|
|
|
model.setName(createReqVO.getName());
|
|
|
|
|
model.setKey(createReqVO.getKey());
|
|
|
|
|
// TODO 芋艿:metaInfo,description、category、formId
|
|
|
|
|
model.setMetaInfo(JsonUtils.toJsonString(createReqVO));
|
|
|
|
|
// 保存流程定义
|
|
|
|
|
repositoryService.saveModel(model);
|
|
|
|
|
// 添加 BPMN XML
|
|
|
|
|
repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(createReqVO.getBpmnXml()));
|
|
|
|
|
return model.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CommonResult<String> updateModel(ModelVO modelVO) {
|
|
|
|
|
try {
|
|
|
|
|
Model model = repositoryService.getModel(modelVO.getId());
|
|
|
|
|
if (ObjectUtils.isEmpty(model)) {
|
|
|
|
|
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
// 只能修改名字跟描述
|
|
|
|
|
ModelVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), ModelVO.class);
|
|
|
|
|
if (ObjectUtils.isEmpty(modelCreateVO)) {
|
|
|
|
|
modelCreateVO = new ModelVO();
|
|
|
|
|
}
|
|
|
|
|
modelCreateVO.setName(modelVO.getName());
|
|
|
|
|
modelCreateVO.setDescription(modelVO.getDescription());
|
|
|
|
|
model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO));
|
|
|
|
|
model.setName(modelVO.getName());
|
|
|
|
|
model.setKey(modelVO.getKey());
|
|
|
|
|
// 更新模型
|
|
|
|
|
repositoryService.saveModel(model);
|
|
|
|
|
|
|
|
|
|
repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
|
|
|
|
|
return CommonResult.success("保存成功");
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.info("模型更新失败!modelVO = {}", modelVO, e);
|
|
|
|
|
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
|
|
|
|
}
|
|
|
|
|
public CommonResult<String> updateModel(BpmModelCreateReqVO modelVO) {
|
|
|
|
|
// try {
|
|
|
|
|
// Model model = repositoryService.getModel(modelVO.getId());
|
|
|
|
|
// if (ObjectUtils.isEmpty(model)) {
|
|
|
|
|
// throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
|
|
|
|
|
// }
|
|
|
|
|
// // 只能修改名字跟描述
|
|
|
|
|
// BpmModelCreateReqVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), BpmModelCreateReqVO.class);
|
|
|
|
|
// if (ObjectUtils.isEmpty(modelCreateVO)) {
|
|
|
|
|
// modelCreateVO = new BpmModelCreateReqVO();
|
|
|
|
|
// }
|
|
|
|
|
// modelCreateVO.setName(modelVO.getName());
|
|
|
|
|
// modelCreateVO.setDescription(modelVO.getDescription());
|
|
|
|
|
// model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO));
|
|
|
|
|
// model.setName(modelVO.getName());
|
|
|
|
|
// model.setKey(modelVO.getKey());
|
|
|
|
|
// // 更新模型
|
|
|
|
|
// repositoryService.saveModel(model);
|
|
|
|
|
//
|
|
|
|
|
// repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
//
|
|
|
|
|
// return CommonResult.success("保存成功");
|
|
|
|
|
// }catch (Exception e){
|
|
|
|
|
// log.info("模型更新失败!modelVO = {}", modelVO, e);
|
|
|
|
|
// throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
|
|
|
|
|
// }
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|