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

工作流编程

上级 77e28278
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.workflow.domain.WFProcessDefinition;
import cn.ibizlab.core.workflow.domain.WFProcessNode;
import cn.ibizlab.core.workflow.service.IWFProcessDefinitionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.activiti.bpmn.model.FlowElement;
import org.activiti.bpmn.model.UserTask;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import java.util.*;
public class WFModelService
{
@Autowired
private RepositoryService repositoryService;
@Autowired
private IWFProcessDefinitionService iwfProcessDefinitionService;
public List<WFProcessDefinition> getWorkflow(String system,String entity) {
return iwfProcessDefinitionService.list(new QueryWrapper<WFProcessDefinition>().
likeRight("definitionkey",system+"-"+entity+"-").eq("modelenable",1).orderByDesc("modelversion"));
}
public LinkedHashMap<String,UserTask> getModelStepByKey(String definitionkey)
{
LinkedHashMap<String, UserTask> allTask=new LinkedHashMap<String,UserTask>();
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().processDefinitionKey(definitionkey).orderByProcessDefinitionVersion().desc().list();
boolean blastest=true;
for (ProcessDefinition def : list) {
LinkedHashMap<String, UserTask> userTasks=getModelStepById(def.getId());
if(blastest){
allTask.putAll(userTasks);
blastest=false;
}
else {
for(String key:userTasks.keySet()) {
if(!allTask.containsKey(key)) {
String taskName = userTasks.get(key).getName() + "-历史版本v" +def.getVersion();
userTasks.get(key).setName(taskName);
allTask.put(key, userTasks.get(key));
}
}
}
}
return allTask;
}
public LinkedHashMap<String,UserTask> getModelStepById(String definitionid)
{
LinkedHashMap<String, UserTask> userTasks = new LinkedHashMap<String, UserTask>();
Map<String,UserTask> map=new HashMap<>();
for(FlowElement f:repositoryService.getBpmnModel(definitionid).getMainProcess().getFlowElements()) {
if(f instanceof UserTask) {
map.put(f.getId(),(UserTask)f);
}
}
List<Map.Entry<String, UserTask>> infoIds =new ArrayList<Map.Entry<String, UserTask>>(map.entrySet());
Collections.sort(infoIds, new Comparator<Map.Entry<String, UserTask>>() {
public int compare(Map.Entry<String, UserTask> o1, Map.Entry<String, UserTask> o2) {
String p1 = o1.getKey();
String p2 = o2.getKey();
return p1.compareTo(p2);
}
});
for(Map.Entry<String,UserTask> entity : infoIds){
userTasks.put(entity.getKey(), entity.getValue());
System.out.println(entity.getKey());
}
return userTasks;
}
}
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.workflow.domain.*;
import cn.ibizlab.core.extensions.service.WFCoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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.web.bind.annotation.*;
import java.util.List;
@Slf4j
@Api(tags = {"wfcore" })
@RestController("api-wfcore")
@RequestMapping("")
public class WFCoreResource
{
@Autowired
private WFCoreService wfCoreService;
@ApiOperation(value = "getWFProcessDefinition", tags = {"WFProcessDefinition" }, notes = "根据系统实体查找当前适配的工作流模型")
@RequestMapping(method = RequestMethod.GET, value = "/wfcore/{system}-app-{appname}/{entity}/process-definitions")
public ResponseEntity<List<WFProcessDefinition>> getworkflow(@PathVariable("system") String system,@PathVariable("appname") String appname,
@PathVariable("entity") String entity) {
return ResponseEntity.status(HttpStatus.OK).body(null);
}
@ApiOperation(value = "getStepByEntity", tags = {"WFProcessNode" }, notes = "根据系统实体查找当前适配的工作流模型步骤")
@RequestMapping(method = RequestMethod.GET, value = "/wfcore/{system}-app-{appname}/{entity}/process-definitions-nodes")
public ResponseEntity<List<WFProcessNode>> getwfstep(@PathVariable("system") String system,@PathVariable("appname") String appname,
@PathVariable("entity") String entity) {
return ResponseEntity.status(HttpStatus.OK).body(null);
}
@PreAuthorize("hasPermission(#entity,'WFSTART',this.getEntity())")
@ApiOperation(value = "wfstart", tags = {"WFProcessInstance" }, notes = "启动工作流")
@RequestMapping(method = RequestMethod.POST, value = "/wfcore/{system}-app-{appname}/{entity}/{businessKey}/process-instances")
public ResponseEntity<WFProcessInstance> wfstart(@PathVariable("system") String system,@PathVariable("appname") String appname,
@PathVariable("entity") String entity,
@PathVariable("businessKey") String businessKey,@RequestBody WFProcessInstance instance) {
instance.setBusinesskey(businessKey);
return ResponseEntity.ok(instance);
}
@ApiOperation(value = "getWayByBusinessKey", tags = {"WFTaskWay" }, notes = "根据业务主键和当前步骤获取操作路径")
@RequestMapping(method = RequestMethod.GET, value = "/wfcore/{system}-app-{appname}/{entity}/{businessKey}/usertasks/{taskDefinitionKey}/ways")
public ResponseEntity<List<WFTaskWay>> getwflink(@PathVariable("system") String system,@PathVariable("appname") String appname,
@PathVariable("entity") String entity,
@PathVariable("businessKey") String businessKey,@PathVariable("taskDefinitionKey") String taskDefinitionKey) {
return ResponseEntity.status(HttpStatus.OK).body(null);
}
@ApiOperation(value = "getWayByTaskId", tags = {"WFTaskWay" }, notes = "根据业务主键和当前步骤获取操作路径")
@RequestMapping(method = RequestMethod.GET, value = "/wfcore/{system}-app-{appname}/{entity}/{businessKey}/tasks/{taskId}/ways")
public ResponseEntity<List<WFTaskWay>> gettasklink(@PathVariable("system") String system,@PathVariable("appname") String appname,
@PathVariable("entity") String entity,
@PathVariable("businessKey") String businessKey,@PathVariable("taskId") String taskId) {
return ResponseEntity.status(HttpStatus.OK).body(null);
}
@PreAuthorize("hasPermission(#entity,'WFSTART',this.getEntity())")
@ApiOperation(value = "wfsubmit", tags = {"WFProcessInstance" }, notes = "工作流执行步骤")
@RequestMapping(method = RequestMethod.POST, value = "/wfcore/{system}-app-{appname}/{entity}/{businessKey}/tasks/{taskId}")
public ResponseEntity<WFProcessInstance> wfsubmit(@PathVariable("system") String system,@PathVariable("appname") String appname,
@PathVariable("entity") String entity,
@PathVariable("businessKey") String businessKey,@PathVariable("taskId") String taskId,
@RequestBody WFTaskWay taskWay) {
WFProcessInstance instance = new WFProcessInstance();
return ResponseEntity.ok(instance);
}
}
......@@ -54,5 +54,19 @@
<artifactId>problem-spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-json-converter</artifactId>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-image-generator</artifactId>
</dependency>
</dependencies>
</project>
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册