MallDataStatisticsConsumer.java
15.6 KB
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package com.viontech.keliu.consumer;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.viontech.keliu.constants.KafkaConstants;
import com.viontech.keliu.entity.MallDataStatisticsInfo;
import com.viontech.keliu.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.common.TopicPartition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
@Service
@Slf4j
public class MallDataStatisticsConsumer {
@Autowired
private ObjectMapper objectMapper;
@Value("${vion.consumer.storeDataStatistics.reidUrl:}")
private String reidUrl;
private ExecutorService executorService = ThreadUtil.newFixedExecutor(15, 5000, "dataStatistics-", true);
@KafkaListener(topics = KafkaConstants.STORE_DATA_STATISTICS_TOPIC
, autoStartup = "${vion.consumer.storeDataStatistics.autoStartup:false}"
, groupId = "StoreDataStiatistics"
, concurrency = "${vion.consumer.storeDataStatistics.concurrency:1}")
public void consumerMallZoneMinuteCount(List<ConsumerRecord<String, String>> recordList, Consumer<?, ?> consumer) {
if (CollectionUtils.isEmpty(recordList)) {
return;
}
try {
Map<String, List<ConsumerRecord<String, String>>> topicPartitionDataMap = recordList.stream().collect(Collectors.groupingBy(d -> d.topic() + "-" + d.partition()));
for (Map.Entry<String, List<ConsumerRecord<String, String>>> entry : topicPartitionDataMap.entrySet()) {
try {
long startTime = System.currentTimeMillis();
List<ConsumerRecord<String, String>> recordValues = entry.getValue();
if (!CollectionUtils.isEmpty(recordValues)) {
for (ConsumerRecord<String, String> consumerRecord : recordValues) {
try {
MallDataStatisticsInfo mallDataStatisticsInfo = objectMapper.readValue(consumerRecord.value(), MallDataStatisticsInfo.class);
executorService.execute(() -> {
log.info("处理storeDataStatisticsInfo,mallId:{},countDate:{}, 开始", mallDataStatisticsInfo.getMallId(), mallDataStatisticsInfo.getCountDate());
execDataStatistics(mallDataStatisticsInfo);
});
} catch (Exception ee) {
log.error("处理storeDataStatisticsInfo[{}], JsonDeserializerThrowable={}", entry.getKey(), ee.getMessage(), ee);
}
// 提交Offset
Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>();
offsets.put(
new TopicPartition(consumerRecord.topic(), consumerRecord.partition()),
new OffsetAndMetadata(consumerRecord.offset() + 1) // 提交下一条偏移量
);
consumer.commitSync(offsets);
}
}
log.info("处理storeDataStatisticsInfo[{}], batchHandle耗时:{} ms", entry.getKey(), System.currentTimeMillis() - startTime);
} catch (Throwable e) {
log.error("处理storeDataStatisticsInfo[{}], Throwable={}", entry.getKey(), e.getMessage(), e);
}
}
} catch (Throwable exx) {
log.error("处理mallDataStatisticsInfo.Throwable={}", exx.getMessage(), exx);
}
}
private void execDataStatistics(MallDataStatisticsInfo mallDataStatisticsInfo) {
if (mallDataStatisticsInfo.getMallId() == null || mallDataStatisticsInfo.getCountDate() == null) {
log.info("数据处理错误:mallId={}, countDate={}", mallDataStatisticsInfo.getMallId(), mallDataStatisticsInfo.getCountDate());
return;
}
if (reidUrl.isEmpty()) {
log.info("数据处理错误:reidUrl is null: {}", reidUrl);
return;
}
log.info("开始执行mallId:{} ,countDate:{} 统计任务", mallDataStatisticsInfo.getMallId(), mallDataStatisticsInfo.getCountDate());
String date = DateUtil.format(mallDataStatisticsInfo.getCountDate(), "yyyy-MM-dd");
String url = reidUrl + "/reid/tool/residenceByMall?mallId=" + mallDataStatisticsInfo.getMallId() + "&countDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 平均滞留时间 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("平均滞留时间计算异常:{}", url, e);
}
url = reidUrl + "/reid/tool/faceResidence?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 滞留时间 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("滞留时间计算异常:{}", url, e);
}
url = reidUrl + "/reid/tool/onlyAcrossCustomer/reCall?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 穿堂客流统计 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("穿堂客流计算异常:{}", url, e);
}
url = reidUrl + "/reid/tool/dataStat/reCallOne?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 客流数据重汇 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("客流数据重汇异常:{}", url, e);
}
url = reidUrl + "/reid/tool/faceRecognition/aggregation?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 监控点进入人次统计 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("监控点进入人次统计异常:{}", url, e);
}
url = reidUrl + "/reid/tool/gateFaceResidence?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 区域滞留时间 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("区域滞留时间异常:{}", url, e);
}
url = reidUrl + "/reid/tool/cashier?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 收银区域客流 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("收银区域客流异常:{}", url, e);
}
url = reidUrl + "/reid/tool/customerGroup/reCall?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 顾客组数 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("顾客组数计算异常:{}", url, e);
}
url = reidUrl + "/reid/tool/personRecord/reCall?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 接待分析统计 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("接待分析统计异常:{}", url, e);
}
url = reidUrl + "/reid/tool/deepNum?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 深逛人数统计 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("深逛人数统计异常:{}", url, e);
}
url = reidUrl + "/reid/tool/heatmap/merge?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 每日热力数据聚合 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("每日热力数据聚合异常:{}", url, e);
}
url = reidUrl + "/reid/tool/dataMonitor/reCall?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 数据运维 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("数据运维异常:{}", url, e);
}
url = reidUrl + "/reid/tool/mallCompare/reCall?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 跨店比对 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("跨店比对异常:{}", url, e);
}
url = reidUrl + "/reid/tool/kafkaPersonReception/resend?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 接待数据发送kafka 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("接待数据发送kafka异常:{}", url, e);
}
url = reidUrl + "/reid/tool/restaurant/countData?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 餐厅排队指标统计 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("餐厅排队指标统计异常:{}", url, e);
}
url = reidUrl + "/reid/tool/channelProduct/countData?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 机位数据统计 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("机位数据统计异常:{}", url, e);
}
url = reidUrl + "/reid/tool/mallProduct/countData?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 商品数据统计 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("商品数据统计异常:{}", url, e);
}
url = reidUrl + "/reid/tool/mallProductGate/countData?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 商品分区数据统计 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("商品分区数据统计异常:{}", url, e);
}
url = reidUrl + "/reid/tool/gateFlowDirection?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 门店分区客流流向 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("门店分区客流流向异常:{}", url, e);
}
url = reidUrl + "/reid/tool/mallBusinessRecord?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 门店营业时间统计任务 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("门店营业时间统计任务异常:{}", url, e);
}
url = reidUrl + "/reid/tool/mallResidenceDistribution?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 门店停留时长分布 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("门店停留时长分布异常:{}", url, e);
}
url = reidUrl + "/reid/tool/effectVisitors/update?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 门店有效顾客统计 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("门店有效顾客统计异常:{}", url, e);
}
url = reidUrl + "/reid/tool/visitorsMovingLing?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 顾客店内分区轨迹 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("顾客店内分区轨迹异常:{}", url, e);
}
url = reidUrl + "/reid/tool/fittingVisitors?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 试衣顾客统计 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("试衣顾客统计异常:{}", url, e);
}
url = reidUrl + "/reid/tool/attentionPassersby?mallIds=" + mallDataStatisticsInfo.getMallId() + "&startDate=" + date + "&endDate=" + date;
try {
String result = HttpUtil.get(url);
log.info("调用mallId:{} 过店关注人次 执行结果:{}", mallDataStatisticsInfo.getMallId(), result);
} catch (Exception e) {
log.error("过店关注人次异常:{}", url, e);
}
}
}