Commit bcf9e410 by 谢海旭

v5.7.1版本 招聘管理:新增招聘需求添加查询主营品牌逻辑、导出增加关联状态以及部分逻辑

1 parent e6caaacc
package cn.com.glsx.dj.staff.dto.recruitment;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
......@@ -18,13 +17,10 @@ public class RecruitmentDemandExportDTO implements Serializable {
private int index;
/**
* 省份
* 所属省市
*/
private String province;
/**
* 城市
*/
private String city;
private String provinceCity;
/**
* 区域运营名称
*/
......@@ -69,6 +65,12 @@ public class RecruitmentDemandExportDTO implements Serializable {
* 招聘状态,0-待人事确认 1-招聘中 2-已完成 3-已驳回
*/
private String recruitmentStatus;
/**
* 关联状态,1-已关联 0-未关联
*/
private String connectionFlag;
/**
* 招聘负责人名称|对接人力
*/
......
......@@ -257,6 +257,12 @@ public class RecruitmentDemandService {
}
}
}
// 查询门店主营品牌信息
Map<Integer, String> merchantBrandMap = merchantService.getMerchantBrandMap(Lists.newArrayList(Integer.parseInt(merchantId)), true);
if (CollectionUtil.isNotEmpty(merchantBrandMap)) {
dto.setBrand(merchantBrandMap.get(Integer.parseInt(merchantId)));
}
}
} else {
// 未创建系统门店:直接使用入参中的字段就存,不查询门店
......@@ -1360,49 +1366,72 @@ public class RecruitmentDemandService {
List<RecruitmentOnboardingPlan> plans = planMapper.selectByExample(planExample);
Map<Integer, List<RecruitmentOnboardingPlan>> demandPlansMap = plans.stream().collect(Collectors.groupingBy(RecruitmentOnboardingPlan::getDemandId));
// 查询门店信息
List<String> merchantIds = demands.stream().map(demand -> demand.getMerchantId()).distinct().collect(Collectors.toList());
RpcPagination<ListMerchantRequest> merchantPagination = new RpcPagination<>();
merchantPagination.setPageNum(1);
merchantPagination.setPageSize(merchantIds.size());
ListMerchantRequest condition = new ListMerchantRequest();
condition.setAccounttypeIdList(Arrays.asList(AccountTypeEnum.SHOP_4S.getValue(), AccountTypeEnum.YQ_SHOP.getValue(), AccountTypeEnum.VIRTUAL_YQ_SHOP.getValue()));
condition.setMerchantNoStrSet(String.join(",", merchantIds));
condition.setStatus(String.valueOf(MerchantAccountStatusEnum.HAVE_PUBLISH.getValue()));
merchantPagination.setCondition(condition);
RpcResponse<RpcPagination<MerchantRopResponse>> merchantWithPageResp = merchantRemote.listMerchantWithPage(merchantPagination);
if (!merchantWithPageResp.hasResult()) {
return dtos;
}
RpcPagination<MerchantRopResponse> merchantWithPage = merchantWithPageResp.getResult();
Map<String, MerchantRopResponse> merchantNoMap = merchantWithPage.getList().stream().collect(Collectors.toMap(MerchantRopResponse::getMerchantNo, o -> o, (o1, o2) -> o2));
// 查询门店主营品牌信息
List<Integer> merchantIdIntegerList = merchantIds.stream().map(Integer::parseInt).collect(Collectors.toList());
Map<Integer, String> merchantBrandMap = merchantService.getMerchantBrandMap(merchantIdIntegerList, true);
// 仅对系统门店创建的需求查询系统门店信息(地址、品牌、销量)
List<String> systemMerchantIds = demands.stream()
.filter(d -> !Boolean.FALSE.equals(d.getBySystemMerchant()))
.map(RecruitmentDemandPageRecordDTO::getMerchantId)
.distinct()
.collect(Collectors.toList());
Map<String, MerchantRopResponse> merchantNoMap = new HashMap<>();
HashMap<Integer, Integer> merchantSalesVolumeMap = new HashMap<>();
merchantIdIntegerList.stream().parallel().forEach(merchantId -> {
merchantSalesVolumeMap.put(merchantId, getSalesVolume(merchantId));
});
if (CollectionUtils.isNotEmpty(systemMerchantIds)) {
// 查询系统门店信息
RpcPagination<ListMerchantRequest> merchantPagination = new RpcPagination<>();
merchantPagination.setPageNum(1);
merchantPagination.setPageSize(systemMerchantIds.size());
ListMerchantRequest condition = new ListMerchantRequest();
condition.setAccounttypeIdList(Arrays.asList(AccountTypeEnum.SHOP_4S.getValue(), AccountTypeEnum.YQ_SHOP.getValue(), AccountTypeEnum.VIRTUAL_YQ_SHOP.getValue()));
condition.setMerchantNoStrSet(String.join(",", systemMerchantIds));
condition.setStatus(String.valueOf(MerchantAccountStatusEnum.HAVE_PUBLISH.getValue()));
merchantPagination.setCondition(condition);
RpcResponse<RpcPagination<MerchantRopResponse>> merchantWithPageResp = merchantRemote.listMerchantWithPage(merchantPagination);
if (merchantWithPageResp.hasResult()) {
RpcPagination<MerchantRopResponse> merchantWithPage = merchantWithPageResp.getResult();
merchantNoMap = merchantWithPage.getList().stream()
.collect(Collectors.toMap(MerchantRopResponse::getMerchantNo, o -> o, (o1, o2) -> o2));
}
// 查询系统门店主营品牌信息
List<Integer> systemMerchantIdIntegers = systemMerchantIds.stream().map(Integer::parseInt).collect(Collectors.toList());
// 查询系统门店新车销量
systemMerchantIdIntegers.stream().parallel().forEach(merchantId -> {
merchantSalesVolumeMap.put(merchantId, getSalesVolume(merchantId));
});
}
final Map<String, MerchantRopResponse> finalMerchantNoMap = merchantNoMap;
// 组装返回数据
for (RecruitmentDemandPageRecordDTO demand : demands) {
String merchantId = demand.getMerchantId();
MerchantRopResponse merchant = merchantNoMap.get(merchantId);
boolean isSystemMerchant = !Boolean.FALSE.equals(demand.getBySystemMerchant());
RecruitmentDemandExportDTO exportDTO = BeanUtil.copyProperties(demand, RecruitmentDemandExportDTO.class);
dtos.add(exportDTO);
if (Objects.nonNull(merchant)) {
exportDTO.setProvince(merchant.getProvinceName());
exportDTO.setCity(merchant.getCityName());
exportDTO.setMerchantAddress(merchant.getMerchantAddress());
if (CollectionUtil.isNotEmpty(merchantBrandMap)) {
exportDTO.setBrand(merchantBrandMap.get(Integer.parseInt(merchantId)));
if (isSystemMerchant) {
// 系统门店:从系统接口获取地址、销量
MerchantRopResponse merchant = finalMerchantNoMap.get(merchantId);
if (Objects.nonNull(merchant)) {
exportDTO.setProvinceCity(merchant.getProvinceName()+merchant.getCityName());
exportDTO.setMerchantAddress(merchant.getMerchantAddress());
}
Integer newCarSales = merchantSalesVolumeMap.get(Integer.parseInt(merchantId));
exportDTO.setNewCarSales(newCarSales != null ? newCarSales : 0);
} else {
// 非系统门店:直接取数据库字段,不查系统接口
exportDTO.setProvinceCity(demand.getProvinceCity());
exportDTO.setMerchantAddress(demand.getMerchantAddress());
exportDTO.setNewCarSales(demand.getSalesVolume() != null ? demand.getSalesVolume() : 0);
}
exportDTO.setBrand(demand.getBrand());
// 关联状态:Boolean -> 文字
Boolean connectionFlag = demand.getConnectionFlag();
exportDTO.setConnectionFlag(Boolean.TRUE.equals(connectionFlag) ? "已关联" : "未关联");
String recruiterName = exportDTO.getRecruiterName();
if (StringUtils.isBlank(recruiterName)) {
exportDTO.setRecruiterName("-");
......@@ -1410,11 +1439,6 @@ public class RecruitmentDemandService {
exportDTO.setDemandApplyTime(DateUtil.format(demand.getCreatedDate(), "yyyy/MM/dd"));
exportDTO.setRecruitmentStatus(RecruitmentDemandStatusEnum.getDisplayNameByValue(demand.getStatus()));
Integer newCarSales = merchantSalesVolumeMap.get(Integer.parseInt(merchantId));
if (Objects.isNull(newCarSales)) {
newCarSales = 0;
}
exportDTO.setNewCarSales(newCarSales);
List<RecruitmentDemandExportDTO.BaseInfo> baseInfos = new ArrayList<>();
List<RecruitmentOnboardingPlan> demandPlans = demandPlansMap.get(demand.getId());
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议

    • 问题 1:循环内调用外部服务接口,存在严重性能隐患

      • 问题描述:在 RecruitmentDemandService 的第 261 行(疑似在循环体内),代码对每个需求都调用了 merchantService.getMerchantBrandMap。虽然该方法支持批量查询,但在此处却传入了单元素的 List。
      • 影响分析:当处理大批量数据时,会产生 N 次 RPC/数据库调用,显著增加接口响应耗时,易引发连接池耗尽或上游服务超时,严重影响系统稳定性。
      • 优化建议:应将品牌查询逻辑提取到循环外,先收集所有 merchantId,一次性批量查询出结果存入 Map,再在循环中从 Map 获取。
    • 问题 2:并行流(parallelStream)使用不当,存在线程安全与性能风险

      • 问题描述:在第 1399 行,使用 systemMerchantIds.stream().parallel().forEach 向 HashMap(merchantSalesVolumeMap)中写入数据。
      • 影响分析:HashMap 非线程安全,在并行流中并发写入可能导致 size 统计错误、数据覆盖甚至触发死循环(在扩容时)。此外,若 getSalesVolume 涉及网络 IO,默认的 ForkJoinPool 可能会因阻塞导致其他并行任务响应变慢。
      • 优化建议:建议使用 ConcurrentHashMap,或者将 parallelStream 替换为普通 stream。鉴于导出场景通常对延迟有一定容忍度,普通流更安全。
    • 问题 3:类型转换未处理异常,健壮性不足

      • 问题描述:在代码中多处直接使用 Integer.parseInt(merchantId)(如第 1395, 1400, 1419 行),未进行非空校验或异常捕获。
      • 影响分析:如果 merchantId 字段包含非数字字符(如空字符串、脏数据),程序将抛出 NumberFormatException 导致整个导出流程崩溃。
      • 优化建议:建议使用 NumberUtils.toInt() 或在转换前增加正则校验/判空,并确保在数据源头保证 merchantId 的格式正确。

    二、评分明细

    • 功能实现的正确性与健壮性(32/40):逻辑基本正确,区分了系统门店与非系统门店的展示逻辑。但类型转换处缺乏健壮性,且并行流下的数据写入存在正确性风险。
    • 安全性与潜在风险(28/30):未发现 SQL 注入等重大安全漏洞。代码主要为数据组装逻辑,安全性较好。
    • 最佳实践与可维护性(15/20):代码结构清晰,DTO 字段变更符合业务需求。但循环内调用外部服务违反了基本的工程最佳实践。
    • 性能与资源利用(2/5):存在明显的循环内调用接口问题,且并行流的使用可能导致资源竞争,性能表现不佳。
    • 提交信息质量(5/5):提交信息包含了版本号、功能描述及作者,清晰准确。

    总分:82分

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