Commit 09fb8058 by 王璐琦

- rop-dj-smartcarlife

  - dj.api.smartcarlife.ordermanage.count 订单管理累计金额增加查询条件
  - cn.com.glsx.dj.smartcarlife.controller.smartCarLife.GoodsOrderController#queryAndExportData 2.1场景导出修改原错误订单号取值
- rpc-dj-smartcarlife
  - cn.com.glsx.dj.smartcarlife.mapper.GoodsOrderMapper#listForExport 修改1.1、2.1场景导出错误订单取值
  - cn.com.glsx.dj.smartcarlife.mapper.GoodsOrderMapper#listWithPage  修改1.1、2.1场景查询原错误订单取值
1 parent 5ab5ca80
......@@ -1122,7 +1122,7 @@ public class GoodsOrderService {
List<Integer> merchantIds;
if (Objects.nonNull(pagination.getCondition().getAdminFlag()) && !pagination.getCondition().getAdminFlag()) {
//查询当前登录人所绑定的线上运营门店ids
merchantIds = getLoginUserMerchantIds(pagination);
merchantIds = getLoginUserMerchantIds(pagination.getCondition());
//我的待审开关打开
if (Objects.nonNull(pagination.getCondition().getMyWaitApplySwitch())
&& CommonFlagEnum.YES.getCode().equals(pagination.getCondition().getMyWaitApplySwitch())) {
......@@ -1193,25 +1193,25 @@ public class GoodsOrderService {
/**
* 获取登录人所绑定的线上运营门店ids
* @param pagination
* @param goodsOrderDTO
* @return
*/
private List<Integer> getLoginUserMerchantIds(RpcPagination<GoodsOrderDTO> pagination) {
private List<Integer> getLoginUserMerchantIds(GoodsOrderDTO goodsOrderDTO) {
List<Integer> merchantIds = new ArrayList<>();
if (StringUtils.isNotBlank(pagination.getCondition().getLoginPhone())) {
List<ShopMerchantDirectorConfig> shopMerchantDirectorConfigs = shopMerchantDirectorConfigService.listShopMerchantDirectorConfigByPhone(pagination.getCondition().getLoginPhone());
if (StringUtils.isNotBlank(goodsOrderDTO.getLoginPhone())) {
List<ShopMerchantDirectorConfig> shopMerchantDirectorConfigs = shopMerchantDirectorConfigService.listShopMerchantDirectorConfigByPhone(goodsOrderDTO.getLoginPhone());
if (CollectionUtils.isNotEmpty(shopMerchantDirectorConfigs)) {
//筛选directorType为 5的数据
if (Objects.equals(pagination.getCondition().getSceneType(), SceneTypeEnum.SCENE1_1.getValue())) {
if (Objects.equals(goodsOrderDTO.getSceneType(), SceneTypeEnum.SCENE1_1.getValue())) {
merchantIds = shopMerchantDirectorConfigs.stream().filter(item -> item.getDirectorType().equals(DirectorTypeEnum.DF_DIRECTOR.getValue())).map(ShopMerchantDirectorConfig::getMerchantId).collect(Collectors.toList());
}
//筛选directorType为7 的数据
if (Objects.equals(pagination.getCondition().getSceneType(), SceneTypeEnum.SCENE1_0.getValue())) {
if (Objects.equals(goodsOrderDTO.getSceneType(), SceneTypeEnum.SCENE1_0.getValue())) {
merchantIds = shopMerchantDirectorConfigs.stream().filter(item -> item.getDirectorType().equals(DirectorTypeEnum.DF_DIRECTOR_2_1.getValue())).map(ShopMerchantDirectorConfig::getMerchantId).collect(Collectors.toList());
}
}
}
log.info("场景值:{},登录人手机号:{},绑定的线上运营门店ids:{}", pagination.getCondition().getSceneType(),pagination.getCondition().getLoginPhone(), JSONObject.toJSONString(merchantIds));
log.info("场景值:{},登录人手机号:{},绑定的线上运营门店ids:{}", goodsOrderDTO.getSceneType(),goodsOrderDTO.getLoginPhone(), JSONObject.toJSONString(merchantIds));
return merchantIds;
}
......@@ -1227,7 +1227,7 @@ public class GoodsOrderService {
if (Objects.nonNull(pagination.getCondition().getMyWaitApplySwitch())
&& CommonFlagEnum.YES.getCode().equals(pagination.getCondition().getMyWaitApplySwitch())) {
//查询当前登录人所绑定的线上运营门店ids
List<Integer> merchantIds = getLoginUserMerchantIds(pagination);
List<Integer> merchantIds = getLoginUserMerchantIds(pagination.getCondition());
pagination.getCondition().setMerchantIdList(merchantIds);
pagination.getCondition().setGoodsOrderApplyStatus(GoodsOrderApplyStatusEnum.ONLINE_SUPERVISION_AUDIT.getValue());
}
......@@ -1298,6 +1298,19 @@ public class GoodsOrderService {
if (goodsOrderDTO.getDirectSalesFlag() != null) {
goodsOrderDTO.setPartnerMerchantId(djServiceMerchantId);
}
List<Integer> merchantIds;
if (Objects.nonNull(goodsOrderDTO.getAdminFlag()) && !goodsOrderDTO.getAdminFlag()) {
//查询当前登录人所绑定的线上运营门店ids
merchantIds = getLoginUserMerchantIds(goodsOrderDTO);
//我的待审开关打开
if (Objects.nonNull(goodsOrderDTO.getMyWaitApplySwitch())
&& CommonFlagEnum.YES.getCode().equals(goodsOrderDTO.getMyWaitApplySwitch())) {
goodsOrderDTO.setMerchantIdList(merchantIds);
goodsOrderDTO.setGoodsOrderApplyStatus(GoodsOrderApplyStatusEnum.ONLINE_SUPERVISION_AUDIT.getValue());
}
} else {
merchantIds = new ArrayList<>();
}
return goodsOrderMapper.countList(goodsOrderDTO);
} catch (Exception e) {
log.error(e.getMessage(), e);
......
......@@ -360,6 +360,9 @@
<if test="businessType != null">
and go.business_type = #{businessType}
</if>
<if test="djOrderType != null">
and go.dj_order_type = #{djOrderType}
</if>
<if test="orderCode != null and orderCode !=''">
and go.order_code = #{orderCode}
</if>
......@@ -881,7 +884,7 @@
go.failure_flag, go.install_merchant_name, go.marketing_merchant_name, go.sub_shop_merchant_id,go.sub_shop_merchant_name,go.merchant_id,go.scene_type,
go.profit_allocation_status, go.wait_profit_allocation_date, go.specify_account_rule_id, go.specify_division_rule_id,
go.technician_name as go_technician_name, go.technician_uuid, go.technician_id as go_technician_id, go.business_type,ifnull(go.invoice_status,1) as invoice_status,
go.dj_order_type,go.abnormal_flag,
go.dj_order_type,go.abnormal_flag, CASE WHEN go.status = 11 THEN null ELSE go.associated_order_code END AS incorrect_order_code,
<!-- 订单客户信息 -->
goc.stand_no, goc.car_brand, goc.car_childs_brand_name, goc.car_series_name, goc.car_type_name, goc.customer_name, goc.customer_phone,
goc.sales_type,
......@@ -894,7 +897,7 @@
<!-- 商户信息 -->
sm.province_name,yc.partner_merchant_id,
<!-- 订单审核信息 -->
goar.status as goodsOrderApplyStatus, goar.association_order_code as incorrect_order_code
goar.status as goodsOrderApplyStatus
from dj_car_life_goods_order go
left join dj_car_life_goods_order_customer goc on goc.order_code=go.order_code and goc.deleted_flag='N'
left join dj_car_life_pay_order po on po.order_code=go.order_code and po.deleted_flag='N'
......@@ -945,7 +948,11 @@
left join dj_car_life_goods_order_customer goc on goc.order_code=go.order_code and goc.deleted_flag='N'
left join dj_car_life_pay_order po on po.order_code=go.order_code and po.deleted_flag='N'
left join dj_car_life_yqmerchant_config yc on go.seller_merchant_id = yc.merchant_id and yc.deleted_flag = 'N'
left join dj_car_life_goods_order_apply_record goar on go.order_code = goar.order_code and goar.deleted_flag = 'N'
<include refid="listCondition"/>
<if test="goodsOrderApplyStatus != null">
and goar.status = #{goodsOrderApplyStatus}
</if>
</select>
<select id="count" parameterType="cn.com.glsx.dj.smartcarlife.dto.GoodsOrderDTO" resultMap="countResultMap">
......@@ -1470,6 +1477,7 @@
go.install_merchant_name, go.marketing_merchant_name,go.profit_allocation_status, go.wait_profit_allocation_date,
go.specify_account_rule_id, go.specify_division_rule_id, go.film_order,CASE WHEN go.abnormal_flag = 'Y' AND go.status IN (4, 6, 12, 13) THEN COALESCE(go.associated_order_code, 'Y') ELSE 'N' END as abnormal_flag,
go.technician_name as go_technician_name, go.technician_uuid, go.technician_id as go_technician_id,ifnull(go.invoice_status,1) as invoice_status,
CASE WHEN go.status = 11 THEN null ELSE go.associated_order_code END AS incorrect_order_code,
<!-- 订单客户信息 -->
goc.customer_id,goc.stand_no,goc.car_key_no, goc.car_brand_id, goc.car_brand,
goc.car_childs_brand_id, goc.car_childs_brand_name,goc.car_series_id, goc.car_series_name, goc.car_type_id,
......@@ -1493,7 +1501,7 @@
<!-- 商户信息 -->
sm.province_name,yc.partner_merchant_id,
<!-- 订单审核信息 -->
goar.status as goodsOrderApplyStatus, goar.association_order_code as incorrect_order_code
goar.status as goodsOrderApplyStatus
from dj_car_life_goods_order go
left join dj_car_life_goods_order_customer goc on goc.order_code=go.order_code and goc.deleted_flag='N'
left join dj_car_life_pay_order po on po.order_code=go.order_code and po.deleted_flag='N'
......
  • @wangxw1
    commented
    Master

    你好,我是资深 Java 开发工程师。针对你提供的 GoodsOrderService.java 和 GoodsOrderMapper.xml 代码变更,我进行了详细的审查。

    以下是审查结果:

    一、关键问题与优化建议(Top 3)

    1. 安全性与逻辑漏洞:空集合导致的权限逃逸风险

    • 问题描述:在 GoodsOrderService 的 countList 方法(以及推测的 listWithPage)中,通过 getLoginUserMerchantIds 获取用户绑定的 merchantIds。如果当前登录用户未绑定任何门店(即 merchantIds 为空列表),且开启了“我的待审”开关(MyWaitApplySwitch),代码会将空列表传入 goodsOrderDTO。
    • 风险:在 MyBatis 的动态 SQL 中,通常写法是 <if test="list != null and list.size() > 0">。如果集合为空,IN (...) 条件往往会被跳过。这意味着未绑定任何门店的用户,可能查询到所有门店的待审核订单,导致严重的数据越权(Data Leak)。
    • 建议:
      • 代码层面:在 Service 层判断,如果开启了权限过滤且 merchantIds 为空,应直接返回 0(针对 count)或空列表(针对 list),或者构造一个不存在的 ID(如 -1)传入查询条件,确保 SQL 此时查不到数据,而不是忽略过滤条件。
      • 示例: java merchantIds = getLoginUserMerchantIds(goodsOrderDTO); if (CollectionUtils.isEmpty(merchantIds)) { // 如果必须绑定门店才能查看,此处应直接返回,避免执行SQL return 0; }

    2. 可维护性问题:SQL 中存在“魔术数字”

    • 问题描述:在 GoodsOrderMapper.xml 的 SQL 语句中,新增了逻辑 CASE WHEN go.status = 11 THEN null ...。这里的 11 是一个典型的硬编码(Magic Number)。
    • 风险:代码阅读者难以理解 11 代表的具体业务含义(是“已取消”?“审核不通过”?)。且如果未来该状态码变更,维护人员很难搜索到 XML 中的这个硬编码进行同步修改。
    • 建议:
      • 遵循阿里巴巴 Java 开发手册,禁止在代码(包括 SQL)中使用魔术数字。
      • 应将状态码定义在 Java 枚举(Enum)中,并通过参数传递给 Mapper,或者在 MyBatis 中引用枚举常量/静态常量。

    3. 性能问题:Count 查询包含冗余的 JOIN 操作

    • 问题描述:在 GoodsOrderMapper.xml 的 countList 查询中,新增了 left join dj_car_life_goods_order_apply_record goar。同时查询依然保留了 goc (客户表), po (支付表), yc (配置表) 的 LEFT JOIN。
    • 风险:SELECT COUNT(*) 不需要返回具体字段。除非 WHERE 条件中用到了这些表的字段,否则无条件的 LEFT JOIN 会导致数据库进行不必要的全表扫描或索引扫描,在数据量大时严重拖慢查询性能。
    • 建议:
      • 检查 listCondition 片段。如果 goc、po、yc 表的字段未参与过滤条件,应在 countList 的 SQL 中移除这些 Join。仅保留主表和参与过滤(WHERE)的关联表(如本次新增的 goar 用于状态过滤)。

    二、评分明细

    维度 评分 扣分/得分理由
    功能正确性 (40分) 32 业务逻辑实现基本吻合,但“空门店列表”的边界情况处理存在逻辑隐患,可能导致查询结果不符合预期。
    安全性 (30分) 20 存在高风险的数据越权隐患(Issue #1),未绑定门店的用户可能因空集合绕过数据权限过滤。
    可维护性 (20分) 15 Service 层重构了参数传递(Good),但 SQL 中引入了魔术数字 11,且 Service 中存在类似的逻辑重复(countList 与 listWithPage 里的权限判断逻辑相似)。
    性能 (5分) 3 countList 查询未针对计数进行优化,包含不必要的 Join,影响大表查询性能。
    提交信息 (5分) 5 提交信息清晰,涵盖了主要变更点。

    总分:75分

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