Browse Source

内河低压分析月度报表,修复1月份不计算环比问题

sbj 1 month ago
parent
commit
c58ef79035
1 changed files with 55 additions and 111 deletions
  1. 55 111
      src/main/java/com/shcd/service/impl/SpStatementInlandLowServiceImpl.java

+ 55 - 111
src/main/java/com/shcd/service/impl/SpStatementInlandLowServiceImpl.java

@@ -118,7 +118,7 @@ public class SpStatementInlandLowServiceImpl extends
       // 计算各区
       executeEveryDistrict(originList, lastReportDataList, spStatementInlandLowList, currentMonthDate);
       // 计算合计
-      executeTotal(spStatementInlandLowList, currentMonthDate, lastMonthDate);
+      executeTotal(spStatementInlandLowList, lastMonthDate);
       log.info("最终存储的内河低压分析表1为:{}", JSONObject.toJSONString(spStatementInlandLowList));
       // 查询本月报表数据
       List<SpStatementInlandLow> currentList = this.selectCurrentMonthReport1Count(
@@ -170,7 +170,7 @@ public class SpStatementInlandLowServiceImpl extends
       List<SpStatementInlandLow> spStatementInlandLowList = executeEveryDistrict2(currentMonthData,
           lastReportDataList, currentDate);
       // 计算合计
-      executeTotal2(spStatementInlandLowList, currentDate, lastMonthDate);
+      executeTotal2(spStatementInlandLowList, lastMonthDate);
       // 查询当月是否有数据
       List<SpStatementInlandLow> currentList = this.selectCurrentMonthReport2Count(
           spStatementInlandLowList.get(0).getReportDate());
@@ -230,37 +230,39 @@ public class SpStatementInlandLowServiceImpl extends
         // 计算当年累计 以及 环比
         Calendar thisCalendar = Calendar.getInstance();
         thisCalendar.setTime(DateUtils.stringToDate(currentMonthDate, DateUtils.DATE_FORMAT_12));
-        // 判断是否为1月份
-        if (thisCalendar.get(Calendar.MONTH) == Calendar.JANUARY) {
-          spStatementInlandLow.setBoatUseNumberYearTotal(
-                  spStatementInlandLow.getBoatUseNumberMonth());
-          spStatementInlandLow.setPowerConnHoursYearTotal(
-                  spStatementInlandLow.getPowerConnHoursMonth());
-          spStatementInlandLow.setElectricityUsageYearTotal(
-                  spStatementInlandLow.getElectricityUsageMonth());
-        } else {
-          // 2月才开始计算环比
-          for (SpStatementInlandLow lastReportData : lastReportDataList) {
+
+        for (SpStatementInlandLow lastReportData : lastReportDataList) {
             if (lastReportData.getDistrict().equals(spStatementInlandLow.getDistrict())) {
+              if (thisCalendar.get(Calendar.MONTH) == Calendar.JANUARY) {
+                spStatementInlandLow.setBoatUseNumberYearTotal(
+                    spStatementInlandLow.getBoatUseNumberMonth());
+                spStatementInlandLow.setPowerConnHoursYearTotal(
+                    spStatementInlandLow.getPowerConnHoursMonth());
+                spStatementInlandLow.setElectricityUsageYearTotal(
+                    spStatementInlandLow.getElectricityUsageMonth());
+              }else{
+                spStatementInlandLow.setBoatUseNumberYearTotal(
+                    spStatementInlandLow.getBoatUseNumberMonth()
+                        .add(lastReportData.getBoatUseNumberYearTotal())
+                        .setScale(2, RoundingMode.HALF_UP));
+                spStatementInlandLow.setPowerConnHoursYearTotal(
+                    spStatementInlandLow.getPowerConnHoursMonth()
+                        .add(lastReportData.getPowerConnHoursYearTotal())
+                        .setScale(2, RoundingMode.HALF_UP));
+                spStatementInlandLow.setElectricityUsageYearTotal(
+                    spStatementInlandLow.getElectricityUsageMonth()
+                        .add(lastReportData.getElectricityUsageYearTotal())
+                        .setScale(2, RoundingMode.HALF_UP));
+              }
+              // 计算环比
               spStatementInlandLow.setBoatUseNumberChain(
                       getRate(spStatementInlandLow.getBoatUseNumberMonth(),
                               lastReportData.getBoatUseNumberMonth()));
-              spStatementInlandLow.setBoatUseNumberYearTotal(
-                      spStatementInlandLow.getBoatUseNumberMonth()
-                              .add(lastReportData.getBoatUseNumberYearTotal())
-                              .setScale(2, RoundingMode.HALF_UP));
-              spStatementInlandLow.setPowerConnHoursYearTotal(
-                      spStatementInlandLow.getPowerConnHoursMonth()
-                              .add(lastReportData.getPowerConnHoursYearTotal())
-                              .setScale(2, RoundingMode.HALF_UP));
-              spStatementInlandLow.setElectricityUsageYearTotal(
-                      spStatementInlandLow.getElectricityUsageMonth()
-                              .add(lastReportData.getElectricityUsageYearTotal())
-                              .setScale(2, RoundingMode.HALF_UP));
+
             }
 
           }
-        }
+
         spStatementInlandLowList.add(spStatementInlandLow);
       }
     }catch (Exception e){
@@ -278,8 +280,7 @@ public class SpStatementInlandLowServiceImpl extends
     return result.setScale(2, RoundingMode.HALF_UP);
   }
 
-  private void executeTotal(List<SpStatementInlandLow> spStatementInlandLowList,
-      String currentMonthDate, String lastMonthDate) {
+  private void executeTotal(List<SpStatementInlandLow> spStatementInlandLowList, String lastMonthDate) {
     // 计算合计
     SpStatementInlandLow spStatementInlandLow = new SpStatementInlandLow();
     spStatementInlandLow.setId(String.valueOf(snowflakeMakeConf.snowflakeStringId()));
@@ -316,21 +317,16 @@ public class SpStatementInlandLowServiceImpl extends
         || lastMonthReportData.getBoatUseNumberMonth().equals(BigDecimal.ZERO)) {
       spStatementInlandLow.setBoatUseNumberChain(null);
     } else {
-      String[] strings = currentMonthDate.split("-");
-      if(strings.length == 2 && Integer.valueOf(strings[1]) != 1) {
         BigDecimal rate = (spStatementInlandLow.getBoatUseNumberMonth()
             .subtract(lastMonthReportData.getBoatUseNumberMonth())).multiply(
                 BigDecimal.valueOf(100))
             .divide(lastMonthReportData.getBoatUseNumberMonth(), 2, RoundingMode.HALF_UP);
         spStatementInlandLow.setBoatUseNumberChain(rate);
-      }else{
-        spStatementInlandLow.setBoatUseNumberChain(null);
-      }
     }
     spStatementInlandLowList.add(spStatementInlandLow);
   }
 
-  private void executeTotal2(List<SpStatementInlandLow> spStatementInlandLowList, String currentDate,
+  private void executeTotal2(List<SpStatementInlandLow> spStatementInlandLowList,
       String lastMonthDate) {
     SpStatementInlandLow spStatementInlandLow = new SpStatementInlandLow();
     spStatementInlandLow.setId(String.valueOf(snowflakeMakeConf.snowflakeStringId()));
@@ -367,16 +363,11 @@ public class SpStatementInlandLowServiceImpl extends
         || lastMonthReportData.getBoatUseNumberMonth().equals(BigDecimal.ZERO)) {
       spStatementInlandLow.setBoatUseNumberChain(null);
     } else {
-      String[] strings = currentDate.split("-");
-      if(strings.length == 2 && Integer.valueOf(strings[1]) != 1) {
         BigDecimal rate = (spStatementInlandLow.getBoatUseNumberMonth()
             .subtract(lastMonthReportData.getBoatUseNumberMonth())).multiply(
                 BigDecimal.valueOf(100))
             .divide(lastMonthReportData.getBoatUseNumberMonth(), 2, RoundingMode.HALF_UP);
         spStatementInlandLow.setBoatUseNumberChain(rate);
-      }else{
-        spStatementInlandLow.setBoatUseNumberChain(null);
-      }
     }
     spStatementInlandLowList.add(spStatementInlandLow);
   }
@@ -415,86 +406,39 @@ public class SpStatementInlandLowServiceImpl extends
       // 计算当年累计 以及 环比
       Calendar thisCalendar = Calendar.getInstance();
       thisCalendar.setTime(DateUtils.stringToDate(currentDate, DateUtils.DATE_FORMAT_12));
-      if (thisCalendar.get(Calendar.MONTH) == Calendar.JANUARY) {
-        spStatementInlandLow.setBoatUseNumberYearTotal(
-            spStatementInlandLow.getBoatUseNumberMonth());
-        spStatementInlandLow.setPowerConnHoursYearTotal(
-            spStatementInlandLow.getPowerConnHoursMonth());
-        spStatementInlandLow.setElectricityUsageYearTotal(
-            spStatementInlandLow.getElectricityUsageMonth());
-      } else {
-        // 2月才开始计算环比
-        for (SpStatementInlandLow lastReportData : lastReportDataList) {
+
+      for (SpStatementInlandLow lastReportData : lastReportDataList) {
           if (lastReportData.getDistrict().equals(spStatementInlandLow.getDistrict())) {
+            if (thisCalendar.get(Calendar.MONTH) == Calendar.JANUARY) {
+              spStatementInlandLow.setBoatUseNumberYearTotal(
+                  spStatementInlandLow.getBoatUseNumberMonth());
+              spStatementInlandLow.setPowerConnHoursYearTotal(
+                  spStatementInlandLow.getPowerConnHoursMonth());
+              spStatementInlandLow.setElectricityUsageYearTotal(
+                  spStatementInlandLow.getElectricityUsageMonth());
+            } else {
+              spStatementInlandLow.setBoatUseNumberYearTotal(
+                  spStatementInlandLow.getBoatUseNumberMonth()
+                      .add(lastReportData.getBoatUseNumberYearTotal())
+                      .setScale(2, RoundingMode.HALF_UP));
+              spStatementInlandLow.setPowerConnHoursYearTotal(
+                  spStatementInlandLow.getPowerConnHoursMonth()
+                      .add(lastReportData.getPowerConnHoursYearTotal())
+                      .setScale(2, RoundingMode.HALF_UP));
+              spStatementInlandLow.setElectricityUsageYearTotal(
+                  spStatementInlandLow.getElectricityUsageMonth()
+                      .add(lastReportData.getElectricityUsageYearTotal())
+                      .setScale(2, RoundingMode.HALF_UP));
+            }
+            // 计算环比
             spStatementInlandLow.setBoatUseNumberChain(
                 getRate(spStatementInlandLow.getBoatUseNumberMonth(),
                     lastReportData.getBoatUseNumberMonth()));
-            spStatementInlandLow.setBoatUseNumberYearTotal(
-                spStatementInlandLow.getBoatUseNumberMonth()
-                    .add(lastReportData.getBoatUseNumberYearTotal())
-                    .setScale(2, RoundingMode.HALF_UP));
-            spStatementInlandLow.setPowerConnHoursYearTotal(
-                spStatementInlandLow.getPowerConnHoursMonth()
-                    .add(lastReportData.getPowerConnHoursYearTotal())
-                    .setScale(2, RoundingMode.HALF_UP));
-            spStatementInlandLow.setElectricityUsageYearTotal(
-                spStatementInlandLow.getElectricityUsageMonth()
-                    .add(lastReportData.getElectricityUsageYearTotal())
-                    .setScale(2, RoundingMode.HALF_UP));
+
           }
         }
-      }
       spStatementInlandLowList.add(spStatementInlandLow);
     }
-//    for (ShorePowerConnRecordInfoVo currentMonth : currentMonthData) {
-//      SpStatementInlandLow spStatementInlandLow = new SpStatementInlandLow();
-//      spStatementInlandLow.setId(String.valueOf(snowflakeMakeConf.snowflakeId()));
-//      spStatementInlandLow.setReportDate(
-//          DateUtils.stringToDate(currentDate, DateUtils.DATE_FORMAT_12));
-//      spStatementInlandLow.setDistrict(
-//          ShorePowerConnRecordInfoEnum.getByArea(Integer.parseInt(currentMonth.getArea()))
-//              .getArea());
-//      spStatementInlandLow.setSort(
-//          AreaSortEnum.getByArea(spStatementInlandLow.getDistrict()).getSort());
-//      spStatementInlandLow.setType(2);
-//      spStatementInlandLow.setBoatUseNumberMonth(currentMonth.getTotal());
-//      // 使用岸电小时在查询数据库时已经转换为小时计算
-//      spStatementInlandLow.setPowerConnHoursMonth(currentMonth.getDuration());
-//      spStatementInlandLow.setElectricityUsageMonth(currentMonth.getElect());
-//      // 计算当年累计 以及 环比
-//      Calendar thisCalendar = Calendar.getInstance();
-//      thisCalendar.setTime(DateUtils.stringToDate(currentDate, DateUtils.DATE_FORMAT_12));
-//      if (thisCalendar.get(Calendar.MONTH) == Calendar.JANUARY) {
-//        spStatementInlandLow.setBoatUseNumberYearTotal(
-//            spStatementInlandLow.getBoatUseNumberMonth());
-//        spStatementInlandLow.setPowerConnHoursYearTotal(
-//            spStatementInlandLow.getPowerConnHoursMonth());
-//        spStatementInlandLow.setElectricityUsageYearTotal(
-//            spStatementInlandLow.getElectricityUsageMonth());
-//      } else {
-//        // 2月才开始计算环比
-//        for (SpStatementInlandLow lastReportData : lastReportDataList) {
-//          if (lastReportData.getDistrict().equals(spStatementInlandLow.getDistrict())) {
-//            spStatementInlandLow.setBoatUseNumberChain(
-//                getRate(spStatementInlandLow.getBoatUseNumberMonth(),
-//                    lastReportData.getBoatUseNumberMonth()));
-//            spStatementInlandLow.setBoatUseNumberYearTotal(
-//                spStatementInlandLow.getBoatUseNumberMonth()
-//                    .add(lastReportData.getBoatUseNumberYearTotal())
-//                    .setScale(2, RoundingMode.HALF_UP));
-//            spStatementInlandLow.setPowerConnHoursYearTotal(
-//                spStatementInlandLow.getPowerConnHoursMonth()
-//                    .add(lastReportData.getPowerConnHoursYearTotal())
-//                    .setScale(2, RoundingMode.HALF_UP));
-//            spStatementInlandLow.setElectricityUsageYearTotal(
-//                spStatementInlandLow.getElectricityUsageMonth()
-//                    .add(lastReportData.getElectricityUsageYearTotal())
-//                    .setScale(2, RoundingMode.HALF_UP));
-//          }
-//        }
-//      }
-//      spStatementInlandLowList.add(spStatementInlandLow);
-//    }
     return spStatementInlandLowList;
   }
 }