Parcourir la source

Merge branch 'shorepower' of http://47.101.207.123:3000/gh_department/ScheduleWork into shorepower

# Conflicts:
#	src/main/java/com/shcd/mapper/SpStatementShipUsageMonthMapper.java
#	src/main/java/com/shcd/service/impl/SpStatementShipUsageMonthServiceImpl.java
#	src/main/resources/mapper/SpStatementShipUsageMonthMapper.xml
zoro il y a 10 mois
Parent
commit
be69ddc94a

+ 11 - 6
src/main/java/com/shcd/mapper/SpStatementShipUsageMonthMapper.java

@@ -17,8 +17,8 @@ import java.util.List;
 public interface SpStatementShipUsageMonthMapper extends BaseMapper<SpStatementShipUsageMonth> {
 
   List<SpStatementShipUsageDetail> selectOriginDataMonth(
-          @Param("thisDate") Date thisDate, @Param("lastDate") Date lastDate,
-          @Param("lastCycleStart") Date lastCycleStart, @Param("lastCycleEnd") Date lastCycleEnd);
+      @Param("thisDate") Date thisDate, @Param("lastDate") Date lastDate,
+      @Param("lastCycleStart") Date lastCycleStart, @Param("lastCycleEnd") Date lastCycleEnd);
 
   SpStatementShipUsageMonthVo selectOriginDataYear(@Param("toDate") String thisDate);
 
@@ -67,11 +67,16 @@ public interface SpStatementShipUsageMonthMapper extends BaseMapper<SpStatementS
       @Param("end") Date end);
 
   List<SpStatementShipUsageDetail> selectNhAndWgMonth(@Param("thisDate") Date thisDate,
-                                                      @Param("lastDate") Date lastDate,
-                                                      @Param("lastCycleStart") Date lastCycleStart,
-                                                      @Param("lastCycleEnd") Date lastCycleEnd);
+      @Param("lastDate") Date lastDate,
+      @Param("lastCycleStart") Date lastCycleStart,
+      @Param("lastCycleEnd") Date lastCycleEnd);
+
+  SpStatementShipUsageMonthVo selectNhAndWgLastMonthSum(@Param("thisMonth") Date thisDate);
 
-    SpStatementShipUsageMonthVo selectNhAndWgLastMonthSum(@Param("thisMonth") Date thisDate);
+  List<ShorePowerDataVo> selectPortIdEq1146(@Param("currentCycleStart") String currentCycleStart,
+      @Param("currentCycleEnd") String currentCycleEnd,
+      @Param("lastCycleStart") String lastCycleStart,
+      @Param("lastCycleEnd") String lastCycleEnd);
 
   List<SpStatementShipUsageDetailV2> selectNhAndWgMonthV2(@Param("thisDate") Date thisDate,@Param("lastDate") Date lastDate);
 

+ 84 - 15
src/main/java/com/shcd/service/impl/SpStatementShipUsageMonthServiceImpl.java

@@ -1,6 +1,7 @@
 package com.shcd.service.impl;
 
 import cn.hutool.core.lang.generator.SnowflakeGenerator;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.shanghaigeography.Util.DateUtils;
@@ -11,6 +12,7 @@ import com.shcd.mapper.SpStatementShipUsageMonthMapper;
 import com.shcd.service.SpStatementSgService;
 import com.shcd.service.SpStatementShipUsageMonthService;
 import com.shcd.service.SpStatementYearAnalysisService;
+import com.shcd.vo.ShorePowerDataVo;
 import com.shcd.vo.SpStatementShipUsageDetail;
 import com.shcd.vo.SpStatementShipUsageDetailV2;
 import com.shcd.vo.SpStatementShipUsageMonthVo;
@@ -27,6 +29,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
 /**
  * @author csdl
  * @description 针对表【SP_STATEMENT_SHIP_USAGE_MONTH(上海市长江经济带船舶使用岸电情况报表)】的数据库操作Service实现
@@ -85,7 +89,8 @@ public class SpStatementShipUsageMonthServiceImpl extends
       Date toDate = DateUtils.stringToDate(thisYear + "-" + thisMonth + "-01", "yyyy-MM-dd");
       Date toDateBegin = DateUtils.stringToDate(thisYear + "-01-01", "yyyy-MM-dd");
       Date yearCountBegin = DateUtils.stringToDate(thisYear - 1 + "-12-25", "yyyy-MM-dd");
-      Date lastCycleStart = DateUtils.stringToDate(lastCycleYear + "-" + lastCycleMonth + "-25", "yyyy-MM-dd");
+      Date lastCycleStart = DateUtils.stringToDate(lastCycleYear + "-" + lastCycleMonth + "-25",
+          "yyyy-MM-dd");
       Date lastCycleEnd = DateUtils.stringToDate(lastYear + "-" + lastMonth + "-25", "yyyy-MM-dd");
       //删除
       String dateStr = thisYear + "-" + thisMonth + "-01";
@@ -98,7 +103,8 @@ public class SpStatementShipUsageMonthServiceImpl extends
       spStatementShipUsageMonthMapper.deleteByDate(dateStr);
       //先算本次月度的
       CompletableFuture<List<SpStatementShipUsageDetail>> future1 = CompletableFuture.supplyAsync(
-          () -> spStatementShipUsageMonthMapper.selectOriginDataMonth(thisDate, lastDate,lastCycleStart,lastCycleEnd));
+          () -> spStatementShipUsageMonthMapper.selectOriginDataMonth(thisDate, lastDate,
+              lastCycleStart, lastCycleEnd));
       CompletableFuture<SpStatementShipUsageMonthVo> future2 = CompletableFuture.supplyAsync(
           () -> spStatementShipUsageMonthMapper.selectGhDataMonth(toDate));
       CompletableFuture<SpStatementShipUsageMonthVo> future5 = CompletableFuture.supplyAsync(
@@ -140,19 +146,22 @@ public class SpStatementShipUsageMonthServiceImpl extends
       origin.setId(snowflakeGenerator.next().toString());
       origin.setShipUsageMonth(originMonth.getShipUsage().add(originSelfMonth.getShipUsage())
           .setScale(2, RoundingMode.HALF_UP));
-      origin.setShipUsageYear(originYear.getShipUsage().add(originMonth.getShipUsage()).add(originSelfMonth.getShipUsage())
+      origin.setShipUsageYear(originYear.getShipUsage().add(originMonth.getShipUsage())
+          .add(originSelfMonth.getShipUsage())
           .setScale(2, RoundingMode.HALF_UP));
       origin.setShorePowerTimeMonth(
           originMonth.getShorePowerTime().add(originSelfMonth.getShorePowerTime())
               .setScale(2, RoundingMode.HALF_UP));
       origin.setShorePowerTimeYear(
-          originYear.getShorePowerTime().add(originMonth.getShorePowerTime()).add(originSelfMonth.getShorePowerTime())
+          originYear.getShorePowerTime().add(originMonth.getShorePowerTime())
+              .add(originSelfMonth.getShorePowerTime())
               .setScale(2, RoundingMode.HALF_UP));
       origin.setShorePowerCountMonth(
           originMonth.getShorePowerCount().add(originSelfMonth.getShorePowerCount())
               .setScale(2, RoundingMode.HALF_UP));
       origin.setShorePowerCountYear(
-          originYear.getShorePowerCount().add(originMonth.getShorePowerCount()).add(originSelfMonth.getShorePowerCount())
+          originYear.getShorePowerCount().add(originMonth.getShorePowerCount())
+              .add(originSelfMonth.getShorePowerCount())
               .setScale(2, RoundingMode.HALF_UP));
       origin.setReportDate(DateUtils.stringToDate(thisYear + "-" + thisMonth, "yyyy-MM"));
       origin.setDataSource(0);
@@ -181,10 +190,10 @@ public class SpStatementShipUsageMonthServiceImpl extends
           toDateBegin, toDate);
       SpStatementShipUsageMonth underLine = new SpStatementShipUsageMonth();
       if (underLineMonth != null || underLineYear != null) {
-        if (underLineMonth == null){
+        if (underLineMonth == null) {
           underLineMonth = new SpStatementShipUsageMonthVo();
         }
-        if (underLineYear == null){
+        if (underLineYear == null) {
           underLineYear = new SpStatementShipUsageMonthVo();
         }
         underLine.setId(snowflakeGenerator.next().toString());
@@ -232,7 +241,7 @@ public class SpStatementShipUsageMonthServiceImpl extends
       spStatementShipUsageMonths.add(sum);
       //傻逼一样的要多算一部分数据,外电1,2,3
       List<SpStatementShipUsageDetail> sbWgq = spStatementShipUsageMonthMapper.selectWgqMonth(
-          thisDate, lastDate,lastCycleStart,lastCycleEnd);
+          thisDate, lastDate, lastCycleStart, lastCycleEnd);
       SpStatementShipUsageMonthVo wgqMonth = makeOriginMonthData(sbWgq);
       SpStatementShipUsageMonthVo wgqYear = spStatementShipUsageMonthMapper.selectWgqYear(
           dateStrLast);
@@ -261,9 +270,10 @@ public class SpStatementShipUsageMonthServiceImpl extends
       List<SpStatementShipUsageDetailV2> nwSum = spStatementShipUsageMonthMapper.selectNhAndWgMonthV2(thisDate,lastDate);
       SpStatementShipUsageMonthVo realSum = makeOriginMonthDataV2(nwSum);
       //获取该月前一个月的合计数据
-      SpStatementShipUsageMonthVo nwSumLastSum = spStatementShipUsageMonthMapper.selectNhAndWgLastMonthSum(DateUtils.stringToDate(dateStrLast,"yyyy-MM"));
+      SpStatementShipUsageMonthVo nwSumLastSum = spStatementShipUsageMonthMapper.selectNhAndWgLastMonthSum(
+          DateUtils.stringToDate(dateStrLast, "yyyy-MM"));
       SpStatementShipUsageMonth nwSumSave = new SpStatementShipUsageMonth();
-      if (nwSumLastSum == null){
+      if (nwSumLastSum == null) {
         nwSumLastSum = new SpStatementShipUsageMonthVo();
       }
       nwSumSave.setId(snowflakeGenerator.next().toString());
@@ -272,9 +282,14 @@ public class SpStatementShipUsageMonthServiceImpl extends
       nwSumSave.setShipUsageMonth(realSum.getShipUsage());
       nwSumSave.setShorePowerCountMonth(realSum.getShorePowerCount());
       nwSumSave.setShorePowerTimeMonth(realSum.getShorePowerTime());
-      nwSumSave.setShipUsageYear(nwSumLastSum.getShipUsage().add(realSum.getShipUsage()).setScale(2,RoundingMode.HALF_UP));
-      nwSumSave.setShorePowerTimeYear(nwSumLastSum.getShorePowerTime().add(realSum.getShorePowerTime()).setScale(2,RoundingMode.HALF_UP));
-      nwSumSave.setShorePowerCountYear(nwSumLastSum.getShorePowerCount().add(realSum.getShorePowerCount()).setScale(2,RoundingMode.HALF_UP));
+      nwSumSave.setShipUsageYear(nwSumLastSum.getShipUsage().add(realSum.getShipUsage())
+          .setScale(2, RoundingMode.HALF_UP));
+      nwSumSave.setShorePowerTimeYear(
+          nwSumLastSum.getShorePowerTime().add(realSum.getShorePowerTime())
+              .setScale(2, RoundingMode.HALF_UP));
+      nwSumSave.setShorePowerCountYear(
+          nwSumLastSum.getShorePowerCount().add(realSum.getShorePowerCount())
+              .setScale(2, RoundingMode.HALF_UP));
       spStatementShipUsageMonths.add(nwSumSave);
       //获取对应年的合计
       //计算内河平台数据
@@ -341,6 +356,58 @@ public class SpStatementShipUsageMonthServiceImpl extends
       outRiverShipUsage.setShorePowerTimeYear(
           origin.getShorePowerTimeYear().subtract(inRiverShipUsage.getShorePowerTimeYear()));
       spStatementShipUsageMonths.add(outRiverShipUsage);
+      // 计算portId = 1146的每个月数据存储到长江经济带中间表 dataSource102
+      ShorePowerDataVo portIdEq1146;
+      SpStatementShipUsageMonth portIdEq1146Data = new SpStatementShipUsageMonth();
+      String portIdEq1146ReportDate = currentDate + "-01";
+      String portIdEq1146Year = portIdEq1146ReportDate.split("-")[0];
+      String portIdEq1146LastYear = String.valueOf(Integer.parseInt(portIdEq1146Year) - 1);
+      String portIdEq1146CurrentStart;
+      String portIdEq1146CurrentEnd = "";
+      String portIdEq1146LastStart = "";
+      String portIdEq1146LastEnd = "";
+      if (portIdEq1146ReportDate.split("-")[1].equals("01")) {
+        portIdEq1146CurrentStart = portIdEq1146LastYear + "-12-25 00:00:00";
+        portIdEq1146CurrentEnd = portIdEq1146Year + "-01-24 23:59:59";
+        portIdEq1146LastStart = portIdEq1146LastYear + "-11-25 00:00:00";
+        portIdEq1146LastEnd = portIdEq1146LastYear + "-12-24 23:59:59";
+      } else if (portIdEq1146ReportDate.split("-")[1].equals("02")) {
+        portIdEq1146CurrentStart = portIdEq1146Year + "-01-25 00:00:00";
+        portIdEq1146CurrentEnd = portIdEq1146Year + "-02-24 23:59:59";
+        portIdEq1146LastStart = portIdEq1146LastYear + "-12-25 00:00:00";
+        portIdEq1146LastEnd = portIdEq1146Year + "-01-24 23:59:59";
+      } else {
+        Integer portIdEq1146lastMonth = Integer.parseInt(portIdEq1146ReportDate.split("-")[1]) - 1;
+        Integer last2Month = Integer.parseInt(portIdEq1146ReportDate.split("-")[1]) - 2;
+        portIdEq1146CurrentStart = portIdEq1146Year + "-" + portIdEq1146lastMonth + "-25 00:00:00";
+        portIdEq1146CurrentEnd =
+            portIdEq1146Year + "-" + Integer.parseInt(portIdEq1146ReportDate.split("-")[1])
+                + "-24 23:59:59";
+        portIdEq1146LastStart = portIdEq1146Year + "-" + last2Month + "-25 00:00:00";
+        portIdEq1146LastEnd = portIdEq1146Year + "-" + portIdEq1146lastMonth + "-24 23:59:59";
+      }
+      log.info("========>当前月份{} 查询参数为 :{},{},{},{}", portIdEq1146ReportDate,
+          portIdEq1146CurrentStart, portIdEq1146CurrentEnd, portIdEq1146LastStart,
+          portIdEq1146LastEnd);
+      List<ShorePowerDataVo> dataVos = spStatementShipUsageMonthMapper.selectPortIdEq1146(
+          portIdEq1146CurrentStart, portIdEq1146CurrentEnd, portIdEq1146LastStart,
+          portIdEq1146LastEnd);
+      if (CollectionUtils.isEmpty(dataVos)) {
+        portIdEq1146 = new ShorePowerDataVo();
+      } else {
+        portIdEq1146 = dataVos.get(0);
+      }
+      log.info("当月{},添加的portId等于1146的数据为:{}", portIdEq1146ReportDate,
+          JSONObject.toJSONString(portIdEq1146));
+      portIdEq1146Data.setId(snowflakeGenerator.next().toString());
+      portIdEq1146Data.setReportDate(DateUtils.stringToDate(portIdEq1146ReportDate,DateUtils.DATE_FORMAT_10));
+      portIdEq1146Data.setDataSource(102);
+      portIdEq1146Data.setShipUsageMonth(portIdEq1146.getBoatUse());
+      portIdEq1146Data.setShorePowerTimeMonth(portIdEq1146.getElectTime());
+      portIdEq1146Data.setShorePowerCountMonth(portIdEq1146.getElectCount());
+      log.info("当月{},长江经济带存储的portId等于1146的数据为:{}", portIdEq1146ReportDate,
+          JSONObject.toJSONString(portIdEq1146Data));
+      spStatementShipUsageMonths.add(portIdEq1146Data);
       this.saveBatch(spStatementShipUsageMonths);
       //岸电年比
       ArrayList<SpStatementYearAnalysis> save = new ArrayList<>();
@@ -535,7 +602,8 @@ public class SpStatementShipUsageMonthServiceImpl extends
               thisYear - 1 + "-" + (thisMonth < 10 ? "0" + thisMonth : thisMonth)));
       //获取去年最后一个月
       SpStatementSg last = spStatementSgService.getOne(
-          Wrappers.<SpStatementSg>lambdaQuery().eq(SpStatementSg::getReportDate, thisYear -1 + "-12"));
+          Wrappers.<SpStatementSg>lambdaQuery()
+              .eq(SpStatementSg::getReportDate, thisYear - 1 + "-12"));
       SpStatementSg spStatementSg = new SpStatementSg();
       spStatementSg.setId(snowflakeGenerator.next().toString());
       spStatementSg.setReportDate(DateUtils.dateToString(toDate, "yyyy-MM"));
@@ -573,7 +641,8 @@ public class SpStatementShipUsageMonthServiceImpl extends
         //查询往期合计,计算本月合计
         SpStatementSg lastMonthSg = spStatementSgService.getOne(
             Wrappers.<SpStatementSg>lambdaQuery()
-                .eq(SpStatementSg::getReportDate, thisYear + "-" + (lastMonth < 10 ? "0" + lastMonth : lastMonth)));
+                .eq(SpStatementSg::getReportDate,
+                    thisYear + "-" + (lastMonth < 10 ? "0" + lastMonth : lastMonth)));
         spStatementSg.setSumChargeTime(
             underLineSg.getShorePowerTime().add(lastMonthSg.getSumChargeTime())
                 .setScale(2, RoundingMode.HALF_UP));

+ 16 - 0
src/main/java/com/shcd/vo/ShorePowerDataVo.java

@@ -0,0 +1,16 @@
+package com.shcd.vo;
+
+import java.math.BigDecimal;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class ShorePowerDataVo {
+  String district;
+  BigDecimal boatUse = BigDecimal.ZERO;
+  BigDecimal electTime = BigDecimal.ZERO;
+  BigDecimal electCount = BigDecimal.ZERO;
+}