Ready for Review
As a 用户, I want 订单快照中的商品名称包含完整的父商品名称和规格信息, so that 订单页面能正确显示商品信息,与购物车显示逻辑保持一致
packages/orders-module-mt/src/services/order.mt.service.ts 中的 createOrder 方法goodsName 字段的赋值逻辑(第139行:goodsName: info.goods.name)spuId 字段的使用方式createOrder 方法的商品循环中,判断商品是否为子商品(通过 spuId 字段)spuId > 0),通过 spuId 查询父商品实体,获取父商品名称goodsName 字段(例如:goodsName =${parentGoods.name} ${goods.name}``)spuId = 0)保持现有逻辑不变createOrder 方法中的商品名称拼接逻辑添加单元测试packages/orders-module-mt/tests/integration/user-orders-routes.integration.test.ts 中新增针对父子商品的订单创建测试用例packages/orders-module-mt/src/services/order.mt.service.ts 的 createOrder 方法中,goodsName 字段直接使用商品实体的 name 字段(第139行)。对于子商品,这会导致订单快照中存储的是子商品的规格名称,而不是父商品名称+规格名称的组合。GoodsMt)包含 spuId 字段,用于标识父子商品关系(spuId = 0 表示父商品,spuId > 0 表示子商品)packages/orders-module-mt/src/services/order.mt.service.ts [Source: architecture/source-tree.md#实际项目结构]packages/orders-module-mt/tests/integration/user-orders-routes.integration.test.ts 中新增测试用例GoodsMt 实体包含 spuId: number 字段(父商品ID)[Source: packages/goods-module-mt/src/entities/goods.entity.mt.ts:77-78]spuId = 0:父商品或无父子关系的商品spuId > 0:子商品,指向父商品的IDname: string [Source: packages/goods-module-mt/src/entities/goods.entity.mt.ts:17-18]createOrder 方法在第134-152行创建订单商品明细goodsName: info.goods.name 直接使用商品名称tenantId 过滤条件 [Source: architecture/coding-standards.md#架构原则]修改 createOrder 方法:
// 在商品循环中收集需要查询的父商品ID
const parentGoodsIds = new Set<number>();
for (const item of products) {
const goods = await this.goodsRepository.findOne({
where: { id: item.id, tenantId }
});
// ... 现有验证逻辑
if (goods.spuId > 0) {
parentGoodsIds.add(goods.spuId);
}
}
// 批量查询父商品信息
const parentGoodsMap = new Map<number, GoodsMt>();
if (parentGoodsIds.size > 0) {
const parentGoods = await this.goodsRepository.find({
where: { id: In([...parentGoodsIds]), tenantId }
});
parentGoods.forEach(g => parentGoodsMap.set(g.id, g));
}
// 创建订单商品明细时使用正确的商品名称
const orderGoodsList = goodsInfo.map(info => {
let goodsName = info.goods.name;
if (info.goods.spuId > 0) {
const parentGoods = parentGoodsMap.get(info.goods.spuId);
if (parentGoods) {
goodsName = `${parentGoods.name} ${info.goods.name}`;
}
}
return {
// ... 其他字段
goodsName,
// ... 其他字段
};
});
测试策略:
packages/orders-module-mt/src/services/order.mt.service.ts - 修改 createOrder 方法中的商品名称拼接逻辑packages/orders-module-mt/tests/integration/user-orders-routes.integration.test.ts - 在现有集成测试中新增针对父子商品的订单创建测试用例,验证订单快照商品名称格式tenantId 条件 [Source: architecture/coding-standards.md#架构原则]In 操作符进行批量查询,避免N+1问题spuId = 0)的行为保持不变packages/orders-module-mt/tests/unit/**/*.test.ts [Source: architecture/testing-strategy.md#单元测试]packages/orders-module-mt/tests/integration/**/*.test.ts [Source: architecture/testing-strategy.md#集成测试]| Date | Version | Description | Author |
|---|---|---|---|
| 2025-12-15 | 1.0 | 初始故事创建 | Bob (Scrum Master) |
此部分由开发代理在实施过程中填写
goodsName 字段直接使用商品名称的问题packages/orders-module-mt/src/services/order.mt.service.ts 中的 createOrder 方法,实现了子商品快照名称优化逻辑spuId = 0)保持现有逻辑不变packages/orders-module-mt/src/services/order.mt.service.ts - 修改了 createOrder 方法,添加了父商品批量查询和商品名称拼接逻辑packages/orders-module-mt/tests/integration/user-orders-routes.integration.test.ts - 新增了两个集成测试用例,验证子商品和单规格商品的订单快照商品名称docs/stories/006.014.order-submit-goods-name-optimization.story.md - 更新了任务状态和开发记录此部分由QA代理在审查完成后填写