Commit e2451fc9 by 庞善天

美团需求功能开发

1 parent 238329b7
package cn.com.glsx.dj.staff.miniprogram.config.dubbo; package cn.com.glsx.dj.staff.miniprogram.config.dubbo;
import cn.com.glsx.dj.staff.remote.MeiTuanOrderRemote;
import cn.com.glsx.dj.staff.remote.RecruitmentDemandRemote; import cn.com.glsx.dj.staff.remote.RecruitmentDemandRemote;
import cn.com.glsx.dj.staff.remote.RecruitmentResumeRemote; import cn.com.glsx.dj.staff.remote.RecruitmentResumeRemote;
import cn.com.glsx.dj.staff.remote.dict.DictRemote; import cn.com.glsx.dj.staff.remote.dict.DictRemote;
...@@ -63,4 +64,8 @@ public class StaffDubboConfig extends DubboConfig { ...@@ -63,4 +64,8 @@ public class StaffDubboConfig extends DubboConfig {
return factory.builder(PerformanceTimeCycleRemote.class).check(check).timeout(timeout).version("1.0.0").build(); return factory.builder(PerformanceTimeCycleRemote.class).check(check).timeout(timeout).version("1.0.0").build();
} }
@Bean
public MeiTuanOrderRemote meiTuanOrderRemote(){
return factory.builder(MeiTuanOrderRemote.class).check(check).timeout(timeout).version("1.0.0").build();
}
} }
package cn.com.glsx.dj.staff.miniprogram.controller.meituan;
import cn.com.glsx.dj.staff.dto.meituan.DeptMonthlyReportDTO;
import cn.com.glsx.dj.staff.dto.meituan.CompanyMonthlyReportDTO;
import cn.com.glsx.dj.staff.dto.meituan.StaffMonthlyReportDTO;
import cn.com.glsx.dj.staff.miniprogram.request.meituan.MeiTuanOrderRequest;
import cn.com.glsx.dj.staff.miniprogram.service.meituan.MeiTuanOrderService;
import cn.com.glsx.framework.rop.response.RopResponse;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.NO)
@Api("美团订单")
public class MeiTuanOrderController {
@Autowired
private MeiTuanOrderService meiTuanOrderService;
@ApiOperation("美团订单-个人月度报表")
@ServiceMethod(method = "dj.api.staff.miniprogram.meituan.order.person", needInSession = NeedInSessionType.NO)
public RopResponse<StaffMonthlyReportDTO> obtainPersonMonthlyReport(MeiTuanOrderRequest request) {
return meiTuanOrderService.obtainPersonMonthlyReport(request);
}
@ApiOperation("美团订单-部门月度报表")
@ServiceMethod(method = "dj.api.staff.miniprogram.meituan.order.dept", needInSession = NeedInSessionType.NO)
public RopResponse<DeptMonthlyReportDTO> obtainDeptMonthlyReport(MeiTuanOrderRequest request) {
return meiTuanOrderService.obtainDeptMonthlyReport(request);
}
@ApiOperation("美团订单-公司月度报表")
@ServiceMethod(method = "dj.api.staff.miniprogram.meituan.order.company", needInSession = NeedInSessionType.NO)
public RopResponse<CompanyMonthlyReportDTO> obtainCompanyMonthlyReport(MeiTuanOrderRequest request) {
return meiTuanOrderService.obtainCompanyMonthlyReport(request);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.miniprogram.request.meituan;
import com.rop.AbstractRopRequest;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@ApiModel("美团订单月度报表请求")
public class MeiTuanOrderRequest extends AbstractRopRequest {
@NotNull(message = "推送ID不能为空")
@ApiModelProperty(notes="推送ID", required = true)
private Long pushId;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.miniprogram.service.meituan;
import cn.com.glsx.dj.staff.dto.meituan.DeptMonthlyReportDTO;
import cn.com.glsx.dj.staff.dto.meituan.CompanyMonthlyReportDTO;
import cn.com.glsx.dj.staff.dto.meituan.StaffMonthlyReportDTO;
import cn.com.glsx.dj.staff.miniprogram.request.meituan.MeiTuanOrderRequest;
import cn.com.glsx.dj.staff.remote.MeiTuanOrderRemote;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.rop.response.RopResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Service
@Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public class MeiTuanOrderService {
@Autowired
private MeiTuanOrderRemote meiTuanOrderRemote;
public RopResponse<StaffMonthlyReportDTO> obtainPersonMonthlyReport(MeiTuanOrderRequest request) {
Long pushId = request.getPushId();
log.info("obtainPersonMonthlyReport, pushId:{}", pushId);
RpcResponse<StaffMonthlyReportDTO> rpcRes = meiTuanOrderRemote.obtainPersonMonthlyReport(pushId);
if (!rpcRes.isSuccess()) {
log.error("obtainPersonMonthlyReport error, msg:{}", rpcRes.getMessage());
return RopResponse.error(rpcRes);
}
return RopResponse.success(rpcRes.getResult());
}
public RopResponse<DeptMonthlyReportDTO> obtainDeptMonthlyReport(MeiTuanOrderRequest request) {
Long pushId = request.getPushId();
log.info("obtainDeptMonthlyReport, pushId:{}", pushId);
RpcResponse<DeptMonthlyReportDTO> rpcRes = meiTuanOrderRemote.obtainDeptMonthlyReport(pushId);
if (!rpcRes.isSuccess()) {
log.error("obtainDeptMonthlyReport error, msg:{}", rpcRes.getMessage());
return RopResponse.error(rpcRes);
}
return RopResponse.success(rpcRes.getResult());
}
public RopResponse<CompanyMonthlyReportDTO> obtainCompanyMonthlyReport(MeiTuanOrderRequest request) {
Long pushId = request.getPushId();
log.info("obtainCompanyMonthlyReport, pushId:{}", pushId);
RpcResponse<CompanyMonthlyReportDTO> rpcRes = meiTuanOrderRemote.obtainCompanyMonthlyReport(pushId);
if (!rpcRes.isSuccess()) {
log.error("obtainCompanyMonthlyReport error, msg:{}", rpcRes.getMessage());
return RopResponse.error(rpcRes);
}
return RopResponse.success(rpcRes.getResult());
}
}
\ No newline at end of file \ No newline at end of file
  • @wangxw1
    commented
    Master

    你好!我是资深的 Java 开发工程师。针对你提供的代码变更,我进行了详细的审查。以下是核心问题分析与评分。

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

    1. 安全性高危风险:越权访问(IDOR)与会话缺失

    • 问题描述:在 MeiTuanOrderController 中,所有接口均配置了 needInSession = NeedInSessionType.NO(无需登录),且仅通过 MeiTuanOrderRequest 中的 pushId(Long 类型)来获取个人、部门甚至公司的敏感报表数据。
    • 风险分析:
      1. 未授权访问:接口完全公开,没有任何身份验证机制。
      2. 越权风险(IDOR):pushId 为 Long 类型,极易被遍历或猜测。攻击者只需通过脚本递增 pushId,即可批量拉取全公司的敏感数据(个人绩效、部门报表等),造成严重的数据泄露。
    • 优化建议:
      1. 将 needInSession 改为 YES,强制要求用户登录。
      2. 在服务端校验当前登录用户是否有权限查看该 pushId 对应的数据(例如校验该 pushId 是否属于当前用户的部门/公司)。
      3. 如果该接口必须对外(如外部回调),应使用高熵的 Token(如 UUID)而非自增 ID,并增加签名校验机制。

    2. 性能与规范:RPC 调用不当使用 @Transactional

    • 问题描述:在 MeiTuanOrderService 类上添加了 @Transactional(propagation = Propagation.SUPPORTS...) 注解。
    • 风险分析:
      1. 资源滥用:该 Service 内部逻辑纯粹是调用 Dubbo 远程接口(RPC),不涉及本地数据库的写操作。根据《阿里巴巴 Java 开发手册》,严禁在 RPC 调用外层包裹事务。
      2. 性能隐患:虽然使用了 SUPPORTS,但如果上层调用者开启了事务,RPC 调用的网络耗时会直接延长数据库连接的占用时间,高并发下极易导致数据库连接池耗尽(Connection Pool Exhausted),引发雪崩。
    • 优化建议:移除 MeiTuanOrderService 上的 @Transactional 注解。纯查询类的 RPC 聚合层不需要事务支持。

    3. 可维护性:依赖注入方式不符合最佳实践

    • 问题描述:Controller 和 Service 中均使用了字段注入(@Autowired private ...)。
    • 风险分析:虽然这是常见写法,但 Spring 官方和《阿里巴巴 Java 开发手册》均推荐使用构造器注入。字段注入会导致对象在测试时难以脱离 Spring 容器进行实例化(NPE 风险),且掩盖了类可能存在的循环依赖问题。
    • 优化建议:使用构造器注入(配合 Lombok 的 @RequiredArgsConstructor 更加简洁)。 java // 示例 @Service @RequiredArgsConstructor public class MeiTuanOrderService { private final MeiTuanOrderRemote meiTuanOrderRemote; // ... }

    二、评分明细

    维度 评分 扣分/得分理由
    功能正确性 (40分) 35 业务逻辑链路清晰,参数校验使用了 @NotNull,Dubbo 配置正常。扣分点在于对异常情况的处理较简单,仅打印日志并返回 Error,未区分业务异常类型。
    安全性 (30分) 5 严重扣分项。涉及敏感报表数据(个人/公司月报)的接口完全未做鉴权(No Session),且存在明显的 ID 遍历风险。这是生产环境绝对不可接受的漏洞。
    可维护性 (20分) 15 代码结构清晰,分层合理。扣分项:使用了字段注入而非构造器注入;Dubbo 版本号硬编码在代码中(建议配置化)。
    性能 (5分) 2 RPC 调用包裹在事务注解中,存在阻塞数据库连接的风险,扣除大部分分数。
    提交信息 (5分) 3 "美团需求功能开发" 过于笼统,建议包含关联的 Jira/需求 ID,以及简要说明变更范围(如:新增美团月度报表查询接口)。

    总分:60分

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