Commit e5ad702a by 杨卫

refactor(recruitment): 重构小场景列表查询逻辑移除业务类型过滤

- 新增 RecruitmentSubSceneConvert 转换器,基于 MapStruct 实现场景对象映射
- 移除按招聘需求业务类型过滤场景的逻辑,改为直接返回门店全部经营场景
- 对转换结果按场景编码去重,使用 LinkedHashMap 保持插入顺序
- 更新 RecruitmentSubSceneDTO 中 businessType 字段注释说明其不再参与过滤
- 更新 RecruitmentDemandRemote 接口描述,明确仅 merchantId 为必填条件
- 升级版本号至 5.8.8-SNAPSHOT
1 parent 963fff92
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</parent> </parent>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
<artifactId>rpc-dj-staff-api</artifactId> <artifactId>rpc-dj-staff-api</artifactId>
<version>5.8.7.5-SNAPSHOT</version> <version>5.8.8-SNAPSHOT</version>
<name>rpc-dj-staff-api</name> <name>rpc-dj-staff-api</name>
<properties> <properties>
<deploy.scanPackage>cn.com.glsx.dj.staff.remote</deploy.scanPackage> <deploy.scanPackage>cn.com.glsx.dj.staff.remote</deploy.scanPackage>
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<dependency> <dependency>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
<artifactId>rpc-dj-staff-api</artifactId> <artifactId>rpc-dj-staff-api</artifactId>
<version>5.8.7.5-SNAPSHOT</version> <version>5.8.8-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</plugin> </plugin>
......
...@@ -18,7 +18,7 @@ public class RecruitmentSubSceneDTO implements Serializable { ...@@ -18,7 +18,7 @@ public class RecruitmentSubSceneDTO implements Serializable {
@ApiModelProperty(notes = "门店商户号(查询条件)") @ApiModelProperty(notes = "门店商户号(查询条件)")
private Integer merchantId; private Integer merchantId;
@ApiModelProperty(notes = "招聘需求业务类型值(查询条件)") @ApiModelProperty(notes = "招聘需求业务类型值(兼容保留,不再参与场景过滤)")
private Integer businessType; private Integer businessType;
@ApiModelProperty(notes = "场景编码") @ApiModelProperty(notes = "场景编码")
......
...@@ -122,8 +122,8 @@ public interface RecruitmentDemandRemote { ...@@ -122,8 +122,8 @@ public interface RecruitmentDemandRemote {
@ApiResponse("省份HRBP关系列表") @ApiResponse("省份HRBP关系列表")
RpcResponse<List<RecruitmentProvinceHrbpRelation>> listProvinceHrbpRelation(@NotNull RecruitmentProvinceHrbpRelation condition); RpcResponse<List<RecruitmentProvinceHrbpRelation>> listProvinceHrbpRelation(@NotNull RecruitmentProvinceHrbpRelation condition);
@ApiMethod("查询小场景列表") @ApiMethod("查询小场景列表(目标门店全部经营场景)")
@ApiParam(name = "dto", notes = "查询条件,merchantId/businessType", dataType = ApiParam.DataTypeEnum.OBJECT, required = true) @ApiParam(name = "dto", notes = "查询条件,merchantId必填", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("小场景列表") @ApiResponse("小场景列表")
RpcResponse<List<RecruitmentSubSceneDTO>> listSubScenes(@NotNull RecruitmentSubSceneDTO dto); RpcResponse<List<RecruitmentSubSceneDTO>> listSubScenes(@NotNull RecruitmentSubSceneDTO dto);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</parent> </parent>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
<artifactId>rpc-dj-staff</artifactId> <artifactId>rpc-dj-staff</artifactId>
<version>5.8.7.5-SNAPSHOT</version> <version>5.8.8-SNAPSHOT</version>
<name>rpc-dj-staff</name> <name>rpc-dj-staff</name>
<packaging>war</packaging> <packaging>war</packaging>
<dependencies> <dependencies>
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<dependency> <dependency>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
<artifactId>rpc-dj-staff-api</artifactId> <artifactId>rpc-dj-staff-api</artifactId>
<version>5.8.7.5-SNAPSHOT</version> <version>5.8.8-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.oreframework.boot</groupId> <groupId>org.oreframework.boot</groupId>
......
package cn.com.glsx.dj.staff.converter;
import cn.com.glsx.dj.smartcarlife.dto.NewMerchantSceneDTO;
import cn.com.glsx.dj.staff.dto.recruitment.RecruitmentSubSceneDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
/**
* 招聘试岗小场景转换器
* @author yangwei_by_claude
* @version 1.0
* @since 2026/11/24 10:00
*/
@Mapper(componentModel = "spring")
public interface RecruitmentSubSceneConvert {
/**
* 门店已上架场景转换为试岗小场景
*
* @param scene 门店已上架场景
* @return cn.com.glsx.dj.staff.dto.recruitment.RecruitmentSubSceneDTO 试岗小场景
* @author yangwei_by_claude
* @since 2026/11/24 10:00
*/
@Mappings({
@Mapping(target = "merchantId", ignore = true),
@Mapping(target = "businessType", ignore = true),
@Mapping(source = "baseSceneCode", target = "sceneCode"),
@Mapping(source = "baseSceneCodeName", target = "sceneName")
})
RecruitmentSubSceneDTO toSubSceneDTO(NewMerchantSceneDTO scene);
}
...@@ -14,6 +14,7 @@ import cn.com.glsx.dj.sale.dto.SalePotentialCustomerBrandDTO; ...@@ -14,6 +14,7 @@ import cn.com.glsx.dj.sale.dto.SalePotentialCustomerBrandDTO;
import cn.com.glsx.dj.sale.dto.SalePotentialCustomersDetailDTO; import cn.com.glsx.dj.sale.dto.SalePotentialCustomersDetailDTO;
import cn.com.glsx.dj.sale.remote.SalePotentialCustomersRemote; import cn.com.glsx.dj.sale.remote.SalePotentialCustomersRemote;
import cn.com.glsx.dj.smartcarlife.remote.*; import cn.com.glsx.dj.smartcarlife.remote.*;
import cn.com.glsx.dj.staff.converter.RecruitmentSubSceneConvert;
import cn.com.glsx.dj.staff.dto.recruitment.*; import cn.com.glsx.dj.staff.dto.recruitment.*;
import cn.com.glsx.dj.staff.enums.FlagEnum; import cn.com.glsx.dj.staff.enums.FlagEnum;
import cn.com.glsx.dj.staff.enums.RecruitmentDemandStatusEnum; import cn.com.glsx.dj.staff.enums.RecruitmentDemandStatusEnum;
...@@ -166,6 +167,9 @@ public class RecruitmentDemandService { ...@@ -166,6 +167,9 @@ public class RecruitmentDemandService {
private SceneMerchantRefRemote sceneMerchantRefRemote; private SceneMerchantRefRemote sceneMerchantRefRemote;
@Autowired @Autowired
private RecruitmentSubSceneConvert recruitmentSubSceneConvert;
@Autowired
private SceneRemote sceneRemote; private SceneRemote sceneRemote;
@Autowired @Autowired
...@@ -2624,14 +2628,16 @@ public class RecruitmentDemandService { ...@@ -2624,14 +2628,16 @@ public class RecruitmentDemandService {
} }
/** /**
* 查询小场景列表 * 查询小场景列表(目标门店的全部经营场景,不再与招聘需求指定的场景取交集)
* *
* @param dto 查询条件(merchantId + businessType) * @param dto 查询条件(merchantId)
* @return 小场景列表 * @return 小场景列表
* @author yangwei_by_claude
* @since 2026/11/24 10:00
*/ */
public List<RecruitmentSubSceneDTO> listSubScenes(RecruitmentSubSceneDTO dto) { public List<RecruitmentSubSceneDTO> listSubScenes(RecruitmentSubSceneDTO dto) {
try { try {
// 1. 通过门店商户号查询门店已上架的全部小场景 // 1. 通过门店商户号查询门店已上架的全部经营场景
RpcResponse<List<NewMerchantSceneDTO>> sceneResp = sceneMerchantRefRemote.findAllSceneByMerchantId(dto.getMerchantId()); RpcResponse<List<NewMerchantSceneDTO>> sceneResp = sceneMerchantRefRemote.findAllSceneByMerchantId(dto.getMerchantId());
if (sceneResp == null || CollectionUtils.isEmpty(sceneResp.getResult())) { if (sceneResp == null || CollectionUtils.isEmpty(sceneResp.getResult())) {
log.info("查询小场景列表-门店无已上架场景,merchantId:{}", dto.getMerchantId()); log.info("查询小场景列表-门店无已上架场景,merchantId:{}", dto.getMerchantId());
...@@ -2640,28 +2646,16 @@ public class RecruitmentDemandService { ...@@ -2640,28 +2646,16 @@ public class RecruitmentDemandService {
List<NewMerchantSceneDTO> merchantSceneList = sceneResp.getResult(); List<NewMerchantSceneDTO> merchantSceneList = sceneResp.getResult();
log.info("查询小场景列表-门店已上架场景数量:{},merchantId:{}", merchantSceneList.size(), dto.getMerchantId()); log.info("查询小场景列表-门店已上架场景数量:{},merchantId:{}", merchantSceneList.size(), dto.getMerchantId());
// 2. 根据业务类型获取允许的场景编号列表 // 2. 直接转换门店全部经营场景(不再按招聘需求业务类型过滤),按场景编码去重
List<String> allowedNums = getAllowedNumsByBusinessType(dto.getBusinessType()); List<RecruitmentSubSceneDTO> result = merchantSceneList.stream()
if (CollectionUtils.isEmpty(allowedNums)) { .filter(scene -> scene != null && StringUtils.isNotBlank(scene.getBaseSceneCode()))
log.info("查询小场景列表-业务类型无对应场景映射,businessType:{}", dto.getBusinessType()); .collect(Collectors.collectingAndThen(
return new ArrayList<>(); Collectors.toMap(NewMerchantSceneDTO::getBaseSceneCode,
} recruitmentSubSceneConvert::toSubSceneDTO,
log.info("查询小场景列表-业务类型:{}, 允许场景编号:{}", dto.getBusinessType(), allowedNums); (scene1, scene2) -> scene1,
LinkedHashMap::new),
// 3. 过滤门店已上架的小场景(匹配场景编号) map -> new ArrayList<>(map.values())));
List<NewMerchantSceneDTO> filteredList = merchantSceneList.stream() log.info("查询小场景列表-返回场景数量:{},merchantId:{}", result.size(), dto.getMerchantId());
.filter(scene -> allowedNums.contains(scene.getNum()))
.collect(Collectors.toList());
log.info("查询小场景列表-过滤后场景数量:{},merchantId:{}", filteredList.size(), dto.getMerchantId());
// 4. 转换小场景数据对象并返回
List<RecruitmentSubSceneDTO> result = new ArrayList<>();
for (NewMerchantSceneDTO scene : filteredList) {
result.add(RecruitmentSubSceneDTO.builder()
.sceneCode(scene.getBaseSceneCode())
.sceneName(scene.getBaseSceneCodeName())
.build());
}
return result; return result;
} catch (Exception e) { } catch (Exception e) {
log.error("查询小场景列表异常,merchantId:{}, businessType:{}", dto.getMerchantId(), dto.getBusinessType(), e); log.error("查询小场景列表异常,merchantId:{}, businessType:{}", dto.getMerchantId(), dto.getBusinessType(), e);
......
...@@ -146,7 +146,7 @@ public class RecruitmentDemandServiceTest extends BaseServiceTest { ...@@ -146,7 +146,7 @@ public class RecruitmentDemandServiceTest extends BaseServiceTest {
@Test @Test
public void testListSubScenes() { public void testListSubScenes() {
RecruitmentSubSceneDTO dto = new RecruitmentSubSceneDTO(); RecruitmentSubSceneDTO dto = new RecruitmentSubSceneDTO();
dto.setMerchantId(44217681); dto.setMerchantId(44211227);
dto.setBusinessType(2); dto.setBusinessType(2);
List<RecruitmentSubSceneDTO> list = recruitmentDemandService.listSubScenes(dto); List<RecruitmentSubSceneDTO> list = recruitmentDemandService.listSubScenes(dto);
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议,如果必要,给出代码示例(仅限 Top 3)

    1. 问题 1:参数校验缺失导致 dto 或 merchantId 为空时直接触发异常或无效 RPC 调用

      • 问题描述:RecruitmentDemandRemote#listSubScenes 标注了 @NotNull 且注释明确 merchantId必填,但在 RecruitmentDemandService#listSubScenes 入口处未对 dto == null 及 dto.getMerchantId() == null 做前置防御校验,直接调用 sceneMerchantRefRemote.findAllSceneByMerchantId(dto.getMerchantId())。若 dto 为 null 会直接抛出 NullPointerException 被 catch (Exception e) 吞掉并误记为异常日志;若 merchantId 为 null 则会产生无效的远程 RPC 调用。
      • 影响分析:缺乏前置空值校验会导致无效网络开销、异常堆栈污染错误日志,且无法向调用方明确区分“参数非法”与“门店无上架场景”。
      • 优化建议:在方法首行增加参数判空校验,提前快速失败(Fast-Fail)并返回空集合或抛出业务参数异常。
      • 代码示例: java public List<RecruitmentSubSceneDTO> listSubScenes(RecruitmentSubSceneDTO dto) { if (dto == null || dto.getMerchantId() == null) { log.warn("查询小场景列表-参数非法,merchantId不能为空"); return Collections.emptyList(); } try { RpcResponse<List<NewMerchantSceneDTO>> sceneResp = sceneMerchantRefRemote.findAllSceneByMerchantId(dto.getMerchantId()); // ...
    2. 问题 2:异常吞没(Swallowing Exceptions)掩盖下游 RPC 调用失败

      • 问题描述:RecruitmentDemandService#listSubScenes 中未校验 sceneResp.isSuccess()(或对应的响应成功状态码),且在 catch (Exception e) 中捕获所有异常后直接返回空列表(推测原代码 catch 块返回 new ArrayList<>()),导致下游 sceneMerchantRefRemote 超时或报错时,上层业务会误判为“该门店没有任何经营场景”。
      • 影响分析:在业务流程中,“下游服务故障”与“门店确实无场景”语义完全不同。静默返回空列表可能导致前端展示空白或误触发后续无场景兜底逻辑,排查线上问题困难。
      • 优化建议:增加下游 RPC 响应状态判断;对于非预期系统/RPC 异常,建议向上抛出自定义业务异常由全局/RPC 异常拦截器统一封装错误码返回给调用方。
    3. 问题 3:遗留废弃私有方法及单元测试未同步更新断言

      • 问题描述:
        1. RecruitmentDemandService 中原有的 getAllowedNumsByBusinessType(Integer businessType) 私有方法在本次重构后已不再被调用(成为死代码),未见同步清理。
        2. RecruitmentDemandServiceTest#testListSubScenes 仅修改了测试用的 merchantId,仍保留了已废弃的 dto.setBusinessType(2) 赋值,且未补充对去重逻辑(相同 baseSceneCode 过滤)和空参数边界的断言验证。
      • 影响分析:死代码会增加后续维护者的理解成本;单元测试未能覆盖本次重构的核心变更点(全量场景返回、按 baseSceneCode 去重),回归保障力度不足。
      • 优化建议:确认无其他调用后删除 getAllowedNumsByBusinessType 方法;完善单元测试,移除无意义的 businessType 设值,增加去重及空入参场景的断言。

    二、评分明细

    • 功能实现的正确性与健壮性(34/40分):核心业务逻辑重构清晰,使用 LinkedHashMap 按 baseSceneCode 去重并保留顺序处理得当;Dubbo Remote 接口保持了字段兼容性(businessType 保留未删除),符合接口兼容规范,未涉及 MyBatis 子查询问题。扣分点在于缺少 dto 与 merchantId 的前置空校验,以及异常捕获后直接吞没返回空列表,无法区分 RPC 失败与真实无数据。
    • 安全性与潜在风险(27/30分):无 SQL 注入、XSS 等常见安全漏洞,Dubbo 接口做到了向后兼容未破坏现有契约。扣分点在于未对下游 RpcResponse 状态做校验,下游异常时静默降级为空列表存在一定的业务状态误判风险。
    • 最佳实践与可维护性(17/20分):引入 MapStruct (RecruitmentSubSceneConvert) 替代手动 builder 组装,注释与接口文档同步更新及时;但重构后遗留了未使用的私有方法 getAllowedNumsByBusinessType,且单元测试覆盖不够充分。
    • 性能与资源利用(5/5分):移除了多余的业务类型映射查询与二次遍历过滤,单次流式去重复杂度为 $O(N)$,无性能瓶颈或资源浪费。
    • 提交信息质量(5/5分):Commit 信息严格遵循 Conventional Commits 规范,标题明确,正文分点清晰列出了改动细节、原因及版本变更,可追溯性极佳。

    总分:88分

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