zhubaomin
19 小时以前 6f2c512bffe6faaa8536fa98fbf2b2e552b6a2ac
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.dy.pipIrrIrrigate.irrigatePlan;
 
import com.dy.common.aop.SsoAop;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.pipIrrIrrigate.irrigatePlan.dto.IrrigatePlan;
import com.dy.pipIrrIrrigate.irrigatePlan.dto.PlanSimple;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Map;
import java.util.Objects;
 
/**
 * @author ZhuBaoMin
 * @date 2025-06-30 14:58
 * @LastEditTime 2025-06-30 14:58
 * @Description
 */
 
@Slf4j
@RestController
@RequestMapping(path = "plan")
@RequiredArgsConstructor
public class IrrigatePlanCtrl {
    private final IrrigatePlanSv irrigatePlanSv;
 
    /**
     * 创建灌溉计划
     * @param planAndSchedule
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "createPlan", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<Boolean> createPlan(@RequestBody @Valid IrrigatePlan planAndSchedule, BindingResult bindingResult){
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = irrigatePlanSv.createPlan(planAndSchedule);
        if(map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess() ;
    }
 
    /**
     * 删除灌溉计划
     * @param planSimple
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "deletePlan")
    @SsoAop()
    public BaseResponse<Boolean> deletePlan(@RequestBody @Valid PlanSimple planSimple, BindingResult bindingResult) {
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = irrigatePlanSv.deletePlan(planSimple);
        if(map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess() ;
    }
 
    /**
     * 发布灌溉计划
     * 1. 修改灌溉计划状态为发布状态
     * 2. 添加灌溉计划操作记录
     * 3. 生成开阀计划
     * @param planSimple
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "publishPlan", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<Boolean> publishPlan(@RequestBody @Valid PlanSimple planSimple, BindingResult bindingResult){
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = irrigatePlanSv.publishPlan(planSimple);
        if(map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess() ;
    }
 
    /**
     * 终止灌溉计划
     * @param planSimple
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "terminatePlan", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<Boolean> terminatePlan(@RequestBody @Valid PlanSimple planSimple, BindingResult bindingResult){
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
 
        Map map_result = irrigatePlanSv.terminatePlan(planSimple);
        if(map_result.get("success").equals(false)) {
            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
        }
        return BaseResponseUtils.buildSuccess() ;
    }
}