Przeglądaj źródła

24.本地自测”近30天查获数量(总表)“接口;
25.本地自测”近30天查获数量(员工/小组/班组/部门)“接口;

sunpanhu 4 tygodni temu
rodzic
commit
03bf50ed4f

+ 9 - 1
airport-ledger/src/main/java/com/sundot/airport/ledger/domain/vo/CountSeizureSingleQuantityResVO.java

@@ -1,5 +1,6 @@
1 1
 package com.sundot.airport.ledger.domain.vo;
2 2
 
3
+import com.fasterxml.jackson.annotation.JsonFormat;
3 4
 import lombok.Data;
4 5
 
5 6
 import java.io.Serializable;
@@ -16,6 +17,7 @@ public class CountSeizureSingleQuantityResVO implements Serializable {
16 17
     /**
17 18
      * 日期(X轴)
18 19
      */
20
+    @JsonFormat(pattern = "yyyy-MM-dd")
19 21
     private Date recordDate;
20 22
     /**
21 23
      * 维度名称:员工名/小组名/班组名/部门名(每条折线)
@@ -24,5 +26,11 @@ public class CountSeizureSingleQuantityResVO implements Serializable {
24 26
     /**
25 27
      * 当日查获数量(Y轴)
26 28
      */
27
-    private Integer seizeNum;
29
+    private Integer seizeQuantity;
30
+
31
+    public CountSeizureSingleQuantityResVO(Date date, String groupName) {
32
+        this.recordDate = date;
33
+        this.groupName = groupName;
34
+        this.seizeQuantity = 0;
35
+    }
28 36
 }

+ 8 - 0
airport-ledger/src/main/java/com/sundot/airport/ledger/domain/vo/CountSeizureTotalQuantityResVO.java

@@ -1,5 +1,6 @@
1 1
 package com.sundot.airport.ledger.domain.vo;
2 2
 
3
+import com.fasterxml.jackson.annotation.JsonFormat;
3 4
 import lombok.Data;
4 5
 
5 6
 import java.io.Serializable;
@@ -16,6 +17,7 @@ public class CountSeizureTotalQuantityResVO implements Serializable {
16 17
     /**
17 18
      * 查获日期
18 19
      */
20
+    @JsonFormat(pattern = "yyyy-MM-dd")
19 21
     private Date recordDate;
20 22
     /**
21 23
      * 分组名称(部门/班组/小组/全量)
@@ -25,4 +27,10 @@ public class CountSeizureTotalQuantityResVO implements Serializable {
25 27
      * 当日查获数量
26 28
      */
27 29
     private Integer seizeQuantity;
30
+
31
+    public CountSeizureTotalQuantityResVO(Date date, String groupName) {
32
+        this.recordDate = date;
33
+        this.groupName = groupName;
34
+        this.seizeQuantity = 0;
35
+    }
28 36
 }

+ 83 - 5
airport-ledger/src/main/java/com/sundot/airport/ledger/service/impl/LedgerSeizureStatsServiceImpl.java

@@ -1,28 +1,34 @@
1 1
 package com.sundot.airport.ledger.service.impl;
2 2
 
3
-import java.util.Collections;
4
-import java.util.List;
5
-
6 3
 import cn.hutool.core.collection.CollUtil;
7 4
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
+import com.google.common.collect.Lists;
8 6
 import com.sundot.airport.common.utils.DateUtils;
9 7
 import com.sundot.airport.ledger.domain.LedgerSeizureStats;
10 8
 import com.sundot.airport.ledger.domain.vo.CountQueryReqVO;
11 9
 import com.sundot.airport.ledger.domain.vo.CountSeizureSingleQuantityResVO;
12 10
 import com.sundot.airport.ledger.domain.vo.CountSeizureTotalQuantityResVO;
11
+import com.sundot.airport.ledger.domain.vo.LaneThroughputResVO;
13 12
 import com.sundot.airport.ledger.domain.vo.SeizeCategoryQuantityVO;
14 13
 import com.sundot.airport.ledger.domain.vo.SeizeItemVO;
15 14
 import com.sundot.airport.ledger.domain.vo.SeizeTotalAndItemVO;
16 15
 import com.sundot.airport.ledger.domain.vo.SeizureAreaVO;
17 16
 import com.sundot.airport.ledger.mapper.LedgerSeizureStatsMapper;
18 17
 import com.sundot.airport.ledger.service.ILedgerSeizureStatsService;
18
+import lombok.extern.slf4j.Slf4j;
19 19
 import org.springframework.beans.factory.annotation.Autowired;
20 20
 import org.springframework.stereotype.Service;
21 21
 import org.springframework.transaction.annotation.Transactional;
22 22
 
23
+import java.util.Date;
24
+import java.util.List;
25
+import java.util.Map;
26
+import java.util.stream.Collectors;
27
+
23 28
 /**
24 29
  * 查获违规品统计Service实现
25 30
  */
31
+@Slf4j
26 32
 @Service
27 33
 public class LedgerSeizureStatsServiceImpl extends ServiceImpl<LedgerSeizureStatsMapper, LedgerSeizureStats> implements ILedgerSeizureStatsService {
28 34
 
@@ -54,7 +60,43 @@ public class LedgerSeizureStatsServiceImpl extends ServiceImpl<LedgerSeizureStat
54 60
     @Override
55 61
     public List<CountSeizureTotalQuantityResVO> countSeizureTotalQuantity(CountQueryReqVO countQueryReq) {
56 62
         List<CountSeizureTotalQuantityResVO> seizureQuantityResList = this.baseMapper.countSeizureTotalQuantity(countQueryReq);
57
-        return CollUtil.emptyIfNull(seizureQuantityResList);
63
+        seizureQuantityResList = CollUtil.emptyIfNull(seizureQuantityResList);
64
+
65
+        log.info("SQL查询返回数据条数: {}", seizureQuantityResList.size());
66
+
67
+        // 生成近30天的日期列表
68
+        List<Date> last30Days = DateUtils.generateLast30Days();
69
+
70
+        // 将查询结果按日期建立映射(只比较日期部分,忽略时间)
71
+        Map<String, CountSeizureTotalQuantityResVO> dataMap = seizureQuantityResList.stream()
72
+                .collect(Collectors.toMap(
73
+                        vo -> DateUtils.formatDateKey(vo.getRecordDate()),
74
+                        vo -> vo,
75
+                        (existing, replacement) -> existing
76
+                ));
77
+
78
+        log.info("数据Map中的日期键: {}", dataMap.keySet());
79
+
80
+        // 获取小组名称
81
+        String groupName = "";
82
+        if (CollUtil.isNotEmpty(seizureQuantityResList)) {
83
+            groupName = seizureQuantityResList.get(0).getGroupName();
84
+        }
85
+
86
+        // 补齐缺失的日期数据
87
+        List<CountSeizureTotalQuantityResVO> resultList = Lists.newArrayList();
88
+        for (Date date : last30Days) {
89
+            String dateKey = DateUtils.formatDateKey(date);
90
+            if (dataMap.containsKey(dateKey)) {
91
+                // 存在的日期,使用查询结果
92
+                resultList.add(dataMap.get(dateKey));
93
+            } else {
94
+                // 缺失的日期,补充0数据
95
+                CountSeizureTotalQuantityResVO countSeizureTotalQuantity = new CountSeizureTotalQuantityResVO(date, groupName);
96
+                resultList.add(countSeizureTotalQuantity);
97
+            }
98
+        }
99
+        return resultList;
58 100
     }
59 101
 
60 102
     /**
@@ -69,7 +111,43 @@ public class LedgerSeizureStatsServiceImpl extends ServiceImpl<LedgerSeizureStat
69 111
     @Override
70 112
     public List<CountSeizureSingleQuantityResVO> countSeizureSingleQuantity(CountQueryReqVO countQueryReq) {
71 113
         List<CountSeizureSingleQuantityResVO> seizureQuantityResList = this.baseMapper.countSeizureSingleQuantity(countQueryReq);
72
-        return CollUtil.emptyIfNull(seizureQuantityResList);
114
+        seizureQuantityResList = CollUtil.emptyIfNull(seizureQuantityResList);
115
+
116
+        log.info("SQL查询返回数据条数: {}", seizureQuantityResList.size());
117
+
118
+        // 生成近30天的日期列表
119
+        List<Date> last30Days = DateUtils.generateLast30Days();
120
+
121
+        // 将查询结果按日期建立映射(只比较日期部分,忽略时间)
122
+        Map<String, CountSeizureSingleQuantityResVO> dataMap = seizureQuantityResList.stream()
123
+                .collect(Collectors.toMap(
124
+                        vo -> DateUtils.formatDateKey(vo.getRecordDate()),
125
+                        vo -> vo,
126
+                        (existing, replacement) -> existing
127
+                ));
128
+
129
+        log.info("数据Map中的日期键: {}", dataMap.keySet());
130
+
131
+        // 获取小组名称
132
+        String groupName = "";
133
+        if (CollUtil.isNotEmpty(seizureQuantityResList)) {
134
+            groupName = seizureQuantityResList.get(0).getGroupName();
135
+        }
136
+
137
+        // 补齐缺失的日期数据
138
+        List<CountSeizureSingleQuantityResVO> resultList = Lists.newArrayList();
139
+        for (Date date : last30Days) {
140
+            String dateKey = DateUtils.formatDateKey(date);
141
+            if (dataMap.containsKey(dateKey)) {
142
+                // 存在的日期,使用查询结果
143
+                resultList.add(dataMap.get(dateKey));
144
+            } else {
145
+                // 缺失的日期,补充0数据
146
+                CountSeizureSingleQuantityResVO countSeizureTotalQuantity = new CountSeizureSingleQuantityResVO(date, groupName);
147
+                resultList.add(countSeizureTotalQuantity);
148
+            }
149
+        }
150
+        return resultList;
73 151
     }
74 152
 
75 153
     /**

+ 9 - 9
airport-ledger/src/main/resources/mapper/ledger/LedgerSeizureStatsMapper.xml

@@ -94,7 +94,7 @@
94 94
                 <when test="deptId != null">dept_name AS groupName</when>
95 95
                 <otherwise>'站' AS groupName</otherwise>
96 96
             </choose>,
97
-            IFNULL(SUM(item_quantity), 0) AS seizeNum
97
+            IFNULL(SUM(item_quantity), 0) AS seizeQuantity
98 98
         FROM ledger_seizure_stats
99 99
         <where>
100 100
             <include refid="FILTER_FIXED_DATE_CRITERIA_SQL"/>
@@ -102,9 +102,9 @@
102 102
         <!-- 动态分组:重点!全为空时仅按日期分组 -->
103 103
         GROUP BY
104 104
             <choose>
105
-                <when test="groupId != null">group_id, record_date</when>
106
-                <when test="teamId != null">team_id, record_date</when>
107
-                <when test="deptId != null">dept_id, record_date</when>
105
+                <when test="groupId != null">group_id, record_date, group_name</when>
106
+                <when test="teamId != null">team_id, record_date, team_name</when>
107
+                <when test="deptId != null">dept_id, record_date, dept_name</when>
108 108
                 <otherwise>record_date</otherwise>
109 109
             </choose>
110 110
         ORDER BY record_date ASC
@@ -121,7 +121,7 @@
121 121
                 <when test="deptId != null">team_name AS groupName</when>
122 122
                 <otherwise>dept_name AS groupName</otherwise>
123 123
             </choose>,
124
-            IFNULL(SUM(item_quantity), 0) AS seizeNum
124
+            IFNULL(SUM(item_quantity), 0) AS seizeQuantity
125 125
         FROM ledger_seizure_stats
126 126
         <where>
127 127
             <include refid="FILTER_FIXED_DATE_CRITERIA_SQL"/>
@@ -129,10 +129,10 @@
129 129
         <!-- 动态分组,严格层级下钻 -->
130 130
         GROUP BY
131 131
             <choose>
132
-                <when test="groupId != null">inspector_id, record_date</when>
133
-                <when test="teamId != null">group_id, record_date</when>
134
-                <when test="deptId != null">team_id, record_date</when>
135
-                <otherwise>dept_id, record_date</otherwise>
132
+                <when test="groupId != null">inspector_id, record_date, inspector_name</when>
133
+                <when test="teamId != null">group_id, record_date, group_name</when>
134
+                <when test="deptId != null">team_id, record_date, team_name</when>
135
+                <otherwise>dept_id, record_date, dept_name</otherwise>
136 136
             </choose>
137 137
         ORDER BY record_date ASC
138 138
     </select>