|
|
@@ -1,154 +1,193 @@
|
|
|
package com.ruoyi.ems.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.thread.ThreadUtil;
|
|
|
-import com.ruoyi.common.core.utils.DateTimeUtil;
|
|
|
-import com.ruoyi.ems.domain.ElecPvSupplyH;
|
|
|
+import com.huashe.common.utils.DateUtils;
|
|
|
import com.ruoyi.ems.mapper.ElecPvSupplyHMapper;
|
|
|
+import com.ruoyi.ems.model.PvSupplyExportVO;
|
|
|
+import com.ruoyi.ems.model.PvSupplyVO;
|
|
|
import com.ruoyi.ems.model.QueryMeter;
|
|
|
import com.ruoyi.ems.service.IElecPvSupplyHService;
|
|
|
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;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.concurrent.Future;
|
|
|
|
|
|
/**
|
|
|
- * 光伏并网计量光伏并网计量-小时Service业务层处理
|
|
|
- *
|
|
|
- * @author ruoyi
|
|
|
- * @date 2024-08-02
|
|
|
+ * 光伏产能统计Service业务层处理
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class ElecPvSupplyHServiceImpl implements IElecPvSupplyHService {
|
|
|
+
|
|
|
@Autowired
|
|
|
private ElecPvSupplyHMapper pvSupplyHMapper;
|
|
|
|
|
|
- /**
|
|
|
- * 查询光伏并网计量光伏并网计量-小时
|
|
|
- *
|
|
|
- * @param id 光伏并网计量光伏并网计量-小时主键
|
|
|
- * @return 光伏并网计量光伏并网计量-小时
|
|
|
- */
|
|
|
@Override
|
|
|
- public ElecPvSupplyH selectPvSupplyHById(Long id) {
|
|
|
- return pvSupplyHMapper.selectPvSupplyHById(id);
|
|
|
+ public List<PvSupplyVO> selectPvSupplyList(QueryMeter queryMeter) {
|
|
|
+ if (queryMeter == null) {
|
|
|
+ log.warn("查询参数为空,返回空列表");
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ log.info("查询光伏产能统计,时间维度: {}, 区域: {}", queryMeter.getTimeDimension(), queryMeter.getAreaCode());
|
|
|
+
|
|
|
+ // 根据时间维度调用相应的查询方法
|
|
|
+ switch (queryMeter.getTimeDimension().toLowerCase()) {
|
|
|
+ case "day":
|
|
|
+ return pvSupplyHMapper.selectPvSupplyDailyList(queryMeter);
|
|
|
+ case "month":
|
|
|
+ return pvSupplyHMapper.selectPvSupplyMonthlyList(queryMeter);
|
|
|
+ case "year":
|
|
|
+ return pvSupplyHMapper.selectPvSupplyYearlyList(queryMeter);
|
|
|
+ default:
|
|
|
+ log.warn("未识别的时间维度: {},使用月统计", queryMeter.getTimeDimension());
|
|
|
+ return pvSupplyHMapper.selectPvSupplyMonthlyList(queryMeter);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询光伏产能统计列表异常", e);
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 查询光伏并网计量光伏并网计量-小时列表
|
|
|
- *
|
|
|
- * @param pvSupplyH 光伏并网计量光伏并网计量-小时
|
|
|
- * @return 光伏并网计量光伏并网计量-小时
|
|
|
- */
|
|
|
@Override
|
|
|
- public List<ElecPvSupplyH> selectPvSupplyHList(ElecPvSupplyH pvSupplyH) {
|
|
|
- if (StringUtils.equals("-1", pvSupplyH.getAreaCode())) {
|
|
|
- return pvSupplyHMapper.selectPvSupplyHAll(pvSupplyH);
|
|
|
+ public PvSupplyVO selectPvSupplySummary(QueryMeter queryMeter) {
|
|
|
+ if (queryMeter == null) {
|
|
|
+ log.warn("查询参数为空,返回空对象");
|
|
|
+ return new PvSupplyVO();
|
|
|
}
|
|
|
- else {
|
|
|
- return pvSupplyHMapper.selectPvSupplyHList(pvSupplyH);
|
|
|
+
|
|
|
+ try {
|
|
|
+ log.info("查询光伏产能汇总,区域: {}", queryMeter.getAreaCode());
|
|
|
+
|
|
|
+ PvSupplyVO summary = pvSupplyHMapper.selectPvSupplySummary(queryMeter);
|
|
|
+ return summary != null ? summary : new PvSupplyVO();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询光伏产能统计汇总异常", e);
|
|
|
+ return new PvSupplyVO();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<ElecPvSupplyH> selectPvSupplyDayList(QueryMeter param) {
|
|
|
- return pvSupplyHMapper.selectPvSupplyDayList(param);
|
|
|
+ public List<PvSupplyVO> exportPvSupplyList(QueryMeter queryMeter) {
|
|
|
+ if (queryMeter == null) {
|
|
|
+ log.warn("导出参数为空,返回空列表");
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 导出时不分页,清除分页参数
|
|
|
+ QueryMeter exportQuery = cloneQueryMeter(queryMeter);
|
|
|
+ exportQuery.setPageNum(null);
|
|
|
+ exportQuery.setPageSize(null);
|
|
|
+
|
|
|
+ log.info("导出光伏产能统计,时间维度: {}", exportQuery.getTimeDimension());
|
|
|
+
|
|
|
+ List<PvSupplyVO> result = selectPvSupplyList(exportQuery);
|
|
|
+ log.info("导出光伏产能统计完成,记录数: {}", result.size());
|
|
|
+
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出光伏产能统计异常", e);
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 新增光伏并网计量光伏并网计量-小时
|
|
|
- *
|
|
|
- * @param pvSupplyH 光伏并网计量光伏并网计量-小时
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
@Override
|
|
|
- public int insertPvSupplyH(ElecPvSupplyH pvSupplyH) {
|
|
|
- return pvSupplyHMapper.insertPvSupplyH(pvSupplyH);
|
|
|
+ public List<PvSupplyExportVO> convertToPvSupplyExportVOList(List<PvSupplyVO> originalList, String timeDimension) {
|
|
|
+ if (CollectionUtils.isEmpty(originalList)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ return originalList.stream()
|
|
|
+ .map(vo -> convertToPvSupplyExportVO(vo, timeDimension))
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 修改光伏并网计量光伏并网计量-小时
|
|
|
- *
|
|
|
- * @param pvSupplyH 光伏并网计量光伏并网计量-小时
|
|
|
- * @return 结果
|
|
|
+ * 转换单个产能VO为导出VO
|
|
|
*/
|
|
|
- @Override
|
|
|
- public int updatePvSupplyH(ElecPvSupplyH pvSupplyH) {
|
|
|
- return pvSupplyHMapper.updatePvSupplyH(pvSupplyH);
|
|
|
+ private PvSupplyExportVO convertToPvSupplyExportVO(PvSupplyVO vo, String timeDimension) {
|
|
|
+ PvSupplyExportVO exportVO = new PvSupplyExportVO();
|
|
|
+
|
|
|
+ // 区域名称
|
|
|
+ exportVO.setAreaName(vo.getAreaName());
|
|
|
+
|
|
|
+ // 统计时间 - 根据时间维度格式化
|
|
|
+ exportVO.setStatisticTime(formatStatisticTime(vo, timeDimension));
|
|
|
+
|
|
|
+ // 产能数据 - 格式化为2位小数
|
|
|
+ exportVO.setGenElecQuantity(formatNumber(vo.getGenElecQuantity(), 2));
|
|
|
+ exportVO.setUseElecQuantity(formatNumber(vo.getUseElecQuantity(), 2));
|
|
|
+ exportVO.setUpElecQuantity(formatNumber(vo.getUpElecQuantity(), 2));
|
|
|
+ exportVO.setUpElecEarn(formatNumber(vo.getUpElecEarn(), 2));
|
|
|
+
|
|
|
+ return exportVO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 批量删除光伏并网计量光伏并网计量-小时
|
|
|
- *
|
|
|
- * @param ids 需要删除的光伏并网计量光伏并网计量-小时主键
|
|
|
- * @return 结果
|
|
|
+ * 格式化统计时间
|
|
|
*/
|
|
|
- @Override
|
|
|
- public int deletePvSupplyHByIds(Long[] ids) {
|
|
|
- return pvSupplyHMapper.deletePvSupplyHByIds(ids);
|
|
|
+ private String formatStatisticTime(PvSupplyVO vo, String timeDimension) {
|
|
|
+ if (timeDimension == null) {
|
|
|
+ timeDimension = "month";
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (timeDimension.toLowerCase()) {
|
|
|
+ case "day":
|
|
|
+ return formatDateForDisplay(vo.getStatisticDate());
|
|
|
+ case "month":
|
|
|
+ return StringUtils.isNotBlank(vo.getStatisticMonth()) ? vo.getStatisticMonth() : "";
|
|
|
+ case "year":
|
|
|
+ return vo.getStatisticYear() != null ? vo.getStatisticYear() : "";
|
|
|
+ default:
|
|
|
+ return StringUtils.isNotBlank(vo.getStatisticMonth()) ? vo.getStatisticMonth() : "";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除光伏并网计量光伏并网计量-小时信息
|
|
|
- *
|
|
|
- * @param id 光伏并网计量光伏并网计量-小时主键
|
|
|
- * @return 结果
|
|
|
+ * 数字格式化
|
|
|
*/
|
|
|
- @Override
|
|
|
- public int deletePvSupplyHById(Long id) {
|
|
|
- return pvSupplyHMapper.deletePvSupplyHById(id);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<String, ElecPvSupplyH> calPvByDateRange(QueryMeter param) {
|
|
|
- Future<?> thisDay = ThreadUtil.execAsync(() -> pvSupplyHMapper.calPvByDateRange(new QueryMeter() {{
|
|
|
- setDate(DateTimeUtil.currentDateTime(DateTimeUtil.DateFormatter.yyyy_MM_dd));
|
|
|
- setAreaCode(param.getAreaCode());
|
|
|
- }}));
|
|
|
- Future<?> thisMonth = ThreadUtil.execAsync(() -> pvSupplyHMapper.calPvByDateRange(new QueryMeter() {
|
|
|
- {
|
|
|
- setDate(DateTimeUtil.currentDateTime(DateTimeUtil.DateFormatter.yyyy_MM));
|
|
|
- setAreaCode(param.getAreaCode());
|
|
|
+ private String formatNumber(java.math.BigDecimal num, int decimals) {
|
|
|
+ if (num == null) {
|
|
|
+ StringBuilder sb = new StringBuilder("0.");
|
|
|
+ for (int i = 0; i < decimals; i++) {
|
|
|
+ sb.append("0");
|
|
|
}
|
|
|
- }));
|
|
|
- Future<?> thisYear = ThreadUtil.execAsync(() -> pvSupplyHMapper.calPvByDateRange(new QueryMeter() {{
|
|
|
- setAreaCode(param.getAreaCode());
|
|
|
- setDate(DateTimeUtil.currentDateTime(DateTimeUtil.DateFormatter.yyyy));
|
|
|
- }}));
|
|
|
- Future<?> total = ThreadUtil.execAsync(() -> pvSupplyHMapper.calPvByDateRange(new QueryMeter() {{
|
|
|
- setAreaCode(param.getAreaCode());
|
|
|
- }}));
|
|
|
- Map<String, ElecPvSupplyH> result = new HashMap<>();
|
|
|
- try {
|
|
|
- result.put("thisDay", (ElecPvSupplyH) thisDay.get());
|
|
|
- result.put("thisMonth", (ElecPvSupplyH) thisMonth.get());
|
|
|
- result.put("thisYear", (ElecPvSupplyH) thisYear.get());
|
|
|
- result.put("total", (ElecPvSupplyH) total.get());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("calPvByDateRange error {}", e.getMessage());
|
|
|
+ return sb.toString();
|
|
|
}
|
|
|
- return result;
|
|
|
+ return String.format("%." + decimals + "f", num.doubleValue());
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<ElecPvSupplyH> calDayPvRange(QueryMeter param) {
|
|
|
- return pvSupplyHMapper.calDayPvRange(param);
|
|
|
+ /**
|
|
|
+ * 日期格式化用于显示
|
|
|
+ */
|
|
|
+ private String formatDateForDisplay(Date dateObj) {
|
|
|
+ return DateUtils.dateToString(dateObj, "yyyy-MM-dd");
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<ElecPvSupplyH> calHourPvRange(QueryMeter param) {
|
|
|
- return pvSupplyHMapper.calHourPvRange(param);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 克隆查询参数对象
|
|
|
+ */
|
|
|
+ private QueryMeter cloneQueryMeter(QueryMeter source) {
|
|
|
+ if (source == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public List<ElecPvSupplyH> calMonthPvByDateRange(QueryMeter param) {
|
|
|
- return pvSupplyHMapper.calMonthPvByDateRange(param);
|
|
|
+ QueryMeter target = new QueryMeter();
|
|
|
+ target.setAreaCode(source.getAreaCode());
|
|
|
+ target.setTimeDimension(source.getTimeDimension());
|
|
|
+ target.setStartRecTime(source.getStartRecTime());
|
|
|
+ target.setEndRecTime(source.getEndRecTime());
|
|
|
+ target.setOrderFlag(source.getOrderFlag());
|
|
|
+ // 不复制分页参数
|
|
|
+ target.setPageNum(null);
|
|
|
+ target.setPageSize(null);
|
|
|
+
|
|
|
+ return target;
|
|
|
}
|
|
|
-}
|
|
|
+}
|