apzl_leasing/src_sys/com/tenwa/flow/action/comm/FlowController.java
2019-08-18 14:34:29 +08:00

96 lines
3.9 KiB
Java

package com.tenwa.flow.action.comm;
import com.amarsoft.awe.util.JavaMethod;
import com.amarsoft.context.ASUser;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.stereotype.Controller;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@Controller
public class FlowController extends HttpServlet {
private static final long serialVersionUID = -8195828333793281342L;
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
this.doGet(request, response);
}
/**
* 共需要传递几个基础参数
* ClassName: 用于查找需要执行的startAction
* Args内必须提供参数
* ApplyType: 用于查找哪个流程
* @return
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("application/x-www-form-urlencoded;charset=UTF-8");
response.setHeader( "Cache-Control", "no-store" );
response.setHeader( "Pragma", "no-cache" );
response.setDateHeader( "Expires", 0L );
response.setCharacterEncoding( "UTF-8" );
PrintWriter out = response.getWriter();
String type = request.getParameter( "type" );
//发起流程固定initFLow
String sMethodName = "interfaceInitFlow";
String result;
try {
String sResult = null;
if("new".equals(type)){
String sClassName = request.getParameter( "ClassName" );
String curUserID = request.getParameter("CurUserID");
String sArgs = request.getParameter("Args");
if ( sArgs == null ) {
sArgs = "";
} else {
sArgs += getFixedFlowParam( sArgs );
}
ASUser CurUser = ASUser.getUser(curUserID, null );
sResult = JavaMethod.runTrans( sClassName, sMethodName, sArgs, CurUser ).getReturnText();
if (sResult.indexOf("success")==-1) {
throw new Exception( "发起流程失败" );
}
}else if("alter".equals(type)){
BaseFlowStartAction baseFlowStartAction = new BaseFlowStartAction();
baseFlowStartAction.setSubmitFlowunid(request.getParameter("flowunid"));
baseFlowStartAction.setSubmitFlowNo(request.getParameter("flowNo"));
baseFlowStartAction.setSubmitUserId(request.getParameter("userId"));
baseFlowStartAction.setSubmitTask(request.getParameter("submitTask"));
sResult = baseFlowStartAction.submitFlow();
baseFlowStartAction=null;
if (sResult.indexOf("success")==-1) {
throw new Exception( "提交流程失败" );
}
}
result = sResult.split("@")[1];
} catch ( Exception e ) {
e.printStackTrace();
result = "ERR-9999";
}
ObjectMapper objectMapper = new ObjectMapper();
out.print(objectMapper.writeValueAsString(result));
out.flush();
out.close();
}
public static String getFixedFlowParam ( String args ) {
StringBuffer fixedFlowParam = new StringBuffer( "{'" );
if ( args != null && args.length() > 0 ) {
String[] argObjects = args.split( "," );
for ( String obj : argObjects ) {
if ( fixedFlowParam.length() > 2 ) {
fixedFlowParam.append( "'@'" );
}
fixedFlowParam.append( obj.split( "=" )[0] ).append( "':'" ).append( obj.split( "=" )[1] );
}
fixedFlowParam.append( "'}" );
}
return ",FixedFlowParam=" + fixedFlowParam.toString();
}
}