Przeglądaj źródła

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

sunpanhu 3 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
 package com.sundot.airport.ledger.domain.vo;
1
 package com.sundot.airport.ledger.domain.vo;
2
 
2
 
3
+import com.fasterxml.jackson.annotation.JsonFormat;
3
 import lombok.Data;
4
 import lombok.Data;
4
 
5
 
5
 import java.io.Serializable;
6
 import java.io.Serializable;
@@ -16,6 +17,7 @@ public class CountSeizureSingleQuantityResVO implements Serializable {
16
     /**
17
     /**
17
      * 日期(X轴)
18
      * 日期(X轴)
18
      */
19
      */
20
+    @JsonFormat(pattern = "yyyy-MM-dd")
19
     private Date recordDate;
21
     private Date recordDate;
20
     /**
22
     /**
21
      * 维度名称:员工名/小组名/班组名/部门名(每条折线)
23
      * 维度名称:员工名/小组名/班组名/部门名(每条折线)
@@ -24,5 +26,11 @@ public class CountSeizureSingleQuantityResVO implements Serializable {
24
     /**
26
     /**
25
      * 当日查获数量(Y轴)
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
 package com.sundot.airport.ledger.domain.vo;
1
 package com.sundot.airport.ledger.domain.vo;
2
 
2
 
3
+import com.fasterxml.jackson.annotation.JsonFormat;
3
 import lombok.Data;
4
 import lombok.Data;
4
 
5
 
5
 import java.io.Serializable;
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
     private Date recordDate;
21
     private Date recordDate;
20
     /**
22
     /**
21
      * 分组名称(部门/班组/小组/全量)
23
      * 分组名称(部门/班组/小组/全量)
@@ -25,4 +27,10 @@ public class CountSeizureTotalQuantityResVO implements Serializable {
25
      * 当日查获数量
27
      * 当日查获数量
26
      */
28
      */
27
     private Integer seizeQuantity;
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
 package com.sundot.airport.ledger.service.impl;
1
 package com.sundot.airport.ledger.service.impl;
2
 
2
 
3
-import java.util.Collections;
4
-import java.util.List;
5
-
6
 import cn.hutool.core.collection.CollUtil;
3
 import cn.hutool.core.collection.CollUtil;
7
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
+import com.google.common.collect.Lists;
8
 import com.sundot.airport.common.utils.DateUtils;
6
 import com.sundot.airport.common.utils.DateUtils;
9
 import com.sundot.airport.ledger.domain.LedgerSeizureStats;
7
 import com.sundot.airport.ledger.domain.LedgerSeizureStats;
10
 import com.sundot.airport.ledger.domain.vo.CountQueryReqVO;
8
 import com.sundot.airport.ledger.domain.vo.CountQueryReqVO;
11
 import com.sundot.airport.ledger.domain.vo.CountSeizureSingleQuantityResVO;
9
 import com.sundot.airport.ledger.domain.vo.CountSeizureSingleQuantityResVO;
12
 import com.sundot.airport.ledger.domain.vo.CountSeizureTotalQuantityResVO;
10
 import com.sundot.airport.ledger.domain.vo.CountSeizureTotalQuantityResVO;
11
+import com.sundot.airport.ledger.domain.vo.LaneThroughputResVO;
13
 import com.sundot.airport.ledger.domain.vo.SeizeCategoryQuantityVO;
12
 import com.sundot.airport.ledger.domain.vo.SeizeCategoryQuantityVO;
14
 import com.sundot.airport.ledger.domain.vo.SeizeItemVO;
13
 import com.sundot.airport.ledger.domain.vo.SeizeItemVO;
15
 import com.sundot.airport.ledger.domain.vo.SeizeTotalAndItemVO;
14
 import com.sundot.airport.ledger.domain.vo.SeizeTotalAndItemVO;
16
 import com.sundot.airport.ledger.domain.vo.SeizureAreaVO;
15
 import com.sundot.airport.ledger.domain.vo.SeizureAreaVO;
17
 import com.sundot.airport.ledger.mapper.LedgerSeizureStatsMapper;
16
 import com.sundot.airport.ledger.mapper.LedgerSeizureStatsMapper;
18
 import com.sundot.airport.ledger.service.ILedgerSeizureStatsService;
17
 import com.sundot.airport.ledger.service.ILedgerSeizureStatsService;
18
+import lombok.extern.slf4j.Slf4j;
19
 import org.springframework.beans.factory.annotation.Autowired;
19
 import org.springframework.beans.factory.annotation.Autowired;
20
 import org.springframework.stereotype.Service;
20
 import org.springframework.stereotype.Service;
21
 import org.springframework.transaction.annotation.Transactional;
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
  * 查获违规品统计Service实现
29
  * 查获违规品统计Service实现
25
  */
30
  */
31
+@Slf4j
26
 @Service
32
 @Service
27
 public class LedgerSeizureStatsServiceImpl extends ServiceImpl<LedgerSeizureStatsMapper, LedgerSeizureStats> implements ILedgerSeizureStatsService {
33
 public class LedgerSeizureStatsServiceImpl extends ServiceImpl<LedgerSeizureStatsMapper, LedgerSeizureStats> implements ILedgerSeizureStatsService {
28
 
34
 
@@ -54,7 +60,43 @@ public class LedgerSeizureStatsServiceImpl extends ServiceImpl<LedgerSeizureStat
54
     @Override
60
     @Override
55
     public List<CountSeizureTotalQuantityResVO> countSeizureTotalQuantity(CountQueryReqVO countQueryReq) {
61
     public List<CountSeizureTotalQuantityResVO> countSeizureTotalQuantity(CountQueryReqVO countQueryReq) {
56
         List<CountSeizureTotalQuantityResVO> seizureQuantityResList = this.baseMapper.countSeizureTotalQuantity(countQueryReq);
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
     @Override
111
     @Override
70
     public List<CountSeizureSingleQuantityResVO> countSeizureSingleQuantity(CountQueryReqVO countQueryReq) {
112
     public List<CountSeizureSingleQuantityResVO> countSeizureSingleQuantity(CountQueryReqVO countQueryReq) {
71
         List<CountSeizureSingleQuantityResVO> seizureQuantityResList = this.baseMapper.countSeizureSingleQuantity(countQueryReq);
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
                 <when test="deptId != null">dept_name AS groupName</when>
94
                 <when test="deptId != null">dept_name AS groupName</when>
95
                 <otherwise>'站' AS groupName</otherwise>
95
                 <otherwise>'站' AS groupName</otherwise>
96
             </choose>,
96
             </choose>,
97
-            IFNULL(SUM(item_quantity), 0) AS seizeNum
97
+            IFNULL(SUM(item_quantity), 0) AS seizeQuantity
98
         FROM ledger_seizure_stats
98
         FROM ledger_seizure_stats
99
         <where>
99
         <where>
100
             <include refid="FILTER_FIXED_DATE_CRITERIA_SQL"/>
100
             <include refid="FILTER_FIXED_DATE_CRITERIA_SQL"/>
@@ -102,9 +102,9 @@
102
         <!-- 动态分组:重点!全为空时仅按日期分组 -->
102
         <!-- 动态分组:重点!全为空时仅按日期分组 -->
103
         GROUP BY
103
         GROUP BY
104
             <choose>
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
                 <otherwise>record_date</otherwise>
108
                 <otherwise>record_date</otherwise>
109
             </choose>
109
             </choose>
110
         ORDER BY record_date ASC
110
         ORDER BY record_date ASC
@@ -121,7 +121,7 @@
121
                 <when test="deptId != null">team_name AS groupName</when>
121
                 <when test="deptId != null">team_name AS groupName</when>
122
                 <otherwise>dept_name AS groupName</otherwise>
122
                 <otherwise>dept_name AS groupName</otherwise>
123
             </choose>,
123
             </choose>,
124
-            IFNULL(SUM(item_quantity), 0) AS seizeNum
124
+            IFNULL(SUM(item_quantity), 0) AS seizeQuantity
125
         FROM ledger_seizure_stats
125
         FROM ledger_seizure_stats
126
         <where>
126
         <where>
127
             <include refid="FILTER_FIXED_DATE_CRITERIA_SQL"/>
127
             <include refid="FILTER_FIXED_DATE_CRITERIA_SQL"/>
@@ -129,10 +129,10 @@
129
         <!-- 动态分组,严格层级下钻 -->
129
         <!-- 动态分组,严格层级下钻 -->
130
         GROUP BY
130
         GROUP BY
131
             <choose>
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
             </choose>
136
             </choose>
137
         ORDER BY record_date ASC
137
         ORDER BY record_date ASC
138
     </select>
138
     </select>