Commit f6c859de by 章家宝

feat:新增查询所有区域运营接口

1 parent dd9cac84
......@@ -12,6 +12,8 @@ import cn.com.glsx.framework.core.annotation.*;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import java.util.List;
@ApiService(value = "督导任务", owner = "fanfr")
public interface SupervisorTaskInfoRemote {
......@@ -154,4 +156,11 @@ public interface SupervisorTaskInfoRemote {
@ApiParams({@ApiParam(name = "request", notes = "专项任务信息(门店ID、门店名称、任务描述、督导手机号、督导姓名、创建人)", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)})
@ApiResponse("新增结果(任务ID)")
RpcResponse<Long> createSpecialTask(CreateSpecialTaskDTO request);
/**
* 查询所有区域运营
*/
@ApiMethod("查询所有区域运营")
@ApiResponse("区域运营列表")
RpcResponse<List<RegionOperatorDTO>> listAllRegionOperator();
}
\ No newline at end of file
......@@ -18,11 +18,15 @@ import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.model.response.MerchantStaffResponse;
import com.github.pagehelper.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@DubboService(retries = 0, timeout = 30000, validation = "true")
public class SupervisorTaskInfoRemoteImpl implements SupervisorTaskInfoRemote {
......@@ -283,4 +287,30 @@ public class SupervisorTaskInfoRemoteImpl implements SupervisorTaskInfoRemote {
return RpcResponse.error(DefaultErrorEnum.SERVER_ERROR, e.getMessage());
}
}
@Override
public RpcResponse<List<RegionOperatorDTO>> listAllRegionOperator() {
try {
log.info("查询所有区域运营 - 开始");
List<MerchantStaffResponse> staffList = supervisorTaskInfoService.listAllRegionOperator();
// 转换为 RegionOperatorDTO
List<RegionOperatorDTO> result = new ArrayList<>();
if (staffList != null) {
for (MerchantStaffResponse staff : staffList) {
RegionOperatorDTO dto = new RegionOperatorDTO();
dto.setName(staff.getStaffName());
dto.setPhone(staff.getStaffPhone());
result.add(dto);
}
}
log.info("查询所有区域运营 - 成功,size={}", result.size());
return RpcResponse.success(result);
} catch (RpcServiceException e) {
log.error("cn.com.glsx.dj.supervisor.remote.SupervisorTaskInfoRemoteImpl.listAllRegionOperator error {}", e);
return RpcResponse.error(e.getError(), e.getMessage());
} catch (Exception e) {
log.error("cn.com.glsx.dj.supervisor.remote.SupervisorTaskInfoRemoteImpl.listAllRegionOperator system error {}", e);
return RpcResponse.error(DefaultErrorEnum.SERVER_ERROR, e.getMessage());
}
}
}
......@@ -27,14 +27,12 @@ import cn.com.glsx.merchants.model.request.MerchantStaffRequest;
import cn.com.glsx.merchants.model.response.MerchantStaffResponse;
import cn.com.glsx.merchants.remote.MerchantStaffRemote;
import cn.com.glsx.merchants.remote.MerchantUserRemote;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.commons.lang3.StringUtils;
import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable;
import org.springframework.beans.BeanUtils;
......@@ -271,6 +269,25 @@ public class SupervisorTaskInfoService {
}
/**
* 查询所有区域运营
* @return
*/
public List<MerchantStaffResponse> listAllRegionOperator() {
MerchantStaffRequest staffRequest = new MerchantStaffRequest();
staffRequest.setMerchantNo(env.getProperty("glsk_merchant_id", Integer.class, 44205577));
staffRequest.setRoleName(env.getProperty("glsk_supervisor_role_name", String.class, "区域运营"));
staffRequest.setDelFlag((byte) 0);
// 过滤被删除被禁用的员工
RpcResponse<List<MerchantStaffResponse>> response = merchantStaffRemote.findMerchantStaffListRemote(staffRequest);
if (response.hasResult()) {
return response.getResult();
} else {
log.error("查询督导人员列表失败,merchantNo={}, roleName={}, message={}", staffRequest.getMerchantNo(), staffRequest.getRoleName(), response.getMessage());
throw new RpcServiceException(DefaultErrorEnum.RPC_ERROR, response.getMessage());
}
}
/**
* 查询所有飞行督导人员
* @return
*/
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议

    • 1. 疑似配置 Key 拼写错误(功能正确性)

      • 问题描述:在 SupervisorTaskInfoService.java 第 278-279 行,获取配置的 Key 为 "glsk_merchant_id"。
      • 影响分析:根据项目上下文及公司命名习惯(glsx),此处极大概率将 glsx 误写为 glsk。这将导致程序无法从配置文件中读取到正确的商户 ID,从而始终回退到硬编码的默认值 44205577,在多环境部署时会导致业务逻辑错误。
      • 优化建议:核对配置中心或 application.yml 中的 Key 定义,修正拼写错误。建议将此类 Key 定义为常量。
    • 2. 远程调用结果处理缺乏空值保护(健壮性)

      • 问题描述:在 SupervisorTaskInfoService 中调用 merchantStaffRemote.findMerchantStaffListRemote(staffRequest) 后,直接执行了 if (response.hasResult())。
      • 影响分析:若 Dubbo 调用发生网络超时或框架层异常导致 response 为 null,此处将抛出 NullPointerException (NPE),导致服务不可用。此外,response.hasResult() 仅表示结果不为空,未充分考虑 response.isSuccess() 的状态。
      • 优化建议:先判断 response 是否为 null 及其 success 状态。 java RpcResponse<List<MerchantStaffResponse>> response = merchantStaffRemote.findMerchantStaffListRemote(staffRequest); if (response != null && response.isSuccess() && response.getResult() != null) { return response.getResult(); } else { String msg = (response == null) ? "RPC返回为空" : response.getMessage(); log.error("查询督导人员列表失败, message={}", msg); throw new RpcServiceException(DefaultErrorEnum.RPC_ERROR, msg); }
    • 3. 全量查询接口缺乏数量限制(性能与稳定性)

      • 问题描述:listAllRegionOperator 语义为查询“所有”区域运营人员,且底层调用未传分页参数。
      • 影响分析:随着业务增长,若“区域运营”角色下的员工数量达到数千甚至更多,全量拉取会导致 RPC 响应体过大(耗尽带宽)、内存占用激增(OOM 风险)以及序列化耗时增加,严重影响系统稳定性。
      • 优化建议:即使业务上目前数据量较小,也应在 RPC 接口层面增加 limit 限制或强制分页,或在 Service 层对返回结果集大小进行阈值监控。

    二、评分明细

    • 1. 功能实现的正确性与健壮性(32/40):逻辑实现基本完整,但配置 Key 疑似拼写错误可能导致环境隔离失效,且远程调用结果处理缺乏 NPE 保护。
    • 2. 安全性与潜在风险(28/30):未发现 SQL 注入等严重安全问题。但硬编码的商户 ID 默认值存在一定的配置泄露风险。
    • 3. 最佳实践与可维护性(15/20):代码结构清晰,遵循了现有的 Service/Remote 模式;但存在魔法值(商户 ID、角色名、删除标志位 0),建议提取为常量或配置。
    • 4. 性能与资源利用(4/5):存在全量查询风险,虽目前可能非瓶颈,但属于工程隐患。
    • 5. 提交信息质量(5/5):Commit 信息简洁明了,符合规范。

    总分:84分

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