From e33bca52d26faa836a4db7436e85eb3a0a08adff Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 19 八月 2025 17:26:02 +0800
Subject: [PATCH] 1、增加查询所有作物昨日蒸腾量功能; 2、增加查询一个作物一段时间内容所有蒸腾量功能。

---
 pipIrr-platform/pipIrr-web/pipIrr-web-model/src/main/java/com/dy/pipIrrModel/modelCalculate/ModelCalculator.java |  130 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 130 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-model/src/main/java/com/dy/pipIrrModel/modelCalculate/ModelCalculator.java b/pipIrr-platform/pipIrr-web/pipIrr-web-model/src/main/java/com/dy/pipIrrModel/modelCalculate/ModelCalculator.java
new file mode 100644
index 0000000..308d460
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-model/src/main/java/com/dy/pipIrrModel/modelCalculate/ModelCalculator.java
@@ -0,0 +1,130 @@
+package com.dy.pipIrrModel.modelCalculate;
+
+import com.dy.common.util.DateTime;
+import com.dy.pipIrrGlobal.pojoMd.MdEt0;
+import com.dy.pipIrrGlobal.voMd.VoCrops;
+import com.dy.pipIrrGlobal.voPr.VoWeather;
+import com.dy.pipIrrGlobal.voRm.VoWeatherMaxMinTmp;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/8/18 16:26
+ * @Description
+ */
+@Slf4j
+@Component(ModelCalculator.selfBeanName)
+@Scope("prototype") //閲囩敤鍘熷瀷妯″紡锛屾瘡娆¤姹傛柊寤轰竴涓疄渚嬪璞�
+public class ModelCalculator {
+    public static final String selfBeanName = "modelCalculator";
+
+    private ModelCalculatorSv sv ;
+
+    @Autowired
+    public void setSv(ModelCalculatorSv sv){
+        this.sv = sv ;
+    }
+
+    public void execute(){
+        List<VoCrops> crops = this.sv.selectAllCrops() ;
+        if(crops != null && crops.size() > 0){
+            for (VoCrops crop : crops) {
+                if(crop.weatherId != null){
+                    try{
+                        VoWeather voWeather = this.sv.getWeather(crop.weatherId);
+                        if(voWeather.lat != null){
+                            this.executeOnCrop(crop, voWeather);
+                        }
+                    }catch (Exception e){
+                        log.error("璁$畻浣滅墿锛坕d=" + crop.id + "锛夎捀鑵炬暟鎹椂寮傚父", e);
+                    }
+                }
+            }
+        }
+    }
+    private void executeOnCrop(VoCrops vo, VoWeather voWeather) throws Exception{
+        String yesterday_ymd = DateTime.yesterday_yyyy_MM_dd(Integer.parseInt(DateTime.yyyy()), Integer.parseInt(DateTime.MM()), Integer.parseInt(DateTime.dd())) ; //鏄ㄥぉ
+        Double factor = this.getCropsFactor(vo, yesterday_ymd) ;
+        if(factor != null){
+            //璇存槑浣滅墿澶勪簬璁$畻鏈燂紙浣滅墿鐢熼暱鏈燂級涓�
+            List<VoWeatherMaxMinTmp> tmps = this.sv.selectYesterdayMaxMinTemperature(vo.weatherId) ;
+            if(tmps != null && tmps.size() > 0){
+                VoWeatherMaxMinTmp voMmTmp = tmps.get(0);//鍙兘鏈変竴鏉¤褰�
+                Double et0 = this.calculateEt0(yesterday_ymd, vo, voWeather, voMmTmp, factor) ;//璁$畻钂歌吘鏁版嵁
+                this.saveEt0(yesterday_ymd, vo, voWeather, voMmTmp, factor, et0) ;
+            }
+        }
+    }
+    private Double getCropsFactor(VoCrops vo, String yesterday) throws Exception{
+        Double factor = null ;
+        if(vo.stopped != null && vo.stopped != 1){
+            if(vo.startDt != null && vo.endDt != null){
+                String start = DateTime.yyyy() + "-" + vo.startDt ;
+                Long days = DateTime.daysBetweenyyyy_MM_dd(yesterday, start) ;
+                if(days >= 0){
+                    if(vo.life4Start != null && vo.life4End != null){
+                        if(days >= vo.life4Start && days <= vo.life4End){
+                            factor = vo.life4Factor ;
+                        }
+                        if(days > vo.life4End){
+                            factor = null ;
+                        }
+                    }
+                    if(vo.life3Start != null && vo.life3End != null){
+                        if(days >= vo.life3Start && days <= vo.life3End){
+                            factor = vo.life3Factor ;
+                        }
+                    }
+                    if(vo.life2Start != null && vo.life2End != null){
+                        if(days >= vo.life2Start && days <= vo.life2End){
+                            factor = vo.life2Factor ;
+                        }
+                    }
+                    if(vo.life1Start != null && vo.life1End != null){
+                        if(days >= vo.life1Start && days <= vo.life1End){
+                            factor = vo.life1Factor ;
+                        }
+                        if(days < vo.life1Start){
+                            factor = null ;
+                        }
+                    }
+                }else{
+                    factor = null ;
+                }
+            }
+        }
+        return factor ;
+    }
+
+    private Double calculateEt0(String yesterday_ymd, VoCrops vo, VoWeather voWeather, VoWeatherMaxMinTmp voMmTmp, Double factor) throws Exception{
+        Long days = DateTime.daysBetweenyyyy_MM_dd(yesterday_ymd, DateTime.yyyy() + "-01-01");
+        Integer dayIndex = days.intValue() + 1 ;
+
+        Double fai = Hargreaves.rad(voWeather.lat);
+
+        Double sunMagnetismAngular = Hargreaves.sunMagnetismAngular(dayIndex);
+
+        Double sunEarthDistance = Hargreaves.sunEarthDistance(dayIndex);
+
+        Double sunTimeAngular = Hargreaves.sunTimeAngular(fai, sunMagnetismAngular);
+
+        Double zenithRadiation = Hargreaves.zenithRadiation(sunEarthDistance, sunTimeAngular, fai, sunMagnetismAngular);
+
+        Double et0 = Hargreaves.ET0(factor, voMmTmp.maxAirTemperature, voMmTmp.minAirTemperature, zenithRadiation);
+        return et0 ;
+    }
+
+    private void saveEt0(String yesterday_ymd, VoCrops vo, VoWeather voWeather, VoWeatherMaxMinTmp voMmTmp, Double factor, Double et0)throws Exception{
+        MdEt0 po = this.sv.selectByCropWeatherDt(vo.id, voWeather.id, yesterday_ymd);
+        if(po != null){
+            Date yesterday = DateTime.dateFrom_yyyy_MM_dd(yesterday_ymd) ;
+            this.sv.saveEt0(vo.id, voWeather.id, yesterday, voMmTmp.maxAirTemperature, voMmTmp.minAirTemperature, factor, et0) ;
+        }
+    }
+}

--
Gitblit v1.8.0