<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
    BaseBean bb = new BaseBean();
    RecordSet rs = new RecordSet();
    List<Map<String,String>> list = new ArrayList<Map<String,String>>();
    try{

//        "select d1.responskind,d2.responsdepart,d2.performance\n" +
//        "from formtable_main_2992_dt1 d1 \n" +
//        "left join formtable_main_2992_dt2 d2 on d2.mainid = d1.mainid and d1.responsdept = d2.responsdept and d1.responskind = d2.responskind"

        Map<String,String> zrlxMap = new HashMap<String,String>();
        String sql =" select selectvalue,selectname \n" +
                    "   from workflow_selectitem \n" +
                    "   where fieldid in(\n" +
                    "       select id from workflow_billfield \n" +
                    "       where billid in( select id from workflow_bill where tablename='formtable_main_2992' ) and fieldname='responskind' \n" +
                    "       and detailtable='formtable_main_2992_dt1'\n" +
                    " ) ";
        rs.executeQuery(sql);
        while (rs.next()){
            String selectvalue = rs.getString("selectvalue");
            String selectname = rs.getString("selectname");
            out.print("selectname:"+selectname+" selectvalue:"+selectvalue);
            zrlxMap.put(selectvalue,selectname);
        }

        List<Map<String,String>> requestList = new ArrayList<Map<String,String>>();
        sql =" select t.requestid,t.id,k.currentnodetype \n" +
                    " from formtable_main_2992 t \n" +
                    " inner join workflow_requestbase k on k.requestid = t.requestid\n" +
                    " where currentnodetype in(1,2,3,5) " +
                    " order by t.learndate desc";
        out.print("sql:"+sql+"</br>");

        rs.executeQuery(sql);
        while (rs.next()){
            String requestid = Util.null2String(rs.getString("requestid"));
            String id = Util.null2String(rs.getString("id"));
            String currentnodetype = Util.null2String(rs.getString("currentnodetype"));

            out.print("requestid:"+requestid+" mainid:"+id +" currentnodetype:"+currentnodetype);

            Map<String,String> map = new HashMap<String,String>();
            map.put("id",id);
            map.put("requestid",requestid);
            requestList.add(map);
        }

        out.print("requestList:"+requestList.size()+"</br>");

        for(int i=0;i<requestList.size();i++){
            Map<String,String> mainMap = requestList.get(i);
            String requestid = mainMap.get("requestid");
            String mainid = mainMap.get("id");
            out.print("requestid:"+requestid+"</br>");
//            sql =   " select t.learndate,t.learnform,t.xjpzsjcyjhcyzspsjsfbzyhyzksj,t.frommeet," +
//                    "        t.publishunit,t.requirements,t.partyrequires,k.responskind,k.responsdepart," +
//                    "        '' as performance " +
//                    " from formtable_main_2992 t" +
//                    " inner join (" +
//                    "   select d1.mainid,d1.responskind,d1.responsdepart\n" +
//                    "   from formtable_main_2992_dt1 d1 \n" +
//                    "   where d1.mainid=" + mainid+
//                    " ) k on k.mainid = t.id " +
//                    " where t.requestid= "+requestid;


            sql =   " select t.learndate,t.learnform,t.xjpzsjcyjhcyzspsjsfbzyhyzksj,t.frommeet," +
                    "        t.publishunit,t.requirements,t.partyrequires,k.responskind,k.responsdepart,k.performance " +
                    " from formtable_main_2992 t" +
                    " inner join (" +
                    "   select d1.mainid,d1.responskind,d1.responsdepart,d2.performance\n" +
                    "   from formtable_main_2992_dt1 d1 \n" +
                    "   left join formtable_main_2992_dt2 d2 on d2.mainid = d1.mainid " +
                    "   and d1.responsdepart = d2.responsdepart " +
                    "   and d1.responskind = d2.responskind " +
                    "   where d1.mainid=" + mainid+
                    " ) k on k.mainid = t.id " +
                    " where t.requestid= "+requestid+" order by ";


            out.print("sql:"+sql+"</br>");
            rs.executeQuery(sql);
            while (rs.next()){

                String learndate = Util.null2String(rs.getString("learndate"));
                String learnform = Util.null2String(rs.getString("learnform"));
                String xjpzsjcyjhcyzspsjsfbzyhyzksj = Util.null2String(rs.getString("xjpzsjcyjhcyzspsjsfbzyhyzksj"));
                String frommeet = Util.null2String(rs.getString("frommeet"));
                String publishunit = Util.null2String(rs.getString("publishunit"));
                String requirements = Util.null2String(rs.getString("requirements"));
                String partyrequires = Util.null2String(rs.getString("partyrequires"));
                String responskind = Util.null2String(rs.getString("responskind"));
                String responsdepart = Util.null2String(rs.getString("responsdepart"));
                String performance = Util.null2String(rs.getString("performance"));

                out.print("learndate:"+learndate+"</br>");

                Map<String,String> map = new HashMap<String,String>();
                map.put("xh",(i+1)+"");
                map.put("xxsj",learndate);
                map.put("xxxs",learnform);
                map.put("zksj",xjpzsjcyjhcyzspsjsfbzyhyzksj);
                map.put("fbdw",publishunit);
                map.put("zcyq",requirements);
                map.put("hymc",frommeet);
                map.put("fgsgzbs",partyrequires);
                map.put("zrbm",responskind);
                String zrlx = "";
                out.print("responskind:"+responskind+"<br>");
                if(StringUtils.isNotBlank(responskind)){
                    zrlx = zrlxMap.get(responskind);
                }
                out.print("zrlx:"+zrlx+"<br>");
                map.put("zrlx",zrlx);

                map.put("zrlx",responsdepart);
                map.put("lsqk",performance);
                list.add(map);
            }
        }
    }catch (Exception e){

    }

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("list",list);
%>

<%=jsonObject.toJSONString() %>