Commit 5fa36c37 by 崔彦峰

feat(clues): 添加线索销售门店分页查询功能

- 新增 CluesMerchantPageReq 请求类用于线索销售门店分页查询
- 新增 CluesMerchantPageResp 响应类定义线索销售门店分页列表项结构
- 在 CluesRemote 接口中添加 merchantPage 方法支持远程调用
- 在 CluesController 中实现 merchantPage 控制器方法
- 在 CluesInfoMapper 中添加 merchantPage 数据访问方法
- 在 CluesInfoMapper.xml 中编写 merchantPage 查询 SQL 语句
- 在 CluesInfoService 中实现 merchantPage 业务逻辑方法
- 在 Web 门面层添加 merchantPage 端点支持门店分页查询
1 parent 955c164a
......@@ -6,6 +6,7 @@ import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.AddCluesResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesDetailResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesFollowRecordListResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesFollowTimeStatusCountResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesMerchantPageResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesOperationLogListResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesPageResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesStatusCountResp;
......@@ -18,6 +19,7 @@ import com.gsc4cloud.gsc.vpc.api.req.pad.clues.CluesPadPageReq;
import com.gsc4cloud.gsc.vpc.api.req.pad.clues.CluesStatusCountReq;
import com.gsc4cloud.gsc.vpc.api.req.web.clues.CluesWebPageReq;
import com.gsc4cloud.gsc.vpc.api.req.web.clues.CluesOperationLogListReq;
import com.gsc4cloud.gsc.vpc.api.req.web.clues.CluesMerchantPageReq;
import com.gsc4cloud.gsc.vpc.service.clues.CluesInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -79,4 +81,10 @@ public class CluesController {
Page<CluesPageResp> page = cluesInfoService.webPage(req);
return R.ok(page);
}
@PostMapping("/merchantPage")
public R<Page<CluesMerchantPageResp>> merchantPage(
@RequestBody PageRequest<CluesMerchantPageReq> req) {
return R.ok(cluesInfoService.merchantPage(req));
}
}
......@@ -4,11 +4,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesDetailResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesFollowTimeStatusCountResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesMerchantPageResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesPageResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesStatusCountResp;
import com.gsc4cloud.gsc.vpc.api.entity.clues.CluesInfo;
import com.gsc4cloud.gsc.vpc.api.req.pad.clues.CluesDetailReq;
import com.gsc4cloud.gsc.vpc.api.req.pad.clues.CluesStatusCountReq;
import com.gsc4cloud.gsc.vpc.api.req.web.clues.CluesMerchantPageReq;
import com.gsc4cloud.gsc.vpc.service.clues.CluesPageQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -23,6 +25,9 @@ public interface CluesInfoMapper extends BaseMapper<CluesInfo> {
Page<CluesPageResp> page(Page<CluesPageResp> page, @Param("req") CluesPageQuery req);
Page<CluesMerchantPageResp> merchantPage(Page<CluesMerchantPageResp> page,
@Param("req") CluesMerchantPageReq req);
CluesDetailResp detail(@Param("req") CluesDetailReq req);
CluesStatusCountResp statusCount(@Param("request") CluesStatusCountReq request);
......
......@@ -7,6 +7,7 @@ import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.AddCluesResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesDetailResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesFollowRecordListResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesFollowTimeStatusCountResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesMerchantPageResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesOperationLogListResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesPageResp;
import com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.FollowRecordItemResp;
......@@ -32,6 +33,7 @@ import com.gsc4cloud.gsc.vpc.api.req.pad.clues.CluesPadPageReq;
import com.gsc4cloud.gsc.vpc.api.req.pad.clues.CluesStatusCountReq;
import com.gsc4cloud.gsc.vpc.api.req.web.clues.CluesWebPageReq;
import com.gsc4cloud.gsc.vpc.api.req.web.clues.CluesOperationLogListReq;
import com.gsc4cloud.gsc.vpc.api.req.web.clues.CluesMerchantPageReq;
import com.gsc4cloud.gsc.vpc.mapper.clues.CluesFollowRecordMapper;
import com.gsc4cloud.gsc.vpc.mapper.clues.CluesInfoMapper;
import com.gsc4cloud.gsc.vpc.mapper.clues.CluesOperationLogMapper;
......@@ -310,6 +312,14 @@ public class CluesInfoService extends ServiceImpl<CluesInfoMapper, CluesInfo> {
return result;
}
public Page<CluesMerchantPageResp> merchantPage(PageRequest<CluesMerchantPageReq> req) {
PageRequest<CluesMerchantPageReq> pageRequest = req == null ? new PageRequest<>() : req;
CluesMerchantPageReq queryReq = pageRequest.getT() == null
? new CluesMerchantPageReq() : pageRequest.getT();
Page<CluesMerchantPageResp> page = new Page<>(pageRequest.getCurrentPage(), pageRequest.getPageSize());
return baseMapper.merchantPage(page, queryReq);
}
private CluesPageQuery toPadPageQuery(CluesPadPageReq req) {
CluesPageQuery query = new CluesPageQuery();
query.setKeyword(req.getKeyword());
......
......@@ -233,4 +233,21 @@
</choose>
</select>
<select id="merchantPage"
resultType="com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesMerchantPageResp">
SELECT
c.seller_merchant_id AS sellerMerchantId,
c.seller_merchant_name AS sellerMerchantName
FROM vcp_clues_info c
WHERE c.deleted_flag = 'N'
AND c.seller_merchant_id IS NOT NULL
AND c.seller_merchant_name IS NOT NULL
AND c.seller_merchant_name &lt;&gt; ''
<if test="req.keyword != null and req.keyword != ''">
AND c.seller_merchant_name LIKE CONCAT('%', #{req.keyword}, '%')
</if>
GROUP BY c.seller_merchant_id, c.seller_merchant_name
ORDER BY c.seller_merchant_id ASC
</select>
</mapper>
  • @wangxw1
    commented
    Master

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

    1. 性能与架构设计:在业务表(事实表)上使用 GROUP BY 提取维度数据

    • 问题描述:在 CluesInfoMapper.xml 的 merchantPage 查询中,直接对线索业务表 vcp_clues_info 使用 GROUP BY c.seller_merchant_id, c.seller_merchant_name 来获取去重后的门店列表。
    • 影响分析:vcp_clues_info 作为核心业务表,数据量通常会快速增长。在大表上进行全表(或大范围)扫描并使用 GROUP BY 会导致严重的性能瓶颈(极易产生临时表和文件排序 Using temporary; Using filesort),大量消耗数据库 CPU 和内存资源。此外,MyBatis-Plus 在对包含 GROUP BY 的原生 SQL 进行自动分页 COUNT 查询时,有时会出现统计总数不准确的隐患。
    • 优化建议:
      1. 最优解:门店列表应该直接查询门店维度表(如 merchant_info),而不是从线索表中反向推导。
      2. 折中解:如果业务逻辑确实是“只查询有线索记录的门店”,强烈建议在 vcp_clues_info 表上建立联合索引 (deleted_flag, seller_merchant_id, seller_merchant_name),以实现覆盖索引扫描(Index Only Scan),避免回表。

    2. 工程最佳实践:DTO 包路径规划不一致(Web 与 Pad 混用)

    • 问题描述:观察 CluesController.java 和 CluesInfoService.java 中的 import 语句可以发现,请求入参 CluesMerchantPageReq 位于 web 包下,而响应出参 CluesMerchantPageResp 却位于 pad 包下。
      • Req: com.gsc4cloud.gsc.vpc.api.req.web.clues.CluesMerchantPageReq
      • Resp: com.gsc4cloud.gsc.vpc.api.dto.pad.resdto.clues.CluesMerchantPageResp
    • 影响分析:破坏了工程结构的统一性和可维护性,容易让后续接手的开发者对该 API 的实际调用端(是 Web 端还是 Pad 端)产生困惑。
    • 优化建议:统一包路径。根据该接口的实际归属,将 Req 和 Resp 统一移动到 web 或 pad 对应的目录下。

    3. 工程最佳实践:Service 层存在冗余的防御性代码

    • 问题描述:在 CluesInfoService.merchantPage 方法中,对 req 和 req.getT() 进行了判空和 new 对象的操作。
    • 影响分析:由于 Controller 层使用了 @RequestBody 注解,Spring 框架在请求到达时会强制要求 body 存在(除非设置 required = false),因此 req 在这里几乎不可能为 null。过度的防御性编程不仅增加了无意义的样板代码,还可能掩盖了上游接口契约未严格遵守的问题。
    • 优化建议:移除 Service 层的判空逻辑,将校验前置。建议在 Controller 层利用 Spring Validation(如 @Valid / @Validated 注解)来保证分页参数的合法性。 java // 优化后的 Service public Page<CluesMerchantPageResp> merchantPage(PageRequest<CluesMerchantPageReq> req) { Page<CluesMerchantPageResp> page = new Page<>(req.getCurrentPage(), req.getPageSize()); return baseMapper.merchantPage(page, req.getT()); }

    二、评分明细

    • 功能实现的正确性与健壮性(38/40分): 功能逻辑基本正确,未发现 MyBatis 子查询违规现象。扣掉 2 分是因为 GROUP BY 分页在 MyBatis-Plus 中存在偶发的 Count 统计隐患(取决于具体 MP 版本配置)。
    • 安全性与潜在风险(30/30分): SQL 中使用了 CONCAT('%', #{req.keyword}, '%'),有效防止了 SQL 注入;无明显越权或敏感信息泄露风险。
    • 最佳实践与可维护性(15/20分): 代码整体风格整洁,但存在 DTO 包路径(Web/Pad)不一致,以及 Service 层冗余判空的问题,扣 5 分。
    • 性能与资源利用(2/5分): 在业务大表上直接使用 GROUP BY 提取维度属性,是典型的 SQL 性能反模式,长期运行存在较大的慢 SQL 风险,扣 3 分。
    • 提交信息质量(5/5分): Commit 信息非常优秀,采用了 Conventional Commits 规范,且清晰地列出了每一个文件的变更意图,可追溯性极强。

    总分:90分

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