package com.base.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import jbo.sys.FLOW_OBJECT; import jbo.sys.FLOW_TASK; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import com.amarsoft.app.flow.FlowAction; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.amarsoft.are.lang.StringX; import com.tenwa.flow.task.TenwaFlowTask; public class FlowManageUtil { public static Map getApprovalNode(Map fieldMap,JBOTransaction tx) throws Exception{ Map body = new HashMap(); String taskNo ; String flowNo; String phaseNo; String flowState ; String objectNo = fieldMap.get("OBJECTNO") == null ? "" : fieldMap.get("OBJECTNO").toString(); String serialNo = fieldMap.get("SERIALNO") == null ? "" : fieldMap.get("SERIALNO").toString(); BizObject bo = queryFlowTask(objectNo, serialNo, tx); if (null != bo) { String objectType = bo.getAttribute("OBJECTTYPE") == null ? "" : bo .getAttribute("OBJECTTYPE").toString(); objectNo = bo.getAttribute("OBJECTNO") == null ? "" : bo .getAttribute("OBJECTNO").toString(); flowNo = bo.getAttribute("FLOWNO") == null ? "" : bo .getAttribute("FLOWNO").toString(); phaseNo = bo.getAttribute("PHASENO") == null ? "" : bo .getAttribute("PHASENO").toString(); taskNo = bo.getAttribute("SERIALNO") == null ? "" : bo .getAttribute("SERIALNO").toString(); //String flowName = bo.getAttribute("FLOWNAME") == null ? "" : bo.getAttribute("FLOWNAME").toString(); //String applyType = bo.getAttribute("APPLYTYPE") == null ? "" : bo.getAttribute("APPLYTYPE").toString(); //String phaseName = bo.getAttribute("phasename") == null ? "" : bo.getAttribute("phasename").toString(); //String assignedTaskNo = bo.getAttribute("assignedtaskno") == null ? "": bo.getAttribute("assignedtaskno").toString(); flowState = bo.getAttribute("flowState") == null ? "" : bo .getAttribute("flowState").toString(); } else { body.put("static", "N"); body.put("message", "此流程任务不存在!"); return body; } if ("".equals(taskNo)) { body.put("static", "N"); body.put("message", "请选择一条信息!"); return body; } //String sUserId = fieldMap.get("userid") == null ? "" : fieldMap.get("userid").toString(); TenwaFlowTask ft1 = new TenwaFlowTask(taskNo, tx);// 使用jboTrans String routeInfo = ft1.getRouteInfo(); flowNo = ft1.FlowNo; phaseNo = ft1.PhaseNo; flowState = ft1.FlowState; JSONObject json = JsonUtil.str2JSONObject(routeInfo); String routeType = json.getString("routeType") == null ? "" : json .getString("routeType").toString(); List> list2 = new ArrayList>(); // 一般路由和条件路由初始化 APP 发起业务 只有一般路由 if (routeType.equals("commroute") || routeType.equals("conditionroute")) { Map mMap = new HashMap(); String route = json.getString("route") == null ? "" : json .getString("route").toString(); if (route.length() > 0) { String type = "radio"; JSONArray jsonArray = JsonUtil.str2JSONArray(route); JSONObject jo = jsonArray.getJSONObject(0); String joPhaseNo = jo.getString("phaseNo") == null ? "" : jo .getString("phaseNo").toString(); // phaseNo String joPhaseName = jo.getString("phaseName") == null ? "" : jo .getString("phaseName").toString(); // phaseName String joUserInfo = jo.getString("userInfo") == null ? "" : jo .getString("userInfo").toString(); // userInfo String joFlowUserOperatorType = jo.getString("flowUserOperatorType") == null ? "" : jo .getString("flowUserOperatorType").toString(); // flowUserOperatorType String joNodeType = jo.getString("nodeType") == null ? "" : jo .getString("nodeType").toString(); // nodeType String headMessage = "请选择" + joPhaseName + "用户:"; mMap.put("phaseName", joPhaseName); mMap.put("phaseNo", joPhaseNo); mMap.put("nodeType", joNodeType); mMap.put("headMessage", headMessage); mMap.put("flowUserOperatorType", joFlowUserOperatorType); if (!"01".equals(joFlowUserOperatorType)) { type = "checkBox"; } mMap.put("type", type); List> list = new ArrayList>(); if(StringX.isSpace(joUserInfo.trim())) { Map map = new HashMap(); map.put("userId", ""); map.put("userName", ""); list.add(map); } else { String [] vUser = joUserInfo.split("@"); for (int i=0; i < vUser.length; i ++) { Map map = new HashMap(); String [] vUserinfo=vUser[i].split(" "); map.put("userId", vUser[i]); map.put("userName", vUserinfo[1]); list.add(map); } } mMap.put("userInfo", list); list2.add(mMap); } } body.put("static", "Y"); body.put("message", ""); body.put("phaseopinion", list2); body.put("routeType", routeType); return body; } public static BizObject queryFlowTask(String objectNo,String serialNo, JBOTransaction tx) throws Exception { String sSql = "SELECT O.* FROM O,"; sSql += FLOW_OBJECT.CLASS_NAME + " FLOW_OBJECT "; sSql += "WHERE FLOW_OBJECT.OBJECTNO=O.OBJECTNO "; sSql += "AND FLOW_OBJECT.FLOWNO=O.FLOWNO "; sSql += "AND FLOW_OBJECT.PHASENO=O.PHASENO "; sSql += "AND FLOW_OBJECT.PHASETYPE=O.PHASETYPE "; sSql += "AND FLOW_OBJECT.OBJECTNO='" + objectNo + "' "; BizObjectManager bom = JBOFactory .getBizObjectManager(FLOW_TASK.CLASS_NAME); sSql = (!StringX.isSpace(serialNo)) ? "SERIALNO='" + serialNo + "'" : sSql; return bom.createQuery(sSql).getSingleResult(false); } //提交流程 public static String commit(Map fieldMap, JBOTransaction tx)throws Exception { String taskNo = "" ; String message = ""; String phaseActionw = "" ; String type = fieldMap.get("submittype") == null ? "": fieldMap.get("submittype").toString(); String userid = fieldMap.get("userid") == null ? "": fieldMap.get("userid").toString(); //FlowTask FlowTask = new FlowTask(); String objectNo = fieldMap.get("OBJECTNO") == null ? "" : fieldMap.get("OBJECTNO").toString(); String serialNo = fieldMap.get("SERIALNO") == null ? "" : fieldMap.get("SERIALNO").toString(); BizObject bo = queryFlowTask(objectNo, serialNo, tx); if (null != bo) { taskNo = bo.getAttribute("SERIALNO") == null ? "" : bo .getAttribute("SERIALNO").toString(); } else { return "请选择一条信息!"; } String endTime = bo.getAttribute("ENDTIME") == null ? "" : bo .getAttribute("ENDTIME").toString(); if (!"".equals(endTime)) { return "此流程任务已提交!"; } switch (type) { case "1": return AssignedTaskNo(taskNo, tx); case "2": return endMeetingTask(taskNo, tx); } FlowAction FlowAction = new FlowAction(); FlowAction.setTaskNo(taskNo); String isCommited = FlowAction.isCommited(tx); if ("yes".equals(isCommited)) { return "此流程任务已提交!"; } else { String phaseOpinion = fieldMap.get("phaseopinion") == null ? "": fieldMap.get("phaseopinion").toString(); phaseActionw = fieldMap.get("userinfo") == null ? "": fieldMap.get("userinfo").toString(); String nodeType = fieldMap.get("nodetype") == null ? "": fieldMap.get("nodetype").toString(); if (StringX.isSpace(phaseOpinion)) { message = "请选择提交动作!"; } else { FlowAction.setPhaseOpinion(phaseOpinion); String nextPhaseAttrs = FlowAction.getNextPhaseAttr(tx); String[] nextPhases = nextPhaseAttrs.split("@"); String phaseAction = ""; phaseAction = getNextActionValue(nextPhases, FlowAction,phaseActionw, tx); if (StringX.isSpace(phaseAction)) { message = "请选择提交用户信息!"; } else { FlowAction.setPhaseAction(phaseAction); String joinNode = FlowAction.isJoinNode(tx); if ("1".equals(joinNode)) {// 如果是join节点 String joinUserID = FlowAction.getJoinUser(tx); String curUserID = phaseAction.split(" ")[0]; if ((!curUserID.equals(joinUserID) && (!"" .equals(joinUserID)))) { message = "先前分支的提交人为" + joinUserID + ",请选择相同人员!"; } } String commitPeopleTip = ""; boolean bPool = Boolean.valueOf(null); if (bPool) {// 如果下一阶段是任务池,则提示 可以挑选任务的用户 String[] arr = phaseAction.split("@"); for (int i = 0; i < arr.length; i++) { String userID = arr[i].split(" ")[0]; if (userID.indexOf("|") > -1) {// 并行任务 String[] phaseUser = userID.split("|"); userID = "阶段:" + phaseUser[0] + "-用户:" + phaseUser[1]; } commitPeopleTip = commitPeopleTip + userID + " "; } } String readUserIds = ""; FlowAction.setTaskNo(taskNo); FlowAction.setPhaseOpinion(phaseOpinion); FlowAction.setPhaseAction(phaseActionw); FlowAction.setReadUserIds(readUserIds); FlowAction.setUserID(userid); FlowAction.setNextNodeType(nodeType); String returnValue = FlowAction.submit(tx); if (StringX.isSpace(returnValue) || "undefined".equals(returnValue) || "null".equals(returnValue) || "_CANCEL_".equals(returnValue)) { return "SUCCESS"; } else if ("Success".toLowerCase().equals( returnValue.toLowerCase())) { return "SUCCESS"; } else { return "提交失败!"; } } } } if (!StringX.isSpace(message)) { return message; } return "SUCCESS"; } public static String endMeetingTask(String taskNo,JBOTransaction tx) throws Exception { FlowAction FlowAction = new FlowAction(); FlowAction.setTaskNo(taskNo); FlowAction.endMeetingTask(tx); return "SUCCESS"; } public static String AssignedTaskNo(String taskNo,JBOTransaction tx) throws Exception { FlowAction FlowAction = new FlowAction(); FlowAction.setTaskNo(taskNo); FlowAction.setPhaseOpinion("null"); FlowAction.setPhaseAction("null"); FlowAction.submit(tx); FlowAction.submit(tx); return "SUCCESS"; } public static String getNextActionValue(String[] nextPhases,FlowAction FlowAction,String phaseActionc, JBOTransaction tx) throws Exception { String phaseAction = ""; if (nextPhases.length == 1) { String nextPhaseDes = ""; nextPhaseDes = nextPhases[0].split(",")[2]; if ("POOL".equals(nextPhaseDes) || "FORK&POOL".equals(nextPhaseDes)) { phaseAction = FlowAction.getActionList(tx); } else if ("END".equals(nextPhaseDes)) { phaseAction = "system"; } else { phaseAction = phaseActionc; } } else { String actionList = FlowAction.getActionList(tx); for (int i = 0; i < nextPhases.length; i++) { //String mPhaseName = nextPhases[i].split(",")[1]; String mPhaseNo = nextPhases[i].split(",")[0]; String mPhaseDes = nextPhases[i].split(",")[2]; String mPhaseAction = ""; if ("POOL".equals(mPhaseDes) || "FORK&POOL".equals(mPhaseDes)) { for (int j = 0; j < actionList.split("@").length; j++) { String userIDStr = actionList.split("@")[j]; String userID = userIDStr.split(" ")[0]; if (userID.indexOf("|") > -1) { String phaseNo = userID.split("|")[0]; if (mPhaseNo.equals(phaseNo)) { mPhaseAction = mPhaseAction + "@" + userIDStr; } } } if (mPhaseAction.indexOf("@") > -1) mPhaseAction = mPhaseAction.substring(1); phaseAction += "@" + mPhaseAction; } else { mPhaseAction = phaseActionc; phaseAction += "@" + mPhaseNo + "|" + mPhaseAction; } if (StringX.isSpace(mPhaseAction)) { return null; //return "请选择" + mPhaseName + "用户!"; } } if (phaseAction.indexOf("@") > -1) phaseAction = phaseAction.substring(1); } return phaseAction; } }