puzhibing
2026-09-11 72ac1dce414d20a973104a0eb046809a2eaa5ed7
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,51 @@
        }
        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);
        }
        return CollectionUtils.isNotEmpty(insertList) && saveBatch(insertList);
    }
}