ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/emind/controller/EmindStationController.java
@@ -6,8 +6,10 @@ import com.ruoyi.other.emind.dto.EmindStationPageQuery; import com.ruoyi.other.emind.service.EmindStationManagementService; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -30,14 +32,27 @@ @PostMapping public R<EmindStation> add(@RequestBody EmindStation station) { if (station.getName() == null || station.getName().trim().isEmpty()) { return R.fail("电站名称不能为空"); } return R.ok(service.add(station)); String validation = validate(station); return validation == null ? R.ok(service.add(station)) : R.fail(validation); } @GetMapping("/{id}") public R<EmindStation> detail(@PathVariable Long id) { return R.ok(service.detail(id)); } @PutMapping("/{id}") public R<EmindStation> update(@PathVariable Long id, @RequestBody EmindStation station) { String validation = validate(station); return validation == null ? R.ok(service.update(id, station)) : R.fail(validation); } @DeleteMapping("/{ids}") public R<Integer> delete(@PathVariable List<Long> ids) { return R.ok(service.delete(ids)); } private String validate(EmindStation station) { return station.getName() == null || station.getName().trim().isEmpty() ? "电站名称不能为空" : null; } } ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/emind/service/EmindStationManagementService.java
@@ -59,6 +59,31 @@ return station; } public EmindStation detail(Long id) { EmindStation station = mapper.selectById(id); if (station == null || Integer.valueOf(1).equals(station.getManagementDeleted())) { throw new IllegalArgumentException("储能电站不存在"); } return station; } @Transactional(rollbackFor = Exception.class) public EmindStation update(Long id, EmindStation input) { EmindStation station = detail(id); station.setName(input.getName()); station.setAddress(input.getAddress()); station.setProvince(input.getProvince()); station.setCity(input.getCity()); station.setLongitude(input.getLongitude()); station.setLatitude(input.getLatitude()); station.setMaxPower(input.getMaxPower()); station.setCapacity(input.getCapacity()); station.setCommissioningTime(input.getCommissioningTime()); station.setUpdateTime(LocalDateTime.now(clock)); mapper.updateById(station); return station; } @Transactional(rollbackFor = Exception.class) public int delete(List<Long> ids) { if (ids == null || ids.isEmpty()) { ruoyi-service/ruoyi-other/src/test/java/com/ruoyi/other/emind/service/EmindStationManagementServiceTest.java
@@ -83,4 +83,26 @@ eq(Arrays.asList(1L, 2L)), eq(LocalDateTime.of(2026, 7, 24, 6, 0))); } @Test void updatePreservesManagedFieldsAndUpdatesEditableValues() { EmindStation existing = new EmindStation(); existing.setId(1L); existing.setStationId(9L); existing.setPlatformName("利普芯"); existing.setSourceType(EmindStation.SOURCE_REMOTE); when(mapper.selectById(1L)).thenReturn(existing); EmindStation input = new EmindStation(); input.setName("更新后的电站"); input.setAddress("新地址"); input.setCapacity("100kWh"); service.update(1L, input); verify(mapper).updateById(existing); assertEquals("更新后的电站", existing.getName()); assertEquals("利普芯", existing.getPlatformName()); assertEquals(Long.valueOf(9L), existing.getStationId()); assertEquals(LocalDateTime.of(2026, 7, 24, 6, 0), existing.getUpdateTime()); } }