<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%

    String dwid = request.getParameter("dwid");
    List<Map<String,String>> list = new ArrayList<Map<String,String>>();
    Map<String,String> sqslMap = getSqslMap(dwid);
    if(sqslMap !=null && sqslMap.size()>0){
        list.add(sqslMap);
        String yxDate = sqslMap.get("enddate");

        Map<String,String> smscMap = getSmscMap(dwid,yxDate);
        list.add(smscMap);


        Map<String,String> xcscMap = getXcscMap(dwid,yxDate);
        list.add(xcscMap);


        Map<String,String> spjdMap = getSpjdMap(dwid,yxDate);
        list.add(spjdMap);

        Map<String,String> fzrqMap = getFzrqMap(dwid,yxDate);
        list.add(fzrqMap);


    }

    JSONObject dataJson = new JSONObject();
    dataJson.put("dataList",list);
    dataJson.put("api_status",true);
    dataJson.put("message","success");


%>

<%=dataJson.toJSONString() %>

<%!

    public Map<String,String> getSqslMap(String dwid){
        RecordSet rs = new RecordSet();
        Map<String,String> sqslMap = new HashMap<String,String>();
        sqslMap.put("detail_desc","受理日期");
        sqslMap.put("title","申请受理");
        sqslMap.put("finish","0");

        String slrq = "";
        String status = "4";
        String sql =" select slrq\n" +
                    " from uf_sqsl\n" +
                    " where id in(\n" +
                    "  select max(id) from uf_sqsl where dwmc = '"+dwid+"'"+
                    " ) " ;
        rs.executeQuery(sql);
        if (rs.next()){
            slrq = rs.getString("slrq");
            status = "2";
        }

        sqslMap.put("enddate",slrq);
        sqslMap.put("detail_date",slrq);
        sqslMap.put("status",status);
        return sqslMap;
    }

    public Map<String,String> getSmscMap(String dwid,String yxDate){
        RecordSet rs = new RecordSet();
        Map<String,String> sqslMap = new HashMap<String,String>();
        sqslMap.put("finish","0");
        sqslMap.put("title","书面审查");
        sqslMap.put("status","2");

        sqslMap.put("detail_desc","书面审查日期");

        String smscrq = "";
        String status = "4";
        if(StringUtils.isNotBlank(yxDate)){
            String sql =" select smscrq from uf_smsc where dwmc = '"+dwid+"' and smscrq >='"+yxDate+"'" ;
            rs.executeQuery(sql);
            if (rs.next()){
                smscrq = rs.getString("smscrq");
                status = "2";
            }

        }



        sqslMap.put("enddate",smscrq);
        sqslMap.put("detail_date",smscrq);
        sqslMap.put("status",status);
        return sqslMap;
    }


    public Map<String,String> getXcscMap(String dwid,String yxDate){
        RecordSet rs = new RecordSet();
        Map<String,String> sqslMap = new HashMap<String,String>();

        sqslMap.put("title","现场审查");
        sqslMap.put("status","2");
        sqslMap.put("finish","0");
        sqslMap.put("detail_desc","现场审查日期");

        String xcscrq = "";
        String status = "4";
        if(StringUtils.isNotBlank(yxDate)){
            String sql =" select xcscrq from uf_xcscjl where dwmc = '"+dwid+"' and xcscrq >='"+yxDate+"'" ;
            rs.executeQuery(sql);
            if (rs.next()) {
                xcscrq = rs.getString("xcscrq");
                status = "2";
            }
        }
        sqslMap.put("enddate",xcscrq);
        sqslMap.put("detail_date",xcscrq);
        sqslMap.put("status",status);
        return sqslMap;
    }


    public Map<String,String> getSpjdMap(String dwid,String yxDate){
        RecordSet rs = new RecordSet();
        Map<String,String> sqslMap = new HashMap<String,String>();

        sqslMap.put("finish","0");
        sqslMap.put("title","审批决定");
        sqslMap.put("status","2");

        sqslMap.put("detail_desc","行政许可日期");

        String xzxkrq = "";
        String status = "4";
        if(StringUtils.isNotBlank(yxDate)){
            String sql =" select xzxkrq from uf_spjdjl where dwmc = '"+dwid+"' and xzxkrq >='"+yxDate+"' " ;
            rs.executeQuery(sql);
            if (rs.next()){
                xzxkrq = rs.getString("xzxkrq");
                status = "2";
            }
        }


        sqslMap.put("enddate",xzxkrq);
        sqslMap.put("detail_date",xzxkrq);
        sqslMap.put("status",status);

        return sqslMap;
    }


    public Map<String,String> getFzrqMap(String dwid,String yxDate){
        RecordSet rs = new RecordSet();
        Map<String,String> sqslMap = new HashMap<String,String>();
        sqslMap.put("finish","0");
        sqslMap.put("detail_desc","发证日期");
        sqslMap.put("title","制证发证");


        String fzrq = "";
        String status = "4";
        if(StringUtils.isNotBlank(yxDate)) {
            String sql = " select fzrq from uf_zzfzjl where dwmc = '" + dwid + "' and fzrq >= '" + yxDate + "' ";
            rs.executeQuery(sql);
            if (rs.next()) {
                fzrq = rs.getString("fzrq");
                status = "2";
            }
        }

        sqslMap.put("enddate",fzrq);
        sqslMap.put("detail_date",fzrq);
        sqslMap.put("status",status);

        return sqslMap;
    }


%>


