MerchantAnalysisController.java
24.7 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
package cn.com.glsx.dj.strategy.controller;
import cn.com.glsx.dj.mindworkplate.dto.monitoring.MonitorFilterRequest;
import cn.com.glsx.dj.mindworkplate.dto.monitoring.StoreItemResponse;
import cn.com.glsx.dj.mindworkplate.dto.warning.EarlyWarningThresholdConfigHistoryDTO;
import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdConfig;
import cn.com.glsx.dj.mindworkplate.model.MonitorTypeDict;
import cn.com.glsx.dj.mindworkplate.remote.EarlyWarningMsgRemote;
import cn.com.glsx.dj.mindworkplate.remote.MonitoringRemote;
import cn.com.glsx.dj.mindworkplate.remote.WarningMsgRemote;
import cn.com.glsx.dj.peanalysis.dto.req.output.SceneBaseReq;
import cn.com.glsx.dj.peanalysis.dto.res.output.EmployeeDetailSummaryResponse;
import cn.com.glsx.dj.peanalysis.dto.res.output.GoodsCategorySummaryResponse;
import cn.com.glsx.dj.peanalysis.dto.res.output.StoreDetailSummaryResponse;
import cn.com.glsx.dj.peanalysis.dto.strategy.StaffAnalysisDTO;
import cn.com.glsx.dj.peanalysis.remote.BusinessSceneAnalysisRemote;
import cn.com.glsx.dj.smartcarlife.dto.merchant.CarBrandDTO;
import cn.com.glsx.dj.strategy.dto.OperatorResponse;
import cn.com.glsx.dj.strategy.dto.SceneMerchantBaseParam;
import cn.com.glsx.dj.strategy.dto.StaffHistoryRecordDTO;
import cn.com.glsx.dj.strategy.dto.StaffSummaryDTO;
import cn.com.glsx.dj.strategy.dto.warning.WarningRecordDTO;
import cn.com.glsx.dj.strategy.dto.warning.WarningRecordQueryRequest;
import cn.com.glsx.dj.strategy.remote.StrategyInfoRemote;
import cn.com.glsx.dj.strategy.remote.WarningEngineRemote;
import cn.com.glsx.dj.strategy.request.MerchantStaffHistoryRecordRequest;
import cn.com.glsx.dj.strategy.request.MonitorDictRopRequest;
import cn.com.glsx.dj.strategy.request.MonitorFilterRopRequest;
import cn.com.glsx.dj.strategy.request.SceneMerchantBaseRequest;
import cn.com.glsx.dj.strategy.response.MerchantDetailResponse;
import cn.com.glsx.dj.strategy.service.LoginService;
import cn.com.glsx.dj.strategy.service.StrategyDetailService;
import cn.com.glsx.dj.strategy.uitl.CommonUtil;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.com.glsx.merchants.model.response.merchant.MerchantBasicInfoListResponse;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import javax.annotation.Resource;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Slf4j
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
@Api("策略中心-门店看板")
public class MerchantAnalysisController {
@Autowired
private BusinessSceneAnalysisRemote businessSceneAnalysisRemote;
@Autowired
private StrategyInfoRemote strategyInfoRemote;
@Autowired
private MonitoringRemote monitoringRemote;
@Autowired
private LoginService loginService;
@Autowired
private EarlyWarningMsgRemote earlyWarningMsgRemote;
@Autowired
private Environment environment;
@Autowired
private StrategyDetailService strategyDetailService;
@Resource
private WarningMsgRemote warningMsgRemote;
@Resource
private WarningEngineRemote warningEngineRemote;
@ApiOperation("查询驻店员工列表")
@ServiceMethod(method = "dj.api.strategy.staff.list.analysis")
public RopResponse<List<StaffAnalysisDTO>> listStaffAnalysis(SceneMerchantBaseRequest request) {
try {
SceneBaseReq req = CommonUtil.convertRequest(SceneBaseReq.class);
RpcResponse<List<StaffAnalysisDTO>> response = businessSceneAnalysisRemote.listStaffAnalysis(req);
if (response.hasError()) {
log.error(response.getMessage());
return RopResponse.error(response.getError(), response.getMessage());
}
return RopResponse.success(response.getResult());
} catch (RpcServiceException e) {
log.error("=====dj.api.strategy.staff.list.analysis rpcServiceException:{}", e.getMessage());
return RopResponse.error(e);
} catch (Exception e) {
log.error("=====dj.api.strategy.staff.list.analysis exception:{}", e.getMessage(), e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("查询门店预警信息列表")
@ServiceMethod(method = "dj.api.strategy.merchant.list.warningInfo")
public RopResponse<List<WarningRecordDTO>> listMerchantWarningInfo(SceneMerchantBaseRequest request) {
try {
WarningRecordQueryRequest queryRequest = new WarningRecordQueryRequest();
// 1.1 bizs -> businessType
queryRequest.setBusinessType(request.getBizs());
// 1.2 时间维度映射:自定义直接返回空列表;cycleType 2=周(W), 3=月(M)
Integer cycleType = request.getCycleType();
if (cycleType != null && cycleType == 4) {
return RopResponse.success(Collections.emptyList());
}
if (cycleType != null) {
if (cycleType == 2) {
queryRequest.setTimeDimension("W");
} else if (cycleType == 3) {
queryRequest.setTimeDimension("M");
}
}
// 1.3 开始/结束日期
queryRequest.setStartDate(request.getStartTime());
queryRequest.setEndDate(request.getEndTime());
// 1.4 monitorTarget=2(门店)
queryRequest.setMonitorTarget(2);
// 1.5 门店号取第一个
if (CollectionUtils.isNotEmpty(request.getMerchantIds())) {
queryRequest.setStoreId(request.getMerchantIds().get(0));
}
RpcResponse<List<WarningRecordDTO>> response = warningEngineRemote.findWarningDetailByStoreAndStaff(queryRequest);
if (response.hasError()) {
log.error(response.getMessage());
return RopResponse.error(response.getError(), response.getMessage());
}
return RopResponse.success(response.getResult());
} catch (RpcServiceException e) {
log.error("=====dj.api.strategy.merchant.list.warningInfo rpcServiceException:{}", e.getMessage());
return RopResponse.error(e);
} catch (Exception e) {
log.error("=====dj.api.strategy.merchant.list.warningInfo exception:{}", e.getMessage(), e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("查询驻店员工时长信息")
@ServiceMethod(method = "dj.api.strategy.staff.summary.duration")
public RopResponse<StaffSummaryDTO> summaryStaffDuration(SceneMerchantBaseRequest request) {
try {
SceneMerchantBaseParam req = CommonUtil.convertRequest(SceneMerchantBaseParam.class);
RpcResponse<StaffSummaryDTO> response = strategyInfoRemote.summaryStaffDuration(req);
if (response.hasError()) {
log.error(response.getMessage());
return RopResponse.error(response.getError(), response.getMessage());
}
return RopResponse.success(response.getResult());
} catch (RpcServiceException e) {
log.error("=====dj.api.strategy.staff.list.analysis rpcServiceException:{}", e.getMessage());
return RopResponse.error(e);
} catch (Exception e) {
log.error("=====dj.api.strategy.staff.list.analysis exception:{}", e.getMessage(), e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("策略中心-门店分析-门店经营概况")
@ServiceMethod(method = "dj.api.strategy.merchant.analysis.store.detail.summary", needInSession = NeedInSessionType.YES)
public RopResponse<StoreDetailSummaryResponse> merchantDetailSummary(SceneMerchantBaseRequest request) {
try {
SceneBaseReq req = CommonUtil.convertRequest(SceneBaseReq.class);
RpcResponse<StoreDetailSummaryResponse> response = businessSceneAnalysisRemote.storeDetailSummary(req);
if (response.isSuccess()) {
return RopResponse.success(response.getResult());
}
return RopResponse.error(response.getMessage());
} catch (Exception e) {
log.error("接口异常", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("策略中心-门店商品品类分析")
@ServiceMethod(method = "dj.api.strategy.merchant.analysis.goods.summary.withWarn", needInSession = NeedInSessionType.YES)
public RopResponse<GoodsCategorySummaryResponse> merchantGoodsSummaryWithWarm(SceneMerchantBaseRequest request) {
try {
SceneBaseReq req = CommonUtil.convertRequest(SceneBaseReq.class);
RpcResponse<GoodsCategorySummaryResponse> response = businessSceneAnalysisRemote.goodsSummary(req);
if (response.isSuccess()) {
GoodsCategorySummaryResponse result = Optional.ofNullable(response.getResult()).orElse(new GoodsCategorySummaryResponse());
// 处理兜底指标
Optional.ofNullable(req.getMerchantIds())
.filter(CollUtil::isNotEmpty)
.flatMap(list -> Optional.ofNullable(list.get(0)).map(ObjectUtil::toString))
.filter(StrUtil::isNotEmpty)
.ifPresent(merchantId -> {
RpcResponse<EarlyWarningThresholdConfig> warningConfigRes = warningMsgRemote.findByMerchantNo(merchantId);
if (!warningConfigRes.hasResult()) {
log.error("兜底预警目标配置查询异常: {}", warningConfigRes);
return;
}
EarlyWarningThresholdConfig warningConfig = warningConfigRes.getResult();
// 电池转化率
result.setBatteryWarrantyConversionBottomTarget(warningConfig.getBatteryConversionRate());
// 电池渗透率
result.setBatteryWarrantyPenetrationBottomTarget(warningConfig.getBatteryPenetrationRate());
// 延保转化率
result.setVehicleWarrantyConversionBottomTarget(warningConfig.getEwConRate());
// 延保渗透率
result.setVehicleWarrantyPenetrationBottomTarget(warningConfig.getEwPenetrationRate());
// 延保安心包转化率
result.setSafetyPackageConversionBottomTarget(warningConfig.getEwAxbConRate());
// 安心包渗透率
result.setSafetyPackagePenetrationBottomTarget(warningConfig.getEwAxbPenetrationRate());
// 延保轮胎转化率
result.setTireWarrantyConversionBottomTarget(warningConfig.getEwLtConRate());
// 轮胎渗透率
result.setTireWarrantyPenetrationBottomTarget(warningConfig.getEwLtPenetrationRate());
});
return RopResponse.success(result);
}
return RopResponse.error(response.getMessage());
} catch (Exception e) {
log.error("接口异常", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("策略中心-门店分析-驻店员工分析")
@ServiceMethod(method = "dj.api.strategy.merchant.analysis.employee.summary", needInSession = NeedInSessionType.YES)
public RopResponse<EmployeeDetailSummaryResponse> storeEmployeeSummary(SceneMerchantBaseRequest request) {
try {
SceneBaseReq req = CommonUtil.convertRequest(SceneBaseReq.class);
req.setExts("staffIds");
RpcResponse<EmployeeDetailSummaryResponse> response = businessSceneAnalysisRemote.storeEmployeeSummary(req);
if (response.isSuccess()) {
return RopResponse.success(response.getResult());
}
return RopResponse.error(response.getMessage());
} catch (Exception e) {
log.error("接口异常", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("策略中心-预警指标树")
@ServiceMethod(method = "dj.api.strategy.monitor.findMonitorTypeDictList", needInSession = NeedInSessionType.YES)
public RopResponse<List<MonitorTypeDict>> findMonitorTypeDictList(MonitorDictRopRequest request) {
try {
RpcResponse<List<MonitorTypeDict>> response = monitoringRemote.findMonitorTypeDictList(request.getBusinessType());
if (response.isSuccess()) {
return RopResponse.success(response.getResult());
}
return RopResponse.error(response.getMessage());
} catch (Exception e) {
log.error("接口异常", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("策略中心-查询预警信息")
@ServiceMethod(method = "dj.api.strategy.monitor.findMonitorListPage", needInSession = NeedInSessionType.YES)
public RopResponse<List<StoreItemResponse>> findMonitorListPage(MonitorFilterRopRequest request) {
try {
MonitorFilterRequest req = CommonUtil.convertRequest(MonitorFilterRequest.class);
RpcResponse<List<StoreItemResponse>> response = monitoringRemote.findMonitorListPage(req);
if (response.isSuccess()) {
List<StoreItemResponse> result = response.getResult();
if (CollectionUtils.isNotEmpty( result)){
List<Integer> collect = result.stream().map(StoreItemResponse::getMerchantNo).map(Integer::valueOf)
.collect(Collectors.toList());
List<MerchantDetailResponse> responses = strategyDetailService.findMerchantDetail(
collect, request.getBusinessType()+ "");
for (StoreItemResponse itemResponse : result) {
MerchantDetailResponse merchantDetailResponse = responses.stream().filter(detailResponse -> (detailResponse.getMerchantNo()+"").equals(itemResponse.getMerchantNo())).findFirst().orElse(null);
if (merchantDetailResponse != null) {
itemResponse.setMainBrands(
merchantDetailResponse.getCarBrandResponses().stream()
// 1. 过滤掉 null 的 CarBrandDTO
.filter(Objects::nonNull)
// 2. 过滤掉 id 为 null 的(避免 toMap 报错)
.filter(carBrand -> carBrand.getId() != null)
.collect(Collectors.toMap(
CarBrandDTO::getId, // 按 id 去重(唯一标识)
Function.identity(),
(existing, replacement) -> existing, // 保留第一个
LinkedHashMap::new
))
.values()
.stream()
.flatMap(parent ->
(parent.getChildren() != null && !parent.getChildren().isEmpty())
? parent.getChildren().stream()
.map(child -> parent.getLabel() + "-" + child.getLabel())
: Stream.of(parent.getLabel())
)
.collect(Collectors.joining("/"))
);
itemResponse.setOnlineOperators(merchantDetailResponse.getOnlineOperator().stream().map(
OperatorResponse::getUsername).collect(
Collectors.joining("/")));
itemResponse.setRegionalOperators(merchantDetailResponse.getAreaOperator().stream().map(
OperatorResponse::getUsername).collect(
Collectors.joining("/")));
}
}
}
return RopResponse.success(response.getResult());
}
return RopResponse.error(response.getMessage());
} catch (Exception e) {
log.error("接口异常", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("策略中心-门店分析-历史人员记录")
@ServiceMethod(method = "dj.api.strategy.merchant.analysis.employee.history", needInSession = NeedInSessionType.YES)
public RopResponse<List<StaffHistoryRecordDTO>> merchantAnalysisEmployeeHistory(MerchantStaffHistoryRecordRequest request) {
try {
RpcResponse<List<StaffHistoryRecordDTO>> response = strategyInfoRemote.listMerchantAnalysisEmployeeHistory(request.getMerchantId(), request.getBizs());
if (response.isSuccess()) {
return RopResponse.success(response.getResult());
}
return RopResponse.error(response.getMessage());
} catch (RpcServiceException e) {
log.error("=====dj.api.strategy.merchant.analysis.employee.history rpcServiceException:{}", e.getMessage());
return RopResponse.error(e);
} catch (Exception e) {
log.error("=====dj.api.strategy.merchant.analysis.employee.history exception:{}", e.getMessage(), e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("策略中心-门店分析-历史兜底指标")
@ServiceMethod(method = "dj.api.strategy.merchant.analysis.index.history", needInSession = NeedInSessionType.YES)
public RopResponse<List<EarlyWarningThresholdConfigHistoryDTO>> merchantAnalysisIndexHistory(MerchantStaffHistoryRecordRequest request) {
try {
RpcResponse<List<EarlyWarningThresholdConfigHistoryDTO>> response = earlyWarningMsgRemote.listMerchantAnalysisIndexHistory(request.getMerchantId().toString());
if (response.isSuccess()) {
return RopResponse.success(response.getResult());
}
return RopResponse.error(response.getMessage());
} catch (RpcServiceException e) {
log.error("=====dj.api.strategy.merchant.analysis.index.history rpcServiceException:{}", e.getMessage());
return RopResponse.error(e);
} catch (Exception e) {
log.error("=====dj.api.strategy.merchant.analysis.index.history exception:{}", e.getMessage(), e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("延保/权益/轻改-查询门店是否鸿蒙")
@ServiceMethod(method = "dj.api.strategy.business.analysis.store.special.brand", needInSession = NeedInSessionType.NO)
public RopResponse<Boolean> isHarmonyStore(SceneMerchantBaseRequest request) {
try {
RpcAssert.assertNotNull(request.getMerchantIds(), DefaultErrorEnum.SERVICE_ERROR, "门店参数不能为空");
List<MerchantBasicInfoListResponse> merchant = loginService.findMerchant(request.getMerchantIds(), null);
if (CollectionUtils.isEmpty(merchant)) {
log.warn("查询门店信息返回空");
return RopResponse.success(false);
}
List<Integer> merchantIds = merchant.stream().map(p -> p.getMerchantId()).collect(Collectors.toList());
List<String> brandIds = merchant.stream()
.map(p -> p.getMerchantBrandCars())
.filter(StringUtils::isNotBlank)
.flatMap(p -> Arrays.stream(p.split(";")))
.flatMap(p -> Arrays.stream(p.split(",")))
.collect(Collectors.toList());
log.info("merchant.id: {}, brandIds: {}", merchantIds, brandIds);
String harmonyBrandId = environment.getProperty("dj.pe.analysis.business.scene.harmony.brandId", String.class, "2978");
return RopResponse.success(brandIds.contains(harmonyBrandId));
} catch (Exception e) {
log.error("接口异常", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("策略中心-门店分析-门店经营概况-主机厂")
@ServiceMethod(method = "dj.api.strategy.merchant.analysis.store.detail.zjsummary", needInSession = NeedInSessionType.YES)
public RopResponse<StoreDetailSummaryResponse> merchantDetailSummaryZJ(SceneMerchantBaseRequest request) {
try {
SceneBaseReq req = CommonUtil.convertRequest(SceneBaseReq.class);
RpcResponse<StoreDetailSummaryResponse> response = businessSceneAnalysisRemote.storeDetailSummaryZj(req);
if (response.isSuccess()) {
return RopResponse.success(response.getResult());
}
return RopResponse.error(response.getMessage());
} catch (Exception e) {
log.error("接口异常", e);
return RopResponse.error(e.getMessage());
}
}
@ApiOperation("策略中心-门店商品品类分析-主机厂")
@ServiceMethod(method = "dj.api.strategy.merchant.analysis.goods.summary.withWarnZJ", needInSession = NeedInSessionType.YES)
public RopResponse<GoodsCategorySummaryResponse> merchantGoodsSummaryWithWarmZJ(SceneMerchantBaseRequest request) {
try {
SceneBaseReq req = CommonUtil.convertRequest(SceneBaseReq.class);
// 调用主机厂版方法,交付数从目标配置表获取
RpcResponse<GoodsCategorySummaryResponse> response = businessSceneAnalysisRemote.goodsSummaryZj(req);
if (response.isSuccess()) {
GoodsCategorySummaryResponse result = Optional.ofNullable(response.getResult()).orElse(new GoodsCategorySummaryResponse());
// 处理兜底指标
Optional.ofNullable(req.getMerchantIds())
.filter(CollUtil::isNotEmpty)
.flatMap(list -> Optional.ofNullable(list.get(0)).map(ObjectUtil::toString))
.filter(StrUtil::isNotEmpty)
.ifPresent(merchantId -> {
RpcResponse<EarlyWarningThresholdConfig> warningConfigRes = warningMsgRemote.findByMerchantNo(merchantId);
if (!warningConfigRes.hasResult()) {
log.error("兜底预警目标配置查询异常: {}", warningConfigRes);
return;
}
EarlyWarningThresholdConfig warningConfig = warningConfigRes.getResult();
// 电池转化率
result.setBatteryWarrantyConversionBottomTarget(warningConfig.getBatteryConversionRate());
// 电池渗透率
result.setBatteryWarrantyPenetrationBottomTarget(warningConfig.getBatteryPenetrationRate());
// 延保转化率
result.setVehicleWarrantyConversionBottomTarget(warningConfig.getEwConRate());
// 延保渗透率
result.setVehicleWarrantyPenetrationBottomTarget(warningConfig.getEwPenetrationRate());
// 延保安心包转化率
result.setSafetyPackageConversionBottomTarget(warningConfig.getEwAxbConRate());
// 安心包渗透率
result.setSafetyPackagePenetrationBottomTarget(warningConfig.getEwAxbPenetrationRate());
// 延保轮胎转化率
result.setTireWarrantyConversionBottomTarget(warningConfig.getEwLtConRate());
// 轮胎渗透率
result.setTireWarrantyPenetrationBottomTarget(warningConfig.getEwLtPenetrationRate());
});
return RopResponse.success(result);
}
return RopResponse.error(response.getMessage());
} catch (Exception e) {
log.error("接口异常", e);
return RopResponse.error(e.getMessage());
}
}
}