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); 
 | 
    } 
 | 
} 
 |