Commit a779af55 by 范富荣

优化查询员工驻店类型标识逻辑

1 parent 6e9715c2
...@@ -2152,12 +2152,13 @@ public class BusinessSceneAnalysisService { ...@@ -2152,12 +2152,13 @@ public class BusinessSceneAnalysisService {
return staff; return staff;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
req.setStaffUuids(staffIds); req.setStaffUuids(staffIds);
List<String> baseSceneCodeList = resolveBaseSceneCodeList(req.getBizs());
//查询驻店类型 //查询驻店类型
handlerStaffStationType(staffList, req, staffIds); handlerStaffStationType(staffList, req, staffIds, baseSceneCodeList);
//查询预警信息 //查询预警信息
handlerStaffWarning(staffList, req, staffIds); handlerStaffWarning(staffList, req, staffIds);
//查询员工禁用标识 //查询员工禁用标识
handlerStaffStatus(staffList, req, staffIds); handlerStaffStatus(staffList, req, staffIds, baseSceneCodeList);
return staffList; return staffList;
} }
...@@ -2170,13 +2171,11 @@ public class BusinessSceneAnalysisService { ...@@ -2170,13 +2171,11 @@ public class BusinessSceneAnalysisService {
* @param req 场景请求参数 * @param req 场景请求参数
* @param staffIds 员工ID列表 * @param staffIds 员工ID列表
*/ */
public void handlerStaffStationType(List<StaffAnalysisDTO> staffList, SceneBaseReq req, List<String> staffIds) { public void handlerStaffStationType(List<StaffAnalysisDTO> staffList, SceneBaseReq req, List<String> staffIds, List<String> baseSceneCodeList) {
Integer bizs = req.getBizs(); Integer bizs = req.getBizs();
if (bizs == null || CollectionUtils.isEmpty(staffIds)) { if (bizs == null || CollectionUtils.isEmpty(staffIds)) {
return; return;
} }
// 提前解析 bizs -> baseSceneCodeList
List<String> baseSceneCodeList = resolveBaseSceneCodeList(bizs);
if (CollectionUtils.isEmpty(baseSceneCodeList)) { if (CollectionUtils.isEmpty(baseSceneCodeList)) {
return; return;
} }
...@@ -2202,8 +2201,8 @@ public class BusinessSceneAnalysisService { ...@@ -2202,8 +2201,8 @@ public class BusinessSceneAnalysisService {
if (merchantId != null && StringUtils.isNotBlank(req.getStartTime()) && StringUtils.isNotBlank(req.getEndTime())) { if (merchantId != null && StringUtils.isNotBlank(req.getStartTime()) && StringUtils.isNotBlank(req.getEndTime())) {
cn.com.glsx.dj.strategy.dto.StaffTempSupportReqDTO tempReq = new cn.com.glsx.dj.strategy.dto.StaffTempSupportReqDTO(); cn.com.glsx.dj.strategy.dto.StaffTempSupportReqDTO tempReq = new cn.com.glsx.dj.strategy.dto.StaffTempSupportReqDTO();
tempReq.setMerchantId(merchantId); tempReq.setMerchantId(merchantId);
tempReq.setStartDate(req.getStartTime()); tempReq.setStartDate(req.getStartTime() + " 00:00:00");
tempReq.setEndDate(req.getEndTime()); tempReq.setEndDate(req.getEndTime() + " 23:59:59");
tempReq.setStaffIds(staffIds); tempReq.setStaffIds(staffIds);
tempReq.setBizs(bizs); tempReq.setBizs(bizs);
RpcResponse<List<String>> tempResp = strategyInfoRemote.selectStaffTempSupportByDateRange(tempReq); RpcResponse<List<String>> tempResp = strategyInfoRemote.selectStaffTempSupportByDateRange(tempReq);
...@@ -2257,14 +2256,15 @@ public class BusinessSceneAnalysisService { ...@@ -2257,14 +2256,15 @@ public class BusinessSceneAnalysisService {
* @param req 场景请求参数 * @param req 场景请求参数
* @param staffIds 员工ID列表 * @param staffIds 员工ID列表
*/ */
public void handlerStaffStatus(List<StaffAnalysisDTO> staffList, SceneBaseReq req, List<String> staffIds) { public void handlerStaffStatus(List<StaffAnalysisDTO> staffList, SceneBaseReq req, List<String> staffIds, List<String> baseSceneCodeList) {
StaffInfoDTO staffParam = new StaffInfoDTO(); StaffInfoDTO staffParam = new StaffInfoDTO();
staffParam.setStaffUuidList(staffIds); staffParam.setStaffUuidList(staffIds);
staffParam.setShopMerchantId(req.getMerchantIds().get(0)); staffParam.setShopMerchantId(req.getMerchantIds().get(0));
staffParam.setSubMerchantTypeList(Arrays.asList(6, 8)); staffParam.setSubMerchantTypeList(Arrays.asList(6, 8));
staffParam.setSceneType(req.getSceneType()); staffParam.setSceneType(req.getSceneType());
staffParam.setStaffDeletedFlags(Arrays.asList(BaseModel.DeletedFlagEnum.N.name(), BaseModel.DeletedFlagEnum.D.name(), "I")); staffParam.setStaffDeletedFlags(Arrays.asList(BaseModel.DeletedFlagEnum.N.name(), BaseModel.DeletedFlagEnum.D.name(), "I"));
RpcResponse<List<StaffInfoDTO>> listRpcResponse = staffInfoRemote.listBySceneShop(staffParam); staffParam.setBaseSceneCodeList(baseSceneCodeList);
RpcResponse<List<StaffInfoDTO>> listRpcResponse = staffInfoRemote.listBySceneShopWithBizs(staffParam);
if (listRpcResponse.hasError()) { if (listRpcResponse.hasError()) {
log.error("查询员工禁用标识异常: {}", listRpcResponse.getMessage()); log.error("查询员工禁用标识异常: {}", listRpcResponse.getMessage());
throw new RpcServiceException(listRpcResponse.getError(), listRpcResponse.getMessage()); throw new RpcServiceException(listRpcResponse.getError(), listRpcResponse.getMessage());
...@@ -2310,8 +2310,8 @@ public class BusinessSceneAnalysisService { ...@@ -2310,8 +2310,8 @@ public class BusinessSceneAnalysisService {
queryRequest.setEndDate(req.getEndTime()); queryRequest.setEndDate(req.getEndTime());
// monitorTarget=1(员工) // monitorTarget=1(员工)
queryRequest.setMonitorTarget(1); queryRequest.setMonitorTarget(1);
// TODO 员工ID参数暂未定义,后续支持批量员工查询时补充 staffId 过滤 queryRequest.setStaffIds(staffIds);
log.info("查询员工预警入参[{}]", JSON.toJSONString(queryRequest));
RpcResponse<List<WarningRecordDTO>> response = warningEngineRemote.findWarningDetailByStoreAndStaff(queryRequest); RpcResponse<List<WarningRecordDTO>> response = warningEngineRemote.findWarningDetailByStoreAndStaff(queryRequest);
if (response.hasError()) { if (response.hasError()) {
log.error("查询预警信息异常: {}", response.getMessage()); log.error("查询预警信息异常: {}", response.getMessage());
......
...@@ -14,6 +14,7 @@ import com.google.common.collect.Lists; ...@@ -14,6 +14,7 @@ import com.google.common.collect.Lists;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -344,4 +345,21 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest { ...@@ -344,4 +345,21 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest {
req.setMerchantIds(Lists.newArrayList(44217700)); req.setMerchantIds(Lists.newArrayList(44217700));
System.out.println(service.queryTargetAvgCustomerPrice(req)); System.out.println(service.queryTargetAvgCustomerPrice(req));
} }
@Test
public void testHandlerStaffStationType() {
List<StaffAnalysisDTO> staffList = new ArrayList<>();
StaffAnalysisDTO staff = new StaffAnalysisDTO();
staff.setStaffId("304c01b8abf14db581606ce42e35ede5");
staffList.add(staff);
StaffAnalysisDTO staff1 = new StaffAnalysisDTO();
staffList.add(staff1);
staff1.setStaffId("d4ea07f2bebc4647aab630d9c6acae36");
SceneBaseReq req = new SceneBaseReq();
req.setBizs(1);
req.setMerchantIds(Lists.newArrayList(44209339));
req.setStartTime("2026-01-15");
req.setEndTime("2026-01-25");
service.handlerStaffStationType(staffList, req, Lists.newArrayList("304c01b8abf14db581606ce42e35ede5", "d4ea07f2bebc4647aab630d9c6acae36"), Lists.newArrayList("100101"));
}
} }
  • @wangxw1
    commented
    Master

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

    1. 【高风险】Dubbo Remote 接口请求参数变更风险(违反重要规则)

    • 问题描述:在 handlerStaffStatus 和 handlerStaffWarning 方法中,分别对用于 Dubbo 远程调用的入参对象新增了属性赋值:staffParam.setBaseSceneCodeList(baseSceneCodeList) 以及 queryRequest.setStaffIds(staffIds)。根据审查规则,Dubbo 服务提供者 Remote 接口中的已有请求参数变更被视为危险实现。
    • 影响分析:如果服务提供方(Provider)和消费方(Consumer)未同步发布,或者底层序列化机制(如 Hessian2)对新增字段处理不当,极易引发反序列化异常(SerializationException)或导致业务逻辑报错,造成线上故障。
    • 优化建议:
      1. 确认 Provider 端是否已兼容这些新增字段,并确保 Provider 优先于 Consumer 发布。
      2. 建议在新老版本过渡期间,Provider 端对新增参数做好判空与兼容处理。
      3. 若架构允许,对于重大变更建议通过接口版本号(version)进行隔离。

    2. 【逻辑健壮性】日期字符串直接拼接存在解析异常风险

    • 问题描述:在 handlerStaffStationType 方法中,直接使用字符串拼接构造起止时间:tempReq.setStartDate(req.getStartTime() + " 00:00:00");。
    • 影响分析:虽然前置条件校验了 StringUtils.isNotBlank,但未校验日期格式。如果调用方传入的 startTime 已经是包含时分秒的完整时间格式(例如 "2023-10-01 10:00:00"),拼接后将变成 "2023-10-01 10:00:00 00:00:00",这会导致下游服务在进行日期解析时抛出 ParseException。
    • 优化建议:建议先判断字符串长度或格式,或者使用标准的日期处理库进行安全转换。 java // 示例建议:确保传入的日期长度为10(如 yyyy-MM-dd)再进行拼接 String start = req.getStartTime(); tempReq.setStartDate(start.length() == 10 ? start + " 00:00:00" : start);

    3. 【性能与最佳实践】在 INFO 级别日志中对大对象进行 JSON 序列化

    • 问题描述:代码第 2314 行新增了日志:log.info("查询员工预警入参[{}]", JSON.toJSONString(queryRequest));。queryRequest 中包含了 staffIds 列表。
    • 影响分析:staffIds 作为一个集合,在批量查询场景下可能包含大量元素。在 INFO 级别直接对包含大集合的对象进行 JSON.toJSONString 序列化,会消耗大量 CPU 和内存资源,且会导致日志文件迅速膨胀,影响系统性能。
    • 优化建议:避免在生产环境常规日志中序列化大对象。若仅为调试目的,建议将日志级别降为 DEBUG,或者仅打印关键参数(如集合的大小)。 java if (log.isDebugEnabled()) { log.debug("查询员工预警入参[{}]", JSON.toJSONString(queryRequest)); } else { log.info("查询员工预警, staffIds数量:[{}]", staffIds.size()); }

    二、评分明细

    • 功能实现的正确性与健壮性(32/40分): 提取公共变量 baseSceneCodeList 减少了重复计算,逻辑方向正确。但时间字符串的硬编码拼接缺乏格式校验,降低了代码的健壮性,扣 8 分。
    • 安全性与潜在风险(20/30分): 触犯了“Dubbo Remote接口参数变更视为危险实现”的红线规则,存在较高的微服务发布协同风险与序列化风险,扣 10 分。
    • 最佳实践与可维护性(17/20分): 代码整体结构清晰,补充了单元测试值得肯定。但 INFO 级别打印大对象 JSON 的做法不符合日志最佳实践,扣 3 分。
    • 性能与资源利用(3/5分): FastJSON 序列化大对象会带来不必要的 CPU 和内存开销,扣 2 分。
    • 提交信息质量(3/5分): Commit 信息“优化查询员工驻店类型标识逻辑”过于简略,本次提交实际上还修改了预警信息(Warning)和员工状态(Status)的查询逻辑,Commit 未能完整反映变更范围,扣 2 分。

    总分:75分

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