| | |
| | | import com.ruoyi.other.mapper.TStationInfoMapper; |
| | | import com.ruoyi.other.query.StationCollectQuery; |
| | | import com.ruoyi.other.service.TStationCollectService; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.format.DateTimeParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | .like(StringUtils.isNotBlank(query.getDeviceModel()), TStationCollect::getDeviceModel, query.getDeviceModel()) |
| | | .like(StringUtils.isNotBlank(query.getInverterId()), TStationCollect::getInverterId, query.getInverterId()) |
| | | .eq(StringUtils.isNotBlank(query.getStatus()), TStationCollect::getStatus, query.getStatus()) |
| | | .in(StringUtils.isBlank(query.getStatus()) && Boolean.TRUE.equals(query.getAbnormalOnly()), |
| | | TStationCollect::getStatus, "2", "3") |
| | | .orderByAsc(TStationCollect::getSortOrder).orderByDesc(TStationCollect::getCreateTime).page(page); |
| | | fillStationAddress(page.getRecords()); |
| | | return page; |
| | |
| | | } |
| | | } |
| | | |
| | | 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; |
| | |
| | | private String firstNotBlank(String preferred, String fallback) { |
| | | return StringUtils.isNotBlank(preferred) ? preferred : fallback; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据ids删除数据时,校验示范存在第三方同步的数据,第三方同步的数据不允许删除 |
| | | * @param ids 数据id |
| | | * @return true可以删除,false不可以删除 |
| | | */ |
| | | public Boolean validateDelete(Long[] ids) { |
| | | if(ids != null && ids.length > 0) { |
| | | List<Long> idList = Arrays.stream(ids).collect(Collectors.toList()); |
| | | List<TStationCollect> infoList = lambdaQuery().eq(TStationCollect::getDataSource, 2).in(TStationCollect::getId, idList).list(); |
| | | if(CollectionUtils.isNotEmpty(infoList) && !infoList.isEmpty()) { |
| | | return false; |
| | | } |
| | | } |
| | | 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"); |
| | | Integer devTypeId = json.getInteger("devTypeId"); |
| | | if (StringUtils.isBlank(collectId) || StringUtils.isBlank(stationId) |
| | | || existingKeys.contains(collectId) || !pendingKeys.add(collectId) || devTypeId != 1) { |
| | | 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); |
| | | } |
| | | } |