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