liurunyu
5 天以前 e1f1023dee5d094fcb1e428f36cce09211c4542a
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
package com.dy.pipIrrModel.vapor;
 
import com.dy.common.aop.SsoAop;
import com.dy.common.util.DateTime;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.pipIrrModel.modelCalculate.Hargreaves;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
 
/**
 * @Author: liurunyu
 * @Date: 2025/8/22 10:20
 * @Description 不要删除!!! 为前端蒸散量计算提供的服务
 */
 
@Slf4j
@Tag(name = "作物日蒸散量计算测试", description = "作物日蒸散量计算测试")
@RestController
@RequestMapping(path = "mdTest")
public class TestCtrl {
 
    private TestSv sv;
 
    @Autowired
    private void setSv(TestSv sv) { this.sv = sv; }
 
    /**
     * 得到初始化数据
     */
    @GetMapping(path = "initData")
    @SsoAop()
    public BaseResponse<TestInitVo> initData(){
        try {
            TestInitVo vo = new TestInitVo();
            String yesterday_ymd = DateTime.lastXDay_yyyy_MM_dd(1) ;
            Long days = DateTime.daysBetweenyyyy_MM_dd(yesterday_ymd, DateTime.yyyy() + "-01-01");
            vo.dateIndex = days.intValue() + 1 ;
            vo.ymd = yesterday_ymd ;
 
            Object[] objs = this.sv.getOneWeatherNameAndLat() ;
            if(objs != null){
                vo.weatherName = objs[0].toString() ;
                vo.lat = Double.parseDouble(objs[1].toString()) ;
            }else{
                vo.weatherName = "" ;
                vo.lat = 0.0 ;
            }
            return BaseResponseUtils.buildSuccess(vo);
        } catch (Exception e) {
            log.error("查询所有作物的昨日蒸散量异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
 
    /**
     * 计算日序
     */
    @GetMapping(path = "dateIndex")
    @SsoAop()
    public BaseResponse<Integer> dateIndex(String y_m_d){
        try {
            Long days = DateTime.daysBetweenyyyy_MM_dd(y_m_d, y_m_d.substring(0, 4) + "-01-01");
            Integer dateIndex = days.intValue() + 1 ;
            return BaseResponseUtils.buildSuccess(dateIndex);
        } catch (Exception e) {
            log.error("计算日序异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
 
    @PostMapping(path = "calculate", consumes = MediaType.APPLICATION_JSON_VALUE)
    @SsoAop()
    public BaseResponse<Double> calculate(@RequestBody TestQo qo){
        try {
            Double fai = Hargreaves.rad(qo.lat);
 
            Double sunMagnetismAngular = Hargreaves.sunMagnetismAngular(qo.dateIndex);
 
            Double sunEarthDistance = Hargreaves.sunEarthDistance(qo.dateIndex);
 
            Double sunTimeAngular = Hargreaves.sunTimeAngular(fai, sunMagnetismAngular);
 
            Double zenithRadiation = Hargreaves.zenithRadiation(sunEarthDistance, sunTimeAngular, fai, sunMagnetismAngular);
 
            Double et0 = Hargreaves.ET0(qo.kc, qo.maxTmp, qo.minTmp, zenithRadiation);
            return BaseResponseUtils.buildSuccess(et0);
        } catch (Exception e) {
            log.error("查询所有作物的昨日蒸散量异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
 
    public static void main(String[] args) {
        String ymd = "2025-08-22" ;
        String year = ymd.substring(0, 4) ;
        System.out.println(year);
    }
}