|
@@ -17,6 +17,7 @@ import com.shcd.mapper.SpStatementShipUsageMonthMapper;
|
|
|
import com.shcd.service.SpStatementSgService;
|
|
|
import com.shcd.service.SpStatementShipUsageMonthService;
|
|
|
import com.shcd.service.SpStatementYearAnalysisService;
|
|
|
+import com.shcd.utils.PrintLogUtils;
|
|
|
import com.shcd.vo.ShorePowerDataVo;
|
|
|
import com.shcd.vo.SpQuarterReportBlVo;
|
|
|
import com.shcd.vo.SpQuarterReportOriginVo;
|
|
@@ -626,101 +627,127 @@ public class SpStatementShipUsageMonthServiceImpl extends
|
|
|
spStatementSgService.remove(Wrappers.<SpStatementSg>lambdaQuery()
|
|
|
.eq(SpStatementSg::getReportDate,
|
|
|
thisYear + "-" + (thisMonth < 10 ? "0" + thisMonth : thisMonth)));
|
|
|
- SpStatementShipUsageMonthVo underLineSg = spStatementShipUsageMonthMapper.getUnderLineMonthDataSg(
|
|
|
- toDate);
|
|
|
- if (underLineSg == null) {
|
|
|
- underLineSg = new SpStatementShipUsageMonthVo();
|
|
|
- }
|
|
|
- //查询去年同期数据
|
|
|
- SpStatementSg sameTimeLastYear = spStatementSgService.getOne(
|
|
|
- Wrappers.<SpStatementSg>lambdaQuery().eq(SpStatementSg::getReportDate,
|
|
|
- thisYear - 1 + "-" + (thisMonth < 10 ? "0" + thisMonth : thisMonth)));
|
|
|
- //获取去年最后一个月
|
|
|
- SpStatementSg last = spStatementSgService.getOne(
|
|
|
- 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"));
|
|
|
- spStatementSg.setShipUsage(underLineSg.getShipUsage().setScale(2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setChargeTime(
|
|
|
- underLineSg.getShorePowerTime().setScale(2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setElectUsage(
|
|
|
- underLineSg.getShorePowerCount().setScale(2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setShipUsageTon(
|
|
|
- underLineSg.getShipUsage().subtract(sameTimeLastYear.getShipUsage())
|
|
|
- .multiply(BigDecimal.valueOf(100))
|
|
|
- .divide(sameTimeLastYear.getShipUsage(), 2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setElectUsageTon(
|
|
|
- underLineSg.getShorePowerCount().subtract(sameTimeLastYear.getElectUsage())
|
|
|
- .multiply(BigDecimal.valueOf(100))
|
|
|
- .divide(sameTimeLastYear.getElectUsage(), 2, RoundingMode.HALF_UP));
|
|
|
- //如果当前是第一月
|
|
|
- if (toDate.getMonth() + 1 == 1) {
|
|
|
- //不用查往期合计
|
|
|
- spStatementSg.setSumChargeTime(
|
|
|
- underLineSg.getShorePowerTime().setScale(2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setSumShipUsageNum(
|
|
|
- underLineSg.getShipUsage().setScale(2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setSumElectUse(
|
|
|
- underLineSg.getShorePowerCount().setScale(2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setSumShipUsageTon(
|
|
|
- spStatementSg.getSumShipUsageNum().subtract(last.getSumShipUsageNum())
|
|
|
- .multiply(BigDecimal.valueOf(100))
|
|
|
- .divide(last.getSumShipUsageNum(), 2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setSumElectUseTon(
|
|
|
- spStatementSg.getSumElectUse().subtract(last.getSumElectUse())
|
|
|
- .multiply(BigDecimal.valueOf(100))
|
|
|
- .divide(last.getSumElectUse(), 2, RoundingMode.HALF_UP));
|
|
|
- } else {
|
|
|
- //查询往期合计,计算本月合计
|
|
|
- SpStatementSg lastMonthSg = spStatementSgService.getOne(
|
|
|
- Wrappers.<SpStatementSg>lambdaQuery()
|
|
|
- .eq(SpStatementSg::getReportDate,
|
|
|
- thisYear + "-" + (lastMonth < 10 ? "0" + lastMonth : lastMonth)));
|
|
|
- spStatementSg.setSumChargeTime(
|
|
|
- underLineSg.getShorePowerTime().add(lastMonthSg.getSumChargeTime())
|
|
|
- .setScale(2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setSumShipUsageNum(
|
|
|
- underLineSg.getShipUsage().add(lastMonthSg.getSumShipUsageNum())
|
|
|
- .setScale(2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setSumElectUse(
|
|
|
- underLineSg.getShorePowerCount().add(lastMonthSg.getSumElectUse())
|
|
|
- .setScale(2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setSumShipUsageTon(
|
|
|
- spStatementSg.getSumShipUsageNum().subtract(last.getSumShipUsageNum())
|
|
|
- .multiply(BigDecimal.valueOf(100))
|
|
|
- .divide(last.getSumShipUsageNum(), 2, RoundingMode.HALF_UP));
|
|
|
- spStatementSg.setSumElectUseTon(
|
|
|
- spStatementSg.getSumElectUse().subtract(last.getSumElectUse())
|
|
|
- .multiply(BigDecimal.valueOf(100))
|
|
|
- .divide(last.getSumElectUse(), 2, RoundingMode.HALF_UP));
|
|
|
+ log.info("开始计算靠泊上港集团码头的集装箱船舶部分报表 ===========");
|
|
|
+ try {
|
|
|
+ executeSg(toDate, thisYear, thisMonth, snowflakeGenerator, lastMonth);
|
|
|
+ } catch (Exception e) {
|
|
|
+ PrintLogUtils.printErrorLogInfo(e);
|
|
|
+ log.info("计算靠泊上港集团码头的集装箱船舶部分报表出错 ========== 原因:{}",
|
|
|
+ e.getMessage());
|
|
|
}
|
|
|
- spStatementSgService.save(spStatementSg);
|
|
|
// 计算靠泊集装箱码头船舶数据
|
|
|
- List<SpQuarterReportOriginVo> spQuarterReportOriginVos = spStatementShipUsageMonthMapper.selectQuarterOrigin(
|
|
|
- lastDate, thisDate, lastCycleStart, lastCycleEnd);
|
|
|
- List<SpQuarterReportBlVo> spQuarterReportBlVos = spStatementShipUsageMonthMapper.selectQuarterBlBerth(
|
|
|
- lastDate, thisDate);
|
|
|
- List<SpQuarterReportOriginVo> container = spQuarterReportOriginVos.stream()
|
|
|
- .filter(i -> i.getBerthType().equals(1)).collect(Collectors.toList());
|
|
|
- List<SpQuarterReportBlVo> containerBl = spQuarterReportBlVos.stream()
|
|
|
- .filter(i -> i.getBerthType().equals(1)).collect(Collectors.toList());
|
|
|
- SpStatementQuarterReport spStatementQuarterReport = new SpStatementQuarterReport();
|
|
|
- spStatementQuarterReport.setDataType(ShorePowerQuarterDataType.CONTAINER_BERTH.getDataType());
|
|
|
- spStatementQuarterReport.setId(snowflakeConfig.snowflakeStringId());
|
|
|
- spStatementQuarterReport.setYear(thisYear);
|
|
|
- spStatementQuarterReport.setQuarter(
|
|
|
- (thisMonth % 3 == 0) ? (thisMonth / 3) : (thisMonth / 3 + 1));
|
|
|
- calculateQuarterReportDetailOriginMonth(spStatementQuarterReport, container);
|
|
|
- calculateQuarterReportDetailBlMonth(spStatementQuarterReport, containerBl);
|
|
|
- saveCurrentMonthContainerDataToDB(spStatementQuarterReport,currentDate);
|
|
|
+ log.info("开始计算靠泊集装箱码头船舶数据部分报表 ===========");
|
|
|
+ try {
|
|
|
+ executeContainer(currentDate, lastDate, thisDate, lastCycleStart, lastCycleEnd, thisYear,
|
|
|
+ thisMonth);
|
|
|
+ } catch (Exception e) {
|
|
|
+ PrintLogUtils.printErrorLogInfo(e);
|
|
|
+ log.info("计算靠泊集装箱码头船舶数据部分报表出错 ========== 原因:{}",
|
|
|
+ e.getMessage());
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void executeContainer(String currentDate, Date lastDate, Date thisDate,
|
|
|
+ Date lastCycleStart,
|
|
|
+ Date lastCycleEnd, int thisYear, int thisMonth) {
|
|
|
+ List<SpQuarterReportOriginVo> spQuarterReportOriginVos = spStatementShipUsageMonthMapper.selectQuarterOrigin(
|
|
|
+ lastDate, thisDate, lastCycleStart, lastCycleEnd);
|
|
|
+ List<SpQuarterReportBlVo> spQuarterReportBlVos = spStatementShipUsageMonthMapper.selectQuarterBlBerth(
|
|
|
+ lastDate, thisDate);
|
|
|
+ List<SpQuarterReportOriginVo> container = spQuarterReportOriginVos.stream()
|
|
|
+ .filter(i -> i.getBerthType().equals(1)).collect(Collectors.toList());
|
|
|
+ List<SpQuarterReportBlVo> containerBl = spQuarterReportBlVos.stream()
|
|
|
+ .filter(i -> i.getBerthType().equals(1)).collect(Collectors.toList());
|
|
|
+ SpStatementQuarterReport spStatementQuarterReport = new SpStatementQuarterReport();
|
|
|
+ spStatementQuarterReport.setDataType(ShorePowerQuarterDataType.CONTAINER_BERTH.getDataType());
|
|
|
+ spStatementQuarterReport.setId(snowflakeConfig.snowflakeStringId());
|
|
|
+ spStatementQuarterReport.setYear(thisYear);
|
|
|
+ spStatementQuarterReport.setQuarter(
|
|
|
+ (thisMonth % 3 == 0) ? (thisMonth / 3) : (thisMonth / 3 + 1));
|
|
|
+ calculateQuarterReportDetailOriginMonth(spStatementQuarterReport, container);
|
|
|
+ calculateQuarterReportDetailBlMonth(spStatementQuarterReport, containerBl);
|
|
|
+ saveCurrentMonthContainerDataToDB(spStatementQuarterReport, currentDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void executeSg(Date toDate, int thisYear, int thisMonth,
|
|
|
+ SnowflakeGenerator snowflakeGenerator, int lastMonth) {
|
|
|
+ SpStatementShipUsageMonthVo underLineSg = spStatementShipUsageMonthMapper.getUnderLineMonthDataSg(
|
|
|
+ toDate);
|
|
|
+ if (underLineSg == null) {
|
|
|
+ underLineSg = new SpStatementShipUsageMonthVo();
|
|
|
+ }
|
|
|
+ //查询去年同期数据
|
|
|
+ SpStatementSg sameTimeLastYear = spStatementSgService.getOne(
|
|
|
+ Wrappers.<SpStatementSg>lambdaQuery().eq(SpStatementSg::getReportDate,
|
|
|
+ thisYear - 1 + "-" + (thisMonth < 10 ? "0" + thisMonth : thisMonth)));
|
|
|
+ //获取去年最后一个月
|
|
|
+ SpStatementSg last = spStatementSgService.getOne(
|
|
|
+ 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"));
|
|
|
+ spStatementSg.setShipUsage(underLineSg.getShipUsage().setScale(2, RoundingMode.HALF_UP));
|
|
|
+ spStatementSg.setChargeTime(
|
|
|
+ underLineSg.getShorePowerTime().setScale(2, RoundingMode.HALF_UP));
|
|
|
+ spStatementSg.setElectUsage(
|
|
|
+ underLineSg.getShorePowerCount().setScale(2, RoundingMode.HALF_UP));
|
|
|
+ spStatementSg.setShipUsageTon(
|
|
|
+ underLineSg.getShipUsage().subtract(sameTimeLastYear.getShipUsage())
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .divide(sameTimeLastYear.getShipUsage(), 2, RoundingMode.HALF_UP));
|
|
|
+ spStatementSg.setElectUsageTon(
|
|
|
+ underLineSg.getShorePowerCount().subtract(sameTimeLastYear.getElectUsage())
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .divide(sameTimeLastYear.getElectUsage(), 2, RoundingMode.HALF_UP));
|
|
|
+ //如果当前是第一月
|
|
|
+ if (toDate.getMonth() + 1 == 1) {
|
|
|
+ //不用查往期合计
|
|
|
+// spStatementSg.setSumChargeTime(
|
|
|
+// underLineSg.getShorePowerTime().setScale(2, RoundingMode.HALF_UP));
|
|
|
+// spStatementSg.setSumShipUsageNum(
|
|
|
+// underLineSg.getShipUsage().setScale(2, RoundingMode.HALF_UP));
|
|
|
+// spStatementSg.setSumElectUse(
|
|
|
+// underLineSg.getShorePowerCount().setScale(2, RoundingMode.HALF_UP));
|
|
|
+// spStatementSg.setSumShipUsageTon(
|
|
|
+// spStatementSg.getSumShipUsageNum().subtract(last.getSumShipUsageNum())
|
|
|
+// .multiply(BigDecimal.valueOf(100))
|
|
|
+// .divide(last.getSumShipUsageNum(), 2, RoundingMode.HALF_UP));
|
|
|
+// spStatementSg.setSumElectUseTon(
|
|
|
+// spStatementSg.getSumElectUse().subtract(last.getSumElectUse())
|
|
|
+// .multiply(BigDecimal.valueOf(100))
|
|
|
+// .divide(last.getSumElectUse(), 2, RoundingMode.HALF_UP));
|
|
|
+ } else {
|
|
|
+ //查询往期合计,计算本月合计
|
|
|
+ SpStatementSg lastMonthSg = spStatementSgService.getOne(
|
|
|
+ Wrappers.<SpStatementSg>lambdaQuery()
|
|
|
+ .eq(SpStatementSg::getReportDate,
|
|
|
+ thisYear + "-" + (lastMonth < 10 ? "0" + lastMonth : lastMonth)));
|
|
|
+// spStatementSg.setSumChargeTime(
|
|
|
+// underLineSg.getShorePowerTime().add(lastMonthSg.getSumChargeTime())
|
|
|
+// .setScale(2, RoundingMode.HALF_UP));
|
|
|
+// spStatementSg.setSumShipUsageNum(
|
|
|
+// underLineSg.getShipUsage().add(lastMonthSg.getSumShipUsageNum())
|
|
|
+// .setScale(2, RoundingMode.HALF_UP));
|
|
|
+// spStatementSg.setSumElectUse(
|
|
|
+// underLineSg.getShorePowerCount().add(lastMonthSg.getSumElectUse())
|
|
|
+// .setScale(2, RoundingMode.HALF_UP));
|
|
|
+// spStatementSg.setSumShipUsageTon(
|
|
|
+// spStatementSg.getSumShipUsageNum().subtract(last.getSumShipUsageNum())
|
|
|
+// .multiply(BigDecimal.valueOf(100))
|
|
|
+// .divide(last.getSumShipUsageNum(), 2, RoundingMode.HALF_UP));
|
|
|
+// spStatementSg.setSumElectUseTon(
|
|
|
+// spStatementSg.getSumElectUse().subtract(last.getSumElectUse())
|
|
|
+// .multiply(BigDecimal.valueOf(100))
|
|
|
+// .divide(last.getSumElectUse(), 2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ spStatementSgService.save(spStatementSg);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void saveCurrentMonthContainerDataToDB(SpStatementQuarterReport spStatementQuarterReport,
|
|
|
String currentDate) {
|