提交 f1233299 编写于 作者: sq3536's avatar sq3536

工作流部署

上级 eabffe5e
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.workflow.domain.WFProcessDefinition;
import cn.ibizlab.core.workflow.domain.WFProcessInstance;
import cn.ibizlab.core.workflow.domain.WFProcessNode;
import cn.ibizlab.core.workflow.domain.WFTaskWay;
import cn.ibizlab.core.workflow.domain.*;
import cn.ibizlab.core.workflow.service.IWFGroupService;
import cn.ibizlab.core.workflow.service.IWFProcessDefinitionService;
import cn.ibizlab.util.domain.EntityBase;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.security.AuthenticationUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.SequenceFlow;
import org.flowable.bpmn.model.UserTask;
import lombok.extern.slf4j.Slf4j;
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.HistoryService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.DeploymentBuilder;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Timestamp;
import java.util.*;
@Service
@Slf4j
public class WFCoreService
{
......@@ -45,6 +54,12 @@ public class WFCoreService
@Autowired
private WFModelService wfModelService;
@Autowired
private IWFGroupService iwfGroupService;
@Autowired
private IWFProcessDefinitionService iwfProcessDefinitionService;
public List<WFProcessDefinition> getWorkflow(String system,String appname,String entity) {
return wfModelService.getWorkflow(system,entity);
......@@ -271,6 +286,115 @@ public class WFCoreService
return instance;
}
public synchronized boolean wfdeploy(File bpmnFile)
{
XMLStreamReader reader = null;
InputStream inputStream = null;
try {
BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
XMLInputFactory factory = XMLInputFactory.newInstance();
inputStream=new FileInputStream(bpmnFile);
reader = factory.createXMLStreamReader(inputStream);
BpmnModel model = bpmnXMLConverter.convertToBpmnModel(reader);
List<Process> processes = model.getProcesses();
Process curProcess = null;
if (CollectionUtils.isEmpty(processes)) {
return false;
}
curProcess = processes.get(0);
String bookings="";
String refgroups="";
if(!curProcess.getExtensionElements().containsKey("field"))
{
log.error(bpmnFile.getName()+"没有实体订阅");
return false;
}
for(ExtensionElement field:curProcess.getExtensionElements().get("field"))
{
if("bookings".equals(field.getAttributes().get("name").get(0).getValue()))
bookings=field.getChildElements().get("string").get(0).getElementText();
if("refgroups".equals(field.getAttributes().get("name").get(0).getValue()))
refgroups=field.getChildElements().get("string").get(0).getElementText();
}
if(StringUtils.isEmpty(bookings))
{
log.error(bpmnFile.getName()+"没有实体订阅");
return false;
}
if(!StringUtils.isEmpty(refgroups))
{
List<WFGroup> listGroup=new ArrayList<>();
for(String refgroup:refgroups.split(","))
{
String[] groupParam=refgroup.split("[\\|]");
if(groupParam.length==3)
{
WFGroup wfGroup=new WFGroup();
wfGroup.setId(groupParam[0]);
wfGroup.setName(groupParam[1]);
wfGroup.setGroupscope(groupParam[2]);
listGroup.add(wfGroup);
}
}
if(listGroup.size()>0)
iwfGroupService.saveBatch(listGroup);
}
String[] params=curProcess.getId().split("-");
if(params.length!=2)
{
log.error(bpmnFile.getName()+"没有系统名称");
return false;
}
String system=params[0];
Integer version= Integer.parseInt(params[1].substring(params[1].lastIndexOf("v")+1));
inputStream=new FileInputStream(bpmnFile);
String md5= DigestUtils.md5DigestAsHex(inputStream);
for(String booking:bookings.split(","))
{
String processDefinitionKey=system+"-"+booking+"-"+params[1];
WFProcessDefinition old=iwfProcessDefinitionService.get(processDefinitionKey);
if(md5.equals(old.getMd5check()))
continue;
WFProcessDefinition wfProcessDefinition=new WFProcessDefinition();
wfProcessDefinition.setDefinitionkey(processDefinitionKey);
wfProcessDefinition.setDeploykey(processDefinitionKey);
wfProcessDefinition.setPssystemid(system);
wfProcessDefinition.setModelenable(1);
wfProcessDefinition.setModelversion(version);
wfProcessDefinition.setDefinitionname(curProcess.getName());
wfProcessDefinition.setBpmnfile("[{\"id\":\""+md5+"\",\"name\":\""+bpmnFile.getName()+"\"}]");
wfProcessDefinition.setMd5check(md5);
iwfProcessDefinitionService.save(wfProcessDefinition);
inputStream=new FileInputStream(bpmnFile);
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().name(curProcess.getName()).key(processDefinitionKey)
.addInputStream(bpmnFile.getPath(),inputStream);
Deployment deployment= deploymentBuilder.deploy();
// wfProcessDefinition.setMd5check(md5);
// iwfProcessDefinitionService.update(wfProcessDefinition);
log.warn("部署流程 name:"+curProcess.getName()+" key "+deployment.getKey() + " deploy "+deployment);
}
return true;
}
catch (Exception e){
log.error(bpmnFile.getName()+"BPMN模型创建流程异常",e);
return false;
}
finally {
try {
reader.close();
} catch (Exception e) {
log.error(bpmnFile.getName()+"关闭异常",e);
}
}
}
public void execute(DelegateExecution delegateExecution,Object activedata) throws Exception {
String entity = (String)delegateExecution.getVariable("pass");
......
package cn.ibizlab.core.extensions.service.impl;
import cn.ibizlab.core.extensions.service.WFCoreService;
import cn.ibizlab.core.workflow.domain.WFProcessDefinition;
import cn.ibizlab.core.workflow.service.impl.WFProcessDefinitionServiceImpl;
import cn.ibizlab.util.domain.FileItem;
import cn.ibizlab.util.service.FileService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.io.File;
import java.util.List;
@Service
@Primary
public class WFProcessDefinitionServicePublishImpl extends WFProcessDefinitionServiceImpl
{
@Override
public boolean create(WFProcessDefinition et)
{
if(!super.create(et))
return false;
publish(et);
return true;
}
@Override
public boolean update(WFProcessDefinition et)
{
if(!super.update(et))
return false;
publish(et);
return true;
}
@Autowired
private FileService fileService;
@Autowired
@Lazy
private WFCoreService wfCoreService;
public void publish(WFProcessDefinition et)
{
if(StringUtils.isEmpty(et.getBpmnfile()))
return;
String oldMd5="";
if(!StringUtils.isEmpty(et.getMd5check()))
oldMd5=et.getMd5check();
List<FileItem> items= JSONArray.parseArray(et.getBpmnfile(),FileItem.class);
if(items.size()==0)
return;
FileItem item=items.get(items.size()-1);
if(item.getId().equals(oldMd5))
return;
File bpmnFile=fileService.getFile(item.getId());
if(!bpmnFile.exists())
return;
wfCoreService.wfdeploy(bpmnFile);
}
}
......@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -76,5 +77,19 @@ public class WFCoreResource
}
@ApiOperation(value = "getBusinessKeys", tags = {"String" }, notes = "根据流程步骤查询我的待办主键清单")
@RequestMapping(method = RequestMethod.GET, value = "/{system}-app-{appname}/{entity}/process-definitions/{taskDefinitionKey}/usertasks/{taskDefinitionKey}/tasks")
public ResponseEntity<List<String>> getbusinesskeys(@PathVariable("system") String system,@PathVariable("appname") String appname,
@PathVariable("entity") String entity,@PathVariable("taskDefinitionKey") String processDefinitionKey,@PathVariable("taskDefinitionKey") String taskDefinitionKey) {
if(StringUtils.isEmpty(appname)||"null".equals(appname)||"alls".equals(appname))
appname="";
if(StringUtils.isEmpty(processDefinitionKey)||"null".equals(processDefinitionKey)||"alls".equals(processDefinitionKey))
processDefinitionKey="";
if(StringUtils.isEmpty(taskDefinitionKey)||"null".equals(taskDefinitionKey)||"alls".equals(taskDefinitionKey))
taskDefinitionKey="";
return ResponseEntity.status(HttpStatus.OK).body(wfCoreService.getBusinessKeys(system,appname,entity,processDefinitionKey,taskDefinitionKey));
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册