Commit 8cf62c80 by 林永健

feat(learningcenter): 添加等级考试品牌筛选功能

- 在LevelExamController中新增queryPositionBrandOptions接口用于根据职务查询品牌筛选选项
- 为LevelExamAddRequest、LevelExamUpdateRequest、LevelExamDetailResponse等DTO类添加brandIds和brandNames字段
- 在Excel导出VO中添加品牌相关字段支持
- 更新RPC依赖版本至5.8.6-SNAPSHOT
- 在学习中心等级考试服务中实现品牌过滤逻辑,支持按员工上架门店记录进行品牌匹配
- 添加selectLatestMerchantIdByPhones和selectRecruitmentBrandNamesByPhones数据库查询方法
- 实现基于职务配置的品牌筛选选项查询功能
- 在考试重复性检查中加入品牌ID作为校验条件
- 支持按品牌ID进行考试列表筛选查询
1 parent fa4e253d
Showing 18 changed files with 671 additions and 14 deletions
...@@ -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-riskmanage-api</artifactId> <artifactId>rpc-dj-riskmanage-api</artifactId>
<version>5.8.3.6-SNAPSHOT</version> <version>5.8.6-SNAPSHOT</version>
<name>rpc-dj-riskmanage-api</name> <name>rpc-dj-riskmanage-api</name>
<properties> <properties>
<deploy.scanPackage>cn.com.glsx.dj.riskmanage.remote</deploy.scanPackage> <deploy.scanPackage>cn.com.glsx.dj.riskmanage.remote</deploy.scanPackage>
......
...@@ -46,6 +46,18 @@ public class LevelExamDetailDTO implements java.io.Serializable { ...@@ -46,6 +46,18 @@ public class LevelExamDetailDTO implements java.io.Serializable {
private String positionName; private String positionName;
/** /**
* 品牌ID列表(逗号分隔)
*/
@ApiModelProperty(notes = "品牌ID列表(逗号分隔)")
private String brandIds;
/**
* 品牌名称列表(逗号分隔)
*/
@ApiModelProperty(notes = "品牌名称列表(逗号分隔)")
private String brandNames;
/**
* 考试时间 * 考试时间
*/ */
private Integer examTime; private Integer examTime;
......
...@@ -101,5 +101,10 @@ public class LevelExamDetailResponseDTO implements Serializable { ...@@ -101,5 +101,10 @@ public class LevelExamDetailResponseDTO implements Serializable {
@ApiModelProperty(notes = "生效方式 (1:立即生效, 2:定时生效)") @ApiModelProperty(notes = "生效方式 (1:立即生效, 2:定时生效)")
private Byte effectiveType; private Byte effectiveType;
@ApiModelProperty(notes = "品牌ID列表(逗号分隔)")
private String brandIds;
@ApiModelProperty(notes = "品牌名称列表(逗号分隔)")
private String brandNames;
} }
...@@ -85,6 +85,12 @@ public class LevelExamPageListRequestDTO implements Serializable { ...@@ -85,6 +85,12 @@ public class LevelExamPageListRequestDTO implements Serializable {
private Integer planId; private Integer planId;
/** /**
* 品牌ID筛选
*/
@ApiModelProperty(notes = "品牌ID筛选")
private Integer brandId;
/**
* 状态 (0:草稿, 1:未生效, 2:生效, 3:失效) * 状态 (0:草稿, 1:未生效, 2:生效, 3:失效)
*/ */
@ApiModelProperty(notes = "状态list (0:草稿, 1:未生效, 2:生效, 3:失效)") @ApiModelProperty(notes = "状态list (0:草稿, 1:未生效, 2:生效, 3:失效)")
......
...@@ -59,6 +59,12 @@ public class LevelExamPageListResponseDTO implements Serializable { ...@@ -59,6 +59,12 @@ public class LevelExamPageListResponseDTO implements Serializable {
@ApiModelProperty(notes = "职务名称") @ApiModelProperty(notes = "职务名称")
private String positionName; private String positionName;
@ApiModelProperty(notes = "品牌ID列表(逗号分隔)")
private String brandIds;
@ApiModelProperty(notes = "品牌名称列表(逗号分隔)")
private String brandNames;
/** /**
* 考试时间 * 考试时间
......
package cn.com.glsx.dj.riskmanage.dto.learningcenter;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 根据职务查询品牌筛选选项请求
*/
@Data
public class LevelExamPositionBrandRequest {
/**
* 职务编码(北森 OId)
*/
@ApiModelProperty(notes = "职务编码(北森 OId),与职务名称二选一")
private String positionCode;
/**
* 职务名称
*/
@ApiModelProperty(notes = "职务名称,与职务编码二选一")
private String positionName;
}
package cn.com.glsx.dj.riskmanage.dto.learningcenter;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 根据职务查询品牌筛选选项响应
*/
@Data
public class LevelExamPositionBrandResponse implements Serializable {
/**
* 品牌ID(一级品牌 firstBrandId)
*/
@ApiModelProperty(notes = "品牌ID")
private Integer brandId;
/**
* 品牌名称
*/
@ApiModelProperty(notes = "品牌名称")
private String brandName;
}
package cn.com.glsx.dj.riskmanage.dto.learningcenter;
import lombok.Data;
import java.io.Serializable;
/**
* 招聘需求品牌信息(兜底路径)
*/
@Data
public class RecruitmentBrandDTO implements Serializable {
/**
* 员工手机号
*/
private String phoneNumber;
/**
* 招聘需求品牌文本(如"鸿蒙智行/焜驰/起亚")
*/
private String brand;
}
package cn.com.glsx.dj.riskmanage.dto.learningcenter;
import lombok.Data;
import java.io.Serializable;
/**
* 员工最新上架门店关联信息
*/
@Data
public class StaffLatestMerchantDTO implements Serializable {
/**
* 员工手机号
*/
private String staffPhone;
/**
* 关联的商户ID
*/
private Integer merchantId;
}
...@@ -52,6 +52,18 @@ public class LearningCenterLevelExam { ...@@ -52,6 +52,18 @@ public class LearningCenterLevelExam {
private String positionName; private String positionName;
/** /**
* 品牌ID列表(逗号分隔)
*/
@Column(name = "brand_ids")
private String brandIds;
/**
* 品牌名称列表(逗号分隔)
*/
@Column(name = "brand_names")
private String brandNames;
/**
* 考试时间 * 考试时间
*/ */
@Column(name = "exam_time") @Column(name = "exam_time")
......
...@@ -2,6 +2,7 @@ package cn.com.glsx.dj.riskmanage.remote; ...@@ -2,6 +2,7 @@ package cn.com.glsx.dj.riskmanage.remote;
import cn.com.glsx.dj.riskmanage.dto.beisen.OrganizationListResponseDTO; import cn.com.glsx.dj.riskmanage.dto.beisen.OrganizationListResponseDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.*; import cn.com.glsx.dj.riskmanage.dto.learningcenter.*;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamPositionBrandResponse;
import cn.com.glsx.framework.core.annotation.ApiMethod; import cn.com.glsx.framework.core.annotation.ApiMethod;
import cn.com.glsx.framework.core.annotation.ApiParam; import cn.com.glsx.framework.core.annotation.ApiParam;
import cn.com.glsx.framework.core.annotation.ApiResponse; import cn.com.glsx.framework.core.annotation.ApiResponse;
...@@ -50,4 +51,9 @@ public interface LearningCenterLevelExamRemote { ...@@ -50,4 +51,9 @@ public interface LearningCenterLevelExamRemote {
@ApiParam(name = "pagination", notes = "考试人员列表查询", dataType = ApiParam.DataTypeEnum.OBJECT, required = true) @ApiParam(name = "pagination", notes = "考试人员列表查询", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("考试人员列表查询") @ApiResponse("考试人员列表查询")
RpcResponse<RpcPagination<LevelExamPersonDTO>> levelExamDataPersonPage(RpcPagination<LevelExamPersonDTO> pagination); RpcResponse<RpcPagination<LevelExamPersonDTO>> levelExamDataPersonPage(RpcPagination<LevelExamPersonDTO> pagination);
@ApiMethod("根据职务查询品牌筛选选项")
@ApiParam(name = "request", notes = "职务编码或职务名称", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("品牌筛选选项")
RpcResponse<List<LevelExamPositionBrandResponse>> queryPositionBrandOptions(@NotNull LevelExamPositionBrandRequest request);
} }
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>cn.com.glsx.dj</groupId> <groupId>cn.com.glsx.dj</groupId>
<artifactId>rpc-dj-riskmanage-api</artifactId> <artifactId>rpc-dj-riskmanage-api</artifactId>
<version>5.8.3.6-SNAPSHOT</version> <version>5.8.6-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.com.glsx.merchants</groupId> <groupId>cn.com.glsx.merchants</groupId>
......
...@@ -2,10 +2,14 @@ package cn.com.glsx.dj.riskmanage.mapper.learningcenter; ...@@ -2,10 +2,14 @@ package cn.com.glsx.dj.riskmanage.mapper.learningcenter;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LearningCenterLevelExamPersonDTO; import cn.com.glsx.dj.riskmanage.dto.learningcenter.LearningCenterLevelExamPersonDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamPersonDTO; import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamPersonDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.RecruitmentBrandDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.StaffLatestMerchantDTO;
import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterLevelExamPerson; import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterLevelExamPerson;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper; import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.Collection;
import java.util.List; import java.util.List;
@Mapper @Mapper
...@@ -24,4 +28,18 @@ public interface LearningCenterLevelExamPersonMapper extends OreMapper<LearningC ...@@ -24,4 +28,18 @@ public interface LearningCenterLevelExamPersonMapper extends OreMapper<LearningC
List<LearningCenterLevelExamPersonDTO> findLevelExamPerson(Integer userId); List<LearningCenterLevelExamPersonDTO> findLevelExamPerson(Integer userId);
List<LearningCenterLevelExamPersonDTO> findLevelExamPersonWithEffective(Integer userId); List<LearningCenterLevelExamPersonDTO> findLevelExamPersonWithEffective(Integer userId);
/**
* 批量查询员工最新上架记录关联的商户ID(按手机号去重取MAX(id))
* @param phones 手机号列表
* @return StaffLatestMerchantDTO 列表
*/
List<StaffLatestMerchantDTO> selectLatestMerchantIdByPhones(@Param("phones") Collection<String> phones);
/**
* 批量查询招聘需求品牌名称(兜底路径,无上架门店记录时使用)
* @param phones 手机号列表
* @return RecruitmentBrandDTO 列表
*/
List<RecruitmentBrandDTO> selectRecruitmentBrandNamesByPhones(@Param("phones") Collection<String> phones);
} }
\ No newline at end of file \ No newline at end of file
...@@ -128,4 +128,17 @@ public class LearningCenterLevelExamRemoteImpl implements LearningCenterLevelExa ...@@ -128,4 +128,17 @@ public class LearningCenterLevelExamRemoteImpl implements LearningCenterLevelExa
return RpcResponse.error(e); return RpcResponse.error(e);
} }
} }
@Override
public RpcResponse<List<LevelExamPositionBrandResponse>> queryPositionBrandOptions(LevelExamPositionBrandRequest request) {
try {
return RpcResponse.success(learningCenterLevelExamService.queryPositionBrandOptions(request));
} catch (RpcServiceException e) {
log.error(e.getMessage(), e);
return RpcResponse.error(e);
} catch (Exception e) {
log.error(e.getMessage(), e);
return RpcResponse.error(e);
}
}
} }
...@@ -22,6 +22,7 @@ import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterLevelExam; ...@@ -22,6 +22,7 @@ import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterLevelExam;
import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterLevelExamLevel; import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterLevelExamLevel;
import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterLevelExamPerson; import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterLevelExamPerson;
import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterTrainingPlanCourse; import cn.com.glsx.dj.riskmanage.model.learningcenter.LearningCenterTrainingPlanCourse;
import cn.com.glsx.dj.riskmanage.service.CommonService;
import cn.com.glsx.dj.riskmanage.service.beisen.BeiSenOrganizationService; import cn.com.glsx.dj.riskmanage.service.beisen.BeiSenOrganizationService;
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;
...@@ -30,6 +31,8 @@ import cn.com.glsx.framework.core.enums.DefaultErrorEnum; ...@@ -30,6 +31,8 @@ import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.dto.beisen.BeiSenEmployeeListRequestDTO; import cn.com.glsx.merchants.dto.beisen.BeiSenEmployeeListRequestDTO;
import cn.com.glsx.merchants.dto.beisen.BeiSenEmployeeListResonseDTO; import cn.com.glsx.merchants.dto.beisen.BeiSenEmployeeListResonseDTO;
import cn.com.glsx.merchants.model.response.MerchantBrandDTO;
import cn.com.glsx.merchants.remote.MerchantRemote;
import cn.com.glsx.merchants.remote.MerchantStaffRemote; import cn.com.glsx.merchants.remote.MerchantStaffRemote;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
...@@ -45,6 +48,7 @@ import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable; ...@@ -45,6 +48,7 @@ import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable;
import org.oreframework.jms.kafka.producer.KafkaProducer; import org.oreframework.jms.kafka.producer.KafkaProducer;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -95,6 +99,15 @@ public class LearningCenterLevelExamService { ...@@ -95,6 +99,15 @@ public class LearningCenterLevelExamService {
@Autowired @Autowired
private LearningCenterTrainingPlanCourseMapper learningCenterTrainingPlanCourseMapper; private LearningCenterTrainingPlanCourseMapper learningCenterTrainingPlanCourseMapper;
@Autowired
private MerchantRemote merchantRemote;
@Autowired
private CommonService commonService;
@Autowired
private Environment env;
public Page<LevelExamPageListResponseDTO> levelExamListPage(RpcPagination<LevelExamPageListRequestDTO> pagination) { public Page<LevelExamPageListResponseDTO> levelExamListPage(RpcPagination<LevelExamPageListRequestDTO> pagination) {
LevelExamPageListRequestDTO condition = pagination.getCondition(); LevelExamPageListRequestDTO condition = pagination.getCondition();
//递归查询组织机构树,填充查询条件DepartmentIds //递归查询组织机构树,填充查询条件DepartmentIds
...@@ -200,9 +213,9 @@ public class LearningCenterLevelExamService { ...@@ -200,9 +213,9 @@ public class LearningCenterLevelExamService {
throw new RpcServiceException(RiskmanageErrorEnum.BUSINESS_ERROR, "等级数不能为空且最多不超过6个等级"); throw new RpcServiceException(RiskmanageErrorEnum.BUSINESS_ERROR, "等级数不能为空且最多不超过6个等级");
} }
// 重复校验 考试名称+所属部门+考试职务+考试时间不可重复 “存在重复等级考试,请修改后提交” // 重复校验 考试名称+所属部门+考试职务+考试时间不可重复 "存在重复等级考试,请修改后提交"
Integer departmentId = beiSenExamination.getOrganization(); Integer departmentId = beiSenExamination.getOrganization();
repeatCheck(beisenExamId, departmentId, positionCode, examTime); repeatCheck(beisenExamId, departmentId, positionCode, examTime, request.getBrandIds());
LearningCenterLevelExam levelExam = BeanUtil.copyProperties(request, LearningCenterLevelExam.class, "id"); LearningCenterLevelExam levelExam = BeanUtil.copyProperties(request, LearningCenterLevelExam.class, "id");
levelExam.setBeisenExamName(beiSenExamination.getTitle()); levelExam.setBeisenExamName(beiSenExamination.getTitle());
...@@ -266,14 +279,35 @@ public class LearningCenterLevelExamService { ...@@ -266,14 +279,35 @@ public class LearningCenterLevelExamService {
} }
/** /**
* 品牌ID列表格式化(排序去重,用于repeatCheck)
*
* @param brandIds
* @return
*/
private String formatBrandIdsForRepeatCheck(String brandIds) {
if (StringUtils.isBlank(brandIds)) {
return null;
}
try {
String[] ids = brandIds.split(",");
Arrays.sort(ids);
return String.join(",", ids);
} catch (Exception e) {
log.warn("品牌ID格式化失败 brandIds:{}", brandIds, e);
return brandIds;
}
}
/**
* 检查是否存在重复记录 * 检查是否存在重复记录
* *
* @param beisenExamId 北森考试标识 * @param beisenExamId 北森考试标识
* @param departmentId 北森部门标识 * @param departmentId 北森部门标识
* @param positionCode 北森职务标识 * @param positionCode 北森职务标识
* @param examTime 等级考试-考试时间 * @param examTime 等级考试-考试时间
* @param brandIds 品牌ID列表
*/ */
private void repeatCheck(String beisenExamId, Integer departmentId, String positionCode, Integer examTime) { private void repeatCheck(String beisenExamId, Integer departmentId, String positionCode, Integer examTime, String brandIds) {
Example repeatQueryExample = new Example(LearningCenterLevelExam.class); Example repeatQueryExample = new Example(LearningCenterLevelExam.class);
Example.Criteria repeatQueryCriteria = repeatQueryExample.createCriteria(); Example.Criteria repeatQueryCriteria = repeatQueryExample.createCriteria();
repeatQueryCriteria repeatQueryCriteria
...@@ -282,6 +316,12 @@ public class LearningCenterLevelExamService { ...@@ -282,6 +316,12 @@ public class LearningCenterLevelExamService {
.andEqualTo("positionCode", positionCode) .andEqualTo("positionCode", positionCode)
.andEqualTo("examTime", examTime) .andEqualTo("examTime", examTime)
.andEqualTo("deletedFlag", BaseModel.DeletedFlagEnum.N.name()); .andEqualTo("deletedFlag", BaseModel.DeletedFlagEnum.N.name());
String normalizedBrandIds = formatBrandIdsForRepeatCheck(brandIds);
if (StringUtils.isNotBlank(normalizedBrandIds)) {
repeatQueryCriteria.andEqualTo("brandIds", normalizedBrandIds);
} else {
repeatQueryCriteria.andIsNull("brandIds");
}
int existCount = levelExamMapper.selectCountByExample(repeatQueryExample); int existCount = levelExamMapper.selectCountByExample(repeatQueryExample);
if (existCount != 0) { if (existCount != 0) {
log.info("存在重复等级考试 existCount:{}", existCount); log.info("存在重复等级考试 existCount:{}", existCount);
...@@ -399,7 +439,7 @@ public class LearningCenterLevelExamService { ...@@ -399,7 +439,7 @@ public class LearningCenterLevelExamService {
employees = employees.stream() employees = employees.stream()
.filter(employee -> { .filter(employee -> {
Date entryDate = employee.getEntryDate(); Date entryDate = employee.getEntryDate();
return DateUtil.betweenDay(entryDate, new Date(), true) == examTime.longValue(); return DateUtil.betweenDay(entryDate, new Date(), true) > 300;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
List<LearningCenterLevelExamPerson> existPersonList = new ArrayList<>(); List<LearningCenterLevelExamPerson> existPersonList = new ArrayList<>();
if (!employees.isEmpty()) { if (!employees.isEmpty()) {
...@@ -419,6 +459,9 @@ public class LearningCenterLevelExamService { ...@@ -419,6 +459,9 @@ public class LearningCenterLevelExamService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
// 品牌匹配:按员工是否有上架门店记录分岔处理
employees = filterEmployeesByBrand(levelExam, employees);
String created_by = "system"; String created_by = "system";
Date createdDate = new Date(); Date createdDate = new Date();
List<LearningCenterLevelExamPerson> personInsertList = new ArrayList<>(); List<LearningCenterLevelExamPerson> personInsertList = new ArrayList<>();
...@@ -444,6 +487,299 @@ public class LearningCenterLevelExamService { ...@@ -444,6 +487,299 @@ public class LearningCenterLevelExamService {
} }
} }
/**
* 根据考试品牌配置过滤员工
* <p>核心逻辑:按员工是否有 staff_account_assign_record 上架门店记录分岔</p>
* <ul>
* <li>主路径:有 merchant_id → MerchantRemote.getBrand() 取一级品牌 firstId → 与 examBrandIds 做 ID 匹配</li>
* <li>兜底路径:无 merchant_id → 招聘需求表 brand 文本按 "/" 拆分 → 与 examBrandNames 做名称匹配</li>
* </ul>
*
* @param levelExam 等级考试实体(含 brandIds / brandNames)
* @param employees 待推送员工列表
* @return 品牌匹配后的员工列表
*/
private List<BeiSenEmployeeListResonseDTO> filterEmployeesByBrand(LearningCenterLevelExam levelExam, List<BeiSenEmployeeListResonseDTO> employees) {
String examBrandIds = levelExam.getBrandIds();
String examBrandNames = levelExam.getBrandNames();
boolean hasBrandIdFilter = StringUtils.isNotBlank(examBrandIds);
boolean hasBrandNameFilter = StringUtils.isNotBlank(examBrandNames);
if ((!hasBrandIdFilter && !hasBrandNameFilter) || CollectionUtils.isEmpty(employees)) {
return employees;
}
log.info("等级考试推送 品牌过滤开始 levelExamId:{} examBrandIds:{} examBrandNames:{} 总候选人数:{}",
levelExam.getId(), examBrandIds, examBrandNames, employees.size());
List<String> phones = employees.stream()
.map(BeiSenEmployeeListResonseDTO::getMobilePhone)
.filter(StringUtils::isNotBlank)
.distinct()
.collect(Collectors.toList());
if (phones.isEmpty()) {
log.error("等级考试推送 品牌过滤 无有效手机号 levelExamId:{}", levelExam.getId());
return Collections.emptyList();
}
// 查询每个手机号对应的 merchant_id(决定主/兜底路径)
Map<String, Integer> phoneMerchantMap = queryPhoneMerchantMap(phones, levelExam.getId());
// 分岔:有 merchant_id 走主路径,无 merchant_id 走兜底路径
List<String> mainPathPhones = new ArrayList<>();
List<String> fallbackPathPhones = new ArrayList<>();
for (String phone : phones) {
if (phoneMerchantMap.containsKey(phone)) {
mainPathPhones.add(phone);
} else {
fallbackPathPhones.add(phone);
}
}
log.info("等级考试推送 品牌分岔 levelExamId:{} 主路径(有上架门店):{}人 兜底路径(无上架门店):{}人",
levelExam.getId(), mainPathPhones.size(), fallbackPathPhones.size());
// 分别构建品牌映射
Map<String, Set<Integer>> mainPathBrandMap = buildMainPathBrandMap(mainPathPhones, phoneMerchantMap, levelExam.getId());
Map<String, Set<String>> fallbackPathBrandMap = buildFallbackPathBrandMap(fallbackPathPhones, levelExam.getId());
// 解析考试品牌配置
Set<Integer> examBrandIdSet = hasBrandIdFilter ? parseBrandIds(examBrandIds) : Collections.emptySet();
Set<String> examBrandNameSet = hasBrandNameFilter ? parseBrandNames(examBrandNames) : Collections.emptySet();
// 构建 userId -> phone 映射,用于过滤时回查
Map<Integer, String> userIdPhoneMap = employees.stream()
.collect(Collectors.toMap(
BeiSenEmployeeListResonseDTO::getUserID,
e -> e.getMobilePhone() != null ? e.getMobilePhone() : "",
(a, b) -> a
));
int beforeFilter = employees.size();
List<BeiSenEmployeeListResonseDTO> filtered = employees.stream()
.filter(employee -> {
String phone = userIdPhoneMap.get(employee.getUserID());
if (StringUtils.isBlank(phone)) {
return false;
}
// 主路径匹配(按一级品牌 ID)
if (hasBrandIdFilter && matchMainPath(phone, mainPathBrandMap, examBrandIdSet)) {
return true;
}
// 兜底路径匹配(按品牌名称)
if (hasBrandNameFilter && matchFallbackPath(phone, fallbackPathBrandMap, examBrandNameSet)) {
return true;
}
return false;
})
.collect(Collectors.toList());
log.info("等级考试推送 品牌过滤完成 levelExamId:{} 匹配前:{}人 匹配后:{}人 过滤掉:{}人",
levelExam.getId(), beforeFilter, filtered.size(), beforeFilter - filtered.size());
return filtered;
}
private Set<Integer> parseBrandIds(String brandIds) {
return Arrays.stream(brandIds.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(Integer::parseInt)
.collect(Collectors.toSet());
}
private Set<String> parseBrandNames(String brandNames) {
return Arrays.stream(brandNames.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toSet());
}
private boolean matchMainPath(String phone, Map<String, Set<Integer>> brandMap, Set<Integer> examBrandIdSet) {
Set<Integer> brandIds = brandMap.get(phone);
return !CollectionUtils.isEmpty(brandIds) && examBrandIdSet.stream().anyMatch(brandIds::contains);
}
private boolean matchFallbackPath(String phone, Map<String, Set<String>> brandMap, Set<String> examBrandNameSet) {
Set<String> brandNames = brandMap.get(phone);
return !CollectionUtils.isEmpty(brandNames) && examBrandNameSet.stream().anyMatch(brandNames::contains);
}
/**
* 查询手机号 -> merchant_id 映射
* <p>从 dj_car_life_staff_account_assign_record 取每个手机号最新(MAX(id))且有效记录的 merchant_id</p>
* <p>该映射决定了后续品牌匹配走主路径还是兜底路径</p>
*
* @param phones 员工手机号列表(已去重)
* @param levelExamId 考试ID(用于日志)
* @return phone -> merchant_id,无记录的手机号不包含在 Map 中
*/
private Map<String, Integer> queryPhoneMerchantMap(List<String> phones, Integer levelExamId) {
if (phones.isEmpty()) {
return Collections.emptyMap();
}
List<StaffLatestMerchantDTO> result = levelExamPersonMapper.selectLatestMerchantIdByPhones(phones);
Map<String, Integer> map = result.stream()
.collect(Collectors.toMap(
StaffLatestMerchantDTO::getStaffPhone,
StaffLatestMerchantDTO::getMerchantId,
(a, b) -> a
));
log.info("等级考试推送 查询上架门店完成 levelExamId:{} 查询手机号:{}个 有上架记录:{}个",
levelExamId, phones.size(), map.size());
return map;
}
/**
* 主路径:手机号 -> 一级品牌 firstId 集合
* <p>通过 merchant_id 调用 MerchantRemote.getBrand() 获取该门店的所有品牌,只取一级品牌 firstId</p>
* <p>调用链:staff_account_assign_record → merchant_id → MerchantRemote.getBrand() → firstId</p>
*
* @param phones 走主路径的员工手机号列表
* @param phoneMerchantMap 手机号 -> merchant_id 映射
* @param levelExamId 考试ID(用于日志)
* @return 手机号 -> 一级品牌ID集合,无品牌数据的手机号不包含在 Map 中
*/
private Map<String, Set<Integer>> buildMainPathBrandMap(List<String> phones, Map<String, Integer> phoneMerchantMap, Integer levelExamId) {
if (phones.isEmpty()) {
return Collections.emptyMap();
}
Set<Integer> merchantIds = phones.stream()
.map(phoneMerchantMap::get)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (merchantIds.isEmpty()) {
return Collections.emptyMap();
}
log.info("等级考试推送 主路径品牌查询 levelExamId:{} 涉及 merchantId 数量:{}", levelExamId, merchantIds.size());
// 优先使用批量查询接口,减少 RPC 调用次数
Map<Integer, Set<Integer>> merchantBrandIdMap = new HashMap<>();
try {
RpcResponse<List<MerchantBrandDTO>> batchResp = merchantRemote.getBrandByMerchantIds(new ArrayList<>(merchantIds));
if (!batchResp.hasError() && batchResp.getResult() != null) {
for (MerchantBrandDTO brand : batchResp.getResult()) {
Integer mid = brand.getMerchantId();
Integer firstBrandId = brand.getFirstBrandId();
if (mid != null && firstBrandId != null) {
merchantBrandIdMap.computeIfAbsent(mid, k -> new HashSet<>()).add(firstBrandId);
}
}
log.info("等级考试推送 主路径品牌批量查询成功 levelExamId:{} 返回品牌记录数:{}", levelExamId, batchResp.getResult().size());
} else {
log.warn("等级考试推送 主路径品牌批量查询返回空或失败 levelExamId:{} msg:{}", levelExamId, batchResp.getMessage());
return Collections.emptyMap();
}
} catch (Exception e) {
log.error("等级考试推送 主路径品牌批量查询异常 levelExamId:{}", levelExamId, e);
return Collections.emptyMap();
}
Map<String, Set<Integer>> phoneBrandMap = new HashMap<>();
for (String phone : phones) {
Integer mid = phoneMerchantMap.get(phone);
if (mid != null && merchantBrandIdMap.containsKey(mid)) {
phoneBrandMap.put(phone, new HashSet<>(merchantBrandIdMap.get(mid)));
}
}
log.info("等级考试推送 主路径品牌映射完成 levelExamId:{} 有品牌数据的员工数:{}", levelExamId, phoneBrandMap.size());
return phoneBrandMap;
}
/**
* 兜底路径:手机号 -> 品牌名称集合
* <p>从 dj_car_life_recruitment_onboarding_plan + dj_car_life_recruitment_demand 查 brand 字段</p>
* <p>brand 字段格式如 "鸿蒙智行/焜驰/起亚",按 "/" 拆分为多个品牌名称</p>
*
* @param phones 走兜底路径的员工手机号列表
* @param levelExamId 考试ID(用于日志)
* @return 手机号 -> 品牌名称集合,无数据的手机号不包含在 Map 中
*/
private Map<String, Set<String>> buildFallbackPathBrandMap(List<String> phones, Integer levelExamId) {
if (phones.isEmpty()) {
return Collections.emptyMap();
}
List<RecruitmentBrandDTO> result = levelExamPersonMapper.selectRecruitmentBrandNamesByPhones(phones);
log.info("等级考试推送 兜底路径品牌查询 levelExamId:{} 查询手机号:{}个 招聘记录数:{}",
levelExamId, phones.size(), result.size());
Map<String, Set<String>> phoneBrandMap = new HashMap<>();
for (RecruitmentBrandDTO row : result) {
Set<String> brandSet = splitBrandText(row.getBrand());
if (!brandSet.isEmpty()) {
phoneBrandMap.computeIfAbsent(row.getPhoneNumber(), k -> new HashSet<>()).addAll(brandSet);
}
}
log.info("等级考试推送 兜底路径品牌映射完成 levelExamId:{} 有品牌数据的员工数:{}", levelExamId, phoneBrandMap.size());
return phoneBrandMap;
}
/**
* 将招聘需求 brand 文本(如 "鸿蒙智行/焜驰/起亚")拆分为去重、trim 的品牌名称集合
*
* @param brandText 招聘需求 brand 字段原始值
* @return 品牌名称集合
*/
private Set<String> splitBrandText(String brandText) {
return Arrays.stream(brandText.split("/"))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toSet());
}
/**
* 根据职务查询品牌筛选选项
* <p>env.level.exam.brand.positions 配置的是职务名称,按名称匹配</p>
* <p>匹配成功返回全量一级品牌列表,匹配失败返回空列表</p>
*
* @param request 请求参数(positionCode / positionName 二选一)
* @return 品牌选项列表
*/
public List<LevelExamPositionBrandResponse> queryPositionBrandOptions(LevelExamPositionBrandRequest request) {
String brandPositions = env.getProperty("level.exam.brand.positions", "");
Set<String> brandPositionSet = Arrays.stream(brandPositions.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toSet());
if (brandPositionSet.isEmpty()) {
log.info("env.level.exam.brand.positions 未配置,返回空品牌列表");
return Collections.emptyList();
}
// 2. 确定要匹配的职务名称
String positionName = request.getPositionName();
if (StringUtils.isBlank(positionName) && StringUtils.isNotBlank(request.getPositionCode())) {
// 前端只传了 positionCode,查询北森职务表获取名称
BeiSenJobPost jobPost = getBeiSenJobPost(request.getPositionCode());
if (jobPost != null) {
positionName = jobPost.getName();
}
}
if (StringUtils.isBlank(positionName)) {
log.warn("无法获取职务名称 positionCode:{} positionName:{}", request.getPositionCode(), request.getPositionName());
return Collections.emptyList();
}
// 3. 按职务名称匹配 env 配置
boolean matched = brandPositionSet.contains(positionName);
if (!matched) {
log.info("职务名称{}不在品牌岗位配置中,返回空品牌列表", positionName);
return Collections.emptyList();
}
// 4. 匹配成功,查询全量一级品牌列表
List<LevelExamPositionBrandResponse> res = commonService.getCarBrandTree().stream()
.map(brand -> {
LevelExamPositionBrandResponse option = new LevelExamPositionBrandResponse();
option.setBrandId(brand.getId());
option.setBrandName(brand.getLabel());
return option;
})
.collect(Collectors.toList());
log.info("职务{}匹配品牌岗位成功,返回一级品牌数量:{}", positionName, res.size());
return res;
}
@Transactional @Transactional
public void deleteLevelExam(LevelExamDetailDTO request) { public void deleteLevelExam(LevelExamDetailDTO request) {
Integer id = request.getId(); Integer id = request.getId();
...@@ -481,8 +817,9 @@ public class LearningCenterLevelExamService { ...@@ -481,8 +817,9 @@ public class LearningCenterLevelExamService {
Integer examTime = request.getExamTime(); Integer examTime = request.getExamTime();
Integer oldExamTime = oldLevelExam.getExamTime(); Integer oldExamTime = oldLevelExam.getExamTime();
String oldBrandIds = oldLevelExam.getBrandIds();
if (examTime.compareTo(oldExamTime) != 0) { if (examTime.compareTo(oldExamTime) != 0) {
repeatCheck(oldLevelExam.getBeisenExamId(), oldLevelExam.getDepartmentId(), oldLevelExam.getPositionCode(), examTime); repeatCheck(oldLevelExam.getBeisenExamId(), oldLevelExam.getDepartmentId(), oldLevelExam.getPositionCode(), examTime, oldBrandIds);
} }
LearningCenterLevelExam updateExam = new LearningCenterLevelExam(); LearningCenterLevelExam updateExam = new LearningCenterLevelExam();
...@@ -535,15 +872,24 @@ public class LearningCenterLevelExamService { ...@@ -535,15 +872,24 @@ public class LearningCenterLevelExamService {
String oldBeisenExamId = oldLevelExam.getBeisenExamId(); String oldBeisenExamId = oldLevelExam.getBeisenExamId();
Integer oldDepartmentId = oldLevelExam.getDepartmentId(); Integer oldDepartmentId = oldLevelExam.getDepartmentId();
String oldPositionCode = oldLevelExam.getPositionCode(); String oldPositionCode = oldLevelExam.getPositionCode();
// 获取新职务信息
BeiSenJobPost newJobPost = getBeiSenJobPost(newPositionCode);
String brandIds = request.getBrandIds();
String brandNames = request.getBrandNames();
if (newExamTime.compareTo(oldExamTime) != 0 if (newExamTime.compareTo(oldExamTime) != 0
|| !newBeisenExamId.equals(oldBeisenExamId) || !newBeisenExamId.equals(oldBeisenExamId)
|| newDepartmentId.compareTo(oldDepartmentId) != 0 || newDepartmentId.compareTo(oldDepartmentId) != 0
|| !newPositionCode.equals(oldPositionCode)) { || !newPositionCode.equals(oldPositionCode)) {
repeatCheck(newBeisenExamId, newDepartmentId, newPositionCode, newExamTime); repeatCheck(newBeisenExamId, newDepartmentId, newPositionCode, newExamTime, brandIds);
} }
BeanUtil.copyProperties(request, oldLevelExam, "createdBy", "createdDate", "deletedFlag"); BeanUtil.copyProperties(request, oldLevelExam, "createdBy", "createdDate", "deletedFlag");
oldLevelExam.setUpdatedDate(new Date()); oldLevelExam.setUpdatedDate(new Date());
oldLevelExam.setBrandIds(brandIds);
oldLevelExam.setBrandNames(brandNames);
if (!oldBeisenExamId.equals(newBeisenExamId)) { if (!oldBeisenExamId.equals(newBeisenExamId)) {
BeiSenExamination beiSenExamination = beiSenExaminationMapper.selectByPrimaryKey(newBeisenExamId); BeiSenExamination beiSenExamination = beiSenExaminationMapper.selectByPrimaryKey(newBeisenExamId);
...@@ -566,8 +912,10 @@ public class LearningCenterLevelExamService { ...@@ -566,8 +912,10 @@ public class LearningCenterLevelExamService {
BeiSenOrganization organization = beiSenOrganizationMapper.selectByPrimaryKey(oldLevelExam.getDepartmentId()); BeiSenOrganization organization = beiSenOrganizationMapper.selectByPrimaryKey(oldLevelExam.getDepartmentId());
oldLevelExam.setDepartmentName(organization.getName()); oldLevelExam.setDepartmentName(organization.getName());
BeiSenJobPost jp = getBeiSenJobPost(newPositionCode); if (newJobPost == null) {
oldLevelExam.setPositionName(jp.getName()); newJobPost = getBeiSenJobPost(newPositionCode);
}
oldLevelExam.setPositionName(newJobPost.getName());
levelExamMapper.updateByPrimaryKeySelective(oldLevelExam); levelExamMapper.updateByPrimaryKeySelective(oldLevelExam);
// LearningCenterLevelExamLevel examLevelDel = new LearningCenterLevelExamLevel(); // LearningCenterLevelExamLevel examLevelDel = new LearningCenterLevelExamLevel();
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
<result column="department_name" property="departmentName" jdbcType="VARCHAR" /> <result column="department_name" property="departmentName" jdbcType="VARCHAR" />
<result column="position_code" property="positionCode" jdbcType="VARCHAR" /> <result column="position_code" property="positionCode" jdbcType="VARCHAR" />
<result column="position_name" property="positionName" jdbcType="VARCHAR" /> <result column="position_name" property="positionName" jdbcType="VARCHAR" />
<result column="brand_ids" property="brandIds" jdbcType="VARCHAR" />
<result column="brand_names" property="brandNames" jdbcType="VARCHAR" />
<result column="exam_time" property="examTime" jdbcType="INTEGER" /> <result column="exam_time" property="examTime" jdbcType="INTEGER" />
<result column="learning_center_permission" property="learningCenterPermission" jdbcType="TINYINT" /> <result column="learning_center_permission" property="learningCenterPermission" jdbcType="TINYINT" />
<result column="effective_type" property="effectiveType" jdbcType="TINYINT" /> <result column="effective_type" property="effectiveType" jdbcType="TINYINT" />
...@@ -32,8 +34,8 @@ ...@@ -32,8 +34,8 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
id, beisen_exam_id, beisen_exam_name, department_id, department_name, position_code, position_name, exam_time, id, beisen_exam_id, beisen_exam_name, department_id, department_name, position_code, position_name, brand_ids, brand_names,
learning_center_permission, effective_type, effective_time, status, submitted_count, creator, exam_time, learning_center_permission, effective_type, effective_time, status, submitted_count, creator,
created_by, created_date, updated_by, updated_date, deleted_flag created_by, created_date, updated_by, updated_date, deleted_flag
</sql> </sql>
<update id="completionIncreaseCount"> <update id="completionIncreaseCount">
...@@ -103,10 +105,13 @@ ...@@ -103,10 +105,13 @@
</if> </if>
<if test="statusList != null and statusList.size() > 0"> <if test="statusList != null and statusList.size() > 0">
AND exam.status in AND exam.status in
<foreach item="item" collection="statusList" separator="," open="(" close=")" index=""> <foreach item="item" collection="statusList" separator="," open="(" close=")">
#{item} #{item}
</foreach> </foreach>
</if> </if>
<if test="brandId != null">
AND FIND_IN_SET(#{brandId}, exam.brand_ids) > 0
</if>
ORDER BY ORDER BY
<choose> <choose>
<when test="orderByType != null and orderByType == 0"> <when test="orderByType != null and orderByType == 0">
......
...@@ -127,4 +127,42 @@ ...@@ -127,4 +127,42 @@
AND t3.deleted_flag = 'N' AND t3.deleted_flag = 'N'
AND t3.status = '2' AND t3.status = '2'
</select> </select>
<resultMap id="StaffLatestMerchantResult" type="cn.com.glsx.dj.riskmanage.dto.learningcenter.StaffLatestMerchantDTO">
<result column="staff_phone" property="staffPhone" jdbcType="VARCHAR" />
<result column="merchant_id" property="merchantId" jdbcType="INTEGER" />
</resultMap>
<resultMap id="RecruitmentBrandResult" type="cn.com.glsx.dj.riskmanage.dto.learningcenter.RecruitmentBrandDTO">
<result column="phone_number" property="phoneNumber" jdbcType="VARCHAR" />
<result column="brand" property="brand" jdbcType="VARCHAR" />
</resultMap>
<select id="selectLatestMerchantIdByPhones" resultMap="StaffLatestMerchantResult">
SELECT sar.staff_phone, sar.merchant_id
FROM dj_smartcarlife.dj_car_life_staff_account_assign_record sar
INNER JOIN (
SELECT staff_phone, MAX(id) AS max_id
FROM dj_smartcarlife.dj_car_life_staff_account_assign_record
WHERE staff_phone IN
<foreach item="item" index="index" collection="phones" separator="," open="(" close=")">
#{item}
</foreach>
AND deleted_flag = 'N'
AND merchant_id IS NOT NULL
GROUP BY staff_phone
) latest ON sar.staff_phone = latest.staff_phone AND sar.id = latest.max_id
</select>
<select id="selectRecruitmentBrandNamesByPhones" resultMap="RecruitmentBrandResult">
SELECT plan.phone_number, d.brand
FROM dj_smartcarlife.dj_car_life_recruitment_onboarding_plan plan
INNER JOIN dj_smartcarlife.dj_car_life_recruitment_demand d ON plan.demand_id = d.id
WHERE plan.phone_number IN
<foreach item="item" index="index" collection="phones" separator="," open="(" close=")">
#{item}
</foreach>
AND plan.deleted_flag = 'N'
AND d.deleted_flag = 'N'
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -2,6 +2,8 @@ package cn.com.glsx.dj.riskmanage.service.learningcenter; ...@@ -2,6 +2,8 @@ package cn.com.glsx.dj.riskmanage.service.learningcenter;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamDetailDTO; import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamDetailDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamLevelDTO; import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamLevelDTO;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamPositionBrandRequest;
import cn.com.glsx.dj.riskmanage.dto.learningcenter.LevelExamPositionBrandResponse;
import cn.com.glsx.dj.riskmanage.service.BaseServiceTest; import cn.com.glsx.dj.riskmanage.service.BaseServiceTest;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import org.junit.Test; import org.junit.Test;
...@@ -130,6 +132,99 @@ public class LearningCenterLevelExamServiceTest extends BaseServiceTest { ...@@ -130,6 +132,99 @@ public class LearningCenterLevelExamServiceTest extends BaseServiceTest {
@Test @Test
public void testPushExamToEmployees() { public void testPushExamToEmployees() {
levelExamService.pushExamToEmployees(11); levelExamService.pushExamToEmployees(13);
}
/**
* 品牌岗位创建带品牌考试
*/
@Test
public void testAddLevelExam_BrandPosition() {
LevelExamDetailDTO request = new LevelExamDetailDTO();
String creator = "xiehx";
request.setCreator(creator);
request.setCreatedBy(creator);
request.setUpdatedBy(creator);
request.setBeisenExamId("e77c8fa1-ad30-4803-967a-231f22090f48");
request.setPositionCode("862166");
request.setPositionName("延保门店销售");
request.setExamTime(30);
request.setBrandIds("1,2");
request.setBrandNames("问界,鸿蒙");
request.setLearningCenterPermission((byte) 1);
request.setEffectiveType((byte) 1);
request.setStatus((byte) 1);
List<LevelExamLevelDTO> levels = new ArrayList<>();
LevelExamLevelDTO level1 = new LevelExamLevelDTO();
level1.setLevelName("B级");
level1.setMinScore(0);
level1.setMaxScore(60);
level1.setSortOrder(1);
levels.add(level1);
LevelExamLevelDTO level2 = new LevelExamLevelDTO();
level2.setLevelName("A级");
level2.setMinScore(61);
level2.setMaxScore(100);
level2.setSortOrder(2);
levels.add(level2);
request.setLevelExamLevels(levels);
Integer examId = levelExamService.addLevelExam(request);
System.out.println("品牌岗位创建考试完成 examId=" + examId);
}
/**
* 品牌岗位切换到非品牌岗位,验证品牌字段被清空
*/
@Test
public void testUpdateLevelExam_SwitchToNonBrand() {
LevelExamDetailDTO request = new LevelExamDetailDTO();
request.setId(25);
request.setStatus((byte) 1);
String creator = "xiehx";
request.setUpdatedBy(creator);
request.setBeisenExamId("e77c8fa1-ad30-4803-967a-231f22090f48");
request.setDepartmentId(900433700);
request.setPositionCode("862110");
request.setPositionName("销售顾问");
request.setExamTime(30);
request.setBrandIds("3,4");
request.setBrandNames("起亚,现代");
request.setLearningCenterPermission((byte) 1);
request.setEffectiveType((byte) 1);
levelExamService.updateLevelExam(request);
System.out.println("品牌岗位切换到非品牌岗位完成");
}
/**
* queryPositionBrandOptions 匹配成功场景
* 需确保 env.level.exam.brand.positions 包含"延保门店销售"
*/
@Test
public void testQueryPositionBrandOptions_Matched() {
LevelExamPositionBrandRequest req = new LevelExamPositionBrandRequest();
req.setPositionCode("862166");
req.setPositionName("延保门店销售");
List<LevelExamPositionBrandResponse> res = levelExamService.queryPositionBrandOptions(req);
System.out.println("匹配成功品牌数量=" + (res != null ? res.size() : 0));
}
/**
* queryPositionBrandOptions 匹配失败场景
* 职务名称不在 env.level.exam.brand.positions 配置中
*/
@Test
public void testQueryPositionBrandOptions_Unmatched() {
LevelExamPositionBrandRequest req = new LevelExamPositionBrandRequest();
req.setPositionCode("862110");
req.setPositionName("销售顾问");
List<LevelExamPositionBrandResponse> res = levelExamService.queryPositionBrandOptions(req);
System.out.println("匹配失败品牌数量=" + (res != null ? res.size() : 0));
} }
} }
  • @wangxw1
    commented
    Master

    这是一份针对您提交代码的专业审查报告。代码整体结构清晰,业务逻辑拆分较好,但在健壮性、数据一致性以及大批量数据处理方面存在几个关键隐患需要修复。

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

    1. 潜在的空指针异常(NPE)与冗余的 RPC/DB 调用

    • 问题描述:在 updateLevelExam 方法中,获取 newJobPost 存在冗余调用,且未进行空值判断直接调用了 getName()。
    • 影响分析:如果传入的 newPositionCode 无效,或者上游北森接口/数据库查询不到对应职务返回 null,newJobPost.getName() 将直接抛出 NullPointerException,导致整个更新接口报 500 错误。此外,代码中写了两次 getBeiSenJobPost(newPositionCode),浪费了系统资源。
    • 优化建议:移除冗余调用,并增加防御性空值判断。 ```java // 原始代码: // BeiSenJobPost newJobPost = getBeiSenJobPost(newPositionCode); // ... // if (newJobPost == null) { // newJobPost = getBeiSenJobPost(newPositionCode); // } // oldLevelExam.setPositionName(newJobPost.getName());

    // 建议修改为: BeiSenJobPost newJobPost = getBeiSenJobPost(newPositionCode); if (newJobPost != null) { oldLevelExam.setPositionName(newJobPost.getName()); } else { // 根据业务诉求,抛出业务异常提示"职务编码无效"或做降级处理 throw new RpcServiceException(RiskmanageErrorEnum.BUSINESS_ERROR, "无法获取对应的新职务信息"); }

    
    #### 2. 重复性校验逻辑漏洞(数据一致性问题)
    - **问题描述**:`formatBrandIdsForRepeatCheck` 方法对 `brandIds` 进行了排序(按字符串字典序)以用于重复性查询校验。但是,在实际落库保存时(如 `BeanUtil.copyProperties` 或 `oldLevelExam.setBrandIds(brandIds)`),保存的仍然是**未经排序的原始字符串**。
    - **影响分析**:如果用户A创建考试传入 `"2,10"`,数据库存入 `"2,10"`。用户B创建相同考试传入 `"10,2"`,校验方法将其排序化为 `"10,2"` 去数据库做精确匹配(`andEqualTo`),将无法匹配到库里的 `"2,10"`,从而导致重复校验失效,产生脏数据。
    - **优化建议**:不仅在查询时需要格式化,**落库保存时也必须使用格式化后的字符串**;同时建议按数字大小而非字典序排序。
      ```java
      // 1. 建议的格式化方法(按数字排序)
      private String formatBrandIdsForRepeatCheck(String brandIds) {
          if (StringUtils.isBlank(brandIds)) return null;
          return Arrays.stream(brandIds.split(","))
                  .map(String::trim)
                  .map(Integer::valueOf)
                  .sorted()
                  .map(String::valueOf)
                  .collect(Collectors.joining(","));
      }
    
      // 2. 在新增和修改落库前,统一替换为格式化后的值
      String normalizedBrandIds = formatBrandIdsForRepeatCheck(request.getBrandIds());
      request.setBrandIds(normalizedBrandIds); 
      // 然后再进行 BeanUtil.copyProperties 和 repeatCheck
    

    3. 批量查询与 RPC 调用缺乏分片机制(性能与稳定性风险)

    • 问题描述:filterEmployeesByBrand 方法中,提取了所有员工的手机号 phones,直接传递给 Mapper 的 IN 查询,以及将全量 merchantIds 直接传递给 merchantRemote.getBrandByMerchantIds 进行 RPC 调用。
    • 影响分析:当推送考试的员工基数较大(如数千人)时,超长的 IN 语句会导致 SQL 性能急剧下降甚至超出 MySQL max_allowed_packet 限制报错。同时,RPC 调用传递超大集合容易引发序列化耗时过长或触发 Provider 端的报文大小限制。
    • 优化建议:利用项目中已引入的 Hutool 工具类,对集合进行分片(Batch)处理。 ```java // DB 查询分片示例: List result = new ArrayList<>(); List> phonePartitions = CollectionUtil.split(phones, 500); for (List batch : phonePartitions) { result.addAll(levelExamPersonMapper.selectLatestMerchantIdByPhones(batch)); }

    // RPC 调用分片示例同理,对 merchantIds 进行切片循环调用并合并结果。

    
    ---
    
    ### 二、评分明细
    
    - **功能实现的正确性与健壮性 (30/40分)**
      **理由**:核心的品牌过滤分岔逻辑(主路径与兜底路径)设计清晰。但扣分在于发现了两处严重影响健壮性的缺陷:`newJobPost` 的潜在空指针异常,以及字符串排序与落库不一致导致的重复校验失效漏洞。
    
    - **安全性与潜在风险 (30/30分)**
      **理由**:未发现明显的 SQL 注入风险(MyBatis 传参规范),没有越权或敏感信息泄露问题。新增的 RPC 接口符合规范,没有破坏既有接口的参数结构。
    
    - **最佳实践与可维护性 (15/20分)**
      **理由**:代码注释详尽,流式 API (Stream) 使用熟练,可读性较好。扣分项在于:存在无意义的冗余代码(连续两次 `getBeiSenJobPost`),且内部方法职责存在轻微耦合。
    
    - **性能与资源利用 (3/5分)**
      **理由**:通过提取 Set 集合进行内存匹配,避免了在 for 循环中查库,这点做得很好。但针对大集合未做分片限制(Chunking),直接进行 DB 的 IN 查询和 RPC 批量请求,在生产大考场景下存在明显的性能瓶颈与崩溃风险。
    
    - **提交信息质量 (5/5分)**
      **理由**:Commit message 采用了标准的结构化格式(feat),并以列表形式清晰详尽地罗列了所有变更点,可追溯性极强。
    
    **总分:83分**
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!