liurunyu
2024-12-27 30923b57df60538534baa12e15f2da6f32f280b3
pipIrr-platform/pipIrr-web/pipIrr-web-temp/src/main/java/com/dy/pipIrrTemp/changeSome/ChSomeIntakeAmountSv.java
@@ -3,12 +3,15 @@
import com.dy.common.util.DateTime;
import com.dy.pipIrrGlobal.daoTmp.ChangeMapper;
import com.dy.pipIrrGlobal.pojoRm.RmIntakeAmountDay;
import com.dy.pipIrrGlobal.pojoSt.StIntakeAmountMonth;
import com.dy.pipIrrGlobal.pojoSt.StIntakeAmountYear;
import com.dy.pipIrrGlobal.voSt.VoIntake;
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.Date;
import java.util.List;
/**
@@ -31,6 +34,17 @@
        this.dao = dao;
    }
    ////////////////////////////////////////
    //
    // 有关日统计
    //
    ///////////////////////////////////////
    /**
     * 调整取水口日取水量统计
     * @throws Exception
     */
    public void chIntakeAmountDay() throws Exception{
        RmIntakeAmountDay lastAd = null ;
        List<VoIntake> list = dao.selectAllPrIntakes() ;
@@ -105,7 +119,7 @@
                                    );
                                    ad.amount = 0.0 ;
                                }
                                this.doUpdateOneIntakeAmountDay(ad.id, 0.0);
                                this.doUpdateOneIntakeAmountDay(ad.id,  ad.amount);
                            }
                        }
                        lastAd = ad ;
@@ -116,7 +130,110 @@
    }
    @Transactional
    int doUpdateOneIntakeAmountDay(Long id, Double amount){
    protected int doUpdateOneIntakeAmountDay(Long id, Double amount){
        return dao.updateOneIntakeAmountDay(id, amount);
    }
    ////////////////////////////////////////
    //
    // 有关月统计
    //
    ///////////////////////////////////////
    private static final int DealStartYear = 2024 ;
    private static final int DealStartMonth = 8 ;
    /**
     * 删除所有取水口月取水量统计
     * @throws Exception
     */
    @Transactional
    public void deleteAllIntakeAmountMonth(){
        dao.deleteAllIntakeAmountMonth();
    }
    /**
     * 统计取水口月取水量
     * @throws Exception
     */
    public void statisticsIntakeAmountMonth() throws Exception{
        int nowYear = Integer.parseInt(DateTime.yyyy()) ;
        int nowMonth = Integer.parseInt(DateTime.mm()) ;
        Date startDt ;
        Date endDt ;
        List<StIntakeAmountMonth> list ;
        for(int year = DealStartYear; year <= nowYear; year ++){
            list = null ;
            if(year < nowYear){
                for(int month = 1 ; month <= 12 ; month ++){
                    startDt = DateTime.dateFrom_yyyy_MM_dd(year + "-" + month + "-01") ;
                    endDt = DateTime.dateFrom_yyyy_MM_dd(year + "-" + month + "-" + DateTime.endDayOfMonth(year, month)) ;
                    list = dao.statisticAllIntakeAmountMonthFromAmountDay(startDt, endDt) ;
                    this.doStatisticsIntakeAmountMonth(year, month, list) ;
                }
            }else{
                for(int month = 1 ; month <= nowMonth ; month ++){
                    startDt = DateTime.dateFrom_yyyy_MM_dd(year + "-" + month + "-01") ;
                    endDt = DateTime.dateFrom_yyyy_MM_dd(year + "-" + month + "-" + DateTime.endDayOfMonth(year, month)) ;
                    list = dao.statisticAllIntakeAmountMonthFromAmountDay(startDt, endDt) ;
                    this.doStatisticsIntakeAmountMonth(year, month, list) ;
                }
            }
        }
    }
    @Transactional
    protected void doStatisticsIntakeAmountMonth(int year, int month, List<StIntakeAmountMonth> list) throws Exception{
        if(list != null && list.size() > 0){
            for(StIntakeAmountMonth po : list){
                po.year = year ;
                po.month = month ;
                dao.saveOneIntakeAmountMonth(po) ;
            }
        }
    }
    ////////////////////////////////////////
    //
    // 有关年统计
    //
    ///////////////////////////////////////
    /**
     * 删除所有取水口年取水量统计
     * @throws Exception
     */
    @Transactional
    public void deleteAllIntakeAmountYear(){
        dao.deleteAllIntakeAmountYear();
    }
    /**
     * 统计取水口月取水量
     * @throws Exception
     */
    public void statisticsIntakeAmountYear() throws Exception{
        int nowYear = Integer.parseInt(DateTime.yyyy()) ;
        Date startDt ;
        Date endDt ;
        List<StIntakeAmountYear> list ;
        for(int year = DealStartYear; year <= nowYear; year ++){
            list = null ;
            startDt = DateTime.dateFrom_yyyy_MM_dd(year + "-01-01") ;
            endDt = DateTime.dateFrom_yyyy_MM_dd(year + "-12-31") ;
            list = dao.statisticAllIntakeAmountYearFromAmountDay(startDt, endDt) ;
            this.doStatisticsIntakeAmountYear(year, list) ;
        }
    }
    @Transactional
    protected void doStatisticsIntakeAmountYear(int year, List<StIntakeAmountYear> list) throws Exception{
        if(list != null && list.size() > 0){
            for(StIntakeAmountYear po : list){
                po.year = year ;
                dao.saveOneIntakeAmountYear(po) ;
            }
        }
    }
}