liurunyu
2025-08-21 5715d16c6fc4842191c802adb2e3b94d19f44f17
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
package com.dy.pipIrrModel.modelCalculate;
 
import com.dy.common.util.DateTime;
import com.dy.common.util.IDLongGenerator;
import com.dy.pipIrrGlobal.daoMd.MdCropsMapper;
import com.dy.pipIrrGlobal.daoMd.MdEt0Mapper;
import com.dy.pipIrrGlobal.daoPr.PrStWeatherMapper;
import com.dy.pipIrrGlobal.daoRm.RmWeatherHistoryMapper;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.List;
 
/**
 * @Author: liurunyu
 * @Date: 2025/8/18 16:34
 * @Description
 */
@Slf4j
@Service
public class ModelCalculatorSv {
    private MdCropsMapper mdCropsDao ;
    private PrStWeatherMapper prWeatherDao ;
    private RmWeatherHistoryMapper rmWeatherHistoryDao;
    private MdEt0Mapper mdEt0Dao;
 
    @Autowired
    private void setDao(MdCropsMapper mdCropsDao,
                        PrStWeatherMapper prWeatherDao,
                        RmWeatherHistoryMapper rmWeatherHistoryDao,
                        MdEt0Mapper mdEt0Dao) {
        this.mdCropsDao = mdCropsDao;
        this.prWeatherDao = prWeatherDao;
        this.rmWeatherHistoryDao = rmWeatherHistoryDao;
        this.mdEt0Dao = mdEt0Dao;
    }
    /**
     * 查询所有作物
     * @return 包含实体集合的结果对象
     */
    @SuppressWarnings("unchecked")
    public List<VoCrops> selectAllCrops(){
        return this.mdCropsDao.selectAll() ;
    }
 
    public VoWeather getWeather(Long weatherId) throws Exception{
        return this.prWeatherDao.selectOne(weatherId) ;
    }
 
    public List<VoWeatherMaxMinTmp> selectYesterdayMaxMinTemperature(Long weatherId) throws Exception{
        String ymd = DateTime.yesterday_yyyy_MM_dd(Integer.parseInt(DateTime.yyyy()), Integer.parseInt(DateTime.MM()), Integer.parseInt(DateTime.dd())) ; //昨天
        int[] ymdGrp = DateTime.yyyy_MM_dd_2_ymdGroup(ymd) ;
        Long startId = IDLongGenerator.generateOneDayStartId(ymdGrp[0], ymdGrp[1], ymdGrp[2]) ;
        Long endId = IDLongGenerator.generateOneDayEndId(ymdGrp[0], ymdGrp[1], ymdGrp[2]) ;
        return this.rmWeatherHistoryDao.selectMaxMinTemperature(weatherId, startId, endId);
    }
 
    public MdEt0 selectByCropWeatherDt(Long cropId, Long weatherId, String yesterday) throws Exception{
        return this.mdEt0Dao.selectByCropWeatherDt(cropId, weatherId, yesterday) ;
    }
 
    @Transactional(rollbackFor=Exception.class)
    public int saveEt0(Long cropId, Long weatherId, Date yesterday, Double maxAirTemperature, Double minAirTemperature, Double factor, Double et0){
        MdEt0 po = new MdEt0();
        po.cropId = cropId ;
        po.weatherId = weatherId ;
        po.dt = yesterday ;
        po.maxTmp = maxAirTemperature ;
        po.minTmp = minAirTemperature ;
        po.factor = factor ;
        po.et0 = et0 ;
        return this.mdEt0Dao.insert(po) ;
    }
}