<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="java.util.ArrayList" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%!
    private boolean isEmpty(String str) {
        if ("".equals(str) ||"(null)".equals(str) || str == null) {
            return true;
        } else {
            return false;
        }
    }
%>
<%
    RecordSet rs = new RecordSet();
    BaseBean bb=new BaseBean();
    JSONArray array = new JSONArray();
    JSONObject json = new JSONObject();
    bb.writeLog("进入getdeleCount.jsp-->");
    String resquestid=request.getParameter("resquestid");
    int count=0;
    String mainWorkflowid = "0";
    String touchnodeid = "0";
    String currentnodeid = "0";
    if (!isEmpty(resquestid)){
        String queryMainWorkflowidSql = "select workflowid ,lastnodeid , currentnodeid from workflow_requestbase where requestid="+resquestid;
        bb.writeLog("queryMainWorkflowidSql-->"+queryMainWorkflowidSql);
        rs.execute(queryMainWorkflowidSql);
        if(rs.next()){
            mainWorkflowid = rs.getString(1);
            touchnodeid = rs.getString(2);
            currentnodeid = rs.getString(3);
        }

        ArrayList<String> touchnodeids = new ArrayList<>();
        String queryTouchNodeidSql = "select touchnodeid from uf_sczlc where workflowid="+mainWorkflowid;
        bb.writeLog("queryTouchNodeidSql-->"+queryTouchNodeidSql);
        rs.execute(queryTouchNodeidSql);
        if(rs.next()){
            String nodeid = rs.getString(1);
            if(nodeid.equals(currentnodeid)){
                touchnodeid = rs.getString(1);
                touchnodeids.add(touchnodeid);
            }

        }

        String sql="select COUNT(*) as cnt from workflow_requestbase where mainrequestid="+resquestid+" and workflowid in (select workflowid subWorkflowId from workflow_requestbase  where requestid in (select subrequestid  from workflow_subwfrequest where subrequestid in (select requestid from workflow_requestbase where mainrequestid="+resquestid+" and triggernode = "+touchnodeid+")))";
        // String sql="select COUNT(*) as cnt from workflow_requestbase where mainrequestid="+resquestid+" and workflowid in (select workflowid subWorkflowId from workflow_requestbase  where requestid in (select subrequestid  from workflow_subwfrequest where subrequestid in (select requestid from workflow_requestbase where mainrequestid="+resquestid+" and triggernode in ( "+String.join(",",touchnodeids)+"))))";
        bb.writeLog("sql-->"+sql);
        rs.execute(sql);
        if (rs.next()){
            count=rs.getInt("cnt");
            json.put("code",0);
            json.put("count",count);
            array.add(json);
            out.print(array.toJSONString());
        }else {
            json.put("code",1);
            json.put("errMsg","查无此resquestid");
            array.add(json);
            out.print(array.toJSONString());
        }
    }else {
        json.put("code",1);
        json.put("errMsg","resquestid为空");
        array.add(json);
        out.print(array.toJSONString());
    }
%>

