|
@@ -16,6 +16,7 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -103,17 +104,16 @@ public class SpStatementInlandLowServiceImpl extends
|
|
|
List<ShorePowerDeviceUsage> originList = this.getOriginDataFromPage(
|
|
|
currentMonthDate);
|
|
|
log.info("统计当月原始数据为:{}", JSONObject.toJSONString(originList));
|
|
|
- // 查询上个月数据 用来计算环比
|
|
|
- List<ShorePowerDeviceUsage> lastOriginList = this.getOriginDataFromPage(
|
|
|
- lastMonthDate);
|
|
|
- log.info("统计上月原始数据为:{}", JSONObject.toJSONString(lastOriginList));
|
|
|
- // 查询全年原始数据 用来计算当年累计
|
|
|
- List<ShorePowerDeviceUsage> currentYearOriginList = this.getCurrentYearOriginDataFromPage();
|
|
|
- log.info("当年累计原始数据为:{}", JSONObject.toJSONString(currentYearOriginList));
|
|
|
+ // 查询上个月报表数据 用来计算环比
|
|
|
+ List<SpStatementInlandLow> lastReportDataList = this.getAllLastMonthReportData(lastMonthDate,
|
|
|
+ 1);
|
|
|
+ log.info("统计上月报表数据为:{}", JSONObject.toJSONString(lastReportDataList));
|
|
|
+// 查询全年原始数据 用来计算当年累计
|
|
|
+// List<ShorePowerDeviceUsage> currentYearOriginList = this.getCurrentYearOriginDataFromPage();
|
|
|
+// log.info("当年累计原始数据为:{}", JSONObject.toJSONString(currentYearOriginList));
|
|
|
List<SpStatementInlandLow> spStatementInlandLowList = new ArrayList<>(originList.size());
|
|
|
// 计算各区
|
|
|
- executeEveryDistrict(originList, lastOriginList, spStatementInlandLowList,
|
|
|
- currentYearOriginList);
|
|
|
+ executeEveryDistrict(originList, lastReportDataList, spStatementInlandLowList);
|
|
|
// 计算合计
|
|
|
executeTotal(spStatementInlandLowList, lastMonthDate);
|
|
|
log.info("最终存储的内河低压分析表1为:{}", JSONObject.toJSONString(spStatementInlandLowList));
|
|
@@ -145,29 +145,23 @@ public class SpStatementInlandLowServiceImpl extends
|
|
|
List<ShorePowerConnRecordInfoVo> currentMonthData = this.selectDataFromShorePower(
|
|
|
params);
|
|
|
log.info("市级平台自动上传<当月>数据为:{}", JSONObject.toJSONString(currentMonthData));
|
|
|
- String lastMonthParamDate = lastMonthDate + "-24 23:59:59";
|
|
|
- String last2MonthParamDate = last2MonthDate + "-25 00:00:00";
|
|
|
- Map<String, Object> LastMonthParams = new HashMap<>(2);
|
|
|
- LastMonthParams.put("reportDateStart", last2MonthParamDate);
|
|
|
- LastMonthParams.put("reportDateEnd", lastMonthParamDate);
|
|
|
- params.put("lastReportDateStart", last3MonthDate + "-25 00:00:00");
|
|
|
- params.put("lastReportDateEnd", last2MonthDate + "-24 23:59:59");
|
|
|
- List<ShorePowerConnRecordInfoVo> lastMonthData = this.selectDataFromShorePower(
|
|
|
- LastMonthParams);
|
|
|
- log.info("市级平台自动上传<上月>数据为:{}", JSONObject.toJSONString(lastMonthData));
|
|
|
+ // 查询上个月报表数据 用来计算环比
|
|
|
+ List<SpStatementInlandLow> lastReportDataList = this.getAllLastMonthReportData(lastMonthDate,
|
|
|
+ 2);
|
|
|
+ log.info("市级平台自动上传<上月>数据为:{}", JSONObject.toJSONString(lastReportDataList));
|
|
|
// 查询全年原始数据 用来计算当年累计
|
|
|
- String yearStartDate =
|
|
|
- (Integer.parseInt(currentDate.split("-")[0]) - 1) + "-12-25 00:00:00";
|
|
|
- String yearEndDate = currentDate + "-24 23:59:59";
|
|
|
- Map<String, Object> yearParams = new HashMap<>(2);
|
|
|
- yearParams.put("reportDateStart", yearStartDate);
|
|
|
- yearParams.put("reportDateEnd", yearEndDate);
|
|
|
- List<ShorePowerConnRecordInfoVo> currentYearDataList = this.selectDataFromShorePower(
|
|
|
- yearParams);
|
|
|
- log.info("市级平台自动上传<全年>数据为:{}", JSONObject.toJSONString(currentYearDataList));
|
|
|
+// String yearStartDate =
|
|
|
+// (Integer.parseInt(currentDate.split("-")[0]) - 1) + "-12-25 00:00:00";
|
|
|
+// String yearEndDate = currentDate + "-24 23:59:59";
|
|
|
+// Map<String, Object> yearParams = new HashMap<>(2);
|
|
|
+// yearParams.put("reportDateStart", yearStartDate);
|
|
|
+// yearParams.put("reportDateEnd", yearEndDate);
|
|
|
+// List<ShorePowerConnRecordInfoVo> currentYearDataList = this.selectDataFromShorePower(
|
|
|
+// yearParams);
|
|
|
+// log.info("市级平台自动上传<全年>数据为:{}", JSONObject.toJSONString(currentYearDataList));
|
|
|
// 计算各区
|
|
|
List<SpStatementInlandLow> spStatementInlandLowList = executeEveryDistrict2(currentMonthData,
|
|
|
- lastMonthData, currentYearDataList, currentDate);
|
|
|
+ lastReportDataList, currentDate);
|
|
|
// 计算合计
|
|
|
executeTotal2(spStatementInlandLowList, lastMonthDate);
|
|
|
List<SpStatementInlandLow> currentList = this.selectCurrentMonthReport2Count(
|
|
@@ -184,13 +178,17 @@ public class SpStatementInlandLowServiceImpl extends
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<SpStatementInlandLow> getAllLastMonthReportData(String lastMonthDate, int type) {
|
|
|
+ return mapper.getAllLastMonthReportData(lastMonthDate, type);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void executeEveryDistrict(List<ShorePowerDeviceUsage> originList,
|
|
|
- List<ShorePowerDeviceUsage> lastOriginList,
|
|
|
- List<SpStatementInlandLow> spStatementInlandLowList,
|
|
|
- List<ShorePowerDeviceUsage> currentYearOriginList) {
|
|
|
+ List<SpStatementInlandLow> lastReportDataList,
|
|
|
+ List<SpStatementInlandLow> spStatementInlandLowList) {
|
|
|
for (ShorePowerDeviceUsage thisMonthData : originList) {
|
|
|
- // 计算各区
|
|
|
+ // 计算各区 当月数据
|
|
|
SpStatementInlandLow spStatementInlandLow = new SpStatementInlandLow();
|
|
|
String id = String.valueOf(snowflakeMakeConf.snowflakeId());
|
|
|
spStatementInlandLow.setId(id);
|
|
@@ -203,40 +201,51 @@ public class SpStatementInlandLowServiceImpl extends
|
|
|
thisMonthData.getElectricityConsumption());
|
|
|
spStatementInlandLow.setReportDate(thisMonthData.getReportDate());
|
|
|
spStatementInlandLow.setType(1);
|
|
|
- if (CollectionUtils.isEmpty(lastOriginList)) {
|
|
|
- spStatementInlandLow.setBoatUseNumberChain(null);
|
|
|
+ // 计算当年累计 以及 环比
|
|
|
+ Calendar thisCalendar = Calendar.getInstance();
|
|
|
+ thisCalendar.setTime(thisMonthData.getReportDate());
|
|
|
+ if (thisCalendar.get(Calendar.MONTH) == Calendar.JANUARY) {
|
|
|
+ spStatementInlandLow.setBoatUseNumberYearTotal(
|
|
|
+ spStatementInlandLow.getBoatUseNumberMonth());
|
|
|
+ spStatementInlandLow.setPowerConnHoursYearTotal(
|
|
|
+ spStatementInlandLow.getPowerConnHoursMonth());
|
|
|
+ spStatementInlandLow.setElectricityUsageYearTotal(
|
|
|
+ spStatementInlandLow.getElectricityUsageMonth());
|
|
|
} else {
|
|
|
- for (ShorePowerDeviceUsage lastMonthData : lastOriginList) {
|
|
|
- if (lastMonthData.getDistrict().equals(thisMonthData.getDistrict())) {
|
|
|
- BigDecimal rate = getRate(thisMonthData, lastMonthData);
|
|
|
- spStatementInlandLow.setBoatUseNumberChain(rate);
|
|
|
- } else {
|
|
|
- spStatementInlandLow.setBoatUseNumberChain(null);
|
|
|
+ // 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);
|
|
|
}
|
|
|
- for (SpStatementInlandLow statementInlandLow : spStatementInlandLowList) {
|
|
|
- for (ShorePowerDeviceUsage yearData : currentYearOriginList) {
|
|
|
- if (statementInlandLow.getDistrict().equals(yearData.getDistrict())) {
|
|
|
- statementInlandLow.setBoatUseNumberYearTotal(yearData.getShorePowerBoatUseNumber());
|
|
|
- statementInlandLow.setPowerConnHoursYearTotal(yearData.getPowerConnHours());
|
|
|
- statementInlandLow.setElectricityUsageYearTotal(yearData.getElectricityConsumption());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- private static BigDecimal getRate(ShorePowerDeviceUsage thisMonthData,
|
|
|
- ShorePowerDeviceUsage lastMonthData) {
|
|
|
- if (Objects.isNull(lastMonthData) || Objects.isNull(lastMonthData.getShorePowerBoatUseNumber())
|
|
|
- || lastMonthData.getShorePowerBoatUseNumber().equals(BigDecimal.ZERO)) {
|
|
|
+ private static BigDecimal getRate(BigDecimal thisMonthData,
|
|
|
+ BigDecimal lastMonthData) {
|
|
|
+ if (Objects.isNull(lastMonthData) || lastMonthData.equals(BigDecimal.ZERO)) {
|
|
|
return null;
|
|
|
}
|
|
|
- return (thisMonthData.getShorePowerBoatUseNumber()
|
|
|
- .subtract(lastMonthData.getShorePowerBoatUseNumber())).multiply(BigDecimal.valueOf(100))
|
|
|
- .divide(lastMonthData.getShorePowerBoatUseNumber(), 2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal result = (thisMonthData.subtract(lastMonthData)).multiply(BigDecimal.valueOf(100))
|
|
|
+ .divide(lastMonthData, 2, RoundingMode.HALF_UP);
|
|
|
+ return result.setScale(2, RoundingMode.HALF_UP);
|
|
|
}
|
|
|
|
|
|
private void executeTotal(List<SpStatementInlandLow> spStatementInlandLowList,
|
|
@@ -335,8 +344,7 @@ public class SpStatementInlandLowServiceImpl extends
|
|
|
|
|
|
private List<SpStatementInlandLow> executeEveryDistrict2(
|
|
|
List<ShorePowerConnRecordInfoVo> currentMonthData,
|
|
|
- List<ShorePowerConnRecordInfoVo> lastMonthData,
|
|
|
- List<ShorePowerConnRecordInfoVo> currentYearDataList, String currentDate)
|
|
|
+ List<SpStatementInlandLow> lastReportDataList, String currentDate)
|
|
|
throws ParseException {
|
|
|
List<SpStatementInlandLow> spStatementInlandLowList = new ArrayList<>(
|
|
|
currentMonthData.size());
|
|
@@ -353,53 +361,45 @@ public class SpStatementInlandLowServiceImpl extends
|
|
|
spStatementInlandLow.setType(2);
|
|
|
spStatementInlandLow.setBoatUseNumberMonth(currentMonth.getTotal());
|
|
|
// 使用岸电小时在查询数据库时已经转换为小时计算
|
|
|
-// spStatementInlandLow.setPowerConnHoursMonth(
|
|
|
-// currentMonth.getDuration().divide(BigDecimal.valueOf(60), 2,
|
|
|
-// RoundingMode.HALF_UP));
|
|
|
spStatementInlandLow.setPowerConnHoursMonth(currentMonth.getDuration());
|
|
|
spStatementInlandLow.setElectricityUsageMonth(currentMonth.getElect());
|
|
|
- if (CollectionUtils.isEmpty(lastMonthData)) {
|
|
|
- spStatementInlandLow.setBoatUseNumberChain(null);
|
|
|
+ // 计算当年累计 以及 环比
|
|
|
+ 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 {
|
|
|
- for (ShorePowerConnRecordInfoVo lastMonth : lastMonthData) {
|
|
|
- if (currentMonth.getArea().equals(lastMonth.getArea())) {
|
|
|
- // 计算使用岸电船舶(艘次)环比
|
|
|
- BigDecimal rate = getRate2(currentMonth, lastMonth);
|
|
|
- spStatementInlandLow.setBoatUseNumberChain(rate);
|
|
|
+ // 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);
|
|
|
}
|
|
|
- // 计算各区的当年累计
|
|
|
- for (SpStatementInlandLow statementInlandLow : spStatementInlandLowList) {
|
|
|
- for (ShorePowerConnRecordInfoVo yearData : currentYearDataList) {
|
|
|
- if (statementInlandLow.getDistrict().equals(
|
|
|
- ShorePowerConnRecordInfoEnum.getByArea(Integer.parseInt(yearData.getArea()))
|
|
|
- .getArea())) {
|
|
|
- statementInlandLow.setBoatUseNumberYearTotal(yearData.getTotal());
|
|
|
-// statementInlandLow.setPowerConnHoursYearTotal(
|
|
|
-// yearData.getDuration().divide(BigDecimal.valueOf(60), 2,
|
|
|
-// RoundingMode.HALF_UP));
|
|
|
- statementInlandLow.setPowerConnHoursYearTotal(yearData.getDuration());
|
|
|
- statementInlandLow.setElectricityUsageYearTotal(yearData.getElect());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
return spStatementInlandLowList;
|
|
|
}
|
|
|
-
|
|
|
- private BigDecimal getRate2(ShorePowerConnRecordInfoVo currentMonth,
|
|
|
- ShorePowerConnRecordInfoVo lastMonth) {
|
|
|
- if (Objects.isNull(lastMonth) || Objects.isNull(lastMonth.getTotal())
|
|
|
- || lastMonth.getTotal().equals(BigDecimal.ZERO)) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- return (currentMonth.getTotal()
|
|
|
- .subtract(lastMonth.getTotal())).multiply(BigDecimal.valueOf(100))
|
|
|
- .divide(lastMonth.getTotal(), 2, RoundingMode.HALF_UP);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
|