七 获取流程节点信息

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_38441551/article/details/88386994
@ApiOperation(value = "获取申请、报销联合节点")
  @GetMapping(path = "/def/nodes/union")
  public Response auditNodeList(@RequestParam String creator, @RequestParam String agyCode,
    @RequestParam Integer fiscal) {
    return Response.success().setData(workflowService.auditNodeList(creator, agyCode, fiscal));
  }
  public List<Map> auditNodeList(String creator, String agyCode, Integer fiscal);

@Override
  public List <Map> auditNodeList(String creator, String agyCode, Integer fiscal) {
    List <Map> result = new ArrayList <Map>();
    List <String> list = new ArrayList <String>();

    // 填充申请流程节点
    PexWfSetting applyWfSetting = wfSettingService.getWfSetting(agyCode, fiscal, PexConstants.BILL_FUNC_APPLY);
    // todo(liubo): 增加tenantId, category
    WfDefinition applyWfDefinition = wfDefinitionService.getNodeDefinition(PexConstants.PEX_SYS_ID,
            applyWfSetting.getWfId());
    List <Map> applyNodes = applyWfDefinition.getNodes().stream().map(node -> {
      Map ele = new HashMap();
      ele.put("wfId", node.getWfId());
      ele.put("exeNodeId", node.getNodeId());
      ele.put("title", node.getName());
      ele.put("billFunc", PexConstants.BILL_FUNC_APPLY);
      ele.put("NodeType", node.getNodeType());//NodeType: UserTask 任务节点 , Event 起止节点 All 全部节点
      ele.put("isStart", 0);
      ele.put("isEnd", 0);
      ele.put("isSecond", 0);
      return ele;
    }).collect(Collectors.toList());
    applyNodes.get(0).put("isStart", 1);
    list.add((String) applyNodes.get(0).get("wfId"));
    applyNodes.get(applyNodes.size() - 1).put("isEnd", 1);
    List<String> applySecondNode=wfRuntimeService.getSecondNode(applyNodes,PexConstants.PEX_SYS_ID,applyWfSetting.getWfId());
    for (Map map : applyNodes) {
    	if(applySecondNode.contains(map.get("exeNodeId"))){
    		map.put("isSecond", 1);
    	}
	}
    
    result.addAll(applyNodes);

    // 填充报销流程节点
    PexWfSetting expenseWfSetting = wfSettingService.getWfSetting(agyCode, fiscal, PexConstants.BILL_FUNC_EXPENSE);
    WfDefinition expenseWfDefinition = wfDefinitionService.getNodeDefinition(PexConstants.PEX_SYS_ID,
            expenseWfSetting.getWfId());
    List <Map> expenseNodes = expenseWfDefinition.getNodes().stream().map(node -> {
      Map ele = new HashMap();
      ele.put("wfId", node.getWfId());
      ele.put("exeNodeId", node.getNodeId());
      ele.put("title", node.getName());
      ele.put("billFunc", PexConstants.BILL_FUNC_EXPENSE);
      ele.put("NodeType", node.getNodeType());//NodeType: UserTask 任务节点 , Event 起止节点 All 全部节点
      ele.put("isStart", 0);
      ele.put("isEnd", 0);
      ele.put("isSecond", 0);
      return ele;
    }).collect(Collectors.toList());

    expenseNodes.get(0).put("isStart", 1);
    list.add((String) expenseNodes.get(0).get("wfId"));
    expenseNodes.get(expenseNodes.size() - 1).put("isEnd", 1);
    List<String> expenseSecondNode=wfRuntimeService.getSecondNode(expenseNodes,PexConstants.PEX_SYS_ID,expenseWfSetting.getWfId());
    for (Map map : expenseNodes) {
    	if(expenseSecondNode.contains(map.get("exeNodeId"))){
    		map.put("isSecond", 1);
    	}
	}
    result.addAll(expenseNodes);

    //填充借款流程节点
    PexWfSetting loanWfSetting = wfSettingService.getWfSetting(agyCode, fiscal, PexConstants.BILL_FUNC_LOAN);
    WfDefinition loanWfDefinition = wfDefinitionService.getNodeDefinition(PexConstants.PEX_SYS_ID,
            loanWfSetting.getWfId());
    List <Map> loanNodes = loanWfDefinition.getNodes().stream().map(node -> {
      Map ele = new HashMap();
      ele.put("wfId", node.getWfId());
      ele.put("exeNodeId", node.getNodeId());
      ele.put("title", node.getName());
      ele.put("billFunc", PexConstants.BILL_FUNC_LOAN);
      ele.put("NodeType", node.getNodeType());//NodeType: UserTask 任务节点 , Event 起止节点 All 全部节点
      ele.put("isStart", 0);
      ele.put("isEnd", 0);
      ele.put("isSecond", 0);
      return ele;
    }).collect(Collectors.toList());

    loanNodes.get(0).put("isStart", 1);
    list.add((String) loanNodes.get(0).get("wfId"));
    loanNodes.get(loanNodes.size() - 1).put("isEnd", 1);
    List<String> loanSecondNode=wfRuntimeService.getSecondNode(loanNodes,PexConstants.PEX_SYS_ID,loanWfSetting.getWfId());
    for (Map map : loanNodes) {
    	if(loanSecondNode.contains(map.get("exeNodeId"))){
    		map.put("isSecond", 1);
    	}
	}
    result.addAll(loanNodes);

    Map ele = new HashMap();
    ele.put("wfId", (String) applyNodes.get(0).get("wfId") + "," + (String) expenseNodes.get(0).get("wfId") + ","
            + (String) loanNodes.get(0).get("wfId"));
    ele.put("title", "历史单据");
    ele.put("NodeType", "All");//NodeType: UserTask 任务节点 , Event 起止节点  All 全部节点
    ele.put("billFunc", "");
    ele.put("isStart", 0);
    ele.put("isEnd", 2);
    ele.put("isSecond", 0);
    result.add(ele);

    // 填充节点待审核数据条数
    result.parallelStream().forEach(map -> {
      PexContentBillVo cond = new PexContentBillVo();
      cond.setCreator(creator);
      cond.setFiscal(fiscal);
      cond.setAgyCode(agyCode);
      cond.setExeNodeId((String) map.get("exeNodeId"));
      cond.setBillFunc((String) map.get("billFunc"));
      cond.setWfId((String) map.get("wfId"));
      switch ((int) map.get("isEnd")) {
        //指定节点的待审核数据
        case 0:
          map.put("count", commonInfoService.countToDoByNodeId(cond));
          break;
        //流程结束节点的审核数据
        case 1:
          map.put("count", commonInfoService.countDnoeByNodeId(cond));
          break;
        //流程审核的全部数据
        default:
          map.put("count", commonInfoService.countAllByNodeId(cond, list));
          break;
      }
    });
    return result;
  }
@Data
public class WfDefinition {
	private String key;
	private String name;
	private String category;
	private List<WfNodeInfo> nodes = new ArrayList<WfNodeInfo>();

	public void addNode(WfNodeInfo node) {
		nodes.add(node);
	}

	// 获取首节点
	public WfNodeInfo getFirstNode() {
		return nodes.get(0);
	}

	// 判断是否首节点
	public Integer isFirstNode(String nodeId) {
		boolean isFirst = getFirstNode().getNodeId().equals(nodeId);
		return isFirst ? 1 : 0;
	}
}

@Override
	//获取流程图中流程节点信息(流程图信息展示)
	public WfDefinition getNodeDefinition(String tenantId, String key) {
		List<WfNodeInfo> nodes =getAllDefinition(tenantId,key);
		nodes.remove(0);
		WfDefinition result = arrangeDefinition(tenantId, key);
		for (WfNodeInfo wfNodeInfo : nodes) {
			result.addNode(wfNodeInfo);
		}
		return result;
	}
// TODO(liubo): 在流程重新部署的时候,清除pex_cache, pty_workflow
	// @Cacheable(value = "pty_workflow", key = "'pty_workflow_definition_' + #key")
	// 获取包括任务节点,起止节点在内的流程图节点信息
	public List<WfNodeInfo> getAllDefinition(String tenantId,String key) {
		WfDefinition result = new WfDefinition();
		List<WfNodeInfo> nodes = new ArrayList<WfNodeInfo>();
		WfNodeInfo nodeEnd = new WfNodeInfo();
		result.setKey(key);
		RepositoryService repositoryService = activitiEngine.getRepositoryService();
		ProcessDefinition definition = repositoryService.createProcessDefinitionQuery()
				.processDefinitionTenantId(tenantId).processDefinitionKey(key)
				.latestVersion().singleResult();
		if (definition != null) {
			result.setName(definition.getName());
			Collection<FlowElement> list=repositoryService.getBpmnModel(definition.getId()).getMainProcess().getFlowElements();
			for (FlowElement flowElement : list) {
			     //假设是任务节点
			     if(flowElement instanceof UserTask ) {
			      if(flowElement != null) {
			    	  WfNodeInfo node = new WfNodeInfo();
						node.setNodeId(flowElement.getId());
						node.setName(flowElement.getName());
						node.setWfId(key);
						node.setNodeType("UserTask");
						nodes.add(node);
						result.addNode(node);
			      }
			     }
			    /* if(flowElement instanceof StartEvent || flowElement instanceof EndEvent){
			    	  if(flowElement != null) {
				    	  WfNodeInfo node = new WfNodeInfo();
							node.setNodeId(flowElement.getId());
							node.setName(flowElement.getName());
							node.setWfId(key);
							node.setNodeType("Event");
							nodes.add(0,node);
				      }  
			      }*/
			     if(flowElement instanceof StartEvent){
			    	  if(flowElement != null) {
				    	  WfNodeInfo node = new WfNodeInfo();
							node.setNodeId(flowElement.getId());
							node.setName(flowElement.getName());
							node.setWfId(key);
							node.setNodeType("Event");
							nodes.add(0,node);
							result.addNode(node);
				      }  
			      }
			     if(flowElement instanceof EndEvent){
			    	 if(flowElement != null) {
				    	  WfNodeInfo node = new WfNodeInfo();
							nodeEnd.setNodeId(flowElement.getId());
							nodeEnd.setName(flowElement.getName());
							nodeEnd.setWfId(key);
							nodeEnd.setNodeType("Event");
							//nodes.add(node);
							result.addNode(node);
				      }  
			     }
			    }
			nodes.add(nodeEnd);
		}
		return nodes;
	}
public WfDefinition arrangeDefinition(String tenantId, String key) {
		ProcessDefinition definition = activitiEngine.getRepositoryService().createProcessDefinitionQuery()
				.processDefinitionTenantId(tenantId).processDefinitionKey(key)
				.latestVersion().singleResult();
		WfDefinition result = new WfDefinition();
		if(definition != null){
			result.setName(definition.getName());
		}
		return result;
	}
@Override
	public List<String> getSecondNode(List<Map> applyNodes,String tenantId,String key) {
		List<String> secondNode=new ArrayList<String>();
		List<String> gatWaySecondNode=new ArrayList<String>();
		String gatWay=null;
		WfDefinition result = new WfDefinition();
		List<WfNodeInfo> nodes = new ArrayList<WfNodeInfo>();
		WfNodeInfo nodeEnd = new WfNodeInfo();
		result.setKey(key);
		RepositoryService repositoryService = activitiEngine.getRepositoryService();
		ProcessDefinition definition = repositoryService.createProcessDefinitionQuery()
				.processDefinitionTenantId(tenantId).processDefinitionKey(key)
				.latestVersion().singleResult();
		if (definition != null) {
			result.setName(definition.getName());
			Collection<FlowElement> list=repositoryService.getBpmnModel(definition.getId()).getMainProcess().getFlowElements();
			String targetRef=null;
			for (FlowElement flowElement : list) {
				String name=flowElement.getName();
				flowElement.getAttributes();
				
				if(flowElement instanceof StartEvent){
			    	  if(flowElement != null) {
				    	  WfNodeInfo node = new WfNodeInfo();
				    	  List<SequenceFlow> listFlow= ((StartEvent) flowElement).getOutgoingFlows();
				    	  for (SequenceFlow sequenceFlow : listFlow) {
				    		  //获取的流程第一个节点
				    		  targetRef= sequenceFlow.getTargetRef();
						}	
				      }  
			      }
				//获取第一个节点的信息
				if(flowElement instanceof UserTask){
					if(flowElement.getId().equals(targetRef)){
						//第一个节点的所有的出方向的线
						List<SequenceFlow> listFlow=((UserTask) flowElement).getOutgoingFlows();
						if(listFlow.size()==1){
							//第一个任务节点之后的节点信息(任务节点或者网管节点)
							secondNode.add(listFlow.get(0).getTargetRef());
						}
		    	  	}
				}
				//获取网管节点信息
				if(flowElement instanceof ExclusiveGateway|| flowElement instanceof ParallelGateway){
					//List<SequenceFlow> listFlow=	((UserTask) flowElement).getOutgoingFlows();
					 gatWay=flowElement.getId();
					 List<SequenceFlow> listFlow=	((Gateway) flowElement).getOutgoingFlows();
					 if(secondNode.size()!=0){
						 if(gatWay.equals(secondNode.get(0))){
							 for (SequenceFlow sequenceFlow : listFlow) {
								 gatWaySecondNode.add(sequenceFlow.getTargetRef());
							}
						 }
					 }
				}
			}
		}
		if(gatWaySecondNode.size()==0){
			return secondNode;
		}else{
			return gatWaySecondNode;
		}
		
	}
<select id="countToDoByNodeId" parameterType="com.pty.pex.vo.PexContentBillVo" resultType="java.lang.Integer">
        select
        COUNT(1)
        from pex_bill inner join
        <include refid="com.pty.workflow.dao.WfTaskDao.todo_node_sql"/>
        on pex_bill.bill_id=wf_task.busi_key
        WHERE 1=1
        <include refid="allColumnCond"/>
    </select>
<sql id="todo_node_sql">
		(
				SELECT
				  act_ru_execution.ACT_ID_ AS task_node_id,
				  act_ru_task.ID_ AS wf_task_id,
				  act_ru_task.IS_RETURN_ AS is_return,
				  act_hi_procinst.BUSINESS_KEY_ AS busi_key,
				  act_hi_procinst.PROC_INST_ID_ AS proc_inst_id,
				  act_hi_procinst.PROC_DEF_ID_ AS proc_def_id
				FROM
				  act_ru_task
				  INNER JOIN act_ru_execution ON act_ru_task.EXECUTION_ID_=act_ru_execution.ID_
				  INNER JOIN act_hi_procinst
				    ON act_hi_procinst.PROC_INST_ID_ = act_ru_task.PROC_INST_ID_
				    <if test="creator != null and creator != ''">
				    	AND act_hi_procinst.START_USER_ID_=#{creator}
				    </if>
				  INNER JOIN act_re_procdef
				    ON act_hi_procinst.PROC_DEF_ID_ = act_re_procdef.ID_
				    <if test="wfId != null and wfId !=''">
				    	AND act_re_procdef.KEY_ = #{wfId}
				    </if>
				WHERE 1=1
					<if test="exeNodeId != null and exeNodeId != ''">
						AND act_ru_execution.ACT_ID_=#{exeNodeId}
					</if>
		) wf_task
	</sql>
<select id="countDnoeByNodeId" parameterType="com.pty.pex.vo.PexContentBillVo" resultType="java.lang.Integer">
        select
        COUNT(1)
        from pex_bill inner join act_hi_procinst
        on pex_bill.bill_id=act_hi_procinst.business_key_
        AND act_hi_procinst.END_TIME_ is not null
        <if test="creator != null and creator != ''">
            AND act_hi_procinst.START_USER_ID_=#{creator}
        </if>
        INNER JOIN act_re_procdef
        ON act_hi_procinst.PROC_DEF_ID_ = act_re_procdef.ID_
        <if test="wfId != null and wfId !=''">
            AND act_re_procdef.KEY_ = #{wfId}
        </if>
        WHERE 1=1
        <include refid="allColumnCond"/>
    </select>
<select id="countAllByNodeId" parameterType="java.util.Map" resultType="java.lang.Integer">
        select
        COUNT(1)
        from pex_bill inner join act_hi_procinst
        on pex_bill.bill_id=act_hi_procinst.business_key_
        <if test="cond.creator != null and cond.creator != ''">
            AND act_hi_procinst.START_USER_ID_=#{cond.creator}
        </if>
        INNER JOIN act_re_procdef
        ON act_hi_procinst.PROC_DEF_ID_ = act_re_procdef.ID_
        AND act_re_procdef.KEY_ IN
        <foreach collection="list" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        WHERE 1=1
        and (bill_func ='apply' or bill_func = 'expense' or bill_func = 'loan')
        <if test="cond.createdTimeStart != null and cond.createdTimeStart != ''">
            AND created_time &gt;=#{cond.createdTimeStart,jdbcType=VARCHAR}
        </if>
        <if test="cond.createdTimeEnd != null and cond.createdTimeEnd != ''">
            AND created_time &lt;=#{cond.createdTimeEnd,jdbcType=VARCHAR}
        </if>
        <if test="cond.billNo != null and cond.billNo != ''">
            AND bill_no=#{cond.billNo,jdbcType=VARCHAR}
        </if>
        <if test="cond.agyCode != null and cond.agyCode != ''">
            AND agy_code=#{cond.agyCode,jdbcType=VARCHAR}
        </if>
        <if test="cond.fiscal != null">
            AND fiscal=#{cond.fiscal,jdbcType=INTEGER}
        </if>
        <if test="cond.billId != null and cond.billId != ''">
            AND bill_id=#{cond.billId,jdbcType=VARCHAR}
        </if>
        <if test="cond.creator != null and cond.creator != ''">
            AND creator=#{cond.creator,jdbcType=VARCHAR}
        </if>
        <if test="cond.billFunc != null and cond.billFunc != ''">
            AND bill_func=#{cond.billFunc,jdbcType=VARCHAR}
        </if>
        <if test="cond.billType != null and cond.billType != ''">
            AND bill_type=#{cond.billType,jdbcType=VARCHAR}
        </if>
    </select>
展开阅读全文

关于获取点击treeview的节点信息的问题

02-19

我在default.aspx中有一个treeview1,点击treeview1的节点时,会导航到该节点对应的页面,但是我获取不到这个节点的信息,比如我在SQL2005中的数据库是这样的rnrn在booktree表中rnid pid name urlrn 1 0 图书 rn 2 1 小说 ../book.aspxrn 3 .. .. ..rnrntreeview1的点击代码如下rn protected void treeview1_SelectedNodeChanged(object sender, EventArgs e)rn rn string strSelect = treeview1.SelectedNode.Value.ToString();rn Session["selected"] = strSelect.ToString(); rn rnrn当我点击treeview的节点"小说"时就自动导航到book.aspx,但是获取不到该节点的值,也就是说上面的事件并没有发生,为了验证这个说法,我在另外一个页面test.aspx中添加了获取Session["selected"]的代码,运行程序之后,我先点击了父节点"图书",然后手动转到test.aspx,是可以获取到Session["selected"]的。rnrn我创建treeview的代码如下:rn public void AddTree(int ParentID, TreeNode pNode)rn rn DataSet ds = (DataSet)this.ViewState["ds"];rn DataView dvTree = new DataView(ds.Tables[0]);rnrn //过滤ParentID,得到当前的所有子节点 rn treeview1.RowFilter = "pid = " + ParentID;rnrn foreach (DataRowView Row in dvTree)rn rn TreeNode Node = new TreeNode();rn if (pNode == null)rn //添加根节点 rn Node.Text = Row["name"].ToString();rn [color=#FF0000]Node.NavigateUrl = Row["url"].ToString();[/color]rn treeview1.Nodes.Add(Node);rn Node.Expanded = true; //获取或设置一个值,该值指示是否展开节点。rn AddTree(Int32.Parse(Row["id"].ToString()), Node); //再次递归 rn rn elsern //添加当前节点的子节点 rn Node.Text = Row["name"].ToString();rn [color=#FF0000]Node.NavigateUrl = Row["url"].ToString();[/color]rn pNode.ChildNodes.Add(Node);rn Node.Expanded = true; //获取或设置一个值,该值指示是否展开节点。rn AddTree(Int32.Parse(Row["id"].ToString()), Node); //再次递归 rn rn rn rnrn请问我应该怎么做才能在自动导航到的页面中获取Session["selected"]的值? 论坛

没有更多推荐了,返回首页