admin
2020-02-18 ddf5db7d31af51fcf697eac0cee7dd46ff73bcc1
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package com.yeshi.fanli.service.impl.money.extract;
 
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
import org.yeshi.utils.DateUtil;
 
import com.google.gson.Gson;
import com.yeshi.fanli.dao.mybatis.ExtractAuditRecordMapper;
import com.yeshi.fanli.dao.user.count.CountUserInfoDao;
import com.yeshi.fanli.dto.ChartTDO;
import com.yeshi.fanli.dto.money.ExtractOrderStatisticDTO;
import com.yeshi.fanli.entity.admin.count.CountUserInfo;
import com.yeshi.fanli.entity.admin.count.CountUserInfo.CountUserEnum;
import com.yeshi.fanli.entity.bus.user.ExtractAuditRecord;
import com.yeshi.fanli.service.inter.money.extract.ExtractAuditRecordService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
 
@Service
public class ExtractAuditRecordServiceImpl implements ExtractAuditRecordService {
 
    @Resource
    private ExtractAuditRecordMapper extractAuditRecordMapper;
    
    @Resource
    private CountUserInfoDao countUserInfoDao;
 
    @Override
    public List<ExtractAuditRecord> getList(int pageIndex, int pageSize, String key, String startTime, String endTime) {
        return extractAuditRecordMapper.getList((pageIndex - 1) * pageSize, pageSize, key, startTime, endTime);
    }
 
    @Override
    public int getCount(String key, String startTime, String endTime) {
        return extractAuditRecordMapper.getCount(key, startTime, endTime);
    }
 
    @Override
    public List<ExtractAuditRecord> getMyAuditedAllList(int pageIndex, int pageSize, String key, Integer state,
            Long adminId) {
        return extractAuditRecordMapper.getMyAuditedAllList((pageIndex - 1) * pageSize, pageSize, key, state, adminId);
    }
 
    @Override
    public int getMyAuditedAllCount(String key, Integer state, Long adminId) {
        return extractAuditRecordMapper.getMyAuditedAllCount(key, state, adminId);
    }
 
    @Override
    public List<ExtractAuditRecord> getMyAuditedTimeSlotList(int pageIndex, int pageSize, String key, Integer state,
            Long adminId, Integer days) {
        List<ExtractAuditRecord> list = extractAuditRecordMapper.getMyAuditedTimeSlotList((pageIndex - 1) * pageSize,
                pageSize, key, state, adminId, days);
        Gson gson = new Gson();
        if (list != null)
            for (ExtractAuditRecord record : list) {
                if (!StringUtil.isNullOrEmpty(record.getExtraInfoStr())) {
                    record.setExtraInfo(gson.fromJson(record.getExtraInfoStr(), ExtractOrderStatisticDTO.class));
                }
            }
        return list;
    }
 
    @Override
    public int getMyAuditedTimeSlotCount(String key, Integer state, Long adminId, Integer days) {
        return extractAuditRecordMapper.getMyAuditedTimeSlotCount(key, state, adminId, days);
    }
 
    @Override
    public int getMyAuditedCountWeek(Long adminId) {
        return extractAuditRecordMapper.getMyAuditedCountWeek(adminId);
    }
 
    @Override
    public int getMyAuditedCountMonth(Long adminId) {
        return extractAuditRecordMapper.getMyAuditedCountMonth(adminId);
    }
 
    @Override
    public int getMyAuditedCountToday(Long adminId) {
        return extractAuditRecordMapper.getMyAuditedCountToday(adminId);
    }
 
    @Override
    public List<ExtractAuditRecord> getByUidList(int pageIndex, int pageSize, Long uid) {
        List<ExtractAuditRecord> list = extractAuditRecordMapper.getByUidList((pageIndex - 1) * pageSize, pageSize, uid);
        
        Gson gson = new Gson();
        if (list != null)
            for (ExtractAuditRecord record : list) {
                if (!StringUtil.isNullOrEmpty(record.getExtraInfoStr())) {
                    record.setExtraInfo(gson.fromJson(record.getExtraInfoStr(), ExtractOrderStatisticDTO.class));
                }
            }
        return list;
    }
 
    @Override
    public int getByUidCount(Long key) {
        return extractAuditRecordMapper.getByUidCount(key);
    }
 
    @Override
    public List<ExtractAuditRecord> getListbyExtractId(Long extractId) {
        return extractAuditRecordMapper.getListbyExtractId(extractId);
    }
 
    @Override
    public List<ExtractAuditRecord> getbyExtractId(Long extractId) {
        return extractAuditRecordMapper.getbyExtractId(extractId);
    }
 
    @Override
    public List<CountUserInfo> getAuditCount(Date startTime, Date endTime, Integer state) throws Exception {
        // 重新查询统计今日以及空缺
        initAuditCount();
        
        return countUserInfoDao.query(CountUserEnum.extractAuditNumber, startTime, endTime, state);
    }
 
    // 初始化统计
    @Override
    public void initAuditCount() {
        try {
            CountUserInfo lastRecord = countUserInfoDao.getMaxDate(CountUserEnum.extractAuditNumber);
            Date lastDay = null;
            if (lastRecord != null && lastRecord.getDay() != null) {
                lastDay = lastRecord.getDay();
            }
            
            if (lastDay == null) {
                lastDay = TimeUtil.parse("2017-07-19");
            }
            
            Date today = new Date();
            int betweenDays = DateUtil.daysBetween2(lastDay, today);
            if (betweenDays > 0) {
                for (int i = 0; i <= betweenDays; i++ ) {
                    addRecordAuditCount(DateUtil.plusDay(i, lastDay));
                }
            }
            // 重新统计今日
            addRecordAuditCount(TimeUtil.getGernalTime(today.getTime()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private void addRecordAuditCount(String preDay) throws Exception{
        for (int i = 1; i < 3; i++) {
            int count = extractAuditRecordMapper.countAuditTotal(i, preDay);
            CountUserInfo record = new CountUserInfo();
            record.setState(i);
            record.setNum(count);
            record.setId(StringUtil.Md5(preDay + CountUserEnum.extractAuditNumber.name())+ "-" + i);
            record.setDay(TimeUtil.parse(preDay));
            record.setType(CountUserEnum.extractAuditNumber);
            countUserInfoDao.save(record);
        }
    }    
 
    
    @Override
    public List<CountUserInfo> getApplyMoney(Date startTime, Date endTime) throws Exception {
        // 重新查询统计今日以及空缺
        initApplyMoneyCount();
        
        return countUserInfoDao.query(CountUserEnum.extractApplyMoney, startTime, endTime);
    }
    
    // 初始化统计
    @Override
    public void initApplyMoneyCount() {
        try {
            CountUserInfo lastRecord = countUserInfoDao.getMaxDate(CountUserEnum.extractApplyMoney);
            Date lastDay = null;
            if (lastRecord != null && lastRecord.getDay() != null) {
                lastDay = lastRecord.getDay();
            }
            
            if (lastDay == null) {
                lastDay = TimeUtil.parse("2017-07-19");
            }
            
            Date today = new Date();
            int betweenDays = DateUtil.daysBetween2(lastDay, today);
            if (betweenDays > 0) {
                for (int i = 0; i <= betweenDays; i++ ) {
                    addRecordApplyMoneyCount(DateUtil.plusDay(i, lastDay));
                }
            }
            // 重新统计今日
            addRecordApplyMoneyCount(TimeUtil.getGernalTime(today.getTime()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private void addRecordApplyMoneyCount(String preDay) throws Exception{
        BigDecimal money = extractAuditRecordMapper.countApplyExtractMoney(preDay);
        if (money == null)
            money = new BigDecimal(0);
        CountUserInfo record = new CountUserInfo();
        record.setMoney(money);
        record.setId(StringUtil.Md5(preDay + CountUserEnum.extractApplyMoney.name()));
        record.setDay(TimeUtil.parse(preDay));
        record.setType(CountUserEnum.extractApplyMoney);
        countUserInfoDao.save(record);
    }    
 
    @Override
    public List<CountUserInfo> geApplyNumber(Date startTime, Date endTime) throws Exception {
        // 重新查询统计今日以及空缺
        initApplyNumberCount();
        
        return countUserInfoDao.query(CountUserEnum.extractApplyNumber, startTime, endTime);
    }
 
    
    // 初始化统计
    @Override
    public void initApplyNumberCount() {
        try {
            CountUserInfo lastRecord = countUserInfoDao.getMaxDate(CountUserEnum.extractApplyNumber);
            Date lastDay = null;
            if (lastRecord != null && lastRecord.getDay() != null) {
                lastDay = lastRecord.getDay();
            }
            
            if (lastDay == null) {
                lastDay = TimeUtil.parse("2017-07-19");
            }
            
            Date today = new Date();
            int betweenDays = DateUtil.daysBetween2(lastDay, today);
            if (betweenDays > 0) {
                for (int i = 0; i <= betweenDays; i++ ) {
                    addRecordCount(DateUtil.plusDay(i, lastDay));
                }
            }
            // 重新统计今日
            addRecordCount(TimeUtil.getGernalTime(today.getTime()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private void addRecordCount(String preDay) throws Exception{
        int count = extractAuditRecordMapper.countApplyNumberByDay(preDay);
        CountUserInfo record = new CountUserInfo();
        record.setNum(count);
        record.setId(StringUtil.Md5(preDay + CountUserEnum.extractApplyNumber.name()));
        record.setDay(TimeUtil.parse(preDay));
        record.setType(CountUserEnum.extractApplyNumber);
        countUserInfoDao.save(record);
    }
 
}