SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
boolean isset=false;
Long small=-1l;
Long bigger=-1l;
JSONArray jsonStr=new JSONArray(queryStr.trim());
JSONArray jsonStr_new=new JSONArray();
for(int j=0;j<jsonStr.length();j++)
{
JSONObject obj=jsonStr.getJSONObject(j);
if(!obj.has("thedate"))
{
jsonStr_new.put(obj);
continue;
}
}
for(int j=0;j<jsonStr.length();j++)
{
JSONObject obj=jsonStr.getJSONObject(j);
if(!obj.has("thedate"))
{
continue;
}
JSONObject thedate=obj.getJSONObject("thedate");
Integer operate=Integer.parseInt(thedate.get("operate").toString());
String[] val=WebServiceParams.parseFqValue(thedate.getString("value"), operate).split(",");
if(operate==1 ||operate==5||operate==6||operate==7||operate==8||operate==9)//=,range
{
Long min=Long.MAX_VALUE;
Long max=Long.MIN_VALUE;
for(String day:val)
{
Date d=fmt.parse(day.replaceAll("-", ""));
Long time=d.getTime();
max=Math.max(max, time);
min=Math.min(min, time);
isset=true;
}
String[] days=getKmeans(min, max);
for(String day:days)
{
rtn.add(day);
}
break;
}
if(operate==13||operate==3)//<,<=
{
for(String day:val)
{
Date d=fmt.parse(day.replaceAll("-", ""));
Long time=d.getTime()+(operate==3?0:1);
small=small>0?Math.min(small, time):time;
}
}
if(operate==14||operate==4)//>,>=
{
for(String day:val)
{
Date d=fmt.parse(day.replaceAll("-", ""));
Long time=d.getTime()-(operate==4?0:1);
bigger=bigger>0?Math.max(bigger, time):time;
}
}
if(bigger>0&&small>0)
{
isset=true;
String[] days=getKmeans(small, bigger);
for(String day:days)
{
rtn.add(day);
}
small=Long.MAX_VALUE;
bigger=Long.MIN_VALUE;
break;
}
}
if(!isset)
{
throw new Exception("no thedate");
}
String[] rtnarr=new String[rtn.size()];
KmeansQueryParse kmeans=new KmeansQueryParse();
kmeans.days=rtn.toArray(rtnarr);
kmeans.queryStr=jsonStr_new.toString();
return kmeans;
}