diff --git a/ecom-dmb-backend/docs/订单同步转换与BI日汇聚设计.md b/ecom-dmb-backend/docs/订单同步转换与BI日汇聚设计.md index 1f9ccff6..b7ad8ba6 100644 --- a/ecom-dmb-backend/docs/订单同步转换与BI日汇聚设计.md +++ b/ecom-dmb-backend/docs/订单同步转换与BI日汇聚设计.md @@ -222,8 +222,6 @@ FE 打开店铺增量开关 | `order.convert.pdd.full.dlq` | Queue | 全量转换死信 | | `order.convert.pdd.inc` | Queue | PDD 增量转换 | | `order.convert.pdd.inc.dlq` | Queue | 增量转换死信 | -| `order.convert.pdd` | Queue | **遗留**共用队列(仅排水转发到 full/inc) | -| `order.convert.pdd.dlq` | Queue | 遗留转换死信 | | `bi.stat.full` | Queue | BI 全日重算 | | `bi.stat.full.dlq` | Queue | 全量计算死信 | | `bi.stat.inc` | Queue | BI 增量 delta 累加 | @@ -235,7 +233,6 @@ RoutingKey: |-----|----------| | `order.convert.pdd.full` | `order.convert.pdd.full` | | `order.convert.pdd.inc` | `order.convert.pdd.inc` | -| `order.convert.pdd` | `order.convert.pdd`(遗留排水) | | `bi.stat.full` | `bi.stat.full` | | `bi.stat.inc` | `bi.stat.inc` | @@ -332,7 +329,6 @@ RoutingKey: | `PddOrderConvertPublisher` | sync 成功后发 `OrderConvertMessage`(full/inc 分队列) | | `PddOrderConvertFullConsumer` | 消费 `order.convert.pdd.full`(日锁+信号量) | | `PddOrderConvertIncConsumer` | 消费 `order.convert.pdd.inc`(同店独占) | -| `PddOrderConvertLegacyDrainConsumer` | 旧共用队列排水转发 | | `PddOrderConvertService` | `channel_pdd_order(+item)` → `ec_order(+item)` | | `PddOrderStatusMapper` | PDD 状态整型 → 内部 `OrderStatus` | | `PddBiCalcPublisher` | 转换完成后发 `bi.stat.full` / `bi.stat.inc` | diff --git a/ecom-dmb-backend/sql/design/channel/channel_pdd_shop_design.sql b/ecom-dmb-backend/sql/design/channel/channel_pdd_shop_design.sql index 067bb3b2..36e1c059 100644 --- a/ecom-dmb-backend/sql/design/channel/channel_pdd_shop_design.sql +++ b/ecom-dmb-backend/sql/design/channel/channel_pdd_shop_design.sql @@ -3,8 +3,8 @@ -- 数据来源:pdd.mall.info.get → mall_info_get_response -- 设计原则: -- 1. 与 ec_shop(内部店铺)分离,本表只存拼多多平台店铺镜像 --- 2. 不主动 FK 关联 ec_shop;绑定由 ec_shop.platform_code + external_shop_id(= mall_id)维护 --- 3. 授权后拉取写入本表,再按公司 + 拼多多平台 + mall_id upsert ec_shop +-- 2. 不主动 FK 关联 ec_shop;绑定由 ec_shop.platform_code + external_shop_id(= channel_pdd_shop.id)维护 +-- 3. 授权后写入本表,再把本表主键写入 ec_shop.external_shop_id -- ======================================== DROP TABLE IF EXISTS `channel_pdd_shop`; diff --git a/ecom-dmb-backend/sql/design/ec/ec_shop_design.sql b/ecom-dmb-backend/sql/design/ec/ec_shop_design.sql index 6021767a..f4dd2ffb 100644 --- a/ecom-dmb-backend/sql/design/ec/ec_shop_design.sql +++ b/ecom-dmb-backend/sql/design/ec/ec_shop_design.sql @@ -14,14 +14,14 @@ CREATE TABLE `ec_shop` ( `logo_image_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT 'logo图片ID', `logo_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'logo外链URL(渠道授权等;查询时有 logo_image_id 则覆盖)', `platform_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台代码(软约定枚举,无平台表)', - `external_shop_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '外部店铺ID(如拼多多 mall_id;与 platform_code 组合关联平台店铺)', + `external_shop_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '外部/平台店铺表主键ID(如 channel_pdd_shop.id;与 platform_code 组合关联)', `order_inc_sync_enabled` tinyint NOT NULL DEFAULT 0 COMMENT '订单增量同步开关:0关 1开(产品配置,与渠道运行态分离)', `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', `create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID', `update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID', PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `uk_ec_shop_company_platform_external`(`company_id` ASC, `platform_code` ASC, `external_shop_id` ASC) USING BTREE COMMENT '同一公司同一平台下外部店铺ID唯一(NULL 可重复,手工店)', + UNIQUE INDEX `uk_ec_shop_company_platform_external`(`company_id` ASC, `platform_code` ASC, `external_shop_id` ASC) USING BTREE COMMENT '同一公司同一平台下平台店铺主键唯一(NULL 可重复,手工店)', INDEX `idx_company_id`(`company_id` ASC) USING BTREE, INDEX `idx_platform_code`(`platform_code` ASC) USING BTREE, INDEX `idx_ec_shop_order_inc_sync`(`platform_code` ASC, `order_inc_sync_enabled` ASC) USING BTREE COMMENT '增量同步 Job 扫描', diff --git a/ecom-dmb-backend/sql/migration/V20260820__ec_shop_external_shop_pk.sql b/ecom-dmb-backend/sql/migration/V20260820__ec_shop_external_shop_pk.sql new file mode 100644 index 00000000..89c9bc8b --- /dev/null +++ b/ecom-dmb-backend/sql/migration/V20260820__ec_shop_external_shop_pk.sql @@ -0,0 +1,26 @@ +-- ec_shop.external_shop_id:由平台侧业务 ID(如 PDD mall_id)改为平台店铺表主键(如 channel_pdd_shop.id) + +-- 1) 拼多多:mall_id → channel_pdd_shop.id +UPDATE `ec_shop` s +INNER JOIN `channel_pdd_shop` cps + ON cps.`company_id` = s.`company_id` + AND s.`platform_code` = 'pdd' + AND s.`external_shop_id` = CAST(cps.`mall_id` AS CHAR) +SET s.`external_shop_id` = CAST(cps.`id` AS CHAR); + +-- 2) 无法映射到平台店铺主键的遗留值清空(避免改类型失败 / 脏数据) +UPDATE `ec_shop` s +LEFT JOIN `channel_pdd_shop` cps + ON cps.`id` = CAST(NULLIF(TRIM(s.`external_shop_id`), '') AS UNSIGNED) +SET s.`external_shop_id` = NULL +WHERE s.`external_shop_id` IS NOT NULL + AND TRIM(s.`external_shop_id`) <> '' + AND cps.`id` IS NULL; + +-- 3) 列类型改为 bigint,语义为平台店铺表主键 +ALTER TABLE `ec_shop` + DROP INDEX `uk_ec_shop_company_platform_external`, + MODIFY COLUMN `external_shop_id` bigint UNSIGNED NULL DEFAULT NULL + COMMENT '外部/平台店铺表主键ID(如 channel_pdd_shop.id;与 platform_code 组合关联)', + ADD UNIQUE INDEX `uk_ec_shop_company_platform_external`(`company_id` ASC, `platform_code` ASC, `external_shop_id` ASC) + USING BTREE COMMENT '同一公司同一平台下平台店铺主键唯一(NULL 可重复,手工店)'; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/mq/OrderMqConstants.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/mq/OrderMqConstants.java index 493f6406..e5c410da 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/mq/OrderMqConstants.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/mq/OrderMqConstants.java @@ -23,16 +23,6 @@ public final class OrderMqConstants { public static final String QUEUE_ORDER_CONVERT_PDD_INC = "order.convert.pdd.inc"; public static final String QUEUE_ORDER_CONVERT_PDD_INC_DLQ = "order.convert.pdd.inc.dlq"; - /** @deprecated 已拆为 full/inc;保留供旧队列排水 */ - @Deprecated - public static final String RK_ORDER_CONVERT_PDD = "order.convert.pdd"; - /** @deprecated 已拆为 full/inc;保留供旧队列排水 */ - @Deprecated - public static final String QUEUE_ORDER_CONVERT_PDD = "order.convert.pdd"; - /** @deprecated */ - @Deprecated - public static final String QUEUE_ORDER_CONVERT_PDD_DLQ = "order.convert.pdd.dlq"; - public static final String RK_BI_STAT_FULL = "bi.stat.full"; public static final String QUEUE_BI_STAT_FULL = "bi.stat.full"; public static final String QUEUE_BI_STAT_FULL_DLQ = "bi.stat.full.dlq"; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/infra/config/RabbitBiConfig.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/infra/config/RabbitBiConfig.java index c147771d..63ce01bb 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/infra/config/RabbitBiConfig.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/bi/infra/config/RabbitBiConfig.java @@ -83,27 +83,6 @@ public class RabbitBiConfig { .with(OrderMqConstants.RK_ORDER_CONVERT_PDD_INC); } - /** 旧共用队列:仅排水,新消息不再写入 */ - @Bean - public Queue orderConvertPddQueue() { - return QueueBuilder.durable(OrderMqConstants.QUEUE_ORDER_CONVERT_PDD) - .withArgument("x-dead-letter-exchange", "") - .withArgument("x-dead-letter-routing-key", OrderMqConstants.QUEUE_ORDER_CONVERT_PDD_DLQ) - .build(); - } - - @Bean - public Queue orderConvertPddDlq() { - return QueueBuilder.durable(OrderMqConstants.QUEUE_ORDER_CONVERT_PDD_DLQ).build(); - } - - @Bean - public Binding orderConvertPddBinding(Queue orderConvertPddQueue, TopicExchange orderTopicExchange) { - return BindingBuilder.bind(orderConvertPddQueue) - .to(orderTopicExchange) - .with(OrderMqConstants.RK_ORDER_CONVERT_PDD); - } - @Bean public Queue orderProductAutoCreatePddQueue() { return QueueBuilder.durable(OrderMqConstants.QUEUE_ORDER_PRODUCT_AUTO_CREATE_PDD) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/auth/model/vo/PddAuthVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/auth/model/vo/PddAuthVO.java new file mode 100644 index 00000000..7b4a976b --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/auth/model/vo/PddAuthVO.java @@ -0,0 +1,41 @@ +package top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 拼多多授权信息(对外展示,不含 token / raw_response) + */ +@Data +@Schema(description = "拼多多授权信息VO") +public class PddAuthVO { + + @Schema(description = "授权主键ID") + private Long id; + + @Schema(description = "公司ID") + private Long companyId; + + @Schema(description = "拼多多授权主体ID(owner_id)") + private String ownerId; + + @Schema(description = "access_token 过期时间") + private LocalDateTime expiresAt; + + @Schema(description = "refresh_token 过期时间") + private LocalDateTime refreshTokenExpiresAt; + + @Schema(description = "授权 scope(JSON 数组字符串)") + private String scope; + + @Schema(description = "状态:0=失效 1=正常 2=已撤销") + private Integer status; + + @Schema(description = "创建时间") + private LocalDateTime createTime; + + @Schema(description = "更新时间") + private LocalDateTime updateTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/auth/service/impl/PddAuthServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/auth/service/impl/PddAuthServiceImpl.java index 0136f59b..a46d831b 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/auth/service/impl/PddAuthServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/auth/service/impl/PddAuthServiceImpl.java @@ -181,7 +181,14 @@ public class PddAuthServiceImpl implements PddAuthService { } upsertPddShop(companyId, auth.getId(), mallId, mallInfo, tokenResponse.getOwnerName()); - bindInternalShop(companyId, userId, shopId, mallId, mallInfo); + PddShopPO pddShop = pddShopMapper.selectOne(new LambdaQueryWrapper() + .eq(PddShopPO::getCompanyId, companyId) + .eq(PddShopPO::getMallId, mallId) + .last("LIMIT 1")); + if (pddShop == null || pddShop.getId() == null) { + return buildResultHtml(false, "同步拼多多店铺失败"); + } + bindInternalShop(companyId, userId, shopId, pddShop.getId(), mallInfo); String shopName = firstNonBlank( mallInfo != null ? mallInfo.getMallName() : null, @@ -326,12 +333,12 @@ public class PddAuthServiceImpl implements PddAuthService { } /** - * 将拼多多 mall_id 写入指定内部店铺的 external_shop_id;若已被其他内部店占用则先解绑再改绑。 + * 将 channel_pdd_shop 主键写入指定内部店铺的 external_shop_id;若已被其他内部店占用则先解绑再改绑。 */ private void bindInternalShop(Long companyId, Long userId, Long shopId, - Long mallId, + Long channelPddShopId, PddMallApiSnapshot mallInfo) { ShopPO shop = shopMapper.selectById(shopId); if (shop == null || !companyId.equals(shop.getCompanyId())) { @@ -342,13 +349,11 @@ public class PddAuthServiceImpl implements PddAuthService { throw new BusinessException("内部店铺不是拼多多平台,无法绑定"); } - String externalShopId = String.valueOf(mallId); - - // 同一公司+平台下外部店 ID 唯一:若已被其他内部店占用则解绑 + // 同一公司+平台下外部店主键唯一:若已被其他内部店占用则解绑 ShopPO occupied = shopMapper.selectOne(new LambdaQueryWrapper() .eq(ShopPO::getCompanyId, companyId) .eq(ShopPO::getPlatformCode, shop.getPlatformCode()) - .eq(ShopPO::getExternalShopId, externalShopId) + .eq(ShopPO::getExternalShopId, channelPddShopId) .ne(ShopPO::getId, shopId) .last("LIMIT 1")); if (occupied != null) { @@ -356,10 +361,10 @@ public class PddAuthServiceImpl implements PddAuthService { .eq(ShopPO::getId, occupied.getId()) .set(ShopPO::getExternalShopId, null) .set(ShopPO::getUpdateBy, userId)); - log.info("拼多多外部店 {} 从内部店 {} 解绑,改绑至 {}", externalShopId, occupied.getId(), shopId); + log.info("拼多多平台店铺 {} 从内部店 {} 解绑,改绑至 {}", channelPddShopId, occupied.getId(), shopId); } - shop.setExternalShopId(externalShopId); + shop.setExternalShopId(channelPddShopId); // 无系统内部 logo 时,用授权店铺 logo 填充外链(与商品渠道图口径一致) if (shop.getLogoImageId() == null && !StringUtils.hasText(shop.getLogoUrl()) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/convert/consumer/PddOrderConvertLegacyDrainConsumer.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/convert/consumer/PddOrderConvertLegacyDrainConsumer.java deleted file mode 100644 index f9a4268f..00000000 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/convert/consumer/PddOrderConvertLegacyDrainConsumer.java +++ /dev/null @@ -1,35 +0,0 @@ -package top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.consumer; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.stereotype.Component; -import top.xyquan.ecomdmbbackend.common.mq.OrderConvertMessage; -import top.xyquan.ecomdmbbackend.common.mq.OrderConvertMode; -import top.xyquan.ecomdmbbackend.common.mq.OrderMqConstants; - -/** - * 旧共用队列排水:按 mode 转发到 full/inc 新队列后丢弃本消息。 - */ -@Slf4j -@Component -@RequiredArgsConstructor -public class PddOrderConvertLegacyDrainConsumer { - - private final RabbitTemplate rabbitTemplate; - - @RabbitListener(queues = OrderMqConstants.QUEUE_ORDER_CONVERT_PDD) - public void onMessage(OrderConvertMessage message) { - if (message == null || message.getMode() == null) { - log.warn("旧转换队列消息非法,丢弃: {}", message); - return; - } - String rk = message.getMode() == OrderConvertMode.FULL_DAY - ? OrderMqConstants.RK_ORDER_CONVERT_PDD_FULL - : OrderMqConstants.RK_ORDER_CONVERT_PDD_INC; - rabbitTemplate.convertAndSend(OrderMqConstants.EXCHANGE, rk, message); - log.info("旧转换队列已转发 mode={} shopId={} messageId={} -> {}", - message.getMode(), message.getShopId(), message.getMessageId(), rk); - } -} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/job/PddOrderIncrementalSyncJob.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/job/PddOrderIncrementalSyncJob.java index 58939356..8e19affc 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/job/PddOrderIncrementalSyncJob.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/job/PddOrderIncrementalSyncJob.java @@ -40,8 +40,7 @@ public class PddOrderIncrementalSyncJob { List shops = shopMapper.selectList(new LambdaQueryWrapper() .eq(ShopPO::getPlatformCode, PlatformCode.PDD.getCode()) .eq(ShopPO::getOrderIncSyncEnabled, 1) - .isNotNull(ShopPO::getExternalShopId) - .ne(ShopPO::getExternalShopId, "")); + .isNotNull(ShopPO::getExternalShopId)); Set done = new HashSet<>(); for (ShopPO shop : shops) { if (!done.add(shop.getId())) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/service/PddOrderSyncContextResolver.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/service/PddOrderSyncContextResolver.java index a7bd2994..d2fa846b 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/service/PddOrderSyncContextResolver.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/service/PddOrderSyncContextResolver.java @@ -48,19 +48,13 @@ public class PddOrderSyncContextResolver { if (!PlatformCode.PDD.getCode().equals(shop.getPlatformCode())) { throw new BusinessException("仅支持拼多多平台店铺同步订单"); } - if (!StringUtils.hasText(shop.getExternalShopId())) { + if (shop.getExternalShopId() == null) { throw new BusinessException("店铺尚未绑定拼多多外部店,请先完成授权"); } - Long mallId; - try { - mallId = Long.parseLong(shop.getExternalShopId().trim()); - } catch (NumberFormatException e) { - throw new BusinessException("外部店铺 ID 非法: " + shop.getExternalShopId()); - } PddShopPO pddShop = pddShopMapper.selectOne(new LambdaQueryWrapper() + .eq(PddShopPO::getId, shop.getExternalShopId()) .eq(PddShopPO::getCompanyId, companyId) - .eq(PddShopPO::getMallId, mallId) .last("LIMIT 1")); if (pddShop == null || pddShop.getPddAuthId() == null) { throw new BusinessException("未找到拼多多店铺授权绑定,请重新授权"); @@ -77,7 +71,7 @@ public class PddOrderSyncContextResolver { .auth(auth) .companyId(companyId) .shopId(shopId) - .mallId(mallId) + .mallId(pddShop.getMallId()) .accessToken(auth.getAccessToken()) .build(); } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/service/PddOrderSyncService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/service/PddOrderSyncService.java index e24b839e..3ed0208b 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/service/PddOrderSyncService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/order/sync/service/PddOrderSyncService.java @@ -171,8 +171,7 @@ public class PddOrderSyncService { public List listBoundPddShops(Long companyId) { return shopMapper.selectList(new LambdaQueryWrapper() .eq(ShopPO::getCompanyId, companyId) - .isNotNull(ShopPO::getExternalShopId) - .ne(ShopPO::getExternalShopId, "")); + .isNotNull(ShopPO::getExternalShopId)); } public PddOrderSyncResultVO syncByConfirmDateForTask(Long companyId, Long shopId, LocalDate day, Long taskId) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/controller/PddShopController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/controller/PddShopController.java index 2f219a10..3263d2e4 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/controller/PddShopController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/controller/PddShopController.java @@ -60,7 +60,7 @@ public class PddShopController { return ApiResponse.success("获取成功", result); } - @Operation(summary = "详情", description = "根据ID获取拼多多店铺详情") + @Operation(summary = "详情", description = "根据ID获取拼多多店铺详情(含授权信息,不含 token)") @GetMapping("/detail/{id}") @RequirePermission(value = "biz:pdd:shop:read", description = "查询拼多多店铺详情", allowSuper = true) public ApiResponse getPddShopDetail(@Parameter(description = "店铺ID") @PathVariable Long id) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/model/vo/PddShopVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/model/vo/PddShopVO.java index b9548b26..80f4c7db 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/model/vo/PddShopVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/model/vo/PddShopVO.java @@ -2,6 +2,7 @@ package top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.model.vo.PddAuthVO; import java.time.LocalDateTime; @@ -18,6 +19,9 @@ public class PddShopVO { @Schema(description = "拼多多授权ID(channel_pdd_auth.id)") private Long pddAuthId; + @Schema(description = "关联的拼多多授权信息(有 pddAuthId 时返回,不含 token)") + private PddAuthVO auth; + @Schema(description = "拼多多店铺ID(mall_id)") private Long mallId; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/PddShopService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/PddShopService.java index 5cce358e..8fe69aba 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/PddShopService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/PddShopService.java @@ -9,6 +9,8 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.dto.UpdatePddSho import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.po.PddShopPO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.vo.PddShopVO; +import java.util.List; + public interface PddShopService extends IService { PddShopVO createPddShop(CreatePddShopDTO createPddShopDTO); @@ -20,4 +22,14 @@ public interface PddShopService extends IService { PageResultVO getPddShopPage(PageQueryDTO pageQueryDTO); PddShopVO getPddShopDetail(Long id); + + /** 转为 VO;withAuth=true 时按 pddAuthId 嵌套授权信息(不含 token) */ + PddShopVO toVo(PddShopPO shop, boolean withAuth); + + List toVoList(List shops, boolean withAuth); + + /** 列表用简要信息(不含描述/类型/授权详情等) */ + PddShopVO toBriefVo(PddShopPO shop); + + List toBriefVoList(List shops); } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/impl/PddShopServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/impl/PddShopServiceImpl.java index d2f22e7a..f3928eda 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/impl/PddShopServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/impl/PddShopServiceImpl.java @@ -10,6 +10,9 @@ import top.xyquan.ecomdmbbackend.common.exception.BusinessException; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.mapper.PddAuthMapper; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.model.po.PddAuthPO; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.model.vo.PddAuthVO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.mapper.PddShopMapper; import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.dto.CreatePddShopDTO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.dto.PddShopFilterDTO; @@ -20,15 +23,20 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.service.PddShopService import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; @Service public class PddShopServiceImpl extends ServiceImpl implements PddShopService { private final CurrentUserContext currentUserContext; + private final PddAuthMapper pddAuthMapper; - public PddShopServiceImpl(CurrentUserContext currentUserContext) { + public PddShopServiceImpl(CurrentUserContext currentUserContext, PddAuthMapper pddAuthMapper) { this.currentUserContext = currentUserContext; + this.pddAuthMapper = pddAuthMapper; } @Override @@ -59,7 +67,7 @@ public class PddShopServiceImpl extends ServiceImpl im } this.save(shop); - return convertToVO(shop); + return toVo(shop, true); } @Override @@ -95,7 +103,7 @@ public class PddShopServiceImpl extends ServiceImpl im shop.setCompanyId(companyId); this.updateById(shop); - return convertToVO(shop); + return toVo(this.getById(id), true); } @Override @@ -135,9 +143,7 @@ public class PddShopServiceImpl extends ServiceImpl im IPage page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); IPage result = this.page(page, wrapper); - List voList = result.getRecords().stream() - .map(this::convertToVO) - .collect(Collectors.toList()); + List voList = toBriefVoList(result.getRecords()); return PageResultVO.create(voList, result.getTotal(), (int) pageQueryDTO.getPage(), (int) pageQueryDTO.getPageSize()); @@ -149,12 +155,90 @@ public class PddShopServiceImpl extends ServiceImpl im if (shop == null) { throw new BusinessException("拼多多店铺不存在"); } - return convertToVO(shop); + Long companyId = currentUserContext.getCurrentCompanyId(); + if (!companyId.equals(shop.getCompanyId())) { + throw new BusinessException("拼多多店铺不存在"); + } + return toVo(shop, true); } - private PddShopVO convertToVO(PddShopPO shop) { + @Override + public PddShopVO toVo(PddShopPO shop, boolean withAuth) { + if (shop == null) { + return null; + } PddShopVO vo = new PddShopVO(); BeanCopyUtils.copyProperties(shop, vo); + if (withAuth && shop.getPddAuthId() != null) { + vo.setAuth(toAuthVo(pddAuthMapper.selectById(shop.getPddAuthId()))); + } + return vo; + } + + @Override + public List toVoList(List shops, boolean withAuth) { + if (shops == null || shops.isEmpty()) { + return List.of(); + } + Map authById = Map.of(); + if (withAuth) { + Set authIds = shops.stream() + .map(PddShopPO::getPddAuthId) + .filter(Objects::nonNull) + .collect(Collectors.toSet()); + if (!authIds.isEmpty()) { + authById = pddAuthMapper.selectBatchIds(authIds).stream() + .collect(Collectors.toMap(PddAuthPO::getId, this::toAuthVo, (a, b) -> a)); + } + } + Map finalAuthById = authById; + return shops.stream().map(shop -> { + PddShopVO vo = new PddShopVO(); + BeanCopyUtils.copyProperties(shop, vo); + if (withAuth && shop.getPddAuthId() != null) { + vo.setAuth(finalAuthById.get(shop.getPddAuthId())); + } + return vo; + }).collect(Collectors.toList()); + } + + @Override + public PddShopVO toBriefVo(PddShopPO shop) { + if (shop == null) { + return null; + } + PddShopVO vo = new PddShopVO(); + vo.setId(shop.getId()); + vo.setCompanyId(shop.getCompanyId()); + vo.setMallId(shop.getMallId()); + vo.setMallName(shop.getMallName()); + vo.setLogo(shop.getLogo()); + vo.setPddAuthId(shop.getPddAuthId()); + return vo; + } + + @Override + public List toBriefVoList(List shops) { + if (shops == null || shops.isEmpty()) { + return List.of(); + } + return shops.stream().map(this::toBriefVo).collect(Collectors.toList()); + } + + private PddAuthVO toAuthVo(PddAuthPO auth) { + if (auth == null) { + return null; + } + PddAuthVO vo = new PddAuthVO(); + vo.setId(auth.getId()); + vo.setCompanyId(auth.getCompanyId()); + vo.setOwnerId(auth.getOwnerId()); + vo.setExpiresAt(auth.getExpiresAt()); + vo.setRefreshTokenExpiresAt(auth.getRefreshTokenExpiresAt()); + vo.setScope(auth.getScope()); + vo.setStatus(auth.getStatus()); + vo.setCreateTime(auth.getCreateTime()); + vo.setUpdateTime(auth.getUpdateTime()); return vo; } } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/importtask/service/impl/ImportTaskProcessorServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/importtask/service/impl/ImportTaskProcessorServiceImpl.java index e8e93434..756853f5 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/importtask/service/impl/ImportTaskProcessorServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/importtask/service/impl/ImportTaskProcessorServiceImpl.java @@ -4,8 +4,6 @@ import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.ibatis.session.SqlSessionFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import top.xyquan.ecomdmbbackend.common.exception.BusinessException; import top.xyquan.ecomdmbbackend.modules.ec.importtask.model.po.ImportTaskPO; @@ -36,7 +34,6 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CodingErrorAction; import java.nio.charset.StandardCharsets; -import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -46,8 +43,6 @@ import java.util.stream.Collectors; @Service public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorService { - private static final Logger log = LoggerFactory.getLogger(ImportTaskProcessorServiceImpl.class); - private final ImportTaskService importTaskService; private final OrderMapper orderMapper; private final RealtimeSseService realtimeSseService; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/mapper/OrderMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/mapper/OrderMapper.java index 29d2ea42..b07061e3 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/mapper/OrderMapper.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/mapper/OrderMapper.java @@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Update; -import org.apache.ibatis.annotations.Select; import top.xyquan.ecomdmbbackend.modules.ec.order.model.dto.OrderListQueryParam; import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderPO; import java.math.BigDecimal; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/service/impl/OrderServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/service/impl/OrderServiceImpl.java index 00ed5731..cb51a416 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/service/impl/OrderServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/service/impl/OrderServiceImpl.java @@ -26,7 +26,6 @@ import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO; import top.xyquan.ecomdmbbackend.modules.ec.order.model.vo.BatchImportResultVO; import top.xyquan.ecomdmbbackend.modules.ec.order.model.vo.OrderItemVO; import top.xyquan.ecomdmbbackend.modules.ec.order.model.vo.OrderVO; -import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuVO; import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO; import top.xyquan.ecomdmbbackend.modules.ec.order.service.OrderService; import top.xyquan.ecomdmbbackend.modules.ec.order.status.model.enums.OrderStatus; @@ -43,10 +42,8 @@ import org.slf4j.Logger; import java.math.BigDecimal; import org.slf4j.LoggerFactory; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -171,8 +168,6 @@ public class OrderServiceImpl extends ServiceImpl implemen @Override @Transactional public void deleteOrder(Long id) { - Long companyId = currentUserContext.getCurrentCompanyId(); - OrderPO existingOrder = requireOrder(id, companyId); orderItemMapper.delete(new LambdaQueryWrapper().eq(OrderItemPO::getOrderId, id)); this.removeById(id); } @@ -278,7 +273,6 @@ public class OrderServiceImpl extends ServiceImpl implemen java.math.BigDecimal shippingCost, java.math.BigDecimal otherCost, java.time.LocalDateTime startTime, java.time.LocalDateTime endTime) { try { - ProductSkuPO sku = productSkuService.getById(skuId); int n = baseMapper.updateCostFields(productCost, shippingCost, otherCost, skuId, startTime, endTime); return n; } catch (Exception ex) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/status/support/OrderStatusStatResolver.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/status/support/OrderStatusStatResolver.java index 8beaa7d6..bbfb626d 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/status/support/OrderStatusStatResolver.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/status/support/OrderStatusStatResolver.java @@ -1,7 +1,6 @@ package top.xyquan.ecomdmbbackend.modules.ec.order.status.support; import org.springframework.stereotype.Component; -import top.xyquan.ecomdmbbackend.modules.ec.order.status.model.enums.OrderStatus; /** * 解析订单统计状态集合。去表后全局固定,忽略 companyId。 diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/support/OrderDtoSupport.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/support/OrderDtoSupport.java index 283d5125..351ea94f 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/support/OrderDtoSupport.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/order/support/OrderDtoSupport.java @@ -10,7 +10,6 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO; import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductSkuPO; import java.math.BigDecimal; -import java.util.ArrayList; import java.util.List; /** diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/controller/ProductSkuController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/controller/ProductSkuController.java index 45a856c7..e5009bba 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/controller/ProductSkuController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/controller/ProductSkuController.java @@ -1,6 +1,5 @@ package top.xyquan.ecomdmbbackend.modules.ec.product.controller; -import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/service/impl/ProductSkuServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/service/impl/ProductSkuServiceImpl.java index 42545ac2..f11e0214 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/service/impl/ProductSkuServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/product/service/impl/ProductSkuServiceImpl.java @@ -30,7 +30,6 @@ import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO; import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; import top.xyquan.ecomdmbbackend.utils.SysFileUtils; -import java.math.BigDecimal; import java.util.Collection; import java.util.HashMap; import java.util.List; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/controller/ShopController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/controller/ShopController.java index 11e9e316..b141a5f8 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/controller/ShopController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/controller/ShopController.java @@ -61,7 +61,7 @@ public class ShopController { return ApiResponse.success("店铺删除成功"); } - @Operation(summary = "分页获取店铺列表", description = "分页获取店铺列表,支持条件过滤;已绑定外部店时附带对应外部店铺 VO(如 pddShop)") + @Operation(summary = "分页获取店铺列表", description = "分页获取店铺列表;已绑定外部店时仅附带渠道店简要信息(id/名称/logo 等),详情请调渠道店铺详情接口") @PostMapping("/list") @RequirePermission(value = "ecom:shop:read", description = "查询店铺列表", allowSuper = true) public ApiResponse> getShopPage( @@ -70,6 +70,14 @@ public class ShopController { return ApiResponse.success("获取店铺列表成功", result); } + @Operation(summary = "店铺详情", description = "根据内部店铺ID获取详情;按 platformCode 嵌套平台店铺简要信息,完整渠道店/授权请再调渠道店铺详情") + @GetMapping("/detail/{id}") + @RequirePermission(value = "ecom:shop:read", description = "查询店铺详情", allowSuper = true) + public ApiResponse getShopDetail(@Parameter(description = "店铺ID") @PathVariable Long id) { + ShopVO vo = shopService.getShopDetail(id); + return ApiResponse.success("获取成功", vo); + } + @Operation(summary = "上传店铺Logo", description = "上传店铺Logo图片,支持跨公司共享") @PostMapping("/upload-logo") @RequirePermission(value = "ecom:shop:manage", description = "上传店铺Logo", allowSuper = true) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/dto/CreateShopDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/dto/CreateShopDTO.java index 8e9d8f70..d3b7537c 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/dto/CreateShopDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/dto/CreateShopDTO.java @@ -31,8 +31,8 @@ public class CreateShopDTO { private String platformCode; /** - * 外部店铺ID(平台侧店铺标识,如拼多多 mall_id) + * 外部/平台店铺表主键 ID(如 channel_pdd_shop.id) */ - @Schema(description = "外部店铺ID(平台侧店铺标识,如拼多多 mall_id)", example = "123456789") - private String externalShopId; + @Schema(description = "外部/平台店铺表主键ID(如 channel_pdd_shop.id)", example = "1") + private Long externalShopId; } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/dto/UpdateShopDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/dto/UpdateShopDTO.java index c586b3bd..a7cf12a4 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/dto/UpdateShopDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/dto/UpdateShopDTO.java @@ -31,8 +31,8 @@ public class UpdateShopDTO { private String platformCode; /** - * 外部店铺ID(平台侧店铺标识,如拼多多 mall_id) + * 外部/平台店铺表主键 ID(如 channel_pdd_shop.id) */ - @Schema(description = "外部店铺ID(平台侧店铺标识,如拼多多 mall_id)", example = "123456789") - private String externalShopId; + @Schema(description = "外部/平台店铺表主键ID(如 channel_pdd_shop.id)", example = "1") + private Long externalShopId; } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/po/ShopPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/po/ShopPO.java index 9313977b..df5bbded 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/po/ShopPO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/po/ShopPO.java @@ -51,10 +51,10 @@ public class ShopPO { private String platformCode; /** - * 外部店铺ID(如拼多多 mall_id;与 platform_code 组合关联平台店铺) + * 外部/平台店铺表主键 ID(如 channel_pdd_shop.id;与 platform_code 组合关联) */ @TableField("external_shop_id") - private String externalShopId; + private Long externalShopId; /** * 订单增量同步开关:0关 1开 diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/vo/ShopVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/vo/ShopVO.java index 78ce6932..b4251b59 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/vo/ShopVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/model/vo/ShopVO.java @@ -44,10 +44,10 @@ public class ShopVO { private String platformCode; /** - * 外部店铺ID(平台侧店铺标识,如拼多多 mall_id) + * 外部/平台店铺表主键 ID(如 channel_pdd_shop.id) */ - @Schema(description = "外部店铺ID(平台侧店铺标识,如拼多多 mall_id)", example = "123456789") - private String externalShopId; + @Schema(description = "外部/平台店铺表主键ID(如 channel_pdd_shop.id)", example = "1") + private Long externalShopId; /** * 关联的拼多多外部店铺(仅 platform=pdd 且已绑定 externalShopId 时有值) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/service/ShopService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/service/ShopService.java index a19b90ca..6ec1e619 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/service/ShopService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/service/ShopService.java @@ -50,6 +50,14 @@ public interface ShopService extends IService { */ PageResultVO getShopPage(PageQueryDTO pageQueryDTO); + /** + * 店铺详情(按平台编码嵌套平台店铺及授权信息) + * + * @param id 店铺ID + * @return 店铺VO + */ + ShopVO getShopDetail(Long id); + /** * 上传店铺Logo * diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/service/impl/ShopServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/service/impl/ShopServiceImpl.java index d4e2a16b..04756c8e 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/service/impl/ShopServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ec/shop/service/impl/ShopServiceImpl.java @@ -13,6 +13,7 @@ import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.mapper.PddShopMapper; import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.po.PddShopPO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.vo.PddShopVO; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.service.PddShopService; import top.xyquan.ecomdmbbackend.modules.ec.product.mapper.ProductMapper; import top.xyquan.ecomdmbbackend.modules.ec.platform.model.enums.PlatformCode; import top.xyquan.ecomdmbbackend.modules.ec.shop.mapper.ShopMapper; @@ -56,17 +57,19 @@ public class ShopServiceImpl extends ServiceImpl implements private final ShopProductRelationMapper shopProductRelationMapper; private final ProductSkuService productSkuService; private final PddShopMapper pddShopMapper; + private final PddShopService pddShopService; public ShopServiceImpl(CurrentUserContext currentUserContext, SysFileService sysFileService, ProductMapper productMapper, ShopProductRelationMapper shopProductRelationMapper, ProductSkuService productSkuService, - PddShopMapper pddShopMapper) { + PddShopMapper pddShopMapper, PddShopService pddShopService) { this.currentUserContext = currentUserContext; this.sysFileService = sysFileService; this.productMapper = productMapper; this.shopProductRelationMapper = shopProductRelationMapper; this.productSkuService = productSkuService; this.pddShopMapper = pddShopMapper; + this.pddShopService = pddShopService; } /** @@ -103,8 +106,9 @@ public class ShopServiceImpl extends ServiceImpl implements // 保存店铺 this.save(shop); - // 转换为VO并返回 - return convertToVO(shop); + ShopVO vo = convertToVO(shop); + attachExternalShop(vo, shop); + return vo; } /** @@ -148,8 +152,10 @@ public class ShopServiceImpl extends ServiceImpl implements // 更新店铺 this.updateById(shop); - // 转换为VO并返回 - return convertToVO(shop); + ShopPO updated = this.getById(id); + ShopVO vo = convertToVO(updated); + attachExternalShop(vo, updated); + return vo; } /** @@ -251,20 +257,35 @@ public class ShopServiceImpl extends ServiceImpl implements if (shop.getPlatformCode() != null && !shop.getPlatformCode().isBlank()) { shopVO.setPlatformName(PlatformCode.labelOf(shop.getPlatformCode())); } + return shopVO; + } + + private void attachExternalShop(ShopVO shopVO, ShopPO shop) { + if (shopVO == null || shop == null) { + return; + } if (PLATFORM_CODE_PDD.equals(shop.getPlatformCode()) - && shop.getExternalShopId() != null && !shop.getExternalShopId().isBlank()) { - Long mallId = parseMallId(shop.getExternalShopId()); - if (mallId != null) { - PddShopPO pddShop = pddShopMapper.selectOne(new LambdaQueryWrapper() - .eq(PddShopPO::getCompanyId, shop.getCompanyId()) - .eq(PddShopPO::getMallId, mallId) - .last("LIMIT 1")); - if (pddShop != null) { - shopVO.setPddShop(convertPddShopToVO(pddShop)); - } + && shop.getExternalShopId() != null) { + PddShopPO pddShop = pddShopMapper.selectOne(new LambdaQueryWrapper() + .eq(PddShopPO::getId, shop.getExternalShopId()) + .eq(PddShopPO::getCompanyId, shop.getCompanyId()) + .last("LIMIT 1")); + if (pddShop != null) { + shopVO.setPddShop(pddShopService.toBriefVo(pddShop)); } } - return shopVO; + } + + @Override + public ShopVO getShopDetail(Long id) { + Long companyId = currentUserContext.getCurrentCompanyId(); + ShopPO shop = this.getById(id); + if (shop == null || !companyId.equals(shop.getCompanyId())) { + throw new BusinessException("店铺不存在"); + } + ShopVO vo = convertToVO(shop); + attachExternalShop(vo, shop); + return vo; } private static void validatePlatformCode(String platformCode) { @@ -287,52 +308,35 @@ public class ShopServiceImpl extends ServiceImpl implements .filter(v -> v.getId() != null) .collect(Collectors.toMap(ShopVO::getId, Function.identity(), (a, b) -> a)); - Map shopIdToMallId = new HashMap<>(); + Map shopIdToExternalId = new HashMap<>(); for (ShopPO shop : shops) { - if (shop.getExternalShopId() == null || shop.getExternalShopId().isBlank()) { + if (shop.getExternalShopId() == null) { continue; } if (!PLATFORM_CODE_PDD.equals(shop.getPlatformCode())) { continue; } - Long mallId = parseMallId(shop.getExternalShopId()); - if (mallId != null) { - shopIdToMallId.put(shop.getId(), mallId); - } + shopIdToExternalId.put(shop.getId(), shop.getExternalShopId()); } - if (shopIdToMallId.isEmpty()) { + if (shopIdToExternalId.isEmpty()) { return; } List pddShops = pddShopMapper.selectList(new LambdaQueryWrapper() .eq(PddShopPO::getCompanyId, companyId) - .in(PddShopPO::getMallId, shopIdToMallId.values())); - Map pddByMallId = pddShops.stream() - .collect(Collectors.toMap(PddShopPO::getMallId, this::convertPddShopToVO, (a, b) -> a)); + .in(PddShopPO::getId, shopIdToExternalId.values())); + Map pddById = pddShopService.toBriefVoList(pddShops).stream() + .collect(Collectors.toMap(PddShopVO::getId, Function.identity(), (a, b) -> a)); - shopIdToMallId.forEach((shopId, mallId) -> { + shopIdToExternalId.forEach((shopId, externalId) -> { ShopVO vo = voById.get(shopId); - PddShopVO pddShop = pddByMallId.get(mallId); + PddShopVO pddShop = pddById.get(externalId); if (vo != null && pddShop != null) { vo.setPddShop(pddShop); } }); } - private static Long parseMallId(String externalShopId) { - try { - return Long.parseLong(externalShopId.trim()); - } catch (NumberFormatException e) { - return null; - } - } - - private PddShopVO convertPddShopToVO(PddShopPO pddShop) { - PddShopVO vo = new PddShopVO(); - BeanCopyUtils.copyProperties(pddShop, vo); - return vo; - } - /** * 分页获取店铺商品信息 */ diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/pdd/shop/apis.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/pdd/shop/apis.ts new file mode 100644 index 00000000..3673e233 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/pdd/shop/apis.ts @@ -0,0 +1,10 @@ +import type { PddShopInfo } from '#/api/ecommerce/shop/types'; + +import { requestClient } from '#/api/request'; + +/** + * 拼多多渠道店铺详情(含授权信息,不含 token) + */ +export async function getPddShopDetailApi(id: number) { + return requestClient.get(`/channel/pdd/shop/detail/${id}`); +} diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/pdd/shop/index.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/pdd/shop/index.ts new file mode 100644 index 00000000..3cefd991 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/pdd/shop/index.ts @@ -0,0 +1 @@ +export * from './apis'; diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/apis.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/apis.ts index b6519e05..42b8eb5f 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/apis.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/apis.ts @@ -37,6 +37,13 @@ export async function deleteShopApi(id: number) { return requestClient.delete(`/ec/shop/delete/${id}`); } +/** + * 店铺详情(含平台店铺及授权信息) + */ +export async function getShopDetailApi(id: number) { + return requestClient.get(`/ec/shop/detail/${id}`); +} + /** * 上传店铺Logo */ diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts index cdacd696..fe01336f 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts @@ -2,31 +2,55 @@ * 店铺相关VO类型定义 */ -/** 拼多多外部店铺信息(列表关联返回) */ +/** 拼多多授权信息(不含 token) */ +export interface PddAuthInfo { + /** 授权主键ID */ + id: number; + /** 公司ID */ + companyId: number; + /** 拼多多授权主体ID(owner_id) */ + ownerId?: string; + /** access_token 过期时间 */ + expiresAt?: string; + /** refresh_token 过期时间 */ + refreshTokenExpiresAt?: string; + /** 授权 scope(JSON 数组字符串) */ + scope?: string; + /** 状态:0=失效 1=正常 2=已撤销 */ + status?: number; + /** 创建时间 */ + createTime?: string; + /** 更新时间 */ + updateTime?: string; +} + +/** 拼多多外部店铺信息 */ export interface PddShopInfo { /** 主键ID */ id: number; /** 公司ID */ - companyId: number; - /** 拼多多授权ID */ + companyId?: number; + /** 拼多多授权ID(列表简要也会带,用于判断是否已授权) */ pddAuthId?: null | number; + /** 关联授权信息(仅详情接口返回) */ + auth?: null | PddAuthInfo; /** 拼多多店铺ID(mall_id) */ - mallId: number; + mallId?: number; /** 店铺名称 */ mallName?: string; /** 店铺logo */ logo?: string; - /** 店铺描述 */ + /** 店铺描述(详情) */ mallDesc?: string; - /** 店铺类型:1个人 2企业 3旗舰店 4专卖店 5专营店 6普通店 */ + /** 店铺类型(详情) */ merchantType?: number; - /** 店铺身份:0厂商 1分销商 2都不是 3都是 */ + /** 店铺身份(详情) */ mallCharacter?: number; - /** 最近一次同步时间 */ + /** 最近一次同步时间(详情) */ lastSyncTime?: string; - /** 创建时间 */ + /** 创建时间(详情) */ createTime?: string; - /** 更新时间 */ + /** 更新时间(详情) */ updateTime?: string; } @@ -47,8 +71,8 @@ export namespace ShopVO { platformCode?: string; /** 平台名称(后端回填) */ platformName?: string; - /** 外部店铺ID(如拼多多 mall_id) */ - externalShopId?: null | string; + /** 外部/平台店铺表主键 ID(如 channel_pdd_shop.id) */ + externalShopId?: null | number; /** 关联的拼多多外部店铺(已授权绑定时返回) */ pddShop?: null | PddShopInfo; /** 创建时间 */ diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/index.vue index 713c1aa9..e1ec1821 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/index.vue @@ -1,25 +1,136 @@ diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/list/components/PddShopDetailModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/list/components/PddShopDetailModal.vue index 4b9aca08..e8b125a7 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/list/components/PddShopDetailModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/list/components/PddShopDetailModal.vue @@ -5,7 +5,9 @@ import { computed, ref } from 'vue'; import { useVbenModal } from '@vben/common-ui'; -import { Descriptions, Tag } from 'ant-design-vue'; +import { Descriptions, Spin, Tag, message } from 'ant-design-vue'; + +import { getPddShopDetailApi } from '#/api/ecommerce/pdd/shop'; const MERCHANT_TYPE_MAP: Record = { 1: '个人', @@ -23,6 +25,13 @@ const MALL_CHARACTER_MAP: Record = { 3: '都是', }; +const AUTH_STATUS_MAP: Record = { + 0: { color: 'error', label: '失效' }, + 1: { color: 'success', label: '正常' }, + 2: { color: 'default', label: '已撤销' }, +}; + +const loading = ref(false); const pddShop = ref(null); const internalShopName = ref(''); @@ -45,10 +54,34 @@ const mallCharacterLabel = computed(() => { return MALL_CHARACTER_MAP[character] ?? String(character); }); -function open(shop: PddShopInfo, shopName?: string) { - pddShop.value = shop; +const authStatus = computed(() => { + const status = pddShop.value?.auth?.status; + if (status == null) { + return pddShop.value?.pddAuthId + ? { color: 'success', label: '已绑定' } + : { color: 'default', label: '未绑定' }; + } + return AUTH_STATUS_MAP[status] ?? { color: 'default', label: String(status) }; +}); + +async function open(pddShopId: number, shopName?: string) { + if (!pddShopId) { + message.warning('暂无外部店铺详情,请先完成授权同步'); + return; + } internalShopName.value = shopName || ''; + pddShop.value = null; modalApi.open(); + try { + loading.value = true; + pddShop.value = await getPddShopDetailApi(pddShopId); + } catch (error) { + console.error('获取拼多多店铺详情失败:', error); + message.error('获取拼多多店铺详情失败'); + modalApi.close(); + } finally { + loading.value = false; + } } defineExpose({ open }); @@ -56,52 +89,84 @@ defineExpose({ open }); diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/list/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/list/index.vue index 7c474b39..476a99f1 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/list/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/list/index.vue @@ -362,11 +362,12 @@ function handleModalSuccess() { } function handleViewExternalShop(record: ShopVO.Info) { - if (!record.pddShop) { + const pddShopId = record.pddShop?.id ?? record.externalShopId; + if (!pddShopId) { message.warning('暂无外部店铺详情,请先完成授权同步'); return; } - pddShopDetailModalRef.value?.open(record.pddShop, record.name); + pddShopDetailModalRef.value?.open(Number(pddShopId), record.name); } function handleSyncPddOrders(record: ShopVO.Info) { @@ -477,7 +478,7 @@ onUnmounted(() => { v-else-if="row.externalShopId" class="text-center text-xs text-slate-500" > - mall_id: {{ row.externalShopId }} + 平台店#{{ row.externalShopId }} -