Commit 72b898bf by 章家宝

feat:九月份日报大版本代码提交

1 parent 41af3d37
package com.gsc4cloud.gsc.vpc.controller.report;
import com.gsc4cloud.gsc.common.core.util.R;
import com.gsc4cloud.gsc.vpc.api.dto.thirdparty.mcp.McpDailyReportDTO;
import com.gsc4cloud.gsc.vpc.api.dto.thirdparty.mcp.McpDailyRequest;
import com.gsc4cloud.gsc.vpc.api.dto.thirdparty.mcp.McpMonthlyReportDTO;
import com.gsc4cloud.gsc.vpc.api.dto.thirdparty.mcp.McpMonthlyRequest;
import com.gsc4cloud.gsc.vpc.service.report.McpReportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* MCP 报表数据查询端点
* <p>
* 供 gsc-vcp-thirdparty-facade 通过 Feign 调用
* </p>
*/
@Slf4j
@RestController
@RequestMapping("/mcp/report")
@Tag(name = "MCP 报表数据查询", description = "供第三方 facade 调用的内部接口")
public class McpReportController {
@Autowired
private McpReportService mcpReportService;
/**
* 查询月度经营数据(按月聚合)
* <p>
* 参数走 JSON body:中文门店名经 query string 传输会被原样编码导致 Tomcat 400
* </p>
*
* @param request month(YYYY-MM)必填,storeName 可选
* @return 月度聚合数据列表
*/
@Operation(summary = "查询月度经营数据")
@PostMapping("/monthly")
public R<List<McpMonthlyReportDTO>> queryMonthlyReport(@RequestBody McpMonthlyRequest request) {
try {
List<McpMonthlyReportDTO> result = mcpReportService.queryMonthlyReport(request.getMonth(), request.getStoreName());
return R.ok(result);
} catch (Exception e) {
log.error("查询月度经营数据失败", e);
return R.failed("查询失败:" + e.getMessage());
}
}
/**
* 查询员工日报明细
* <p>
* 参数走 JSON body:中文门店名经 query string 传输会被原样编码导致 Tomcat 400
* </p>
*
* @param request storeName/startDate/endDate(YYYY-MM-DD)必填,employee 可选
* @return 员工日报明细列表
*/
@Operation(summary = "查询员工日报明细")
@PostMapping("/daily")
public R<List<McpDailyReportDTO>> queryDailyReport(@RequestBody McpDailyRequest request) {
try {
List<McpDailyReportDTO> result = mcpReportService.queryDailyReport(request.getStoreName(), request.getEmployee(),
request.getStartDate(), request.getEndDate());
return R.ok(result);
} catch (Exception e) {
log.error("查询员工日报明细失败", e);
return R.failed("查询失败:" + e.getMessage());
}
}
}
package com.gsc4cloud.gsc.vpc.mapper.report;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gsc4cloud.gsc.vpc.api.entity.report.DjCarLifeDailyReportFieldData;
import org.apache.ibatis.annotations.Mapper;
/**
* 日报普通字段数据表 Mapper
*/
@Mapper
public interface DjCarLifeDailyReportFieldDataMapper extends BaseMapper<DjCarLifeDailyReportFieldData> {
}
package com.gsc4cloud.gsc.vpc.mapper.report;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gsc4cloud.gsc.vpc.api.entity.report.DjCarLifeDailyReportRecord;
import org.apache.ibatis.annotations.Mapper;
/**
* 日报填报记录表 Mapper
*/
@Mapper
public interface DjCarLifeDailyReportRecordMapper extends BaseMapper<DjCarLifeDailyReportRecord> {
}
package com.gsc4cloud.gsc.vpc.mapper.report;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gsc4cloud.gsc.vpc.api.entity.report.RptReportStoreDaily;
import org.apache.ibatis.annotations.Mapper;
/**
* 日报门店级宽表
*
* @author Claude
* @since 2026-09-01
*/
@Mapper
public interface RptReportStoreDailyMapper extends BaseMapper<RptReportStoreDaily> {
}
package com.gsc4cloud.gsc.vpc.service.report;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gsc4cloud.gsc.vpc.api.entity.report.DjCarLifeDailyReportFieldData;
import com.gsc4cloud.gsc.vpc.mapper.report.DjCarLifeDailyReportFieldDataMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 日报普通字段数据表 Service
*/
@Slf4j
@Service
public class DjCarLifeDailyReportFieldDataService extends ServiceImpl<DjCarLifeDailyReportFieldDataMapper, DjCarLifeDailyReportFieldData> {
}
package com.gsc4cloud.gsc.vpc.service.report;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gsc4cloud.gsc.vpc.api.entity.report.DjCarLifeDailyReportRecord;
import com.gsc4cloud.gsc.vpc.mapper.report.DjCarLifeDailyReportRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 日报填报记录表 Service
*/
@Slf4j
@Service
public class DjCarLifeDailyReportRecordService extends ServiceImpl<DjCarLifeDailyReportRecordMapper, DjCarLifeDailyReportRecord> {
}
package com.gsc4cloud.gsc.vpc.service.report;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gsc4cloud.gsc.vpc.api.entity.report.RptReportStoreDaily;
import com.gsc4cloud.gsc.vpc.mapper.report.RptReportStoreDailyMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 日报门店级宽表
*
* @author Claude
* @since 2026-09-01
*/
@Slf4j
@Service
public class RptReportStoreDailyService extends ServiceImpl<RptReportStoreDailyMapper, RptReportStoreDaily> {
}
\ No newline at end of file
  • @wangxw1
    commented
    Master

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

    1. 严重的内存聚合反模式(性能与稳定性风险极高)

    • 问题描述:在 McpReportService.queryMonthlyReport 方法中,代码将整月(甚至跨所有门店)的 RptReportStoreDaily 每日明细数据全部加载到应用内存中,然后使用 Java Stream 进行 SUM 和 AVG 的聚合计算。
    • 影响分析:这是典型的数据库反模式。随着业务量增长,极易导致大对象频繁创建,引发 GC 停顿甚至 OOM(内存溢出)。同时,大量无用数据通过网络从 DB 传输到应用服务器,极大地浪费了网络带宽和 DB 资源。
    • 优化建议:应将聚合逻辑下推至数据库,在 Mapper 层手写 SQL 使用 GROUP BY 进行聚合。 代码示例: xml <!-- 在 RptReportStoreDailyMapper.xml 中新增 --> <select id="aggregateMonthlyReport" resultType="com.gsc4cloud.gsc.vpc.api.dto.thirdparty.mcp.McpMonthlyReportDTO"> SELECT seller_merchant_id AS sellerMerchantId, seller_merchant_name AS sellerMerchantName, SUM(new_car_order_quantity) AS newCarOrderQuantity, AVG(dispose_avg_price) AS disposeAvgPrice -- 其他聚合字段... FROM rpt_report_store_daily WHERE stat_date BETWEEN #{startDate} AND #{endDate} <if test="storeName != null and storeName != ''"> AND seller_merchant_name LIKE CONCAT('%', #{storeName}, '%') </if> GROUP BY seller_merchant_id, seller_merchant_name </select>

    2. 潜在的超大 IN 集合查询风险(功能与稳定性风险)

    • 问题描述:在 McpReportService.queryDailyReport 方法中,先查出主表记录获取所有的 recordIds,然后使用 in(DjCarLifeDailyReportFieldData::getReportRecordId, recordIds) 查询子表字段数据。
    • 影响分析:如果查询的时间跨度较大,recordIds 列表可能会包含成千上万个 ID。数据库对 IN 子句的长度通常有严格限制(如 Oracle 限制 1000 个,MySQL 过长也会导致解析性能急剧下降甚至报错),这会导致生产环境在数据量变大时直接报错。
    • 优化建议:建议通过 JOIN 语句一次性关联查询出所需数据;如果必须在代码中组装,请使用 Lists.partition(recordIds, 500) 将 ID 列表分批查询后再合并结果。

    3. 异常处理不当导致潜在信息泄露(安全性与最佳实践)

    • 问题描述:McpReportController 中的两个接口在 catch (Exception e) 后,直接将 e.getMessage() 拼接到返回值中返回给调用方。
    • 影响分析:底层抛出的异常(如 SQL 语法错误、空指针异常、数据库连接异常等)往往包含敏感的系统内部信息(表结构、IP地址、类名等)。直接暴露给第三方调用者存在安全隐患,且对调用方不友好。
    • 优化建议:应返回统一且模糊的错误提示,详细的错误信息仅保留在日志中。推荐使用全局异常处理器(@RestControllerAdvice)。如果局部处理,可改为如下方式: 代码示例: java catch (Exception e) { // 日志记录完整堆栈,但返回给前端的要是安全提示 log.error("查询月度经营数据失败, request: {}", request, e); return R.failed("系统内部错误,查询月度经营数据失败,请稍后重试或联系管理员"); }

    二、评分明细

    • 功能实现的正确性与健壮性(30/40分): 扣分原因:queryDailyReport 存在大集合 IN 查询隐患,在数据量上升时会导致 SQL 执行失败;parseInt 吞掉了 NumberFormatException 返回 null,虽不致命但掩盖了脏数据。
    • 安全性与潜在风险(25/30分): 扣分原因:Controller 层直接向外部返回了原生 Exception.getMessage(),存在系统内部敏感信息泄露风险。代码中未见明显的 SQL 注入风险(使用了 MyBatis-Plus 包装器)。
    • 最佳实践与可维护性(13/20分): 扣分原因:
      1. 严重违反数据库使用最佳实践(在内存中做大量数据的聚合计算)。
      2. 滥用 @Autowired 字段注入(Spring 官方推荐使用构造器注入,可配合 @RequiredArgsConstructor)。
      3. 代码中存在硬编码的魔术字符串(如 "F2-108"、"0" 逻辑删除标识),应提取为常量或枚举。
      4. 使用了已废弃的常量 BigDecimal.ROUND_HALF_UP,应替换为 RoundingMode.HALF_UP。
    • 性能与资源利用(1/5分): 扣分原因:内存聚合和 N+1 变体查询(先查主表再查子表)对 CPU、内存及数据库网络 I/O 造成了极大的不必要消耗,存在明显的性能瓶颈。
    • 提交信息质量(3/5分): 扣分原因:“feat:九月份日报大版本代码提交” 描述过于宽泛,缺乏对具体修改内容(如新增 MCP 报表查询接口、宽表 Mapper 等)的实质性说明,不利于后续追溯。

    总分:72分

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