package com.ruoyi.other.service.impl; import com.alibaba.fastjson.JSONArray; import com.ruoyi.other.api.domain.TStationEarn; import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.time.LocalDate; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; class TStationEarnServiceImplTest { @Test void refreshesExistingDailyEarnInsteadOfDroppingIt() { TStationEarn existing = new TStationEarn(); existing.setId(9L); existing.setPlatformId(0L); existing.setStationId("station-1"); existing.setSaveTime(LocalDate.of(2026, 7, 28)); Map existingByKey = new LinkedHashMap<>(); existingByKey.put("0|station-1|2026-07-28", existing); JSONArray records = JSONArray.parseArray("[" + "{\"stationId\":\"station-1\",\"stationName\":\"光伏1号\",\"saveTime\":\"2026-07-28 12:00:00\",\"elecTotal\":\"611.5\",\"earnTotal\":\"611.5\"}," + "{\"stationId\":\"station-2\",\"stationName\":\"光伏2号\",\"saveTime\":\"2026-07-28 12:00:00\",\"elecTotal\":\"694.2\",\"earnTotal\":\"694.2\"}" + "]"); List merged = TStationEarnServiceImpl.buildStationEarnSyncList(records, existingByKey); assertEquals(2, merged.size()); assertEquals(9L, merged.get(0).getId()); assertEquals(new BigDecimal("611.5"), merged.get(0).getElecTotal()); assertEquals(new BigDecimal("694.2"), merged.get(1).getElecTotal()); assertEquals(null, merged.get(1).getId()); } }