Commit 999dd10f763633e39f415c5d59207c4929c5c990

Authored by 娄高锋
1 parent 4e7fc07e

加个临港给投控年度总里程的接口

src/main/java/com/bsth/server_rs/bigdata/BigdataService.java
1 package com.bsth.server_rs.bigdata; 1 package com.bsth.server_rs.bigdata;
2 2
  3 +import java.math.BigDecimal;
3 import java.sql.ResultSet; 4 import java.sql.ResultSet;
4 import java.sql.SQLException; 5 import java.sql.SQLException;
5 import java.text.DecimalFormat; 6 import java.text.DecimalFormat;
@@ -1483,7 +1484,9 @@ public class BigdataService { @@ -1483,7 +1484,9 @@ public class BigdataService {
1483 return resList; 1484 return resList;
1484 } 1485 }
1485 1486
1486 - //全部挂牌线路 1487 + /**
  1488 + * 全部挂牌线路
  1489 + */
1487 @GET 1490 @GET
1488 @Path("/findLinePlate/all") 1491 @Path("/findLinePlate/all")
1489 public List<Map<String, Object>> findLinePlate() { 1492 public List<Map<String, Object>> findLinePlate() {
@@ -1509,4 +1512,51 @@ public class BigdataService { @@ -1509,4 +1512,51 @@ public class BigdataService {
1509 return resList; 1512 return resList;
1510 } 1513 }
1511 1514
  1515 + /**
  1516 + * 年度总里程(单位:万公里)(临港给投控的接口,周文彬)
  1517 + */
  1518 + @GET
  1519 + @Path("/findMileageByYear/all/{year}")
  1520 + public Map<String, Object> findMileageByYear(@PathParam("year") String year) {
  1521 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1522 + SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
  1523 + Map<String, Object> resMap = new HashMap<String, Object>();
  1524 + try {
  1525 + logger.info(year);
  1526 + Date parse = yearFormat.parse(year);
  1527 + String date1 = year + "-01-01", date2 = year + "-12-31";
  1528 + dateFormat.parse(year + "-01-01");
  1529 + dateFormat.parse(year + "-12-31");
  1530 + List<String> strList = new ArrayList<>();
  1531 + strList.add(date1);
  1532 + strList.add(date2);
  1533 + String sql = "select sjzgl from bsth_c_calc_count "
  1534 + + "where date >= ? and date <= ? ";
  1535 + logger.info(sql);
  1536 + logger.info(date1 + "><" + date2);
  1537 + List<Map<String, Object>> list=jdbcTemplate.query(sql, strList.toArray(),
  1538 + new RowMapper<Map<String, Object>>(){
  1539 + @Override
  1540 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1541 + Map<String, Object> m=new HashMap<String,Object>();
  1542 + m.put("sjzgl", rs.getString("sjzgl"));
  1543 + return m;
  1544 + }
  1545 + });
  1546 +
  1547 + BigDecimal zgl = new BigDecimal(0);
  1548 + logger.info(list.size()+"");
  1549 + for(Map<String, Object> m : list){
  1550 + if(m.containsKey("sjzgl") && m.get("sjzgl").toString().length() > 0){
  1551 + zgl = zgl.add(new BigDecimal(m.get("sjzgl").toString()));
  1552 + }
  1553 + }
  1554 + resMap.put("mileage", zgl.divide(new BigDecimal(10000), 3, BigDecimal.ROUND_HALF_UP).doubleValue());
  1555 + } catch (Exception e) {
  1556 + // TODO: handle exception
  1557 + e.printStackTrace();
  1558 + }
  1559 + return resMap;
  1560 + }
  1561 +
1512 } 1562 }