zhubaomin
2025-04-11 9f3c4a33279f10ed420d604765487558ab0744f0
pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/stClient/StClientSv.java
New file
@@ -0,0 +1,236 @@
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<VoStClientAmountYear> selectStClientAmountYear(StClientQo qo, List<Integer> yearGrp) throws ParseException {
        QueryResultVo<VoStClientAmountYear> rsQrVo = new QueryResultVo<>() ;
        VoStClientAmountYear rsVo = new VoStClientAmountYear();
        rsVo.yearGrp = yearGrp ;
        rsQrVo.obj = rsVo ;
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ;
        // 获取符合条件的记录数
        Long itemTotal = stClientAmountYearDao.selectCountYearStatistics(params) ;
        if(itemTotal != null && itemTotal > 0) {
            rsQrVo.pageSize = qo.pageSize;
            rsQrVo.pageCurr = qo.pageCurr;
            rsQrVo.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.records = group ;
        }
        return rsQrVo ;
    }
    /**
     * 补全, 集合中没有就生成一个
     * @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;
        }
    }
}