当前位置: 首页 > >

Java叁重循环逻辑运算+多条SQL拼接,时间处理异步

发布时间:

public String Weekly(String From ,String to,String city) throws Exception{
//存储最终返回结果
String JsonString="[";
if ("".equals(city)) city ="XZ0116";
if(null != From && !"".equals(From) && !"".equals("XZ0116") && null != to && !"".equals(to)){
String[][] Weeks = {{"1","周一"},{"2","周二"},{"3","周三"},{"4","周四"},{"5","周五"},{"6","周六"},{"7","周日"}};
for(int current = 0; current<7 ; current++)
{
//构建主要告警信息SQL
String sqlMajor = "select count(*) as alarmsum from alarminfo where 1=1 and alarmlevel='major' and to_char(starttime-1,'d')='"+Weeks[current][0]+"'";
sqlMajor +=" and province = '"+city+"' and ";
sqlMajor += " starttime>to_date('"+From+"','yyyy-MM-dd') and ";
sqlMajor += " starttime<to_date('"+to+"','yyyy-MM-dd')";
System.out.println(sqlMajor);

//构建紧急告警信息SQL
String sqlCritical = "select count(*) as alarmsum from alarminfo where 1=1 and alarmlevel='critical' and to_char(starttime-1,'d')='"+Weeks[current][0]+"'";
sqlCritical +=" and province = '"+city+"' and ";
sqlCritical += "starttime>to_date('"+From+"','yyyy-MM-dd')and ";
sqlCritical += " starttime<to_date('"+to+"','yyyy-MM-dd')";
System.out.println(sqlCritical);

//---------------------------执行查询--------------------------
//执行查询主要告警的信息
List major = this.alamdao.findBySQL(sqlMajor);
//存储周目信息
String itemstr = "{'week':'"+Weeks[current][1]+"',";
//遍历、保存主要告警结果集
for(Object obj : major){
Map marjorMap =(Map)obj;
itemstr+="'Major':'"+marjorMap.get("alarmsum").toString()+"',";
}
//执行查询紧急告警的信息
List critical = this.alamdao.findBySQL(sqlCritical);
for(Object obj : critical){
Map criticalMap =(Map)obj;
itemstr+="'critical':'"+criticalMap.get("alarmsum")+"'";
}
itemstr.substring(0,itemstr.length()-1);
itemstr+="}";
JsonString+=itemstr+",";
}
//---------------------------查询结束--------------------------
JsonString=JsonString.substring(0,JsonString.length()-1);
}
return JsonString.replace('\'', '\"')+"]";
}



友情链接: