From 8fab4df47dcd0dc7efe4a13f2f31897ce5751963 Mon Sep 17 00:00:00 2001
From: yanderong <307678080@qq.com>
Date: 星期日, 27 九月 2026 14:14:12 +0800
Subject: [PATCH] feat: 储能数据同步-能量链修改,新增需求
---
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TStationCollectServiceImpl.java | 65 ++++++++++++++++++++++++++++++++
1 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TStationCollectServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TStationCollectServiceImpl.java
index 78bb1d8..d4ef6ca 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TStationCollectServiceImpl.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TStationCollectServiceImpl.java
@@ -262,6 +262,17 @@
}
}
+ private Integer parseInteger(String value) {
+ if (StringUtils.isBlank(value)) {
+ return 0;
+ }
+ try {
+ return Integer.valueOf(value);
+ } catch (NumberFormatException exception) {
+ return parsePowerNum(value);
+ }
+ }
+
private LocalDateTime parseDateTime(String value) {
if (StringUtils.isBlank(value)) {
return null;
@@ -293,4 +304,58 @@
}
return true;
}
+
+ /**
+ * 将华为 FusionSolar 设备列表转换为逆变器记录并批量保存。
+ * devDn 作为设备唯一标识(接口未提供时使用 esnCode)。
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public boolean saveCollectHuaWeiList(JSONArray devList) {
+ if (devList == null || devList.isEmpty()) {
+ return false;
+ }
+ Set<String> existingKeys = getExistingCollectKeys();
+ Set<String> pendingKeys = new HashSet<>();
+ List<TStationCollect> insertList = new ArrayList<>(devList.size());
+ for (Object item : devList) {
+ if (item == null) {
+ continue;
+ }
+ JSONObject json = JSONObject.parseObject(item.toString());
+ String collectId = firstNotBlank(json.getString("devDn"), json.getString("esnCode"));
+ String stationId = json.getString("stationCode");
+ if (StringUtils.isBlank(collectId) || StringUtils.isBlank(stationId)
+ || existingKeys.contains(collectId) || !pendingKeys.add(collectId)) {
+ continue;
+ }
+ TStationCollect collect = new TStationCollect();
+ collect.setPlatformId(1L);
+ collect.setStationId(stationId);
+ collect.setStationName(firstNotBlank(json.getString("stationName"), ""));
+ collect.setCollectId(collectId);
+ collect.setCollectName(firstNotBlank(json.getString("devName"), collectId));
+ collect.setDeviceModel(firstNotBlank(json.getString("invType"), json.getString("model")));
+ collect.setInverterId(json.getString("esnCode"));
+ collect.setInstalledCapacity(firstNotBlank(json.getString("capacity"), "0"));
+ collect.setPowerNum(parseInteger(json.getString("optimizerNumber")));
+ collect.setLatitude(json.getString("latitude"));
+ collect.setLongitude(json.getString("longitude"));
+ collect.setStatus("1");
+ collect.setDataSource(2);
+ collect.setSyncTime(LocalDateTime.now());
+ collect.setCreateTime(LocalDateTime.now());
+ collect.setUpdateTime(LocalDateTime.now());
+ fillDefaults(collect);
+ insertList.add(collect);
+ }
+ // 设置电站名称
+ List<TStationInfo> infoList = stationInfoMapper.selectList(new LambdaQueryWrapper<>());
+ insertList.forEach(s -> infoList.forEach(info -> {
+ if(StringUtils.isNotEmpty(s.getStationId()) && s.getStationId().equals(info.getStationId())) {
+ s.setStationName(info.getStationName());
+ }
+ }));
+ return CollectionUtils.isNotEmpty(insertList) && saveBatch(insertList);
+ }
}
--
Gitblit v1.7.1