Commit 9c7c388f9b0cb55d197b3520a6c9027004c20abb

Authored by 娄高锋
1 parent f07de4cc

新增年度总能耗接口,给投控。(周文彬)

src/main/java/com/bsth/server_rs/bigdata/BigdataService.java
... ... @@ -1576,4 +1576,102 @@ public class BigdataService {
1576 1576 return resMap;
1577 1577 }
1578 1578  
  1579 + /**
  1580 + * 年度总能耗(单位:万公里)(临港给投控的接口,周文彬)
  1581 + */
  1582 + @GET
  1583 + @Path("/findConsumptionByYear/all/{year}")
  1584 + public Map<String, Object> findConsumptionByYear(@PathParam("year") String year) {
  1585 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1586 + SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
  1587 + SimpleDateFormat monFormat = new SimpleDateFormat("MM");
  1588 + Map<String, Object> resMap = new HashMap<String, Object>();
  1589 + try {
  1590 + logger.info(year);
  1591 + Date parse = yearFormat.parse(year);
  1592 + String date1 = year + "-01-01", date2 = year + "-12-31";
  1593 + dateFormat.parse(year + "-01-01");
  1594 + dateFormat.parse(year + "-12-31");
  1595 + List<String> strList = new ArrayList<>();
  1596 + strList.add(date1);
  1597 + strList.add(date2);
  1598 + BigDecimal zyh = new BigDecimal(0), zdh = new BigDecimal(0), zqh = new BigDecimal(0);
  1599 + String ylbSql = "select yh from bsth_c_ylb "
  1600 + + "where rq >= ? and rq <= ? ";
  1601 + List<Map<String, Object>> ylbList=jdbcTemplate.query(ylbSql, strList.toArray(),
  1602 + new RowMapper<Map<String, Object>>(){
  1603 + @Override
  1604 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1605 + Map<String, Object> m=new HashMap<String,Object>();
  1606 + m.put("yh", rs.getString("yh"));
  1607 + return m;
  1608 + }
  1609 + });
  1610 +
  1611 +// logger.info(list.size()+"");
  1612 +// HashMap<String, BigDecimal> monMap = new HashMap<String, BigDecimal>();
  1613 + for(Map<String, Object> m : ylbList){
  1614 + if(m.containsKey("yh") && m.get("yh").toString().length() > 0){
  1615 + try {
  1616 + zyh = zyh.add(new BigDecimal(m.get("yh").toString()));
  1617 + } catch (Exception e) {
  1618 + continue;
  1619 + }
  1620 + }
  1621 + }
  1622 +
  1623 + String dlbSql = "select hd from bsth_c_dlb "
  1624 + + "where rq >= ? and rq <= ? ";
  1625 + List<Map<String, Object>> dlbList=jdbcTemplate.query(dlbSql, strList.toArray(),
  1626 + new RowMapper<Map<String, Object>>(){
  1627 + @Override
  1628 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1629 + Map<String, Object> m=new HashMap<String,Object>();
  1630 + m.put("hd", rs.getString("hd"));
  1631 + return m;
  1632 + }
  1633 + });
  1634 +
  1635 + for(Map<String, Object> m : dlbList){
  1636 + if(m.containsKey("hd") && m.get("hd").toString().length() > 0){
  1637 + try {
  1638 + zdh = zdh.add(new BigDecimal(m.get("hd").toString()));
  1639 + } catch (Exception e) {
  1640 + continue;
  1641 + }
  1642 + }
  1643 + }
  1644 +
  1645 + String qlbSql = "select hn from bsth_c_qlb "
  1646 + + "where rq >= ? and rq <= ? ";
  1647 + List<Map<String, Object>> qlbList=jdbcTemplate.query(qlbSql, strList.toArray(),
  1648 + new RowMapper<Map<String, Object>>(){
  1649 + @Override
  1650 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1651 + Map<String, Object> m=new HashMap<String,Object>();
  1652 + m.put("hn", rs.getString("hn"));
  1653 + return m;
  1654 + }
  1655 + });
  1656 +
  1657 + for(Map<String, Object> m : qlbList){
  1658 + if(m.containsKey("hn") && m.get("hn").toString().length() > 0){
  1659 + try {
  1660 + zqh = zdh.add(new BigDecimal(m.get("hn").toString()));
  1661 + } catch (Exception e) {
  1662 + continue;
  1663 + }
  1664 + }
  1665 + }
  1666 +
  1667 + resMap.put("oil", zyh.doubleValue());
  1668 + resMap.put("electricity", zdh.doubleValue());
  1669 + resMap.put("hydrogen", zqh.doubleValue());
  1670 + } catch (Exception e) {
  1671 + // TODO: handle exception
  1672 + e.printStackTrace();
  1673 + }
  1674 + return resMap;
  1675 + }
  1676 +
1579 1677 }
... ...