package com.ruoyi.other.emind.controller;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.other.emind.domain.EmindStation;
|
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;
|
|
import java.util.List;
|
|
@RestController
|
@RequestMapping("/emind/stations")
|
public class EmindStationController {
|
private final EmindStationManagementService service;
|
|
public EmindStationController(EmindStationManagementService service) {
|
this.service = service;
|
}
|
|
@PostMapping("/page")
|
public R<IPage<EmindStation>> page(@RequestBody EmindStationPageQuery query) {
|
return R.ok(service.page(query));
|
}
|
|
@PostMapping
|
public R<EmindStation> add(@RequestBody EmindStation 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;
|
}
|
}
|