mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 新增拼多多草稿箱推送
This commit is contained in:
@@ -1,2 +1,84 @@
|
||||
-- 拼多多发布工作台表设计(与 V20260912 migration 一致,供文档查阅)
|
||||
-- channel_pdd_goods_publish_draft / job / job_item
|
||||
-- 拼多多发布工作台表设计(供文档查阅,与 migration 终态一致)
|
||||
-- V20260912__channel_pdd_goods_publish_desk.sql 建表
|
||||
-- V20260915c__pdd_publish_draft_platform_commit.sql 平台草稿关联字段
|
||||
--
|
||||
-- 表:
|
||||
-- channel_pdd_goods_publish_draft 系统草稿(唯一工作区)
|
||||
-- channel_pdd_goods_publish_job 批量发布任务
|
||||
-- channel_pdd_goods_publish_job_item 任务明细
|
||||
--
|
||||
-- 约定:
|
||||
-- 1) 系统草稿为主;拼多多草稿箱是导出结果(pdd_goods_commit_id 等)
|
||||
-- 2) payload_json = { editorState, publishPayload? }
|
||||
-- 3) 跨店克隆不复制 pdd_goods_commit_id / pdd_goods_id / pdd_draft_pushed_at
|
||||
-- 4) 正式上架仍走 pdd.goods.add;推平台草稿走 edit/submit.goods.commit
|
||||
-- ========================================
|
||||
|
||||
-- ========================================
|
||||
-- 系统草稿(发布工作台)
|
||||
-- ========================================
|
||||
CREATE TABLE IF NOT EXISTS `channel_pdd_goods_publish_draft` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`pdd_shop_id` bigint UNSIGNED NULL COMMENT '渠道店铺ID(可空=未分配)',
|
||||
`title` varchar(500) NOT NULL DEFAULT '' COMMENT '草稿标题(展示用)',
|
||||
`cat_id` bigint UNSIGNED NULL COMMENT '叶子类目',
|
||||
`sku_count` int NOT NULL DEFAULT 0 COMMENT 'SKU 组合数快照',
|
||||
`status` varchar(32) NOT NULL DEFAULT 'EDITING' COMMENT 'EDITING/NEED_CHECK/READY/PUBLISHING/FAILED/PUBLISHED',
|
||||
`payload_json` json NULL COMMENT '编辑器状态+可选 publishPayload',
|
||||
`source_draft_id` bigint UNSIGNED NULL COMMENT '克隆来源草稿',
|
||||
`last_error` varchar(1000) NULL COMMENT '最近发布/推送失败原因',
|
||||
`pdd_goods_commit_id` bigint UNSIGNED NULL COMMENT '拼多多草稿 goods_commit_id(最近一次推送)',
|
||||
`pdd_goods_id` bigint UNSIGNED NULL COMMENT '拼多多商品 goods_id(草稿阶段可能为空)',
|
||||
`pdd_draft_pushed_at` datetime NULL COMMENT '最近推送到平台草稿箱时间',
|
||||
`created_by` bigint UNSIGNED NULL COMMENT '创建人',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_pdd_pub_draft_company_shop` (`company_id`, `pdd_shop_id`, `status`),
|
||||
KEY `idx_pdd_pub_draft_company_status` (`company_id`, `status`),
|
||||
CONSTRAINT `fk_pdd_pub_draft_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='拼多多商品发布系统草稿';
|
||||
|
||||
-- ========================================
|
||||
-- 批量发布任务
|
||||
-- ========================================
|
||||
CREATE TABLE IF NOT EXISTS `channel_pdd_goods_publish_job` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`company_id` bigint UNSIGNED NOT NULL,
|
||||
`status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT 'PENDING/RUNNING/SUCCESS/PARTIAL/FAILED',
|
||||
`total_count` int NOT NULL DEFAULT 0,
|
||||
`success_count` int NOT NULL DEFAULT 0,
|
||||
`fail_count` int NOT NULL DEFAULT 0,
|
||||
`message` varchar(1000) NULL,
|
||||
`created_by` bigint UNSIGNED NULL,
|
||||
`started_at` datetime NULL,
|
||||
`finished_at` datetime NULL,
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_pdd_pub_job_company` (`company_id`, `create_time`),
|
||||
CONSTRAINT `fk_pdd_pub_job_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='拼多多商品批量发布任务';
|
||||
|
||||
-- ========================================
|
||||
-- 批量发布任务明细
|
||||
-- ========================================
|
||||
CREATE TABLE IF NOT EXISTS `channel_pdd_goods_publish_job_item` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`job_id` bigint UNSIGNED NOT NULL,
|
||||
`company_id` bigint UNSIGNED NOT NULL,
|
||||
`draft_id` bigint UNSIGNED NOT NULL,
|
||||
`pdd_shop_id` bigint UNSIGNED NULL,
|
||||
`title` varchar(500) NOT NULL DEFAULT '',
|
||||
`status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT 'PENDING/RUNNING/SUCCESS/FAILED',
|
||||
`goods_id` varchar(64) NULL COMMENT '发布成功后的拼多多 goodsId',
|
||||
`error_message` varchar(1000) NULL,
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_pdd_pub_job_item_job` (`job_id`, `status`),
|
||||
KEY `idx_pdd_pub_job_item_draft` (`draft_id`),
|
||||
CONSTRAINT `fk_pdd_pub_job_item_job` FOREIGN KEY (`job_id`) REFERENCES `channel_pdd_goods_publish_job` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `fk_pdd_pub_job_item_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='拼多多商品批量发布任务明细';
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- 系统草稿关联拼多多平台草稿(最近一次推送)
|
||||
ALTER TABLE `channel_pdd_goods_publish_draft`
|
||||
ADD COLUMN `pdd_goods_commit_id` bigint UNSIGNED NULL COMMENT '拼多多草稿 goods_commit_id' AFTER `last_error`,
|
||||
ADD COLUMN `pdd_goods_id` bigint UNSIGNED NULL COMMENT '拼多多商品 goods_id(草稿阶段可能为空)' AFTER `pdd_goods_commit_id`,
|
||||
ADD COLUMN `pdd_draft_pushed_at` datetime NULL COMMENT '最近推送到平台草稿箱时间' AFTER `pdd_goods_id`;
|
||||
+6
@@ -76,6 +76,12 @@ public class PddGoodsPublishDeskController {
|
||||
return ApiResponse.success("删除成功", null);
|
||||
}
|
||||
|
||||
@PostMapping("/drafts/{id}/push-platform")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "推送到拼多多草稿箱", allowSuper = true)
|
||||
public ApiResponse<PddGoodsPublishDraftVO> pushPlatformDraft(@PathVariable Long id) {
|
||||
return ApiResponse.success("已推送到拼多多草稿箱", deskService.pushPlatformDraft(id));
|
||||
}
|
||||
|
||||
@PostMapping("/drafts/clone")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "一键克隆发布草稿", allowSuper = true)
|
||||
public ApiResponse<List<PddGoodsPublishDraftVO>> cloneDraft(@Valid @RequestBody PddPublishDeskCloneDTO dto) {
|
||||
|
||||
+11
@@ -52,6 +52,17 @@ public class PddGoodsPublishDraftPO {
|
||||
@TableField("last_error")
|
||||
private String lastError;
|
||||
|
||||
/** 最近一次推送到拼多多草稿箱的 commitId */
|
||||
@TableField("pdd_goods_commit_id")
|
||||
private Long pddGoodsCommitId;
|
||||
|
||||
/** 平台可能返回的 goodsId;草稿阶段常为空 */
|
||||
@TableField("pdd_goods_id")
|
||||
private Long pddGoodsId;
|
||||
|
||||
@TableField("pdd_draft_pushed_at")
|
||||
private LocalDateTime pddDraftPushedAt;
|
||||
|
||||
@TableField("created_by")
|
||||
private Long createdBy;
|
||||
|
||||
|
||||
+3
@@ -20,6 +20,9 @@ public class PddGoodsPublishDraftVO {
|
||||
private String payloadJson;
|
||||
private Long sourceDraftId;
|
||||
private String lastError;
|
||||
private Long pddGoodsCommitId;
|
||||
private Long pddGoodsId;
|
||||
private LocalDateTime pddDraftPushedAt;
|
||||
private Long createdBy;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
+3
@@ -38,4 +38,7 @@ public interface PddGoodsPublishDeskService {
|
||||
|
||||
/** 重试任务中失败的明细 */
|
||||
PddGoodsPublishJobVO retryFailedItems(Long jobId);
|
||||
|
||||
/** 将系统草稿推送到拼多多草稿箱并回写 commitId */
|
||||
PddGoodsPublishDraftVO pushPlatformDraft(Long id);
|
||||
}
|
||||
|
||||
+72
-1
@@ -12,6 +12,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddGoodsPublishDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddGoodsPublishResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.PddGoodsPublishService;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.mapper.PddGoodsPublishDraftMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.mapper.PddGoodsPublishJobItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.mapper.PddGoodsPublishJobMapper;
|
||||
@@ -33,6 +36,7 @@ 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.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -42,7 +46,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 发布工作台:草稿持久化、克隆、创建异步发布任务。
|
||||
* 发布工作台:系统草稿持久化、克隆、推送平台草稿、批量发布任务。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -62,6 +66,7 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic
|
||||
private final PddShopMapper pddShopMapper;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final PddGoodsPublishJobRunner jobRunner;
|
||||
private final PddGoodsPublishService publishService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
@@ -325,6 +330,69 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic
|
||||
return getJob(jobId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PddGoodsPublishDraftVO pushPlatformDraft(Long id) {
|
||||
PddGoodsPublishDraftPO po = requireDraft(id);
|
||||
if (po.getPddShopId() == null) {
|
||||
throw new BusinessException("请先为系统草稿分配渠道店铺");
|
||||
}
|
||||
if (PddGoodsPublishDraftPO.STATUS_PUBLISHING.equals(po.getStatus())) {
|
||||
throw new BusinessException("发布中的草稿不可推送到平台草稿箱");
|
||||
}
|
||||
PddGoodsPublishDTO payload;
|
||||
try {
|
||||
payload = extractPublishPayload(po);
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("草稿发布数据解析失败:" + e.getMessage());
|
||||
}
|
||||
if (payload.getCatId() == null) {
|
||||
throw new BusinessException("缺少叶子类目,请先在编辑页补全后再推送");
|
||||
}
|
||||
payload.setPddShopId(po.getPddShopId());
|
||||
try {
|
||||
PddGoodsPublishResultVO result = publishService.pushPlatformDraft(
|
||||
payload, po.getPddGoodsCommitId(), po.getPddGoodsId());
|
||||
po.setPddGoodsCommitId(result.getGoodsCommitId());
|
||||
po.setPddGoodsId(result.getGoodsId());
|
||||
po.setPddDraftPushedAt(LocalDateTime.now());
|
||||
po.setLastError(null);
|
||||
draftMapper.updateById(po);
|
||||
return toDraftVo(po, loadShopNamesForOne(po));
|
||||
} catch (BusinessException e) {
|
||||
po.setLastError(trimError(e.getMessage()));
|
||||
draftMapper.updateById(po);
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
po.setLastError(trimError(e.getMessage()));
|
||||
draftMapper.updateById(po);
|
||||
throw new BusinessException("推送到拼多多草稿箱失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String trimError(String msg) {
|
||||
if (!StringUtils.hasText(msg)) {
|
||||
return "推送到拼多多草稿箱失败";
|
||||
}
|
||||
return msg.length() > 1000 ? msg.substring(0, 1000) : msg;
|
||||
}
|
||||
|
||||
private PddGoodsPublishDTO extractPublishPayload(PddGoodsPublishDraftPO draft) throws Exception {
|
||||
if (!StringUtils.hasText(draft.getPayloadJson())) {
|
||||
throw new BusinessException("系统草稿缺少内容,请先在编辑页保存并生成可推送数据");
|
||||
}
|
||||
JsonNode root = objectMapper.readTree(draft.getPayloadJson());
|
||||
JsonNode payload = root.get("publishPayload");
|
||||
if (payload == null || payload.isNull() || !payload.isObject()) {
|
||||
throw new BusinessException("尚未生成可推送数据,请先在编辑页点击「推送到拼多多草稿箱」或「保存并标记可发布」");
|
||||
}
|
||||
if (payload instanceof ObjectNode on && draft.getPddShopId() != null) {
|
||||
on.put("pddShopId", draft.getPddShopId());
|
||||
}
|
||||
return objectMapper.treeToValue(payload, PddGoodsPublishDTO.class);
|
||||
}
|
||||
|
||||
private String rewritePayloadForShop(String payloadJson, Long targetShopId, boolean clearShopBound) {
|
||||
if (!StringUtils.hasText(payloadJson)) {
|
||||
return payloadJson;
|
||||
@@ -417,6 +485,9 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic
|
||||
vo.setPayloadJson(po.getPayloadJson());
|
||||
vo.setSourceDraftId(po.getSourceDraftId());
|
||||
vo.setLastError(po.getLastError());
|
||||
vo.setPddGoodsCommitId(po.getPddGoodsCommitId());
|
||||
vo.setPddGoodsId(po.getPddGoodsId());
|
||||
vo.setPddDraftPushedAt(po.getPddDraftPushedAt());
|
||||
vo.setCreatedBy(po.getCreatedBy());
|
||||
vo.setCreateTime(po.getCreateTime());
|
||||
vo.setUpdateTime(po.getUpdateTime());
|
||||
|
||||
+9
@@ -43,4 +43,13 @@ public interface PddGoodsPublishService {
|
||||
String transferImage(PddPublishTransferImageDTO dto);
|
||||
|
||||
PddGoodsPublishResultVO publish(PddGoodsPublishDTO dto);
|
||||
|
||||
/**
|
||||
* 推送到拼多多草稿箱:图转传 + commit,不入库渠道商品。
|
||||
*
|
||||
* @param existingCommitId 系统草稿上已挂的平台 commitId,可空
|
||||
* @param existingGoodsId 已挂的平台 goodsId,可空;与 commitId 同时有效时走覆盖保存
|
||||
*/
|
||||
PddGoodsPublishResultVO pushPlatformDraft(
|
||||
PddGoodsPublishDTO dto, Long existingCommitId, Long existingGoodsId);
|
||||
}
|
||||
|
||||
+193
-105
@@ -57,7 +57,7 @@ import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 拼多多商品发布:元数据 + 图转传 + add + 按主商品入库。
|
||||
* 拼多多商品发布:元数据 + 图转传 + add / 平台草稿。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -270,104 +270,9 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
ShopAuth ctx = requireShopAuth(dto.getPddShopId());
|
||||
|
||||
ProductPO primary = productMapper.selectById(dto.getPrimaryProductId());
|
||||
if (primary == null || !Objects.equals(primary.getCompanyId(), companyId)) {
|
||||
throw new BusinessException("主内部商品不存在或不属于当前公司");
|
||||
}
|
||||
if (!StringUtils.hasText(primary.getProductCode())) {
|
||||
throw new BusinessException("主内部商品缺少商品编码,无法写入 out_goods_id");
|
||||
}
|
||||
|
||||
List<Long> skuIds = dto.getSkus().stream()
|
||||
.map(PddGoodsPublishSkuDTO::getInternalSkuId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, ProductSkuPO> skuById = new HashMap<>();
|
||||
if (!skuIds.isEmpty()) {
|
||||
List<ProductSkuPO> skus = productSkuService.getByIds(skuIds);
|
||||
if (skus == null || skus.size() != skuIds.size()) {
|
||||
throw new BusinessException("部分内部SKU不存在");
|
||||
}
|
||||
for (ProductSkuPO sku : skus) {
|
||||
if (!Objects.equals(sku.getCompanyId(), companyId)) {
|
||||
throw new BusinessException("内部SKU不属于当前公司 skuId=" + sku.getId());
|
||||
}
|
||||
skuById.put(sku.getId(), sku);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> carousel = resolveImages(companyId, ctx, dto.getCarouselImages());
|
||||
List<String> detail = resolveImages(companyId, ctx, dto.getDetailImages());
|
||||
String mainImage = null;
|
||||
if (StringUtils.hasText(dto.getImageUrl())) {
|
||||
mainImage = resolveOneImage(companyId, ctx, dto.getImageUrl().trim());
|
||||
}
|
||||
|
||||
List<PddGoodsPublishPopApiClient.SkuAddItem> skuAdds = new ArrayList<>();
|
||||
for (PddGoodsPublishSkuDTO skuDto : dto.getSkus()) {
|
||||
ProductSkuPO internal = skuDto.getInternalSkuId() == null
|
||||
? null
|
||||
: skuById.get(skuDto.getInternalSkuId());
|
||||
String outSkuSn = resolveOutSkuSn(skuDto, internal);
|
||||
String thumb = resolveOneImage(companyId, ctx, skuDto.getThumbImage());
|
||||
List<PddGoodsPublishPopApiClient.SkuPropertyItem> sps = new ArrayList<>();
|
||||
if (skuDto.getSkuProperties() != null) {
|
||||
for (PddGoodsPublishSkuPropertyDTO sp : skuDto.getSkuProperties()) {
|
||||
if (sp == null) {
|
||||
continue;
|
||||
}
|
||||
sps.add(new PddGoodsPublishPopApiClient.SkuPropertyItem(
|
||||
sp.getRefPid(), sp.getVid(), sp.getValue(), sp.getPunit()));
|
||||
}
|
||||
}
|
||||
skuAdds.add(new PddGoodsPublishPopApiClient.SkuAddItem(
|
||||
skuDto.getIsOnsale() == null ? 1 : skuDto.getIsOnsale(),
|
||||
999L,
|
||||
skuDto.getMultiPriceFen(),
|
||||
skuDto.getPriceFen(),
|
||||
skuDto.getQuantity(),
|
||||
skuDto.getWeight(),
|
||||
thumb,
|
||||
outSkuSn,
|
||||
normalizeSpecIdList(skuDto.getSpecIdList()),
|
||||
sps));
|
||||
}
|
||||
|
||||
List<PddGoodsPublishPopApiClient.GoodsPropertyItem> goodsProps = new ArrayList<>();
|
||||
if (dto.getGoodsProperties() != null) {
|
||||
for (PddGoodsPublishPropertyDTO p : dto.getGoodsProperties()) {
|
||||
if (p == null) {
|
||||
continue;
|
||||
}
|
||||
goodsProps.add(new PddGoodsPublishPopApiClient.GoodsPropertyItem(
|
||||
p.getRefPid(), p.getVid(), p.getValue(), p.getValueUnit(), p.getTemplatePid(),
|
||||
p.getParentSpecId(), p.getSpecId(), p.getImgUrl(), p.getNote(), p.getGroupId()));
|
||||
}
|
||||
}
|
||||
|
||||
PddGoodsPublishPopApiClient.GoodsAddCommand command =
|
||||
new PddGoodsPublishPopApiClient.GoodsAddCommand(
|
||||
dto.getGoodsName().trim(),
|
||||
dto.getGoodsDesc(),
|
||||
dto.getCatId(),
|
||||
dto.getCostTemplateId(),
|
||||
0,
|
||||
1,
|
||||
dto.getMarketPriceFen(),
|
||||
dto.getShipmentLimitSecond(),
|
||||
dto.getIsFolt(),
|
||||
dto.getIsPreSale(),
|
||||
dto.getIsRefundable(),
|
||||
dto.getSecondHand(),
|
||||
dto.getTwoPiecesDiscount() == null ? 95 : dto.getTwoPiecesDiscount(),
|
||||
carousel,
|
||||
detail,
|
||||
primary.getProductCode().trim(),
|
||||
mainImage,
|
||||
goodsProps,
|
||||
skuAdds);
|
||||
assembleAddCommand(dto, companyId, ctx, true);
|
||||
|
||||
PddGoodsPublishPopApiClient.GoodsAddResult addResult =
|
||||
publishPopApiClient.addGoods(ctx.mallId(), ctx.accessToken(), command);
|
||||
@@ -378,6 +283,11 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
|
||||
throw new BusinessException("发布成功但拉取商品详情为空 goodsId=" + addResult.goodsId());
|
||||
}
|
||||
|
||||
ProductPO primary = productMapper.selectById(dto.getPrimaryProductId());
|
||||
if (primary == null || !Objects.equals(primary.getCompanyId(), companyId)) {
|
||||
throw new BusinessException("主内部商品不存在或不属于当前公司");
|
||||
}
|
||||
|
||||
// 主商品下补缺失 SKU(外商品已有 sku_code 会跳过,不挪绑)
|
||||
productAutoCreateService.ensureMissingSkus(companyId, primary.getId(), detailInfo);
|
||||
pddGoodsService.upsertFromGoodsDetail(
|
||||
@@ -408,37 +318,215 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PddGoodsPublishResultVO pushPlatformDraft(
|
||||
PddGoodsPublishDTO dto, Long existingCommitId, Long existingGoodsId) {
|
||||
if (dto == null || dto.getCatId() == null) {
|
||||
throw new BusinessException("叶子类目不能为空");
|
||||
}
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
ShopAuth ctx = requireShopAuth(dto.getPddShopId());
|
||||
try {
|
||||
PddGoodsPublishPopApiClient.GoodsAddCommand command =
|
||||
assembleAddCommand(dto, companyId, ctx, false);
|
||||
PddGoodsPublishPopApiClient.GoodsAddResult popResult;
|
||||
if (existingCommitId != null && existingGoodsId != null && existingGoodsId > 0) {
|
||||
popResult = publishPopApiClient.submitGoodsCommitSave(
|
||||
ctx.mallId(), ctx.accessToken(), command, existingCommitId, existingGoodsId);
|
||||
} else {
|
||||
popResult = publishPopApiClient.editGoodsCommit(ctx.mallId(), ctx.accessToken(), command);
|
||||
}
|
||||
PddGoodsPublishResultVO result = new PddGoodsPublishResultVO();
|
||||
result.setGoodsCommitId(popResult.goodsCommitId());
|
||||
Long goodsId = popResult.goodsId();
|
||||
result.setGoodsId(goodsId != null && goodsId > 0 ? goodsId : null);
|
||||
result.setMatchedSpuId(popResult.matchedSpuId());
|
||||
log.info("拼多多草稿推送成功 companyId={} shopId={} commitId={} goodsId={}",
|
||||
companyId, ctx.shop().getId(), popResult.goodsCommitId(), result.getGoodsId());
|
||||
return result;
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw wrapPop("推送到拼多多草稿箱失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装 POP 商品命令。strict=true 走发布强校验;false 仅要求能组包,缺图/SKU 交给平台报错。
|
||||
*/
|
||||
private PddGoodsPublishPopApiClient.GoodsAddCommand assembleAddCommand(
|
||||
PddGoodsPublishDTO dto, Long companyId, ShopAuth ctx, boolean strict) throws Exception {
|
||||
String outGoodsId = null;
|
||||
if (dto.getPrimaryProductId() != null) {
|
||||
ProductPO primary = productMapper.selectById(dto.getPrimaryProductId());
|
||||
if (primary == null || !Objects.equals(primary.getCompanyId(), companyId)) {
|
||||
if (strict) {
|
||||
throw new BusinessException("主内部商品不存在或不属于当前公司");
|
||||
}
|
||||
} else if (StringUtils.hasText(primary.getProductCode())) {
|
||||
outGoodsId = primary.getProductCode().trim();
|
||||
} else if (strict) {
|
||||
throw new BusinessException("主内部商品缺少商品编码,无法写入 out_goods_id");
|
||||
}
|
||||
} else if (strict) {
|
||||
throw new BusinessException("主内部商品不能为空");
|
||||
}
|
||||
|
||||
List<PddGoodsPublishSkuDTO> skuDtos = dto.getSkus() == null ? List.of() : dto.getSkus();
|
||||
if (strict && skuDtos.isEmpty()) {
|
||||
throw new BusinessException("SKU列表不能为空");
|
||||
}
|
||||
|
||||
List<Long> skuIds = skuDtos.stream()
|
||||
.map(PddGoodsPublishSkuDTO::getInternalSkuId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, ProductSkuPO> skuById = new HashMap<>();
|
||||
if (!skuIds.isEmpty()) {
|
||||
List<ProductSkuPO> skus = productSkuService.getByIds(skuIds);
|
||||
if (strict && (skus == null || skus.size() != skuIds.size())) {
|
||||
throw new BusinessException("部分内部SKU不存在");
|
||||
}
|
||||
if (skus != null) {
|
||||
for (ProductSkuPO sku : skus) {
|
||||
if (!Objects.equals(sku.getCompanyId(), companyId)) {
|
||||
if (strict) {
|
||||
throw new BusinessException("内部SKU不属于当前公司 skuId=" + sku.getId());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
skuById.put(sku.getId(), sku);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> carousel = resolveImages(companyId, ctx, dto.getCarouselImages(), strict);
|
||||
List<String> detail = resolveImages(companyId, ctx, dto.getDetailImages(), strict);
|
||||
String mainImage = null;
|
||||
if (StringUtils.hasText(dto.getImageUrl())) {
|
||||
mainImage = resolveOneImage(companyId, ctx, dto.getImageUrl().trim(), strict);
|
||||
}
|
||||
|
||||
List<PddGoodsPublishPopApiClient.SkuAddItem> skuAdds = new ArrayList<>();
|
||||
for (PddGoodsPublishSkuDTO skuDto : skuDtos) {
|
||||
ProductSkuPO internal = skuDto.getInternalSkuId() == null
|
||||
? null
|
||||
: skuById.get(skuDto.getInternalSkuId());
|
||||
String outSkuSn = resolveOutSkuSn(skuDto, internal, strict);
|
||||
String thumb = resolveOneImage(companyId, ctx, skuDto.getThumbImage(), strict);
|
||||
List<PddGoodsPublishPopApiClient.SkuPropertyItem> sps = new ArrayList<>();
|
||||
if (skuDto.getSkuProperties() != null) {
|
||||
for (PddGoodsPublishSkuPropertyDTO sp : skuDto.getSkuProperties()) {
|
||||
if (sp == null) {
|
||||
continue;
|
||||
}
|
||||
sps.add(new PddGoodsPublishPopApiClient.SkuPropertyItem(
|
||||
sp.getRefPid(), sp.getVid(), sp.getValue(), sp.getPunit()));
|
||||
}
|
||||
}
|
||||
String specIdList = skuDto.getSpecIdList();
|
||||
if (StringUtils.hasText(specIdList)) {
|
||||
specIdList = normalizeSpecIdList(specIdList);
|
||||
} else if (strict) {
|
||||
throw new BusinessException("规格列表不能为空");
|
||||
}
|
||||
skuAdds.add(new PddGoodsPublishPopApiClient.SkuAddItem(
|
||||
skuDto.getIsOnsale() == null ? 1 : skuDto.getIsOnsale(),
|
||||
999L,
|
||||
skuDto.getMultiPriceFen(),
|
||||
skuDto.getPriceFen(),
|
||||
skuDto.getQuantity(),
|
||||
skuDto.getWeight(),
|
||||
thumb,
|
||||
outSkuSn,
|
||||
specIdList,
|
||||
sps));
|
||||
}
|
||||
|
||||
List<PddGoodsPublishPopApiClient.GoodsPropertyItem> goodsProps = new ArrayList<>();
|
||||
if (dto.getGoodsProperties() != null) {
|
||||
for (PddGoodsPublishPropertyDTO p : dto.getGoodsProperties()) {
|
||||
if (p == null) {
|
||||
continue;
|
||||
}
|
||||
goodsProps.add(new PddGoodsPublishPopApiClient.GoodsPropertyItem(
|
||||
p.getRefPid(), p.getVid(), p.getValue(), p.getValueUnit(), p.getTemplatePid(),
|
||||
p.getParentSpecId(), p.getSpecId(), p.getImgUrl(), p.getNote(), p.getGroupId()));
|
||||
}
|
||||
}
|
||||
|
||||
String goodsName = dto.getGoodsName() == null ? null : dto.getGoodsName().trim();
|
||||
if (strict && !StringUtils.hasText(goodsName)) {
|
||||
throw new BusinessException("商品标题不能为空");
|
||||
}
|
||||
|
||||
return new PddGoodsPublishPopApiClient.GoodsAddCommand(
|
||||
goodsName,
|
||||
dto.getGoodsDesc(),
|
||||
dto.getCatId(),
|
||||
dto.getCostTemplateId(),
|
||||
0,
|
||||
1,
|
||||
dto.getMarketPriceFen(),
|
||||
dto.getShipmentLimitSecond(),
|
||||
dto.getIsFolt(),
|
||||
dto.getIsPreSale(),
|
||||
dto.getIsRefundable(),
|
||||
dto.getSecondHand(),
|
||||
dto.getTwoPiecesDiscount() == null ? 95 : dto.getTwoPiecesDiscount(),
|
||||
carousel,
|
||||
detail,
|
||||
outGoodsId,
|
||||
mainImage,
|
||||
goodsProps,
|
||||
skuAdds);
|
||||
}
|
||||
|
||||
/** 优先手填 outSkuSn;否则用内部 sku_code。 */
|
||||
private static String resolveOutSkuSn(PddGoodsPublishSkuDTO skuDto, ProductSkuPO internal) {
|
||||
private static String resolveOutSkuSn(PddGoodsPublishSkuDTO skuDto, ProductSkuPO internal, boolean strict) {
|
||||
if (StringUtils.hasText(skuDto.getOutSkuSn())) {
|
||||
return skuDto.getOutSkuSn().trim();
|
||||
}
|
||||
if (internal != null && StringUtils.hasText(internal.getSkuCode())) {
|
||||
return internal.getSkuCode().trim();
|
||||
}
|
||||
throw new BusinessException("SKU商家编码不能为空:请选择内部SKU或手填编码");
|
||||
if (strict) {
|
||||
throw new BusinessException("SKU商家编码不能为空:请选择内部SKU或手填编码");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<String> resolveImages(Long companyId, ShopAuth ctx, List<String> refs) throws Exception {
|
||||
private List<String> resolveImages(Long companyId, ShopAuth ctx, List<String> refs, boolean strict)
|
||||
throws Exception {
|
||||
if (refs == null || refs.isEmpty()) {
|
||||
throw new BusinessException("图片列表不能为空");
|
||||
if (strict) {
|
||||
throw new BusinessException("图片列表不能为空");
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
List<String> urls = new ArrayList<>();
|
||||
for (String ref : refs) {
|
||||
if (!StringUtils.hasText(ref)) {
|
||||
continue;
|
||||
}
|
||||
urls.add(resolveOneImage(companyId, ctx, ref.trim()));
|
||||
String url = resolveOneImage(companyId, ctx, ref.trim(), strict);
|
||||
if (StringUtils.hasText(url)) {
|
||||
urls.add(url);
|
||||
}
|
||||
}
|
||||
if (urls.isEmpty()) {
|
||||
if (urls.isEmpty() && strict) {
|
||||
throw new BusinessException("图片列表不能为空");
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
private String resolveOneImage(Long companyId, ShopAuth ctx, String ref) throws Exception {
|
||||
private String resolveOneImage(Long companyId, ShopAuth ctx, String ref, boolean strict) throws Exception {
|
||||
if (!StringUtils.hasText(ref)) {
|
||||
throw new BusinessException("图片引用不能为空");
|
||||
if (strict) {
|
||||
throw new BusinessException("图片引用不能为空");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
String s = ref.trim();
|
||||
if (looksLikeUrl(s)) {
|
||||
|
||||
+2
@@ -20,6 +20,8 @@ public final class PddPopApiTypes {
|
||||
public static final String GOODS_DETAIL_GET = "pdd.goods.detail.get";
|
||||
public static final String GOODS_LIST_GET = "pdd.goods.list.get";
|
||||
public static final String GOODS_ADD = "pdd.goods.add";
|
||||
public static final String GOODS_EDIT_GOODS_COMMIT = "pdd.goods.edit.goods.commit";
|
||||
public static final String GOODS_SUBMIT_GOODS_COMMIT = "pdd.goods.submit.goods.commit";
|
||||
public static final String GOODS_IMAGE_UPLOAD = "pdd.goods.image.upload";
|
||||
public static final String GOODS_AUTHORIZATION_CATS = "pdd.goods.authorization.cats";
|
||||
/** 平台全量类目树(无需 accessToken) */
|
||||
|
||||
+216
-1
@@ -1,6 +1,8 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.goods;
|
||||
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsAddRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsEditGoodsCommitRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsSubmitGoodsCommitRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsAuthorizationCatsRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsCatTemplateGetRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsImageUploadRequest;
|
||||
@@ -9,6 +11,8 @@ import com.pdd.pop.sdk.http.api.pop.request.PddGoodsSpecGetRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsSpecIdGetRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddOneExpressCostTemplateRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsAddResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsEditGoodsCommitResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsSubmitGoodsCommitResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsAuthorizationCatsResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsCatTemplateGetResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsImageUploadResponse;
|
||||
@@ -28,7 +32,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品发布域 POP:类目/运费模板/属性模板/规格/传图/新增。
|
||||
* 商品发布域 POP:类目/运费模板/属性模板/规格/传图/新增/平台草稿。
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -169,6 +173,46 @@ public class PddGoodsPublishPopApiClient {
|
||||
});
|
||||
}
|
||||
|
||||
/** 新增或编辑拼多多草稿箱(无 commitId)。 */
|
||||
public GoodsAddResult editGoodsCommit(Long mallId, String accessToken, GoodsAddCommand command)
|
||||
throws Exception {
|
||||
if (command == null) {
|
||||
throw new BusinessException("草稿参数不能为空");
|
||||
}
|
||||
return invokeSupport.invoke(PddPopApiTypes.GOODS_EDIT_GOODS_COMMIT, mallId, client -> {
|
||||
PddGoodsEditGoodsCommitRequest request = toEditCommitRequest(command);
|
||||
PddGoodsEditGoodsCommitResponse response = client.syncInvoke(request, accessToken);
|
||||
invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_EDIT_GOODS_COMMIT);
|
||||
var body = response.getGoodsUpdateResponse();
|
||||
if (body == null || body.getGoodsCommitId() == null) {
|
||||
throw new BusinessException("拼多多草稿未返回 goods_commit_id");
|
||||
}
|
||||
return new GoodsAddResult(body.getGoodsId(), body.getGoodsCommitId(), body.getMatchedSpuId());
|
||||
});
|
||||
}
|
||||
|
||||
/** 覆盖已有平台草稿并仅保存(operate_type=1,不提交上架)。 */
|
||||
public GoodsAddResult submitGoodsCommitSave(
|
||||
Long mallId, String accessToken, GoodsAddCommand command, Long goodsCommitId, Long goodsId)
|
||||
throws Exception {
|
||||
if (command == null) {
|
||||
throw new BusinessException("草稿参数不能为空");
|
||||
}
|
||||
if (goodsCommitId == null || goodsId == null || goodsId <= 0) {
|
||||
throw new BusinessException("覆盖平台草稿需要有效的 goods_commit_id 与 goods_id");
|
||||
}
|
||||
return invokeSupport.invoke(PddPopApiTypes.GOODS_SUBMIT_GOODS_COMMIT, mallId, client -> {
|
||||
PddGoodsSubmitGoodsCommitRequest request = toSubmitCommitRequest(command, goodsCommitId, goodsId);
|
||||
PddGoodsSubmitGoodsCommitResponse response = client.syncInvoke(request, accessToken);
|
||||
invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_SUBMIT_GOODS_COMMIT);
|
||||
var body = response.getGoodsUpdateResponse();
|
||||
if (body == null || body.getGoodsCommitId() == null) {
|
||||
throw new BusinessException("拼多多草稿未返回 goods_commit_id");
|
||||
}
|
||||
return new GoodsAddResult(body.getGoodsId(), body.getGoodsCommitId(), body.getMatchedSpuId());
|
||||
});
|
||||
}
|
||||
|
||||
private PddGoodsAddRequest toAddRequest(GoodsAddCommand cmd) {
|
||||
PddGoodsAddRequest request = new PddGoodsAddRequest();
|
||||
request.setGoodsName(cmd.goodsName());
|
||||
@@ -237,6 +281,177 @@ public class PddGoodsPublishPopApiClient {
|
||||
return request;
|
||||
}
|
||||
|
||||
private PddGoodsEditGoodsCommitRequest toEditCommitRequest(GoodsAddCommand cmd) {
|
||||
PddGoodsEditGoodsCommitRequest request = new PddGoodsEditGoodsCommitRequest();
|
||||
request.setGoodsName(cmd.goodsName());
|
||||
request.setGoodsDesc(cmd.goodsDesc());
|
||||
request.setCatId(cmd.catId());
|
||||
request.setCostTemplateId(cmd.costTemplateId());
|
||||
request.setCountryId(cmd.countryId() == null ? 0 : cmd.countryId());
|
||||
request.setGoodsType(cmd.goodsType() == null ? 1 : cmd.goodsType());
|
||||
request.setMarketPrice(cmd.marketPrice());
|
||||
request.setShipmentLimitSecond(cmd.shipmentLimitSecond());
|
||||
request.setIsFolt(cmd.isFolt());
|
||||
request.setIsPreSale(cmd.isPreSale());
|
||||
request.setIsRefundable(cmd.isRefundable());
|
||||
request.setSecondHand(cmd.secondHand());
|
||||
request.setCarouselGallery(cmd.carouselGallery());
|
||||
request.setDetailGallery(cmd.detailGallery());
|
||||
request.setOutGoodsId(cmd.outGoodsId());
|
||||
request.setImageUrl(cmd.imageUrl());
|
||||
if (cmd.twoPiecesDiscount() != null) {
|
||||
request.setTwoPiecesDiscount(cmd.twoPiecesDiscount());
|
||||
}
|
||||
if (cmd.goodsProperties() != null && !cmd.goodsProperties().isEmpty()) {
|
||||
List<PddGoodsEditGoodsCommitRequest.GoodsPropertiesItem> props = new ArrayList<>();
|
||||
for (GoodsPropertyItem p : cmd.goodsProperties()) {
|
||||
PddGoodsEditGoodsCommitRequest.GoodsPropertiesItem item =
|
||||
new PddGoodsEditGoodsCommitRequest.GoodsPropertiesItem();
|
||||
item.setRefPid(p.refPid());
|
||||
item.setVid(p.vid());
|
||||
item.setValue(p.value());
|
||||
item.setValueUnit(p.valueUnit());
|
||||
item.setTemplatePid(p.templatePid());
|
||||
item.setParentSpecId(p.parentSpecId());
|
||||
item.setSpecId(p.specId());
|
||||
item.setImgUrl(p.imgUrl());
|
||||
item.setNote(p.note());
|
||||
item.setGroupId(p.groupId());
|
||||
props.add(item);
|
||||
}
|
||||
request.setGoodsProperties(props);
|
||||
}
|
||||
if (cmd.skuList() != null && !cmd.skuList().isEmpty()) {
|
||||
List<PddGoodsEditGoodsCommitRequest.SkuListItem> skuList = new ArrayList<>();
|
||||
for (SkuAddItem sku : cmd.skuList()) {
|
||||
PddGoodsEditGoodsCommitRequest.SkuListItem item =
|
||||
new PddGoodsEditGoodsCommitRequest.SkuListItem();
|
||||
item.setIsOnsale(sku.isOnsale() == null ? 1 : sku.isOnsale());
|
||||
item.setLimitQuantity(sku.limitQuantity() == null ? 999L : sku.limitQuantity());
|
||||
item.setMultiPrice(sku.multiPrice());
|
||||
item.setPrice(sku.price());
|
||||
item.setQuantity(sku.quantity());
|
||||
item.setWeight(sku.weight());
|
||||
item.setThumbUrl(sku.thumbUrl());
|
||||
item.setOutSkuSn(sku.outSkuSn());
|
||||
item.setSpecIdList(sku.specIdList());
|
||||
if (sku.skuProperties() != null && !sku.skuProperties().isEmpty()) {
|
||||
List<PddGoodsEditGoodsCommitRequest.SkuListItemSkuPropertiesItem> sps = new ArrayList<>();
|
||||
for (SkuPropertyItem sp : sku.skuProperties()) {
|
||||
PddGoodsEditGoodsCommitRequest.SkuListItemSkuPropertiesItem spi =
|
||||
new PddGoodsEditGoodsCommitRequest.SkuListItemSkuPropertiesItem();
|
||||
spi.setRefPid(sp.refPid());
|
||||
spi.setVid(sp.vid());
|
||||
spi.setValue(sp.value());
|
||||
spi.setPunit(sp.punit());
|
||||
sps.add(spi);
|
||||
}
|
||||
item.setSkuProperties(sps);
|
||||
}
|
||||
skuList.add(item);
|
||||
}
|
||||
request.setSkuList(skuList);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
private PddGoodsSubmitGoodsCommitRequest toSubmitCommitRequest(
|
||||
GoodsAddCommand cmd, Long goodsCommitId, Long goodsId) {
|
||||
PddGoodsSubmitGoodsCommitRequest request = new PddGoodsSubmitGoodsCommitRequest();
|
||||
request.setGoodsCommitId(goodsCommitId);
|
||||
request.setGoodsId(goodsId);
|
||||
request.setOperateType(1);
|
||||
request.setGoodsName(cmd.goodsName());
|
||||
request.setGoodsDesc(cmd.goodsDesc());
|
||||
request.setCatId(cmd.catId());
|
||||
request.setCostTemplateId(cmd.costTemplateId());
|
||||
request.setCountryId(cmd.countryId() == null ? 0 : cmd.countryId());
|
||||
request.setGoodsType(cmd.goodsType() == null ? 1 : cmd.goodsType());
|
||||
request.setMarketPrice(cmd.marketPrice());
|
||||
request.setShipmentLimitSecond(cmd.shipmentLimitSecond());
|
||||
request.setIsFolt(cmd.isFolt());
|
||||
request.setIsPreSale(cmd.isPreSale());
|
||||
request.setIsRefundable(cmd.isRefundable());
|
||||
request.setSecondHand(cmd.secondHand());
|
||||
request.setCarouselGallery(cmd.carouselGallery());
|
||||
request.setDetailGallery(cmd.detailGallery());
|
||||
request.setOutGoodsId(cmd.outGoodsId());
|
||||
request.setImageUrl(cmd.imageUrl());
|
||||
if (cmd.twoPiecesDiscount() != null) {
|
||||
request.setTwoPiecesDiscount(cmd.twoPiecesDiscount());
|
||||
}
|
||||
if (cmd.goodsProperties() != null && !cmd.goodsProperties().isEmpty()) {
|
||||
List<PddGoodsSubmitGoodsCommitRequest.GoodsPropertiesItem> props = new ArrayList<>();
|
||||
for (GoodsPropertyItem p : cmd.goodsProperties()) {
|
||||
PddGoodsSubmitGoodsCommitRequest.GoodsPropertiesItem item =
|
||||
new PddGoodsSubmitGoodsCommitRequest.GoodsPropertiesItem();
|
||||
item.setRefPid(p.refPid());
|
||||
item.setVid(p.vid());
|
||||
item.setValue(p.value());
|
||||
item.setValueUnit(p.valueUnit());
|
||||
item.setTemplatePid(p.templatePid());
|
||||
item.setParentSpecId(p.parentSpecId());
|
||||
item.setSpecId(p.specId());
|
||||
item.setImgUrl(p.imgUrl());
|
||||
item.setNote(p.note());
|
||||
item.setGroupId(p.groupId());
|
||||
props.add(item);
|
||||
}
|
||||
request.setGoodsProperties(props);
|
||||
}
|
||||
if (cmd.skuList() != null && !cmd.skuList().isEmpty()) {
|
||||
List<PddGoodsSubmitGoodsCommitRequest.SkuListItem> skuList = new ArrayList<>();
|
||||
for (SkuAddItem sku : cmd.skuList()) {
|
||||
PddGoodsSubmitGoodsCommitRequest.SkuListItem item =
|
||||
new PddGoodsSubmitGoodsCommitRequest.SkuListItem();
|
||||
item.setIsOnsale(sku.isOnsale() == null ? 1 : sku.isOnsale());
|
||||
item.setLimitQuantity(sku.limitQuantity() == null ? 999L : sku.limitQuantity());
|
||||
item.setMultiPrice(sku.multiPrice());
|
||||
item.setPrice(sku.price());
|
||||
item.setQuantity(sku.quantity());
|
||||
item.setWeight(sku.weight());
|
||||
item.setThumbUrl(sku.thumbUrl());
|
||||
item.setOutSkuSn(sku.outSkuSn());
|
||||
item.setSpecIdList(parseSpecIdLongs(sku.specIdList()));
|
||||
if (sku.skuProperties() != null && !sku.skuProperties().isEmpty()) {
|
||||
List<PddGoodsSubmitGoodsCommitRequest.SkuListItemSkuPropertiesItem> sps = new ArrayList<>();
|
||||
for (SkuPropertyItem sp : sku.skuProperties()) {
|
||||
PddGoodsSubmitGoodsCommitRequest.SkuListItemSkuPropertiesItem spi =
|
||||
new PddGoodsSubmitGoodsCommitRequest.SkuListItemSkuPropertiesItem();
|
||||
spi.setRefPid(sp.refPid());
|
||||
spi.setVid(sp.vid());
|
||||
spi.setValue(sp.value());
|
||||
spi.setPunit(sp.punit());
|
||||
sps.add(spi);
|
||||
}
|
||||
item.setSkuProperties(sps);
|
||||
}
|
||||
skuList.add(item);
|
||||
}
|
||||
request.setSkuList(skuList);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
private static List<Long> parseSpecIdLongs(String specIdList) {
|
||||
if (!StringUtils.hasText(specIdList)) {
|
||||
return null;
|
||||
}
|
||||
String s = specIdList.trim();
|
||||
if (s.startsWith("[")) {
|
||||
s = s.substring(1, s.endsWith("]") ? s.length() - 1 : s.length());
|
||||
}
|
||||
List<Long> ids = new ArrayList<>();
|
||||
for (String part : s.split(",")) {
|
||||
String p = part.trim();
|
||||
if (p.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
ids.add(Long.parseLong(p));
|
||||
}
|
||||
return ids.isEmpty() ? null : ids;
|
||||
}
|
||||
|
||||
private List<AuthCatItem> mapAuthCats(PddGoodsAuthorizationCatsResponse response) {
|
||||
if (response == null || response.getGoodsAuthCatsGetResponse() == null
|
||||
|| response.getGoodsAuthCatsGetResponse().getGoodsCatsList() == null) {
|
||||
|
||||
+1
-1
@@ -568,7 +568,7 @@ public class FeedbackServiceImpl implements FeedbackService {
|
||||
if (CollectionUtils.isEmpty(fileIds)) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<SysFilePO> files = sysFileMapper.selectBatchIds(fileIds);
|
||||
List<SysFilePO> files = sysFileMapper.selectByIds(fileIds);
|
||||
Map<Long, String> map = new HashMap<>();
|
||||
for (SysFilePO file : files) {
|
||||
if (file == null || file.getId() == null || file.getDeleteTime() != null) {
|
||||
|
||||
@@ -166,6 +166,13 @@ export async function deletePddPublishDeskDraftApi(id: number) {
|
||||
return requestClient.delete(`/channel/pdd/goods/publish-desk/drafts/${id}`);
|
||||
}
|
||||
|
||||
/** 将系统草稿推送到拼多多草稿箱 */
|
||||
export async function pushPddPublishDeskDraftApi(id: number) {
|
||||
return requestClient.post<PddPublishDeskVO.Draft>(
|
||||
`/channel/pdd/goods/publish-desk/drafts/${id}/push-platform`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function clonePddPublishDeskDraftApi(
|
||||
data: PddPublishDeskDTO.Clone,
|
||||
) {
|
||||
|
||||
@@ -49,6 +49,9 @@ export namespace PddPublishDeskVO {
|
||||
payloadJson?: string;
|
||||
sourceDraftId?: number;
|
||||
lastError?: string;
|
||||
pddGoodsCommitId?: number;
|
||||
pddGoodsId?: number;
|
||||
pddDraftPushedAt?: string;
|
||||
createdBy?: number;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
|
||||
@@ -23,7 +23,7 @@ withDefaults(
|
||||
resizable?: boolean;
|
||||
splitHandle?: boolean;
|
||||
splitLine?: boolean;
|
||||
/** 店铺待发草稿数 */
|
||||
/** 店铺系统草稿数 */
|
||||
draftCountByShopId?: Record<number, number>;
|
||||
showUnassignedFilter?: boolean;
|
||||
unassignedCount?: number;
|
||||
|
||||
+85
-15
@@ -60,6 +60,7 @@ import {
|
||||
listPddPublishLogisticsApi,
|
||||
listPddPublishParentSpecsApi,
|
||||
publishPddGoodsApi,
|
||||
pushPddPublishDeskDraftApi,
|
||||
updatePddPublishDeskDraftApi,
|
||||
} from '#/api/channel/pdd/goods';
|
||||
import {
|
||||
@@ -113,6 +114,7 @@ const hasDraft = defineModel<boolean>('hasDraft', { default: false });
|
||||
/** 点击遮罩时的去向询问 */
|
||||
const dismissChoiceVisible = ref(false);
|
||||
const draftSaving = ref(false);
|
||||
const platformPushing = ref(false);
|
||||
const boundDraftId = ref<number | null>(null);
|
||||
|
||||
/** 外层 Modal / 页面壳通过 open 控制;编辑器本身不持有 vben Modal */
|
||||
@@ -2686,15 +2688,26 @@ async function hydrateFromDraft(id: number) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 保存工作台草稿;markReady=true 时写入 publishPayload 供批量发布 */
|
||||
async function saveDeskDraft(markReady: boolean) {
|
||||
/** 保存系统草稿;markReady=true 时写入 publishPayload 供批量发布 */
|
||||
async function saveDeskDraft(
|
||||
markReady: boolean,
|
||||
extras?: { includePublishPayload?: boolean; silentSuccess?: boolean },
|
||||
): Promise<{ id: number; hasPayload: boolean } | null> {
|
||||
if (!form.pddShopId) {
|
||||
message.warning('请先选择渠道店铺');
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
const title = form.goodsName.trim() || '未命名草稿';
|
||||
const includePayload = markReady || extras?.includePublishPayload === true;
|
||||
draftSaving.value = true;
|
||||
const hide = message.loading(markReady ? '生成可发布数据…' : '保存草稿…', 0);
|
||||
const hide = message.loading(
|
||||
markReady
|
||||
? '生成可发布数据…'
|
||||
: includePayload
|
||||
? '保存系统草稿…'
|
||||
: '保存系统草稿…',
|
||||
0,
|
||||
);
|
||||
try {
|
||||
// 普通保存也上传图片,否则下次打开无法回填(未上传的合并一次签名)
|
||||
const pendingThumbs = skuRows.value
|
||||
@@ -2722,19 +2735,26 @@ async function saveDeskDraft(markReady: boolean) {
|
||||
});
|
||||
|
||||
let publishPayload: PddGoodsPublishDTO.Publish | undefined;
|
||||
if (markReady) {
|
||||
if (!validateForm()) {
|
||||
return;
|
||||
if (includePayload) {
|
||||
if (markReady && !validateForm()) {
|
||||
return null;
|
||||
}
|
||||
const thumbFileIdBySkuKey = new Map<number, number>();
|
||||
for (const [k, v] of thumbBySkuKey) {
|
||||
thumbFileIdBySkuKey.set(k, v.fileId);
|
||||
}
|
||||
publishPayload = await buildPublishPayload(
|
||||
carouselFiles.map((f) => f.fileId),
|
||||
detailFiles.map((f) => f.fileId),
|
||||
thumbFileIdBySkuKey,
|
||||
);
|
||||
try {
|
||||
publishPayload = await buildPublishPayload(
|
||||
carouselFiles.map((f) => f.fileId),
|
||||
detailFiles.map((f) => f.fileId),
|
||||
thumbFileIdBySkuKey,
|
||||
);
|
||||
} catch (e: any) {
|
||||
if (markReady) {
|
||||
throw e;
|
||||
}
|
||||
// 推送场景:先落系统草稿,调用方再提示无法推送
|
||||
}
|
||||
}
|
||||
|
||||
const payloadJson = JSON.stringify({
|
||||
@@ -2801,15 +2821,58 @@ async function saveDeskDraft(markReady: boolean) {
|
||||
: await createPddPublishDeskDraftApi(body);
|
||||
boundDraftId.value = saved.id;
|
||||
emit('draft-saved', saved.id);
|
||||
message.success(markReady ? '已保存为可发布草稿' : '草稿已保存');
|
||||
if (!extras?.silentSuccess) {
|
||||
message.success(markReady ? '已保存为可发布草稿' : '系统草稿已保存');
|
||||
}
|
||||
return { id: saved.id, hasPayload: !!publishPayload };
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '保存草稿失败');
|
||||
message.error(e?.message || '保存系统草稿失败');
|
||||
return null;
|
||||
} finally {
|
||||
hide();
|
||||
draftSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 先落系统草稿(尽量带 publishPayload),再推送到拼多多草稿箱 */
|
||||
async function pushToPlatformDraft() {
|
||||
if (!form.pddShopId) {
|
||||
message.warning('请先选择渠道店铺');
|
||||
return;
|
||||
}
|
||||
if (!form.catId) {
|
||||
message.warning('请先选择叶子类目');
|
||||
return;
|
||||
}
|
||||
platformPushing.value = true;
|
||||
try {
|
||||
const saved = await saveDeskDraft(false, {
|
||||
includePublishPayload: true,
|
||||
silentSuccess: true,
|
||||
});
|
||||
if (!saved) return;
|
||||
if (!saved.hasPayload) {
|
||||
message.error('未能生成可推送数据,请补全规格、价格与图片后再试');
|
||||
return;
|
||||
}
|
||||
const hide = message.loading('推送到拼多多草稿箱…', 0);
|
||||
try {
|
||||
const vo = await pushPddPublishDeskDraftApi(saved.id);
|
||||
message.success(
|
||||
vo.pddGoodsCommitId
|
||||
? `已推送到拼多多草稿箱(ID ${vo.pddGoodsCommitId})`
|
||||
: '已推送到拼多多草稿箱',
|
||||
);
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '推送到拼多多草稿箱失败');
|
||||
} finally {
|
||||
platformPushing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!validateForm()) return;
|
||||
submitting.value = true;
|
||||
@@ -3718,7 +3781,7 @@ onBeforeUnmount(() => {
|
||||
{{ variant === 'page' ? '返回' : '取消' }}
|
||||
</Button>
|
||||
<Button :loading="draftSaving" @click="saveDeskDraft(false)">
|
||||
保存草稿
|
||||
保存系统草稿
|
||||
</Button>
|
||||
<Button
|
||||
type="default"
|
||||
@@ -3728,6 +3791,13 @@ onBeforeUnmount(() => {
|
||||
>
|
||||
保存并标记可发布
|
||||
</Button>
|
||||
<Button
|
||||
:loading="platformPushing || draftSaving"
|
||||
:disabled="catAuthAuthorized === false || catAuthChecking"
|
||||
@click="pushToPlatformDraft"
|
||||
>
|
||||
推送到拼多多草稿箱
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:loading="submitting"
|
||||
|
||||
@@ -34,7 +34,7 @@ function goBack() {
|
||||
<template #title>
|
||||
<div class="w-full space-y-3">
|
||||
<div class="mb-0 flex items-baseline text-lg font-semibold">
|
||||
编辑发布草稿
|
||||
编辑系统草稿
|
||||
<span
|
||||
v-if="draftId"
|
||||
class="text-muted-foreground ml-2 text-sm font-normal"
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Tooltip,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
@@ -27,6 +28,7 @@ import {
|
||||
deletePddPublishDeskDraftApi,
|
||||
getPddPublishDeskJobApi,
|
||||
listPddPublishDeskDraftsApi,
|
||||
pushPddPublishDeskDraftApi,
|
||||
retryPddPublishDeskJobFailedApi,
|
||||
} from '#/api/channel/pdd/goods';
|
||||
import { getPddShopPageApi } from '#/api/channel/pdd/shop';
|
||||
@@ -58,6 +60,7 @@ const cloneSubmitting = ref(false);
|
||||
const jobOpen = ref(false);
|
||||
const jobLoading = ref(false);
|
||||
const currentJob = ref<PddPublishDeskVO.Job | null>(null);
|
||||
const pushingDraftId = ref<number | null>(null);
|
||||
let jobPollTimer: ReturnType<typeof setInterval> | undefined;
|
||||
|
||||
const statusLabel: Record<string, { text: string; color: string }> = {
|
||||
@@ -91,7 +94,7 @@ const draftCountRecord = computed(() => {
|
||||
|
||||
const summaryText = computed(
|
||||
() =>
|
||||
`${shopWithDraft.value || 0} 店 · ${totalPending.value || 0} 待发`,
|
||||
`${shopWithDraft.value || 0} 店 · ${totalPending.value || 0} 条系统草稿`,
|
||||
);
|
||||
|
||||
const columns = [
|
||||
@@ -100,8 +103,9 @@ const columns = [
|
||||
{ title: '店铺', dataIndex: 'shopName', key: 'shopName', width: 140 },
|
||||
{ title: 'SKU数', dataIndex: 'skuCount', key: 'skuCount', width: 88 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '拼多多草稿', key: 'platformDraft', width: 148 },
|
||||
{ title: '更新时间', dataIndex: 'updateTime', key: 'updateTime', width: 170 },
|
||||
{ title: '操作', key: 'actions', width: 200 },
|
||||
{ title: '操作', key: 'actions', width: 280 },
|
||||
];
|
||||
|
||||
/** 列表悬停:从草稿 payloadJson.editorState.skuRows 解析 */
|
||||
@@ -202,6 +206,60 @@ function formatSkuPrice(price?: number) {
|
||||
return `¥${price.toFixed(2)}`;
|
||||
}
|
||||
|
||||
/** Table bodyCell 的 record 偏宽,只读推送判断所需字段 */
|
||||
function draftHasPublishPayload(draft: { payloadJson?: string }): boolean {
|
||||
if (!draft.payloadJson) return false;
|
||||
try {
|
||||
const root = JSON.parse(draft.payloadJson) as { publishPayload?: unknown };
|
||||
return (
|
||||
root.publishPayload != null && typeof root.publishPayload === 'object'
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function pushDisabledReason(draft: {
|
||||
pddShopId?: number;
|
||||
payloadJson?: string;
|
||||
}): string {
|
||||
if (!draft.pddShopId) return '请先分配渠道店铺';
|
||||
if (!draftHasPublishPayload(draft)) {
|
||||
return '请先在编辑页生成可推送数据';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
async function pushPlatform(draft: {
|
||||
id?: number;
|
||||
pddShopId?: number;
|
||||
payloadJson?: string;
|
||||
}) {
|
||||
if (draft.id == null) return;
|
||||
const reason = pushDisabledReason(draft);
|
||||
if (reason) {
|
||||
message.warning(reason);
|
||||
return;
|
||||
}
|
||||
pushingDraftId.value = draft.id;
|
||||
const hide = message.loading('推送到拼多多草稿箱…', 0);
|
||||
try {
|
||||
const vo = await pushPddPublishDeskDraftApi(draft.id);
|
||||
message.success(
|
||||
vo.pddGoodsCommitId
|
||||
? `已推送到拼多多草稿箱(ID ${vo.pddGoodsCommitId})`
|
||||
: '已推送到拼多多草稿箱',
|
||||
);
|
||||
await loadDrafts();
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '推送失败');
|
||||
await loadDrafts();
|
||||
} finally {
|
||||
hide();
|
||||
pushingDraftId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadShops() {
|
||||
try {
|
||||
const data = await getPddShopPageApi({
|
||||
@@ -263,7 +321,7 @@ async function createDraft() {
|
||||
status: 'EDITING',
|
||||
skuCount: 0,
|
||||
});
|
||||
message.success('已创建草稿');
|
||||
message.success('已创建系统草稿');
|
||||
await router.push(`/pdd/goods/publish/edit/${draft.id}`);
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '创建失败');
|
||||
@@ -442,7 +500,7 @@ onUnmounted(() => stopJobPoll());
|
||||
>
|
||||
<template #title>
|
||||
<div class="flex min-w-0 items-center gap-3">
|
||||
<span class="text-base font-semibold">发布工作台</span>
|
||||
<span class="text-base font-semibold">发布工作台(系统草稿)</span>
|
||||
<span class="text-muted-foreground truncate text-sm font-normal">
|
||||
{{ summaryText }}
|
||||
</span>
|
||||
@@ -451,7 +509,7 @@ onUnmounted(() => stopJobPoll());
|
||||
<template #extra>
|
||||
<Space wrap class="py-1">
|
||||
<PermissionGate code="channel:pdd:goods:create">
|
||||
<Button type="primary" @click="createDraft">新建草稿</Button>
|
||||
<Button type="primary" @click="createDraft">新建系统草稿</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="channel:pdd:goods:create">
|
||||
<Button
|
||||
@@ -492,7 +550,7 @@ onUnmounted(() => stopJobPoll());
|
||||
selectedRowKeys,
|
||||
onChange: onDraftSelectionChange,
|
||||
}"
|
||||
:locale="{ emptyText: '暂无待发草稿' }"
|
||||
:locale="{ emptyText: '暂无系统草稿' }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'skuCount'">
|
||||
@@ -530,6 +588,18 @@ onUnmounted(() => stopJobPoll());
|
||||
</Popover>
|
||||
<span v-else>{{ record.skuCount ?? 0 }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'platformDraft'">
|
||||
<div v-if="record.pddGoodsCommitId">
|
||||
<Tag color="green">已推送</Tag>
|
||||
<div
|
||||
class="text-muted-foreground mt-1 max-w-[130px] truncate text-xs"
|
||||
:title="String(record.pddGoodsCommitId)"
|
||||
>
|
||||
{{ record.pddGoodsCommitId }}
|
||||
</div>
|
||||
</div>
|
||||
<span v-else class="text-muted-foreground text-xs">未推送</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<Tag :color="statusLabel[record.status]?.color || 'default'">
|
||||
{{ statusLabel[record.status]?.text || record.status }}
|
||||
@@ -547,6 +617,19 @@ onUnmounted(() => stopJobPoll());
|
||||
<Button type="link" size="small" @click="openEdit(record.id)">
|
||||
编辑
|
||||
</Button>
|
||||
<Tooltip :title="pushDisabledReason(record) || '推送到拼多多草稿箱'">
|
||||
<span>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
:disabled="!!pushDisabledReason(record)"
|
||||
:loading="pushingDraftId === record.id"
|
||||
@click="pushPlatform(record)"
|
||||
>
|
||||
推送平台
|
||||
</Button>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
@@ -569,7 +652,7 @@ onUnmounted(() => stopJobPoll());
|
||||
<Empty
|
||||
v-if="!loading && drafts.length === 0"
|
||||
class="mt-8"
|
||||
description="暂无草稿,点击「新建草稿」开始"
|
||||
description="暂无系统草稿,点击「新建系统草稿」开始"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user