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
package com.dy.pipIrrTemp.changeSome;
 
import com.dy.common.util.DateTime;
import com.dy.pipIrrGlobal.daoTmp.ChangeMapper;
import com.dy.pipIrrGlobal.pojoRm.RmIntakeAmountDay;
import com.dy.pipIrrGlobal.voSt.VoIntake;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * @Author: liurunyu
 * @Date: 2024/12/14 9:25
 * @Description
 */
 
 
@Slf4j
@Service
public class ChSomeIntakeAmountSv {
 
    private ChangeMapper dao;
 
    private static final int IntakeAmountDayFlag = 800 ;//2024-12-14统计元谋数据库实时数据,发现大于800的正确的数据不存在,而小于800的基本为正确数据
 
    @Autowired
    private void setDao(ChangeMapper dao){
        this.dao = dao;
    }
 
    public void chIntakeAmountDay() throws Exception{
        RmIntakeAmountDay lastAd = null ;
        List<VoIntake> list = dao.selectAllPrIntakes() ;
        if(list != null && list.size() > 0){
            for(VoIntake vo : list){
                lastAd = null ;
                List<RmIntakeAmountDay> adList = dao.selectOneIntakeAllAmountDay(vo.getIntakeId()) ;
                if(adList != null && adList.size() > 0){
                    //adList中数据以id升序排列
                    for(RmIntakeAmountDay ad : adList){
                        if(lastAd == null){
                            lastAd = ad ;
                            if(lastAd.amount != null && lastAd.amount > IntakeAmountDayFlag){
                                dao.updateOneIntakeAmountDay(lastAd.id, 0.0);
                            }
                        }else{
                            if(ad.amount != null && ad.amount > IntakeAmountDayFlag){
                                if(ad.totalAmountLast != null && lastAd.totalAmountLast != null){
                                    ad.amount = ad.totalAmountLast - lastAd.totalAmountLast;
                                    if(ad.amount < 0){//存这种情况
                                        ad.amount = 0.0 ;
                                    }
                                    if(ad.amount > IntakeAmountDayFlag){
                                        log.info("出现调整后的日取水量仍大于"
                                                + IntakeAmountDayFlag
                                                + "的情况,数据id=" + ad.id
                                                + ",取水口id=" + ad.intakeId
                                                + ",日期=" + ad.dt
                                                + ad.amount
                                        );
                                        if(ad.dt != null && lastAd.dt != null){
                                            if(DateTime.daysBetweenyyyy_MM_dd(ad.dt, lastAd.dt) == 1){
                                                //只相差一天
                                                ad.amount = 0.0 ;
                                                log.info("出现相差一天但日取水量大于"
                                                        + IntakeAmountDayFlag
                                                        + "的情况,数据id=" + ad.id
                                                        + ",取水口id=" + ad.intakeId
                                                        + ",日期=" + ad.dt
                                                        + ",水量=" + ad.amount
                                                );
                                            }else{
                                                //已经修改后的数值仍然大于IntakeAmountDayFlag,说明是大日未上报数据而积累下来,可以大于IntakeAmountDayFlag
                                                //ad.amount = ad.amount ;
                                                log.info("出现相差多天日取水量大于"
                                                        + IntakeAmountDayFlag
                                                        + "的情况,数据id=" + ad.id
                                                        + ",取水口id=" + ad.intakeId
                                                        + ",日期=" + ad.dt
                                                        + ",水量=" + ad.amount
                                                );
                                            }
                                        }
                                    }
                                }else{
                                    ad.amount = 0.0 ;
                                }
                                dao.updateOneIntakeAmountDay(ad.id, 0.0);
                            }
                        }
                    }
                }
            }
        }
    }
}