|
|
@@ -3,23 +3,20 @@ package com.sundot.airport.ledger.service.impl;
|
|
3
|
3
|
import cn.hutool.core.collection.CollUtil;
|
|
4
|
4
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
5
|
5
|
import com.google.common.collect.Lists;
|
|
|
6
|
+import com.sundot.airport.common.core.domain.entity.SysDept;
|
|
|
7
|
+import com.sundot.airport.common.enums.DeptTypeEnum;
|
|
6
|
8
|
import com.sundot.airport.common.utils.DateUtils;
|
|
7
|
9
|
import com.sundot.airport.ledger.domain.LedgerSeizureStats;
|
|
8
|
|
-import com.sundot.airport.ledger.domain.vo.CountQueryReqVO;
|
|
9
|
|
-import com.sundot.airport.ledger.domain.vo.CountSeizureSingleQuantityResVO;
|
|
10
|
|
-import com.sundot.airport.ledger.domain.vo.CountSeizureTotalQuantityResVO;
|
|
11
|
|
-import com.sundot.airport.ledger.domain.vo.LaneThroughputResVO;
|
|
12
|
|
-import com.sundot.airport.ledger.domain.vo.SeizeCategoryQuantityVO;
|
|
13
|
|
-import com.sundot.airport.ledger.domain.vo.SeizeItemVO;
|
|
14
|
|
-import com.sundot.airport.ledger.domain.vo.SeizeTotalAndItemVO;
|
|
15
|
|
-import com.sundot.airport.ledger.domain.vo.SeizureAreaVO;
|
|
|
10
|
+import com.sundot.airport.ledger.domain.vo.*;
|
|
16
|
11
|
import com.sundot.airport.ledger.mapper.LedgerSeizureStatsMapper;
|
|
17
|
12
|
import com.sundot.airport.ledger.service.ILedgerSeizureStatsService;
|
|
|
13
|
+import com.sundot.airport.system.service.ISysDeptService;
|
|
18
|
14
|
import lombok.extern.slf4j.Slf4j;
|
|
19
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
20
|
16
|
import org.springframework.stereotype.Service;
|
|
21
|
17
|
import org.springframework.transaction.annotation.Transactional;
|
|
22
|
18
|
|
|
|
19
|
+import java.util.Calendar;
|
|
23
|
20
|
import java.util.Date;
|
|
24
|
21
|
import java.util.List;
|
|
25
|
22
|
import java.util.Map;
|
|
|
@@ -35,6 +32,10 @@ public class LedgerSeizureStatsServiceImpl extends ServiceImpl<LedgerSeizureStat
|
|
35
|
32
|
@Autowired
|
|
36
|
33
|
private LedgerSeizureStatsMapper mapper;
|
|
37
|
34
|
|
|
|
35
|
+ @Autowired
|
|
|
36
|
+ private ISysDeptService sysDeptService;
|
|
|
37
|
+
|
|
|
38
|
+
|
|
38
|
39
|
@Override
|
|
39
|
40
|
public List<LedgerSeizureStats> selectList(LedgerSeizureStats query) {
|
|
40
|
41
|
return mapper.selectList(query);
|
|
|
@@ -160,18 +161,145 @@ public class LedgerSeizureStatsServiceImpl extends ServiceImpl<LedgerSeizureStat
|
|
160
|
161
|
* @date 2026/5/20 13:43
|
|
161
|
162
|
*/
|
|
162
|
163
|
@Override
|
|
163
|
|
- public SeizeTotalAndItemVO getTimeRangeStats(CountQueryReqVO countQueryReq) {
|
|
164
|
|
- SeizeTotalAndItemVO result = new SeizeTotalAndItemVO();
|
|
|
164
|
+ public DailyDeptStatisticsVO getTimeRangeStats(CountQueryReqVO countQueryReq) {
|
|
|
165
|
+ DailyDeptStatisticsVO result = new DailyDeptStatisticsVO();
|
|
165
|
166
|
// 总查获数
|
|
166
|
167
|
Integer total = this.baseMapper.statsTimeRangeTotal(countQueryReq);
|
|
167
|
168
|
result.setTotalSeizeNum(total);
|
|
168
|
|
- // 柱状明细
|
|
169
|
|
- List<SeizeItemVO> itemList = this.baseMapper.statsTimeRangeItem(countQueryReq);
|
|
|
169
|
+
|
|
|
170
|
+ List<DailyDeptStatisticsVO.DailyDeptItemVO> itemList = getDetailedStatsByLevel(countQueryReq);
|
|
|
171
|
+
|
|
|
172
|
+ // 每日部门统计数据
|
|
170
|
173
|
result.setItemList(itemList);
|
|
171
|
174
|
return result;
|
|
172
|
175
|
}
|
|
173
|
176
|
|
|
174
|
177
|
/**
|
|
|
178
|
+ * 获取详细统计数据(每天每个部门/班组/小组的数据)
|
|
|
179
|
+ *
|
|
|
180
|
+ */
|
|
|
181
|
+ private List<DailyDeptStatisticsVO.DailyDeptItemVO> getDetailedStatsByLevel(CountQueryReqVO countQueryReq) {
|
|
|
182
|
+ List<DailyDeptStatisticsVO.DailyDeptItemVO> result = Lists.newArrayList();
|
|
|
183
|
+
|
|
|
184
|
+ // 生成时间范围内的所有日期列表
|
|
|
185
|
+ List<Date> dateRange = generateDateRange(countQueryReq.getStartDate(), countQueryReq.getEndDate());
|
|
|
186
|
+
|
|
|
187
|
+ // 判断查询类型
|
|
|
188
|
+ if (countQueryReq.getDeptId() == null && countQueryReq.getTeamId() == null && countQueryReq.getGroupId() == null) {
|
|
|
189
|
+ // 站级别查询:获取所有大队的数据
|
|
|
190
|
+ SysDept dept = new SysDept();
|
|
|
191
|
+ dept.setStatus("0");
|
|
|
192
|
+ dept.setDeptType("BRIGADE");
|
|
|
193
|
+ List<SysDept> brigadeList = sysDeptService.selectDeptList(dept);
|
|
|
194
|
+
|
|
|
195
|
+ if (CollUtil.isNotEmpty(brigadeList)) {
|
|
|
196
|
+ for (SysDept brigade : brigadeList) {
|
|
|
197
|
+ processDepartmentData(countQueryReq, dateRange, brigade.getDeptName(), brigade.getDeptId(), "DEPT", result);
|
|
|
198
|
+ }
|
|
|
199
|
+ }
|
|
|
200
|
+ } else {
|
|
|
201
|
+ // 部门/班组/小组级别查询
|
|
|
202
|
+ String displayName = "";
|
|
|
203
|
+ Long targetId = null;
|
|
|
204
|
+ String levelType = "";
|
|
|
205
|
+ if (countQueryReq.getGroupId() != null) {
|
|
|
206
|
+ SysDept dept = sysDeptService.selectDeptById(countQueryReq.getGroupId());
|
|
|
207
|
+ displayName = (dept != null) ? dept.getDeptName() : "小组" + countQueryReq.getDeptId();;
|
|
|
208
|
+ targetId = countQueryReq.getGroupId();
|
|
|
209
|
+ levelType = DeptTypeEnum.TEAMS.getCode();
|
|
|
210
|
+ }else if (countQueryReq.getTeamId() != null) {
|
|
|
211
|
+ SysDept dept = sysDeptService.selectDeptById(countQueryReq.getTeamId());
|
|
|
212
|
+ displayName = (dept != null) ? dept.getDeptName() : "班组" + countQueryReq.getDeptId();
|
|
|
213
|
+ targetId = countQueryReq.getTeamId();
|
|
|
214
|
+ levelType =DeptTypeEnum.MANAGER.getCode();
|
|
|
215
|
+ } else if (countQueryReq.getDeptId() != null) {
|
|
|
216
|
+ SysDept dept = sysDeptService.selectDeptById(countQueryReq.getDeptId());
|
|
|
217
|
+ displayName = (dept != null) ? dept.getDeptName() : "部门" + countQueryReq.getDeptId();
|
|
|
218
|
+ targetId = countQueryReq.getDeptId();
|
|
|
219
|
+ levelType =DeptTypeEnum.BRIGADE.getCode();
|
|
|
220
|
+ }
|
|
|
221
|
+
|
|
|
222
|
+ processDepartmentData(countQueryReq, dateRange, displayName, targetId, levelType, result);
|
|
|
223
|
+ }
|
|
|
224
|
+
|
|
|
225
|
+ return result;
|
|
|
226
|
+ }
|
|
|
227
|
+
|
|
|
228
|
+ /**
|
|
|
229
|
+ * 处理单个部门/团队/小组的数据
|
|
|
230
|
+ */
|
|
|
231
|
+ private void processDepartmentData(CountQueryReqVO countQueryReq, List<Date> dateRange, String deptName, Long targetId, String levelType, List<DailyDeptStatisticsVO.DailyDeptItemVO> result) {
|
|
|
232
|
+ CountQueryReqVO req = new CountQueryReqVO();
|
|
|
233
|
+ req.setStartDate(countQueryReq.getStartDate());
|
|
|
234
|
+ req.setEndDate(countQueryReq.getEndDate());
|
|
|
235
|
+
|
|
|
236
|
+ // 根据层级类型设置查询参数
|
|
|
237
|
+ switch (levelType) {
|
|
|
238
|
+ case "BRIGADE":
|
|
|
239
|
+ req.setDeptId(targetId);
|
|
|
240
|
+ break;
|
|
|
241
|
+ case "MANAGER":
|
|
|
242
|
+ req.setTeamId(targetId);
|
|
|
243
|
+ break;
|
|
|
244
|
+ case "TEAMS":
|
|
|
245
|
+ req.setGroupId(targetId);
|
|
|
246
|
+ break;
|
|
|
247
|
+ }
|
|
|
248
|
+
|
|
|
249
|
+ // 获取统计数据
|
|
|
250
|
+ List<CountSeizureSingleQuantityResVO> dailyData = this.baseMapper.countSeizureSingleQuantity(req);
|
|
|
251
|
+
|
|
|
252
|
+ // 创建日期到统计数据的映射
|
|
|
253
|
+ Map<String, CountSeizureSingleQuantityResVO> dataMap = dailyData.stream()
|
|
|
254
|
+ .collect(Collectors.toMap(
|
|
|
255
|
+ item -> DateUtils.formatDateKey(item.getRecordDate()),
|
|
|
256
|
+ item -> item,
|
|
|
257
|
+ (existing, replacement) -> existing
|
|
|
258
|
+ ));
|
|
|
259
|
+
|
|
|
260
|
+ // 没有数据的补0
|
|
|
261
|
+ for (Date date : dateRange) {
|
|
|
262
|
+ String dateKey = DateUtils.formatDateKey(date);
|
|
|
263
|
+ if (dataMap.containsKey(dateKey)) {
|
|
|
264
|
+ // 有数据,使用实际数据
|
|
|
265
|
+ CountSeizureSingleQuantityResVO dailyStat = dataMap.get(dateKey);
|
|
|
266
|
+ DailyDeptStatisticsVO.DailyDeptItemVO item = new DailyDeptStatisticsVO.DailyDeptItemVO();
|
|
|
267
|
+ item.setDeptName(deptName);
|
|
|
268
|
+ item.setDate(dailyStat.getRecordDate());
|
|
|
269
|
+ item.setSeizeNum(dailyStat.getSeizeQuantity());
|
|
|
270
|
+ result.add(item);
|
|
|
271
|
+ } else {
|
|
|
272
|
+ // 没有数据,补0
|
|
|
273
|
+ DailyDeptStatisticsVO.DailyDeptItemVO item = new DailyDeptStatisticsVO.DailyDeptItemVO();
|
|
|
274
|
+ item.setDeptName(deptName);
|
|
|
275
|
+ item.setDate(date);
|
|
|
276
|
+ item.setSeizeNum(0);
|
|
|
277
|
+ result.add(item);
|
|
|
278
|
+ }
|
|
|
279
|
+ }
|
|
|
280
|
+ }
|
|
|
281
|
+
|
|
|
282
|
+ /**
|
|
|
283
|
+ * 生成日期范围列表
|
|
|
284
|
+ */
|
|
|
285
|
+ private List<Date> generateDateRange(Date startDate, Date endDate) {
|
|
|
286
|
+ List<Date> dateList = Lists.newArrayList();
|
|
|
287
|
+
|
|
|
288
|
+ Calendar startCal = Calendar.getInstance();
|
|
|
289
|
+ startCal.setTime(startDate);
|
|
|
290
|
+
|
|
|
291
|
+ Calendar endCal = Calendar.getInstance();
|
|
|
292
|
+ endCal.setTime(endDate);
|
|
|
293
|
+
|
|
|
294
|
+ while (!startCal.getTime().after(endCal.getTime())) {
|
|
|
295
|
+ dateList.add(startCal.getTime());
|
|
|
296
|
+ startCal.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
297
|
+ }
|
|
|
298
|
+
|
|
|
299
|
+ return dateList;
|
|
|
300
|
+ }
|
|
|
301
|
+
|
|
|
302
|
+ /**
|
|
175
|
303
|
* 功能描述:查获物品分布
|
|
176
|
304
|
*
|
|
177
|
305
|
* @param countQueryReq 查询参数
|
|
|
@@ -202,4 +330,4 @@ public class LedgerSeizureStatsServiceImpl extends ServiceImpl<LedgerSeizureStat
|
|
202
|
330
|
List<SeizureAreaVO> seizureAreaList = this.baseMapper.countSeizeAreaQuantity(countQueryReq);
|
|
203
|
331
|
return CollUtil.emptyIfNull(seizureAreaList);
|
|
204
|
332
|
}
|
|
205
|
|
-}
|
|
|
333
|
+}
|