Skip to content

Commit

Permalink
修正流程轨迹高亮不显示问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
think-gem committed Jul 15, 2016
1 parent 0856a3a commit effffdd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.thinkgem.jeesite.modules.act.rest.diagram.services;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -24,11 +23,9 @@
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.impl.pvm.PvmTransition;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -40,7 +37,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.thinkgem.jeesite.common.mapper.JsonMapper;

@RestController
public class ProcessInstanceHighlightsResource {
Expand Down Expand Up @@ -69,28 +65,13 @@ public ObjectNode getHighlighted(@PathVariable String processInstanceId) {

try {
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
String processDefinitionId = null;
List<String> highLightedActivities = Collections.<String> emptyList();
List<HistoricActivityInstance> historicActivityInstances = null;
if (processInstance == null) {
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult();
processDefinitionId = historicProcessInstance.getProcessDefinitionId();
historicActivityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list();

System.out.println(JsonMapper.toJsonString(historicActivityInstances));

} else {
processDefinitionId = processInstance.getProcessDefinitionId();
highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
}

ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId);
ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) processDefinition;
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processInstance
.getProcessDefinitionId());

responseJSON.put("processDefinitionId", processDefinitionId);
responseJSON.put("processDefinitionId", processInstance.getProcessDefinitionId());

List<String> highLightedFlows = getHighLightedFlows(processDefinitionEntity, historicActivityInstances);//getHighLightedFlows(processDefinitionEntity, processInstanceId);
List<String> highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
List<String> highLightedFlows = getHighLightedFlows(processDefinition, processInstanceId);

for (String activityId : highLightedActivities) {
activitiesArray.add(activityId);
Expand All @@ -110,37 +91,6 @@ public ObjectNode getHighlighted(@PathVariable String processInstanceId) {
return responseJSON;
}

private List<String> getHighLightedFlows(ProcessDefinitionEntity processDefinitionEntity, List<HistoricActivityInstance> historicActivityInstances) {

List<String> highFlows = new ArrayList<String>();// 用 以保存高亮的线flowId
for (int i = 0; i < historicActivityInstances.size() - 1; i++) {// 对历史流程节点进行遍历
ActivityImpl activityImpl = processDefinitionEntity.findActivity(historicActivityInstances.get(i).getActivityId());// 得到节点定义的详细信息

List<ActivityImpl> sameStartTimeNodes = new ArrayList<ActivityImpl>(); // 用以保存后需开始时间相同的节点
ActivityImpl sameActivityImpl1 = processDefinitionEntity.findActivity(historicActivityInstances.get(i + 1).getActivityId()); // 将后面第一个节点放在时间相同节点的集合里
sameStartTimeNodes.add(sameActivityImpl1);
for (int j = i + 1; j < historicActivityInstances.size() - 1; j++) {
HistoricActivityInstance activityImpl1 = historicActivityInstances.get(j); // 后续第一个节点
HistoricActivityInstance activityImpl2 = historicActivityInstances.get(j + 1); // 后续第二个节点
if (activityImpl1.getStartTime().equals(activityImpl2.getStartTime())) { // 如果第一个节点和第二个节点开始时间相同保存
ActivityImpl sameActivityImpl2 = processDefinitionEntity.findActivity(activityImpl2.getActivityId());
sameStartTimeNodes.add(sameActivityImpl2);
} else {
break;
}
}
List<PvmTransition> pvmTransitions = activityImpl.getOutgoingTransitions();// 取出节点的所有出去的线
for (PvmTransition pvmTransition : pvmTransitions) { // 对所有的线进行遍历
ActivityImpl pvmActivityImpl = (ActivityImpl) pvmTransition.getDestination();// 如果取出的线的目标节点存在时间相同的节点里,保存该线的id,进行高亮显示
if (sameStartTimeNodes.contains(pvmActivityImpl)) {
highFlows.add(pvmTransition.getId());
}
}

}
return highFlows;
}

/**
* getHighLightedFlows
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public class ModelSaveRestResource implements ModelDataJsonConstants {
@Autowired
private RepositoryService repositoryService;

// @Autowired
// private ObjectMapper objectMapper;
// @Autowired
// private ObjectMapper objectMapper;
protected ObjectMapper objectMapper = new ObjectMapper();

@RequiresPermissions("act:model:edit")
Expand Down Expand Up @@ -85,7 +85,7 @@ public void saveModel(@PathVariable String modelId, @RequestBody MultiValueMap<S
final byte[] result = outStream.toByteArray();
repositoryService.addModelEditorSourceExtra(model.getId(), result);
outStream.close();
LOGGER.debug("Model Saved.");

} catch (Exception e) {
LOGGER.error("Error saving model", e);
throw new ActivitiException("Error saving model", e);
Expand Down

0 comments on commit effffdd

Please sign in to comment.