342 lines
12 KiB
Java
342 lines
12 KiB
Java
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<String, Object> getApprovalNode(Map<String, Object> fieldMap,JBOTransaction tx) throws Exception{
|
||
Map<String, Object> body = new HashMap<String, Object>();
|
||
|
||
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", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||
return body;
|
||
}
|
||
|
||
if ("".equals(taskNo)) {
|
||
body.put("static", "N");
|
||
body.put("message", "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ!");
|
||
return body;
|
||
|
||
}
|
||
//String sUserId = fieldMap.get("userid") == null ? "" : fieldMap.get("userid").toString();
|
||
|
||
TenwaFlowTask ft1 = new TenwaFlowTask(taskNo, tx);// ʹ<><CAB9>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<Map<String, Object>> list2 = new ArrayList<Map<String,Object>>();
|
||
// һ<><D2BB>·<EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD>ɳ<EFBFBD>ʼ<EFBFBD><CABC> APP <20><><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5> ֻ<><D6BB>һ<EFBFBD><D2BB>·<EFBFBD><C2B7>
|
||
if (routeType.equals("commroute") || routeType.equals("conditionroute")) {
|
||
Map<String, Object> mMap = new HashMap<String, Object>();
|
||
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 = "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>" + joPhaseName + "<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>";
|
||
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<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
|
||
if(StringX.isSpace(joUserInfo.trim())) {
|
||
Map<String, Object> map = new HashMap<String, Object>();
|
||
map.put("userId", "");
|
||
map.put("userName", "");
|
||
list.add(map);
|
||
} else {
|
||
String [] vUser = joUserInfo.split("@");
|
||
|
||
|
||
|
||
for (int i=0; i < vUser.length; i ++) {
|
||
Map<String, Object> map = new HashMap<String, Object>();
|
||
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);
|
||
}
|
||
|
||
//<2F>ύ<EFBFBD><E1BDBB><EFBFBD><EFBFBD>
|
||
public static String commit(Map<String, Object> 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 "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ!";
|
||
}
|
||
String endTime = bo.getAttribute("ENDTIME") == null ? "" : bo
|
||
.getAttribute("ENDTIME").toString();
|
||
if (!"".equals(endTime)) {
|
||
return "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ύ!";
|
||
}
|
||
|
||
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 "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ύ!";
|
||
} 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 = "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>ύ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!";
|
||
} 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 = "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>ύ<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ϣ!";
|
||
} else {
|
||
FlowAction.setPhaseAction(phaseAction);
|
||
String joinNode = FlowAction.isJoinNode(tx);
|
||
|
||
if ("1".equals(joinNode)) {// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>join<69>ڵ<EFBFBD>
|
||
String joinUserID = FlowAction.getJoinUser(tx);
|
||
String curUserID = phaseAction.split(" ")[0];
|
||
if ((!curUserID.equals(joinUserID) && (!""
|
||
.equals(joinUserID)))) {
|
||
message = "<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD>ύ<EFBFBD><EFBFBD>Ϊ" + joinUserID + ",<2C><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>Ա!";
|
||
}
|
||
}
|
||
String commitPeopleTip = "";
|
||
boolean bPool = Boolean.valueOf(null);
|
||
if (bPool) {// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><D7B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD>ʾ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>
|
||
String[] arr = phaseAction.split("@");
|
||
|
||
for (int i = 0; i < arr.length; i++) {
|
||
String userID = arr[i].split(" ")[0];
|
||
if (userID.indexOf("|") > -1) {// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
String[] phaseUser = userID.split("|");
|
||
userID = "<EFBFBD><EFBFBD>:" + phaseUser[0] + "-<2D>û<EFBFBD>:"
|
||
+ 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 "<EFBFBD>ύʧ<EFBFBD><EFBFBD>!";
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
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 "<22><>ѡ<EFBFBD><D1A1>" + mPhaseName + "<22>û<EFBFBD>!";
|
||
}
|
||
}
|
||
if (phaseAction.indexOf("@") > -1)
|
||
phaseAction = phaseAction.substring(1);
|
||
|
||
}
|
||
return phaseAction;
|
||
}
|
||
|
||
}
|