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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.dy.pipIrrTemp.statistics;
 
import com.dy.common.util.DateTime;
import com.dy.pipIrrGlobal.daoSt.StClientAmountDayMapper;
import com.dy.pipIrrGlobal.daoSt.StClientAmountMonthMapper;
import com.dy.pipIrrGlobal.daoSt.StClientAmountYearMapper;
import com.dy.pipIrrGlobal.pojoSt.StClientAmountMonth;
import com.dy.pipIrrGlobal.pojoSt.StClientAmountYear;
import com.dy.pipIrrGlobal.voSt.VoClientAmountStatistics;
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.List;
 
/**
 * @Author: liurunyu
 * @Date: 2024/12/30 09:52
 * @Description
 */
 
@Slf4j
@Service
public class StClientAmountYearSv {
 
    protected StClientAmountDayMapper stClientAmountDayDao;
 
    protected StClientAmountMonthMapper stClientAmountMonthDao;
 
    protected 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;
    }
 
    /**
     * 删除所有
     * @throws Exception
     */
    public void deleteAllStClientAmountYear() throws Exception {
        stClientAmountYearDao.deleteAll() ;
    }
 
    /**
     * 转存农户年取水量
     *
     * @throws Exception
     */
    public void statisticsClientAmountYear() throws Exception {
        //统计到昨天,今天的统计明日零晨定时任务统计
        Long curY = Long.parseLong(DateTime.yyyy().replaceAll("-", ""));
        Long atYear ;
        for(int[] ym : StClientAmountConstant.yearMonthGrp) {
            atYear = ym[0] + 0L ;
            if(atYear <= curY) {
                this.doSome(ym[0]);
            }
        }
    }
 
 
    @Transactional
    protected void doSome(Integer statisticsYear){
        List<VoClientAmountStatistics> list = stClientAmountMonthDao.statisticsByClient(statisticsYear) ;
        if(list != null && list.size() > 0){
            List<StClientAmountYear> listOfYear = stClientAmountYearDao.selectByYear(statisticsYear) ;
            for(VoClientAmountStatistics vo : list){
                StClientAmountYear po = this.getDataOfClient(listOfYear, vo.clientId) ;
                if(po == null){
                    po = new StClientAmountYear() ;
                    po.clientId = vo.clientId ;
                    po.year = statisticsYear ;
                }
                this.setValue(vo, po);
                if(po.id == null) {
                    stClientAmountYearDao.insert(po);
                }else{
                    stClientAmountYearDao.updateByPrimaryKeySelective(po) ;
                }
            }
        }
    }
 
 
    private StClientAmountYear getDataOfClient(List<StClientAmountYear> list, Long clientId){
        if(list != null && list.size() > 0){
            for(StClientAmountYear vo : list){
                if(vo.clientId.longValue() == clientId.longValue()){
                    //程序逻辑控制上,集合中只有一个对象
                    return vo ;
                }
            }
        }
        return null ;
    }
 
    private void setValue(VoClientAmountStatistics vo, StClientAmountYear po){
        po.amount = vo.amount;
        po.money = vo.money;
        po.times = vo.times;
    }
 
}