ShowProcess.java
package com.mycim.webapp.actions.process;
import com.fa.sesa.i18n.I18nUtils;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.MiscUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.bas.NamedObject;
import com.mycim.webapp.actions.PrpSetupAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 查看工艺流程
*
* @author weike.li
* @version 6.0.0
* @date 2019/12/11
**/
public class ShowProcess extends PrpSetupAction {
@Override
public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
return mapping.getInputForward();
}
public ActionForward query(ActionMapping mapping, HttpServletRequest request) {
if (request.getParameter("nav") == null) {
List routeTree;
Long facilityRrn = LocalContext.getFacilityRrn();
String processId = request.getParameter("processid");
if (processId != null) {
processId = processId.trim().toUpperCase();
}
String productId = request.getParameter("productId");
String processRrn = request.getParameter("processrrn");
long productRrn = 0;
if (productId != null) {
productId = productId.trim().toUpperCase();
productRrn = baseService.getNamedObjectRrn(productId, baseService
.getNamedSpace(facilityRrn.longValue(), ObjectList.PRODUCT_KEY), ObjectList.PRODUCT_KEY);
}
Map matchingRules = new HashMap();
matchingRules.put("productRrn", productRrn + "");
matchingRules.put("processRrn", processRrn + "");
String lotRrn = request.getParameter("lotRrn");
if (StringUtils.isNotEmpty(lotRrn)) {
matchingRules.put("lotRrn", lotRrn);
}
long processVer;
if (request.getParameter("processver") == null) {
processVer = 0;
} else {
String strProcessVer = request.getParameter("processver");
if (strProcessVer.length() == 0) {
processVer = 0;
} else {
processVer = Long.parseLong(strProcessVer);
}
}
String routeString = request.getParameter("routeString");
if (routeString != null) {
routeString = routeString.trim().toUpperCase();
}
long executionRrn = (request.getParameter("executionRrn") == null) ? 0 : Long
.parseLong(request.getParameter("executionRrn"));
Long processRrn1 = null;
Long routeRrn = null;
//get tree of certain route(rework lot used)
if (routeString != null) {
String namedSpace = baseService.getNamedSpace(MiscUtils.parseSQL(facilityRrn), ObjectList.WFL_KEY);
routeRrn = baseService.getNamedObjectRrn(routeString, namedSpace, ObjectList.WFL_KEY);
//get tree of prp through process id
} else if (processId != null && request.getParameter("processrrn") == null) {
String namedSpace = baseService.getNamedSpace(MiscUtils.parseSQL(facilityRrn), ObjectList.WFL_KEY);
processRrn1 = baseService.getNamedObjectRrn(processId, namedSpace, ObjectList.WFL_KEY);
routeRrn = processRrn1;
//get tree of prp through process Rrn
} else if (request.getParameter("processrrn") != null) {
processRrn1 = new Long(request.getParameter("processrrn"));
routeRrn = processRrn1;
}
if (routeRrn != null) {
NamedObject namedObject = baseService.isExisted(routeRrn.longValue());
if (namedObject != null) {
if (StringUtils.equals(ObjectList.PROCEDURE_KEY, namedObject.getObjectSubtype())) {
matchingRules.put("routeRrn", routeRrn);
} else {
matchingRules.put("processRrn", routeRrn);
}
}
}
if (routeString != null) {
NamedObject namedObject = baseService.isExisted(routeRrn);
if (StringUtils.equals(ObjectList.PROCEDURE_KEY, namedObject.getObjectSubtype())) {
matchingRules.put("routeRrn", routeRrn);
} else {
matchingRules.put("processRrn", routeRrn);
}
if (processVer > 0) {
routeTree = prpService.getWorkFlowTree(routeRrn, (int) processVer, matchingRules);
} else {
routeTree = prpService.getWorkFlowTree(routeRrn.longValue(), matchingRules);
}
} else {
if (routeRrn == null) {
routeTree = prpService.getWorkFlowTreeAfter(executionRrn);
} else {
if (processVer > 0) {
routeTree = prpService.getWorkFlowTree(routeRrn.longValue(), (int) processVer, matchingRules);
} else {
routeTree = prpService.getWorkFlowTree(routeRrn.longValue(), matchingRules);
}
}
}
if ("true".equals(request.getParameter("firstFlag"))) {
StringBuffer script = new StringBuffer();
if (routeTree.size() <= 0) {
String msg = "This process is not active.";
if (request.getParameter("type") != null && request.getParameter("type").equals("treebefore")) {
//TODO i18n
msg = I18nUtils.getMessage("process.first_step", "Already at the first step");
} else if (request.getParameter("type") != null &&
request.getParameter("type").equals("treeafter")) {
//TODO i18n
msg = I18nUtils.getMessage("process.last_step", "Already at the last step");
} else if (request.getParameter("type") != null &&
request.getParameter("type").equals("treeafterwithrework")) {
msg = I18nUtils.getMessage("process.last_step", "Already at the last step");
} else if (request.getParameter("type") != null &&
request.getParameter("type").equals("treeafterCurrentwithrework")) {
msg = I18nUtils.getMessage("process.last_step", "Already at the last step");
}
script.append("myToc.doc.write('<font class=' + myToc.styleItemFolderNoLink + '><b>" + msg + "</b" +
"></font>');");
} else {
script.append(
"myToc.node1 = myToc.makeFolder('','','content','" + request.getContextPath() + "/img" +
"/menu/explorer/root.gif');");
int i = 1;
int j = 1;
String parentStep = null;
String parentWfl = null;
String parentRoute = null;
//hard code here.
String wfl_ver = "1";
for (Object obj : routeTree) {
String[] temp = (String[]) obj;
script.append("myToc.node");
if (temp[7] != null && temp[7].equals("0")) {
++j;
// re-init i;
i = 0;
script.append(j);
script.append(" = myToc.makeFolder('");
script.append(temp[2]);
script.append("','','content','');");
script.append("myToc.insertNode(myToc.node");
script.append("1");
script.append(", myToc.node");
script.append(j);
script.append(");");
parentStep = temp[1];
parentWfl = temp[5];
parentRoute = temp[2];
} else {
if (routeString != null) {
parentRoute = routeString;
}
++i;
script.append(j + i);
script.append(" = myToc.makeItem('");
script.append(temp[2]);
script.append("---");
script.append(temp[5]);
script.append("','javascript:setOpener(\"");
if (parentRoute.indexOf("--") != -1) {
//路径id
script.append(
parentRoute.substring((parentRoute.indexOf("--") + 3), parentRoute.length()));
script.append("\",\"");
//路径序号
script.append(parentRoute.substring(0, parentRoute.indexOf("--")));
} else {
script.append(parentRoute);
script.append("\",\"");
script.append("");
}
script.append("\",\"");
//operation id
if (temp[2].indexOf("-") != -1) {
script.append(temp[2].substring((temp[2].indexOf("--") + 3), temp[2].length()));
script.append("\",\"");
script.append(temp[2].substring(0, temp[2].indexOf("-")));//步骤序号
} else {
script.append(temp[2]);
}
script.append("\",\"");
//step path
script.append(temp[6]);
script.append("\");','','" + request.getContextPath() + "/img/menu/item.gif','" +
request.getContextPath() + "/img/menu/item.gif');");
script.append("myToc.insertNode(myToc.node");
script.append(j);
script.append(", myToc.node");
script.append(j + i);
script.append(");");
}
}
script.append("myToc.display (myToc.node1,1);");
}
request.setAttribute("script", script.toString());
}
}
return mapping.getInputForward();
}
}