Commit b20d6411 by 林永健

fix(analysis): 修复门店权限及指标查询异常处理

- 在获取门店权限方法中添加空权限抛出异常处理
- regionalDistribution方法中添加权限获取异常捕获,避免异常抛出影响调用
- 调整查询指标为空时的日志级别为warn,防止误判日志严重性
- 优化数据分组逻辑,保证空数据时初始化空集合
- 修改查询区域方法调用参数,避免使用错误的商户ID集合
- 修正门店数量统计顺序,保证统计准确性
- touchRateSummary方法中改用请求参数中的商户ID列表,统一权限处理逻辑
- 增加获取区域失败的错误日志记录,提升异常监控能力
1 parent 2940e30b
...@@ -188,6 +188,10 @@ public class BusinessSceneAnalysisService { ...@@ -188,6 +188,10 @@ public class BusinessSceneAnalysisService {
merchantIds = merchantIds.stream().filter(p -> req.getExcludeIds().contains(p)).collect(Collectors.toList()); merchantIds = merchantIds.stream().filter(p -> req.getExcludeIds().contains(p)).collect(Collectors.toList());
log.info("查询指标[{}]门店权限, 屏蔽:{}:{}", itemCode, req.getExcludeIds(), merchantIds); log.info("查询指标[{}]门店权限, 屏蔽:{}:{}", itemCode, req.getExcludeIds(), merchantIds);
} }
if (CollectionUtils.isEmpty(merchantIds)) {
log.error("查询指标[{}]门店权限为空", itemCode);
throw new RpcServiceException("门店权限为空");
}
return merchantIds; return merchantIds;
} }
...@@ -938,27 +942,34 @@ public class BusinessSceneAnalysisService { ...@@ -938,27 +942,34 @@ public class BusinessSceneAnalysisService {
public List<RegionalDistributionResponse> regionalDistribution(SceneBaseReq req) { public List<RegionalDistributionResponse> regionalDistribution(SceneBaseReq req) {
List<RegionalDistributionResponse> res = new ArrayList<>(); List<RegionalDistributionResponse> res = new ArrayList<>();
try {
req.setMerchantIds(getMerchantIdPermission(req, false));
}catch (Exception e){
return res;
}
// 查询指标 // 查询指标
DataBizQueryParamsDTO queryParams = req.convertQueryParam(); DataBizQueryParamsDTO queryParams = req.convertQueryParam();
queryParams.setBrandIds(dataStatsConfig.defaultBrandId); queryParams.setBrandIds(dataStatsConfig.defaultBrandId);
queryParams.setExts("merchantIds"); queryParams.setExts("merchantIds");
queryParams.setItemCodes(DataStatsConstants.ITEM_CODE_A062); queryParams.setItemCodes(DataStatsConstants.ITEM_CODE_A062);
Map<Integer, List<DataBusinessDTO>> dataMerchantMap;
DataResp<List<DataBusinessDTO>> dataResp = getDataStatsService.getListDataResp(JSON.toJSONString(queryParams)); DataResp<List<DataBusinessDTO>> dataResp = getDataStatsService.getListDataResp(JSON.toJSONString(queryParams));
if (CollectionUtils.isEmpty(dataResp.getContent())) { if (CollectionUtils.isEmpty(dataResp.getContent())) {
log.info("查询指标返回空, req:{}, res:{}", queryParams, dataResp); log.warn("查询指标返回空, req:{}, res:{}", queryParams, dataResp);
return res; dataMerchantMap = new HashMap<>();
} }else {
List<DataBusinessDTO> dataList = dataResp.getContent(); List<DataBusinessDTO> dataList = dataResp.getContent();
if (CollectionUtils.isNotEmpty(req.getExcludeIds())) { if (CollectionUtils.isNotEmpty(req.getExcludeIds())) {
dataList = dataList.stream() dataList = dataList.stream()
.filter(p -> !req.getExcludeIds().contains(p.getMerchantId())) .filter(p -> !req.getExcludeIds().contains(p.getMerchantId()))
.collect(Collectors.toList()); .collect(Collectors.toList());
}
dataMerchantMap = dataList.stream().collect(Collectors.groupingBy(p -> p.getMerchantId()));
} }
Map<Integer, List<DataBusinessDTO>> dataMerchantMap = dataList.stream()
.collect(Collectors.groupingBy(p -> p.getMerchantId()));
// 查询区域 // 查询区域
List<MerchantProvinceDTO> provinceList = businessAnalysisService.getProvinceByMerchantIdConcurrent(new ArrayList<>(dataMerchantMap.keySet())); List<MerchantProvinceDTO> provinceList = businessAnalysisService.getProvinceByMerchantIdConcurrent(new ArrayList<>(req.getMerchantIds()));
if (CollectionUtils.isEmpty(provinceList)) { if (CollectionUtils.isEmpty(provinceList)) {
log.info("查询区域返回空, req:{}, res:{}", queryParams, provinceList); log.info("查询区域返回空, req:{}, res:{}", queryParams, provinceList);
return res; return res;
...@@ -974,6 +985,7 @@ public class BusinessSceneAnalysisService { ...@@ -974,6 +985,7 @@ public class BusinessSceneAnalysisService {
int storeCount = 0; int storeCount = 0;
BigDecimal itemVal = BigDecimal.ZERO; BigDecimal itemVal = BigDecimal.ZERO;
for (MerchantProvinceDTO p : merchants) { for (MerchantProvinceDTO p : merchants) {
storeCount++;
if (!dataMerchantMap.containsKey(p.getMerchantId())) { if (!dataMerchantMap.containsKey(p.getMerchantId())) {
continue; continue;
} }
...@@ -983,7 +995,6 @@ public class BusinessSceneAnalysisService { ...@@ -983,7 +995,6 @@ public class BusinessSceneAnalysisService {
continue; continue;
} }
itemVal = itemVal.add(data.getItemValue()); itemVal = itemVal.add(data.getItemValue());
storeCount++;
} }
item.setDeliveryCount(itemVal); item.setDeliveryCount(itemVal);
item.setStoreCount(storeCount); item.setStoreCount(storeCount);
...@@ -1061,15 +1072,14 @@ public class BusinessSceneAnalysisService { ...@@ -1061,15 +1072,14 @@ public class BusinessSceneAnalysisService {
*/ */
public List<ContactRateAnalysisResponse> touchRateSummary(SceneBaseReq req) { public List<ContactRateAnalysisResponse> touchRateSummary(SceneBaseReq req) {
List<ContactRateAnalysisResponse> res = new ArrayList<>(); List<ContactRateAnalysisResponse> res = new ArrayList<>();
List<Integer> merchantIds;
try { try {
merchantIds = getMerchantIdPermission(req, DataStatsConstants.ITEM_CODE_A064, false); req.setMerchantIds(getMerchantIdPermission(req, false));
}catch (Exception e){ }catch (Exception e){
return res; return res;
} }
// 查询区域 // 查询区域
RpcResponse<List<MerchantProvinceDTO>> merchantProvinceListByIds = merchantRemote.findMerchantProvinceListByIds(merchantIds); RpcResponse<List<MerchantProvinceDTO>> merchantProvinceListByIds = merchantRemote.findMerchantProvinceListByIds(req.getMerchantIds());
if (merchantProvinceListByIds.isFailed()) { if (merchantProvinceListByIds.isFailed()) {
log.error("查询区域异常, req: {}, res: {}", req, merchantProvinceListByIds); log.error("查询区域异常, req: {}, res: {}", req, merchantProvinceListByIds);
return res; return res;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!