<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.*" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>


<%
    try {
        String id = request.getParameter("id");
        ArrayList<Map<String, String>> sourceidsList = new ArrayList<Map<String, String>>();
        RecordSet recordSet = new RecordSet();
        recordSet.executeQuery("select lcbt from uf_CCSPDTZ where id = ?",id);
        int lc = 0;
        if (recordSet.next()){
            lc = Util.getIntValue(recordSet.getString("lcbt"));
        }
        ArrayList<String> lcArr = new ArrayList();
        recordSet.executeQuery("select mainid from uf_CCBGJLB_dt1 where ccbgjllc = ?",lc);
        if(recordSet.getCounts() == 0){
            // recordSet.executeQuery("select lc from uf_CCBGJLB ccqqlc = ?",lc);
            // recordSet.next();
            lcArr.add(lc+"");
        }else {
            recordSet.next();
            String mainid = recordSet.getString("mainid");
            recordSet.executeQuery("select  ccqqlc from uf_CCBGJLB where id = ?",mainid);
            recordSet.next();
            String ccqqlc = recordSet.getString("ccqqlc");
            lcArr.add(ccqqlc);
            recordSet.executeQuery("select ccbgjllc from uf_CCBGJLB_dt1 where mainid = ?",mainid);
            while (recordSet.next()){
                String ccbgjllc = recordSet.getString("ccbgjllc");
                lcArr.add(ccbgjllc);
            }
        }
        // out.print(lcArr);
        if (lcArr.size() > 0){
            recordSet.executeQuery("select requestid from formtable_main_206 where yccsj in ( " + String.join(",",lcArr) + ")");
        }
        ArrayList<String> requestArr = new ArrayList();
        while (recordSet.next()){
            String requestid = recordSet.getString("requestid");
            requestArr.add(requestid);
        }
        // out.print(requestArr);
        recordSet.executeQuery("select REQUESTID , currentnodetype ,REQUESTMARK from WORKFLOW_REQUESTBASE where REQUESTID in ( " + String.join(",",requestArr) + " )");
        ArrayList<String> noArchivingReq = new ArrayList<>();
        ArrayList<Map<String, String>> specialobj = new ArrayList<>();
        while (recordSet.next()){
            String currentnodetype = recordSet.getString("currentnodetype");
            if(!"3".equals(currentnodetype)){
                String requestid = recordSet.getString("requestid");
                String requestname = recordSet.getString("REQUESTMARK");
                noArchivingReq.add(requestid);
                HashMap<String, String> map = new HashMap<>();
                map.put("id",requestid);
                map.put("name",requestname);
                specialobj.add(map);
            }
        }
        if (noArchivingReq.size() > 0){
            HashMap<String, Object> changeFieldValue = new HashMap<>();
            String value= String.join(",",noArchivingReq);
            changeFieldValue.put("value" ,value );
            changeFieldValue.put("specialobj",specialobj);
            out.print(JSONObject.toJSONString(changeFieldValue));
            // out.print("-2");
        }else {
            out.print("-1");
        }
    }catch (Exception e){
        out.print(e);
        out.print("");
        out.print(e.getStackTrace());
    }

%>
<%!

%>