查出某个特定时间一小时内,两小时内,N小时内的累计和

来源:互联网 发布:mac截图怎么发给别人 编辑:程序博客网 时间:2024/04/29 10:58
public List<Map<String,Object>> rainchart(String year,String stcd,Date tmbegin, Date tmend) {
StringBuilder sql1 = new StringBuilder();
StringBuilder sql = new StringBuilder();
JdbcTemplate temp1=allJDBCTemplate.getJdbcTemplate();

sql1.append("select top 1 rain,tm from dt_rain where stcd ='"+stcd+"'  and tm between '"+tmbegin+"' and '"+tmend+"' order by rain desc");
List<Map<String, Object>> list1 =temp1.queryForList(sql1.toString());
List<Map<String, Object>> listall=new ArrayList(6*list1.size());
for(int i=0;i<list1.size();i++){


// Timestamp tm00=new Timestamp( (long) list1.get(i).get("tm"));
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String tm0 = sdf.format(list1.get(i).get("tm"));

Integer shi = Integer.parseInt(tm0.substring(11, 13));
Integer tian = Integer.parseInt(tm0.substring(8, 10));

String shi1 = null;
String shi6 = null;
String shi12 = null;
String shi122 = null;
String shi24 = null;
String shi48 = null;
String shi72 = null;

//1小时
if (shi < 9) {
int shi11 = shi + 1;
shi1 = "0" + String.valueOf(shi11);
} else {
shi1 = String.valueOf(shi + 1);
}
//6小时
if (shi < 3) {
int shi61 = shi + 6;
shi6 = "0" + String.valueOf(shi61);
} else {
shi6 = String.valueOf(shi + 6);
}

 
// 12小时
String tm12 = null;
if (shi < 13) {
int shi121 = shi + 12;
shi12 = String.valueOf(shi121);
tm12 = tm0.substring(0, 10) + " " + shi12
+ tm0.substring(13, 19);
} else {
String tian12a = null;
if (tian < 31) {
int tian12 = tian + 1;
tian12a = String.valueOf(tian12);
}
shi122 = "06";//06为大概给的时间
tm12 = tm0.substring(0, 8) + tian12a + " " + shi122
+ tm0.substring(13, 19);
}
// 一天(24小时),两天(48小时),三天(72小时)
if (tian < 31) {
int shi241 = tian + 1;
shi24 = String.valueOf(shi241);
}
if (tian < 30) {
int shi481 = tian + 2;
shi48 = String.valueOf(shi481);
}
if (tian < 29) {
int shi721 = tian + 3;
shi72 = String.valueOf(shi721);
}
String tm1 = tm0.substring(0, 10) + " " + shi1
+ tm0.substring(13, 19);
String tm6 = tm0.substring(0, 10) + " " + shi6
+ tm0.substring(13, 19);
String tm24 = tm0.substring(0, 8)  + shi24
+ tm0.substring(10, 19);
String tm48 = tm0.substring(0, 8)  + shi48
+ tm0.substring(10, 19);
String tm72 = tm0.substring(0, 8)  + shi72
+ tm0.substring(10, 19);





sql.append("(select rain as rain,'"+tm0+"' as tm from dt_rain where stcd ='"+stcd+"'  and tm='"+tm0+"')");
sql.append(" union all ");
sql.append("(select sum(rain) as rain,'"+tm1+"' as tm  from dt_rain where stcd ='"+stcd+"'  and tm between '"+tm0+"' and '"+tm1+"' )"); 
sql.append(" union all ");
sql.append("(select sum(rain) as rain,'"+tm6+"' as tm  from dt_rain where stcd ='"+stcd+"'  and tm between '"+tm0+"' and '"+tm6+"' )"); 
sql.append(" union all ");
sql.append("(select sum(rain) as rain,'"+tm12+"' as tm  from dt_rain where stcd ='"+stcd+"'  and tm between '"+tm0+"' and '"+tm12+"' )"); 
sql.append(" union all ");
sql.append("(select sum(rain) as rain,'"+tm24+"' as tm  from dt_rain where stcd ='"+stcd+"'  and tm between '"+tm0+"' and '"+tm24+"' )"); 
sql.append(" union all ");
sql.append("(select sum(rain) as rain,'"+tm48+"' as tm  from dt_rain where stcd ='"+stcd+"'  and tm between '"+tm0+"' and '"+tm48+"' )"); 
sql.append(" union all ");
sql.append("(select sum(rain) as rain,'"+tm72+"' as tm  from dt_rain where stcd ='"+stcd+"'  and tm between '"+tm0+"' and '"+tm72+"' )"); 

JdbcTemplate temp2=allJDBCTemplate.getJdbcTemplate();
List<Map<String, Object>> list =temp2.queryForList(sql.toString());

listall.addAll(list);
}



return listall;
}
0 0
原创粉丝点击