Activiti 流程圖上標記當前任務

tiantangqiu發表於2014-09-11
[img]http://dl2.iteye.com/upload/attachment/0101/0349/cd728153-435b-3215-826e-266a0f57aeb9.png[/img]



public byte[] getCurrTaskTrackImage(String deoployId,String processInstanceId) {
byte[] imageByte = null;
ByteArrayOutputStream out = null;
try{
ProcessDefinition processDefinition = null;
if(deoployId != null) {
processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deoployId).singleResult();
}else{
HistoricProcessInstance processInstance = findProcessInstanceHisById(processInstanceId);
processDefinition = ((RepositoryServiceImpl)repositoryService).getProcessDefinition(processInstance.getProcessDefinitionId());
}
String diagramResourceName = processDefinition.getDiagramResourceName();
InputStream imageStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName);
BufferedImage image = ImageIO.read(imageStream);
List<Task> list = taskService.createTaskQuery().processInstanceId(processInstanceId).list();
Task currTask = list.get(0);
String taskId = currTask.getId();
Graphics g = image.getGraphics();
g.setColor(Color.red);
ActivityImpl currActivity = findCurrActivityGraph(taskId);
int x = currActivity.getX(),
y = currActivity.getY(),
weight = currActivity.getWidth(),
height = currActivity.getHeight();
g.drawRect(x-1, y-1, weight, height);
g.dispose();
//
ImageIO.write(image, "PNG", new File("C:/1.png"));
out = new ByteArrayOutputStream();
ImageIO.write(image, "PNG", out);
imageByte = out.toByteArray();

}catch(Exception e) {
e.printStackTrace();
}finally{
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return imageByte;
}


public ActivityImpl findCurrActivityGraph(String taskId) {
HistoricTaskInstance currTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
String currActivitiId = currTask.getTaskDefinitionKey();
ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl)repositoryService).
getDeployedProcessDefinition(currTask.getProcessDefinitionId());
ActivityImpl activityImpl = def.findActivity(currActivitiId);
return activityImpl;
}

private HistoricProcessInstance findProcessInstanceHisById(String processInstanceId) throws Exception {
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
if(historicProcessInstance == null) {
throw new Exception("流程歷史例項未找到!");
}
return historicProcessInstance;
}

相關文章