Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Activiti:获取当前Task在流程图的坐标
/**
* 读取资源
*
* @return
*/
public String loadResource() {
try {
InputStream resourceAsStream = null;
if (StringUtils.isNotBlank(processInstanceId)) {
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
ProcessDefinition singleResult = repositoryService.createProcessDefinitionQuery()
.processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
String resourceName = "";
if (resourceType.equals("image")) {
resourceName = singleResult.getDiagramResourceName();
} else if (resourceType.equals("xml")) {
resourceName = singleResult.getResourceName();
}
resourceAsStream = repositoryService.getResourceAsStream(singleResult.getDeploymentId(), resourceName);
} else {
resourceAsStream = repositoryService.getResourceAsStream(deploymentId, resourceName);
}
byte[] b = new byte[1024];
int len = -1;
while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
Struts2Utils.getResponse().getOutputStream().write(b, 0, len);
}
} catch (Exception e) {
logger.error("读取资源出错:", e);
}
return null;
}
/**
* 流程跟踪图
* @return
*/
public String traceProcess() {
try {
Execution execution = runtimeService.createExecutionQuery().executionId(processInstanceId).singleResult();//执行实例
Object property = PropertyUtils.getProperty(execution, "activityId");
String activityId = "";
if (property != null) {
activityId = property.toString();
}
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
.getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
List<ActivityImpl> activitiList = processDefinition.getActivities();//获得当前任务的所有节点
ActivityImpl activity = null;
for (ActivityImpl activityImpl : activitiList) {
String id = activityImpl.getId();
if (id.equals(activityId)) {//获得执行到那个节点
activity = activityImpl;
break;
}
}
Map<String, Object> activityImageInfo = new HashMap<String, Object>();
activityImageInfo.put("x", activity.getX());
activityImageInfo.put("y", activity.getY());
activityImageInfo.put("width", activity.getWidth());
activityImageInfo.put("height", activity.getHeight());
Struts2Utils.renderJson(activityImageInfo);
} catch (Exception e) {
logger.error("查看流程跟踪图出错:");
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.