public void town_data_selectforecast(){
List<Town> t= townManager.select(town);
if(t.size()<=0){
Date beginDate = new Date();
t = this.findTown(beginDate);
}
writeJson(t);
}
/**
* 递归查询
* @param data日期
* @return
*/
private List<Town> findTown(Date data){
List<Town> townlist =new ArrayList<Town>();
Town town=new Town();
SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
String startTime = dft.format(data.getTime());
Calendar date = Calendar.getInstance();
date.setTime(data);
date.set(Calendar.DATE, date.get(Calendar.DATE) - 1);
Date endDate=null;
try {
endDate = dft.parse(dft.format(date.getTime()));
String endTime = dft.format(date.getTime());
town.setTown_time(endTime);
town.setType("3");
townlist=townManager.select(town);
} catch (Exception e) {
e.printStackTrace();
}
if(townlist.size()>0){
return townlist;
}else{
return findTown(endDate);
}
}