String rtn= MdrillService.result(projectName, null, startStr,rowsStr, queryStr, null, fl, groupby, sort, order, null, null);
HashMap<String,Object> rtna=new HashMap<String, Object>();
JSONObject jsonObj = new JSONObject(rtn);
if(!jsonObj.getString("code").equals("1"))
{
rtna.put("code",0);
rtna.put("msg","服务器异常,请稍后再试");
hb.stop();
return new JSONObject(rtna).toString();
}
JSONArray list=jsonObj.getJSONObject("data").getJSONArray("docs");
ArrayList<Object> data=new ArrayList< Object>();
ArrayList<String> showFields = WebServiceParams.showFields(fl);
String flkey=groupby;
String flvalue="";
for (String showfield : showFields) {
StateField showfielda=WebServiceParams.parseStat(showfield);
if(showfielda.isstat)
{
flvalue=showfield;
}
}
JSONArray filterother=new JSONArray(WebServiceParams.query(queryStr));
JSONArray filterother2=new JSONArray();
for(int i=0;i<list.length();i++)
{
JSONObject item=list.getJSONObject(i);
JSONObject newitem=new JSONObject();
newitem.put("label", String.valueOf(item.get(flkey)));
newitem.put("data", Double.parseDouble(item.getString(flvalue)));
data.add(newitem);
JSONObject newitemfilter=new JSONObject();
newitemfilter.put("key", flkey);
newitemfilter.put("operate", "2");
newitemfilter.put("value", String.valueOf(item.get(flkey)));
filterother.put(newitemfilter);
filterother2.put(newitemfilter);
}
if("Y".equals(showOther))
{
String rtnother= MdrillService.result(projectName, null, startStr,rowsStr, filterother.toString(), null, flvalue, null, sort, order, null, null);
JSONObject jsonObjother = new JSONObject(rtnother);
if(jsonObjother.getString("code").equals("1"))
{
JSONArray listother=jsonObjother.getJSONObject("data").getJSONArray("docs");
for(int i=0;i<listother.length();i++)
{
JSONObject item=listother.getJSONObject(i);
Double d=Double.parseDouble(item.getString(flvalue));
if(d>0)
{
JSONObject newitem=new JSONObject();
newitem.put("label", "其他");
newitem.put("data",d );
data.add(newitem);
}
}
}
}
hb.stop();
rtna.put("code", 1);
rtna.put("其他", filterother2);
rtna.put("data", data);
String rtnstr= new JSONObject(rtna).toString();
out.write(rtnstr);
return rtnstr;
}