From 24f91c6e8b6a5e5be813e0b740dec3d381abe254 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期一, 06 一月 2025 10:56:50 +0800
Subject: [PATCH] 农户用水月统计、年统计查询实现

---
 pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/stClient/StClientSv.java |  175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 173 insertions(+), 2 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/stClient/StClientSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/stClient/StClientSv.java
index 7cd7cfe..d1c9168 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/stClient/StClientSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/stClient/StClientSv.java
@@ -4,13 +4,14 @@
 import com.dy.pipIrrGlobal.daoSt.StClientAmountDayMapper ;
 import com.dy.pipIrrGlobal.daoSt.StClientAmountMonthMapper ;
 import com.dy.pipIrrGlobal.daoSt.StClientAmountYearMapper ;
-import com.dy.pipIrrGlobal.voSt.VoStClientAmountDay;
+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;
 
@@ -41,7 +42,12 @@
     }
 
 
-    public QueryResultVo<List<VoStClientAmountDay>> selectStClientAmountDay(StClientQo qo) throws ParseException {
+    /**
+     * 鏌ヨ鍐滄埛鐢ㄦ按鏃ョ粺璁�
+     * @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) ;
@@ -57,4 +63,169 @@
         }
         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;
+        }
+    }
 }

--
Gitblit v1.8.0