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:
@@ -0,0 +1,2 @@
|
||||
-- 拼多多发布工作台表设计(与 V20260912 migration 一致,供文档查阅)
|
||||
-- channel_pdd_goods_publish_draft / job / job_item
|
||||
@@ -0,0 +1,105 @@
|
||||
-- 拼多多发布工作台:草稿 + 批量发布任务
|
||||
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 '最近发布失败原因',
|
||||
`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='拼多多商品批量发布任务明细';
|
||||
|
||||
-- 菜单:发布工作台(挂在拼多多下,order=6)
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 12036,
|
||||
(SELECT id FROM `sys_menu` WHERE `id` = 52 OR `title` = '拼多多' OR `route_name` = 'PddChannel' LIMIT 1),
|
||||
0,
|
||||
'PddGoodsPublishDesk',
|
||||
'发布工作台',
|
||||
'/pdd/goods/publish',
|
||||
'/channel/pdd/goods/publish/index',
|
||||
'',
|
||||
'lucide:send',
|
||||
'menu',
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
6
|
||||
FROM DUAL
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 12036 OR `route_name` = 'PddGoodsPublishDesk');
|
||||
|
||||
-- 隐藏详情编辑路由(挂在拼多多下,embedded,不进侧栏)
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 12037,
|
||||
(SELECT id FROM `sys_menu` WHERE `id` = 52 OR `title` = '拼多多' OR `route_name` = 'PddChannel' LIMIT 1),
|
||||
0,
|
||||
'PddGoodsPublishDeskEdit',
|
||||
'编辑发布草稿',
|
||||
'/pdd/goods/publish/edit/:draftId',
|
||||
'/channel/pdd/goods/publish/edit',
|
||||
'',
|
||||
'',
|
||||
'embedded',
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
99
|
||||
FROM DUAL
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 12037 OR `route_name` = 'PddGoodsPublishDeskEdit');
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id
|
||||
FROM `sys_menu` m
|
||||
JOIN `sys_permission` p ON p.code IN (
|
||||
'channel:pdd:goods:read',
|
||||
'channel:pdd:goods:create',
|
||||
'channel:pdd:cat:read'
|
||||
)
|
||||
WHERE m.route_name IN ('PddGoodsPublishDesk', 'PddGoodsPublishDeskEdit');
|
||||
@@ -0,0 +1,9 @@
|
||||
-- 修复:编辑草稿路由不能挂在工作台菜单子级(父级有组件无 router-view,跳转无反应)
|
||||
-- 改为挂在「拼多多」目录下,类型 embedded(与店铺/商品概览一致)
|
||||
UPDATE `sys_menu`
|
||||
SET
|
||||
`parent_id` = (SELECT id FROM (SELECT id FROM `sys_menu` WHERE `id` = 52 OR `title` = '拼多多' OR `route_name` = 'PddChannel' LIMIT 1) t),
|
||||
`type` = 'embedded',
|
||||
`visible` = 0,
|
||||
`order` = 99
|
||||
WHERE `id` = 12037 OR `route_name` = 'PddGoodsPublishDeskEdit';
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskCloneDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskDraftFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskDraftSaveDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskJobCreateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.PddGoodsPublishDraftVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.PddGoodsPublishJobVO;
|
||||
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 top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.service.PddGoodsPublishDeskService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 拼多多发布工作台 API(草稿 / 克隆 / 批量任务)。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/channel/pdd/goods/publish-desk")
|
||||
public class PddGoodsPublishDeskController {
|
||||
|
||||
private final PddGoodsPublishDeskService deskService;
|
||||
|
||||
public PddGoodsPublishDeskController(PddGoodsPublishDeskService deskService) {
|
||||
this.deskService = deskService;
|
||||
}
|
||||
|
||||
@PostMapping("/drafts/list")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "发布工作台草稿列表", allowSuper = true)
|
||||
public ApiResponse<PddPublishDeskDraftPageVO> listDrafts(
|
||||
@Valid @RequestBody PageQueryDTO<PddPublishDeskDraftFilterDTO> query) {
|
||||
return ApiResponse.success("获取成功", deskService.pageDrafts(query));
|
||||
}
|
||||
|
||||
@GetMapping("/drafts/shop-counts")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "发布工作台按店计数", allowSuper = true)
|
||||
public ApiResponse<List<PddPublishDeskShopCountVO>> shopCounts() {
|
||||
return ApiResponse.success("获取成功", deskService.listShopCounts());
|
||||
}
|
||||
|
||||
@GetMapping("/drafts/{id}")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "发布工作台草稿详情", allowSuper = true)
|
||||
public ApiResponse<PddGoodsPublishDraftVO> getDraft(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取成功", deskService.getDraft(id));
|
||||
}
|
||||
|
||||
@PostMapping("/drafts")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建发布草稿", allowSuper = true)
|
||||
public ApiResponse<PddGoodsPublishDraftVO> createDraft(@Valid @RequestBody PddPublishDeskDraftSaveDTO dto) {
|
||||
return ApiResponse.success("创建成功", deskService.createDraft(dto));
|
||||
}
|
||||
|
||||
@PutMapping("/drafts/{id}")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "更新发布草稿", allowSuper = true)
|
||||
public ApiResponse<PddGoodsPublishDraftVO> updateDraft(
|
||||
@PathVariable Long id, @Valid @RequestBody PddPublishDeskDraftSaveDTO dto) {
|
||||
return ApiResponse.success("保存成功", deskService.updateDraft(id, dto));
|
||||
}
|
||||
|
||||
@DeleteMapping("/drafts/{id}")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "删除发布草稿", allowSuper = true)
|
||||
public ApiResponse<Void> deleteDraft(@PathVariable Long id) {
|
||||
deskService.deleteDraft(id);
|
||||
return ApiResponse.success("删除成功", null);
|
||||
}
|
||||
|
||||
@PostMapping("/drafts/clone")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "一键克隆发布草稿", allowSuper = true)
|
||||
public ApiResponse<List<PddGoodsPublishDraftVO>> cloneDraft(@Valid @RequestBody PddPublishDeskCloneDTO dto) {
|
||||
return ApiResponse.success("克隆成功", deskService.cloneDraft(dto));
|
||||
}
|
||||
|
||||
@PostMapping("/jobs")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建批量发布任务", allowSuper = true)
|
||||
public ApiResponse<PddGoodsPublishJobVO> createJob(@Valid @RequestBody PddPublishDeskJobCreateDTO dto) {
|
||||
return ApiResponse.success("任务已创建", deskService.createJob(dto));
|
||||
}
|
||||
|
||||
@GetMapping("/jobs/{id}")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "查询批量发布任务", allowSuper = true)
|
||||
public ApiResponse<PddGoodsPublishJobVO> getJob(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取成功", deskService.getJob(id));
|
||||
}
|
||||
|
||||
@PostMapping("/jobs/{id}/retry-failed")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "重试失败发布项", allowSuper = true)
|
||||
public ApiResponse<PddGoodsPublishJobVO> retryFailed(@PathVariable Long id) {
|
||||
return ApiResponse.success("已开始重试", deskService.retryFailedItems(id));
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.PddGoodsPublishDraftPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.PddPublishDeskShopCountVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 发布草稿 Mapper。
|
||||
*/
|
||||
@Mapper
|
||||
public interface PddGoodsPublishDraftMapper extends BaseMapper<PddGoodsPublishDraftPO> {
|
||||
|
||||
@Select("""
|
||||
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')
|
||||
GROUP BY pdd_shop_id
|
||||
""")
|
||||
List<PddPublishDeskShopCountVO> countByShop(@Param("companyId") Long companyId);
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.PddGoodsPublishJobItemPO;
|
||||
|
||||
/**
|
||||
* 批量发布任务明细 Mapper。
|
||||
*/
|
||||
@Mapper
|
||||
public interface PddGoodsPublishJobItemMapper extends BaseMapper<PddGoodsPublishJobItemPO> {
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.PddGoodsPublishJobPO;
|
||||
|
||||
/**
|
||||
* 批量发布任务 Mapper。
|
||||
*/
|
||||
@Mapper
|
||||
public interface PddGoodsPublishJobMapper extends BaseMapper<PddGoodsPublishJobPO> {
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 一键克隆:母版草稿 → 多目标店 × 份数。
|
||||
*/
|
||||
@Data
|
||||
public class PddPublishDeskCloneDTO {
|
||||
|
||||
@NotNull(message = "源草稿不能为空")
|
||||
private Long sourceDraftId;
|
||||
|
||||
@NotEmpty(message = "请至少选择一个目标店铺")
|
||||
@Valid
|
||||
private List<Target> targets;
|
||||
|
||||
@Data
|
||||
public static class Target {
|
||||
@NotNull(message = "目标店铺不能为空")
|
||||
private Long pddShopId;
|
||||
|
||||
@NotNull(message = "份数不能为空")
|
||||
@Min(value = 1, message = "每店至少 1 份")
|
||||
@Max(value = 20, message = "每店最多 20 份")
|
||||
private Integer count = 1;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 草稿列表筛选。
|
||||
*/
|
||||
@Data
|
||||
public class PddPublishDeskDraftFilterDTO {
|
||||
/** 不传=全部;传 0 或负数表示未分配店铺 */
|
||||
private Long pddShopId;
|
||||
private String status;
|
||||
private String keyword;
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建/更新发布草稿。
|
||||
*/
|
||||
@Data
|
||||
public class PddPublishDeskDraftSaveDTO {
|
||||
private Long pddShopId;
|
||||
@NotBlank(message = "标题不能为空")
|
||||
private String title;
|
||||
private Long catId;
|
||||
private Integer skuCount;
|
||||
/** EDITING / NEED_CHECK / READY */
|
||||
private String status;
|
||||
/** 编辑器完整状态 JSON(含可选 publishPayload) */
|
||||
private String payloadJson;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 创建批量发布任务。
|
||||
*/
|
||||
@Data
|
||||
public class PddPublishDeskJobCreateDTO {
|
||||
@NotEmpty(message = "请至少选择一条草稿")
|
||||
private List<Long> draftIds;
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 拼多多商品发布草稿。
|
||||
*/
|
||||
@Data
|
||||
@TableName("channel_pdd_goods_publish_draft")
|
||||
public class PddGoodsPublishDraftPO {
|
||||
|
||||
public static final String STATUS_EDITING = "EDITING";
|
||||
public static final String STATUS_NEED_CHECK = "NEED_CHECK";
|
||||
public static final String STATUS_READY = "READY";
|
||||
public static final String STATUS_PUBLISHING = "PUBLISHING";
|
||||
public static final String STATUS_FAILED = "FAILED";
|
||||
public static final String STATUS_PUBLISHED = "PUBLISHED";
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("pdd_shop_id")
|
||||
private Long pddShopId;
|
||||
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
@TableField("cat_id")
|
||||
private Long catId;
|
||||
|
||||
@TableField("sku_count")
|
||||
private Integer skuCount;
|
||||
|
||||
@TableField("status")
|
||||
private String status;
|
||||
|
||||
@TableField("payload_json")
|
||||
private String payloadJson;
|
||||
|
||||
@TableField("source_draft_id")
|
||||
private Long sourceDraftId;
|
||||
|
||||
@TableField("last_error")
|
||||
private String lastError;
|
||||
|
||||
@TableField("created_by")
|
||||
private Long createdBy;
|
||||
|
||||
@TableField("create_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 拼多多商品批量发布任务明细(一行对应一草稿)。
|
||||
*/
|
||||
@Data
|
||||
@TableName("channel_pdd_goods_publish_job_item")
|
||||
public class PddGoodsPublishJobItemPO {
|
||||
|
||||
public static final String STATUS_PENDING = "PENDING";
|
||||
public static final String STATUS_RUNNING = "RUNNING";
|
||||
public static final String STATUS_SUCCESS = "SUCCESS";
|
||||
public static final String STATUS_FAILED = "FAILED";
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("job_id")
|
||||
private Long jobId;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("draft_id")
|
||||
private Long draftId;
|
||||
|
||||
@TableField("pdd_shop_id")
|
||||
private Long pddShopId;
|
||||
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
@TableField("status")
|
||||
private String status;
|
||||
|
||||
@TableField("goods_id")
|
||||
private String goodsId;
|
||||
|
||||
@TableField("error_message")
|
||||
private String errorMessage;
|
||||
|
||||
@TableField("create_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 拼多多商品批量发布任务。
|
||||
*/
|
||||
@Data
|
||||
@TableName("channel_pdd_goods_publish_job")
|
||||
public class PddGoodsPublishJobPO {
|
||||
|
||||
public static final String STATUS_PENDING = "PENDING";
|
||||
public static final String STATUS_RUNNING = "RUNNING";
|
||||
public static final String STATUS_SUCCESS = "SUCCESS";
|
||||
public static final String STATUS_PARTIAL = "PARTIAL";
|
||||
public static final String STATUS_FAILED = "FAILED";
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("status")
|
||||
private String status;
|
||||
|
||||
@TableField("total_count")
|
||||
private Integer totalCount;
|
||||
|
||||
@TableField("success_count")
|
||||
private Integer successCount;
|
||||
|
||||
@TableField("fail_count")
|
||||
private Integer failCount;
|
||||
|
||||
@TableField("message")
|
||||
private String message;
|
||||
|
||||
@TableField("created_by")
|
||||
private Long createdBy;
|
||||
|
||||
@TableField("started_at")
|
||||
private LocalDateTime startedAt;
|
||||
|
||||
@TableField("finished_at")
|
||||
private LocalDateTime finishedAt;
|
||||
|
||||
@TableField("create_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 发布草稿 VO。
|
||||
*/
|
||||
@Data
|
||||
public class PddGoodsPublishDraftVO {
|
||||
private Long id;
|
||||
private Long companyId;
|
||||
private Long pddShopId;
|
||||
private String shopName;
|
||||
private String title;
|
||||
private Long catId;
|
||||
private Integer skuCount;
|
||||
private String status;
|
||||
private String payloadJson;
|
||||
private Long sourceDraftId;
|
||||
private String lastError;
|
||||
private Long createdBy;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 批量发布任务明细 VO。
|
||||
*/
|
||||
@Data
|
||||
public class PddGoodsPublishJobItemVO {
|
||||
private Long id;
|
||||
private Long jobId;
|
||||
private Long draftId;
|
||||
private Long pddShopId;
|
||||
private String shopName;
|
||||
private String title;
|
||||
private String status;
|
||||
private String goodsId;
|
||||
private String errorMessage;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量发布任务 VO。
|
||||
*/
|
||||
@Data
|
||||
public class PddGoodsPublishJobVO {
|
||||
private Long id;
|
||||
private Long companyId;
|
||||
private String status;
|
||||
private Integer totalCount;
|
||||
private Integer successCount;
|
||||
private Integer failCount;
|
||||
private String message;
|
||||
private LocalDateTime startedAt;
|
||||
private LocalDateTime finishedAt;
|
||||
private LocalDateTime createTime;
|
||||
private List<PddGoodsPublishJobItemVO> items;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 草稿分页结果:附带按店计数供左栏。
|
||||
*/
|
||||
@Data
|
||||
public class PddPublishDeskDraftPageVO {
|
||||
private Long total;
|
||||
private Long page;
|
||||
private Long pageSize;
|
||||
private List<PddGoodsPublishDraftVO> records;
|
||||
private List<PddPublishDeskShopCountVO> shopCounts;
|
||||
/** 有待发草稿的店铺数(不含未分配) */
|
||||
private Integer shopWithDraftCount;
|
||||
/** 全部待发草稿数 */
|
||||
private Integer totalPendingCount;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 按店待发草稿计数(左栏徽章)。
|
||||
*/
|
||||
@Data
|
||||
public class PddPublishDeskShopCountVO {
|
||||
/** null 表示未分配店铺 */
|
||||
private Long pddShopId;
|
||||
private Long draftCount;
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskCloneDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskDraftFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskDraftSaveDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskJobCreateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.PddGoodsPublishDraftVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.PddGoodsPublishJobVO;
|
||||
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.util.List;
|
||||
|
||||
/**
|
||||
* 拼多多发布工作台:草稿 CRUD、一键克隆、批量发布任务。
|
||||
*/
|
||||
public interface PddGoodsPublishDeskService {
|
||||
|
||||
PddPublishDeskDraftPageVO pageDrafts(PageQueryDTO<PddPublishDeskDraftFilterDTO> query);
|
||||
|
||||
List<PddPublishDeskShopCountVO> listShopCounts();
|
||||
|
||||
PddGoodsPublishDraftVO getDraft(Long id);
|
||||
|
||||
PddGoodsPublishDraftVO createDraft(PddPublishDeskDraftSaveDTO dto);
|
||||
|
||||
PddGoodsPublishDraftVO updateDraft(Long id, PddPublishDeskDraftSaveDTO dto);
|
||||
|
||||
void deleteDraft(Long id);
|
||||
|
||||
/** 克隆母版到多店,返回新建草稿列表 */
|
||||
List<PddGoodsPublishDraftVO> cloneDraft(PddPublishDeskCloneDTO dto);
|
||||
|
||||
PddGoodsPublishJobVO createJob(PddPublishDeskJobCreateDTO dto);
|
||||
|
||||
PddGoodsPublishJobVO getJob(Long jobId);
|
||||
|
||||
/** 重试任务中失败的明细 */
|
||||
PddGoodsPublishJobVO retryFailedItems(Long jobId);
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.service;
|
||||
|
||||
/**
|
||||
* 异步执行批量发布任务(避免同类自调用导致 @Async 失效)。
|
||||
*/
|
||||
public interface PddGoodsPublishJobRunner {
|
||||
|
||||
void runJob(Long companyId, Long jobId);
|
||||
|
||||
void retryFailed(Long companyId, Long jobId);
|
||||
}
|
||||
+461
@@ -0,0 +1,461 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
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.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;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskCloneDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskDraftFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskDraftSaveDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.dto.PddPublishDeskJobCreateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.PddGoodsPublishDraftPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.PddGoodsPublishJobItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.PddGoodsPublishJobPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.PddGoodsPublishDraftVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.PddGoodsPublishJobItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo.PddGoodsPublishJobVO;
|
||||
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 top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.service.PddGoodsPublishDeskService;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.service.PddGoodsPublishJobRunner;
|
||||
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.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 发布工作台:草稿持久化、克隆、创建异步发布任务。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskService {
|
||||
|
||||
private static final Set<String> PENDING_STATUSES = Set.of(
|
||||
PddGoodsPublishDraftPO.STATUS_EDITING,
|
||||
PddGoodsPublishDraftPO.STATUS_NEED_CHECK,
|
||||
PddGoodsPublishDraftPO.STATUS_READY,
|
||||
PddGoodsPublishDraftPO.STATUS_FAILED,
|
||||
PddGoodsPublishDraftPO.STATUS_PUBLISHING
|
||||
);
|
||||
|
||||
private final PddGoodsPublishDraftMapper draftMapper;
|
||||
private final PddGoodsPublishJobMapper jobMapper;
|
||||
private final PddGoodsPublishJobItemMapper jobItemMapper;
|
||||
private final PddShopMapper pddShopMapper;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final PddGoodsPublishJobRunner jobRunner;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public PddPublishDeskDraftPageVO pageDrafts(PageQueryDTO<PddPublishDeskDraftFilterDTO> query) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PddPublishDeskDraftFilterDTO filter =
|
||||
query.getFilters() != null ? query.getFilters() : new PddPublishDeskDraftFilterDTO();
|
||||
|
||||
LambdaQueryWrapper<PddGoodsPublishDraftPO> qw = new LambdaQueryWrapper<>();
|
||||
qw.eq(PddGoodsPublishDraftPO::getCompanyId, companyId);
|
||||
if (filter.getPddShopId() != null) {
|
||||
if (filter.getPddShopId() <= 0) {
|
||||
qw.isNull(PddGoodsPublishDraftPO::getPddShopId);
|
||||
} else {
|
||||
qw.eq(PddGoodsPublishDraftPO::getPddShopId, filter.getPddShopId());
|
||||
}
|
||||
}
|
||||
if (StringUtils.hasText(filter.getStatus())) {
|
||||
qw.eq(PddGoodsPublishDraftPO::getStatus, filter.getStatus());
|
||||
} else {
|
||||
qw.in(PddGoodsPublishDraftPO::getStatus, PENDING_STATUSES);
|
||||
}
|
||||
if (StringUtils.hasText(filter.getKeyword())) {
|
||||
qw.like(PddGoodsPublishDraftPO::getTitle, filter.getKeyword().trim());
|
||||
}
|
||||
qw.orderByDesc(PddGoodsPublishDraftPO::getUpdateTime);
|
||||
|
||||
IPage<PddGoodsPublishDraftPO> page =
|
||||
draftMapper.selectPage(new Page<>(query.getPage(), query.getPageSize()), qw);
|
||||
Map<Long, String> shopNames = loadShopNames(companyId, page.getRecords().stream()
|
||||
.map(PddGoodsPublishDraftPO::getPddShopId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet()));
|
||||
|
||||
PddPublishDeskDraftPageVO vo = new PddPublishDeskDraftPageVO();
|
||||
vo.setTotal(page.getTotal());
|
||||
vo.setPage((long) query.getPage());
|
||||
vo.setPageSize((long) query.getPageSize());
|
||||
vo.setRecords(page.getRecords().stream()
|
||||
.map(po -> toDraftVo(po, shopNames))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
List<PddPublishDeskShopCountVO> counts = draftMapper.countByShop(companyId);
|
||||
vo.setShopCounts(counts == null ? List.of() : counts);
|
||||
int totalPending = 0;
|
||||
int shopWith = 0;
|
||||
for (PddPublishDeskShopCountVO c : vo.getShopCounts()) {
|
||||
int n = c.getDraftCount() == null ? 0 : c.getDraftCount().intValue();
|
||||
totalPending += n;
|
||||
if (c.getPddShopId() != null && n > 0) {
|
||||
shopWith++;
|
||||
}
|
||||
}
|
||||
vo.setTotalPendingCount(totalPending);
|
||||
vo.setShopWithDraftCount(shopWith);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PddPublishDeskShopCountVO> listShopCounts() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
List<PddPublishDeskShopCountVO> counts = draftMapper.countByShop(companyId);
|
||||
return counts == null ? List.of() : counts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PddGoodsPublishDraftVO getDraft(Long id) {
|
||||
PddGoodsPublishDraftPO po = requireDraft(id);
|
||||
return toDraftVo(po, loadShopNamesForOne(po));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PddGoodsPublishDraftVO createDraft(PddPublishDeskDraftSaveDTO dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
if (dto.getPddShopId() != null) {
|
||||
requireOwnedShop(dto.getPddShopId(), companyId);
|
||||
}
|
||||
PddGoodsPublishDraftPO po = new PddGoodsPublishDraftPO();
|
||||
po.setCompanyId(companyId);
|
||||
po.setPddShopId(dto.getPddShopId());
|
||||
po.setTitle(dto.getTitle().trim());
|
||||
po.setCatId(dto.getCatId());
|
||||
po.setSkuCount(dto.getSkuCount() == null ? 0 : dto.getSkuCount());
|
||||
po.setStatus(normalizeStatus(dto.getStatus(), PddGoodsPublishDraftPO.STATUS_EDITING));
|
||||
po.setPayloadJson(dto.getPayloadJson());
|
||||
po.setCreatedBy(currentUserContext.getCurrentUserId());
|
||||
draftMapper.insert(po);
|
||||
return toDraftVo(po, loadShopNamesForOne(po));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PddGoodsPublishDraftVO updateDraft(Long id, PddPublishDeskDraftSaveDTO dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PddGoodsPublishDraftPO po = requireDraft(id);
|
||||
if (PddGoodsPublishDraftPO.STATUS_PUBLISHING.equals(po.getStatus())
|
||||
|| PddGoodsPublishDraftPO.STATUS_PUBLISHED.equals(po.getStatus())) {
|
||||
throw new BusinessException("发布中或已发布的草稿不可编辑");
|
||||
}
|
||||
if (dto.getPddShopId() != null) {
|
||||
requireOwnedShop(dto.getPddShopId(), companyId);
|
||||
}
|
||||
po.setPddShopId(dto.getPddShopId());
|
||||
po.setTitle(dto.getTitle().trim());
|
||||
po.setCatId(dto.getCatId());
|
||||
po.setSkuCount(dto.getSkuCount() == null ? 0 : dto.getSkuCount());
|
||||
if (StringUtils.hasText(dto.getStatus())) {
|
||||
po.setStatus(normalizeStatus(dto.getStatus(), po.getStatus()));
|
||||
}
|
||||
po.setPayloadJson(dto.getPayloadJson());
|
||||
po.setLastError(null);
|
||||
draftMapper.updateById(po);
|
||||
return toDraftVo(po, loadShopNamesForOne(po));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteDraft(Long id) {
|
||||
PddGoodsPublishDraftPO po = requireDraft(id);
|
||||
if (PddGoodsPublishDraftPO.STATUS_PUBLISHING.equals(po.getStatus())) {
|
||||
throw new BusinessException("发布中的草稿不可删除");
|
||||
}
|
||||
draftMapper.deleteById(po.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<PddGoodsPublishDraftVO> cloneDraft(PddPublishDeskCloneDTO dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PddGoodsPublishDraftPO source = requireDraft(dto.getSourceDraftId());
|
||||
List<PddGoodsPublishDraftVO> created = new ArrayList<>();
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
|
||||
for (PddPublishDeskCloneDTO.Target target : dto.getTargets()) {
|
||||
requireOwnedShop(target.getPddShopId(), companyId);
|
||||
int count = target.getCount() == null ? 1 : target.getCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
PddGoodsPublishDraftPO po = new PddGoodsPublishDraftPO();
|
||||
po.setCompanyId(companyId);
|
||||
po.setPddShopId(target.getPddShopId());
|
||||
String title = source.getTitle();
|
||||
if (count > 1) {
|
||||
title = title + " (" + (i + 1) + ")";
|
||||
}
|
||||
po.setTitle(title);
|
||||
po.setCatId(source.getCatId());
|
||||
po.setSkuCount(source.getSkuCount());
|
||||
boolean sameShop = Objects.equals(source.getPddShopId(), target.getPddShopId());
|
||||
String status = sameShop
|
||||
? (StringUtils.hasText(source.getStatus())
|
||||
? source.getStatus()
|
||||
: PddGoodsPublishDraftPO.STATUS_EDITING)
|
||||
: PddGoodsPublishDraftPO.STATUS_NEED_CHECK;
|
||||
if (PddGoodsPublishDraftPO.STATUS_PUBLISHED.equals(status)
|
||||
|| PddGoodsPublishDraftPO.STATUS_PUBLISHING.equals(status)) {
|
||||
status = PddGoodsPublishDraftPO.STATUS_EDITING;
|
||||
}
|
||||
po.setStatus(status);
|
||||
po.setPayloadJson(rewritePayloadForShop(source.getPayloadJson(), target.getPddShopId(), !sameShop));
|
||||
po.setSourceDraftId(source.getId());
|
||||
po.setCreatedBy(userId);
|
||||
draftMapper.insert(po);
|
||||
created.add(toDraftVo(po, loadShopNamesForOne(po)));
|
||||
}
|
||||
}
|
||||
return created;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PddGoodsPublishJobVO createJob(PddPublishDeskJobCreateDTO dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
List<Long> ids = dto.getDraftIds().stream().distinct().toList();
|
||||
List<PddGoodsPublishDraftPO> drafts = draftMapper.selectBatchIds(ids);
|
||||
if (drafts.size() != ids.size()) {
|
||||
throw new BusinessException("部分草稿不存在");
|
||||
}
|
||||
for (PddGoodsPublishDraftPO d : drafts) {
|
||||
if (!companyId.equals(d.getCompanyId())) {
|
||||
throw new BusinessException("无权操作该草稿");
|
||||
}
|
||||
if (d.getPddShopId() == null) {
|
||||
throw new BusinessException("草稿「" + d.getTitle() + "」未分配店铺");
|
||||
}
|
||||
if (PddGoodsPublishDraftPO.STATUS_NEED_CHECK.equals(d.getStatus())) {
|
||||
throw new BusinessException("草稿「" + d.getTitle() + "」待校验(跨店克隆后请核对类目/运费)");
|
||||
}
|
||||
if (PddGoodsPublishDraftPO.STATUS_PUBLISHING.equals(d.getStatus())
|
||||
|| PddGoodsPublishDraftPO.STATUS_PUBLISHED.equals(d.getStatus())) {
|
||||
throw new BusinessException("草稿「" + d.getTitle() + "」正在发布或已发布");
|
||||
}
|
||||
if (!StringUtils.hasText(d.getPayloadJson()) || !d.getPayloadJson().contains("publishPayload")) {
|
||||
throw new BusinessException("草稿「" + d.getTitle() + "」缺少可发布数据,请先在编辑器保存");
|
||||
}
|
||||
}
|
||||
|
||||
PddGoodsPublishJobPO job = new PddGoodsPublishJobPO();
|
||||
job.setCompanyId(companyId);
|
||||
job.setStatus(PddGoodsPublishJobPO.STATUS_PENDING);
|
||||
job.setTotalCount(drafts.size());
|
||||
job.setSuccessCount(0);
|
||||
job.setFailCount(0);
|
||||
job.setCreatedBy(userId);
|
||||
jobMapper.insert(job);
|
||||
|
||||
for (PddGoodsPublishDraftPO d : drafts) {
|
||||
PddGoodsPublishJobItemPO item = new PddGoodsPublishJobItemPO();
|
||||
item.setJobId(job.getId());
|
||||
item.setCompanyId(companyId);
|
||||
item.setDraftId(d.getId());
|
||||
item.setPddShopId(d.getPddShopId());
|
||||
item.setTitle(d.getTitle());
|
||||
item.setStatus(PddGoodsPublishJobItemPO.STATUS_PENDING);
|
||||
jobItemMapper.insert(item);
|
||||
d.setStatus(PddGoodsPublishDraftPO.STATUS_PUBLISHING);
|
||||
draftMapper.updateById(d);
|
||||
}
|
||||
|
||||
jobRunner.runJob(companyId, job.getId());
|
||||
return getJob(job.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PddGoodsPublishJobVO getJob(Long jobId) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PddGoodsPublishJobPO job = jobMapper.selectById(jobId);
|
||||
if (job == null || !companyId.equals(job.getCompanyId())) {
|
||||
throw new BusinessException("任务不存在");
|
||||
}
|
||||
List<PddGoodsPublishJobItemPO> items = jobItemMapper.selectList(
|
||||
new LambdaQueryWrapper<PddGoodsPublishJobItemPO>()
|
||||
.eq(PddGoodsPublishJobItemPO::getJobId, jobId)
|
||||
.orderByAsc(PddGoodsPublishJobItemPO::getId));
|
||||
Map<Long, String> shopNames = loadShopNames(companyId, items.stream()
|
||||
.map(PddGoodsPublishJobItemPO::getPddShopId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet()));
|
||||
return toJobVo(job, items, shopNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PddGoodsPublishJobVO retryFailedItems(Long jobId) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PddGoodsPublishJobPO job = jobMapper.selectById(jobId);
|
||||
if (job == null || !companyId.equals(job.getCompanyId())) {
|
||||
throw new BusinessException("任务不存在");
|
||||
}
|
||||
long failed = jobItemMapper.selectCount(new LambdaQueryWrapper<PddGoodsPublishJobItemPO>()
|
||||
.eq(PddGoodsPublishJobItemPO::getJobId, jobId)
|
||||
.eq(PddGoodsPublishJobItemPO::getStatus, PddGoodsPublishJobItemPO.STATUS_FAILED));
|
||||
if (failed == 0) {
|
||||
throw new BusinessException("没有可重试的失败项");
|
||||
}
|
||||
job.setStatus(PddGoodsPublishJobPO.STATUS_PENDING);
|
||||
job.setMessage("重试失败项中");
|
||||
jobMapper.updateById(job);
|
||||
jobRunner.retryFailed(companyId, jobId);
|
||||
return getJob(jobId);
|
||||
}
|
||||
|
||||
private String rewritePayloadForShop(String payloadJson, Long targetShopId, boolean clearShopBound) {
|
||||
if (!StringUtils.hasText(payloadJson)) {
|
||||
return payloadJson;
|
||||
}
|
||||
try {
|
||||
JsonNode root = objectMapper.readTree(payloadJson);
|
||||
if (!(root instanceof ObjectNode rootObj)) {
|
||||
return payloadJson;
|
||||
}
|
||||
JsonNode editor = rootObj.get("editorState");
|
||||
if (editor instanceof ObjectNode editorObj) {
|
||||
editorObj.put("pddShopId", targetShopId);
|
||||
if (clearShopBound) {
|
||||
editorObj.putNull("costTemplateId");
|
||||
}
|
||||
}
|
||||
JsonNode publish = rootObj.get("publishPayload");
|
||||
if (publish instanceof ObjectNode pubObj) {
|
||||
pubObj.put("pddShopId", targetShopId);
|
||||
if (clearShopBound) {
|
||||
pubObj.putNull("costTemplateId");
|
||||
}
|
||||
}
|
||||
return objectMapper.writeValueAsString(rootObj);
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("克隆草稿内容失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizeStatus(String status, String fallback) {
|
||||
if (!StringUtils.hasText(status)) {
|
||||
return fallback;
|
||||
}
|
||||
String s = status.trim().toUpperCase();
|
||||
return switch (s) {
|
||||
case "EDITING", "NEED_CHECK", "READY", "FAILED" -> s;
|
||||
default -> fallback;
|
||||
};
|
||||
}
|
||||
|
||||
private PddGoodsPublishDraftPO requireDraft(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PddGoodsPublishDraftPO po = draftMapper.selectById(id);
|
||||
if (po == null || !companyId.equals(po.getCompanyId())) {
|
||||
throw new BusinessException("草稿不存在");
|
||||
}
|
||||
return po;
|
||||
}
|
||||
|
||||
private void requireOwnedShop(Long shopId, Long companyId) {
|
||||
PddShopPO shop = pddShopMapper.selectById(shopId);
|
||||
if (shop == null || !companyId.equals(shop.getCompanyId())) {
|
||||
throw new BusinessException("渠道店铺不存在或无权访问");
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Long, String> loadShopNamesForOne(PddGoodsPublishDraftPO po) {
|
||||
if (po.getPddShopId() == null) {
|
||||
return Map.of();
|
||||
}
|
||||
return loadShopNames(po.getCompanyId(), Set.of(po.getPddShopId()));
|
||||
}
|
||||
|
||||
private Map<Long, String> loadShopNames(Long companyId, Set<Long> shopIds) {
|
||||
if (shopIds == null || shopIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
List<PddShopPO> shops = pddShopMapper.selectList(new LambdaQueryWrapper<PddShopPO>()
|
||||
.eq(PddShopPO::getCompanyId, companyId)
|
||||
.in(PddShopPO::getId, shopIds));
|
||||
Map<Long, String> map = new HashMap<>();
|
||||
for (PddShopPO s : shops) {
|
||||
map.put(s.getId(), s.getMallName() == null ? ("店铺#" + s.getId()) : s.getMallName());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private PddGoodsPublishDraftVO toDraftVo(PddGoodsPublishDraftPO po, Map<Long, String> shopNames) {
|
||||
PddGoodsPublishDraftVO vo = new PddGoodsPublishDraftVO();
|
||||
vo.setId(po.getId());
|
||||
vo.setCompanyId(po.getCompanyId());
|
||||
vo.setPddShopId(po.getPddShopId());
|
||||
if (po.getPddShopId() != null) {
|
||||
vo.setShopName(shopNames.getOrDefault(po.getPddShopId(), "店铺#" + po.getPddShopId()));
|
||||
}
|
||||
vo.setTitle(po.getTitle());
|
||||
vo.setCatId(po.getCatId());
|
||||
vo.setSkuCount(po.getSkuCount());
|
||||
vo.setStatus(po.getStatus());
|
||||
vo.setPayloadJson(po.getPayloadJson());
|
||||
vo.setSourceDraftId(po.getSourceDraftId());
|
||||
vo.setLastError(po.getLastError());
|
||||
vo.setCreatedBy(po.getCreatedBy());
|
||||
vo.setCreateTime(po.getCreateTime());
|
||||
vo.setUpdateTime(po.getUpdateTime());
|
||||
return vo;
|
||||
}
|
||||
|
||||
private PddGoodsPublishJobVO toJobVo(
|
||||
PddGoodsPublishJobPO job,
|
||||
List<PddGoodsPublishJobItemPO> items,
|
||||
Map<Long, String> shopNames) {
|
||||
PddGoodsPublishJobVO vo = new PddGoodsPublishJobVO();
|
||||
vo.setId(job.getId());
|
||||
vo.setCompanyId(job.getCompanyId());
|
||||
vo.setStatus(job.getStatus());
|
||||
vo.setTotalCount(job.getTotalCount());
|
||||
vo.setSuccessCount(job.getSuccessCount());
|
||||
vo.setFailCount(job.getFailCount());
|
||||
vo.setMessage(job.getMessage());
|
||||
vo.setStartedAt(job.getStartedAt());
|
||||
vo.setFinishedAt(job.getFinishedAt());
|
||||
vo.setCreateTime(job.getCreateTime());
|
||||
List<PddGoodsPublishJobItemVO> itemVos = new ArrayList<>();
|
||||
for (PddGoodsPublishJobItemPO it : items) {
|
||||
PddGoodsPublishJobItemVO iv = new PddGoodsPublishJobItemVO();
|
||||
iv.setId(it.getId());
|
||||
iv.setJobId(it.getJobId());
|
||||
iv.setDraftId(it.getDraftId());
|
||||
iv.setPddShopId(it.getPddShopId());
|
||||
if (it.getPddShopId() != null) {
|
||||
iv.setShopName(shopNames.getOrDefault(it.getPddShopId(), "店铺#" + it.getPddShopId()));
|
||||
}
|
||||
iv.setTitle(it.getTitle());
|
||||
iv.setStatus(it.getStatus());
|
||||
iv.setGoodsId(it.getGoodsId());
|
||||
iv.setErrorMessage(it.getErrorMessage());
|
||||
iv.setUpdateTime(it.getUpdateTime());
|
||||
itemVos.add(iv);
|
||||
}
|
||||
vo.setItems(itemVos);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
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.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;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.PddGoodsPublishDraftPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.PddGoodsPublishJobItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.PddGoodsPublishJobPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.service.PddGoodsPublishJobRunner;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.PddGoodsPublishService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量发布执行器:逐条调用现有单店 publish。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PddGoodsPublishJobRunnerImpl implements PddGoodsPublishJobRunner {
|
||||
|
||||
private final PddGoodsPublishJobMapper jobMapper;
|
||||
private final PddGoodsPublishJobItemMapper jobItemMapper;
|
||||
private final PddGoodsPublishDraftMapper draftMapper;
|
||||
private final PddGoodsPublishService publishService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void runJob(Long companyId, Long jobId) {
|
||||
process(companyId, jobId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void retryFailed(Long companyId, Long jobId) {
|
||||
process(companyId, jobId, true);
|
||||
}
|
||||
|
||||
private void process(Long companyId, Long jobId, boolean onlyFailed) {
|
||||
PddGoodsPublishJobPO job = jobMapper.selectById(jobId);
|
||||
if (job == null || !companyId.equals(job.getCompanyId())) {
|
||||
return;
|
||||
}
|
||||
job.setStatus(PddGoodsPublishJobPO.STATUS_RUNNING);
|
||||
job.setStartedAt(LocalDateTime.now());
|
||||
job.setFinishedAt(null);
|
||||
jobMapper.updateById(job);
|
||||
|
||||
LambdaQueryWrapper<PddGoodsPublishJobItemPO> qw = new LambdaQueryWrapper<>();
|
||||
qw.eq(PddGoodsPublishJobItemPO::getJobId, jobId)
|
||||
.eq(PddGoodsPublishJobItemPO::getCompanyId, companyId);
|
||||
if (onlyFailed) {
|
||||
qw.eq(PddGoodsPublishJobItemPO::getStatus, PddGoodsPublishJobItemPO.STATUS_FAILED);
|
||||
} else {
|
||||
qw.in(PddGoodsPublishJobItemPO::getStatus,
|
||||
PddGoodsPublishJobItemPO.STATUS_PENDING,
|
||||
PddGoodsPublishJobItemPO.STATUS_FAILED);
|
||||
}
|
||||
List<PddGoodsPublishJobItemPO> items = jobItemMapper.selectList(qw);
|
||||
|
||||
int success = job.getSuccessCount() == null ? 0 : job.getSuccessCount();
|
||||
int fail = onlyFailed ? 0 : (job.getFailCount() == null ? 0 : job.getFailCount());
|
||||
if (onlyFailed) {
|
||||
// 重试失败项:先把失败数扣回,下面按结果重算
|
||||
fail = 0;
|
||||
success = (job.getTotalCount() == null ? 0 : job.getTotalCount())
|
||||
- items.size();
|
||||
if (success < 0) {
|
||||
success = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (PddGoodsPublishJobItemPO item : items) {
|
||||
item.setStatus(PddGoodsPublishJobItemPO.STATUS_RUNNING);
|
||||
item.setErrorMessage(null);
|
||||
jobItemMapper.updateById(item);
|
||||
|
||||
PddGoodsPublishDraftPO draft = draftMapper.selectById(item.getDraftId());
|
||||
if (draft == null || !companyId.equals(draft.getCompanyId())) {
|
||||
markItemFailed(item, "草稿不存在");
|
||||
fail++;
|
||||
continue;
|
||||
}
|
||||
draft.setStatus(PddGoodsPublishDraftPO.STATUS_PUBLISHING);
|
||||
draft.setLastError(null);
|
||||
draftMapper.updateById(draft);
|
||||
|
||||
try {
|
||||
PddGoodsPublishDTO dto = extractPublishPayload(draft);
|
||||
if (dto.getPddShopId() == null && draft.getPddShopId() != null) {
|
||||
dto.setPddShopId(draft.getPddShopId());
|
||||
}
|
||||
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);
|
||||
success++;
|
||||
} catch (Exception e) {
|
||||
String msg = e.getMessage() == null ? "发布失败" : e.getMessage();
|
||||
if (msg.length() > 900) {
|
||||
msg = msg.substring(0, 900);
|
||||
}
|
||||
markItemFailed(item, msg);
|
||||
draft.setStatus(PddGoodsPublishDraftPO.STATUS_FAILED);
|
||||
draft.setLastError(msg);
|
||||
draftMapper.updateById(draft);
|
||||
fail++;
|
||||
log.warn("publish desk job item failed jobId={} draftId={}", jobId, item.getDraftId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// 汇总:以库中全部 item 为准
|
||||
long ok = jobItemMapper.selectCount(new LambdaQueryWrapper<PddGoodsPublishJobItemPO>()
|
||||
.eq(PddGoodsPublishJobItemPO::getJobId, jobId)
|
||||
.eq(PddGoodsPublishJobItemPO::getStatus, PddGoodsPublishJobItemPO.STATUS_SUCCESS));
|
||||
long bad = jobItemMapper.selectCount(new LambdaQueryWrapper<PddGoodsPublishJobItemPO>()
|
||||
.eq(PddGoodsPublishJobItemPO::getJobId, jobId)
|
||||
.eq(PddGoodsPublishJobItemPO::getStatus, PddGoodsPublishJobItemPO.STATUS_FAILED));
|
||||
job.setSuccessCount((int) ok);
|
||||
job.setFailCount((int) bad);
|
||||
job.setFinishedAt(LocalDateTime.now());
|
||||
if (bad == 0) {
|
||||
job.setStatus(PddGoodsPublishJobPO.STATUS_SUCCESS);
|
||||
job.setMessage("全部发布成功");
|
||||
} else if (ok == 0) {
|
||||
job.setStatus(PddGoodsPublishJobPO.STATUS_FAILED);
|
||||
job.setMessage("全部失败");
|
||||
} else {
|
||||
job.setStatus(PddGoodsPublishJobPO.STATUS_PARTIAL);
|
||||
job.setMessage("部分成功");
|
||||
}
|
||||
jobMapper.updateById(job);
|
||||
}
|
||||
|
||||
private void markItemFailed(PddGoodsPublishJobItemPO item, String msg) {
|
||||
item.setStatus(PddGoodsPublishJobItemPO.STATUS_FAILED);
|
||||
item.setErrorMessage(msg);
|
||||
jobItemMapper.updateById(item);
|
||||
}
|
||||
|
||||
private PddGoodsPublishDTO extractPublishPayload(PddGoodsPublishDraftPO draft) throws Exception {
|
||||
if (draft.getPayloadJson() == null || draft.getPayloadJson().isBlank()) {
|
||||
throw new IllegalStateException("草稿缺少发布内容,请先在编辑器保存完整表单");
|
||||
}
|
||||
JsonNode root = objectMapper.readTree(draft.getPayloadJson());
|
||||
JsonNode payload = root.get("publishPayload");
|
||||
if (payload == null || payload.isNull()) {
|
||||
throw new IllegalStateException("草稿尚未生成可发布数据,请在编辑器点击「保存并标记可发布」");
|
||||
}
|
||||
if (payload instanceof ObjectNode on && draft.getPddShopId() != null) {
|
||||
on.put("pddShopId", draft.getPddShopId());
|
||||
}
|
||||
return objectMapper.treeToValue(payload, PddGoodsPublishDTO.class);
|
||||
}
|
||||
}
|
||||
@@ -879,6 +879,19 @@ INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path
|
||||
SELECT 14009, (SELECT id FROM `sys_menu` WHERE `id` = 52 OR `title` = '拼多多' LIMIT 1), 0, 'PddGoodsAdFeeManagement', '商品广告费', '/pdd/goods-ad-fee', '/channel/pdd/goods-ad-fee/index', '', 'lucide:megaphone', 'menu', 1, 1, 0, 5
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14009 OR `route_name` = 'PddGoodsAdFeeManagement');
|
||||
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 12036, (SELECT id FROM `sys_menu` WHERE `id` = 52 OR `title` = '拼多多' LIMIT 1), 0, 'PddGoodsPublishDesk', '发布工作台', '/pdd/goods/publish', '/channel/pdd/goods/publish/index', '', 'lucide:send', 'menu', 1, 1, 1, 6
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 12036 OR `route_name` = 'PddGoodsPublishDesk');
|
||||
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 12037, (SELECT id FROM `sys_menu` WHERE `id` = 52 OR `title` = '拼多多' LIMIT 1), 0, 'PddGoodsPublishDeskEdit', '编辑发布草稿', '/pdd/goods/publish/edit/:draftId', '/channel/pdd/goods/publish/edit', '', '', 'embedded', 0, 1, 0, 99
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 12037 OR `route_name` = 'PddGoodsPublishDeskEdit');
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id FROM `sys_menu` m
|
||||
JOIN `sys_permission` p ON p.code IN ('channel:pdd:goods:read', 'channel:pdd:goods:create', 'channel:pdd:cat:read')
|
||||
WHERE m.route_name IN ('PddGoodsPublishDesk', 'PddGoodsPublishDeskEdit');
|
||||
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 14010, (SELECT id FROM `sys_menu` WHERE `id` = 7 OR `title` = '经营店铺' LIMIT 1), 0, 'ShopManagement', '店铺列表', '/ec/shop/list', '/ec/shop/list/index', '', 'solar:shop-outline', 'menu', 1, 1, 1, 1
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14010 OR `route_name` = 'ShopManagement');
|
||||
|
||||
@@ -7,6 +7,8 @@ import type {
|
||||
PddGoodsPublishDTO,
|
||||
PddGoodsPublishVO,
|
||||
PddGoodsVO,
|
||||
PddPublishDeskDTO,
|
||||
PddPublishDeskVO,
|
||||
} from './types';
|
||||
|
||||
/** 分页查询拼多多渠道商品 */
|
||||
@@ -118,3 +120,78 @@ export async function publishPddGoodsApi(data: PddGoodsPublishDTO.Publish) {
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** 发布工作台:草稿分页(含按店计数) */
|
||||
export async function listPddPublishDeskDraftsApi(
|
||||
params: PageQueryDTO<PddPublishDeskDTO.DraftFilters>,
|
||||
) {
|
||||
return requestClient.post<PddPublishDeskVO.DraftPage>(
|
||||
'/channel/pdd/goods/publish-desk/drafts/list',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export async function listPddPublishDeskShopCountsApi() {
|
||||
return requestClient.get<PddPublishDeskVO.ShopCount[]>(
|
||||
'/channel/pdd/goods/publish-desk/drafts/shop-counts',
|
||||
);
|
||||
}
|
||||
|
||||
export async function getPddPublishDeskDraftApi(id: number) {
|
||||
return requestClient.get<PddPublishDeskVO.Draft>(
|
||||
`/channel/pdd/goods/publish-desk/drafts/${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createPddPublishDeskDraftApi(
|
||||
data: PddPublishDeskDTO.DraftSave,
|
||||
) {
|
||||
return requestClient.post<PddPublishDeskVO.Draft>(
|
||||
'/channel/pdd/goods/publish-desk/drafts',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export async function updatePddPublishDeskDraftApi(
|
||||
id: number,
|
||||
data: PddPublishDeskDTO.DraftSave,
|
||||
) {
|
||||
return requestClient.put<PddPublishDeskVO.Draft>(
|
||||
`/channel/pdd/goods/publish-desk/drafts/${id}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export async function deletePddPublishDeskDraftApi(id: number) {
|
||||
return requestClient.delete(`/channel/pdd/goods/publish-desk/drafts/${id}`);
|
||||
}
|
||||
|
||||
export async function clonePddPublishDeskDraftApi(
|
||||
data: PddPublishDeskDTO.Clone,
|
||||
) {
|
||||
return requestClient.post<PddPublishDeskVO.Draft[]>(
|
||||
'/channel/pdd/goods/publish-desk/drafts/clone',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export async function createPddPublishDeskJobApi(
|
||||
data: PddPublishDeskDTO.JobCreate,
|
||||
) {
|
||||
return requestClient.post<PddPublishDeskVO.Job>(
|
||||
'/channel/pdd/goods/publish-desk/jobs',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getPddPublishDeskJobApi(id: number) {
|
||||
return requestClient.get<PddPublishDeskVO.Job>(
|
||||
`/channel/pdd/goods/publish-desk/jobs/${id}`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function retryPddPublishDeskJobFailedApi(id: number) {
|
||||
return requestClient.post<PddPublishDeskVO.Job>(
|
||||
`/channel/pdd/goods/publish-desk/jobs/${id}/retry-failed`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from './publish';
|
||||
export * from './publish-desk';
|
||||
|
||||
export namespace PddGoodsDTO {
|
||||
export interface Filters {
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/** 拼多多发布工作台类型 */
|
||||
export namespace PddPublishDeskDTO {
|
||||
export interface DraftFilters {
|
||||
/** <=0 表示未分配店铺 */
|
||||
pddShopId?: number;
|
||||
status?: string;
|
||||
keyword?: string;
|
||||
}
|
||||
|
||||
export interface DraftSave {
|
||||
pddShopId?: number;
|
||||
title: string;
|
||||
catId?: number;
|
||||
skuCount?: number;
|
||||
status?: string;
|
||||
payloadJson?: string;
|
||||
}
|
||||
|
||||
export interface CloneTarget {
|
||||
pddShopId: number;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface Clone {
|
||||
sourceDraftId: number;
|
||||
targets: CloneTarget[];
|
||||
}
|
||||
|
||||
export interface JobCreate {
|
||||
draftIds: number[];
|
||||
}
|
||||
}
|
||||
|
||||
export namespace PddPublishDeskVO {
|
||||
export interface ShopCount {
|
||||
pddShopId?: number | null;
|
||||
draftCount: number;
|
||||
}
|
||||
|
||||
export interface Draft {
|
||||
id: number;
|
||||
companyId?: number;
|
||||
pddShopId?: number;
|
||||
shopName?: string;
|
||||
title: string;
|
||||
catId?: number;
|
||||
skuCount?: number;
|
||||
status: string;
|
||||
payloadJson?: string;
|
||||
sourceDraftId?: number;
|
||||
lastError?: string;
|
||||
createdBy?: number;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
export interface DraftPage {
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
records: Draft[];
|
||||
shopCounts: ShopCount[];
|
||||
shopWithDraftCount?: number;
|
||||
totalPendingCount?: number;
|
||||
}
|
||||
|
||||
export interface JobItem {
|
||||
id: number;
|
||||
jobId: number;
|
||||
draftId: number;
|
||||
pddShopId?: number;
|
||||
shopName?: string;
|
||||
title: string;
|
||||
status: string;
|
||||
goodsId?: string;
|
||||
errorMessage?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
export interface Job {
|
||||
id: number;
|
||||
companyId?: number;
|
||||
status: string;
|
||||
totalCount: number;
|
||||
successCount: number;
|
||||
failCount: number;
|
||||
message?: string;
|
||||
startedAt?: string;
|
||||
finishedAt?: string;
|
||||
createTime?: string;
|
||||
items?: JobItem[];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
/**
|
||||
* 发布草稿编辑页:静态注册,避免挂在工作台菜单子级导致无 router-view 跳转无效。
|
||||
* 菜单里仍保留 embedded 项以绑定权限;路由以本静态路由为准。
|
||||
*/
|
||||
const staticRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'PddGoodsPublishDeskEdit',
|
||||
path: '/pdd/goods/publish/edit/:draftId',
|
||||
component: () => import('#/views/channel/pdd/goods/publish/edit.vue'),
|
||||
meta: {
|
||||
title: '编辑发布草稿',
|
||||
hideInMenu: true,
|
||||
ignoreAccess: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default staticRoutes;
|
||||
@@ -87,18 +87,18 @@ async function uploadFileToOssWithHeaderSignature(
|
||||
}
|
||||
}
|
||||
|
||||
/** multipart:经后端落盘/对象存储 */
|
||||
/** multipart:经后端落盘/对象存储(支持多文件一次提交) */
|
||||
async function uploadViaMultipart(
|
||||
file: File,
|
||||
files: File[],
|
||||
options?: UploadOptions,
|
||||
): Promise<FileVO.Info> {
|
||||
): Promise<FileVO.Info[]> {
|
||||
if (files.length === 0) return [];
|
||||
const category = resolveCategory(options?.category);
|
||||
const uploaded = await batchUploadFilesApi([file], category);
|
||||
const first = uploaded[0];
|
||||
if (!first) {
|
||||
const uploaded = await batchUploadFilesApi(files, category);
|
||||
if (!uploaded?.length || uploaded.length !== files.length) {
|
||||
throw new Error('文件上传失败');
|
||||
}
|
||||
return {
|
||||
return uploaded.map((first) => ({
|
||||
id: first.id,
|
||||
storageType: first.storageType,
|
||||
storagePath: first.storagePath,
|
||||
@@ -113,63 +113,98 @@ async function uploadViaMultipart(
|
||||
accessUrl: first.accessUrl,
|
||||
uploadTime: '',
|
||||
updateTime: '',
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
/** direct:签名直传 OSS 后入库 */
|
||||
/**
|
||||
* direct:一次 batch-sign-url → 直传 OSS → 一次 batch-create-oss
|
||||
*(避免每张图各打一次签名接口)
|
||||
*/
|
||||
async function uploadViaDirect(
|
||||
file: File,
|
||||
files: File[],
|
||||
options?: UploadOptions,
|
||||
): Promise<FileVO.Info> {
|
||||
): Promise<FileVO.Info[]> {
|
||||
if (files.length === 0) return [];
|
||||
const category = resolveCategory(options?.category);
|
||||
const fileHash = await calculateFileHash(file);
|
||||
const hashes = await Promise.all(files.map((f) => calculateFileHash(f)));
|
||||
|
||||
const signResponse = await batchSignUrlApi({
|
||||
files: [{ filename: file.name, fileHash, category }],
|
||||
files: files.map((file, i) => ({
|
||||
filename: file.name,
|
||||
fileHash: hashes[i]!,
|
||||
category,
|
||||
})),
|
||||
});
|
||||
|
||||
const signInfo = signResponse.files?.[0];
|
||||
if (!signInfo) {
|
||||
throw new Error('获取签名失败');
|
||||
const signInfos = signResponse.files ?? [];
|
||||
if (signInfos.length !== files.length) {
|
||||
throw new Error('获取签名失败:返回数量与请求不一致');
|
||||
}
|
||||
|
||||
if (signInfo.exists && signInfo.fileInfo) {
|
||||
return signInfo.fileInfo;
|
||||
const results: (FileVO.Info | undefined)[] = Array.from({
|
||||
length: files.length,
|
||||
});
|
||||
const toCreate: {
|
||||
index: number;
|
||||
file: File;
|
||||
fileHash: string;
|
||||
storagePath: string;
|
||||
}[] = [];
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i]!;
|
||||
const signInfo = signInfos[i]!;
|
||||
if (signInfo.exists && signInfo.fileInfo) {
|
||||
results[i] = signInfo.fileInfo;
|
||||
continue;
|
||||
}
|
||||
if (!signInfo.uploadUrl) {
|
||||
throw new Error(`未获取到上传URL:${file.name}`);
|
||||
}
|
||||
if (!signInfo.uploadHeaders) {
|
||||
throw new Error(`未获取到上传Header签名信息:${file.name}`);
|
||||
}
|
||||
if (!signInfo.storagePath) {
|
||||
throw new Error(`未获取到存储路径:${file.name}`);
|
||||
}
|
||||
await uploadFileToOssWithHeaderSignature(
|
||||
file,
|
||||
signInfo.uploadUrl,
|
||||
signInfo.uploadHeaders,
|
||||
);
|
||||
toCreate.push({
|
||||
index: i,
|
||||
file,
|
||||
fileHash: hashes[i]!,
|
||||
storagePath: signInfo.storagePath,
|
||||
});
|
||||
}
|
||||
|
||||
if (!signInfo.uploadUrl) {
|
||||
throw new Error('未获取到上传URL');
|
||||
}
|
||||
if (!signInfo.uploadHeaders) {
|
||||
throw new Error('未获取到上传Header签名信息');
|
||||
}
|
||||
if (!signInfo.storagePath) {
|
||||
throw new Error('未获取到存储路径');
|
||||
}
|
||||
|
||||
await uploadFileToOssWithHeaderSignature(
|
||||
file,
|
||||
signInfo.uploadUrl,
|
||||
signInfo.uploadHeaders,
|
||||
);
|
||||
|
||||
const createResponse = await batchCreateOssFilesApi({
|
||||
files: [
|
||||
{
|
||||
if (toCreate.length > 0) {
|
||||
const createResponse = await batchCreateOssFilesApi({
|
||||
files: toCreate.map(({ file, fileHash, storagePath }) => ({
|
||||
filename: file.name,
|
||||
fileHash,
|
||||
storagePath: signInfo.storagePath,
|
||||
storagePath,
|
||||
fileSize: file.size,
|
||||
mimeType: file.type,
|
||||
category,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const fileInfo = createResponse?.[0];
|
||||
if (!fileInfo) {
|
||||
throw new Error('创建文件记录失败');
|
||||
})),
|
||||
});
|
||||
if (!createResponse?.length || createResponse.length !== toCreate.length) {
|
||||
throw new Error('创建文件记录失败');
|
||||
}
|
||||
for (let j = 0; j < toCreate.length; j++) {
|
||||
results[toCreate[j]!.index] = createResponse[j];
|
||||
}
|
||||
}
|
||||
return fileInfo;
|
||||
|
||||
return results.map((info, i) => {
|
||||
if (!info) {
|
||||
throw new Error(`文件上传失败:${files[i]?.name || i}`);
|
||||
}
|
||||
return info;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,14 +214,29 @@ export async function uploadFile(
|
||||
file: File,
|
||||
options?: UploadOptions,
|
||||
): Promise<FileVO.Info> {
|
||||
const [info] = await uploadFiles([file], options);
|
||||
if (!info) {
|
||||
throw new Error(options?.errorMessage || '文件上传失败');
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量上传:direct 模式合并为一次签名 + 一次入库;multipart 一次 batch-upload
|
||||
*/
|
||||
export async function uploadFiles(
|
||||
files: File[],
|
||||
options?: UploadOptions,
|
||||
): Promise<FileVO.Info[]> {
|
||||
if (files.length === 0) return [];
|
||||
try {
|
||||
const appConfig = useAppConfigStore();
|
||||
await appConfig.ensureLoaded();
|
||||
|
||||
if (appConfig.isDirectUpload) {
|
||||
return await uploadViaDirect(file, options);
|
||||
return await uploadViaDirect(files, options);
|
||||
}
|
||||
return await uploadViaMultipart(file, options);
|
||||
return await uploadViaMultipart(files, options);
|
||||
} catch (error) {
|
||||
console.error('文件上传失败:', error);
|
||||
message.error(options?.errorMessage || '文件上传失败');
|
||||
@@ -194,20 +244,6 @@ export async function uploadFile(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量上传(当前按文件串行,保持与单文件同一分流逻辑)
|
||||
*/
|
||||
export async function uploadFiles(
|
||||
files: File[],
|
||||
options?: UploadOptions,
|
||||
): Promise<FileVO.Info[]> {
|
||||
const results: FileVO.Info[] = [];
|
||||
for (const file of files) {
|
||||
results.push(await uploadFile(file, options));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/** @deprecated 使用 uploadFile */
|
||||
export const uploadFileToOss = uploadFile;
|
||||
/** @deprecated 使用 uploadFiles */
|
||||
|
||||
@@ -23,6 +23,11 @@ withDefaults(
|
||||
resizable?: boolean;
|
||||
splitHandle?: boolean;
|
||||
splitLine?: boolean;
|
||||
/** 店铺待发草稿数 */
|
||||
draftCountByShopId?: Record<number, number>;
|
||||
showUnassignedFilter?: boolean;
|
||||
unassignedCount?: number;
|
||||
unassignedSelected?: boolean;
|
||||
}>(),
|
||||
{
|
||||
showAddAction: false,
|
||||
@@ -34,12 +39,17 @@ withDefaults(
|
||||
resizable: true,
|
||||
splitHandle: false,
|
||||
splitLine: false,
|
||||
draftCountByShopId: undefined,
|
||||
showUnassignedFilter: false,
|
||||
unassignedCount: 0,
|
||||
unassignedSelected: false,
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:selectedShopId': [id: number | undefined];
|
||||
select: [shop: PddShopVO.Info | null];
|
||||
selectUnassigned: [];
|
||||
addForShop: [shopId: number];
|
||||
}>();
|
||||
|
||||
@@ -78,10 +88,15 @@ const { width: leftWidth, collapsed: leftCollapsed } =
|
||||
show-collapse-action
|
||||
:selected-shop-id="selectedShopId"
|
||||
:show-add-action="showAddAction"
|
||||
:draft-count-by-shop-id="draftCountByShopId"
|
||||
:show-unassigned-filter="showUnassignedFilter"
|
||||
:unassigned-count="unassignedCount"
|
||||
:unassigned-selected="unassignedSelected"
|
||||
@collapse="collapse"
|
||||
@expand="expand"
|
||||
@update:selected-shop-id="emit('update:selectedShopId', $event)"
|
||||
@select="emit('select', $event)"
|
||||
@select-unassigned="emit('selectUnassigned')"
|
||||
@add-for-shop="emit('addForShop', $event)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
+100
-3
@@ -6,6 +6,7 @@ import { computed, onMounted, ref } from 'vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Card,
|
||||
Empty,
|
||||
@@ -28,6 +29,14 @@ const props = withDefaults(
|
||||
fluid?: boolean;
|
||||
showCollapseAction?: boolean;
|
||||
collapsed?: boolean;
|
||||
/** 店铺待发草稿数(发布工作台左栏徽章) */
|
||||
draftCountByShopId?: Record<number, number>;
|
||||
/** 是否展示「未分配」筛选项(发布工作台) */
|
||||
showUnassignedFilter?: boolean;
|
||||
/** 未分配草稿数 */
|
||||
unassignedCount?: number;
|
||||
/** 当前是否选中「未分配」(与 selectedShopId 互斥) */
|
||||
unassignedSelected?: boolean;
|
||||
}>(),
|
||||
{
|
||||
selectedShopId: undefined,
|
||||
@@ -35,18 +44,25 @@ const props = withDefaults(
|
||||
fluid: false,
|
||||
showCollapseAction: false,
|
||||
collapsed: false,
|
||||
draftCountByShopId: undefined,
|
||||
showUnassignedFilter: false,
|
||||
unassignedCount: 0,
|
||||
unassignedSelected: false,
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:selectedShopId': [id: number | undefined];
|
||||
select: [shop: PddShopVO.Info | null];
|
||||
/** 选中未分配(无店铺)草稿 */
|
||||
selectUnassigned: [];
|
||||
addForShop: [shopId: number];
|
||||
collapse: [];
|
||||
expand: [];
|
||||
}>();
|
||||
|
||||
const StoreIcon = createIconifyIcon('lucide:store');
|
||||
const InboxIcon = createIconifyIcon('lucide:inbox');
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close');
|
||||
const PanelOpenIcon = createIconifyIcon('lucide:panel-left-open');
|
||||
@@ -63,7 +79,10 @@ const shopTotalPages = computed(() => {
|
||||
return Math.max(1, Math.ceil(total / pageSize) || 1);
|
||||
});
|
||||
|
||||
const allSelected = computed(() => props.selectedShopId === undefined);
|
||||
/** 全部:未选具体店且未选「未分配」 */
|
||||
const allSelected = computed(
|
||||
() => props.selectedShopId === undefined && !props.unassignedSelected,
|
||||
);
|
||||
|
||||
function shopLabel(shop: PddShopVO.Info) {
|
||||
return shop.mallName || `店铺 #${shop.id}`;
|
||||
@@ -109,6 +128,10 @@ function selectAll() {
|
||||
emit('select', null);
|
||||
}
|
||||
|
||||
function selectUnassigned() {
|
||||
emit('selectUnassigned');
|
||||
}
|
||||
|
||||
function selectShop(shop: PddShopVO.Info) {
|
||||
emit('update:selectedShopId', shop.id);
|
||||
emit('select', shop);
|
||||
@@ -161,6 +184,31 @@ onMounted(() => {
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip v-if="showUnassignedFilter" title="未分配店铺">
|
||||
<Badge
|
||||
:count="unassignedCount || 0"
|
||||
:number-style="{ backgroundColor: '#999', fontSize: '10px' }"
|
||||
:offset="[-2, 2]"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
|
||||
:class="
|
||||
unassignedSelected
|
||||
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
|
||||
: undefined
|
||||
"
|
||||
@click="selectUnassigned"
|
||||
>
|
||||
<div
|
||||
class="flex h-9 w-9 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||
>
|
||||
<InboxIcon class="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
</button>
|
||||
</Badge>
|
||||
</Tooltip>
|
||||
|
||||
<Spin
|
||||
:spinning="shopsLoading"
|
||||
size="small"
|
||||
@@ -285,6 +333,44 @@ onMounted(() => {
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
v-if="showUnassignedFilter"
|
||||
size="small"
|
||||
:body-style="{ padding: '10px 12px' }"
|
||||
class="mb-2 cursor-pointer !shadow-none hover:border-primary"
|
||||
:class="
|
||||
unassignedSelected ? 'border-primary bg-primary/5' : undefined
|
||||
"
|
||||
@click="selectUnassigned"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<div
|
||||
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||
>
|
||||
<InboxIcon class="h-4 w-4 text-muted-foreground" />
|
||||
</div>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="min-w-0 truncate text-sm font-medium">未分配</span>
|
||||
<Badge
|
||||
v-if="(unassignedCount || 0) > 0"
|
||||
:count="unassignedCount"
|
||||
:number-style="{
|
||||
backgroundColor: '#999',
|
||||
fontSize: '10px',
|
||||
}"
|
||||
/>
|
||||
<span
|
||||
v-else
|
||||
class="shrink-0 text-xs text-muted-foreground"
|
||||
>
|
||||
无店铺
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Spin :spinning="shopsLoading">
|
||||
<Empty
|
||||
v-if="!shopsLoading && shops.length === 0"
|
||||
@@ -313,8 +399,19 @@ onMounted(() => {
|
||||
/>
|
||||
<div class="flex min-w-0 flex-1 items-start justify-between gap-2">
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="truncate text-sm font-medium">
|
||||
{{ shopLabel(shop) }}
|
||||
<div class="flex items-center gap-1 truncate text-sm font-medium">
|
||||
<span class="min-w-0 truncate">{{ shopLabel(shop) }}</span>
|
||||
<Badge
|
||||
v-if="
|
||||
draftCountByShopId &&
|
||||
(draftCountByShopId[shop.id] || 0) > 0
|
||||
"
|
||||
:count="draftCountByShopId[shop.id]"
|
||||
:number-style="{
|
||||
backgroundColor: '#1677ff',
|
||||
fontSize: '10px',
|
||||
}"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="shop.mallId != null"
|
||||
|
||||
+3760
File diff suppressed because it is too large
Load Diff
+23
-2760
File diff suppressed because it is too large
Load Diff
@@ -306,8 +306,11 @@ onMounted(async () => {
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="text-base font-semibold">拼多多商品</span>
|
||||
<PermissionGate code="channel:pdd:goods:create">
|
||||
<Button type="primary" @click="publishOpen = true">
|
||||
{{ publishHasDraft ? '继续发布' : '发布商品' }}
|
||||
<Button type="primary" @click="$router.push('/pdd/goods/publish')">
|
||||
发布工作台
|
||||
</Button>
|
||||
<Button class="ml-2" @click="publishOpen = true">
|
||||
{{ publishHasDraft ? '继续弹窗发布' : '弹窗发布' }}
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import PddGoodsPublishEditor from '../components/PddGoodsPublishEditor.vue';
|
||||
|
||||
defineOptions({ name: 'PddGoodsPublishDeskEdit' });
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const draftId = computed(() => {
|
||||
const raw = route.params.draftId;
|
||||
const n = Number(Array.isArray(raw) ? raw[0] : raw);
|
||||
return Number.isFinite(n) ? n : null;
|
||||
});
|
||||
|
||||
function goBack() {
|
||||
void router.push('/pdd/goods/publish');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 不用 auto-content-height:标题区含店铺/类目后高度动态变化,改用 flex 占满 -->
|
||||
<Page
|
||||
class="flex min-h-0 flex-col"
|
||||
:style="{ height: 'var(--vben-content-height)' }"
|
||||
header-class="!items-start"
|
||||
content-padding-class="p-0"
|
||||
content-class="flex min-h-0 flex-1 flex-col overflow-hidden !h-auto !p-0"
|
||||
>
|
||||
<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"
|
||||
>
|
||||
#{{ draftId }}
|
||||
</span>
|
||||
</div>
|
||||
<!-- Editor 页面态 Teleport:店铺 / 类目 -->
|
||||
<div id="pdd-publish-edit-header-fields" class="w-full min-w-0"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<PddGoodsPublishEditor
|
||||
v-if="draftId"
|
||||
class="h-full min-h-0"
|
||||
variant="page"
|
||||
:open="true"
|
||||
:draft-id="draftId"
|
||||
@close="goBack"
|
||||
@success="goBack"
|
||||
@draft-saved="() => undefined"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,551 @@
|
||||
<script lang="ts" setup>
|
||||
import type { PddPublishDeskVO } from '#/api/channel/pdd/goods';
|
||||
import type { PddShopVO } from '#/api/channel/pdd/shop';
|
||||
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Card,
|
||||
Checkbox,
|
||||
Empty,
|
||||
InputNumber,
|
||||
Modal,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
clonePddPublishDeskDraftApi,
|
||||
createPddPublishDeskDraftApi,
|
||||
createPddPublishDeskJobApi,
|
||||
deletePddPublishDeskDraftApi,
|
||||
getPddPublishDeskJobApi,
|
||||
listPddPublishDeskDraftsApi,
|
||||
retryPddPublishDeskJobFailedApi,
|
||||
} from '#/api/channel/pdd/goods';
|
||||
import { getPddShopPageApi } from '#/api/channel/pdd/shop';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import PddShopColPage from '#/views/channel/pdd/components/PddShopColPage.vue';
|
||||
|
||||
defineOptions({ name: 'PddGoodsPublishDesk' });
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const loading = ref(false);
|
||||
const selectedShopId = ref<number | undefined>(undefined);
|
||||
/** 左栏「未分配」 */
|
||||
const filterUnassigned = ref(false);
|
||||
const drafts = ref<PddPublishDeskVO.Draft[]>([]);
|
||||
const shopCounts = ref<PddPublishDeskVO.ShopCount[]>([]);
|
||||
const totalPending = ref(0);
|
||||
const shopWithDraft = ref(0);
|
||||
const selectedRowKeys = ref<number[]>([]);
|
||||
const shops = ref<PddShopVO.Info[]>([]);
|
||||
|
||||
const cloneOpen = ref(false);
|
||||
const cloneSourceId = ref<number | undefined>();
|
||||
const cloneTargets = ref<{ pddShopId: number; count: number; checked: boolean }[]>(
|
||||
[],
|
||||
);
|
||||
const cloneSubmitting = ref(false);
|
||||
|
||||
const jobOpen = ref(false);
|
||||
const jobLoading = ref(false);
|
||||
const currentJob = ref<PddPublishDeskVO.Job | null>(null);
|
||||
let jobPollTimer: ReturnType<typeof setInterval> | undefined;
|
||||
|
||||
const statusLabel: Record<string, { text: string; color: string }> = {
|
||||
EDITING: { text: '编辑中', color: 'default' },
|
||||
NEED_CHECK: { text: '待校验', color: 'orange' },
|
||||
READY: { text: '可发布', color: 'blue' },
|
||||
PUBLISHING: { text: '发布中', color: 'processing' },
|
||||
FAILED: { text: '失败', color: 'error' },
|
||||
PUBLISHED: { text: '已发布', color: 'success' },
|
||||
};
|
||||
|
||||
const countByShopId = computed(() => {
|
||||
const map = new Map<number | 'unassigned', number>();
|
||||
for (const c of shopCounts.value) {
|
||||
if (c.pddShopId == null) {
|
||||
map.set('unassigned', Number(c.draftCount || 0));
|
||||
} else {
|
||||
map.set(c.pddShopId, Number(c.draftCount || 0));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
const draftCountRecord = computed(() => {
|
||||
const rec: Record<number, number> = {};
|
||||
for (const [k, v] of countByShopId.value) {
|
||||
if (typeof k === 'number') rec[k] = v;
|
||||
}
|
||||
return rec;
|
||||
});
|
||||
|
||||
const summaryText = computed(
|
||||
() =>
|
||||
`${shopWithDraft.value || 0} 店 · ${totalPending.value || 0} 待发`,
|
||||
);
|
||||
|
||||
const columns = [
|
||||
{ type: 'selection', width: 48 },
|
||||
{ title: '标题', dataIndex: 'title', key: 'title', ellipsis: true },
|
||||
{ title: '店铺', dataIndex: 'shopName', key: 'shopName', width: 140 },
|
||||
{ title: 'SKU数', dataIndex: 'skuCount', key: 'skuCount', width: 80 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '更新时间', dataIndex: 'updateTime', key: 'updateTime', width: 170 },
|
||||
{ title: '操作', key: 'actions', width: 200 },
|
||||
];
|
||||
|
||||
async function loadShops() {
|
||||
try {
|
||||
const data = await getPddShopPageApi({
|
||||
page: 1,
|
||||
pageSize: 500,
|
||||
filters: {},
|
||||
});
|
||||
shops.value = data.records ?? [];
|
||||
} catch {
|
||||
message.error('加载店铺失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDrafts() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const filters: {
|
||||
pddShopId?: number;
|
||||
} = {};
|
||||
if (filterUnassigned.value) {
|
||||
filters.pddShopId = 0;
|
||||
} else if (selectedShopId.value != null) {
|
||||
filters.pddShopId = selectedShopId.value;
|
||||
}
|
||||
const page = await listPddPublishDeskDraftsApi({
|
||||
page: 1,
|
||||
pageSize: 200,
|
||||
filters,
|
||||
});
|
||||
drafts.value = page.records ?? [];
|
||||
shopCounts.value = page.shopCounts ?? [];
|
||||
totalPending.value = page.totalPendingCount ?? 0;
|
||||
shopWithDraft.value = page.shopWithDraftCount ?? 0;
|
||||
selectedRowKeys.value = [];
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '加载草稿失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onShopSelect(shop: PddShopVO.Info | null) {
|
||||
filterUnassigned.value = false;
|
||||
selectedShopId.value = shop?.id;
|
||||
void loadDrafts();
|
||||
}
|
||||
|
||||
function selectUnassigned() {
|
||||
filterUnassigned.value = true;
|
||||
selectedShopId.value = undefined;
|
||||
void loadDrafts();
|
||||
}
|
||||
|
||||
async function createDraft() {
|
||||
try {
|
||||
const draft = await createPddPublishDeskDraftApi({
|
||||
title: '未命名草稿',
|
||||
pddShopId: selectedShopId.value,
|
||||
status: 'EDITING',
|
||||
skuCount: 0,
|
||||
});
|
||||
message.success('已创建草稿');
|
||||
await router.push(`/pdd/goods/publish/edit/${draft.id}`);
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '创建失败');
|
||||
}
|
||||
}
|
||||
|
||||
function openEdit(id: number) {
|
||||
void router.push(`/pdd/goods/publish/edit/${id}`).catch((err) => {
|
||||
console.error(err);
|
||||
message.error('无法打开编辑页,请刷新后再试');
|
||||
});
|
||||
}
|
||||
|
||||
async function removeDraft(id: number) {
|
||||
Modal.confirm({
|
||||
title: '删除草稿?',
|
||||
content: '删除后不可恢复',
|
||||
okType: 'danger',
|
||||
async onOk() {
|
||||
await deletePddPublishDeskDraftApi(id);
|
||||
message.success('已删除');
|
||||
await loadDrafts();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function openClone(draftId: number) {
|
||||
cloneSourceId.value = draftId;
|
||||
cloneTargets.value = shops.value.map((s) => ({
|
||||
pddShopId: s.id,
|
||||
count: 1,
|
||||
checked: selectedShopId.value === s.id,
|
||||
}));
|
||||
if (!cloneTargets.value.some((t) => t.checked) && cloneTargets.value[0]) {
|
||||
cloneTargets.value[0]!.checked = true;
|
||||
}
|
||||
cloneOpen.value = true;
|
||||
}
|
||||
|
||||
const clonePreview = computed(() =>
|
||||
cloneTargets.value
|
||||
.filter((t) => t.checked)
|
||||
.map((t) => {
|
||||
const shop = shops.value.find((s) => s.id === t.pddShopId);
|
||||
return `${shop?.mallName || t.pddShopId}+${t.count}`;
|
||||
})
|
||||
.join('、'),
|
||||
);
|
||||
|
||||
async function submitClone() {
|
||||
if (cloneSourceId.value == null) return;
|
||||
const targets = cloneTargets.value
|
||||
.filter((t) => t.checked)
|
||||
.map((t) => ({ pddShopId: t.pddShopId, count: t.count || 1 }));
|
||||
if (targets.length === 0) {
|
||||
message.warning('请至少勾选一个目标店铺');
|
||||
return;
|
||||
}
|
||||
cloneSubmitting.value = true;
|
||||
try {
|
||||
const created = await clonePddPublishDeskDraftApi({
|
||||
sourceDraftId: cloneSourceId.value,
|
||||
targets,
|
||||
});
|
||||
message.success(`已克隆 ${created.length} 条草稿`);
|
||||
cloneOpen.value = false;
|
||||
await loadDrafts();
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '克隆失败');
|
||||
} finally {
|
||||
cloneSubmitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function batchPublish() {
|
||||
if (selectedRowKeys.value.length === 0) {
|
||||
message.warning('请先勾选草稿');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const job = await createPddPublishDeskJobApi({
|
||||
draftIds: selectedRowKeys.value,
|
||||
});
|
||||
currentJob.value = job;
|
||||
jobOpen.value = true;
|
||||
startJobPoll(job.id);
|
||||
await loadDrafts();
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '创建发布任务失败');
|
||||
}
|
||||
}
|
||||
|
||||
/** 表格多选:在 script 中写 ref,避免模板自动解包后误用 .value */
|
||||
function onDraftSelectionChange(keys: (string | number)[]) {
|
||||
selectedRowKeys.value = keys.map(Number);
|
||||
}
|
||||
|
||||
function startJobPoll(jobId: number) {
|
||||
stopJobPoll();
|
||||
jobPollTimer = setInterval(() => {
|
||||
void refreshJob(jobId);
|
||||
}, 2000);
|
||||
void refreshJob(jobId);
|
||||
}
|
||||
|
||||
function stopJobPoll() {
|
||||
if (jobPollTimer) {
|
||||
clearInterval(jobPollTimer);
|
||||
jobPollTimer = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshJob(jobId: number) {
|
||||
jobLoading.value = true;
|
||||
try {
|
||||
const job = await getPddPublishDeskJobApi(jobId);
|
||||
currentJob.value = job;
|
||||
if (
|
||||
job.status === 'SUCCESS' ||
|
||||
job.status === 'PARTIAL' ||
|
||||
job.status === 'FAILED'
|
||||
) {
|
||||
stopJobPoll();
|
||||
void loadDrafts();
|
||||
}
|
||||
} catch {
|
||||
stopJobPoll();
|
||||
} finally {
|
||||
jobLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function retryFailed() {
|
||||
if (!currentJob.value) return;
|
||||
try {
|
||||
const job = await retryPddPublishDeskJobFailedApi(currentJob.value.id);
|
||||
currentJob.value = job;
|
||||
startJobPoll(job.id);
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '重试失败');
|
||||
}
|
||||
}
|
||||
|
||||
watch(selectedShopId, () => {
|
||||
// load via onShopSelect
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
await loadShops();
|
||||
await loadDrafts();
|
||||
});
|
||||
|
||||
onUnmounted(() => stopJobPoll());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PddShopColPage
|
||||
:selected-shop-id="selectedShopId"
|
||||
:draft-count-by-shop-id="draftCountRecord"
|
||||
show-unassigned-filter
|
||||
:unassigned-count="countByShopId.get('unassigned') || 0"
|
||||
:unassigned-selected="filterUnassigned"
|
||||
@select="onShopSelect"
|
||||
@select-unassigned="selectUnassigned"
|
||||
>
|
||||
<Card
|
||||
class="publish-desk-card ml-1 flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden sm:ml-2"
|
||||
:body-style="{
|
||||
flex: 1,
|
||||
minHeight: 0,
|
||||
padding: 0,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
overflow: 'hidden',
|
||||
}"
|
||||
>
|
||||
<template #title>
|
||||
<div class="flex min-w-0 items-center gap-3">
|
||||
<span class="text-base font-semibold">发布工作台</span>
|
||||
<span class="text-muted-foreground truncate text-sm font-normal">
|
||||
{{ summaryText }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
<template #extra>
|
||||
<Space wrap class="py-1">
|
||||
<PermissionGate code="channel:pdd:goods:create">
|
||||
<Button type="primary" @click="createDraft">新建草稿</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="channel:pdd:goods:create">
|
||||
<Button
|
||||
:disabled="selectedRowKeys.length === 0"
|
||||
@click="batchPublish"
|
||||
>
|
||||
批量发布选中
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<Button @click="loadDrafts">刷新</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<div class="min-h-0 flex-1 overflow-auto px-2 pb-2 pt-2 sm:px-3">
|
||||
<div
|
||||
v-if="filterUnassigned"
|
||||
class="text-muted-foreground mb-2 text-xs"
|
||||
>
|
||||
当前筛选:未分配店铺的草稿(点左侧「全部店铺」可查看全部)
|
||||
</div>
|
||||
<div
|
||||
v-else-if="selectedShopId"
|
||||
class="text-muted-foreground mb-2 text-xs"
|
||||
>
|
||||
当前店待发
|
||||
<Badge
|
||||
:count="countByShopId.get(selectedShopId) || 0"
|
||||
:number-style="{ backgroundColor: '#1677ff' }"
|
||||
/>
|
||||
</div>
|
||||
<Table
|
||||
:loading="loading"
|
||||
:columns="columns as any"
|
||||
:data-source="drafts"
|
||||
row-key="id"
|
||||
:pagination="false"
|
||||
:row-selection="{
|
||||
selectedRowKeys,
|
||||
onChange: onDraftSelectionChange,
|
||||
}"
|
||||
:locale="{ emptyText: '暂无待发草稿' }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
<Tag :color="statusLabel[record.status]?.color || 'default'">
|
||||
{{ statusLabel[record.status]?.text || record.status }}
|
||||
</Tag>
|
||||
<div
|
||||
v-if="record.lastError"
|
||||
class="mt-1 max-w-[160px] truncate text-xs text-red-500"
|
||||
:title="record.lastError"
|
||||
>
|
||||
{{ record.lastError }}
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<Space>
|
||||
<Button type="link" size="small" @click="openEdit(record.id)">
|
||||
编辑
|
||||
</Button>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
@click="openClone(record.id)"
|
||||
>
|
||||
克隆
|
||||
</Button>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
danger
|
||||
@click="removeDraft(record.id)"
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</template>
|
||||
</Table>
|
||||
<Empty
|
||||
v-if="!loading && drafts.length === 0"
|
||||
class="mt-8"
|
||||
description="暂无草稿,点击「新建草稿」开始"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Modal
|
||||
v-model:open="cloneOpen"
|
||||
title="一键克隆"
|
||||
:confirm-loading="cloneSubmitting"
|
||||
ok-text="确认克隆"
|
||||
destroy-on-close
|
||||
@ok="submitClone"
|
||||
>
|
||||
<p class="mb-3 text-sm text-muted-foreground">
|
||||
将选中母版复制到目标店(跨店标为「待校验」)。预览:
|
||||
<span class="text-foreground">{{ clonePreview || '无' }}</span>
|
||||
</p>
|
||||
<div class="max-h-72 space-y-2 overflow-y-auto">
|
||||
<div
|
||||
v-for="t in cloneTargets"
|
||||
:key="t.pddShopId"
|
||||
class="flex items-center gap-3 rounded border border-border/60 px-2 py-1.5"
|
||||
>
|
||||
<Checkbox v-model:checked="t.checked" />
|
||||
<span class="min-w-0 flex-1 truncate">
|
||||
{{
|
||||
shops.find((s) => s.id === t.pddShopId)?.mallName || t.pddShopId
|
||||
}}
|
||||
<Badge
|
||||
class="ml-1"
|
||||
:count="countByShopId.get(t.pddShopId) || 0"
|
||||
:number-style="{ backgroundColor: '#1677ff' }"
|
||||
/>
|
||||
</span>
|
||||
<span class="text-xs text-muted-foreground">份数</span>
|
||||
<InputNumber
|
||||
v-model:value="t.count"
|
||||
:min="1"
|
||||
:max="20"
|
||||
class="w-20"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
v-model:open="jobOpen"
|
||||
title="批量发布进度"
|
||||
:footer="null"
|
||||
width="720px"
|
||||
destroy-on-close
|
||||
@cancel="stopJobPoll"
|
||||
>
|
||||
<div v-if="currentJob" class="space-y-3">
|
||||
<div class="flex flex-wrap items-center gap-2 text-sm">
|
||||
<Tag>{{ currentJob.status }}</Tag>
|
||||
<span>
|
||||
成功 {{ currentJob.successCount }} / 失败
|
||||
{{ currentJob.failCount }} / 合计 {{ currentJob.totalCount }}
|
||||
</span>
|
||||
<Button
|
||||
v-if="currentJob.failCount > 0"
|
||||
size="small"
|
||||
@click="retryFailed"
|
||||
>
|
||||
重试失败项
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
:loading="jobLoading"
|
||||
@click="refreshJob(currentJob.id)"
|
||||
>
|
||||
刷新
|
||||
</Button>
|
||||
</div>
|
||||
<Table
|
||||
size="small"
|
||||
:pagination="false"
|
||||
:data-source="currentJob.items || []"
|
||||
row-key="id"
|
||||
:columns="[
|
||||
{ title: '店铺', dataIndex: 'shopName', width: 140 },
|
||||
{ title: '标题', dataIndex: 'title', ellipsis: true },
|
||||
{ title: '状态', dataIndex: 'status', width: 100 },
|
||||
{ title: 'goodsId', dataIndex: 'goodsId', width: 120 },
|
||||
{ title: '错误', dataIndex: 'errorMessage', ellipsis: true },
|
||||
]"
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
</PddShopColPage>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* Card 标题区默认 overflow:hidden + nowrap,会裁切带 Badge 的操作按钮 */
|
||||
.publish-desk-card :deep(.ant-card-head) {
|
||||
flex-shrink: 0;
|
||||
height: auto;
|
||||
min-height: 48px;
|
||||
overflow: visible;
|
||||
}
|
||||
.publish-desk-card :deep(.ant-card-head-wrapper) {
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
overflow: visible;
|
||||
}
|
||||
.publish-desk-card :deep(.ant-card-head-title),
|
||||
.publish-desk-card :deep(.ant-card-extra) {
|
||||
overflow: visible;
|
||||
white-space: normal;
|
||||
padding-top: 12px;
|
||||
padding-bottom: 12px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user