Commit 8f46e14c by 范富荣

策略中心-修改驻店员工列表,驻店类型查询逻辑

1 parent 78535e5a
...@@ -18,7 +18,8 @@ public class StaffAnalysisDTO implements Serializable { ...@@ -18,7 +18,8 @@ public class StaffAnalysisDTO implements Serializable {
@ApiModelProperty(notes = "员工状态(D:已删除;N:未删除 I :禁用)") @ApiModelProperty(notes = "员工状态(D:已删除;N:未删除 I :禁用)")
private String staffStatus = "D"; private String staffStatus = "D";
// private Integer tempFlag; @ApiModelProperty(notes = "驻店类型(1:门店常驻, 2:临时调动支援)")
private Integer stationType;
@ApiModelProperty(notes = "警告信息列表") @ApiModelProperty(notes = "警告信息列表")
private List<WarningInfo> warningInfoList; private List<WarningInfo> warningInfoList;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<properties> <properties>
<platform-merchants.api.version>5.5.1-SNAPSHOT</platform-merchants.api.version> <platform-merchants.api.version>5.5.1-SNAPSHOT</platform-merchants.api.version>
<smartcarlife.api.version>5.6.4-SNAPSHOT</smartcarlife.api.version> <smartcarlife.api.version>5.8.2-SNAPSHOT</smartcarlife.api.version>
<mindworkplate.api.version>5.7.0-SNAPSHOT</mindworkplate.api.version> <mindworkplate.api.version>5.7.0-SNAPSHOT</mindworkplate.api.version>
<pe-analysis.api.version>5.8.2-SNAPSHOT</pe-analysis.api.version> <pe-analysis.api.version>5.8.2-SNAPSHOT</pe-analysis.api.version>
<strategy.api.version>5.8.2-SNAPSHOT</strategy.api.version> <strategy.api.version>5.8.2-SNAPSHOT</strategy.api.version>
......
package cn.com.glsx.dj.peanalysis.config; package cn.com.glsx.dj.peanalysis.config;
import cn.com.glsx.dj.strategy.remote.ProjectGroupRemote;
import cn.com.glsx.dj.smartcarlife.remote.MerchantOutputTargetConfigRemote; import cn.com.glsx.dj.smartcarlife.remote.MerchantOutputTargetConfigRemote;
import cn.com.glsx.dj.smartcarlife.remote.SceneRemote;
import cn.com.glsx.dj.smartcarlife.remote.StaffInfoRemote; import cn.com.glsx.dj.smartcarlife.remote.StaffInfoRemote;
import cn.com.glsx.dj.strategy.remote.ProjectGroupRemote;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -23,4 +24,9 @@ public class SmartCarLifeDubboConfig extends DubboConfig { ...@@ -23,4 +24,9 @@ public class SmartCarLifeDubboConfig extends DubboConfig {
public ProjectGroupRemote projectGroupRemote() { public ProjectGroupRemote projectGroupRemote() {
return factory.builder(ProjectGroupRemote.class).version("1.0.0").check(check).timeout(timeout).build(); return factory.builder(ProjectGroupRemote.class).version("1.0.0").check(check).timeout(timeout).build();
} }
@Bean
public SceneRemote sceneRemote() {
return factory.builder(SceneRemote.class).version("1.0.0").check(check).timeout(timeout).build();
}
} }
...@@ -27,7 +27,10 @@ import cn.com.glsx.dj.peanalysis.utils.MetricsValueUtils; ...@@ -27,7 +27,10 @@ import cn.com.glsx.dj.peanalysis.utils.MetricsValueUtils;
import cn.com.glsx.dj.peanalysis.utils.response.DataResp; import cn.com.glsx.dj.peanalysis.utils.response.DataResp;
import cn.com.glsx.dj.smartcarlife.dto.StaffInfoDTO; import cn.com.glsx.dj.smartcarlife.dto.StaffInfoDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchantTarget.MerchantOutputTargetConfigDTO; import cn.com.glsx.dj.smartcarlife.dto.merchantTarget.MerchantOutputTargetConfigDTO;
import cn.com.glsx.dj.smartcarlife.dto.scene.ListStaffStationTypeParamDTO;
import cn.com.glsx.dj.smartcarlife.dto.scene.StaffStationTypeDTO;
import cn.com.glsx.dj.smartcarlife.remote.MerchantOutputTargetConfigRemote; import cn.com.glsx.dj.smartcarlife.remote.MerchantOutputTargetConfigRemote;
import cn.com.glsx.dj.smartcarlife.remote.SceneRemote;
import cn.com.glsx.dj.smartcarlife.remote.StaffInfoRemote; import cn.com.glsx.dj.smartcarlife.remote.StaffInfoRemote;
import cn.com.glsx.framework.core.beans.BaseModel; import cn.com.glsx.framework.core.beans.BaseModel;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination; import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
...@@ -133,6 +136,9 @@ public class BusinessSceneAnalysisService { ...@@ -133,6 +136,9 @@ public class BusinessSceneAnalysisService {
@Resource @Resource
private ProjectGroupRemote projectGroupRemote; private ProjectGroupRemote projectGroupRemote;
@Resource
private SceneRemote sceneRemote;
/** /**
* 总产值、目标产值、达成率 * 总产值、目标产值、达成率
...@@ -2119,6 +2125,8 @@ public class BusinessSceneAnalysisService { ...@@ -2119,6 +2125,8 @@ public class BusinessSceneAnalysisService {
return staff; return staff;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
req.setStaffUuids(staffIds); req.setStaffUuids(staffIds);
//查询驻店类型
handlerStaffStationType(staffList, req, staffIds);
//查询预警信息 //查询预警信息
handlerStaffWarning(staffList, req, staffIds); handlerStaffWarning(staffList, req, staffIds);
//查询员工禁用标识 //查询员工禁用标识
...@@ -2127,6 +2135,41 @@ public class BusinessSceneAnalysisService { ...@@ -2127,6 +2135,41 @@ public class BusinessSceneAnalysisService {
} }
/** /**
* 处理员工驻店类型
* <p>
* 根据bizs -> sceneType -> baseSceneCode -> station_type 链路查询
*
* @param staffList 员工列表
* @param req 场景请求参数
* @param staffIds 员工ID列表
*/
public void handlerStaffStationType(List<StaffAnalysisDTO> staffList, SceneBaseReq req, List<String> staffIds) {
Integer bizs = req.getBizs();
if (bizs == null || CollectionUtils.isEmpty(staffIds)) {
return;
}
RpcResponse<List<StaffStationTypeDTO>> response = sceneRemote.listStaffStationType(new ListStaffStationTypeParamDTO(bizs, staffIds));
if (!response.isSuccess() || CollectionUtils.isEmpty(response.getResult())) {
return;
}
Map<String, Integer> stationTypeMap = response.getResult().stream()
.filter(dto -> dto.getStationType() != null)
.collect(Collectors.toMap(
StaffStationTypeDTO::getStaffUuid,
StaffStationTypeDTO::getStationType,
(existing, replacement) -> existing));
for (StaffAnalysisDTO staff : staffList) {
Integer stationType = stationTypeMap.get(staff.getStaffId());
if (stationType != null) {
staff.setStationType(stationType);
}
}
}
/**
* 处理员工禁用标识 * 处理员工禁用标识
* *
* @param staffList 员工列表 * @param staffList 员工列表
......
  • @wangxw1
    commented
    Master

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

    1. 潜在的空指针异常(NPE)风险:Collectors.toMap 的 Key 不能为 null

    • 问题描述:在 BusinessSceneAnalysisService.java 的 handlerStaffStationType 方法中,使用 Collectors.toMap 将 RPC 返回的结果转换为 Map。代码中虽然通过 filter(dto -> dto.getStationType() != null) 过滤了 Value 为 null 的情况(toMap 的 Value 为 null 会报 NPE),但忽略了对 Key (staffUuid) 的判空。
    • 影响分析:如果下游服务 sceneRemote 返回的列表中,存在 staffUuid 为 null 的数据,Collectors.toMap 会直接抛出 NullPointerException,导致整个业务接口崩溃。
    • 优化建议:在 filter 中增加对 staffUuid 的非空判断。 java Map<String, Integer> stationTypeMap = response.getResult().stream() .filter(dto -> StringUtils.isNotBlank(dto.getStaffUuid()) && dto.getStationType() != null) .collect(Collectors.toMap( StaffStationTypeDTO::getStaffUuid, StaffStationTypeDTO::getStationType, (existing, replacement) -> existing));

    2. 集合去重逻辑的健壮性隐患:依赖对象的 equals 和 hashCode

    • 问题描述:在 BiAnalyseBackgroundService.java 中,对 flightSupervision 等集合进行去重时,使用了 .stream().distinct().collect(Collectors.toList())。
    • 影响分析:Stream.distinct() 的底层完全依赖于对象(MerchantBiMatterDTO.OperatorDTO)是否正确重写了 equals() 和 hashCode() 方法。如果该 DTO 没有重写这两个方法,distinct() 将只会比较对象的内存地址,导致逻辑上相同的操作员无法被正确去重,进而在前端展示重复数据。
    • 优化建议:建议检查 OperatorDTO 是否重写了相关方法;或者为了防御性编程,推荐使用基于唯一标识(如 operatorId)的去重方式,更加安全可靠。 java // 推荐的按特定属性去重方式 if (CollUtil.isNotEmpty(flightSupervision)) { List<MerchantBiMatterDTO.OperatorDTO> distinctList = flightSupervision.stream() .collect(Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(MerchantBiMatterDTO.OperatorDTO::getOperatorId))), ArrayList::new )); result.setFlightSupervision(distinctList); }

    3. 异常吞没与排查困难:RPC 调用失败未记录日志

    • 问题描述:在 BusinessSceneAnalysisService.java 的 handlerStaffStationType 方法中,调用 sceneRemote.listStaffStationType 后,如果 !response.isSuccess(),代码直接 return,没有任何日志记录。
    • 影响分析:当远程调用失败或发生业务异常时,当前方法会静默失败。最终表现为员工的驻店类型数据丢失,但在系统日志中毫无痕迹,给后续的线上问题排查带来极大的困难。
    • 优化建议:在 return 之前增加 log.warn 或 log.error,记录请求参数和 RPC 返回的错误信息。 java if (!response.isSuccess() || CollectionUtils.isEmpty(response.getResult())) { log.warn("查询员工驻店类型失败或结果为空, bizs:{}, staffIds:{}, msg:{}", bizs, staffIds, response.getMessage()); return; }

    二、评分明细

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

      • 理由:整体业务逻辑闭环完整,充分利用了批量查询来避免 N+1 问题。但存在 Collectors.toMap 未对 Key 判空导致的潜在 NPE 风险,以及 distinct() 去重可能失效的隐患。未发现违反“Mybatis 子查询”及“Dubbo 参数变更”的强制规则。
    2. 安全性与潜在风险(30/30分)

      • 理由:本次变更主要集中在内部 RPC 组装和 DTO 字段扩展,未引入直接面向外部的 SQL 拼接,未发现 SQL 注入、越权、XSS 等安全漏洞。
    3. 最佳实践与可维护性(15/20分)

      • 理由:代码结构清晰,抽取了独立的 handlerStaffStationType 方法,符合单一职责原则。扣分点在于 RPC 调用失败时直接吞没了错误信息,缺乏必要的异常日志,不利于系统运维。
    4. 性能与资源利用(5/5分)

      • 理由:在组装数据时,使用了批量 RPC 查询(传入 staffIds 集合),并在内存中转为 Map 实现 O(1) 的数据映射,性能处理非常优秀,无资源浪费。
    5. 提交信息质量(4/5分)

      • 理由:Commit 信息(修改策略中心-门店详情查询逻辑(区分子场景)...)清晰地说明了“做了什么”,但略微缺乏“为什么做(业务背景)”的描述。整体符合追溯要求。

    总分:86分

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