| | |
| | | import com.ruoyi.other.service.TStationInfoService; |
| | | import com.ruoyi.other.query.StationInfoQuery; |
| | | import com.ruoyi.other.util.KsolarUtils; |
| | | import com.ruoyi.other.util.HuWeiUtils; |
| | | import com.ruoyi.other.vo.StationInfoStatusVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.OffsetDateTime; |
| | | import java.time.ZonedDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.format.DateTimeParseException; |
| | | import java.util.*; |
| | |
| | | @Autowired |
| | | private TStationEarnService stationEarnService; |
| | | |
| | | @Autowired |
| | | private HuWeiUtils huWeiUtils; |
| | | |
| | | /** |
| | | * 每天同步科士达数据到数据库 |
| | |
| | | } |
| | | } |
| | | |
| | | private LocalDateTime parseHuaweiDateTime(String value) { |
| | | if (StringUtils.isBlank(value)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return OffsetDateTime.parse(value).toLocalDateTime(); |
| | | } catch (DateTimeParseException ignored) { |
| | | try { |
| | | return ZonedDateTime.parse(value).toLocalDateTime(); |
| | | } catch (DateTimeParseException ignoredAgain) { |
| | | return parseDataTime(value); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private String firstNotBlank(String preferred, String fallback) { |
| | | return StringUtils.isNotBlank(preferred) ? preferred : fallback; |
| | | } |
| | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 同步华为 FusionSolar 电站数据。 |
| | | * 电站编号 plantCode 作为系统中的 stationId,仅插入数据库中不存在的电站。 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void syncHuaWeiDataTask() { |
| | | log.info("-------1、开始同步华为电站列表信息----"); |
| | | String token = huWeiUtils.getXsrfToken(); |
| | | JSONArray stationArray = huWeiUtils.getStations(1, token); |
| | | Set<String> stationIds = new HashSet<>(); |
| | | if (CollectionUtils.isNotEmpty(stationArray)) { |
| | | List<TStationInfo> insertList = new ArrayList<>(); |
| | | huaWeiBuild(stationArray, stationIds, insertList); |
| | | |
| | | if (CollectionUtils.isNotEmpty(insertList)) { |
| | | List<TStationInfo> existing = lambdaQuery().eq(TStationInfo::getPlatformId, 1L).in(TStationInfo::getStationId, stationIds).list(); |
| | | Set<String> existingIds = existing.stream().map(TStationInfo::getStationId).collect(Collectors.toSet()); |
| | | insertList.removeIf(item -> existingIds.contains(item.getStationId())); |
| | | if (CollectionUtils.isNotEmpty(insertList)) { |
| | | saveBatch(insertList); |
| | | } |
| | | } |
| | | log.info("-------1、结束同步华为电站列表信息,本次新增{}条----", insertList.size()); |
| | | } |
| | | |
| | | log.info("-------2、开始同步华为设备列表信息----"); |
| | | if(CollectionUtils.isNotEmpty(stationIds)) { |
| | | String codes = String.join(",", stationIds); |
| | | JSONArray devList = huWeiUtils.getDevList(codes, token); |
| | | collectService.saveCollectHuaWeiList(devList); |
| | | } |
| | | |
| | | log.info("-------3、开始同步华为电站日数据信息----"); |
| | | List<TStationInfo> existInfos = lambdaQuery().eq(TStationInfo::getPlatformId, 1L).list(); |
| | | Set<String> existIds = existInfos.stream().map(TStationInfo::getStationId).collect(Collectors.toSet()); |
| | | if(CollectionUtils.isNotEmpty(existIds)) { |
| | | String codes = String.join(",", existIds); |
| | | JSONArray stationDayList = huWeiUtils.getKpiStationDay(codes, System.currentTimeMillis(), token); |
| | | stationEarnService.saveStationHuaWeiList(stationDayList); |
| | | } |
| | | log.info("-------3、结束同步华为电站日数据信息----"); |
| | | |
| | | |
| | | } |
| | | |
| | | public void huaWeiBuild(JSONArray stationArray, Set<String> stationIds, List<TStationInfo> insertList) { |
| | | for (Object item : stationArray) { |
| | | JSONObject json = JSONObject.parseObject(item.toString()); |
| | | String stationId = json.getString("plantCode"); |
| | | if (StringUtils.isBlank(stationId) || !stationIds.add(stationId)) { |
| | | continue; |
| | | } |
| | | TStationInfo info = new TStationInfo(); |
| | | info.setPlatformId(1L); |
| | | info.setStationId(stationId); |
| | | info.setStationName(json.getString("plantName")); |
| | | info.setStationType("1"); |
| | | info.setRunStatus("0"); |
| | | info.setInstalledCapacity(toBigDecimal(json, "capacity")); |
| | | info.setContactName(json.getString("contactPerson")); |
| | | info.setPhone(json.getString("contactMethod")); |
| | | info.setLatitude(json.getString("latitude")); |
| | | info.setLongitude(json.getString("longitude")); |
| | | info.setAddress(json.getString("plantAddress")); |
| | | LocalDateTime gridTime = parseHuaweiDateTime(json.getString("gridConnectionDate")); |
| | | info.setDataTime(gridTime); |
| | | info.setLoanStatus(gridTime != null && gridTime.isBefore(LocalDateTime.now()) ? 3 : 1); |
| | | info.setGridStatus(info.getLoanStatus() == 3 ? "1" : "0"); |
| | | info.setDataSource(2); |
| | | info.setSyncTime(LocalDateTime.now()); |
| | | info.setCreateTime(LocalDateTime.now()); |
| | | info.setUpdateTime(LocalDateTime.now()); |
| | | fillDefaults(info); |
| | | insertList.add(info); |
| | | } |
| | | } |
| | | |
| | | } |