feat: 接入拼多多商品审核驳回消息并回写系统草稿 commitId

This commit is contained in:
2026-09-18 13:41:38 +08:00
parent 2ff2407e05
commit 17397f5347
37 changed files with 4055 additions and 17 deletions
@@ -19,6 +19,11 @@ public class PddGoodsPublishDTO {
@NotNull(message = "渠道店铺ID不能为空")
private Long pddShopId;
/**
* 可选:关联的系统草稿 ID。发布成功后回写 goods_commit_id / goods_id,供审核驳回消息匹配。
*/
private Long systemDraftId;
/** 渠道商品绑定的主内部商品 */
@NotNull(message = "主内部商品不能为空")
private Long primaryProductId;
@@ -19,7 +19,7 @@ public interface PddGoodsPublishDraftMapper extends BaseMapper<PddGoodsPublishDr
SELECT pdd_shop_id AS pddShopId, COUNT(*) AS draftCount
FROM channel_pdd_goods_publish_draft
WHERE company_id = #{companyId}
AND status IN ('EDITING', 'NEED_CHECK', 'READY', 'FAILED', 'PUBLISHING')
AND status IN ('EDITING', 'NEED_CHECK', 'READY', 'FAILED', 'PUBLISHING', 'REJECTED')
GROUP BY pdd_shop_id
""")
List<PddPublishDeskShopCountVO> countByShop(@Param("companyId") Long companyId);
@@ -21,6 +21,8 @@ public class PddGoodsPublishDraftPO {
public static final String STATUS_PUBLISHING = "PUBLISHING";
public static final String STATUS_FAILED = "FAILED";
public static final String STATUS_PUBLISHED = "PUBLISHED";
/** 拼多多审核驳回(仅系统草稿有 commit/goods 关联时写入) */
public static final String STATUS_REJECTED = "REJECTED";
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@@ -63,6 +65,14 @@ public class PddGoodsPublishDraftPO {
@TableField("pdd_draft_pushed_at")
private LocalDateTime pddDraftPushedAt;
/** 拼多多审核驳回原因 */
@TableField("reject_comment")
private String rejectComment;
/** 拼多多审核驳回时间 */
@TableField("reject_time")
private LocalDateTime rejectTime;
@TableField("created_by")
private Long createdBy;
@@ -23,6 +23,8 @@ public class PddGoodsPublishDraftVO {
private Long pddGoodsCommitId;
private Long pddGoodsId;
private LocalDateTime pddDraftPushedAt;
private String rejectComment;
private LocalDateTime rejectTime;
private Long createdBy;
private LocalDateTime createTime;
private LocalDateTime updateTime;
@@ -10,6 +10,7 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.PddPublishDeskDraftPageVO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.PddPublishDeskShopCountVO;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -41,4 +42,17 @@ public interface PddGoodsPublishDeskService {
/** 将系统草稿推送到拼多多草稿箱并回写 commitId */
PddGoodsPublishDraftVO pushPlatformDraft(Long id);
/**
* 审核驳回消息回写:按 commitId / goodsId 匹配系统草稿;无匹配则忽略(纯平台草稿)。
*
* @return 是否更新到系统草稿
*/
boolean applyGoodsCheckReject(
Long companyId,
Long pddShopId,
Long goodsCommitId,
Long goodsId,
String rejectComment,
LocalDateTime rejectTime);
}
@@ -1,6 +1,7 @@
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.JsonNode;
@@ -57,7 +58,8 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic
PddGoodsPublishDraftPO.STATUS_NEED_CHECK,
PddGoodsPublishDraftPO.STATUS_READY,
PddGoodsPublishDraftPO.STATUS_FAILED,
PddGoodsPublishDraftPO.STATUS_PUBLISHING
PddGoodsPublishDraftPO.STATUS_PUBLISHING,
PddGoodsPublishDraftPO.STATUS_REJECTED
);
private final PddGoodsPublishDraftMapper draftMapper;
@@ -179,8 +181,20 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic
}
po.setPayloadJson(dto.getPayloadJson());
po.setLastError(null);
draftMapper.updateById(po);
return toDraftVo(po, loadShopNamesForOne(po));
// 用户再次编辑时清掉驳回信息(null 需 UpdateWrapper)
draftMapper.update(null, new LambdaUpdateWrapper<PddGoodsPublishDraftPO>()
.eq(PddGoodsPublishDraftPO::getId, po.getId())
.set(PddGoodsPublishDraftPO::getPddShopId, po.getPddShopId())
.set(PddGoodsPublishDraftPO::getTitle, po.getTitle())
.set(PddGoodsPublishDraftPO::getCatId, po.getCatId())
.set(PddGoodsPublishDraftPO::getSkuCount, po.getSkuCount())
.set(PddGoodsPublishDraftPO::getStatus, po.getStatus())
.set(PddGoodsPublishDraftPO::getPayloadJson, po.getPayloadJson())
.set(PddGoodsPublishDraftPO::getLastError, null)
.set(PddGoodsPublishDraftPO::getRejectComment, null)
.set(PddGoodsPublishDraftPO::getRejectTime, null));
PddGoodsPublishDraftPO refreshed = draftMapper.selectById(po.getId());
return toDraftVo(refreshed != null ? refreshed : po, loadShopNamesForOne(po));
}
@Override
@@ -222,7 +236,8 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic
: PddGoodsPublishDraftPO.STATUS_EDITING)
: PddGoodsPublishDraftPO.STATUS_NEED_CHECK;
if (PddGoodsPublishDraftPO.STATUS_PUBLISHED.equals(status)
|| PddGoodsPublishDraftPO.STATUS_PUBLISHING.equals(status)) {
|| PddGoodsPublishDraftPO.STATUS_PUBLISHING.equals(status)
|| PddGoodsPublishDraftPO.STATUS_REJECTED.equals(status)) {
status = PddGoodsPublishDraftPO.STATUS_EDITING;
}
po.setStatus(status);
@@ -371,6 +386,51 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic
}
}
@Override
@Transactional
public boolean applyGoodsCheckReject(
Long companyId,
Long pddShopId,
Long goodsCommitId,
Long goodsId,
String rejectComment,
LocalDateTime rejectTime) {
if (companyId == null || pddShopId == null) {
return false;
}
PddGoodsPublishDraftPO draft = null;
if (goodsCommitId != null) {
draft = draftMapper.selectOne(new LambdaQueryWrapper<PddGoodsPublishDraftPO>()
.eq(PddGoodsPublishDraftPO::getCompanyId, companyId)
.eq(PddGoodsPublishDraftPO::getPddShopId, pddShopId)
.eq(PddGoodsPublishDraftPO::getPddGoodsCommitId, goodsCommitId)
.orderByDesc(PddGoodsPublishDraftPO::getUpdateTime)
.last("LIMIT 1"));
}
if (draft == null && goodsId != null) {
draft = draftMapper.selectOne(new LambdaQueryWrapper<PddGoodsPublishDraftPO>()
.eq(PddGoodsPublishDraftPO::getCompanyId, companyId)
.eq(PddGoodsPublishDraftPO::getPddShopId, pddShopId)
.eq(PddGoodsPublishDraftPO::getPddGoodsId, goodsId)
.orderByDesc(PddGoodsPublishDraftPO::getUpdateTime)
.last("LIMIT 1"));
}
if (draft == null) {
return false;
}
String comment = rejectComment;
if (StringUtils.hasText(comment) && comment.length() > 1000) {
comment = comment.substring(0, 1000);
}
draftMapper.update(null, new LambdaUpdateWrapper<PddGoodsPublishDraftPO>()
.eq(PddGoodsPublishDraftPO::getId, draft.getId())
.set(PddGoodsPublishDraftPO::getStatus, PddGoodsPublishDraftPO.STATUS_REJECTED)
.set(PddGoodsPublishDraftPO::getRejectComment, comment)
.set(PddGoodsPublishDraftPO::getRejectTime, rejectTime)
.set(PddGoodsPublishDraftPO::getLastError, comment));
return true;
}
private String trimError(String msg) {
if (!StringUtils.hasText(msg)) {
return "推送到拼多多草稿箱失败";
@@ -488,6 +548,8 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic
vo.setPddGoodsCommitId(po.getPddGoodsCommitId());
vo.setPddGoodsId(po.getPddGoodsId());
vo.setPddDraftPushedAt(po.getPddDraftPushedAt());
vo.setRejectComment(po.getRejectComment());
vo.setRejectTime(po.getRejectTime());
vo.setCreatedBy(po.getCreatedBy());
vo.setCreateTime(po.getCreateTime());
vo.setUpdateTime(po.getUpdateTime());
@@ -102,15 +102,13 @@ public class PddGoodsPublishJobRunnerImpl implements PddGoodsPublishJobRunner {
if (dto.getPddShopId() == null && draft.getPddShopId() != null) {
dto.setPddShopId(draft.getPddShopId());
}
dto.setSystemDraftId(draft.getId());
PddGoodsPublishResultVO result = publishService.publish(dto);
item.setStatus(PddGoodsPublishJobItemPO.STATUS_SUCCESS);
item.setGoodsId(result.getGoodsId() == null ? null : String.valueOf(result.getGoodsId()));
item.setErrorMessage(null);
jobItemMapper.updateById(item);
draft.setStatus(PddGoodsPublishDraftPO.STATUS_PUBLISHED);
draft.setLastError(null);
draftMapper.updateById(draft);
// status / commitId / goodsId 由 publish(systemDraftId) 回写
success++;
} catch (Exception e) {
String msg = e.getMessage() == null ? "发布失败" : e.getMessage();
@@ -1,6 +1,7 @@
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -34,6 +35,8 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddP
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishLogisticsTemplateVO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishParentSpecVO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishSpecIdVO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.mapper.PddGoodsPublishDraftMapper;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.PddGoodsPublishDraftPO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.PddGoodsPublishService;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.PddGoodsService;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.support.PddGoodsImageTransfer;
@@ -74,6 +77,7 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
private final PddGoodsService pddGoodsService;
private final PddGoodsMapper pddGoodsMapper;
private final PddProductAutoCreateService productAutoCreateService;
private final PddGoodsPublishDraftMapper publishDraftMapper;
public PddGoodsPublishServiceImpl(CurrentUserContext currentUserContext,
PddShopMapper pddShopMapper,
@@ -85,7 +89,8 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
ProductSkuService productSkuService,
PddGoodsService pddGoodsService,
PddGoodsMapper pddGoodsMapper,
PddProductAutoCreateService productAutoCreateService) {
PddProductAutoCreateService productAutoCreateService,
PddGoodsPublishDraftMapper publishDraftMapper) {
this.currentUserContext = currentUserContext;
this.pddShopMapper = pddShopMapper;
this.authTokenService = authTokenService;
@@ -97,6 +102,7 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
this.pddGoodsService = pddGoodsService;
this.pddGoodsMapper = pddGoodsMapper;
this.productAutoCreateService = productAutoCreateService;
this.publishDraftMapper = publishDraftMapper;
}
@Override
@@ -308,6 +314,8 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
result.setGoodsCommitId(addResult.goodsCommitId());
result.setMatchedSpuId(addResult.matchedSpuId());
result.setGoods(goodsVo);
bindSystemDraftAfterPublish(companyId, dto.getSystemDraftId(),
addResult.goodsCommitId(), addResult.goodsId());
log.info("拼多多商品发布成功 companyId={} shopId={} goodsId={} primaryProductId={}",
companyId, ctx.shop().getId(), addResult.goodsId(), primary.getId());
return result;
@@ -755,6 +763,27 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
return new ShopAuth(shop, shop.getMallId(), auth.getAccessToken());
}
/** 发布成功后把平台 commitId/goodsId 写回系统草稿,供审核驳回消息匹配 */
private void bindSystemDraftAfterPublish(
Long companyId, Long systemDraftId, Long goodsCommitId, Long goodsId) {
if (systemDraftId == null) {
return;
}
PddGoodsPublishDraftPO draft = publishDraftMapper.selectById(systemDraftId);
if (draft == null || !Objects.equals(draft.getCompanyId(), companyId)) {
log.warn("发布回写系统草稿跳过:草稿不存在或不属于当前公司 draftId={}", systemDraftId);
return;
}
publishDraftMapper.update(null, new LambdaUpdateWrapper<PddGoodsPublishDraftPO>()
.eq(PddGoodsPublishDraftPO::getId, draft.getId())
.set(PddGoodsPublishDraftPO::getStatus, PddGoodsPublishDraftPO.STATUS_PUBLISHED)
.set(PddGoodsPublishDraftPO::getLastError, null)
.set(PddGoodsPublishDraftPO::getPddGoodsCommitId, goodsCommitId)
.set(PddGoodsPublishDraftPO::getPddGoodsId, goodsId)
.set(PddGoodsPublishDraftPO::getRejectComment, null)
.set(PddGoodsPublishDraftPO::getRejectTime, null));
}
private BusinessException wrapPop(String prefix, Exception e) {
if (e instanceof BusinessException be) {
return be;
@@ -29,6 +29,7 @@ public class PddMsgProperties {
"pdd_goods_GoodsUpdate",
"pdd_goods_GoodsOnShelf",
"pdd_goods_GoodsOffShelf",
"pdd_goods_GoodsDelete"
"pdd_goods_GoodsDelete",
"pdd_goods_GoodsCheckReject"
));
}
@@ -0,0 +1,111 @@
package top.xyquan.ecomdmbbackend.modules.channel.pdd.msg.handler.goods;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.service.PddGoodsPublishDeskService;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.msg.dispatch.PddMsgHandler;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.msg.inbox.model.po.PddMsgInboxPO;
import top.xyquan.ecomdmbbackend.modules.channel.pdd.msg.support.PddMsgContentSupport;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
/**
* 商品审核驳回:仅当系统草稿挂有对应 commitId/goodsId 时回写驳回状态;纯平台草稿忽略。
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class PddGoodsCheckRejectMsgHandler implements PddMsgHandler {
public static final String TYPE = "pdd_goods_GoodsCheckReject";
private final PddGoodsPublishDeskService deskService;
private final PddMsgContentSupport contentSupport;
@Override
public String supportType() {
return TYPE;
}
@Override
public void handle(PddMsgInboxPO inbox) {
if (inbox.getCompanyId() == null || inbox.getChannelShopId() == null) {
throw new IllegalStateException("驳回消息未绑定店铺 inboxId=" + inbox.getId());
}
JsonNode content = contentSupport.parseContent(inbox.getContentJson());
Long commitId = readLong(content, "goods_commit_id");
Long goodsId = readLong(content, "goods_id");
if (goodsId == null && StringUtils.hasText(inbox.getGoodsId())) {
try {
goodsId = Long.parseLong(inbox.getGoodsId().trim());
} catch (NumberFormatException ignored) {
// ignore
}
}
// 文档类型写成 LONG,示例为文案;按字符串兼容
String rejectComment = readText(content, "reject_comment");
Long rejectTimeMs = readLong(content, "reject_time");
LocalDateTime rejectTime = null;
if (rejectTimeMs != null && rejectTimeMs > 0) {
rejectTime = LocalDateTime.ofInstant(
Instant.ofEpochMilli(rejectTimeMs), ZoneId.systemDefault());
}
boolean updated = deskService.applyGoodsCheckReject(
inbox.getCompanyId(),
inbox.getChannelShopId(),
commitId,
goodsId,
rejectComment,
rejectTime);
if (updated) {
log.info("系统草稿已标记审核驳回 shopId={} commitId={} goodsId={}",
inbox.getChannelShopId(), commitId, goodsId);
} else {
log.info("驳回消息无匹配系统草稿,忽略 shopId={} commitId={} goodsId={}",
inbox.getChannelShopId(), commitId, goodsId);
}
}
private static Long readLong(JsonNode content, String field) {
if (content == null || content.isNull()) {
return null;
}
JsonNode node = content.get(field);
if (node == null || node.isNull()) {
return null;
}
if (node.isNumber()) {
return node.asLong();
}
String text = node.asText(null);
if (!StringUtils.hasText(text)) {
return null;
}
try {
return Long.parseLong(text.trim());
} catch (NumberFormatException e) {
return null;
}
}
private static String readText(JsonNode content, String field) {
if (content == null || content.isNull()) {
return null;
}
JsonNode node = content.get(field);
if (node == null || node.isNull()) {
return null;
}
if (node.isTextual()) {
return node.asText();
}
// 兼容错误标注为数字的驳回原因
return node.asText(null);
}
}
@@ -23,6 +23,7 @@ pdd:
- pdd_goods_GoodsOnShelf
- pdd_goods_GoodsOffShelf
- pdd_goods_GoodsDelete
- pdd_goods_GoodsCheckReject
order-sync:
overlap-seconds: 120