liurunyu
2025-01-06 24f91c6e8b6a5e5be813e0b740dec3d381abe254
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package com.dy.pipIrrStatistics.stClient;
 
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoSt.StClientAmountDayMapper ;
import com.dy.pipIrrGlobal.daoSt.StClientAmountMonthMapper ;
import com.dy.pipIrrGlobal.daoSt.StClientAmountYearMapper ;
import com.dy.pipIrrGlobal.voSt.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * @Author: liurunyu
 * @Date: 2024/12/30 15:22
 * @Description
 */
 
@Slf4j
@Service
public class StClientSv {
 
    private StClientAmountDayMapper stClientAmountDayDao ;
    private StClientAmountMonthMapper stClientAmountMonthDao ;
    private StClientAmountYearMapper stClientAmountYearDao ;
    @Autowired
    private void setDao(StClientAmountDayMapper dao){
        this.stClientAmountDayDao = dao ;
    }
    @Autowired
    private void setDao(StClientAmountMonthMapper dao){
        this.stClientAmountMonthDao = dao ;
    }
    @Autowired
    private void setDao(StClientAmountYearMapper dao){
        this.stClientAmountYearDao = dao ;
    }
 
 
    /**
     * 查询农户用水日统计
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoStClientAmountDay>> selectStClientAmountDay(StClientQo qo) {
        QueryResultVo<List<VoStClientAmountDay>> rsVo = new QueryResultVo<>() ;
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ;
        // 获取符合条件的记录数
        Long itemTotal = stClientAmountDayDao.selectCountDayStatistics(params) ;
 
        if(itemTotal != null && itemTotal > 0) {
            rsVo.pageSize = qo.pageSize;
            rsVo.pageCurr = qo.pageCurr;
            rsVo.calculateAndSet(itemTotal, params);
 
            rsVo.obj = stClientAmountDayDao.selectDayStatistics(params);
        }
        return rsVo ;
    }
 
 
    /**
     * 查询农户用水月统计
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoStClientAmountMonth>> selectStClientAmountMonth(StClientQo qo)  {
        QueryResultVo<List<VoStClientAmountMonth>> rsVo = new QueryResultVo<>() ;
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ;
        // 获取符合条件的记录数
        Long itemTotal = stClientAmountMonthDao.selectCountMonthStatistics(params) ;
 
        if(itemTotal != null && itemTotal > 0) {
            rsVo.pageSize = qo.pageSize;
            rsVo.pageCurr = qo.pageCurr;
            rsVo.calculateAndSet(itemTotal, params);
 
            rsVo.obj = stClientAmountMonthDao.selectMonthStatistics(params);
        }
        return rsVo ;
    }
 
 
    /**
     * 查询农户用水年统计
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoStClientAmountYearRecords>> selectStClientAmountYear(StClientQo qo, List<Integer> yearGrp) throws ParseException {
        QueryResultVo<List<VoStClientAmountYearRecords>> rsVo = new QueryResultVo<>() ;
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ;
        params.put("yearGrp", yearGrp);
        // 获取符合条件的记录数
        Long itemTotal = stClientAmountYearDao.selectCountYearStatistics(params) ;
 
        if(itemTotal != null && itemTotal > 0) {
            rsVo.pageSize = qo.pageSize;
            rsVo.pageCurr = qo.pageCurr;
            rsVo.calculateAndSet(itemTotal, params);
 
            List<VoStClientAmountYearRecords> group = new ArrayList<>();
            int count = 1 ;
            for(int year: yearGrp){
                params.put("year", year);
                List<VoStClientAmountYearRecord> list = stClientAmountYearDao.selectYearStatistics(params);
                if(group.isEmpty()){
                    this.completion(group, list);
                }
                this.merge(count, group, list) ;
                count += 1 ;
            }
            rsVo.obj = group ;
        }
        return rsVo ;
    }
 
    /**
     * 补全, 集合中没有就生成一个
     * @param group
     * @param list
     */
    private void completion(List<VoStClientAmountYearRecords> group, List<VoStClientAmountYearRecord> list){
        boolean found ;
        for (VoStClientAmountYearRecord voInList : list) {
            found = false ;
            for(VoStClientAmountYearRecords voInGrp : group) {
                if(voInList.clientId.longValue() == voInGrp.clientId.longValue()) {
                    found = true ;
                }
            }
            if(!found) {
                VoStClientAmountYearRecords vo4s = new VoStClientAmountYearRecords();
                vo4s.clientId = voInList.clientId;
                vo4s.clientNum = voInList.clientNum;
                vo4s.clientName = voInList.clientName;
                vo4s.clientAddress = voInList.clientAddress;
                group.add(vo4s) ;
            }
        }
    }
 
    /**
     * 合并, 集合中有就合并
     * @param count
     * @param group
     * @param list
     */
    private void merge(int count, List<VoStClientAmountYearRecords> group, List<VoStClientAmountYearRecord> list){
        for (VoStClientAmountYearRecord voInList : list) {
            VoStClientAmountYearRecords voInGrp_ = null ;
            for(VoStClientAmountYearRecords voInGrp : group) {
                if(voInList.clientId.longValue() == voInGrp.clientId.longValue()) {
                    voInGrp_ = voInGrp ;
                    break ;
                }
            }
            if(voInGrp_ != null){
                this.merge(count, voInGrp_, voInList);
            }
        }
    }
 
    /**
     * 合并值
     * @param count
     * @param vo4s
     * @param vo
     */
    private void merge(int count, VoStClientAmountYearRecords vo4s, VoStClientAmountYearRecord vo){
        switch (count){
            case 1:
                vo4s.amount1 = vo.amount;
                vo4s.money1 = vo.money;
                vo4s.times1 = vo.times;
                break;
            case 2:
                vo4s.amount2 = vo.amount;
                vo4s.money2 = vo.money;
                vo4s.times2 = vo.times;
                break;
            case 3:
                vo4s.amount3 = vo.amount;
                vo4s.money3 = vo.money;
                vo4s.times3 = vo.times;
                break;
            case 4:
                vo4s.amount4 = vo.amount;
                vo4s.money4 = vo.money;
                vo4s.times4 = vo.times;
                break;
            case 5:
                vo4s.amount5 = vo.amount;
                vo4s.money5 = vo.money;
                vo4s.times5 = vo.times;
                break;
            case 6:
                vo4s.amount6 = vo.amount;
                vo4s.money6 = vo.money;
                vo4s.times6 = vo.times;
                break;
            case 7:
                vo4s.amount7 = vo.amount;
                vo4s.money7 = vo.money;
                vo4s.times7 = vo.times;
                break;
            case 8:
                vo4s.amount8 = vo.amount;
                vo4s.money8 = vo.money;
                vo4s.times8 = vo.times;
                break;
            case 9:
                vo4s.amount9 = vo.amount;
                vo4s.money9 = vo.money;
                vo4s.times9 = vo.times;
                break;
            case 10:
                vo4s.amount10 = vo.amount;
                vo4s.money10 = vo.money;
                vo4s.times10 = vo.times;
                break;
        }
    }
}