Commit 15258e9d247a80db8e9eb529226204040bebc11f
1 parent
c6475169
按月份查询油电氢月度百公里能耗
Showing
1 changed file
with
96 additions
and
0 deletions
src/main/java/com/bsth/server_rs/bigdata/BigscreenService.java
| ... | ... | @@ -3312,6 +3312,102 @@ public class BigscreenService { |
| 3312 | 3312 | return resList; |
| 3313 | 3313 | } |
| 3314 | 3314 | |
| 3315 | + /** 按月查询油电氢百公里能耗(临港大屏,顾婷婷) | |
| 3316 | + * @throws ParseException */ | |
| 3317 | + @GET | |
| 3318 | + @Path("/selectData/getConsumeByMonth/{month}") | |
| 3319 | + public Map<String, Object> getConsumeByMonth(@PathParam("month") String month) throws Exception{ | |
| 3320 | + Map<String, Object> resMap = new HashMap<String, Object>(); | |
| 3321 | + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | |
| 3322 | + SimpleDateFormat monFormat = new SimpleDateFormat("yyyy-MM"); | |
| 3323 | + | |
| 3324 | + Date m1 = monFormat.parse(month); | |
| 3325 | + Date m2 = new Date(); | |
| 3326 | + m2.setTime(m1.getTime() + 32l*1000*60*60*24); | |
| 3327 | + m2 = monFormat.parse(monFormat.format(m2)); | |
| 3328 | + m2.setTime(m2.getTime() - 1l*1000*60*60*24); | |
| 3329 | + | |
| 3330 | + String date1 = dateFormat.format(m1); | |
| 3331 | + String date2 = dateFormat.format(m2); | |
| 3332 | + | |
| 3333 | + String ylbSql="SELECT yh, zlc from bsth_c_ylb where rq >= ? and rq <= ? " | |
| 3334 | + + " and yh is not null and yh > 0 and zlc is not null and zlc > 0 "; | |
| 3335 | + List<Map<String, Object>> ylbList=jdbcTemplate.query(ylbSql, new Object[]{date1, date2}, | |
| 3336 | + new RowMapper<Map<String, Object>>(){ | |
| 3337 | + @Override | |
| 3338 | + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 3339 | + Map<String, Object> m=new HashMap<String,Object>(); | |
| 3340 | + m.put("yh", rs.getString("yh")); | |
| 3341 | + m.put("zlc", rs.getString("zlc")); | |
| 3342 | + return m; | |
| 3343 | + } | |
| 3344 | + }); | |
| 3345 | + | |
| 3346 | + String dlbSql="SELECT hd, zlc from bsth_c_dlb where rq >= ? and rq <= ? " | |
| 3347 | + + " and hd is not null and hd > 0 and zlc is not null and zlc > 0 "; | |
| 3348 | + List<Map<String, Object>> dlbList=jdbcTemplate.query(dlbSql, new Object[]{date1, date2}, | |
| 3349 | + new RowMapper<Map<String, Object>>(){ | |
| 3350 | + @Override | |
| 3351 | + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 3352 | + Map<String, Object> m=new HashMap<String,Object>(); | |
| 3353 | + m.put("hd", rs.getString("hd")); | |
| 3354 | + m.put("zlc", rs.getString("zlc")); | |
| 3355 | + return m; | |
| 3356 | + } | |
| 3357 | + }); | |
| 3358 | + | |
| 3359 | + String qlbSql="SELECT hn, zlc from bsth_c_qlb where rq >= ? and rq <= ? " | |
| 3360 | + + " and hn is not null and hn > 0 and zlc is not null and zlc > 0 "; | |
| 3361 | + List<Map<String, Object>> qlbList=jdbcTemplate.query(qlbSql, new Object[]{date1, date2}, | |
| 3362 | + new RowMapper<Map<String, Object>>(){ | |
| 3363 | + @Override | |
| 3364 | + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 3365 | + Map<String, Object> m=new HashMap<String,Object>(); | |
| 3366 | + m.put("hn", rs.getString("hn")); | |
| 3367 | + m.put("zlc", rs.getString("zlc")); | |
| 3368 | + return m; | |
| 3369 | + } | |
| 3370 | + }); | |
| 3371 | + | |
| 3372 | + BigDecimal yh = new BigDecimal(0), yh_zlc = new BigDecimal(0), | |
| 3373 | + hd = new BigDecimal(0), hd_zlc = new BigDecimal(0), | |
| 3374 | + hn = new BigDecimal(0), hn_zlc = new BigDecimal(0); | |
| 3375 | + for(Map<String, Object> m : ylbList){ | |
| 3376 | + yh = yh.add(new BigDecimal(m.get("yh").toString())); | |
| 3377 | + yh_zlc = yh_zlc.add(new BigDecimal(m.get("zlc").toString())); | |
| 3378 | + } | |
| 3379 | + | |
| 3380 | + for(Map<String, Object> m : dlbList){ | |
| 3381 | + hd = hd.add(new BigDecimal(m.get("hd").toString())); | |
| 3382 | + hd_zlc = hd_zlc.add(new BigDecimal(m.get("zlc").toString())); | |
| 3383 | + } | |
| 3384 | + | |
| 3385 | + for(Map<String, Object> m : qlbList){ | |
| 3386 | + hn = hn.add(new BigDecimal(m.get("hn").toString())); | |
| 3387 | + hn_zlc = hn_zlc.add(new BigDecimal(m.get("zlc").toString())); | |
| 3388 | + } | |
| 3389 | + | |
| 3390 | + if(yh_zlc.compareTo(new BigDecimal(0)) > 0){ | |
| 3391 | + resMap.put("oil", yh.divide(yh_zlc, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).doubleValue()); | |
| 3392 | + } else { | |
| 3393 | + resMap.put("oil", 0); | |
| 3394 | + } | |
| 3395 | + if(hd_zlc.compareTo(new BigDecimal(0)) > 0){ | |
| 3396 | + resMap.put("electricity", hd.divide(hd_zlc, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).doubleValue()); | |
| 3397 | + } else { | |
| 3398 | + resMap.put("electricity", 0); | |
| 3399 | + } | |
| 3400 | + if(hn_zlc.compareTo(new BigDecimal(0)) > 0){ | |
| 3401 | + resMap.put("hydrogen", hn.divide(hn_zlc, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).doubleValue()); | |
| 3402 | + } else { | |
| 3403 | + resMap.put("hydrogen", 0); | |
| 3404 | + } | |
| 3405 | + | |
| 3406 | + | |
| 3407 | + | |
| 3408 | + return resMap; | |
| 3409 | + } | |
| 3410 | + | |
| 3315 | 3411 | // public static void main(String[] args){ |
| 3316 | 3412 | // |
| 3317 | 3413 | // } | ... | ... |