feat: 授权店铺内部店铺无logo自动同步

This commit is contained in:
2026-08-14 00:49:41 +08:00
parent 861ed8df4f
commit b382800301
9 changed files with 173 additions and 115 deletions
@@ -12,6 +12,7 @@ CREATE TABLE `ec_shop` (
`company_id` bigint UNSIGNED NOT NULL COMMENT '所属公司ID',
`name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '店铺名称',
`logo_image_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT 'logo图片ID',
`logo_url` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'logo外链URL(渠道授权等;查询时有 logo_image_id 则覆盖)',
`platform_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台代码(软约定枚举,无平台表)',
`external_shop_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '外部店铺ID(如拼多多 mall_id;与 platform_code 组合关联平台店铺)',
`order_inc_sync_enabled` tinyint NOT NULL DEFAULT 0 COMMENT '订单增量同步开关:0关 1开(产品配置,与渠道运行态分离)',
@@ -0,0 +1,3 @@
-- 店铺 logo 外链:系统上传仍用 logo_image_id;查询时有 id 则覆盖 url;授权无内部图时回填
ALTER TABLE `ec_shop`
ADD COLUMN `logo_url` varchar(512) NULL DEFAULT NULL COMMENT 'logo外链URL(渠道授权等;查询时有 logo_image_id 则覆盖)' AFTER `logo_image_id`;
@@ -181,7 +181,7 @@ public class PddAuthServiceImpl implements PddAuthService {
}
upsertPddShop(companyId, auth.getId(), mallId, mallInfo, tokenResponse.getOwnerName());
bindInternalShop(companyId, userId, shopId, mallId, mallInfo, tokenResponse.getOwnerName());
bindInternalShop(companyId, userId, shopId, mallId, mallInfo);
String shopName = firstNonBlank(
mallInfo != null ? mallInfo.getMallName() : null,
@@ -332,8 +332,7 @@ public class PddAuthServiceImpl implements PddAuthService {
Long userId,
Long shopId,
Long mallId,
PddMallApiSnapshot mallInfo,
String ownerName) {
PddMallApiSnapshot mallInfo) {
ShopPO shop = shopMapper.selectById(shopId);
if (shop == null || !companyId.equals(shop.getCompanyId())) {
throw new BusinessException("授权关联的内部店铺不存在或不属于当前公司");
@@ -361,11 +360,12 @@ public class PddAuthServiceImpl implements PddAuthService {
}
shop.setExternalShopId(externalShopId);
String mallName = firstNonBlank(
mallInfo != null ? mallInfo.getMallName() : null,
ownerName);
if (StringUtils.hasText(mallName)) {
shop.setName(mallName);
// 无系统内部 logo 时,用授权店铺 logo 填充外链(与商品渠道图口径一致)
if (shop.getLogoImageId() == null
&& !StringUtils.hasText(shop.getLogoUrl())
&& mallInfo != null
&& StringUtils.hasText(mallInfo.getLogo())) {
shop.setLogoUrl(mallInfo.getLogo().trim());
}
shop.setUpdateBy(userId);
shopMapper.updateById(shop);
@@ -38,6 +38,12 @@ public class ShopPO {
@TableField("logo_image_id")
private Long logoImageId;
/**
* logo 外链 URL(渠道授权等;查询时有 logo_image_id 则覆盖)
*/
@TableField("logo_url")
private String logoUrl;
/**
* 平台代码(软约定,见 PlatformCode)
*/
@@ -32,9 +32,9 @@ public class ShopVO {
private String name;
/**
* logo URL
* logo URL(有 logo_image_id 时为系统文件访问地址,否则为 logo_url 外链)
*/
@Schema(description = "logo URL", example = "https://example.com/logo.jpg")
@Schema(description = "logo URL(有系统文件 id 时覆盖外链)", example = "https://example.com/logo.jpg")
private String logo;
/**
@@ -238,8 +238,15 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
ShopVO shopVO = new ShopVO();
BeanCopyUtils.copyProperties(shop, shopVO);
// 有系统文件 id 则覆盖;否则用渠道外链 logo_url(与商品 mainImage 口径一致)
if (shop.getLogoImageId() != null) {
shopVO.setLogo(sysFileService.getFileAccessUrl(shop.getLogoImageId()));
String accessUrl = sysFileService.getFileAccessUrl(shop.getLogoImageId());
if (accessUrl != null && !accessUrl.isBlank()) {
shopVO.setLogo(accessUrl);
}
}
if (shopVO.getLogo() == null || shopVO.getLogo().isBlank()) {
shopVO.setLogo(shop.getLogoUrl());
}
if (shop.getPlatformCode() != null && !shop.getPlatformCode().isBlank()) {
shopVO.setPlatformName(PlatformCode.labelOf(shop.getPlatformCode()));
@@ -20,10 +20,10 @@ export const overridesPreferences = defineOverridesPreferences({
mode: 'light',
},
transition: {
enable: false,
name: 'fade',
loading: false,
progress: false,
},
logo: {
source: '/cd-logo.png',
},
});
});
@@ -6,17 +6,22 @@ import type { Dayjs } from 'dayjs';
import { computed, onBeforeUnmount, ref } from 'vue';
import {
Alert,
Button,
Card,
DatePicker,
Descriptions,
Drawer,
Empty,
Form,
List,
Modal,
Progress,
Radio,
Space,
Switch,
Tag,
Typography,
message,
} from 'ant-design-vue';
import dayjs from 'dayjs';
@@ -414,53 +419,61 @@ defineExpose({ open, close: handleClose });
:mask-closable="!hasActiveFullTask"
@close="handleClose"
>
<div class="space-y-4">
<!-- 增量 -->
<div
class="rounded border border-slate-200 p-3 dark:border-[hsl(240deg_3.7%_22%)]"
>
<div class="mb-2 flex items-center justify-between">
<span class="text-sm font-medium">增量同步</span>
<Tag :color="incHealthColor">{{ incHealthLabel }}</Tag>
</div>
<div class="mb-2 flex flex-wrap items-center gap-3">
<Switch
:checked="!!incremental?.enabled"
checked-children="开"
un-checked-children="关"
@change="handleToggleIncremental"
/>
<span class="text-xs text-slate-500">开启后定时 Job 拉取增量并转换</span>
<Button
size="small"
type="primary"
ghost
:loading="incSubmitting"
@click="handleManualIncremental"
>
手动增量一次
</Button>
</div>
<div
class="grid grid-cols-1 gap-1 text-xs text-slate-600 sm:grid-cols-2 dark:text-slate-300"
>
<div>游标:{{ formatTime(incremental?.lastCursorAt) }}</div>
<div>上次成功:{{ formatTime(incremental?.lastSuccessTime) }}</div>
</div>
<p v-if="incremental?.lastError" class="mt-2 text-xs text-red-500">
{{ incremental.lastError }}
</p>
<p class="mt-2 text-xs text-slate-500">
手动增量按订单更新时间拉取自上次游标以来的变更,用于发货/售后等状态同步。
</p>
</div>
<Space direction="vertical" :size="16" class="w-full">
<Card size="small">
<template #title>
<Space>
<span>增量同步</span>
<Tag :color="incHealthColor">{{ incHealthLabel }}</Tag>
</Space>
</template>
<Space direction="vertical" :size="12" class="w-full">
<Space wrap align="center">
<Switch
:checked="!!incremental?.enabled"
checked-children="开"
un-checked-children="关"
@change="handleToggleIncremental"
/>
<Typography.Text type="secondary">
开启后定时 Job 拉取增量并转换
</Typography.Text>
<Button
size="small"
type="primary"
ghost
:loading="incSubmitting"
@click="handleManualIncremental"
>
手动增量一次
</Button>
</Space>
<!-- 全量任务列表 -->
<div
class="rounded border border-slate-200 p-3 dark:border-[hsl(240deg_3.7%_22%)]"
>
<div class="mb-3 flex items-center justify-between gap-2">
<span class="text-sm font-medium">全量同步任务</span>
<Descriptions bordered size="small" :column="1">
<Descriptions.Item label="游标">
{{ formatTime(incremental?.lastCursorAt) }}
</Descriptions.Item>
<Descriptions.Item label="上次成功">
{{ formatTime(incremental?.lastSuccessTime) }}
</Descriptions.Item>
</Descriptions>
<Alert
v-if="incremental?.lastError"
type="error"
show-icon
:message="incremental.lastError"
/>
<Alert
type="info"
show-icon
message="手动增量按订单更新时间拉取自上次游标以来的变更,用于发货/售后等状态同步。"
/>
</Space>
</Card>
<Card size="small" title="全量同步任务">
<template #extra>
<Space size="small">
<Button size="small" :loading="listLoading" @click="loadFullTasks">
刷新
@@ -474,28 +487,19 @@ defineExpose({ open, close: handleClose });
创建全量任务
</Button>
</Space>
</div>
</template>
<div v-if="fullTasks.length > 0" class="max-h-[52vh] space-y-3 overflow-y-auto pr-1">
<div
v-for="task in fullTasks"
:key="task.id"
class="rounded border border-slate-100 p-3 dark:border-[hsl(240deg_3.7%_18%)]"
>
<div class="mb-2 flex flex-wrap items-center justify-between gap-2">
<div class="flex flex-wrap items-center gap-2 text-sm">
<span class="font-medium">#{{ task.id }}</span>
<Tag :color="statusTag(task.status).color">
{{ statusTag(task.status).text }}
</Tag>
<span class="text-xs text-slate-500">
{{ task.doneDays }}/{{ task.totalDays }} 天
<template v-if="task.failedDays">
· 失败日 {{ task.failedDays }}
</template>
</span>
</div>
<Space size="small">
<List
v-if="fullTasks.length > 0"
:data-source="fullTasks"
:loading="listLoading"
item-layout="vertical"
size="small"
class="max-h-[52vh] overflow-y-auto"
>
<template #renderItem="{ item: task }">
<List.Item>
<template #actions>
<Button
v-if="isTaskActive(task)"
size="small"
@@ -515,41 +519,67 @@ defineExpose({ open, close: handleClose });
>
续跑
</Button>
</Space>
</div>
<div class="mb-2 text-xs text-slate-500">
区间 {{ task.dateFrom }} ~ {{ task.dateTo }}
<span v-if="task.currentDate"> · 当前 {{ task.currentDate }}</span>
</div>
<div class="mb-1 text-xs text-slate-400">
创建 {{ formatTime(task.createTime) }}
<template v-if="task.finishTime">
· 结束 {{ formatTime(task.finishTime) }}
</template>
</div>
<Progress
v-if="isTaskActive(task) || task.status === 'SUCCESS'"
:percent="taskProgressPercent(task)"
size="small"
:status="task.status === 'FAILED' ? 'exception' : undefined"
/>
<p v-if="task.lastError" class="mt-2 text-xs text-red-500">
{{ task.lastError }}
</p>
</div>
</div>
<List.Item.Meta>
<template #title>
<Space wrap>
<span>#{{ task.id }}</span>
<Tag :color="statusTag(task.status).color">
{{ statusTag(task.status).text }}
</Tag>
<Typography.Text type="secondary">
{{ task.doneDays }}/{{ task.totalDays }} 天
<template v-if="task.failedDays">
· 失败日 {{ task.failedDays }}
</template>
</Typography.Text>
</Space>
</template>
<template #description>
<div>
区间 {{ task.dateFrom }} ~ {{ task.dateTo }}
<template v-if="task.currentDate">
· 当前 {{ task.currentDate }}
</template>
</div>
<div>
创建 {{ formatTime(task.createTime) }}
<template v-if="task.finishTime">
· 结束 {{ formatTime(task.finishTime) }}
</template>
</div>
</template>
</List.Item.Meta>
<Progress
v-if="isTaskActive(task) || task.status === 'SUCCESS'"
:percent="taskProgressPercent(task)"
size="small"
:status="task.status === 'FAILED' ? 'exception' : undefined"
/>
<Alert
v-if="task.lastError"
class="mt-2"
type="error"
show-icon
:message="task.lastError"
/>
</List.Item>
</template>
</List>
<Empty
v-else
:image="Empty.PRESENTED_IMAGE_SIMPLE"
description="暂无全量任务"
/>
</div>
</div>
</Card>
</Space>
<template #footer>
<div class="flex justify-end">
<Space class="w-full justify-end">
<Button @click="handleClose">关闭</Button>
</div>
</Space>
</template>
</Drawer>
@@ -18,6 +18,10 @@ import { getPddAuthorizeUrlApi } from '#/api/ecommerce/pdd/auth';
import { batchPddOrderSyncStatusApi } from '#/api/ecommerce/pdd/order-sync';
import { getPlatformListApi } from '#/api/ecommerce/platform';
import { deleteShopApi, getShopPageApi } from '#/api/ecommerce/shop';
import {
getPlatformLabel,
getPlatformTagColor,
} from '#/utils/platform-display';
import PddOrderSyncDrawer from './components/PddOrderSyncDrawer.vue';
import PddShopDetailModal from './components/PddShopDetailModal.vue';
@@ -77,12 +81,14 @@ const gridOptions: VxeGridProps<any> = {
{
title: '外部店铺',
minWidth: 180,
align: 'center' as const,
showOverflow: false,
slots: { default: 'externalShop' },
},
{
title: '订单同步',
minWidth: 200,
align: 'center' as const,
showOverflow: false,
slots: { default: 'orderSync' },
},
@@ -98,8 +104,9 @@ const gridOptions: VxeGridProps<any> = {
},
{
title: '操作',
minWidth: 360,
minWidth: 320,
fixed: 'right' as const,
showOverflow: false,
slots: { default: 'action' },
},
],
@@ -450,21 +457,25 @@ onUnmounted(() => {
</template>
<template #externalShop="{ row }: { row: ShopVO.Info }">
<div v-if="isPddShop(row)" class="flex flex-col gap-1">
<Tag v-if="hasExternalShop(row)" color="success" class="!mr-0 w-fit">
已绑定
<div v-if="isPddShop(row)" class="flex flex-col items-center gap-1">
<Tag
v-if="hasExternalShop(row)"
:color="getPlatformTagColor(row.platformCode)"
class="!mr-0 w-fit"
>
{{ getPlatformLabel(row.platformCode, row.platformName) }}
</Tag>
<Tag v-else color="default" class="!mr-0 w-fit">未授权</Tag>
<span
v-if="row.pddShop?.mallName"
class="text-primary cursor-pointer text-xs hover:underline"
class="text-primary cursor-pointer text-center text-xs hover:underline"
@click="handleViewExternalShop(row)"
>
{{ row.pddShop.mallName }}
</span>
<span
v-else-if="row.externalShopId"
class="text-xs text-slate-500"
class="text-center text-xs text-slate-500"
>
mall_id: {{ row.externalShopId }}
</span>
@@ -475,7 +486,7 @@ onUnmounted(() => {
<template #orderSync="{ row }: { row: ShopVO.Info }">
<div
v-if="isPddShop(row) && hasExternalShop(row)"
class="flex cursor-pointer flex-col gap-1"
class="inline-flex cursor-pointer flex-col items-center gap-1"
@click="handleSyncPddOrders(row)"
>
<div class="flex items-center gap-1 text-xs">
@@ -495,7 +506,7 @@ onUnmounted(() => {
</template>
<template #action="{ row }: { row: ShopVO.Info }">
<Space wrap>
<Space>
<Button
v-if="isPddShop(row) && hasExternalShop(row)"
size="small"