潘志宝
2024-09-05 7fd198b8ebe97cd06b10f96b9179caebe679783c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.iailab.module.model.mcs.sche.controller;
 
import com.iailab.framework.common.exception.ErrorCode;
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.module.model.mcs.sche.entity.StScheduleEnergyTypeEntity;
import com.iailab.module.model.mcs.sche.service.StScheduleEnergyTypeService;
import com.iailab.module.model.mcs.sche.vo.StScheduleEnergyTypePageReqVO;
import com.iailab.module.model.mcs.sche.vo.StScheduleEnergyTypeRespVO;
import com.iailab.module.model.mcs.sche.vo.StScheduleRespVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.Map;
 
import static com.iailab.framework.common.pojo.CommonResult.error;
import static com.iailab.framework.common.pojo.CommonResult.success;
 
/**
 * @author PanZhibao
 * @date 2021年07月20日 14:02
 */
@RestController
@RequestMapping("/sche/schedule-energy-type")
public class StScheduleEnergyTypeController {
    @Autowired
    private StScheduleEnergyTypeService stScheduleEnergyTypeService;
 
    /**
     * 调度类型列表
     */
    @GetMapping("/page")
    public CommonResult<PageResult<StScheduleEnergyTypeRespVO>> page(@Validated StScheduleEnergyTypePageReqVO reqVO) {
        PageResult<StScheduleEnergyTypeEntity> page = stScheduleEnergyTypeService.page(reqVO);
 
        return success(BeanUtils.toBean(page, StScheduleEnergyTypeRespVO.class));
    }
 
    /**
     * 调度能源类型信息
     */
    @GetMapping("/info/{id}")
    public CommonResult<StScheduleEnergyTypeEntity> info(@PathVariable("id") String id){
        StScheduleEnergyTypeEntity scheduleEnergyType = stScheduleEnergyTypeService.selectById(id);
        return success(scheduleEnergyType);
    }
 
    /**
     * 保存调度能源类型
     */
    @PostMapping
    public CommonResult<Boolean> save(@RequestBody StScheduleEnergyTypeEntity scheduleEnergyType){
        int count = stScheduleEnergyTypeService.check(scheduleEnergyType);
        if (count > 0) {
            ErrorCode errorCode = new ErrorCode(999, "名称重复");
            return error(errorCode);
        }
        stScheduleEnergyTypeService.saveScheduleEnergyType(scheduleEnergyType);
        return success(true);
    }
 
    /**
     * 修改调度能源类型
     */
    @PutMapping
    public CommonResult<Boolean> update(@RequestBody StScheduleEnergyTypeEntity scheduleEnergyType){
        int count = stScheduleEnergyTypeService.check(scheduleEnergyType);
        if (count > 0) {
            ErrorCode errorCode = new ErrorCode(999, "名称重复");
            return error(errorCode);
        }
        stScheduleEnergyTypeService.update(scheduleEnergyType);
        return success(true);
    }
 
    /**
     * 删除调度能源类型
     */
    @DeleteMapping("/delete")
    public CommonResult<Boolean> delete(@RequestParam("id") String id){
        stScheduleEnergyTypeService.deleteBatch(new String[]{id});
        return success(true);
    }
}