yanderong
2 天以前 686790777f722b0621bcc20e550d15965cda7b67
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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;
    }
}