Commit e51bcbec by zhouhaibao

Merge remote-tracking branch 'origin/v5.5.1' into v5.5.1

2 parents 493cba32 082735cd
...@@ -18,5 +18,6 @@ public interface GoodsOrderMapper extends OreMapper<GoodsOrder> { ...@@ -18,5 +18,6 @@ public interface GoodsOrderMapper extends OreMapper<GoodsOrder> {
@Param("staffUuids") List<String> staffUuids, @Param("staffUuids") List<String> staffUuids,
@Param("startDate") Date startDate, @Param("startDate") Date startDate,
@Param("endDate") Date endDate, @Param("endDate") Date endDate,
@Param("businessType") Byte businessType,
@Param("scene") Integer sceneType); @Param("scene") Integer sceneType);
} }
\ No newline at end of file \ No newline at end of file
...@@ -149,13 +149,18 @@ public class BusinessSceneAnalysisService { ...@@ -149,13 +149,18 @@ public class BusinessSceneAnalysisService {
private List<Integer> getMerchantIdPermission(SceneBaseReq req, boolean containLast) { private List<Integer> getMerchantIdPermission(SceneBaseReq req, boolean containLast) {
return getMerchantIdPermission(req, DataStatsConstants.ITEM_CODE_A036, containLast); return getMerchantIdPermission(req, DataStatsConstants.ITEM_CODE_A036, containLast);
} }
private List<Integer> getMerchantIdPermission(SceneBaseReq req, boolean containLast, boolean filterPermission) {
return getMerchantIdPermission(req, DataStatsConstants.ITEM_CODE_A036, containLast, filterPermission);
}
/** /**
* 查询指定指标数据的权限门店号列表 * 查询指定指标数据的权限门店号列表
* @param req * @param req
* @return * @return
*/ */
private List<Integer> getMerchantIdPermission(SceneBaseReq req, String itemCode, boolean containLast) { private List<Integer> getMerchantIdPermission(SceneBaseReq req, String itemCode, boolean containLast) {
return getMerchantIdPermission(req, itemCode, containLast, false);
}
private List<Integer> getMerchantIdPermission(SceneBaseReq req, String itemCode, boolean containLast, boolean filterPermission) {
DataBizQueryParamsDTO queryParams = req.convertQueryParam(); DataBizQueryParamsDTO queryParams = req.convertQueryParam();
queryParams.setBrandIds(dataStatsConfig.defaultBrandId); queryParams.setBrandIds(dataStatsConfig.defaultBrandId);
queryParams.setItemCodes(itemCode); queryParams.setItemCodes(itemCode);
...@@ -174,6 +179,11 @@ public class BusinessSceneAnalysisService { ...@@ -174,6 +179,11 @@ public class BusinessSceneAnalysisService {
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
log.info("查询指标[{}]门店权限:{}", itemCode, merchantIds); log.info("查询指标[{}]门店权限:{}", itemCode, merchantIds);
if (filterPermission) {
// 查询上个周期的,需要过滤经营品类
merchantIds = filterStoreTypeAndCategoryPermission(merchantIds, req);
log.info("查询指标[{}]门店权限, 过滤经营品类:{}", itemCode, merchantIds);
}
if (CollectionUtils.isNotEmpty(req.getExcludeIds())) { if (CollectionUtils.isNotEmpty(req.getExcludeIds())) {
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);
...@@ -181,6 +191,62 @@ public class BusinessSceneAnalysisService { ...@@ -181,6 +191,62 @@ public class BusinessSceneAnalysisService {
return merchantIds; return merchantIds;
} }
public List<Integer> filterStoreTypeAndCategoryPermission(List<Integer> merchantIdList, SceneBaseReq request) {
if(CollectionUtils.isEmpty(merchantIdList)) {
return merchantIdList;
}
if(Objects.isNull(request.getStoreType()) && Objects.isNull(request.getBusinessCategory())) {
return merchantIdList;
}
List<BiRecord> list = getBiRecords(null, merchantIdList, request.getStartTime(), request.getEndTime());
if(CollectionUtils.isEmpty(list)) {
return Collections.emptyList();
}
List<Integer> permissionList = new ArrayList<>();
Map<Integer, List<BiRecord>> groupByMerchant = list.stream().collect(Collectors.groupingBy(p -> p.getMerchantId()));
// 当门店的所有记录都是老店,才为老店
// 当门店的所有记录都是单品类,才为单品类
groupByMerchant.forEach((merchantId, records) -> {
// 是否属于单品类
boolean isSingle = records.stream().allMatch(p -> (p.getHasBenefits() + p.getHasExtWarranty() + p.getHasLightMod()) == 1);
// 是否属于老店
boolean isOldStore = records.stream().allMatch(p -> {
Integer storeType = p.getStoreTypeByBizs(request.getBizs());
return storeType != null && storeType == 2;
});
// 检查经营品类条件
boolean categoryCondition = true; // 默认为true,表示不进行经营品类过滤
if (request.getBusinessCategory() != null) {
if (request.getBusinessCategory() == 1) {
categoryCondition = isSingle; // 单品类
} else if (request.getBusinessCategory() == 2) {
categoryCondition = !isSingle; // 多品类
} else {
categoryCondition = false; // 不满足条件
}
}
// 检查门店类型条件
boolean storeTypeCondition = true; // 默认为true,表示不进行门店类型过滤
if (request.getStoreType() != null) {
if (request.getStoreType() == 1) {
storeTypeCondition = !isOldStore; // 新店
} else if (request.getStoreType() == 2) {
storeTypeCondition = isOldStore; // 老店
} else {
storeTypeCondition = false; // 不满足条件
}
}
// 同时满足经营品类和门店类型条件时,才添加到权限列表
if (categoryCondition && storeTypeCondition) {
permissionList.add(merchantId);
}
});
return permissionList;
}
/** /**
* 查询门店产值目标 * 查询门店产值目标
*/ */
...@@ -1154,7 +1220,7 @@ public class BusinessSceneAnalysisService { ...@@ -1154,7 +1220,7 @@ public class BusinessSceneAnalysisService {
// 获取产值门店 // 获取产值门店
try { try {
req.setMerchantIds(getMerchantIdPermission(req, false)); req.setMerchantIds(getMerchantIdPermission(req, false, true));
}catch (Exception e){ }catch (Exception e){
return res; return res;
} }
...@@ -1496,22 +1562,23 @@ public class BusinessSceneAnalysisService { ...@@ -1496,22 +1562,23 @@ public class BusinessSceneAnalysisService {
queryParams.setStaffIds(null); queryParams.setStaffIds(null);
itemCodes = Lists.newArrayList(DataStatsConstants.ITEM_CODE_A036, DataStatsConstants.ITEM_CODE_A076, DataStatsConstants.ITEM_CODE_A085); itemCodes = Lists.newArrayList(DataStatsConstants.ITEM_CODE_A036, DataStatsConstants.ITEM_CODE_A076, DataStatsConstants.ITEM_CODE_A085);
Map<String, List<DataBusinessDTO>> merchantDataMap = getDataStatsService.parallelCallListMap(itemCodes, queryParams); Map<String, List<DataBusinessDTO>> merchantDataMap = getDataStatsService.parallelCallListMap(itemCodes, queryParams);
int empCount = CollectionUtils.isEmpty(empMap.values()) ? 1 : empMap.values().size();
merchantDataMap.forEach((code, dataList) -> { merchantDataMap.forEach((code, dataList) -> {
DataBusinessDTO merchantData = mergeDataList(dataList); DataBusinessDTO merchantData = mergeDataList(dataList);
switch (code) { switch (code) {
case DataStatsConstants.ITEM_CODE_A036: case DataStatsConstants.ITEM_CODE_A036:
storeSummary.setTotalOutputValue(scaleItemValue(merchantData.getItemValue())); storeSummary.setTotalOutputValue(scaleItemValue(merchantData.getItemValue()));
int empCount = empMap.values().size(); storeSummary.setAverageOutputValue(merchantData.getItemValue()
if (empCount > 0) { .divide(BigDecimal.valueOf(empCount), 2, RoundingMode.HALF_UP));
storeSummary.setAverageOutputValue(merchantData.getItemValue()
.divide(BigDecimal.valueOf(empCount), 2, RoundingMode.HALF_UP));
}
break; break;
case DataStatsConstants.ITEM_CODE_A076: case DataStatsConstants.ITEM_CODE_A076:
storeSummary.setAverageCustomerPrice(scaleItemValue(merchantData.getItemValue())); storeSummary.setAverageCustomerPrice(merchantData.getItemValue()
.divide(BigDecimal.valueOf(empCount), 2, RoundingMode.HALF_UP));
break; break;
case DataStatsConstants.ITEM_CODE_A085: case DataStatsConstants.ITEM_CODE_A085:
storeSummary.setAverageConversionRate(convertPercentage(merchantData.getItemValue())); storeSummary.setAverageConversionRate(merchantData.getItemValue()
.multiply(BigDecimal.valueOf(100))
.divide(BigDecimal.valueOf(empCount), 2, RoundingMode.HALF_UP));
break; break;
} }
}); });
...@@ -1535,9 +1602,10 @@ public class BusinessSceneAnalysisService { ...@@ -1535,9 +1602,10 @@ public class BusinessSceneAnalysisService {
List<Integer> merchantIds = req.getMerchantIds(); List<Integer> merchantIds = req.getMerchantIds();
Integer sceneType = req.convertToSceneType(queryParams.getBizs()); Integer sceneType = req.convertToSceneType(queryParams.getBizs());
Byte businessType = req.convertToBusinessType(queryParams.getBizs());
Date startTime = DateUtil.beginOfDay(DateUtil.parse(req.getStartTime())); Date startTime = DateUtil.beginOfDay(DateUtil.parse(req.getStartTime()));
Date endTime = DateUtil.endOfDay(DateUtil.parse(req.getEndTime())).toJdkDate(); Date endTime = DateUtil.endOfDay(DateUtil.parse(req.getEndTime())).toJdkDate();
List<TrafficContributionRankResponse> res = goodsOrderMapper.findTrafficRank(merchantIds, staffUuids, startTime, endTime, sceneType); List<TrafficContributionRankResponse> res = goodsOrderMapper.findTrafficRank(merchantIds, staffUuids, startTime, endTime, businessType, sceneType);
if (CollectionUtils.isEmpty(res)) { if (CollectionUtils.isEmpty(res)) {
return Collections.emptyList(); return Collections.emptyList();
} }
...@@ -1787,10 +1855,9 @@ public class BusinessSceneAnalysisService { ...@@ -1787,10 +1855,9 @@ public class BusinessSceneAnalysisService {
// 计算单车采购产值 // 计算单车采购产值
// BigDecimal rate = aggregateType.equals("staffIds") ? BigDecimal.ONE : BigDecimal.valueOf(0.35); // BigDecimal rate = aggregateType.equals("staffIds") ? BigDecimal.ONE : BigDecimal.valueOf(0.35);
BigDecimal rate = BigDecimal.valueOf(0.35); res.setCarBodyFilmPerCarOutput(computeSingleVehiclePurchaseOutput(res.getCarBodyFilmPerCarOutput(), res.getNewCarDeliveryCount(), BigDecimal.ONE));
// res.setCarBodyFilmPerCarOutput(computeSingleVehiclePurchaseOutput(res.getCarBodyFilmPerCarOutput(), res.getNewCarDeliveryCount(), rate)); res.setAccessoriesPerCarOutput(computeSingleVehiclePurchaseOutput(res.getAccessoriesPerCarOutput(), res.getNewCarDeliveryCount(), BigDecimal.ONE));
// res.setAccessoriesPerCarOutput(computeSingleVehiclePurchaseOutput(res.getAccessoriesPerCarOutput(), res.getNewCarDeliveryCount(), rate)); res.setWindowFilmPerCarOutput(computeSingleVehiclePurchaseOutput(res.getWindowFilmPerCarOutput(), res.getNewCarDeliveryCount(), BigDecimal.valueOf(0.35)));
res.setWindowFilmPerCarOutput(computeSingleVehiclePurchaseOutput(res.getWindowFilmPerCarOutput(), res.getNewCarDeliveryCount(), rate));
res.computeWindowFilmEcoCoefficient(); // 车窗膜-生态系数 res.computeWindowFilmEcoCoefficient(); // 车窗膜-生态系数
res.computeCarBodyFilmEcoCoefficient(); // 车身膜-生态系数 res.computeCarBodyFilmEcoCoefficient(); // 车身膜-生态系数
res.computeAccessoriesEcoCoefficient(); // 精品附件-生态系数 res.computeAccessoriesEcoCoefficient(); // 精品附件-生态系数
......
...@@ -170,6 +170,9 @@ ...@@ -170,6 +170,9 @@
</if> </if>
<if test="scene != null"> <if test="scene != null">
and o.scene_type = #{scene} and o.scene_type = #{scene}
<if test="scene == 0">
and o.business_type = #{businessType}
</if>
</if> </if>
<if test="startDate != null"> <if test="startDate != null">
<![CDATA[ and ( <![CDATA[ and (
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    问题描述:

    在 BusinessAnalysisService 类的 stringToPercent 方法中,当输入字符串为空或为 null 时,返回值从 BigDecimal.ZERO 改为了 null。这可能会导致调用该方法的其他部分出现 NullPointerException 异常,尤其是在没有适当空值检查的情况下。

    优化建议:

    1. 恢复默认行为:如果业务逻辑允许将空字符串视为零百分比,则应恢复为返回 BigDecimal.ZERO。
    2. 抛出异常:如果业务逻辑不允许空字符串作为有效输入,则应抛出 IllegalArgumentException 异常,并在调用此方法的地方进行适当的异常处理。
    3. 文档更新:更新方法的 JavaDoc 注释,明确说明在输入为 null 或空字符串时的行为。

    评分明细

    1. 功能实现的正确性与健壮性(40分):

      • 问题:修改可能导致 NullPointerException。
      • 评分:20分(原设计为返回 BigDecimal.ZERO 是合理的,但需要根据业务需求调整)
    2. 安全性与潜在风险(30分):

      • 问题:未发现明显的安全漏洞,但返回 null 可能会引入新的异常情况。
      • 评分:25分(潜在风险较低,但需要根据业务需求调整)
    3. 是否符合最佳实践(20分):

      • 问题:返回 null 可能不符合最佳实践,因为这可能会导致额外的空值检查。
      • 评分:15分(需要根据业务需求调整)
    4. 性能与资源利用效率(5分):

      • 问题:未发现明显的性能问题。
      • 评分:5分
    5. Commits信息的清晰性与准确性(5分):

      • 问题:提交信息不够详细,没有明确指出具体的更改内容。
      • 评分:3分

    总分:68分


    建议的提交信息示例:

    修复百分比处理逻辑:当输入字符串为空或为 null 时,返回 BigDecimal.ZERO 而不是 null
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!