提交 c42911a4 authored 作者: 黄夏豪's avatar 黄夏豪

[流程编辑器] 修改了保存流程的逻辑

[流程编辑器] 更新了回调函数的逻辑-》支持回调函数
上级 656b4923
......@@ -18,9 +18,6 @@ public class Parameter {
@ApiModelProperty(value = "类名")
private String className;
@ApiModelProperty("流程表达式")
private String exp;
/**
* Map形式的实例对象
* key为字段名 value为字段值
......
......@@ -43,6 +43,12 @@ public class AggregationController {
return ResultUtil.success("","保存成功!");
}
@PostMapping("/findTest")
public ResponseEntity findTest(Integer id) {
return ResultUtil.success(aggregationDao.findAllByTableInfoExIdAndParentId(id,null),"保存成功!");
}
@PostMapping("/test")
public ResponseEntity test(@RequestBody AggregationVO AggregationVO) {
String result= "";
......
......@@ -15,6 +15,7 @@ import java.util.List;
*/
public interface AggregationDao extends JpaRepository<Aggregation, Integer>, JpaSpecificationExecutor<Aggregation> {
List<Aggregation> findAllByTableInfoExIdAndParentId(Integer tableExId, Integer parentId);
List<Aggregation> findAllByTableInfoExIdAndParentId(Integer tableExId,Integer parrentId);
}
......@@ -88,7 +88,6 @@ public class AggregationImpl implements AggregationService {
}else {
throw new ApiException("id为:"+parentAggregation.getSideTableId()+"的副表不存在");
}
parentModeName = sideTableInfoOptional.get().getModelName();
}else {
//如果是第一层 则通过rootElement 查出副表的XML字符串
......@@ -157,55 +156,4 @@ public class AggregationImpl implements AggregationService {
return null;
}
// 假设获得的是一份XML
// public Element testDG(List<Aggregation> aggregations, Aggregation parentAggregation, Integer mainId, Element element){
// //循环
// Element elementCLass = DocumentHelper.createElement("class");
// if (parentAggregation!=null){
// elementCLass.addAttribute("name",parentAggregation.getSideTableId()+"_");
// }else {
// elementCLass.addAttribute("name",mainId+"_");
// }
// for (int i = 0; i < aggregations.size(); i++) {
// Aggregation aggregationChild = aggregations.get(i);
// if (aggregationChild.getAggregations()!=null&&aggregationChild.getAggregations().size()>0){
// Element elementClassChild = testDG(aggregationChild.getAggregations(), aggregationChild, mainId, element);
// Element elementSet = DocumentHelper.createElement("set");
// elementSet.addAttribute("setName","c"+elementClassChild.attribute("name").getValue());
// elementCLass.add(elementSet);
// }else {
// Element elementSet = DocumentHelper.createElement("set");
// elementSet.addAttribute("setName","c"+aggregationChild.getSideTableId());
// elementCLass.add(elementSet);
// }
// }
// element.add(elementCLass);
// return elementCLass;
// }
// Optional<TableInfo> sideTableById = tableInfoDao.findById(aggregationChild.getSideTableId());
// aggregationChild.setTableInfoExId(tableExId);
// if (!sideTableById.isPresent()){
// throw new ApiException("id为:"+aggregationChild.getSideTableId()+"的副表不存在");
// }
// if (aggregationChild.getRelationship().equals(AggregationType.ONE_TO_ONE)){
// AggregationUtil.addOneToOne(aggregationChild.getSideTableConnectionKey(), sideTableById.get().getModelName(), document);
// }
// if (aggregationChild.getRelationship().equals(AggregationType.ONE_TO_MANY)){
// //如果是一对多需要 为 aggregationRelationship 生成连接的KEY
// String mainTableConnectionKey = sideTableById.get().getModelName();
// AggregationUtil.addOneToMany(sideTableById.get().getModelName(), mainTableConnectionKey, aggregationChild.getSideTableConnectionKey(), document);
// }
// if (aggregationChild.getRelationship().equals(AggregationType.MANY_TO_MANY)){
// //如果是多对多需要 为 aggregationRelationship 生成连接的KEY
// String mainTableConnectionKey = mainTableInfo.getModelName()+"_Id";
// String sideTableConnectionKey = sideTableById.get().getModelName()+"_Id";
// aggregationChild.setMainTableConnectionKey(mainTableConnectionKey);
// aggregationChild.setSideTableConnectionKey(sideTableConnectionKey);
// //如果是多对多需要 为 aggregationRelationship 生成连接的中间表名
// String connectionTableName = mainTableInfo.getModelName()+"_"+sideTableById.get().getModelName()+"_"+ (UUID.randomUUID().toString().substring(0,8));
// aggregationChild.setConnectionTableName(connectionTableName);
// //Util.addManyToMany
// AggregationUtil.addManyToMany(sideTableById.get().getModelName(),connectionTableName,mainTableConnectionKey,sideTableConnectionKey,document);
// }
}
......@@ -76,7 +76,7 @@ public class FlowsInfoController {
@ApiOperation(value = "保存xml以及其他流程信息")
public ResponseEntity saveXml(@RequestBody FlowsInfoVo flowsInfoVo) throws IOException, XMLStreamException {
//保存节点信息
nodeInfoService.saveNodeInfoList(flowsInfoVo.getNodeInfoList());
// nodeInfoService.saveNodeInfoList(flowsInfoVo.getNodeInfoList());
//保存xml信息
workFlowService.flowXml(flowsInfoVo);
return ResultUtil.success("文件保存成功");
......
package com.tykj.workflowcore.workflow_editer.entity;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.tykj.workflowcore.base.entity.BaseEntity;
import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan;
import com.tykj.workflowcore.workflow_editer.entity.vo.InvokeRequestVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.ParameterVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......@@ -12,6 +14,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import java.util.List;
/**
* ClassName: VariableStorage
......@@ -41,12 +44,11 @@ public class VariableStorage extends BaseEntity {
private String method;
@ApiModelProperty("详情json")
private String invokeRequest;
private String parameterInfo;
@JsonGetter
public InvokeRequestVo getInvokeRequest() {
return JSON.parseObject(invokeRequest,InvokeRequestVo.class);
public List<ParameterVo> getParameterInfo() {
return JSON.parseObject(parameterInfo,new TypeReference<List<ParameterVo>>(){});
}
}
package com.tykj.workflowcore.workflow_editer.entity.vo;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tykj.workflowcore.workflow_editer.entity.FlowsInfo;
import com.tykj.workflowcore.workflow_editer.entity.NodeInfo;
......@@ -28,9 +29,6 @@ public class FlowsInfoVo {
@ApiModelProperty("主键id")
private Integer id;
@ApiModelProperty("发起人的名字")
private Integer userName;
@ApiModelProperty("流程名称")
private String flowName;
......@@ -40,32 +38,25 @@ public class FlowsInfoVo {
@ApiModelProperty(value = "部署状态",notes = "0 已部署,1 未部署")
private Integer state = 1;
@ApiModelProperty("流程创建时间")
private Date createTime;
@ApiModelProperty("流程修改时间")
private Date updateTime;
@ApiModelProperty("流程描述")
private String flowDescribe;
@ApiModelProperty
private String fileXml;
@ApiModelProperty("开始节点的id")
private String startId;
@ApiModelProperty("开始节点的id")
private String startPageId;
@ApiModelProperty("是否和之前一样 0是一样 1不一样")
private Integer isOld = 1;
@ApiModelProperty()
private List<NodeInfo> nodeInfoList;
public FlowsInfo toEntity(){
FlowsInfo flowsInfo = new FlowsInfo();
BeanUtils.copyProperties(this,flowsInfo);
return flowsInfo;
}
public FlowsInfo toEntity(FlowsInfo oldFlowsInfo){
if (!StrUtil.isEmpty(flowName)){
oldFlowsInfo.setFlowName(flowName);
}
if (!StrUtil.isEmpty(flowDescribe)){
oldFlowsInfo.setFlowDescribe(flowDescribe);
}
return oldFlowsInfo;
}
}
package com.tykj.workflowcore.workflow_editer.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* 回调接口配置Vo
* @author HuangXiahao
* @version V1.0
* @class parameterVo
* @packageName com.tykj.workflowcore.workflow_editer.entity.vo
**/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ParameterVo {
private String className;
private String exp;
private String name;
private List<ParameterVo> parameterVoList;
}
......@@ -10,6 +10,8 @@ import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import springfox.documentation.spring.web.json.Json;
import java.util.List;
/**
* @author HuangXiahao
* @version V1.0
......@@ -36,12 +38,12 @@ public class VariableStorageVo {
@ApiModelProperty("调用方法名")
private String method;
private InvokeRequestVo invokeRequest;
private List<ParameterVo> parameterList;
public VariableStorage toEntity(){
VariableStorage variableStorage = new VariableStorage();
BeanUtils.copyProperties(this,variableStorage);
variableStorage.setInvokeRequest(JSON.toJSONString(invokeRequest));
variableStorage.setParameterInfo(JSON.toJSONString(parameterList));
return variableStorage;
}
}
......@@ -7,8 +7,10 @@ import com.tykj.workflowcore.api.entity.Parameter;
import com.tykj.workflowcore.workflow_editer.entity.CommandGetValue;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import com.tykj.workflowcore.workflow_editer.entity.vo.InvokeRequestVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.ParameterVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.SearchVariableStorageVo;
import com.tykj.workflowcore.workflow_editer.service.VariableStorageService;
import liquibase.pro.packaged.I;
import org.flowable.bpmn.model.EndEvent;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
......@@ -20,16 +22,14 @@ import org.flowable.engine.delegate.event.FlowableActivityEvent;
import org.flowable.engine.delegate.event.impl.FlowableActivityEventImpl;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* @author HuangXiahao
......@@ -97,17 +97,20 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
DelegateExecution execution = ((FlowableActivityEventImpl) event).getExecution();
if (execution.getCurrentFlowElement() instanceof EndEvent){
System.out.println("流程结束了");
String processDefinitionId = execution.getProcessDefinitionId();
String processDefinitionId = ((ExecutionEntityImpl) execution).getProcessDefinitionKey();
String flowKey = processDefinitionId;
if (processDefinitionId.indexOf(":")>=0){
flowKey = processDefinitionId.substring(0,processDefinitionId.indexOf(":"));
}
List<VariableStorage> variableStorageList = variableStorageService.searchVariableStorageList(new SearchVariableStorageVo(flowKey,execution.getCurrentActivityId()));
for (VariableStorage variableStorage : variableStorageList) {
InvokeRequestVo variableInfo = variableStorage.getInvokeRequest();
variableInfo.setProcessInstance(execution);
List<ParameterVo> parameterVoList = variableStorage.getParameterInfo();
InvokeRequest invokeRequest = new InvokeRequest();
invokeRequest.setClassName(variableStorage.getClassName());
invokeRequest.setName(variableStorage.getMethod());
invokeRequest.setParams(getApiInvokeParam(parameterVoList,execution));
//调用服务接口
apiController.invoke(getApiInvokeParam(variableInfo));
apiController.invoke(invokeRequest);
}
}
}
......@@ -116,33 +119,38 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
/**
* 获取调用Api用的参数
*
* @param invokeRequestVo 调用服务接口vo
* @param parameterVoList 调用服务接口vo
* @return 调用服务接口实体
*/
public InvokeRequest getApiInvokeParam(InvokeRequestVo invokeRequestVo) {
public List<Parameter> getApiInvokeParam(List<ParameterVo> parameterVoList,DelegateExecution execution) {
//拿出taskId
DelegateExecution execution = invokeRequestVo.getProcessInstance();
List<Parameter> parameterList = invokeRequestVo.getParams();
List<Parameter> newParameterList = new ArrayList<>();
for (int i = 0; i < parameterList.size(); i++) {
Parameter parameter = parameterList.get(i);
if (!StringUtils.isEmpty(parameter.getExp())) {
List<Parameter> parameterList = new ArrayList<>();
for (int i = 0; i < parameterVoList.size(); i++) {
ParameterVo parameterVo = parameterVoList.get(i);
Parameter parameter = new Parameter();
parameter.setClassName(parameterVo.getClassName());
Map<String, Object> instance = new HashMap<>();
FillParameter(instance,parameterVoList.get(i),execution);
parameter.setInstance((Map<String, Object>) instance.get(parameterVo.getName()));
parameterList.add(parameter);
}
return parameterList;
}
public Map<String, Object> FillParameter(Map<String, Object> instance,ParameterVo parameterVo,DelegateExecution execution){
if (!StringUtils.isEmpty(parameterVo.getExp())) {
//如果是表示式 如:${people}
parameter.setInstance((Map<String, Object>) getProcessValue(execution, parameter.getExp()));
} else {
Map<String, Object> instance = parameter.getInstance();
JSONObject newInstance = new JSONObject();
//遍历param的key
Set<String> oldInstanceKey = instance.keySet();
for (String key : oldInstanceKey) {
newInstance.put(key, getProcessValue(execution, (String) instance.get(key)));
instance.put(parameterVo.getName(),getProcessValue(execution, parameterVo.getExp()));
}else {
instance.put(parameterVo.getName(),"");
}
parameter.setInstance(newInstance);
List<ParameterVo> parameterVoList = parameterVo.getParameterVoList();
if (parameterVoList!=null&&parameterVoList.size()>0){
for (int i = 0; i < parameterVoList.size() ; i++) {
FillParameter(instance,parameterVoList.get(i),execution);
}
newParameterList.add(i, parameter);
}
invokeRequestVo.setParams(newParameterList);
return JSONObject.parseObject(JSONObject.toJSONString(invokeRequestVo), InvokeRequest.class);
return instance;
}
public Object getProcessValue(DelegateExecution execution, String exp) {
......
......@@ -40,6 +40,7 @@ public class VariableStorageServiceImpl implements VariableStorageService {
if (searchVariableStorageVo!=null){
predicateBuilder.eq(searchVariableStorageVo.getId()!=null,"id",searchVariableStorageVo.getId());
predicateBuilder.eq(searchVariableStorageVo.getFlowKey()!=null,"flowKey",searchVariableStorageVo.getFlowKey());
predicateBuilder.eq(searchVariableStorageVo.getActivityId()!=null,"activityId",searchVariableStorageVo.getActivityId());
}
return variableStorageMapper.findAll(predicateBuilder.build());
}
......
package com.tykj.workflowcore.workflow_editer.service.impl;
import cn.hutool.core.util.StrUtil;
import com.tykj.workflowcore.api.service.SpringBeanService;
import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.base.util.FileUtil;
......@@ -15,10 +16,12 @@ import com.tykj.workflowcore.workflow_editer.service.VariableStorageService;
import com.tykj.workflowcore.workflow_editer.service.WorkFlowService;
import com.tykj.workflowcore.workflow_editer.util.UserServiceBeanUtil;
import io.swagger.annotations.Api;
import liquibase.pro.packaged.E;
import org.dom4j.*;
import org.dom4j.io.SAXReader;
import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.*;
import org.flowable.bpmn.model.Process;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.*;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
......@@ -56,7 +59,8 @@ import java.util.concurrent.ConcurrentHashMap;
@Service
public class WorkFlowServiceImpl implements WorkFlowService {
private static String XML_FILE_PATH = "\\xml\\";
private static String BASE_PATH = System.getProperty("user.dir");
private final RepositoryService repositoryService;
private final RuntimeService runtimeService;
private final TaskService taskService;
......@@ -117,58 +121,149 @@ public class WorkFlowServiceImpl implements WorkFlowService {
return realPath;
}
// @Override
// public void flowXml(@RequestBody FlowsInfoVo flowsInfoVo) throws XMLStreamException, IOException {
// String basePath = System.getProperty("user.dir") + "\\xml\\";
// Integer id = flowsInfoVo.getId();
// String flowKey = flowsInfoVo.getFlowKey();
// String fileXml = flowsInfoVo.getFileXml();
// //根据ID查询出一个flowsinfo
// if (id != null){
// FlowsInfo oldFlowInfo = flowsInfoMapper.findById(id).get();
// //得到老的fileXml
// String filePath = System.getProperty("user.dir")+oldFlowInfo.getFilePath();
// File oldFile = new File(filePath);
// File file = new File(filePath);
// if(!file.exists()){
// flowsInfoVo.setIsOld(1);
// }else {
// FileInputStream inputStream = new FileInputStream(file);
// int length = inputStream.available();
// byte bytes[] = new byte[length];
// inputStream.read(bytes);
// inputStream.close();
// String oldXml =new String(bytes, StandardCharsets.UTF_8);
// if (oldXml.equals(fileXml)){
// flowsInfoVo.setIsOld(0);
// }else {
// flowsInfoVo.setIsOld(1);
// }
// }
// }else {
// flowsInfoVo.setIsOld(1);
// }
// //end
//
// //生成xml文件
// File file = FileUtil.createFileByString(basePath + flowKey + "bpmn20.xml",
// flowsInfoVo.getFileXml().replaceAll("\\[\\?\\?[^\\]]+\\?\\?\\]", "").replaceAll("&lt;","<").replaceAll("&gt;",">"));
//
// FileUtil.createFileByString(basePath + flowKey + "bpmnCustom20.xml", flowsInfoVo.getFileXml());
//
// FlowsInfo flowsInfo = new FlowsInfo();
// BeanUtils.copyProperties(flowsInfoVo, flowsInfo);
// flowsInfo.setResourceName(flowKey + "bpmn20.xml");
// flowsInfo.setFilePath("\\xml\\" + flowKey + "bpmn20.xml");
// flowsInfo.setFileCustomPath("\\xml\\" + flowKey + "bpmnCustom20.xml");
// flowsInfo.setId(id);
// //进行第一部的校验
// InputStream inputStream = new FileInputStream(file);//实例化FileInputStream
// BpmnXMLConverter converter = new BpmnXMLConverter();
// XMLInputFactory factory = XMLInputFactory.newInstance();
// XMLStreamReader reader = factory.createXMLStreamReader(inputStream);//createXmlStreamReader
// //将xml文件转换成BpmnModel
// BpmnModel bpmnModel = converter.convertToBpmnModel(reader);
// //做校验
// ProcessValidator defaultProcessValidator = processValidatorFactoryExt.createDefaultProcessValidator();
// List<ValidationError> validate = defaultProcessValidator.validate(bpmnModel);
// StringBuffer message = new StringBuffer();
// if (validate.size()!=0){
// for (int i =0;i<validate.size();i++){
// ValidationError validationError = validate.get(i);
// String problem = validationError.getProblem();
// message.append(i+1+""+problem);
// message.append("\r\n");
// }
// throw new ApiException(null,message.toString());
// }
// //更新并保存
// flowsInfoMapper.save(flowsInfo);
//// else {
//// //自动部署
//// deployXml(save);
////
//// }
//
// }
@Override
public void flowXml(@RequestBody FlowsInfoVo flowsInfoVo) throws XMLStreamException, IOException {
String basePath = System.getProperty("user.dir") + "\\xml\\";
Integer id = flowsInfoVo.getId();
String flowKey = flowsInfoVo.getFlowKey();
String fileXml = flowsInfoVo.getFileXml();
//根据ID查询出一个flowsinfo
if (id != null){
FlowsInfo oldFlowInfo = flowsInfoMapper.findById(id).get();
//得到老的fileXml
String filePath = System.getProperty("user.dir")+oldFlowInfo.getFilePath();
File oldFile = new File(filePath);
File file = new File(filePath);
if(!file.exists()){
flowsInfoVo.setIsOld(1);
}else {
FileInputStream inputStream = new FileInputStream(file);
int length = inputStream.available();
byte bytes[] = new byte[length];
inputStream.read(bytes);
inputStream.close();
String oldXml =new String(bytes, StandardCharsets.UTF_8);
if (oldXml.equals(fileXml)){
flowsInfoVo.setIsOld(0);
}else {
flowsInfoVo.setIsOld(1);
String flowXmlResourceName = flowKey + "bpmn20.xml";
String CustomFlowXmlResourceName = flowKey + "bpmnCustom20.xml";
//从数据库里查处来
FlowsInfo flowsInfo = flowsInfoMapper.getOne(flowsInfoVo.getId());
if (StrUtil.isEmpty(flowsInfo.getFilePath())){
//生成xml文件
flowsInfo = flowsInfoVo.toEntity(flowsInfo);
flowsInfo.setResourceName(flowXmlResourceName);
flowsInfo.setFilePath(XML_FILE_PATH + flowXmlResourceName);
flowsInfo.setFileCustomPath(XML_FILE_PATH + CustomFlowXmlResourceName);
}
File file = FileUtil.createFileByString(BASE_PATH + XML_FILE_PATH + flowXmlResourceName,
flowsInfoVo.getFileXml().replaceAll("\\[\\?\\?[^\\]]+\\?\\?\\]", "").replaceAll("&lt;","<").replaceAll("&gt;",">"));
FileUtil.createFileByString(BASE_PATH + XML_FILE_PATH + CustomFlowXmlResourceName, flowsInfoVo.getFileXml());
//获取bmpnModel
BpmnModel bpmnModel = getBpmnModel(file);
//设置开始节点id
flowsInfo.setStartPageId(getStartPageId(bpmnModel));
//进行第一次的校验
checkXml(bpmnModel);
//自动部署
deployXml(flowsInfo.getId());
//更新并保存
flowsInfoMapper.save(flowsInfo);
}
/**
* 获取流程开始页面的ID
* @param bpmnModel
* @return
*/
public Integer getStartPageId(BpmnModel bpmnModel){
Process process = bpmnModel.getProcesses().get(0);
Collection<FlowElement> flowElements = process.getFlowElements();
for (FlowElement flowElement : flowElements) {
if (flowElement instanceof StartEvent){
String formKey = ((StartEvent) flowElement).getFormKey();
if (formKey == null){
throw new ApiException("开始节点表单不能为空");
}else {
flowsInfoVo.setIsOld(1);
return Integer.valueOf(formKey);
}
}
}
return -1;
}
//end
//生成xml文件
File file = FileUtil.createFileByString(basePath + flowKey + "bpmn20.xml",
flowsInfoVo.getFileXml().replaceAll("\\[\\?\\?[^\\]]+\\?\\?\\]", "").replaceAll("&lt;","<").replaceAll("&gt;",">"));
FileUtil.createFileByString(basePath + flowKey + "bpmnCustom20.xml", flowsInfoVo.getFileXml());
FlowsInfo flowsInfo = new FlowsInfo();
BeanUtils.copyProperties(flowsInfoVo, flowsInfo);
flowsInfo.setResourceName(flowKey + "bpmn20.xml");
flowsInfo.setFilePath("\\xml\\" + flowKey + "bpmn20.xml");
flowsInfo.setFileCustomPath("\\xml\\" + flowKey + "bpmnCustom20.xml");
flowsInfo.setId(id);
//进行第一部的校验
InputStream inputStream = new FileInputStream(file);//实例化FileInputStream
/**
* 获取bpmnModel
* @param xmlFile
* @return
* @throws FileNotFoundException
* @throws XMLStreamException
*/
public BpmnModel getBpmnModel(File xmlFile) throws FileNotFoundException, XMLStreamException {
InputStream inputStream = new FileInputStream(xmlFile);
BpmnXMLConverter converter = new BpmnXMLConverter();
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader reader = factory.createXMLStreamReader(inputStream);//createXmlStreamReader
//createXmlStreamReader
XMLStreamReader reader = factory.createXMLStreamReader(inputStream);
//将xml文件转换成BpmnModel
BpmnModel bpmnModel = converter.convertToBpmnModel(reader);
return converter.convertToBpmnModel(reader);
}
public void checkXml(BpmnModel bpmnModel){
//做校验
ProcessValidator defaultProcessValidator = processValidatorFactoryExt.createDefaultProcessValidator();
List<ValidationError> validate = defaultProcessValidator.validate(bpmnModel);
......@@ -182,14 +277,6 @@ public class WorkFlowServiceImpl implements WorkFlowService {
}
throw new ApiException(null,message.toString());
}
//更新并保存
flowsInfoMapper.save(flowsInfo);
// else {
// //自动部署
// deployXml(save);
//
// }
}
......@@ -209,14 +296,15 @@ public class WorkFlowServiceImpl implements WorkFlowService {
deploy = repositoryService.createDeployment().addInputStream(System.getProperty("user.dir") + flowsInfo.getResourceName(),
new FileInputStream(System.getProperty("user.dir") + flowsInfo.getFilePath())).deploy();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
throw new ApiException("流程图不符合规范");
}
//将流程自动挂起
repositoryService.suspendProcessDefinitionByKey(flowsInfo.getFlowKey(), true, new Date());
//修改状态
flowsInfo.setState(0);
flowsInfo.setState(1);
flowsInfo.setDeployId(deploy.getId());
flowsInfoMapper.save(flowsInfo);
}
@Override
......@@ -360,20 +448,12 @@ public class WorkFlowServiceImpl implements WorkFlowService {
repositoryService.suspendProcessDefinitionByKey(flowKey, true, new Date());
flowsInfo.setState(1);
} else {
if (flowsInfo.getIsOld() == 1){
deployXml(id);
//还原标志位
flowsInfo.setIsOld(0);
}else {
//激活
repositoryService.activateProcessDefinitionByKey(flowKey, true, new Date());
}
flowsInfo.setState(0);
}
} else {
deployXml(id);
flowsInfo.setState(0);
flowsInfo.setIsOld(0);
}
flowsInfoMapper.save(flowsInfo);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论