Commit abf35509 by 林永健

fix(peanalysis): 修复门店流量排名查询逻辑

- goodsOrderMapper新增merchantIds参数支持按商户过滤
- 更新MyBatis映射文件添加merchant_id条件判断
- BusinessSceneAnalysisService调用参数增加merchantIds
- 测试用例中添加merchantIds初始化防止空指针异常
- 删除无用的staffUuids空判断逻辑,提高代码健壮性
1 parent 782d9c1f
...@@ -12,5 +12,8 @@ import java.util.List; ...@@ -12,5 +12,8 @@ import java.util.List;
public interface GoodsOrderMapper extends OreMapper<GoodsOrder> { public interface GoodsOrderMapper extends OreMapper<GoodsOrder> {
List<TrafficContributionRankResponse> findTrafficRank(@Param("staffUuids") List<String> staffUuids, @Param("scene") Integer sceneType); List<TrafficContributionRankResponse> findTrafficRank(
@Param("merchantIds") List<Integer> merchantIds,
@Param("staffUuids") List<String> staffUuids,
@Param("scene") Integer sceneType);
} }
\ No newline at end of file \ No newline at end of file
...@@ -1226,12 +1226,10 @@ public class BusinessSceneAnalysisService { ...@@ -1226,12 +1226,10 @@ public class BusinessSceneAnalysisService {
public List<TrafficContributionRankResponse> storeTrafficRank(SceneBaseReq req) { public List<TrafficContributionRankResponse> storeTrafficRank(SceneBaseReq req) {
DataBizQueryParamsDTO queryParams = req.getQueryParams(); DataBizQueryParamsDTO queryParams = req.getQueryParams();
List<String> staffUuids = req.getStaffUuids(); List<String> staffUuids = req.getStaffUuids();
if (CollectionUtils.isEmpty(staffUuids)) { List<Integer> merchantIds = req.getMerchantIds();
return Collections.emptyList();
}
Integer sceneType = req.convertToSceneType(queryParams.getBizs()); Integer sceneType = req.convertToSceneType(queryParams.getBizs());
List<TrafficContributionRankResponse> res = goodsOrderMapper.findTrafficRank(req.getStaffUuids(), sceneType); List<TrafficContributionRankResponse> res = goodsOrderMapper.findTrafficRank(merchantIds, staffUuids, sceneType);
if (CollectionUtils.isEmpty(res)) { if (CollectionUtils.isEmpty(res)) {
return Collections.emptyList(); return Collections.emptyList();
} }
......
...@@ -155,6 +155,12 @@ ...@@ -155,6 +155,12 @@
deleted_flag = 'N' deleted_flag = 'N'
and user_id is not null and user_id is not null
and status in (2, 4, 6) and status in (2, 4, 6)
<if test="merchantIds != null and merchantIds.size() > 0">
and merchant_id in
<foreach collection="merchantIds" item="uuid" open="(" close=")" separator=",">
#{uuid}
</foreach>
</if>
<if test="staffUuids != null and staffUuids.size() > 0"> <if test="staffUuids != null and staffUuids.size() > 0">
and user_id in and user_id in
<foreach collection="staffUuids" item="uuid" open="(" close=")" separator=","> <foreach collection="staffUuids" item="uuid" open="(" close=")" separator=",">
......
...@@ -138,6 +138,7 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest { ...@@ -138,6 +138,7 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest {
req.setCycleType(2); req.setCycleType(2);
req.setStartTime("2025-02-01"); req.setStartTime("2025-02-01");
req.setEndTime("2025-11-31"); req.setEndTime("2025-11-31");
req.setMerchantIds(Lists.newArrayList());
req.setStaffUuids(Lists.newArrayList()); req.setStaffUuids(Lists.newArrayList());
Object res = service.storeTrafficRank(req); Object res = service.storeTrafficRank(req);
System.out.println(res); System.out.println(res);
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 功能实现的正确性与健壮性

    • 问题:storeTrafficRank方法中移除了对staffUuids的空值检查。如果staffUuids为空,则会导致数据库查询条件不完整,可能返回不符合预期的结果。
    • 优化建议:在移除staffUuids的空值检查之前,需要确保新的merchantIds参数能够覆盖所有可能的情况,或者重新引入对staffUuids的空值检查。

    2. 安全性与潜在风险

    • 问题:没有明显的安全漏洞,但需要确保merchantIds和staffUuids的来源是可信的,避免SQL注入等风险。
    • 优化建议:确认merchantIds和staffUuids的来源,并进行必要的验证和清理,确保输入数据的安全性。

    3. 是否符合最佳实践

    • 问题:方法签名和参数名称的修改使得方法更具通用性,但需要确保所有调用该方法的地方都进行了相应的调整。
    • 优化建议:更新文档和注释,明确新参数的用途和约束条件,确保其他开发者理解这些变化。

    4. 性能与资源利用效率

    • 问题:没有明显的性能问题,但需要评估新增的merchantIds参数对查询性能的影响。
    • 优化建议:进行性能测试,确保新增参数不会导致查询性能下降。

    5. Commits信息的清晰性与准确性

    • 问题:提交信息描述了主要变更内容,但可以更详细地描述具体的修改细节。
    • 优化建议:在提交信息中增加更多细节,比如修改的原因和预期效果,以便其他开发者更好地理解这些变更。

    评分明细

    1. 功能实现的正确性与健壮性:35分(5分扣分原因:移除了staffUuids的空值检查)
    2. 安全性与潜在风险:28分(2分扣分原因:未明确merchantIds和staffUuids的来源和验证)
    3. 是否符合最佳实践:18分(2分扣分原因:缺少文档和注释的更新)
    4. 性能与资源利用效率:4分(1分扣分原因:未进行性能测试)
    5. Commits信息的清晰性与准确性:4分(1分扣分原因:提交信息可以更详细)

    总分: 90分

    通过以上审查,代码总体上实现了预期的功能,但在一些细节方面还有改进的空间。希望开发者能够根据这些建议进一步完善代码。

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!