|
|
@@ -3,13 +3,18 @@ package com.sundot.airport.item.service.impl;
|
|
3
|
3
|
import cn.hutool.core.collection.CollUtil;
|
|
4
|
4
|
import cn.hutool.core.util.StrUtil;
|
|
5
|
5
|
import com.sundot.airport.common.core.domain.BaseLargeScreenQueryParamDto;
|
|
|
6
|
+import com.sundot.airport.common.core.domain.BoxPlotDataDto;
|
|
|
7
|
+import com.sundot.airport.common.core.domain.GroupedBoxPlotDataDto;
|
|
|
8
|
+import com.sundot.airport.common.core.domain.LargeScreenHomePageUserInfoSqlDto;
|
|
6
|
9
|
import com.sundot.airport.common.core.domain.SysUsageReportDto;
|
|
7
|
10
|
import com.sundot.airport.common.core.domain.SysUsageReportSeizureDto;
|
|
8
|
11
|
import com.sundot.airport.common.core.domain.entity.SysUser;
|
|
9
|
12
|
import com.sundot.airport.common.dto.BaseCommonDto;
|
|
10
|
13
|
import com.sundot.airport.item.domain.*;
|
|
11
|
14
|
import com.sundot.airport.item.mapper.ItemLargeScreenMapper;
|
|
|
15
|
+import com.sundot.airport.item.mapper.SeizureReportMapper;
|
|
12
|
16
|
import com.sundot.airport.item.service.ItemLargeScreenService;
|
|
|
17
|
+import com.sundot.airport.item.service.SeizureDistributionService;
|
|
13
|
18
|
import com.sundot.airport.system.service.ISysUserService;
|
|
14
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
15
|
20
|
import org.springframework.stereotype.Service;
|
|
|
@@ -35,6 +40,10 @@ public class ItemLargeScreenServiceImpl implements ItemLargeScreenService {
|
|
35
|
40
|
private ItemLargeScreenMapper itemLargeScreenMapper;
|
|
36
|
41
|
@Autowired
|
|
37
|
42
|
private ISysUserService sysUserService;
|
|
|
43
|
+ @Autowired
|
|
|
44
|
+ private SeizureDistributionService seizureDistributionService;
|
|
|
45
|
+ @Autowired
|
|
|
46
|
+ private SeizureReportMapper seizureReportMapper;
|
|
38
|
47
|
|
|
39
|
48
|
/**
|
|
40
|
49
|
* 移交公安情况
|
|
|
@@ -339,4 +348,257 @@ public class ItemLargeScreenServiceImpl implements ItemLargeScreenService {
|
|
339
|
348
|
.collect(Collectors.toList());
|
|
340
|
349
|
}
|
|
341
|
350
|
|
|
|
351
|
+ /**
|
|
|
352
|
+ * 移交公安数据统计(查获总数 + 大队排名)
|
|
|
353
|
+ *
|
|
|
354
|
+ * @param dto 大屏查询参数
|
|
|
355
|
+ * @return 移交公安数据统计
|
|
|
356
|
+ */
|
|
|
357
|
+ @Override
|
|
|
358
|
+ public ItemLargeScreenPoliceStatsDto getPoliceStats(BaseLargeScreenQueryParamDto dto) {
|
|
|
359
|
+ // 1. 查询移交公安的明细数据
|
|
|
360
|
+ List<ItemLargeScreenInfoDto> policeList = itemLargeScreenMapper.police(dto);
|
|
|
361
|
+
|
|
|
362
|
+ // 2. 计算查获总数量
|
|
|
363
|
+ BigDecimal totalQuantity = policeList.stream()
|
|
|
364
|
+ .map(ItemLargeScreenInfoDto::getQuantity)
|
|
|
365
|
+ .filter(java.util.Objects::nonNull)
|
|
|
366
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
367
|
+
|
|
|
368
|
+ // 3. 按大队分组统计
|
|
|
369
|
+ Map<String, List<ItemLargeScreenInfoDto>> groupedByBrigade = policeList.stream()
|
|
|
370
|
+ .collect(Collectors.groupingBy(item ->
|
|
|
371
|
+ item.getInspectBrigadeId() + "###" + item.getInspectBrigadeName()));
|
|
|
372
|
+
|
|
|
373
|
+ // 4. 转换为大队排名列表
|
|
|
374
|
+ List<ItemLargeScreenBrigadeRankDto> brigadeRankList = groupedByBrigade.entrySet().stream()
|
|
|
375
|
+ .map(entry -> {
|
|
|
376
|
+ ItemLargeScreenBrigadeRankDto rankDto = new ItemLargeScreenBrigadeRankDto();
|
|
|
377
|
+ List<ItemLargeScreenInfoDto> items = entry.getValue();
|
|
|
378
|
+
|
|
|
379
|
+ if (!items.isEmpty()) {
|
|
|
380
|
+ ItemLargeScreenInfoDto firstItem = items.get(0);
|
|
|
381
|
+ rankDto.setBrigadeId(firstItem.getInspectBrigadeId());
|
|
|
382
|
+ rankDto.setBrigadeName(firstItem.getInspectBrigadeName());
|
|
|
383
|
+
|
|
|
384
|
+ // 计算该科室的查获总数量
|
|
|
385
|
+ BigDecimal deptQuantity = items.stream()
|
|
|
386
|
+ .map(ItemLargeScreenInfoDto::getQuantity)
|
|
|
387
|
+ .filter(java.util.Objects::nonNull)
|
|
|
388
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
389
|
+ rankDto.setQuantity(deptQuantity);
|
|
|
390
|
+
|
|
|
391
|
+ // 计算占比
|
|
|
392
|
+ if (totalQuantity.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
393
|
+ rankDto.setScale(deptQuantity.multiply(new BigDecimal("100"))
|
|
|
394
|
+ .divide(totalQuantity, 2, BigDecimal.ROUND_HALF_UP));
|
|
|
395
|
+ } else {
|
|
|
396
|
+ rankDto.setScale(BigDecimal.ZERO);
|
|
|
397
|
+ }
|
|
|
398
|
+ }
|
|
|
399
|
+
|
|
|
400
|
+ return rankDto;
|
|
|
401
|
+ })
|
|
|
402
|
+ .sorted(Comparator.comparing(ItemLargeScreenBrigadeRankDto::getQuantity).reversed())
|
|
|
403
|
+ .collect(Collectors.toList());
|
|
|
404
|
+
|
|
|
405
|
+ // 5. 设置排名
|
|
|
406
|
+ for (int i = 0; i < brigadeRankList.size(); i++) {
|
|
|
407
|
+ brigadeRankList.get(i).setRank(i + 1);
|
|
|
408
|
+ }
|
|
|
409
|
+
|
|
|
410
|
+ // 6. 构造返回结果
|
|
|
411
|
+ ItemLargeScreenPoliceStatsDto result = new ItemLargeScreenPoliceStatsDto();
|
|
|
412
|
+ result.setTotalQuantity(totalQuantity);
|
|
|
413
|
+ result.setBrigadeRankList(brigadeRankList);
|
|
|
414
|
+
|
|
|
415
|
+ return result;
|
|
|
416
|
+ }
|
|
|
417
|
+
|
|
|
418
|
+ /**
|
|
|
419
|
+ * X 光机漏检数据
|
|
|
420
|
+ *
|
|
|
421
|
+ * @param dto 大屏查询参数
|
|
|
422
|
+ * @return X 光机漏检数据
|
|
|
423
|
+ */
|
|
|
424
|
+ @Override
|
|
|
425
|
+ public List<ItemXRayMissCheckDto> xRayMissCheck(BaseLargeScreenQueryParamDto dto) {
|
|
|
426
|
+ return itemLargeScreenMapper.xRayMissCheck(dto);
|
|
|
427
|
+ }
|
|
|
428
|
+
|
|
|
429
|
+ /**
|
|
|
430
|
+ * X 光机漏检人员统计 TOP3
|
|
|
431
|
+ *
|
|
|
432
|
+ * @param dto 大屏查询参数
|
|
|
433
|
+ * @return X 光机漏检人员统计 TOP3
|
|
|
434
|
+ */
|
|
|
435
|
+ @Override
|
|
|
436
|
+ public List<ItemXRayMissCheckUserStatsDto> xRayMissCheckUserStatsTop3(BaseLargeScreenQueryParamDto dto) {
|
|
|
437
|
+ // 直接查询并返回前 3 名
|
|
|
438
|
+ return itemLargeScreenMapper.xRayMissCheckUserStatsTop3(dto);
|
|
|
439
|
+ }
|
|
|
440
|
+
|
|
|
441
|
+ /**
|
|
|
442
|
+ * 异常查获数据
|
|
|
443
|
+ *
|
|
|
444
|
+ * @param dto 大屏查询参数
|
|
|
445
|
+ * @return 异常查获数据
|
|
|
446
|
+ */
|
|
|
447
|
+ @Override
|
|
|
448
|
+ public List<ItemAbnormalSeizureDto> getAbnormalSeizureData(BaseLargeScreenQueryParamDto dto) {
|
|
|
449
|
+ // 1. 获取箱线图数据(用于获取上下限)
|
|
|
450
|
+ List<GroupedBoxPlotDataDto> boxPlotDataList = seizureDistributionService.calculateBoxPlotData(dto);
|
|
|
451
|
+
|
|
|
452
|
+ if (boxPlotDataList == null || boxPlotDataList.isEmpty()) {
|
|
|
453
|
+ return Collections.emptyList();
|
|
|
454
|
+ }
|
|
|
455
|
+
|
|
|
456
|
+ // 2. 获取站级数据(第一个分组)的上下限
|
|
|
457
|
+ BigDecimal lowerBound = BigDecimal.ZERO;
|
|
|
458
|
+ BigDecimal upperBound = BigDecimal.ZERO;
|
|
|
459
|
+
|
|
|
460
|
+ if (!boxPlotDataList.isEmpty()) {
|
|
|
461
|
+ BoxPlotDataDto boxPlotData = boxPlotDataList.get(0).getBoxPlotData();
|
|
|
462
|
+ lowerBound = boxPlotData.getLowerBound();
|
|
|
463
|
+ upperBound = boxPlotData.getUpperBound();
|
|
|
464
|
+ }
|
|
|
465
|
+
|
|
|
466
|
+ // 3. 查询用户信息和查获数量
|
|
|
467
|
+ List<ItemLargeScreenHomePageSeizureReportSqlDto> seizureReportList = seizureReportMapper.homePageSeizureReport(dto);
|
|
|
468
|
+ List<LargeScreenHomePageUserInfoSqlDto> userInfoList = sysUserService.homePageUserInfo();
|
|
|
469
|
+
|
|
|
470
|
+ if (CollUtil.isEmpty(seizureReportList) || CollUtil.isEmpty(userInfoList)) {
|
|
|
471
|
+ return Collections.emptyList();
|
|
|
472
|
+ }
|
|
|
473
|
+
|
|
|
474
|
+ // 4. 按用户分组统计查获总数
|
|
|
475
|
+ Map<Long, BigDecimal> userSeizureMap = seizureReportList.stream()
|
|
|
476
|
+ .collect(Collectors.groupingBy(
|
|
|
477
|
+ ItemLargeScreenHomePageSeizureReportSqlDto::getUserId,
|
|
|
478
|
+ Collectors.reducing(BigDecimal.ZERO, ItemLargeScreenHomePageSeizureReportSqlDto::getQuantity, BigDecimal::add)
|
|
|
479
|
+ ));
|
|
|
480
|
+
|
|
|
481
|
+ // 5. 筛选出异常值
|
|
|
482
|
+ List<ItemAbnormalSeizureDto> abnormalList = new ArrayList<>();
|
|
|
483
|
+
|
|
|
484
|
+ for (LargeScreenHomePageUserInfoSqlDto userInfo : userInfoList) {
|
|
|
485
|
+ BigDecimal totalQuantity = userSeizureMap.getOrDefault(userInfo.getUserId(), BigDecimal.ZERO);
|
|
|
486
|
+
|
|
|
487
|
+ // 判断是否为异常值
|
|
|
488
|
+ if (totalQuantity.compareTo(lowerBound) < 0 || totalQuantity.compareTo(upperBound) > 0) {
|
|
|
489
|
+ ItemAbnormalSeizureDto abnormalDto = new ItemAbnormalSeizureDto();
|
|
|
490
|
+ abnormalDto.setBrigadeName(userInfo.getBrigadeName());
|
|
|
491
|
+ abnormalDto.setDepartmentName(userInfo.getDepartmentName());
|
|
|
492
|
+ abnormalDto.setTeamName(userInfo.getTeamName());
|
|
|
493
|
+ abnormalDto.setUserName(userInfo.getNickName());
|
|
|
494
|
+ abnormalDto.setSeizureQuantity(totalQuantity);
|
|
|
495
|
+ abnormalList.add(abnormalDto);
|
|
|
496
|
+ }
|
|
|
497
|
+ }
|
|
|
498
|
+
|
|
|
499
|
+ return abnormalList;
|
|
|
500
|
+ }
|
|
|
501
|
+
|
|
|
502
|
+ /**
|
|
|
503
|
+ * 异常查获数据 TOP3(3 个高于 +3 个低于)
|
|
|
504
|
+ *
|
|
|
505
|
+ * @param dto 大屏查询参数
|
|
|
506
|
+ * @return 异常查获数据 TOP3
|
|
|
507
|
+ */
|
|
|
508
|
+ @Override
|
|
|
509
|
+ public ItemAbnormalSeizureRankDto getAbnormalSeizureDataTop3(BaseLargeScreenQueryParamDto dto) {
|
|
|
510
|
+ ItemAbnormalSeizureRankDto result = new ItemAbnormalSeizureRankDto();
|
|
|
511
|
+ // 1. 获取箱线图数据(用于获取上下限)
|
|
|
512
|
+ List<GroupedBoxPlotDataDto> boxPlotDataList = seizureDistributionService.calculateBoxPlotData(dto);
|
|
|
513
|
+
|
|
|
514
|
+ if (boxPlotDataList == null || boxPlotDataList.isEmpty()) {
|
|
|
515
|
+ return result;
|
|
|
516
|
+ }
|
|
|
517
|
+
|
|
|
518
|
+ // 2. 获取站级数据(第一个分组)的上下限
|
|
|
519
|
+ BigDecimal lowerBound = BigDecimal.ZERO;
|
|
|
520
|
+ BigDecimal upperBound = BigDecimal.ZERO;
|
|
|
521
|
+
|
|
|
522
|
+ if (!boxPlotDataList.isEmpty()) {
|
|
|
523
|
+ BoxPlotDataDto boxPlotData = boxPlotDataList.get(0).getBoxPlotData();
|
|
|
524
|
+ lowerBound = boxPlotData.getLowerBound();
|
|
|
525
|
+ upperBound = boxPlotData.getUpperBound();
|
|
|
526
|
+ }
|
|
|
527
|
+
|
|
|
528
|
+ // 3. 查询用户信息和查获数量
|
|
|
529
|
+ List<ItemLargeScreenHomePageSeizureReportSqlDto> seizureReportList = seizureReportMapper.homePageSeizureReport(dto);
|
|
|
530
|
+ List<LargeScreenHomePageUserInfoSqlDto> userInfoList = sysUserService.homePageUserInfo();
|
|
|
531
|
+
|
|
|
532
|
+ if (CollUtil.isEmpty(seizureReportList) || CollUtil.isEmpty(userInfoList)) {
|
|
|
533
|
+ return result;
|
|
|
534
|
+ }
|
|
|
535
|
+
|
|
|
536
|
+ // 4. 按用户分组统计查获总数
|
|
|
537
|
+ Map<Long, BigDecimal> userSeizureMap = seizureReportList.stream()
|
|
|
538
|
+ .collect(Collectors.groupingBy(
|
|
|
539
|
+ ItemLargeScreenHomePageSeizureReportSqlDto::getUserId,
|
|
|
540
|
+ Collectors.reducing(BigDecimal.ZERO, ItemLargeScreenHomePageSeizureReportSqlDto::getQuantity, BigDecimal::add)
|
|
|
541
|
+ ));
|
|
|
542
|
+
|
|
|
543
|
+ // 5. 筛选出异常值并分类
|
|
|
544
|
+ List<ItemAbnormalSeizureDto> higherList = new ArrayList<>();
|
|
|
545
|
+ List<ItemAbnormalSeizureDto> lowerList = new ArrayList<>();
|
|
|
546
|
+
|
|
|
547
|
+ for (LargeScreenHomePageUserInfoSqlDto userInfo : userInfoList) {
|
|
|
548
|
+ BigDecimal totalQuantity = userSeizureMap.getOrDefault(userInfo.getUserId(), BigDecimal.ZERO);
|
|
|
549
|
+
|
|
|
550
|
+ // 判断是否为异常值
|
|
|
551
|
+ if (totalQuantity.compareTo(upperBound) > 0) {
|
|
|
552
|
+ // 显著高于
|
|
|
553
|
+ ItemAbnormalSeizureDto abnormalDto = new ItemAbnormalSeizureDto();
|
|
|
554
|
+ abnormalDto.setBrigadeName(userInfo.getBrigadeName());
|
|
|
555
|
+ abnormalDto.setDepartmentName(userInfo.getDepartmentName());
|
|
|
556
|
+ abnormalDto.setTeamName(userInfo.getTeamName());
|
|
|
557
|
+ abnormalDto.setUserName(userInfo.getNickName());
|
|
|
558
|
+ abnormalDto.setSeizureQuantity(totalQuantity);
|
|
|
559
|
+ higherList.add(abnormalDto);
|
|
|
560
|
+ } else if (totalQuantity.compareTo(lowerBound) < 0) {
|
|
|
561
|
+ // 显著低于
|
|
|
562
|
+ ItemAbnormalSeizureDto abnormalDto = new ItemAbnormalSeizureDto();
|
|
|
563
|
+ abnormalDto.setBrigadeName(userInfo.getBrigadeName());
|
|
|
564
|
+ abnormalDto.setDepartmentName(userInfo.getDepartmentName());
|
|
|
565
|
+ abnormalDto.setTeamName(userInfo.getTeamName());
|
|
|
566
|
+ abnormalDto.setUserName(userInfo.getNickName());
|
|
|
567
|
+ abnormalDto.setSeizureQuantity(totalQuantity);
|
|
|
568
|
+ lowerList.add(abnormalDto);
|
|
|
569
|
+ }
|
|
|
570
|
+ }
|
|
|
571
|
+
|
|
|
572
|
+ // 6. 排序并设置排名
|
|
|
573
|
+ higherList.sort(Comparator.comparing(ItemAbnormalSeizureDto::getSeizureQuantity).reversed());
|
|
|
574
|
+ lowerList.sort(Comparator.comparing(ItemAbnormalSeizureDto::getSeizureQuantity));
|
|
|
575
|
+
|
|
|
576
|
+ for (int i = 0; i < higherList.size(); i++) {
|
|
|
577
|
+ higherList.get(i).setRank(i + 1);
|
|
|
578
|
+ }
|
|
|
579
|
+
|
|
|
580
|
+ for (int i = 0; i < lowerList.size(); i++) {
|
|
|
581
|
+ lowerList.get(i).setRank(i + 1);
|
|
|
582
|
+ }
|
|
|
583
|
+
|
|
|
584
|
+ // 7. 取前 3 个
|
|
|
585
|
+ int higherCount = Math.min(3, higherList.size());
|
|
|
586
|
+ int lowerCount = Math.min(3, lowerList.size());
|
|
|
587
|
+ List<ItemAbnormalSeizureDto> lowList = new ArrayList<>();
|
|
|
588
|
+ List<ItemAbnormalSeizureDto> higList = new ArrayList<>();
|
|
|
589
|
+
|
|
|
590
|
+ // 添加高于的 3 个
|
|
|
591
|
+ for (int i = 0; i < higherCount; i++) {
|
|
|
592
|
+ higList.add(higherList.get(i));
|
|
|
593
|
+ }
|
|
|
594
|
+ result.setHigList(higList);
|
|
|
595
|
+
|
|
|
596
|
+ // 添加低于的 3 个
|
|
|
597
|
+ for (int i = 0; i < lowerCount; i++) {
|
|
|
598
|
+ lowList.add(lowerList.get(i));
|
|
|
599
|
+ }
|
|
|
600
|
+ result.setLowList(lowList);
|
|
|
601
|
+ return result;
|
|
|
602
|
+ }
|
|
|
603
|
+
|
|
342
|
604
|
}
|