liurunyu
2024-12-27 27bd4b5c03bbc8b665ffecb87d6c2cae3262e503
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
package com.dy.pipIrrStatistics.statistics;
 
import com.dy.pipIrrGlobal.daoRm.RmIntakeAmountDayMapper;
import com.dy.pipIrrGlobal.daoSt.StIntakeAmountMonthMapper;
import com.dy.pipIrrGlobal.daoSt.StIntakeAmountYearMapper;
import com.dy.pipIrrGlobal.pojoSt.StIntakeAmountMonth;
import com.dy.pipIrrGlobal.pojoSt.StIntakeAmountYear;
import com.dy.pipIrrGlobal.voSt.VoIntakeAmountStatistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * @Author: liurunyu
 * @Date: 2024/7/24 16:28
 * @Description
 */
@Component
public class StIntakeSv {
 
    @Autowired
    protected RmIntakeAmountDayMapper rmIntakeAmountDayDao;
 
    @Autowired
    protected StIntakeAmountMonthMapper stIntakeAmountMonthDao ;
 
    @Autowired
    protected StIntakeAmountYearMapper stIntakeAmountYearDao ;
 
    /**
     * 月统计---取水口用水量
     */
    @Transactional
    protected void statisticsMonth(Integer statisticsYear, Integer statisticsMonth, Long statisticsStartId, Long statisticsEndId){
        List<VoIntakeAmountStatistics> list = rmIntakeAmountDayDao.statisticsByIntake(statisticsStartId, statisticsEndId) ;
        if(list != null && list.size() > 0){
            for(VoIntakeAmountStatistics vo : list){
                List<StIntakeAmountMonth> listOfMonth = this.stIntakeAmountMonthDao.selectByIntakeIdAndYearAndMonth(vo.intakeId, statisticsYear, statisticsMonth) ;
                StIntakeAmountMonth po = null ;
                if(listOfMonth != null && listOfMonth.size() > 0) {
                    //程序逻辑控制上,集合中只有一个对象
                    po = listOfMonth.get(0);
                }
                if(po == null){
                    po = new StIntakeAmountMonth() ;
                }
                po.intakeId = vo.intakeId ;
                po.year = statisticsYear ;
                po.month = statisticsMonth ;
                po.amount = vo.amount;
                if(po.id == null) {
                    stIntakeAmountMonthDao.insert(po);
                }else{
                    stIntakeAmountMonthDao.updateByPrimaryKey(po) ;
                }
            }
        }
    }
 
    /**
     * 年统计---取水口用水量
     */
    @Transactional
    protected void statisticsYear(Integer statisticsYear){
        List<VoIntakeAmountStatistics> list = stIntakeAmountMonthDao.statisticsByIntake(statisticsYear) ;
        if(list != null && list.size() > 0){
            for(VoIntakeAmountStatistics vo : list){
                List<StIntakeAmountYear> listOfYear = stIntakeAmountYearDao.selectByIntakeIdAndYear(vo.intakeId, statisticsYear) ;
                StIntakeAmountYear po = null ;
                if(listOfYear != null && listOfYear.size() > 0) {
                    //程序逻辑控制上,集合中只有一个对象
                    po = listOfYear.get(0);
                }
                if(po == null){
                    po = new StIntakeAmountYear() ;
                }
                po.intakeId = vo.intakeId ;
                po.year = statisticsYear ;
                po.amount = vo.amount;
                if(po.id == null){
                    stIntakeAmountYearDao.insert(po) ;
                }else{
                    stIntakeAmountYearDao.updateByPrimaryKey(po) ;
                }
            }
        }
    }
 
}