<%@ 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 language="java" contentType="text/html; charset=UTF-8" %>
<%

    String sqdw = request.getParameter("sqdw");
    List<Map<String,String>> list = new ArrayList<Map<String,String>>();
    RecordSet rs = new RecordSet();
    if(StringUtils.isNotBlank(sqdw)){


        String sql =" select id,'' as parentid,gdmc as name,'' as cgbl,'' as gdlx from \n" +
                    " uf_gd\n" +
                    " where id = '" + sqdw + "'"+
                    " union \n" +
                    " select p.id,sqdw as parentid,p.gdmc as name,t.cgbl,k.selectname as gdlx\n" +
                    " from uf_gdxx t\n" +
                    " inner join uf_gd p on p.id = t.cggd\n" +
                    " left join (\n" +
                    "   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='uf_gd' ) and fieldname='gdlx' \n" +
                    "       and detailtable  is null\n" +
                    "   )  \n" +
                    " ) k on k.selectvalue = p.gdlx\n" +
                    " where sqdw = '"+sqdw+"'" ;

        rs.executeQuery(sql);
        while (rs.next()){
            String parentid = rs.getString("parentid");
            String id = rs.getString("id");
            String name = rs.getString("name");
            String cgbl = rs.getString("cgbl");
            String gdlx = rs.getString("gdlx");

            Map<String,String> map = new HashMap<String,String>();
            map.put("id",id);
            map.put("parentid",parentid);
            map.put("name",name);
            map.put("cgbl",cgbl);
            map.put("gdlx",gdlx);
            list.add(map);
        }
    }

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

%>

<%=dataJson.toJSONString() %>

