wang1
2023-06-25 4cecf59f39ce9b2066c2d328566f1180f8af7be2
Source/UBCS/ubcs-ops/ubcs-flow/src/main/java/com/vci/ubcs/flow/business/service/impl/FlowBusinessServiceImpl.java
@@ -25,13 +25,19 @@
import com.vci.ubcs.flow.engine.entity.FlowProcess;
import com.vci.ubcs.flow.engine.utils.FlowCache;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.history.HistoricProcessInstanceQuery;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
@@ -54,6 +60,7 @@
   private final TaskService taskService;
   private final HistoryService historyService;
   private final RuntimeService runtimeService;
   @Override
   public IPage<BladeFlow> selectClaimPage(IPage<BladeFlow> page, BladeFlow bladeFlow) {
@@ -117,7 +124,7 @@
      HistoricProcessInstanceQuery historyQuery = historyService.createHistoricProcessInstanceQuery().startedBy(taskUser).orderByProcessInstanceStartTime().desc();
      if (bladeFlow.getCategory() != null) {
      if (StringUtils.isNotEmpty(bladeFlow.getCategory())) {
         historyQuery.processDefinitionCategory(bladeFlow.getCategory());
      }
      if (bladeFlow.getProcessDefinitionName() != null) {
@@ -142,7 +149,7 @@
         String[] businessKey = Func.toStrArray(StringPool.COLON, historicProcessInstance.getBusinessKey());
         if (businessKey.length > 1) {
            flow.setBusinessTable(businessKey[0]);
            flow.setBusinessId(businessKey[1]);
            flow.setBusinessId(businessKey.length>1?businessKey[1]:"1");
         }
         flow.setHistoryActivityName(historicProcessInstance.getName());
         flow.setProcessInstanceId(historicProcessInstance.getId());
@@ -190,7 +197,7 @@
      HistoricTaskInstanceQuery doneQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(taskUser).finished()
         .includeProcessVariables().orderByHistoricTaskInstanceEndTime().desc();
      if (bladeFlow.getCategory() != null) {
      if (StringUtils.isNotEmpty(bladeFlow.getCategory())) {
         doneQuery.processCategoryIn(Func.toStrList(bladeFlow.getCategory()));
      }
      if (bladeFlow.getProcessDefinitionName() != null) {
@@ -230,7 +237,7 @@
         if (Func.isNotEmpty(historicProcessInstance)) {
            String[] businessKey = Func.toStrArray(StringPool.COLON, historicProcessInstance.getBusinessKey());
            flow.setBusinessTable(businessKey[0]);
            flow.setBusinessId(businessKey[1]);
            flow.setBusinessId(businessKey.length>1?businessKey[1]:"1");
            if (historicProcessInstance.getEndActivityId() != null) {
               flow.setProcessIsFinished(FlowEngineConstant.STATUS_FINISHED);
            } else {
@@ -263,8 +270,22 @@
         variables = Kv.create();
      }
      variables.put(ProcessConstant.PASS_KEY, flow.isPass());
      // 完成任务
      taskService.complete(taskId, variables);
//      //设置下一步审核人
//      Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).active().singleResult();//下一步节点
//      String taskKey = task.getTaskDefinitionKey();//就是流程配置的节点id
//      Object to = getVar(processInstanceId,taskKey);
//      if(to==null){
//         throw new ServiceException(taskKey+"没有设置审核人");
//      }
//      String assignee = to.toString();
//
//      if(StringUtils.isNotEmpty(assignee)) {
//         task.setAssignee(assignee);
//      }
      return true;
   }
@@ -277,7 +298,8 @@
    * @param status    状态
    */
   private void buildFlowTaskList(BladeFlow bladeFlow, List<BladeFlow> flowList, TaskQuery taskQuery, String status) {
      if (bladeFlow.getCategory() != null) {
//      if (bladeFlow.getCategory() != null) {
      if (StringUtils.isNotEmpty(bladeFlow.getCategory())) {
         taskQuery.processCategoryIn(Func.toStrList(bladeFlow.getCategory()));
      }
      if (bladeFlow.getProcessDefinitionName() != null) {
@@ -304,7 +326,7 @@
         if (Func.isNotEmpty(historicProcessInstance)) {
            String[] businessKey = Func.toStrArray(StringPool.COLON, historicProcessInstance.getBusinessKey());
            flow.setBusinessTable(businessKey[0]);
            flow.setBusinessId(businessKey[1]);
            flow.setBusinessId(businessKey.length>1?businessKey[1]:"1");
         }
         FlowProcess processDefinition = FlowCache.getProcessDefinition(task.getProcessDefinitionId());
@@ -330,4 +352,16 @@
      return historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
   }
   public Object getVar(String processInstanceId,String key){
      Object t = null;
      List<Execution> list = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).list();
      for (Execution execution : list) {
         Object va = runtimeService.getVariable(execution.getId(),key);
         if(va!=null){
            t=va;
         }
      }
      return t;
   }
}