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

    String parentCode = request.getParameter("adcode");
    List<Map<String,Object>> dataList= new ArrayList<Map<String,Object>>();
    RecordSet rs = new RecordSet();
    if(StringUtils.isNotBlank(parentCode)){



        String sql =" select t.jd,t.wd,count(1) as cou\n" +
                    " from uf_zzdwdzxx t\n" +
                    " inner join uf_qjsj k on k.id = t.szq\n" +
                    " where k.yb='"+parentCode+"'\n" +
                    " group by t.jd,t.wd ";

        rs.executeQuery(sql);
        while (rs.next()){

            String jd = rs.getString("jd");
            String wd = rs.getString("wd");
            String cou = rs.getString("cou");
            Map<String,Object> dataMap = new HashMap<String,Object>();
            dataMap.put("jd",jd);
            dataMap.put("wd",wd);
            dataMap.put("num",cou);
            dataList.add(dataMap);
        }

        for(int i=0;i<dataList.size();i++){
            Map<String,Object> dataMap  = dataList.get(i);

            String jd = Util.null2String(dataMap.get("jd"));
            String wd = Util.null2String(dataMap.get("wd"));

            Double[] center = new Double[2];

            if(StringUtils.isNotBlank(jd) && StringUtils.isNotBlank(wd)){
                center[0] = Double.parseDouble(jd);
                center[1] =  Double.parseDouble(wd);
            }

            String adcodes = "";
            String names = "";
            String zcdzs = "";
            String jydzs = "";

            sql =   " select id,dwmc,zcdz,jydz\n" +
                     "from uf_zzdwdzxx\n" +
                    " where jd='"+jd+"'\n" +
                    " and wd='"+wd+"'";

            rs.executeQuery(sql);
            while (rs.next()){
                String adcode = rs.getString("id");
                String name = rs.getString("dwmc");
                String zcdz = rs.getString("zcdz");
                String jydz = rs.getString("jydz");

                adcodes += StringUtils.isBlank(adcodes) ? adcode :" ,"+adcode;
                names += StringUtils.isBlank(names) ? name :" \n"+name;

                zcdzs += StringUtils.isBlank(zcdzs) ? names+":"+zcdz :" \n"+names+":"+zcdz;
                jydzs += StringUtils.isBlank(jydzs) ? names+":"+jydz :" \n"+names+":"+jydz;

            }

            dataMap.put("adcode",adcodes);
            dataMap.put("name",zcdzs);
            dataMap.put("center",center);
            dataMap.put("zcdz",zcdzs);
            dataMap.put("jydz",jydzs);
        }
    }

    JSONObject dataJson = new JSONObject();
    dataJson.put("data",dataList);

%>

<%=dataJson.toJSONString() %>

