pipIrr-platform/pipIrr-web/pipIrr-web-statistics/src/main/java/com/dy/pipIrrStatistics/intake/IntakeSv.java
@@ -1,22 +1,9 @@
package com.dy.pipIrrStatistics.intake;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoRm.RmOnHourReportHistoryMapper;
import com.dy.pipIrrGlobal.daoRm.RmOpenCloseValveHistoryMapper;
import com.dy.pipIrrGlobal.daoRm.RmOnHourReportLastMapper;
import com.dy.pipIrrGlobal.daoRm.RmOpenCloseValveLastMapper;
import com.dy.pipIrrGlobal.daoRm.*;
import com.dy.pipIrrGlobal.voSt.*;
import com.dy.pipIrrStatistics.intake.qo.*;
import com.dy.pipIrrGlobal.voSt.VoBatteryVolt;
import com.dy.pipIrrGlobal.voSt.VoCumulativeFlow;
import com.dy.pipIrrGlobal.voSt.VoIntake;
import com.dy.pipIrrGlobal.voSt.VoIntakeOpenCount;
import com.dy.pipIrrGlobal.voSt.VoSignalIntensity;
import com.dy.pipIrrStatistics.intake.qo.BatteryVoltQO;
import com.dy.pipIrrStatistics.intake.qo.CumulativeFlowQO;
import com.dy.pipIrrStatistics.intake.qo.CommonQO;
import com.dy.pipIrrStatistics.intake.qo.IntakeValueQO;
import com.dy.pipIrrStatistics.intake.qo.SignalIntensityQO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,7 +11,10 @@
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -45,9 +35,13 @@
    private RmOpenCloseValveHistoryMapper rmOpenCloseValveHistoryMapper;
    @Autowired
    private RmOnHourReportLastMapper rmOnHourReportLastMapper;
    @Autowired
    private RmOpenCloseValveLastMapper rmOpenCloseValveLastMapper;
    @Autowired
    private RmIntakeAmountDayMapper rmIntakeAmountDayMapper;
    @Autowired
    private RmLossDayLastMapper rmLossDayLastMapper;
    @Value("${rtu.batteryVolt}")
    private Double batteryVolt;
@@ -70,13 +64,16 @@
         */
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null) {
            timeStart = timeStart + " 00:00:00";
        }else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        if(timeStop != null) {
            timeStop = timeStop + " 23:59:59";
            if(timeStart != null) {
                timeStart = timeStart + " 00:00:00";
            }else {
                timeStart = LocalDate.now() + " 00:00:00";
            }
        }else {
            timeStart = null;
        }
        qo.setTimeStart(timeStart);
        qo.setTimeStop(timeStop);
@@ -197,13 +194,14 @@
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null) {
        if(timeStart != null && timeStart != "") {
            timeStart = timeStart + " 00:00:00";
        }else {
        } else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        qo.setTimeStart(timeStart);
        if(timeStop != null) {
        if(timeStop != null && timeStop != "") {
            timeStop = timeStop + " 23:59:59";
        }else {
            timeStop = LocalDate.now() + " 23:59:59";
@@ -231,17 +229,18 @@
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoIntakeOpenCount>> getOpenValveGtIntakes(IntakeValueQO qo) {
    public QueryResultVo<List<VoIntakeOpenCount>> getOpenValveGtIntakes(IntakeCountValueQO qo) {
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null) {
        if(timeStart != null && timeStart != "") {
            timeStart = timeStart + " 00:00:00";
        }else {
        } else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        qo.setTimeStart(timeStart);
        if(timeStop != null) {
        if(timeStop != null && timeStop != "") {
            timeStop = timeStop + " 23:59:59";
        }else {
            timeStop = LocalDate.now() + " 23:59:59";
@@ -269,17 +268,18 @@
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoIntakeOpenCount>> getOpenValveLtIntakes(IntakeValueQO qo) {
    public QueryResultVo<List<VoIntakeOpenCount>> getOpenValveLtIntakes(IntakeCountValueQO qo) {
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null) {
        if(timeStart != null && timeStart != "") {
            timeStart = timeStart + " 00:00:00";
        }else {
        } else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        qo.setTimeStart(timeStart);
        if(timeStop != null) {
        if(timeStop != null && timeStop != "") {
            timeStop = timeStop + " 23:59:59";
        }else {
            timeStop = LocalDate.now() + " 23:59:59";
@@ -309,39 +309,47 @@
     */
    public VoCountOfOpenType getCountByOpenType(OpenTypeQO qo) {
        /**
         * 补齐起止时间,如果开始时间为空,则默认为当前日期
         * 补齐起止时间,如果开始时间为空,则默认为当前日期,如果结束时间为空,则查询时间为空
         */
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null) {
            timeStart = timeStart + " 00:00:00";
        }else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        if(timeStop != null) {
            timeStop = timeStop + " 23:59:59";
            if(timeStart != null) {
                timeStart = timeStart + " 00:00:00";
            }else {
                timeStart = LocalDate.now() + " 00:00:00";
            }
        }else {
            timeStart = null;
        }
        qo.setTimeStart(timeStart);
        qo.setTimeStop(timeStop);
        Integer openType = qo.getOpenType();
        String openTypeName = "";
        switch (openType) {
            case 1:
                openTypeName = "刷卡开阀";
                break;
            case 3:
                openTypeName = "中心站开阀";
                break;
            case 8:
                openTypeName = "用户远程开阀";
                break;
            case 11:
                openTypeName = "开关阀卡开阀";
                break;
            case 13:
                openTypeName = "开关阀卡开阀";
                break;
        if (openType == null){
            openTypeName = "未知";
        }else {
            switch (openType) {
                case 1:
                    openTypeName = "刷卡开阀";
                    break;
                case 3:
                    openTypeName = "中心站开阀";
                    break;
                case 8:
                    openTypeName = "用户远程开阀";
                    break;
                case 11:
                    openTypeName = "开关阀卡开阀";
                    break;
                case 13:
                    openTypeName = "开关阀卡开阀";
                    break;
                default:
                    openTypeName = "未知";
            }
        }
        // 生成查询参数
@@ -422,4 +430,338 @@
        return vo;
    }
    /**
     * 指定时间段内累积流量超过指定值的取水口
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoIntakeAccumulateAmount>> getTotalFlowGtValueIntakes(IntakeAmountValueQO qo) {
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null && timeStart != "") {
            timeStart = timeStart + " 00:00:00";
        } else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        qo.setTimeStart(timeStart);
        if(timeStop != null && timeStop != "") {
            timeStop = timeStop + " 23:59:59";
        }else {
            timeStop = LocalDate.now() + " 23:59:59";
        }
        qo.setTimeStop(timeStop);
        if (qo.getValue() == null){
            qo.setValue(0.0);
        }
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo);
        Long itemTotal = rmOnHourReportHistoryMapper.getTotalFlowGtValueIntakesCount(params);
        QueryResultVo<List<VoIntakeAccumulateAmount>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = rmOnHourReportHistoryMapper.getTotalFlowGtValueIntakes(params);
        return rsVo ;
    }
    /**
     * 指定时间段内用水量超过指定值的取水口
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoIntakeAccumulateAmount>> getUseWaterGtValueIntakes(IntakeAmountValueQO qo) {
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null && timeStart != "") {
            timeStart = timeStart + " 00:00:00";
        } else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        qo.setTimeStart(timeStart);
        if(timeStop != null && timeStop != "") {
            timeStop = timeStop + " 23:59:59";
        }else {
            timeStop = LocalDate.now() + " 23:59:59";
        }
        qo.setTimeStop(timeStop);
        if (qo.getValue() == null){
            qo.setValue(0.0);
        }
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo);
        Long itemTotal = rmOpenCloseValveHistoryMapper.getUseWaterGtValueIntakesCount(params);
        QueryResultVo<List<VoIntakeAccumulateAmount>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = rmOpenCloseValveHistoryMapper.getUseWaterGtValueIntakes(params);
        return rsVo ;
    }
    /**
     * 指定时间段内消费金额超过指定值的取水口
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoIntakeAccumulateAmount>> getExpenseGtValueIntakes(IntakeAmountValueQO qo) {
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null && timeStart != "") {
            timeStart = timeStart + " 00:00:00";
        } else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        qo.setTimeStart(timeStart);
        if(timeStop != null && timeStop != "") {
            timeStop = timeStop + " 23:59:59";
        }else {
            timeStop = LocalDate.now() + " 23:59:59";
        }
        qo.setTimeStop(timeStop);
        if (qo.getValue() == null){
            qo.setValue(0.0);
        }
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo);
        Long itemTotal = rmOpenCloseValveHistoryMapper.getExpenseGtValueIntakesCount(params);
        QueryResultVo<List<VoIntakeAccumulateAmount>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = rmOpenCloseValveHistoryMapper.getExpenseGtValueIntakes(params);
        return rsVo ;
    }
    /**
     * 指定时间段内用水时长超过指定值的取水口
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoIntakeOpenCount>> getUseWaterDurationGtValueIntakes(IntakeCountValueQO qo) {
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null && timeStart != "") {
            timeStart = timeStart + " 00:00:00";
        } else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        qo.setTimeStart(timeStart);
        if(timeStop != null && timeStop != "") {
            timeStop = timeStop + " 23:59:59";
        }else {
            timeStop = LocalDate.now() + " 23:59:59";
        }
        qo.setTimeStop(timeStop);
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo);
        Long itemTotal = rmOpenCloseValveHistoryMapper.getUseWaterDurationGtValueIntakesCount(params);
        QueryResultVo<List<VoIntakeOpenCount>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = rmOpenCloseValveHistoryMapper.getUseWaterDurationGtValueIntakes(params);
        return rsVo ;
    }
    /**
     * 指定时间段 有开阀 无关阀的取水口
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoIntake>> getHaveOpenNoCloseIntakes(CommonQO qo) {
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null && timeStart != "") {
            timeStart = timeStart + " 00:00:00";
        } else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        qo.setTimeStart(timeStart);
        if(timeStop != null && timeStop != "") {
            timeStop = timeStop + " 23:59:59";
        }else {
            timeStop = LocalDate.now() + " 23:59:59";
        }
        qo.setTimeStop(timeStop);
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo);
        Long itemTotal = rmOpenCloseValveHistoryMapper.getHaveOpenNoCloseIntakesCount(params);
        QueryResultVo<List<VoIntake>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = rmOpenCloseValveHistoryMapper.getHaveOpenNoCloseIntakes(params);
        return rsVo ;
    }
    /**
     * 指定时间段 无开阀 有关阀的取水口
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoIntake>> getNoOpenHaveCloseIntakes(CommonQO qo) {
        String timeStart = qo.getTimeStart();
        String timeStop = qo.getTimeStop();
        if(timeStart != null && timeStart != "") {
            timeStart = timeStart + " 00:00:00";
        } else {
            timeStart = LocalDate.now() + " 00:00:00";
        }
        qo.setTimeStart(timeStart);
        if(timeStop != null && timeStop != "") {
            timeStop = timeStop + " 23:59:59";
        }else {
            timeStop = LocalDate.now() + " 23:59:59";
        }
        qo.setTimeStop(timeStop);
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo);
        Long itemTotal = rmOpenCloseValveHistoryMapper.getNoOpenHaveCloseIntakesCount(params);
        QueryResultVo<List<VoIntake>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = rmOpenCloseValveHistoryMapper.getNoOpenHaveCloseIntakes(params);
        return rsVo ;
    }
    /**
     * 统计指定月份各天用水量
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoDayIntakeAmount>> getDayIntakeAmount(IntakeAmountQO qo) throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String yearMonth = qo.getYearMonth();
        yearMonth = yearMonth + "-01";
        yearMonth = dateFormat.format(dateFormat.parse(yearMonth));
        Integer year = Integer.parseInt(yearMonth.substring(0,4));
        Integer month = Integer.parseInt(yearMonth.substring(5,7));
        qo.setYear(year);
        qo.setMonth(month);
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ;
        // 获取符合条件的记录数
        Long itemTotal = Optional.ofNullable(rmIntakeAmountDayMapper.getDayIntakeAmountCount(params)).orElse(0L);
        QueryResultVo<List<VoDayIntakeAmount>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = rmIntakeAmountDayMapper.getDayIntakeAmount(params);
        return rsVo ;
    }
    /**
     * 统计指定年份各月用水量
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoMonthAmount>> getMonthIntakeAmount(IntakeAmountQO qo) {
        Calendar calendar = Calendar.getInstance();
        Integer year = Optional.ofNullable(qo.getYear()).orElse(calendar.get(Calendar.YEAR));
        qo.setYear(year);
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ;
        // 获取符合条件的记录数
        Long itemTotal = Optional.ofNullable(rmIntakeAmountDayMapper.getMonthIntakeAmountCount(params)).orElse(0L);
        QueryResultVo<List<VoMonthAmount>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = rmIntakeAmountDayMapper.getMonthIntakeAmount(params);
        return rsVo ;
    }
    /**
     * 统计指定月份各天漏损量
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoDayLoss>> getDayLossAmount(IntakeAmountQO qo) throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String yearMonth = qo.getYearMonth();
        yearMonth = yearMonth + "-01";
        yearMonth = dateFormat.format(dateFormat.parse(yearMonth));
        Integer year = Integer.parseInt(yearMonth.substring(0,4));
        Integer month = Integer.parseInt(yearMonth.substring(5,7));
        qo.setYear(year);
        qo.setMonth(month);
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ;
        // 获取符合条件的记录数
        Long itemTotal = Optional.ofNullable(rmLossDayLastMapper.getDayLossAmountCount(params)).orElse(0L);
        QueryResultVo<List<VoDayLoss>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = rmLossDayLastMapper.getDayLossAmount(params);
        return rsVo ;
    }
    /**
     * 统计指定年份各月漏损量
     * @param qo
     * @return
     */
    public QueryResultVo<List<VoMonthAmount>> getMonthLossAmount(IntakeAmountQO qo) {
        Calendar calendar = Calendar.getInstance();
        Integer year = Optional.ofNullable(qo.getYear()).orElse(calendar.get(Calendar.YEAR));
        qo.setYear(year);
        // 生成查询参数
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo) ;
        // 获取符合条件的记录数
        Long itemTotal = Optional.ofNullable(rmLossDayLastMapper.getMonthLossAmountCount(params)).orElse(0L);
        QueryResultVo<List<VoMonthAmount>> rsVo = new QueryResultVo<>() ;
        rsVo.pageSize = qo.pageSize ;
        rsVo.pageCurr = qo.pageCurr ;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = rmLossDayLastMapper.getMonthLossAmount(params);
        return rsVo ;
    }
}