package com.tenwa.flow.action.comm; import java.util.HashMap; import java.util.List; import java.util.Map; import apx.com.amarsoft.als.base.flow.FlowTask; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.amarsoft.app.flow.FlowAction; import com.amarsoft.awe.util.ASResultSet; import com.amarsoft.awe.util.SqlObject; import com.amarsoft.awe.util.Transaction; import jbo.com.tenwa.entity.comm.flow.FLOW_BUSSINESS_OBJECT; import jbo.com.tenwa.entity.comm.flow.FLOW_WORK_FLAG; import jbo.sys.FLOW_OBJECT; import jbo.sys.FLOW_TASK; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOException; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.tenwa.comm.util.jboutil.DataOperatorUtil; public class BaseFlowStartAction extends FlowBussionAction { private String error_message = "failed@发起流程出错"; public String getError_message() { return error_message; } public void setError_message(String error_message) { this.error_message = error_message; } //补充一个需要提交步骤的参数 private String submitTask; private String operator; public String getSubmitTask() { return submitTask; } public void setSubmitTask(String submitTask) { this.submitTask = submitTask; } public String getOperator() { return operator; } public void setOperator(String operator) { this.operator = operator; } @Override public String initFLow(JBOTransaction tx) throws Exception { try { return this.startFlow( tx, createBusinessObject( tx ) ); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); tx.rollback(); return error_message; } } public String createBusinessObject ( JBOTransaction tx ) throws Exception { //初始化当前用户信息 String flowunid = ""; //生成业务流程数据并返回流程的编号 MapdeleteCondition = new HashMap(); BizObject flowBussiness = this.initFLowBusinonObject(tx); this.customOperation( tx,flowBussiness ); flowunid = flowBussiness.getAttribute( "flow_unid" ).toString(); if( this.getFlowMutexConfig().size() > 0 ){ String checkResult = this.flowMutexCheck( tx ); if( checkResult.length() > 0 ) { deleteCondition.put( "flow_unid",flowunid ); DataOperatorUtil.deleteJBOByCondtion( FLOW_BUSSINESS_OBJECT.CLASS_NAME, deleteCondition, tx ); return "failed@" + checkResult; } this.flowMutexInfoInit( tx ); } this.updateFLowBusinonObject( tx ); this.executeFlowStartScript( tx, flowBussiness ); return flowunid; } //接口调用发起流程方法 @Override public String interfaceInitFlow ( JBOTransaction tx ) throws Exception { String sReturn = ""; try { String flowunid = createBusinessObject( tx ); String sResult = this.startFlow( tx, flowunid ); if ( sResult.indexOf( "success" ) != -1 ) { //开始根据参数提交指定步骤 String submitTask = this.getSubmitTask(); if ( submitTask != null && !"".equals( submitTask ) ) { //执行需要提交的步骤 FlowAction flowAction = new FlowAction(); BizObject flowTask = JBOFactory.getBizObjectManager( "jbo.sys.FLOW_TASK", tx ) .createQuery( " objectno = :FlowUnid" ) .setParameter( "FlowUnid", flowunid ) .getSingleResult( false ); //设置当前处理人 flowAction.setTaskNo( flowTask.getAttribute("SERIALNO").toString() ); flowAction.setUserID( this.getOperator() ); flowAction.setFlowNo( this.getFlowNo() ); flowAction.setUserID( this.CurUserID ); flowAction.setNextNodeType( "TASK" ); if ( !"1000".equals( submitTask ) ) { //获取提交步骤的处理人信息 ASResultSet rs = null; Transaction tran = Transaction.createTransaction( tx ); try { rs = tran.getASResultSet( new SqlObject( "select actionscript from flow_model where phaseno = '" + submitTask + "' and flowno = '" + this.getFlowNo() + "'" ) ); if( rs.next() ) { String actionScript = rs.getString( "actionscript" ); flowAction.setPhaseOpinion( submitTask ); JSONArray ja = JSONArray.parseArray( actionScript ); JSONObject obj = ja.getJSONObject( 0 ); flowAction.setPhaseAction( obj.getString( "userinfo" ).replaceAll( ",", " " ) ); } else { throw new Exception( "未找到流程信息" ); } } catch(Exception e) { e.printStackTrace(); throw new Exception("获取流程设计失败"); } finally { if(rs != null) rs.close(); } } else { flowAction.setPhaseOpinion( submitTask ); flowAction.setPhaseAction( "AutoFinish" ); } flowAction.submit( tx ); } sReturn = "success@" + flowunid; } } catch (Exception e) { e.printStackTrace(); tx.rollback(); sReturn = error_message; } return sReturn; } private String submitFlowunid; private String submitFlowNo; private String submitUserId; public String getSubmitFlowunid() { return submitFlowunid; } public void setSubmitFlowunid(String submitFlowunid) { this.submitFlowunid = submitFlowunid; } public String getSubmitFlowNo() { return submitFlowNo; } public void setSubmitFlowNo(String submitFlowNo) { this.submitFlowNo = submitFlowNo; } public String getSubmitUserId() { return submitUserId; } public void setSubmitUserId(String submitUserId) { this.submitUserId = submitUserId; } //接口平台提交流程方法 public String submitFlow(){ JBOTransaction tx = null; try { //开始根据参数提交指定步骤 String submitTask = this.getSubmitTask(); tx = JBOFactory.createJBOTransaction(); Transaction tran = Transaction.createTransaction(tx); String taskNo = tran.getString("SELECT SERIALNO FROM FLOW_TASK WHERE objectno='"+submitFlowunid+"' and flowno='"+submitFlowNo+"' ORDER BY begintime DESC LIMIT 1"); //执行需要提交的步骤 FlowAction flowAction = new FlowAction(); //设置当前处理人 flowAction.setTaskNo(taskNo); flowAction.setFlowNo(submitFlowNo); flowAction.setUserID(submitUserId); flowAction.setNextNodeType("TASK"); if("1000".equals(submitTask)){ flowAction.setPhaseOpinion(submitTask); flowAction.setPhaseAction("AutoFinish"); }else{ flowAction.setPhaseOpinion(submitTask); String actionScript = tran.getString("select actionscript from flow_model where phaseno ='"+submitTask+"' and flowno ='"+submitFlowNo+"'"); if(actionScript==null) throw new Exception( "未找到流程信息" ); JSONArray ja = JSONArray.parseArray(actionScript); JSONObject obj = ja.getJSONObject(0); flowAction.setPhaseAction(obj.getString("userinfo").replaceAll(","," ")); } flowAction.submit( tx ); tx.commit(); return "success@"+submitFlowunid; } catch (Exception e) { try { tx.rollback(); tx.commit(); } catch (JBOException e1) { e1.printStackTrace(); } e.printStackTrace(); return "error_message"; } } /** * 发起流程之前自定义操作 * @param tx * @param flowBussiness * @throws Exception */ public void customOperation(JBOTransaction tx,BizObject flowBussiness)throws Exception{ } /** *流程互斥检查 * @param tx * @throws Exception */ public String flowMutexCheck(JBOTransaction tx)throws Exception{ BizObjectManager bom=JBOFactory.getBizObjectManager(FLOW_WORK_FLAG.CLASS_NAME); tx.join(bom); String mutextKeyValue=""; String mutextKey=""; String res=""; String sql="SELECT O.flow_unid,O.flow_name FROM O WHERE O.mutex_key=:mutex_key AND O.flow_name=:flownameb AND EXISTS (SELECT fc.flow_nameb FROM jbo.com.tenwa.entity.comm.flow.FLOW_MUTEX_CONFIG fc WHERE fc.flow_nameA=:flowname)"; for(int i=0;isearchCondtion=new HashMap(); mutextKeyValue=this.FlowParam.get(mutextKey); ListmutexList=bom.createQuery(sql).setParameter("mutex_key",mutextKeyValue).setParameter("flownameb",this.getFlowMutexConfig().get(i).getAttribute("flow_nameb").getString()).setParameter("flowname",this.getFlowNo()).getResultList(false); if(mutexList.size()>0){ for(int j=0;j flowTask = JBOFactory.getBizObjectManager(FLOW_TASK.CLASS_NAME).createQuery("objectno=:objectno and (endtime is null or endtime='') ").setParameter("objectno", mutexList.get(j).getAttribute("flow_unid").getString()).getResultList(false); String OperatorUser =""; if(flowTask.size()>0){ for(int k=0;k0){OperatorUser+=",";} OperatorUser=OperatorUser+flowTask.get(k).getAttribute("username").getString(); } } if(res!=""){ res+=","; } res+=flowobject.getAttribute("flowname").getString()+"[当前处理人:"+OperatorUser+"]"; } } } if(res.length()>0){res="当前流程和下面流程互斥不同时执行【"+res+"】";} return res; } /** * 保存互斥信息 * @param tx * @throws Exception */ public void flowMutexInfoInit(JBOTransaction tx) throws Exception{ BizObjectManager bom=JBOFactory.getBizObjectManager(FLOW_WORK_FLAG.CLASS_NAME); tx.join(bom); String mutextKey=""; String mutextKeyValue=""; for(int i=0;i