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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.dy.pipIrrTemp.statistics;
 
import com.dy.common.util.DateTime;
import com.dy.common.util.IDLongGenerator;
import com.dy.pipIrrGlobal.daoSt.StClientAmountDayMapper;
import com.dy.pipIrrGlobal.daoSt.StClientAmountMonthMapper;
import com.dy.pipIrrGlobal.pojoSt.StClientAmountMonth;
import com.dy.pipIrrGlobal.pojoSt.StConsumeClientMonth;
import com.dy.pipIrrGlobal.pojoSt.StConsumeClientYear;
import com.dy.pipIrrGlobal.voSt.VoClientAmountStatistics;
import com.dy.pipIrrGlobal.voSt.VoClientConsumeStatistics;
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.List;
 
/**
 * @Author: liurunyu
 * @Date: 2024/12/30 09:52
 * @Description
 */
 
@Slf4j
@Service
public class StClientAmountMonthSv {
 
    protected StClientAmountDayMapper stClientAmountDayDao;
 
    protected StClientAmountMonthMapper stClientAmountMonthDao;
 
    @Autowired
    private void setDao(StClientAmountDayMapper dao) {
        this.stClientAmountDayDao = dao;
    }
 
    @Autowired
    private void setDao(StClientAmountMonthMapper dao) {
        this.stClientAmountMonthDao = dao;
    }
 
    /**
     * 删除所有
     * @throws Exception
     */
    public void deleteAllStClientAmountMonth() throws Exception {
        stClientAmountMonthDao.deleteAll() ;
    }
 
    /**
     * 转存农户月取水量
     *
     * @throws Exception
     */
    public void statisticsClientAmountMonth() throws Exception {
        //统计到昨天,今天的统计明日零晨定时任务统计
        Long curYm = Long.parseLong(DateTime.yyyy_MM().replaceAll("-", ""));
        Long atMonth ;
        for(int[] ym : StClientAmountConstant.yearMonthGrp) {
            atMonth = Long.parseLong(ym[0] + "" + (ym[1] < 10?("0" + ym[1]):ym[1]) ) ;
            if(atMonth <= curYm) {
                this.doSome(ym[0], ym[1]);
            }
        }
    }
 
 
    @Transactional
    protected void doSome(Integer statisticsYear, Integer statisticsMonth){
        List<VoClientAmountStatistics> list = stClientAmountDayDao.statisticsByClient(statisticsYear, statisticsMonth) ;
        if(list != null && list.size() > 0){
            List<StClientAmountMonth> listOfMonth = stClientAmountMonthDao.selectByYear(statisticsYear) ;
            for(VoClientAmountStatistics vo : list){
                StClientAmountMonth po = this.getDataOfClient(listOfMonth, vo.clientId) ;
                if(po == null){
                    po = new StClientAmountMonth() ;
                    po.clientId = vo.clientId ;
                    po.year = statisticsYear ;
                }
                this.setValue(statisticsMonth, vo, po);
                if(po.id == null) {
                    stClientAmountMonthDao.insert(po);
                }else{
                    stClientAmountMonthDao.updateByPrimaryKeySelective(po) ;
                }
            }
        }
    }
 
 
    private StClientAmountMonth getDataOfClient(List<StClientAmountMonth> list, Long clientId){
        if(list != null && list.size() > 0){
            for(StClientAmountMonth vo : list){
                if(vo.clientId.longValue() == clientId.longValue()){
                    //程序逻辑控制上,集合中只有一个对象
                    return vo ;
                }
            }
        }
        return null ;
    }
 
    private void setValue(Integer statisticsMonth, VoClientAmountStatistics vo, StClientAmountMonth po){
        switch (statisticsMonth) {
            case 1:
                po.amount1 = vo.amount;
                po.money1 = vo.money;
                po.times1 = vo.times;
                break;
            case 2:
                po.amount2 = vo.amount;
                po.money2 = vo.money;
                po.times2 = vo.times;
                break;
            case 3:
                po.amount3 = vo.amount;
                po.money3 = vo.money;
                po.times3 = vo.times;
                break;
            case 4:
                po.amount4 = vo.amount;
                po.money4 = vo.money;
                po.times4 = vo.times;
                break;
            case 5:
                po.amount5 = vo.amount;
                po.money5 = vo.money;
                po.times5 = vo.times;
                break;
            case 6:
                po.amount6 = vo.amount;
                po.money6 = vo.money;
                po.times6 = vo.times;
                break;
            case 7:
                po.amount7 = vo.amount;
                po.money7 = vo.money;
                po.times7 = vo.times;
                break;
            case 8:
                po.amount8 = vo.amount;
                po.money8 = vo.money;
                po.times8 = vo.times;
                break;
            case 9:
                po.amount9 = vo.amount;
                po.money9 = vo.money;
                po.times9 = vo.times;
                break;
            case 10:
                po.amount10 = vo.amount;
                po.money10 = vo.money;
                po.times10 = vo.times;
                break;
            case 11:
                po.amount11 = vo.amount;
                po.money11 = vo.money;
                po.times11 = vo.times;
                break;
            case 12:
                po.amount12 = vo.amount;
                po.money12 = vo.money;
                po.times12 = vo.times;
                break;
        }
    }
 
}