<%@ 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 import="weaver.hrm.company.DepartmentComInfo" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
    RecordSet rs = new RecordSet();
    List<Map<String,String>> dataList = new ArrayList<Map<String,String>>();
    List<Map<String,String>> requestList = new ArrayList<Map<String,String>>();
    DepartmentComInfo departmentComInfo = null;
    try{
        departmentComInfo = new DepartmentComInfo();

        Map<String,String> xxxsMap = 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='learnform' \n" +
                "       and detailtable is null\n" +
                " ) ";
        rs.executeQuery(sql);
        while (rs.next()){
            String selectvalue = rs.getString("selectvalue");
            String selectname = rs.getString("selectname");
            xxxsMap.put(selectvalue,selectname);
        }

        Map<String,String> zrlxMap = new HashMap<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");
            zrlxMap.put(selectvalue,selectname);
        }

        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";
        rs.executeQuery(sql);
        while (rs.next()){
            String requestid = Util.null2String(rs.getString("requestid"));
            String id = Util.null2String(rs.getString("id"));

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

        for(int i=0;i<requestList.size();i++){
            Map<String,String> mainMap = requestList.get(i);
            String requestid = mainMap.get("requestid");
            String mainid = mainMap.get("mainid");

            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;
            rs.executeQuery(sql);
            while (rs.next()){

                String learndate = Util.null2String(rs.getString("learndate")).replace("<br>","");
                String learnform = Util.null2String(rs.getString("learnform")).replace("<br>","");
                String xjpzsjcyjhcyzspsjsfbzyhyzksj = Util.null2String(rs.getString("xjpzsjcyjhcyzspsjsfbzyhyzksj")).replace("<br>","/");
                String frommeet = Util.null2String(rs.getString("frommeet")).replace("<br>","");
                String publishunit = Util.null2String(rs.getString("publishunit")).replace("<br>","");
                String requirements = Util.null2String(rs.getString("requirements")).replace("<br>","");
                String partyrequires = Util.null2String(rs.getString("partyrequires")).replace("<br>","");
                String responskind = Util.null2String(rs.getString("responskind")).replace("<br>","");
                String responsdepart = Util.null2String(rs.getString("responsdepart")).replace("<br>","");
                String performance = Util.null2String(rs.getString("performance")).replace("<br>","");

                Map<String,String> map = new HashMap<String,String>();
                map.put("xh",(i+1)+"");
                map.put("xxsj",learndate);
                String xxxs = "";
                if(StringUtils.isNotBlank(learnform)){
                    xxxs = xxxsMap.get(learnform);
                }
                map.put("xxxs",xxxs);
                map.put("zksj",xjpzsjcyjhcyzspsjsfbzyhyzksj);
                map.put("fbdw",publishunit);
                map.put("zcyq",requirements);
                map.put("hymc",frommeet);
                map.put("fgsgzbs",partyrequires);
                String zrbm = "";
                if(StringUtils.isNotBlank(responsdepart)){
                    zrbm = departmentComInfo.getDepartmentname(responsdepart);
                }
                map.put("zrbm",zrbm);
                String zrlx = "";
                if(StringUtils.isNotBlank(responskind)){
                    zrlx = zrlxMap.get(responskind);
                }
                map.put("zrlx",zrlx);
                map.put("lsqk",performance);
                map.put("requestid",requestid);
                dataList.add(map);
            }
        }
    }catch (Exception e){

    }

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

<%=jsonObject.toJSONString() %>